home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil73DFD180666871EC6F7D182ADABA99C2
< prev
next >
Wrap
Text File
|
2010-07-12
|
9KB
|
257 lines
var gYaPartner = {
_init: function() {
OBSERVER_SERVICE.addObserver(this, "quit-application-granted", false);
OBSERVER_SERVICE.addObserver(this, "profile-after-change", false);
},
_uninit: function() {
OBSERVER_SERVICE.removeObserver(this, "profile-after-change");
OBSERVER_SERVICE.removeObserver(this, "quit-application-granted");
if (gYaInstaller && gYaInstaller.isBarUninstalled)
this.removePartnerData(true);
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "quit-application-granted":
this._uninit();
break;
case "profile-after-change":
this._profileInit();
break;
}
},
_profileInit: function() {
var partnerDir = this._getPartnerDir("profile") || this._getPartnerDir("xpi");
if (partnerDir) {
var _partnetXmlProfileFile = this._getPartnerDir("yandex");
if (_partnetXmlProfileFile)
_partnetXmlProfileFile.append("partner.xml");
if (!_partnetXmlProfileFile || !_partnetXmlProfileFile.exists() || !_partnetXmlProfileFile.isFile()) {
var partnerFile = partnerDir.clone();
partnerFile.append("partner.xml");
if (partnerFile.exists() && partnerFile.isFile() && partnerFile.isReadable()) {
var partnerXml = this.convertPartnerFile(partnerFile);
if (partnerXml) {
var partnerXmlProfileFile = this._getPartnerDir("yandex", true);
if (partnerXmlProfileFile) {
partnerXmlProfileFile.append("partner.xml");
try {
partnerXmlProfileFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0755);
if (partnerXmlProfileFile.exists() && partnerXmlProfileFile.isFile() && partnerXmlProfileFile.isWritable()) {
gYaSearchService.writeFile(partnerXmlProfileFile,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
partnerXml.toString());
this._checkPartnerInUI();
}
} catch(e) {
gYaSearchService.log("gYaPartner._profileInit error: " + e);
}
}
}
}
}
this.removePartnerData(false);
}
},
removePartnerData: function(aIncludeInstalled) {
if (aIncludeInstalled == true) {
try { this._getPartnerDir("yandex").remove(true); } catch(e) {}
}
try { this._getPartnerDir("profile").remove(true); } catch(e) {}
try { this._getPartnerDir("xpi").remove(true); } catch(e) {}
},
_getPartnerDir: function(aType, aCreate) {
var partnerDir;
switch (aType) {
case "profile":
partnerDir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
break;
case "xpi":
partnerDir = gYaSearchService.getInstallDir();
break;
case "yandex":
partnerDir = gYaSearchService.getYandexDir();
break;
default:
throw "Wrong directory type";
break;
}
partnerDir.append("yapartner");
if (aCreate == true && !(partnerDir.exists() && partnerDir.isDirectory())) {
try {
partnerDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
} catch(e) {}
}
return (partnerDir.exists() && partnerDir.isDirectory()) ? partnerDir : null;
},
convertPartnerFile: function(aPartnerFile) {
var partnerXml = gYaSearchService.safeE4Xml(gYaSearchService.readFile(aPartnerFile), null, "partner");
if (!partnerXml)
return null;
var partnerDir = aPartnerFile.parent;
for each (var button in partnerXml.button) {
var iconFile = partnerDir.clone();
iconFile.append(button.@icon);
if (iconFile.exists() && iconFile.isFile() && iconFile.isReadable()) {
var iconURI = this.generateImageDataURI(iconFile);
if (iconURI)
button.@image = iconURI;
}
}
partnerXml.@version = "1";
return partnerXml;
},
generateImageDataURI: function(aFile) {
var contentType = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService).getTypeFromFile(aFile);
var inputStream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
inputStream.init(aFile, 0x01, 0600, 0);
var stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
stream.setInputStream(inputStream);
var imageBytes = stream.readByteArray(stream.available());
var encoded = btoa(String.fromCharCode.apply(null, imageBytes));
stream.close();
inputStream.close();
return "data:" + contentType + ";base64," + encoded;
},
_hasToolbaritem: null,
toolbaritemContent: function(aDocument) {
if (this._hasToolbaritem === false)
return false;
var toolbarItem = false;
var partnerXmlFile = this._getPartnerDir("yandex");
if (partnerXmlFile) {
partnerXmlFile.append("partner.xml");
if (partnerXmlFile.exists() && partnerXmlFile.isFile()) {
var toolbarItemXml = gYaSearchService.safeE4Xml(gYaSearchService.readFile(partnerXmlFile), null, "partner");
if (toolbarItemXml) {
toolbarItem =
gYaSearchService.DOMUtils.adoptNode(
gYaSearchService.getDOMDocContent("partner-item",
gYaSearchService.domParser.parseFromString(toolbarItemXml.toString(), "text/xml")
), aDocument);
}
}
}
this._hasToolbaritem = !!toolbarItem;
return toolbarItem;
},
_checkPartnerInUI: function() {
this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
this._dataSource = this._rdf.GetDataSource("rdf:local-store");
this._dirty = false;
var currentsetResource = this._rdf.GetResource("currentset");
var toolbar = this._rdf.GetResource("chrome://browser/content/browser.xul#yasearch-bar");
var currentset = this._getPersist(toolbar, currentsetResource);
var overlayFile = gYaSearchService.getContentDir();
overlayFile.append("yasearch.xul");
var overlayData = gYaSearchService.readFile(overlayFile);
var overlayDoc = gYaSearchService.domParser.parseFromString(overlayData, "text/xml");
var defaultset = overlayDoc.getElementById("yasearch-bar").getAttribute("defaultset");
if (defaultset && currentset) {
var newId = "yasearch-partner",
afterId = "yasearch-preferences",
newset;
function _makeRegexpForId(aId) {
return new RegExp("(^|,)(" + aId.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + ")($|,)");
}
if (currentset == "__empty") {
newset = newId;
} else if (!_makeRegexpForId(newId).test(currentset)) {
var defaultsetCuteArray =
(defaultset.split("," + newId)[0]).split(",")
.filter(function(aId) { return !!aId; })
.map(function(aId) { return _makeRegexpForId(aId); });
var j = defaultsetCuteArray.length,
foundRe = false;
while (!foundRe && --j > -1)
foundRe = defaultsetCuteArray[j].test(currentset) ? defaultsetCuteArray[j] : false;
newset = foundRe ? currentset.replace(foundRe, "$1$2," + newId + "$3") :
newId + ", " + currentset;
}
if (newset)
this._setPersist(toolbar, currentsetResource, newset);
}
if (this._dirty)
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
this._rdf = null;
this._dataSource = null;
},
_getPersist: function bg__getPersist(aSource, aProperty) {
var target = this._dataSource.GetTarget(aSource, aProperty, true);
if (target instanceof Ci.nsIRDFLiteral)
return target.Value;
return null;
},
_setPersist: function bg__setPersist(aSource, aProperty, aTarget) {
this._dirty = true;
try {
var oldTarget = this._dataSource.GetTarget(aSource, aProperty, true);
if (oldTarget) {
if (aTarget)
this._dataSource.Change(aSource, aProperty, oldTarget, this._rdf.GetLiteral(aTarget));
else
this._dataSource.Unassert(aSource, aProperty, oldTarget);
} else {
this._dataSource.Assert(aSource, aProperty, this._rdf.GetLiteral(aTarget), true);
}
}
catch(ex) {}
}
};
gYaPartner._init();