summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/addonManager.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/mozapps/extensions/addonManager.js')
-rw-r--r--toolkit/mozapps/extensions/addonManager.js160
1 files changed, 34 insertions, 126 deletions
diff --git a/toolkit/mozapps/extensions/addonManager.js b/toolkit/mozapps/extensions/addonManager.js
index d34cbaf62..862b1ea69 100644
--- a/toolkit/mozapps/extensions/addonManager.js
+++ b/toolkit/mozapps/extensions/addonManager.js
@@ -12,6 +12,8 @@
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+const PREF_EM_UPDATE_INTERVAL = "extensions.update.interval";
+
// The old XPInstall error codes
const EXECUTION_ERROR = -203;
const CANT_READ_ARCHIVE = -207;
@@ -24,58 +26,42 @@ const MSG_INSTALL_ENABLED = "WebInstallerIsInstallEnabled";
const MSG_INSTALL_ADDONS = "WebInstallerInstallAddonsFromWebpage";
const MSG_INSTALL_CALLBACK = "WebInstallerInstallCallback";
-const MSG_PROMISE_REQUEST = "WebAPIPromiseRequest";
-const MSG_PROMISE_RESULT = "WebAPIPromiseResult";
-const MSG_INSTALL_EVENT = "WebAPIInstallEvent";
-const MSG_INSTALL_CLEANUP = "WebAPICleanup";
-const MSG_ADDON_EVENT_REQ = "WebAPIAddonEventRequest";
-const MSG_ADDON_EVENT = "WebAPIAddonEvent";
-
const CHILD_SCRIPT = "resource://gre/modules/addons/Content.js";
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
-var gSingleton = null;
+let gSingleton = null;
+
+let gParentMM = null;
+
function amManager() {
Cu.import("resource://gre/modules/AddonManager.jsm");
- /* globals AddonManagerPrivate*/
- Services.mm.loadFrameScript(CHILD_SCRIPT, true);
- Services.mm.addMessageListener(MSG_INSTALL_ENABLED, this);
- Services.mm.addMessageListener(MSG_INSTALL_ADDONS, this);
- Services.mm.addMessageListener(MSG_PROMISE_REQUEST, this);
- Services.mm.addMessageListener(MSG_INSTALL_CLEANUP, this);
- Services.mm.addMessageListener(MSG_ADDON_EVENT_REQ, this);
+ let globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
+ .getService(Ci.nsIMessageListenerManager);
+ globalMM.loadFrameScript(CHILD_SCRIPT, true);
+ globalMM.addMessageListener(MSG_INSTALL_ADDONS, this);
- Services.obs.addObserver(this, "message-manager-close", false);
- Services.obs.addObserver(this, "message-manager-disconnect", false);
-
- AddonManager.webAPI.setEventHandler(this.sendEvent);
+ gParentMM = Cc["@mozilla.org/parentprocessmessagemanager;1"]
+ .getService(Ci.nsIMessageListenerManager);
+ gParentMM.addMessageListener(MSG_INSTALL_ENABLED, this);
// Needed so receiveMessage can be called directly by JS callers
this.wrappedJSObject = this;
}
amManager.prototype = {
- observe: function(aSubject, aTopic, aData) {
- switch (aTopic) {
- case "addons-startup":
- AddonManagerPrivate.startup();
- break;
-
- case "message-manager-close":
- case "message-manager-disconnect":
- this.childClosed(aSubject);
- break;
- }
+ observe: function AMC_observe(aSubject, aTopic, aData) {
+ if (aTopic == "addons-startup")
+ AddonManagerPrivate.startup();
},
/**
* @see amIAddonManager.idl
*/
- mapURIToAddonID: function(uri, id) {
+ mapURIToAddonID: function AMC_mapURIToAddonID(uri, id) {
id.value = AddonManager.mapURIToAddonID(uri);
return !!id.value;
},
@@ -83,15 +69,19 @@ amManager.prototype = {
/**
* @see amIWebInstaller.idl
*/
- isInstallEnabled: function(aMimetype, aReferer) {
+ isInstallEnabled: function AMC_isInstallEnabled(aMimetype, aReferer) {
return AddonManager.isInstallEnabled(aMimetype);
},
/**
* @see amIWebInstaller.idl
*/
- installAddonsFromWebpage: function(aMimetype, aBrowser, aInstallingPrincipal,
- aUris, aHashes, aNames, aIcons, aCallback) {
+ installAddonsFromWebpage: function AMC_installAddonsFromWebpage(aMimetype,
+ aBrowser,
+ aInstallingPrincipal,
+ aUris, aHashes,
+ aNames, aIcons,
+ aCallback) {
if (aUris.length == 0)
return false;
@@ -108,7 +98,7 @@ amManager.prototype = {
return;
}
let uri = aUris.shift();
- AddonManager.getInstallForURL(uri, function(aInstall) {
+ AddonManager.getInstallForURL(uri, function buildNextInstall_getInstallForURL(aInstall) {
function callCallback(aUri, aStatus) {
try {
aCallback.onInstallEnded(aUri, aStatus);
@@ -122,22 +112,22 @@ amManager.prototype = {
installs.push(aInstall);
if (aCallback) {
aInstall.addListener({
- onDownloadCancelled: function(aInstall) {
+ onDownloadCancelled: function buildNextInstall_onDownloadCancelled(aInstall) {
callCallback(uri, USER_CANCELLED);
},
- onDownloadFailed: function(aInstall) {
+ onDownloadFailed: function buildNextInstall_onDownloadFailed(aInstall) {
if (aInstall.error == AddonManager.ERROR_CORRUPT_FILE)
callCallback(uri, CANT_READ_ARCHIVE);
else
callCallback(uri, DOWNLOAD_ERROR);
},
- onInstallFailed: function(aInstall) {
+ onInstallFailed: function buildNextInstall_onInstallFailed(aInstall) {
callCallback(uri, EXECUTION_ERROR);
},
- onInstallEnded: function(aInstall, aStatus) {
+ onInstallEnded: function buildNextInstall_onInstallEnded(aInstall, aStatus) {
callCallback(uri, SUCCESS);
}
});
@@ -154,49 +144,17 @@ amManager.prototype = {
return retval;
},
- notify: function(aTimer) {
+ notify: function AMC_notify(aTimer) {
AddonManagerPrivate.backgroundUpdateTimerHandler();
},
- // Maps message manager instances for content processes to the associated
- // AddonListener instances.
- addonListeners: new Map(),
-
- _addAddonListener(target) {
- if (!this.addonListeners.has(target)) {
- let handler = (event, id, needsRestart) => {
- target.sendAsyncMessage(MSG_ADDON_EVENT, {event, id, needsRestart});
- };
- let listener = {
- onEnabling: (addon, needsRestart) => handler("onEnabling", addon.id, needsRestart),
- onEnabled: (addon) => handler("onEnabled", addon.id, false),
- onDisabling: (addon, needsRestart) => handler("onDisabling", addon.id, needsRestart),
- onDisabled: (addon) => handler("onDisabled", addon.id, false),
- onInstalling: (addon, needsRestart) => handler("onInstalling", addon.id, needsRestart),
- onInstalled: (addon) => handler("onInstalled", addon.id, false),
- onUninstalling: (addon, needsRestart) => handler("onUninstalling", addon.id, needsRestart),
- onUninstalled: (addon) => handler("onUninstalled", addon.id, false),
- onOperationCancelled: (addon) => handler("onOperationCancelled", addon.id, false),
- };
- this.addonListeners.set(target, listener);
- AddonManager.addAddonListener(listener);
- }
- },
-
- _removeAddonListener(target) {
- if (this.addonListeners.has(target)) {
- AddonManager.removeAddonListener(this.addonListeners.get(target));
- this.addonListeners.delete(target);
- }
- },
-
/**
* messageManager callback function.
*
* Listens to requests from child processes for InstallTrigger
* activity, and sends back callbacks.
*/
- receiveMessage: function(aMessage) {
+ receiveMessage: function AMC_receiveMessage(aMessage) {
let payload = aMessage.data;
switch (aMessage.name) {
@@ -206,10 +164,9 @@ amManager.prototype = {
case MSG_INSTALL_ADDONS: {
let callback = null;
if (payload.callbackID != -1) {
- let mm = aMessage.target.messageManager;
callback = {
- onInstallEnded: function(url, status) {
- mm.sendAsyncMessage(MSG_INSTALL_CALLBACK, {
+ onInstallEnded: function ITP_callback(url, status) {
+ gParentMM.broadcastAsyncMessage(MSG_INSTALL_CALLBACK, {
callbackID: payload.callbackID,
url: url,
status: status
@@ -222,61 +179,12 @@ amManager.prototype = {
aMessage.target, payload.triggeringPrincipal, payload.uris,
payload.hashes, payload.names, payload.icons, callback);
}
-
- case MSG_PROMISE_REQUEST: {
- let mm = aMessage.target.messageManager;
- let resolve = (value) => {
- mm.sendAsyncMessage(MSG_PROMISE_RESULT, {
- callbackID: payload.callbackID,
- resolve: value
- });
- }
- let reject = (value) => {
- mm.sendAsyncMessage(MSG_PROMISE_RESULT, {
- callbackID: payload.callbackID,
- reject: value
- });
- }
-
- let API = AddonManager.webAPI;
- if (payload.type in API) {
- API[payload.type](aMessage.target, ...payload.args).then(resolve, reject);
- }
- else {
- reject("Unknown Add-on API request.");
- }
- break;
- }
-
- case MSG_INSTALL_CLEANUP: {
- AddonManager.webAPI.clearInstalls(payload.ids);
- break;
- }
-
- case MSG_ADDON_EVENT_REQ: {
- let target = aMessage.target.messageManager;
- if (payload.enabled) {
- this._addAddonListener(target);
- } else {
- this._removeAddonListener(target);
- }
- }
}
- return undefined;
- },
-
- childClosed(target) {
- AddonManager.webAPI.clearInstallsFrom(target);
- this._removeAddonListener(target);
- },
-
- sendEvent(mm, data) {
- mm.sendAsyncMessage(MSG_INSTALL_EVENT, data);
},
classID: Components.ID("{4399533d-08d1-458c-a87a-235f74451cfa}"),
_xpcom_factory: {
- createInstance: function(aOuter, aIid) {
+ createInstance: function AMC_createInstance(aOuter, aIid) {
if (aOuter != null)
throw Components.Exception("Component does not support aggregation",
Cr.NS_ERROR_NO_AGGREGATION);