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
/
fil89C17E505EAA8C21519199303B225741
< prev
next >
Wrap
Text File
|
2010-07-12
|
6KB
|
185 lines
var gYaSearchPlugin = {
__engine: null,
__inited: false,
__checkEnginePrefName: "yasearch.general.searchplugin.check",
init: function() {
if (!this.__inited) {
this.__inited = true;
OBSERVER_SERVICE.addObserver(this, "browser-search-engine-modified", false);
}
},
destroy: function() {
if (this.__inited) {
this.__inited = false;
this.__engine = null;
OBSERVER_SERVICE.removeObserver(this, "browser-search-engine-modified");
this.__searchPluginFilePath = null;
}
},
engineName: UConverter.ConvertToUnicode("Яндекс"),
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "browser-search-engine-modified":
if (aData == "engine-changed" || aData == "engine-added") {
var engine = aSubject.QueryInterface(Ci.nsISearchEngine);
engine = engine.wrappedJSObject;
if (this.searchPluginFilePath && this.searchPluginFilePath == engine._location) {
this.__engine = engine;
} else if (this.__engine && engine._name == this.engineName && engine._location == this.onlineSearchPluginPath) {
for (var p in engine)
if (!(engine.__lookupGetter__(p) || engine.__lookupSetter__(p)))
this.__engine[p] = engine[p];
this.__engine = null;
}
}
break;
}
},
__searchPluginFilePath: null,
get searchPluginFilePath() {
if (this.__searchPluginFilePath === null) {
var engineFile = gYaSearchService.getInstallDir();
engineFile.append("searchplugins");
engineFile.append("yasearch.xml");
this.__searchPluginFilePath = (engineFile.exists() && engineFile.isFile()) ? engineFile.path : false;
}
return this.__searchPluginFilePath;
},
_getSearchPluginsDir: function(aDirType) {
return Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get(aDirType || "SrchPlugns", Ci.nsIFile);
},
__onlineSearchPluginPath: null,
get onlineSearchPluginPath() {
if (this.__onlineSearchPluginPath === null) {
var file = this._getSearchPluginsDir("UsrSrchPlugns");
file.append("yandexsearch.xml");
this.__onlineSearchPluginPath = (file.exists() && file.isFile()) ? file.path : false;
}
return this.__onlineSearchPluginPath;
},
get appSearchPluginFile() {
var file = this._getSearchPluginsDir("SrchPlugns");
file.append("yandex.xml");
return (file.exists() && file.isFile()) ? file : null;
},
addParamToEngine: function(aEngine, aName, aValue) {
if (!aValue)
return;
var url = aEngine._getURLOfType("text/html");
if (url) {
var replaced = false;
for (var i = 0; i < url.params.length; ++i) {
if (url.params[i].name == aName) {
url.params[i].value = aValue;
replaced = true;
break;
}
}
if (!replaced)
url.addParam(aName, aValue);
}
},
checkEngineSearchURL: function(aEngine) {
var service = gYaSearchService.getServiceById("www");
if (service && service.hasAttribute("search-url")) {
var url = aEngine._getURLOfType("text/html");
if (url && url.template) {
url.template = service.getAttribute("search-url").split("?")[0];
let suggestions = aEngine._getURLOfType("application/x-suggestions+json");
if (suggestions && suggestions.template && suggestions.template.indexOf("suggest-ff.cgi") > 0)
suggestions.template = gYaSearchService.searchEngineSuggestURL.split("?")[0];
return true;
}
}
return false;
},
getYaEngineParams: function() {
let params = {};
let yaSPFile = this.appSearchPluginFile;
if (yaSPFile && gYaSearchService.getCharPref("app.distributor") != "yandex") {
let fileData = gYaSearchService.readFile(yaSPFile);
if (fileData) {
let qsXml = gYaSearchService.safeE4Xml(fileData, null, "SearchPlugin");
if (qsXml) {
let qsns = new Namespace("qsns", "http://www.mozilla.org/2006/browser/search/");
let qsUrl = qsXml.qsns::Url.(function::attribute("type") == "text/html")[0];
if (qsUrl) {
for each (let param in qsUrl.qsns::Param.(function::attribute("name").toString() != "text"
&& function::attribute("name").toString() != "")) {
params[param.@name.toString()] = param.@value.toString();
}
return params;
}
}
}
}
params.clid = gYaSearchService.vendorData.clid6;
params.yasoft = gYaSearchService.AppInfo.yasoftStr;
return params;
},
checkSearchPluginInstall: function() {
var checkEngine = gYaSearchService.getBoolPref(this.__checkEnginePrefName);
if (checkEngine)
gYaSearchService.setComplexValue("browser.search.defaultenginename", this.engineName);
var ss = gYaSearchService.searchService;
if (("getEngines" in ss)) {
if (checkEngine) {
gYaSearchService.setBoolPref(this.__checkEnginePrefName, false);
var yaEngine = ss.getEngineByName(this.engineName);
if (yaEngine)
ss.currentEngine = yaEngine;
}
}
if (this.__engine && this.checkEngineSearchURL(this.__engine)) {
let engineParams = this.getYaEngineParams();
for (var [paramName, paramValue] in Iterator(engineParams)) {
this.addParamToEngine(this.__engine, paramName, paramValue);
}
}
this.destroy();
}
}
gYaSearchPlugin.init();