2009-04-22 07:19:48 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Mobile Browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mark Finkle <mfinkle@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
const PREFIX_ITEM_URI = "urn:mozilla:item:";
|
|
|
|
const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";
|
|
|
|
|
|
|
|
const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults";
|
|
|
|
|
2010-06-15 17:26:05 -07:00
|
|
|
#ifdef ANDROID
|
|
|
|
const URI_GENERIC_ICON_XPINSTALL = "drawable://alertaddons";
|
|
|
|
#else
|
2009-10-25 22:41:11 -07:00
|
|
|
const URI_GENERIC_ICON_XPINSTALL = "chrome://browser/skin/images/alert-addons-30.png";
|
2010-06-15 17:26:05 -07:00
|
|
|
#endif
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "AddonManager", function() {
|
|
|
|
Cu.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
return AddonManager;
|
|
|
|
});
|
|
|
|
|
2010-06-17 13:54:44 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "AddonRepository", function() {
|
|
|
|
Cu.import("resource://gre/modules/AddonRepository.jsm");
|
|
|
|
return AddonRepository;
|
|
|
|
});
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
var ExtensionsView = {
|
2009-08-26 17:44:35 -07:00
|
|
|
_strings: {},
|
2009-04-22 07:19:48 -07:00
|
|
|
_list: null,
|
|
|
|
_localItem: null,
|
|
|
|
_repoItem: null,
|
|
|
|
_msg: null,
|
|
|
|
_dloadmgr: null,
|
|
|
|
_restartCount: 0,
|
2009-05-26 18:46:44 -07:00
|
|
|
_observerIndex: -1,
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
_getOpTypeForOperations: function ev__getOpTypeForOperations(aOperations) {
|
|
|
|
if (aOperations & AddonManager.PENDING_UNINSTALL)
|
|
|
|
return "needs-uninstall";
|
|
|
|
if (aOperations & AddonManager.PENDING_ENABLE)
|
|
|
|
return "needs-enable";
|
|
|
|
if (aOperations & AddonManager.PENDING_DISABLE)
|
|
|
|
return "needs-disable";
|
|
|
|
return "";
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
2010-07-22 12:42:40 -07:00
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
_createItem: function ev__createItem(aAddon, aTypeName) {
|
|
|
|
let item = document.createElement("richlistitem");
|
|
|
|
item.setAttribute("id", PREFIX_ITEM_URI + aAddon.id);
|
|
|
|
item.setAttribute("addonID", aAddon.id);
|
|
|
|
item.setAttribute("typeName", aTypeName);
|
|
|
|
item.setAttribute("type", aAddon.type);
|
2009-08-26 17:44:35 -07:00
|
|
|
item.setAttribute("typeLabel", this._strings["addonType." + aAddon.type]);
|
2009-04-22 07:19:48 -07:00
|
|
|
item.setAttribute("name", aAddon.name);
|
|
|
|
item.setAttribute("version", aAddon.version);
|
|
|
|
item.setAttribute("iconURL", aAddon.iconURL);
|
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
2009-04-23 14:10:54 -07:00
|
|
|
clearSection: function ev_clearSection(aSection) {
|
2009-05-14 10:29:04 -07:00
|
|
|
let start = null;
|
|
|
|
let end = null;
|
2009-04-22 07:19:48 -07:00
|
|
|
|
|
|
|
if (aSection == "local") {
|
|
|
|
start = this._localItem;
|
|
|
|
end = this._repoItem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
start = this._repoItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (start.nextSibling != end)
|
|
|
|
this._list.removeChild(start.nextSibling);
|
|
|
|
},
|
|
|
|
|
|
|
|
_messageActions: function ev__messageActions(aData) {
|
|
|
|
if (aData == "addons-restart-app") {
|
|
|
|
// Notify all windows that an application quit has been requested
|
|
|
|
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
|
2009-04-22 07:19:48 -07:00
|
|
|
|
|
|
|
// If nothing aborted, quit the app
|
|
|
|
if (cancelQuit.data == false) {
|
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
getElementForAddon: function ev_getElementForAddon(aKey) {
|
|
|
|
let element = document.getElementById(PREFIX_ITEM_URI + aKey);
|
2009-06-16 12:45:00 -07:00
|
|
|
if (!element && this._list)
|
2010-06-17 13:54:44 -07:00
|
|
|
element = this._list.getElementsByAttribute("sourceURL", aKey)[0];
|
2009-04-22 07:19:48 -07:00
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
showMessage: function ev_showMessage(aMsg, aValue, aButtonLabel, aShowCloseButton, aNotifyData) {
|
|
|
|
let notification = this._msg.getNotificationWithValue(aValue);
|
|
|
|
if (notification)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
let buttons = null;
|
|
|
|
if (aButtonLabel) {
|
|
|
|
buttons = [ {
|
|
|
|
label: aButtonLabel,
|
2009-06-17 06:31:32 -07:00
|
|
|
accessKey: "",
|
2009-04-22 07:19:48 -07:00
|
|
|
data: aNotifyData,
|
|
|
|
callback: function(aNotification, aButton) {
|
|
|
|
self._messageActions(aButton.data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ];
|
|
|
|
}
|
|
|
|
|
|
|
|
this._msg.appendNotification(aMsg, aValue, "", this._msg.PRIORITY_WARNING_LOW, buttons).hideclose = !aShowCloseButton;
|
|
|
|
},
|
|
|
|
|
2010-03-25 10:22:26 -07:00
|
|
|
showRestart: function ev_showRestart(aMode) {
|
2009-06-16 12:45:00 -07:00
|
|
|
// Increment the count in case the view is not completely initialized
|
2009-04-22 07:19:48 -07:00
|
|
|
this._restartCount++;
|
2009-06-16 13:15:46 -07:00
|
|
|
|
2010-03-25 10:22:26 -07:00
|
|
|
// Pick the right message key from the properties file
|
|
|
|
aMode = aMode || "normal";
|
|
|
|
|
2009-06-16 12:45:00 -07:00
|
|
|
if (this._msg) {
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2010-03-25 10:22:26 -07:00
|
|
|
let message = "notificationRestart." + aMode;
|
|
|
|
this.showMessage(strings.getString(message), "restart-app",
|
2009-09-22 07:21:15 -07:00
|
|
|
strings.getString("notificationRestart.button"), false, "addons-restart-app");
|
2009-06-16 12:45:00 -07:00
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hideRestart: function ev_hideRestart() {
|
|
|
|
this._restartCount--;
|
2009-06-16 12:45:00 -07:00
|
|
|
if (this._restartCount == 0 && this._msg) {
|
2009-04-22 07:19:48 -07:00
|
|
|
let notification = this._msg.getNotificationWithValue("restart-app");
|
|
|
|
if (notification)
|
|
|
|
notification.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-03 15:05:43 -07:00
|
|
|
showOptions: function ev_showOptions(aID) {
|
|
|
|
this.hideOptions();
|
|
|
|
|
|
|
|
let item = this.getElementForAddon(aID);
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if the element is not the selected element, select it
|
|
|
|
if (item != this._list.selectedItem)
|
|
|
|
this._list.selectedItem = item;
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2009-09-03 15:05:43 -07:00
|
|
|
item.showOptions();
|
|
|
|
},
|
|
|
|
|
|
|
|
hideOptions: function ev_hideOptions() {
|
|
|
|
if (!this._list)
|
|
|
|
return;
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2009-09-03 15:05:43 -07:00
|
|
|
let items = this._list.childNodes;
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
let item = items[i];
|
|
|
|
if (item.hideOptions)
|
|
|
|
item.hideOptions();
|
|
|
|
}
|
2009-10-23 07:40:48 -07:00
|
|
|
this._list.ensureSelectedElementIsVisible();
|
2009-09-03 15:05:43 -07:00
|
|
|
},
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
get visible() {
|
|
|
|
let items = document.getElementById("panel-items");
|
2009-12-17 14:35:48 -08:00
|
|
|
if (BrowserUI.isPanelVisible() && items.selectedPanel.id == "addons-container")
|
2009-04-22 07:19:48 -07:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function ev_init() {
|
2010-07-13 07:36:09 -07:00
|
|
|
if (this._dloadmgr)
|
2009-04-22 07:19:48 -07:00
|
|
|
return;
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
this._dloadmgr = new AddonInstallListener();
|
|
|
|
AddonManager.addInstallListener(this._dloadmgr);
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-03-16 20:42:01 -07:00
|
|
|
// Watch for add-on update notifications
|
2010-07-13 07:36:09 -07:00
|
|
|
let os = Services.obs;
|
2010-03-16 20:42:01 -07:00
|
|
|
os.addObserver(this, "addon-update-started", false);
|
|
|
|
os.addObserver(this, "addon-update-ended", false);
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
if (!Services.prefs.getBoolPref("extensions.hideUpdateButton"))
|
2010-04-19 06:05:55 -07:00
|
|
|
document.getElementById("addons-update-all").hidden = false;
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
let self = this;
|
|
|
|
let panels = document.getElementById("panel-items");
|
|
|
|
panels.addEventListener("select",
|
|
|
|
function(aEvent) {
|
|
|
|
if (panels.selectedPanel.id == "addons-container")
|
2009-05-22 14:21:20 -07:00
|
|
|
self._delayedInit();
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
false);
|
|
|
|
},
|
|
|
|
|
2009-05-22 14:21:20 -07:00
|
|
|
_delayedInit: function ev__delayedInit() {
|
2009-04-22 07:19:48 -07:00
|
|
|
if (this._list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._list = document.getElementById("addons-list");
|
|
|
|
this._localItem = document.getElementById("addons-local");
|
|
|
|
this._repoItem = document.getElementById("addons-repo");
|
|
|
|
this._msg = document.getElementById("addons-messages");
|
|
|
|
|
2009-06-16 12:45:00 -07:00
|
|
|
// Show the restart notification in case a restart is needed, but the view
|
|
|
|
// was not visible at the time
|
|
|
|
let notification = this._msg.getNotificationWithValue("restart-app");
|
|
|
|
if (this._restartCount > 0 && !notification) {
|
|
|
|
this.showRestart();
|
|
|
|
this._restartCount--; // showRestart() always increments
|
|
|
|
}
|
2009-11-22 23:14:23 -08:00
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2010-05-19 19:43:02 -07:00
|
|
|
this._strings["addonType.extension"] = strings.getString("addonType.2");
|
|
|
|
this._strings["addonType.theme"] = strings.getString("addonType.4");
|
|
|
|
this._strings["addonType.locale"] = strings.getString("addonType.8");
|
|
|
|
this._strings["addonType.search"] = strings.getString("addonType.1024");
|
2009-06-16 13:15:46 -07:00
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
let self = this;
|
|
|
|
setTimeout(function() {
|
|
|
|
self.getAddonsFromLocal();
|
|
|
|
self.getAddonsFromRepo("");
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
|
2009-05-26 18:46:44 -07:00
|
|
|
uninit: function ev_uninit() {
|
2010-07-13 07:36:09 -07:00
|
|
|
let os = Services.obs;
|
2010-03-16 20:42:01 -07:00
|
|
|
os.removeObserver(this, "addon-update-started");
|
|
|
|
os.removeObserver(this, "addon-update-ended");
|
2009-07-01 09:50:20 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
AddonManager.removeInstallListener(this._dloadmgr);
|
2009-05-26 18:46:44 -07:00
|
|
|
},
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2009-11-22 23:14:23 -08:00
|
|
|
hideOnSelect: function ev_handleEvent(aEvent) {
|
|
|
|
// When list selection changes, be sure to close up any open options sections
|
|
|
|
if (aEvent.target == this._list)
|
|
|
|
this.hideOptions();
|
|
|
|
},
|
2009-05-26 18:46:44 -07:00
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
getAddonsFromLocal: function ev_getAddonsFromLocal() {
|
2009-04-23 14:10:54 -07:00
|
|
|
this.clearSection("local");
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
let self = this;
|
|
|
|
AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(items) {
|
2010-09-01 21:05:22 -07:00
|
|
|
let strings = Elements.browserBundle;
|
2010-09-01 12:13:42 -07:00
|
|
|
let anyUpdateable = false;
|
2010-05-19 19:43:02 -07:00
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
let addon = items[i];
|
|
|
|
let appManaged = (addon.scope == AddonManager.SCOPE_APPLICATION);
|
|
|
|
let opType = self._getOpTypeForOperations(addon.pendingOperations);
|
2010-09-01 12:13:42 -07:00
|
|
|
let updateable = (addon.permissions & AddonManager.PERM_CAN_UPGRADE) > 0;
|
2010-05-19 22:16:50 -07:00
|
|
|
let uninstallable = (addon.permissions & AddonManager.PERM_CAN_UNINSTALL) > 0;
|
2010-05-19 19:43:02 -07:00
|
|
|
|
2010-09-01 21:05:22 -07:00
|
|
|
let blocked = "";
|
|
|
|
switch(addon.blocklistState) {
|
|
|
|
case Ci.nsIBlocklistService.STATE_BLOCKED:
|
|
|
|
blocked = strings.getString("addonBlocked.blocked")
|
|
|
|
break;
|
|
|
|
case Ci.nsIBlocklistService.STATE_SOFTBLOCKED:
|
|
|
|
blocked = strings.getString("addonBlocked.softBlocked");
|
|
|
|
break;
|
|
|
|
case Ci.nsIBlocklistService.STATE_OUTDATED:
|
|
|
|
blocked = srings.getString("addonBlocked.outdated");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-01 12:13:42 -07:00
|
|
|
if (updateable)
|
|
|
|
anyUpdateable = true;
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
let listitem = self._createItem(addon, "local");
|
|
|
|
listitem.setAttribute("isDisabled", !addon.isActive);
|
|
|
|
listitem.setAttribute("appDisabled", addon.appDisabled);
|
|
|
|
listitem.setAttribute("appManaged", appManaged);
|
|
|
|
listitem.setAttribute("description", addon.description);
|
|
|
|
listitem.setAttribute("optionsURL", addon.optionsURL);
|
|
|
|
listitem.setAttribute("opType", opType);
|
|
|
|
listitem.setAttribute("updateable", updateable);
|
2010-05-19 22:16:50 -07:00
|
|
|
listitem.setAttribute("isReadonly", !uninstallable);
|
2010-09-15 03:40:12 -07:00
|
|
|
if (blocked)
|
|
|
|
listitem.setAttribute("blockedStatus", blocked);
|
2010-05-19 19:43:02 -07:00
|
|
|
listitem.addon = addon;
|
|
|
|
self._list.insertBefore(listitem, self._repoItem);
|
|
|
|
}
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
// Load the search engines
|
2010-07-13 07:36:09 -07:00
|
|
|
let defaults = Services.search.getDefaultEngines({ }).map(function (e) e.name);
|
2010-05-19 19:43:02 -07:00
|
|
|
function isDefault(aEngine)
|
|
|
|
defaults.indexOf(aEngine.name) != -1
|
2009-09-22 19:19:24 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
let defaultDescription = strings.getString("addonsSearchEngine.description");
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let engines = Services.search.getEngines({ });
|
2010-05-19 19:43:02 -07:00
|
|
|
for (let e = 0; e < engines.length; e++) {
|
|
|
|
let engine = engines[e];
|
|
|
|
let addon = {};
|
|
|
|
addon.id = engine.name;
|
|
|
|
addon.type = "search";
|
|
|
|
addon.name = engine.name;
|
|
|
|
addon.version = "";
|
|
|
|
addon.iconURL = engine.iconURI ? engine.iconURI.spec : "";
|
|
|
|
|
|
|
|
let listitem = self._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 || defaultDescription);
|
|
|
|
listitem.setAttribute("optionsURL", "");
|
|
|
|
listitem.setAttribute("opType", engine.hidden ? "needs-disable" : "");
|
|
|
|
listitem.setAttribute("updateable", "false");
|
|
|
|
self._list.insertBefore(listitem, self._repoItem);
|
|
|
|
}
|
2009-09-22 19:19:24 -07:00
|
|
|
|
2010-09-01 12:13:42 -07:00
|
|
|
if (engines.length + items.length == 0)
|
2010-05-19 19:43:02 -07:00
|
|
|
self.displaySectionMessage("local", strings.getString("addonsLocalNone.label"), null, true);
|
2010-09-01 12:13:42 -07:00
|
|
|
|
|
|
|
if (!anyUpdateable)
|
2010-05-19 19:43:02 -07:00
|
|
|
document.getElementById("addons-update-all").disabled = true;
|
|
|
|
});
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
enable: function ev_enable(aItem) {
|
2009-09-22 19:19:24 -07:00
|
|
|
let opType;
|
2010-05-19 19:43:02 -07:00
|
|
|
if (aItem.getAttribute("type") == "search") {
|
2010-06-03 12:55:37 -07:00
|
|
|
aItem.setAttribute("isDisabled", false);
|
2009-09-22 19:19:24 -07:00
|
|
|
aItem._engine.hidden = false;
|
|
|
|
opType = "needs-enable";
|
|
|
|
} else {
|
2010-05-19 19:43:02 -07:00
|
|
|
aItem.addon.userDisabled = false;
|
|
|
|
opType = this._getOpTypeForOperations(aItem.addon.pendingOperations);
|
2009-09-22 19:19:24 -07:00
|
|
|
|
|
|
|
if (opType == "needs-enable")
|
|
|
|
this.showRestart();
|
|
|
|
else
|
|
|
|
this.hideRestart();
|
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
|
|
|
|
aItem.setAttribute("opType", opType);
|
|
|
|
},
|
|
|
|
|
|
|
|
disable: function ev_disable(aItem) {
|
2009-09-22 19:19:24 -07:00
|
|
|
let opType;
|
2010-05-19 19:43:02 -07:00
|
|
|
if (aItem.getAttribute("type") == "search") {
|
2010-06-03 12:55:37 -07:00
|
|
|
aItem.setAttribute("isDisabled", true);
|
2009-09-22 19:19:24 -07:00
|
|
|
aItem._engine.hidden = true;
|
|
|
|
opType = "needs-disable";
|
|
|
|
} else {
|
2010-05-19 19:43:02 -07:00
|
|
|
aItem.addon.userDisabled = true;
|
|
|
|
opType = this._getOpTypeForOperations(aItem.addon.pendingOperations);
|
2009-09-22 19:19:24 -07:00
|
|
|
|
|
|
|
if (opType == "needs-disable")
|
|
|
|
this.showRestart();
|
|
|
|
else
|
|
|
|
this.hideRestart();
|
|
|
|
}
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
aItem.setAttribute("opType", opType);
|
|
|
|
},
|
|
|
|
|
|
|
|
uninstall: function ev_uninstall(aItem) {
|
2009-09-22 19:19:24 -07:00
|
|
|
let opType;
|
2010-05-19 19:43:02 -07:00
|
|
|
if (aItem.getAttribute("type") == "search") {
|
2009-10-20 22:15:56 -07:00
|
|
|
// Make sure the engine isn't hidden before removing it, to make sure it's
|
|
|
|
// visible if the user later re-adds it (works around bug 341833)
|
|
|
|
aItem._engine.hidden = false;
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.search.removeEngine(aItem._engine);
|
2009-09-22 19:19:24 -07:00
|
|
|
// the search-engine-modified observer in browser.js will take care of
|
|
|
|
// updating the list
|
|
|
|
} else {
|
2010-05-19 19:43:02 -07:00
|
|
|
aItem.addon.uninstall();
|
|
|
|
opType = this._getOpTypeForOperations(aItem.addon.pendingOperations);
|
2009-09-22 19:19:24 -07:00
|
|
|
|
|
|
|
if (opType == "needs-uninstall")
|
|
|
|
this.showRestart();
|
2010-07-22 12:42:40 -07:00
|
|
|
|
|
|
|
// A disabled addon doesn't need a restart so it has no pending ops and
|
|
|
|
// can't be cancelled
|
|
|
|
if (!aItem.addon.isActive && opType == "")
|
|
|
|
opType = "needs-uninstall";
|
|
|
|
|
2009-09-22 19:19:24 -07:00
|
|
|
aItem.setAttribute("opType", opType);
|
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelUninstall: function ev_cancelUninstall(aItem) {
|
2010-05-19 19:43:02 -07:00
|
|
|
aItem.addon.cancelUninstall();
|
2009-04-22 07:19:48 -07:00
|
|
|
|
|
|
|
this.hideRestart();
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
let opType = this._getOpTypeForOperations(aItem.addon.pendingOperations);
|
2009-04-22 07:19:48 -07:00
|
|
|
aItem.setAttribute("opType", opType);
|
|
|
|
},
|
|
|
|
|
|
|
|
installFromRepo: function ev_installFromRepo(aItem) {
|
2010-06-17 13:54:44 -07:00
|
|
|
aItem.install.install();
|
2010-03-29 06:01:27 -07:00
|
|
|
|
|
|
|
// display the progress bar early
|
|
|
|
let opType = aItem.getAttribute("opType");
|
|
|
|
if (!opType)
|
|
|
|
aItem.setAttribute("opType", "needs-install");
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_isSafeURI: function ev_isSafeURI(aURL) {
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
var uri = Services.io.newURI(aURL, null, null);
|
2009-04-22 07:19:48 -07:00
|
|
|
var scheme = uri.scheme;
|
|
|
|
} catch (ex) {}
|
|
|
|
return (uri && (scheme == "http" || scheme == "https" || scheme == "ftp"));
|
|
|
|
},
|
|
|
|
|
2009-04-23 14:10:54 -07:00
|
|
|
displaySectionMessage: function ev_displaySectionMessage(aSection, aMessage, aButtonLabel, aHideThrobber) {
|
2009-04-22 07:19:48 -07:00
|
|
|
let item = document.createElement("richlistitem");
|
|
|
|
item.setAttribute("typeName", "message");
|
|
|
|
item.setAttribute("message", aMessage);
|
2009-04-23 14:10:54 -07:00
|
|
|
if (aButtonLabel)
|
|
|
|
item.setAttribute("button", aButtonLabel);
|
|
|
|
else
|
|
|
|
item.setAttribute("hidebutton", "true");
|
2009-04-22 07:19:48 -07:00
|
|
|
item.setAttribute("hidethrobber", aHideThrobber);
|
2009-04-23 14:10:54 -07:00
|
|
|
|
|
|
|
if (aSection == "repo")
|
2009-06-23 09:23:48 -07:00
|
|
|
this._list.appendChild(item);
|
|
|
|
else
|
2009-09-24 17:20:34 -07:00
|
|
|
this._list.insertBefore(item, this._repoItem);
|
|
|
|
|
|
|
|
return item;
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
2009-09-24 17:20:34 -07:00
|
|
|
getAddonsFromRepo: function ev_getAddonsFromRepo(aTerms, aSelectFirstResult) {
|
2009-04-23 14:10:54 -07:00
|
|
|
this.clearSection("repo");
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
2010-06-17 13:54:44 -07:00
|
|
|
if (AddonRepository.isSearching)
|
|
|
|
AddonRepository.cancelSearch();
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2009-04-22 07:19:48 -07:00
|
|
|
if (aTerms) {
|
2009-09-24 17:20:34 -07:00
|
|
|
AddonSearchResults.selectFirstResult = aSelectFirstResult;
|
2009-04-23 14:10:54 -07:00
|
|
|
this.displaySectionMessage("repo", strings.getString("addonsSearchStart.label"),
|
2009-04-22 07:19:48 -07:00
|
|
|
strings.getString("addonsSearchStart.button"), false);
|
2010-07-13 07:36:09 -07:00
|
|
|
AddonRepository.searchAddons(aTerms, Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), AddonSearchResults);
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (RecommendedSearchResults.cache) {
|
|
|
|
this.displaySearchResults(RecommendedSearchResults.cache, -1, true);
|
|
|
|
}
|
|
|
|
else {
|
2009-04-23 14:10:54 -07:00
|
|
|
this.displaySectionMessage("repo", strings.getString("addonsSearchStart.label"),
|
2009-04-22 07:19:48 -07:00
|
|
|
strings.getString("addonsSearchStart.button"), false);
|
2010-07-13 07:36:09 -07:00
|
|
|
AddonRepository.retrieveRecommendedAddons(Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), RecommendedSearchResults);
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-24 17:20:34 -07:00
|
|
|
displaySearchResults: function ev_displaySearchResults(aAddons, aTotalResults, aIsRecommended, aSelectFirstResult) {
|
2009-04-23 14:10:54 -07:00
|
|
|
this.clearSection("repo");
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2009-04-22 07:19:48 -07:00
|
|
|
if (aAddons.length == 0) {
|
2009-10-23 22:13:13 -07:00
|
|
|
let msg = aIsRecommended ? strings.getString("addonsSearchNone.recommended") :
|
|
|
|
strings.getString("addonsSearchNone.search");
|
|
|
|
let button = aIsRecommended ? strings.getString("addonsSearchNone.button") :
|
|
|
|
strings.getString("addonsSearchSuccess2.button");
|
|
|
|
let item = this.displaySectionMessage("repo", msg, button, true);
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2009-09-24 17:20:34 -07:00
|
|
|
if (aSelectFirstResult)
|
|
|
|
this._list.scrollBoxObject.scrollToElement(item);
|
2009-04-22 07:19:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsRecommended) {
|
|
|
|
// Locale sensitive sort
|
|
|
|
function compare(a, b) {
|
|
|
|
return String.localeCompare(a.name, b.name);
|
|
|
|
}
|
|
|
|
aAddons.sort(compare);
|
|
|
|
}
|
|
|
|
|
2010-06-17 13:54:44 -07:00
|
|
|
var urlproperties = [ "iconURL", "homepageURL" ];
|
|
|
|
var properties = [ "name", "iconURL", "homepageURL", "screenshots" ];
|
2009-09-24 17:20:34 -07:00
|
|
|
var foundItem = false;
|
2009-04-22 07:19:48 -07:00
|
|
|
for (let i = 0; i < aAddons.length; i++) {
|
|
|
|
let addon = aAddons[i];
|
|
|
|
|
|
|
|
// Check for any items with potentially unsafe urls
|
|
|
|
if (urlproperties.some(function (p) !this._isSafeURI(addon[p]), this))
|
|
|
|
continue;
|
2010-06-17 13:54:44 -07:00
|
|
|
if (addon.screenshots &&
|
|
|
|
addon.screenshots.some(function (aScreenshot) !this._isSafeURI(aScreenshot), this))
|
|
|
|
continue;
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
// Convert the numeric type to a string
|
|
|
|
let types = {"2":"extension", "4":"theme", "8":"locale"};
|
|
|
|
addon.type = types[addon.type];
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
let listitem = this._createItem(addon, "search");
|
2010-06-17 13:54:44 -07:00
|
|
|
listitem.setAttribute("description", addon.description);
|
2009-05-15 14:18:38 -07:00
|
|
|
listitem.setAttribute("homepageURL", addon.homepageURL);
|
2010-06-17 13:54:44 -07:00
|
|
|
listitem.install = addon.install;
|
2010-08-23 22:19:49 -07:00
|
|
|
listitem.setAttribute("sourceURL", addon.install.sourceURI.spec);
|
2009-08-26 17:44:35 -07:00
|
|
|
if (!aIsRecommended)
|
2010-09-15 03:40:12 -07:00
|
|
|
listitem.setAttribute("rating", addon.averageRating);
|
|
|
|
|
2009-09-24 17:20:34 -07:00
|
|
|
let item = this._list.appendChild(listitem);
|
|
|
|
|
|
|
|
if (aSelectFirstResult && !foundItem) {
|
|
|
|
foundItem = true;
|
|
|
|
this._list.selectItem(item);
|
|
|
|
this._list.scrollBoxObject.scrollToElement(item);
|
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
2009-06-23 09:23:48 -07:00
|
|
|
|
2010-03-18 21:22:47 -07:00
|
|
|
let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
|
|
|
|
|
|
|
if (!aIsRecommended) {
|
|
|
|
if (aTotalResults > aAddons.length) {
|
|
|
|
let showmore = document.createElement("richlistitem");
|
|
|
|
showmore.setAttribute("typeName", "showmore");
|
2010-03-19 11:01:36 -07:00
|
|
|
|
2010-03-25 10:22:26 -07:00
|
|
|
let labelBase = strings.getString("addonsSearchMore.label");
|
|
|
|
let label = PluralForm.get(aTotalResults, labelBase).replace("#1", aTotalResults);
|
|
|
|
showmore.setAttribute("label", label);
|
2010-03-19 11:01:36 -07:00
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let url = Services.prefs.getCharPref("extensions.getAddons.search.browseURL");
|
2010-03-18 21:22:47 -07:00
|
|
|
url = url.replace(/%TERMS%/g, encodeURIComponent(this.searchBox.value));
|
|
|
|
url = formatter.formatURL(url);
|
|
|
|
showmore.setAttribute("url", url);
|
|
|
|
this._list.appendChild(showmore);
|
|
|
|
}
|
|
|
|
|
2009-10-23 22:13:13 -07:00
|
|
|
this.displaySectionMessage("repo", null, strings.getString("addonsSearchSuccess2.button"), true);
|
2010-03-18 21:22:47 -07:00
|
|
|
} else {
|
|
|
|
let showmore = document.createElement("richlistitem");
|
|
|
|
showmore.setAttribute("typeName", "showmore");
|
2010-03-25 10:22:26 -07:00
|
|
|
showmore.setAttribute("label", strings.getString("addonsBrowseAll.label"));
|
2010-03-18 21:22:47 -07:00
|
|
|
|
|
|
|
let url = formatter.formatURLPref("extensions.getAddons.browseAddons");
|
|
|
|
showmore.setAttribute("url", url);
|
|
|
|
this._list.appendChild(showmore);
|
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
2009-05-15 14:18:38 -07:00
|
|
|
showPage: function ev_showPage(aItem) {
|
|
|
|
let uri = aItem.getAttribute("homepageURL");
|
2009-09-22 15:05:20 -07:00
|
|
|
if (uri)
|
2009-06-30 11:43:45 -07:00
|
|
|
BrowserUI.newTab(uri);
|
2009-05-15 14:18:38 -07:00
|
|
|
},
|
|
|
|
|
2009-09-24 17:20:34 -07:00
|
|
|
get searchBox() {
|
|
|
|
delete this.searchBox;
|
|
|
|
return this.searchBox = document.getElementById("addons-search-text");
|
|
|
|
},
|
|
|
|
|
|
|
|
doSearch: function ev_doSearch(aTerms) {
|
|
|
|
this.searchBox.value = aTerms;
|
|
|
|
this.getAddonsFromRepo(aTerms, true);
|
|
|
|
},
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
resetSearch: function ev_resetSearch() {
|
2009-09-24 17:20:34 -07:00
|
|
|
this.searchBox.value = "";
|
2009-06-23 09:23:48 -07:00
|
|
|
this.getAddonsFromRepo("");
|
2009-09-06 18:08:06 -07:00
|
|
|
},
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2010-03-18 21:22:47 -07:00
|
|
|
showMoreResults: function ev_showMoreResults(aItem) {
|
|
|
|
let uri = aItem.getAttribute("url");
|
|
|
|
if (uri)
|
|
|
|
BrowserUI.newTab(uri);
|
|
|
|
},
|
|
|
|
|
2010-04-19 06:05:55 -07:00
|
|
|
updateAll: function ev_updateAll() {
|
|
|
|
let aus = Cc["@mozilla.org/browser/addon-update-service;1"].getService(Ci.nsITimerCallback);
|
|
|
|
aus.notify(null);
|
|
|
|
|
|
|
|
if (this._list.selectedItem)
|
|
|
|
this._list.selectedItem.focus();
|
|
|
|
},
|
|
|
|
|
2010-03-16 20:42:01 -07:00
|
|
|
observe: function ev_observe(aSubject, aTopic, aData) {
|
|
|
|
if (!document)
|
2009-09-06 18:08:06 -07:00
|
|
|
return;
|
2009-11-24 10:23:41 -08:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
let json = aSubject.QueryInterface(Ci.nsISupportsString).data;
|
2010-09-01 12:13:42 -07:00
|
|
|
let update = JSON.parse(json);
|
2010-05-19 19:43:02 -07:00
|
|
|
|
2010-03-16 20:42:01 -07:00
|
|
|
let strings = Elements.browserBundle;
|
2010-09-01 12:13:42 -07:00
|
|
|
let element = this.getElementForAddon(update.id);
|
2010-03-16 20:42:01 -07:00
|
|
|
if (!element)
|
|
|
|
return;
|
2009-09-06 18:08:06 -07:00
|
|
|
|
2010-09-01 12:13:42 -07:00
|
|
|
let addon = element.addon;
|
|
|
|
|
2010-03-16 20:42:01 -07:00
|
|
|
switch (aTopic) {
|
|
|
|
case "addon-update-started":
|
|
|
|
element.setAttribute("updateStatus", strings.getString("addonUpdate.checking"));
|
|
|
|
break;
|
|
|
|
case "addon-update-ended":
|
|
|
|
let updateable = false;
|
2010-03-25 10:22:26 -07:00
|
|
|
let statusMsg = null;
|
2010-05-19 19:43:02 -07:00
|
|
|
switch (aData) {
|
|
|
|
case "update":
|
2010-09-01 12:13:42 -07:00
|
|
|
statusMsg = strings.getFormattedString("addonUpdate.updating", [update.version]);
|
2010-03-16 20:42:01 -07:00
|
|
|
updateable = true;
|
|
|
|
break;
|
2010-05-19 19:43:02 -07:00
|
|
|
case "compatibility":
|
2010-03-16 20:42:01 -07:00
|
|
|
statusMsg = strings.getString("addonUpdate.compatibility");
|
2010-09-01 12:13:42 -07:00
|
|
|
if (addon.pendingOperations & AddonManager.PENDING_INSTALL || addon.pendingOperations & AddonManager.PENDING_UPGRADE)
|
|
|
|
updateable = true;
|
2010-03-16 20:42:01 -07:00
|
|
|
break;
|
2010-05-19 19:43:02 -07:00
|
|
|
case "error":
|
2010-03-16 20:42:01 -07:00
|
|
|
statusMsg = strings.getString("addonUpdate.error");
|
|
|
|
break;
|
2010-05-19 19:43:02 -07:00
|
|
|
case "no-update":
|
2010-03-25 10:22:26 -07:00
|
|
|
// Ignore if no updated was found. Just let the message go blank.
|
|
|
|
//statusMsg = strings.getString("addonUpdate.noupdate");
|
2010-03-16 20:42:01 -07:00
|
|
|
break;
|
|
|
|
default:
|
2010-03-25 10:22:26 -07:00
|
|
|
// Ignore if no updated was found. Just let the message go blank.
|
|
|
|
//statusMsg = strings.getString("addonUpdate.noupdate");
|
2010-03-16 20:42:01 -07:00
|
|
|
}
|
2010-03-25 10:22:26 -07:00
|
|
|
|
|
|
|
if (statusMsg)
|
|
|
|
element.setAttribute("updateStatus", statusMsg);
|
|
|
|
else
|
|
|
|
element.removeAttribute("updateStatus");
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
// Tag the add-on so the AddonInstallListener knows it's an update
|
2010-03-16 20:42:01 -07:00
|
|
|
if (updateable)
|
|
|
|
element.setAttribute("updating", "true");
|
|
|
|
break;
|
2009-09-06 18:08:06 -07:00
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
|
|
|
|
function searchFailed() {
|
|
|
|
ExtensionsView.clearSection("repo");
|
|
|
|
|
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
let brand = document.getElementById("bundle_brand");
|
|
|
|
|
|
|
|
let failLabel = strings.getFormattedString("addonsSearchFail.label",
|
|
|
|
[brand.getString("brandShortName")]);
|
|
|
|
let failButton = strings.getString("addonsSearchFail.button");
|
|
|
|
ExtensionsView.displaySectionMessage("repo", failLabel, failButton, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-06-17 13:54:44 -07:00
|
|
|
// callback for the recommended search
|
2009-04-22 07:19:48 -07:00
|
|
|
var RecommendedSearchResults = {
|
|
|
|
cache: null,
|
|
|
|
|
|
|
|
searchSucceeded: function(aAddons, aAddonCount, aTotalResults) {
|
|
|
|
this.cache = aAddons;
|
|
|
|
ExtensionsView.displaySearchResults(aAddons, aTotalResults, true);
|
|
|
|
},
|
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
searchFailed: searchFailed
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-06-17 13:54:44 -07:00
|
|
|
// callback for a standard search
|
2009-04-22 07:19:48 -07:00
|
|
|
var AddonSearchResults = {
|
2009-09-24 17:20:34 -07:00
|
|
|
// set by ExtensionsView
|
|
|
|
selectFirstResult: false,
|
|
|
|
|
2009-04-22 07:19:48 -07:00
|
|
|
searchSucceeded: function(aAddons, aAddonCount, aTotalResults) {
|
2009-09-24 17:20:34 -07:00
|
|
|
ExtensionsView.displaySearchResults(aAddons, aTotalResults, false, this.selectFirstResult);
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
searchFailed: searchFailed
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XPInstall download helper
|
2010-05-19 19:43:02 -07:00
|
|
|
function AddonInstallListener() {
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
AddonInstallListener.prototype = {
|
2010-03-25 10:22:26 -07:00
|
|
|
_updating: false,
|
2010-09-01 21:05:22 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
onInstallEnded: function(aInstall, aAddon) {
|
|
|
|
// XXX fix updating stuff
|
|
|
|
if (aAddon.pendingOperations & AddonManager.PENDING_INSTALL)
|
|
|
|
ExtensionsView.showRestart(this._updating ? "update" : "normal");
|
|
|
|
|
2010-09-01 21:05:22 -07:00
|
|
|
this._showInstallCompleteAlert(true);
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2009-06-16 12:45:00 -07:00
|
|
|
if (!ExtensionsView.visible)
|
|
|
|
return;
|
|
|
|
|
2010-08-23 22:19:49 -07:00
|
|
|
let element = ExtensionsView.getElementForAddon(aInstall.sourceURI.spec);
|
2009-04-22 07:19:48 -07:00
|
|
|
if (!element)
|
|
|
|
return;
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
element.setAttribute("opType", "needs-restart");
|
|
|
|
element.setAttribute("status", "success");
|
2010-01-15 14:14:29 -08:00
|
|
|
|
2009-09-06 18:08:06 -07:00
|
|
|
// If we are updating an add-on, change the status
|
|
|
|
if (element.hasAttribute("updating")) {
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2009-09-06 18:08:06 -07:00
|
|
|
element.setAttribute("updateStatus", strings.getFormattedString("addonUpdate.updated", [aAddon.version]));
|
|
|
|
element.removeAttribute("updating");
|
2010-03-25 10:22:26 -07:00
|
|
|
|
|
|
|
// Remember that we are updating so we can customize the restart message
|
|
|
|
this._updating = true;
|
2009-09-06 18:08:06 -07:00
|
|
|
}
|
2009-04-22 07:19:48 -07:00
|
|
|
},
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
onInstallFailed: function(aInstall, aError) {
|
2010-09-01 21:05:22 -07:00
|
|
|
this._showInstallCompleteAlert(false);
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
if (ExtensionsView.visible) {
|
2010-08-23 22:19:49 -07:00
|
|
|
let element = ExtensionsView.getElementForAddon(aInstall.sourceURI.spec);
|
2010-05-19 19:43:02 -07:00
|
|
|
if (!element)
|
|
|
|
return;
|
|
|
|
|
|
|
|
element.removeAttribute("opType");
|
2010-07-13 07:36:09 -07:00
|
|
|
let strings = Services.strings.createBundle("chrome://global/locale/xpinstall/xpinstall.properties");
|
2010-05-19 19:43:02 -07:00
|
|
|
|
|
|
|
let error = null;
|
|
|
|
switch (aError) {
|
|
|
|
case AddonManager.ERROR_NETWORK_FAILURE:
|
|
|
|
error = "error-228";
|
|
|
|
break;
|
|
|
|
case AddonManager.ERROR_INCORRECT_HASH:
|
|
|
|
error = "error-261";
|
|
|
|
break;
|
|
|
|
case AddonManager.ERROR_CORRUPT_FILE:
|
|
|
|
error = "error-207";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var msg = strings.GetStringFromName(error);
|
|
|
|
} catch (ex) {
|
|
|
|
msg = strings.formatStringFromName("unknown.error", [aError]);
|
|
|
|
}
|
|
|
|
element.setAttribute("error", msg);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadProgress: function xpidm_onDownloadProgress(aInstall) {
|
2010-08-23 22:19:49 -07:00
|
|
|
var element = ExtensionsView.getElementForAddon(aInstall.sourceURI.spec);
|
2010-05-19 19:43:02 -07:00
|
|
|
if (!element)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let opType = element.getAttribute("opType");
|
|
|
|
if (!opType)
|
|
|
|
element.setAttribute("opType", "needs-install");
|
|
|
|
|
|
|
|
let progress = Math.round((aInstall.progress / aInstall.maxProgress) * 100);
|
|
|
|
element.setAttribute("progress", progress);
|
|
|
|
},
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
onDownloadFailed: function(aInstall, aError) {
|
|
|
|
this.onInstallFailed(aInstall, aError);
|
|
|
|
},
|
|
|
|
|
2010-09-01 21:05:22 -07:00
|
|
|
onDownloadCancelled: function(aInstall, aAddon) {
|
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
let brandBundle = document.getElementById("bundle_brand");
|
|
|
|
let brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
let host = (aInstall.originatingURI instanceof Ci.nsIStandardURL) && aInstall.originatingURI.host;
|
|
|
|
if (!host)
|
|
|
|
host = (aInstall.sourceURI instanceof Ci.nsIStandardURL) && aInstall.sourceURI.host;
|
|
|
|
|
|
|
|
let error = (host || aInstall.error == 0) ? "addonError" : "addonLocalError";
|
|
|
|
if (aInstall.error != 0)
|
|
|
|
error += aInstall.error;
|
|
|
|
else if (aInstall.addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
|
|
|
|
error += "Blocklisted";
|
2010-09-09 10:06:00 -07:00
|
|
|
else if (!aInstall.addon.isCompatible)
|
2010-09-01 21:05:22 -07:00
|
|
|
error += "Incompatible";
|
2010-09-09 10:06:00 -07:00
|
|
|
else
|
|
|
|
return; // no need to show anything in this case
|
2010-09-01 21:05:22 -07:00
|
|
|
|
|
|
|
let messageString = strings.getString(error);
|
|
|
|
messageString = messageString.replace("#1", aInstall.name);
|
|
|
|
if (host)
|
|
|
|
messageString = messageString.replace("#2", host);
|
|
|
|
messageString = messageString.replace("#3", brandShortName);
|
|
|
|
messageString = messageString.replace("#4", Services.appinfo.version);
|
|
|
|
|
|
|
|
this._showAlert(messageString);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showInstallCompleteAlert: function xpidm_showAlert(aSucceeded) {
|
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
let msg = aSucceeded ? strings.getString("alertAddonsInstalled") :
|
|
|
|
strings.getString("alertAddonsFail");
|
|
|
|
this._showAlert(msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showAlert: function xpidm_showAlert(aMessage) {
|
2009-04-22 07:19:48 -07:00
|
|
|
if (ExtensionsView.visible)
|
|
|
|
return;
|
|
|
|
|
2010-05-19 19:43:02 -07:00
|
|
|
let strings = Elements.browserBundle;
|
2009-04-22 07:19:48 -07:00
|
|
|
|
2009-11-17 12:21:33 -08:00
|
|
|
let observer = {
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "alertclickcallback")
|
|
|
|
BrowserUI.showPanel("addons-container");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let alerts = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
|
2009-04-22 07:19:48 -07:00
|
|
|
alerts.showAlertNotification(URI_GENERIC_ICON_XPINSTALL, strings.getString("alertAddons"),
|
2010-09-01 21:05:22 -07:00
|
|
|
aMessage, true, "", observer, "addons");
|
2009-04-22 07:19:48 -07:00
|
|
|
}
|
|
|
|
};
|