зеркало из https://github.com/mozilla/pjs.git
Bug 514510: search engines should appear in the addons manager, r=gavin
This commit is contained in:
Родитель
99743f82c1
Коммит
08b02bc334
|
@ -110,6 +110,46 @@
|
|||
</implementation>
|
||||
</binding>
|
||||
|
||||
<binding id="extension-searchplugin" extends="chrome://browser/content/bindings.xml#richlistitem">
|
||||
<content orient="vertical">
|
||||
<xul:hbox align="start">
|
||||
<xul:image width="32" height="32" xbl:inherits="src=iconURL"/>
|
||||
<xul:vbox flex="1">
|
||||
<xul:hbox align="center">
|
||||
<xul:label class="title" xbl:inherits="value=name"/>
|
||||
<xul:spacer flex="1"/>
|
||||
<xul:label class="normal" crop="end" xbl:inherits="value=typeLabel"/>
|
||||
</xul:hbox>
|
||||
<xul:vbox>
|
||||
<xul:label class="normal hide-on-select" xbl:inherits="value=description" crop="end" flex="1"/>
|
||||
<xul:description class="normal show-on-select" xbl:inherits="xbl:text=description" flex="1"/>
|
||||
</xul:vbox>
|
||||
</xul:vbox>
|
||||
</xul:hbox>
|
||||
<xul:hbox class="show-on-select">
|
||||
<xul:spacer flex="1"/>
|
||||
<xul:button anonid="enable-button" class="show-on-disable hide-on-enable hide-on-uninstall addon-enable" label="&addonEnable.label;"
|
||||
oncommand="ExtensionsView.enable(document.getBindingParent(this));"/>
|
||||
<xul:button class="show-on-enable hide-on-disable hide-on-uninstall addon-disable" label="&addonDisable.label;"
|
||||
oncommand="ExtensionsView.disable(document.getBindingParent(this));"/>
|
||||
<xul:button anonid="uninstall-button" class="hide-on-uninstall addon-uninstall" label="&addonUninstall.label;"
|
||||
oncommand="ExtensionsView.uninstall(document.getBindingParent(this));"/>
|
||||
<xul:button class="show-on-uninstall addon-cancel" label="&addonCancel.label;"
|
||||
oncommand="ExtensionsView.cancelUninstall(document.getBindingParent(this));"/>
|
||||
</xul:hbox>
|
||||
</content>
|
||||
|
||||
<implementation>
|
||||
<constructor>
|
||||
<![CDATA[
|
||||
let appManaged = this.getAttribute("appManaged");
|
||||
if (appManaged == "true")
|
||||
document.getAnonymousElementByAttribute(this, "anonid", "uninstall-button").setAttribute("disabled", "true");
|
||||
]]>
|
||||
</constructor>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
<binding id="extension-search" extends="chrome://browser/content/bindings.xml#richlistitem">
|
||||
<content orient="vertical">
|
||||
<xul:hbox align="start">
|
||||
|
|
|
@ -106,6 +106,10 @@ richlistitem[typeName="local"] {
|
|||
-moz-binding: url("chrome://browser/content/bindings/extensions.xml#extension-local");
|
||||
}
|
||||
|
||||
richlistitem[typeName="searchplugin"] {
|
||||
-moz-binding: url("chrome://browser/content/bindings/extensions.xml#extension-searchplugin");
|
||||
}
|
||||
|
||||
richlistitem[typeName="search"] {
|
||||
-moz-binding: url("chrome://browser/content/bindings/extensions.xml#extension-search");
|
||||
}
|
||||
|
|
|
@ -471,6 +471,9 @@ var Browser = {
|
|||
// clear out tabs the user hasn't touched lately on memory crunch
|
||||
os.addObserver(MemoryObserver, "memory-pressure", false);
|
||||
|
||||
// search engine changes
|
||||
os.addObserver(BrowserSearch, "browser-search-engine-modified", false);
|
||||
|
||||
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = new nsBrowserAccess();
|
||||
|
||||
let browsers = document.getElementById("browsers");
|
||||
|
@ -573,6 +576,7 @@ var Browser = {
|
|||
#ifdef WINCE
|
||||
os.removeObserver(SoftKeyboardObserver, "softkb-change");
|
||||
#endif
|
||||
os.removeObserver(BrowserSearch, "browser-search-engine-modified");
|
||||
|
||||
window.controllers.removeController(this);
|
||||
window.controllers.removeController(BrowserUI);
|
||||
|
@ -1374,11 +1378,49 @@ const BrowserSearch = {
|
|||
engines: null,
|
||||
_allEngines: [],
|
||||
|
||||
observe: function (aSubject, aTopic, aData) {
|
||||
if (aTopic != "browser-search-engine-modified")
|
||||
return;
|
||||
|
||||
switch (aData) {
|
||||
case "engine-added":
|
||||
case "engine-removed":
|
||||
// force a rebuild of the prefs list, if needed
|
||||
// XXX this is inefficient, shouldn't have to rebuild the entire list
|
||||
if (ExtensionsView._list)
|
||||
ExtensionsView.getAddonsFromLocal();
|
||||
|
||||
// fall through
|
||||
case "engine-changed":
|
||||
// XXX we should probably also update the ExtensionsView list here once
|
||||
// that's efficient, since the icon can change (happen during an async
|
||||
// installs from the web)
|
||||
|
||||
// blow away our cache
|
||||
this._engines = null;
|
||||
break;
|
||||
case "engine-current":
|
||||
// Not relevant
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
get _currentEngines() {
|
||||
let doc = getBrowser().contentDocument;
|
||||
return this._allEngines.filter(function(element) element.doc === doc, this);
|
||||
},
|
||||
|
||||
get searchService() {
|
||||
delete this.searchService;
|
||||
return this.searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
||||
},
|
||||
|
||||
get engines() {
|
||||
if (this._engines)
|
||||
return this._engines;
|
||||
return this._engines = this.searchService.getVisibleEngines({ });
|
||||
},
|
||||
|
||||
addPageSearchEngine: function (aEngine, aDocument) {
|
||||
// Clean the engine referenced for document that didn't exist anymore
|
||||
let browsers = Browser.browsers;
|
||||
|
@ -1427,26 +1469,22 @@ const BrowserSearch = {
|
|||
},
|
||||
|
||||
addPermanentSearchEngine: function (aEngine) {
|
||||
var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
||||
let iconURL = BrowserUI._favicon.src;
|
||||
searchService.addEngine(aEngine.href, Ci.nsISearchEngine.DATA_XML, iconURL, false);
|
||||
this.searchService.addEngine(aEngine.href, Ci.nsISearchEngine.DATA_XML, iconURL, false);
|
||||
|
||||
this.engines = null;
|
||||
this._engines = null;
|
||||
},
|
||||
|
||||
updateSearchButtons: function() {
|
||||
if (this.engines)
|
||||
if (this._engines)
|
||||
return;
|
||||
|
||||
var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
||||
var engines = searchService.getVisibleEngines({ });
|
||||
this.engines = engines;
|
||||
|
||||
// Clean the previous search engines button
|
||||
var container = document.getElementById("search-buttons");
|
||||
while (container.hasChildNodes())
|
||||
container.removeChild(container.lastChild);
|
||||
|
||||
let engines = this.engines;
|
||||
for (var e = 0; e < engines.length; e++) {
|
||||
var button = document.createElement("radio");
|
||||
var engine = engines[e];
|
||||
|
|
|
@ -55,6 +55,7 @@ var ExtensionsView = {
|
|||
_repoItem: null,
|
||||
_msg: null,
|
||||
_dloadmgr: null,
|
||||
_search: null,
|
||||
_restartCount: 0,
|
||||
_observerIndex: -1,
|
||||
|
||||
|
@ -246,6 +247,7 @@ var ExtensionsView = {
|
|||
|
||||
this._pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
|
||||
this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
|
||||
this._search = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
||||
|
||||
let repository = "@mozilla.org/extensions/addon-repository;1";
|
||||
try {
|
||||
|
@ -272,6 +274,7 @@ var ExtensionsView = {
|
|||
this._strings["addonType.2"] = strings.getString("addonType.2");
|
||||
this._strings["addonType.4"] = strings.getString("addonType.4");
|
||||
this._strings["addonType.8"] = strings.getString("addonType.8");
|
||||
this._strings["addonType.1024"] = strings.getString("addonType.1024");
|
||||
|
||||
let self = this;
|
||||
setTimeout(function() {
|
||||
|
@ -291,11 +294,6 @@ var ExtensionsView = {
|
|||
this.clearSection("local");
|
||||
|
||||
let items = this._extmgr.getItemList(Ci.nsIUpdateItem.TYPE_ANY, {});
|
||||
if (items.length == 0) {
|
||||
let strings = document.getElementById("bundle_browser");
|
||||
this.displaySectionMessage("local", strings.getString("addonsLocalNone.label"), null, true);
|
||||
document.getElementById("addons-update-all").disabled = true;
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
let addon = items[i];
|
||||
|
@ -303,6 +301,7 @@ var ExtensionsView = {
|
|||
// Some information is not directly accessible from the extmgr
|
||||
let isDisabled = this._getRDFProperty(addon.id, "isDisabled") == "true";
|
||||
let appDisabled = this._getRDFProperty(addon.id, "appDisabled");
|
||||
let appManaged = this._getRDFProperty(addon.id, "appManaged");
|
||||
let desc = this._getRDFProperty(addon.id, "description");
|
||||
let optionsURL = this._getRDFProperty(addon.id, "optionsURL");
|
||||
let opType = this._getRDFProperty(addon.id, "opType");
|
||||
|
@ -311,46 +310,101 @@ var ExtensionsView = {
|
|||
let listitem = this._createItem(addon, "local");
|
||||
listitem.setAttribute("isDisabled", isDisabled);
|
||||
listitem.setAttribute("appDisabled", appDisabled);
|
||||
listitem.setAttribute("appManaged", appManaged);
|
||||
listitem.setAttribute("description", desc);
|
||||
listitem.setAttribute("optionsURL", optionsURL);
|
||||
listitem.setAttribute("opType", opType);
|
||||
listitem.setAttribute("updateable", updateable);
|
||||
this._list.insertBefore(listitem, this._repoItem);
|
||||
}
|
||||
|
||||
// Load the search engines
|
||||
let defaults = this._search.getDefaultEngines({ }).map(function (e) e.name);
|
||||
function isDefault(aEngine)
|
||||
defaults.indexOf(aEngine.name) != -1
|
||||
|
||||
let engines = this._search.getEngines({ });
|
||||
for (let e = 0; e < engines.length; e++) {
|
||||
let engine = engines[e];
|
||||
let addon = {};
|
||||
addon.id = engine.name;
|
||||
addon.type = 1024;
|
||||
addon.name = engine.name;
|
||||
addon.version = "";
|
||||
addon.iconURL = engine.iconURI ? engine.iconURI.spec : "";
|
||||
|
||||
let listitem = this._createItem(addon, "searchplugin");
|
||||
listitem._engine = engine;
|
||||
listitem.setAttribute("isDisabled", engine.hidden ? "true" : "false");
|
||||
listitem.setAttribute("appDisabled", "false");
|
||||
listitem.setAttribute("appManaged", isDefault(engine));
|
||||
listitem.setAttribute("description", engine.description);
|
||||
listitem.setAttribute("optionsURL", "");
|
||||
listitem.setAttribute("opType", engine.hidden ? "needs-disable" : "");
|
||||
listitem.setAttribute("updateable", "false");
|
||||
this._list.insertBefore(listitem, this._repoItem);
|
||||
}
|
||||
|
||||
if (engines.length + items.length == 0) {
|
||||
let strings = document.getElementById("bundle_browser");
|
||||
this.displaySectionMessage("local", strings.getString("addonsLocalNone.label"), null, true);
|
||||
document.getElementById("addons-update-all").disabled = true;
|
||||
}
|
||||
},
|
||||
|
||||
enable: function ev_enable(aItem) {
|
||||
let id = this._getIDFromURI(aItem.id);
|
||||
this._extmgr.enableItem(id);
|
||||
let opType;
|
||||
if (aItem.getAttribute("type") == "1024") {
|
||||
aItem._engine.hidden = false;
|
||||
opType = "needs-enable";
|
||||
} else {
|
||||
let id = this._getIDFromURI(aItem.id);
|
||||
this._extmgr.enableItem(id);
|
||||
opType = this._getRDFProperty(id, "opType");
|
||||
|
||||
if (opType == "needs-enable")
|
||||
this.showRestart();
|
||||
else
|
||||
this.hideRestart();
|
||||
}
|
||||
|
||||
let opType = this._getRDFProperty(id, "opType");
|
||||
if (opType == "needs-enable")
|
||||
this.showRestart();
|
||||
else
|
||||
this.hideRestart();
|
||||
aItem.setAttribute("opType", opType);
|
||||
},
|
||||
|
||||
disable: function ev_disable(aItem) {
|
||||
let id = this._getIDFromURI(aItem.id);
|
||||
this._extmgr.disableItem(id);
|
||||
let opType;
|
||||
if (aItem.getAttribute("type") == "1024") {
|
||||
aItem._engine.hidden = true;
|
||||
opType = "needs-disable";
|
||||
} else {
|
||||
let id = this._getIDFromURI(aItem.id);
|
||||
this._extmgr.disableItem(id);
|
||||
opType = this._getRDFProperty(id, "opType");
|
||||
|
||||
let opType = this._getRDFProperty(id, "opType");
|
||||
if (opType == "needs-disable")
|
||||
this.showRestart();
|
||||
else
|
||||
this.hideRestart();
|
||||
if (opType == "needs-disable")
|
||||
this.showRestart();
|
||||
else
|
||||
this.hideRestart();
|
||||
}
|
||||
|
||||
aItem.setAttribute("opType", opType);
|
||||
},
|
||||
|
||||
uninstall: function ev_uninstall(aItem) {
|
||||
let id = this._getIDFromURI(aItem.id);
|
||||
this._extmgr.uninstallItem(id);
|
||||
let opType;
|
||||
if (aItem.getAttribute("type") == "1024") {
|
||||
this._search.removeEngine(aItem._engine);
|
||||
// the search-engine-modified observer in browser.js will take care of
|
||||
// updating the list
|
||||
} else {
|
||||
let id = this._getIDFromURI(aItem.id);
|
||||
this._extmgr.uninstallItem(id);
|
||||
opType = this._getRDFProperty(id, "opType");
|
||||
|
||||
let opType = this._getRDFProperty(id, "opType");
|
||||
if (opType == "needs-uninstall")
|
||||
this.showRestart();
|
||||
aItem.setAttribute("opType", opType);
|
||||
if (opType == "needs-uninstall")
|
||||
this.showRestart();
|
||||
aItem.setAttribute("opType", opType);
|
||||
}
|
||||
},
|
||||
|
||||
cancelUninstall: function ev_cancelUninstall(aItem) {
|
||||
|
|
|
@ -13,6 +13,7 @@ addonsConfirmInstall.install=Install
|
|||
addonType.2=Extension
|
||||
addonType.4=Theme
|
||||
addonType.8=Locale
|
||||
addonType.1024=Search
|
||||
|
||||
addonUpdate.checking=Checking for updates…
|
||||
addonUpdate.updating=Updating to %S
|
||||
|
|
Загрузка…
Ссылка в новой задаче