2012-05-29 15:52:43 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2011-07-19 20:16:35 +00:00
|
|
|
"use strict";
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
2013-02-07 21:47:33 +00:00
|
|
|
const Cu = Components.utils;
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2013-10-28 04:52:00 +00:00
|
|
|
// Cannot use Services.appinfo here, or else xpcshell-tests will blow up, as
|
|
|
|
// most tests later register different nsIAppInfo implementations, which
|
|
|
|
// wouldn't be reflected in Services.appinfo anymore, as the lazy getter
|
|
|
|
// underlying it would have been initialized if we used it here.
|
|
|
|
if ("@mozilla.org/xre/app-info;1" in Cc) {
|
|
|
|
let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
|
|
|
|
if (runtime.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
|
|
|
|
// Refuse to run in child processes.
|
|
|
|
throw new Error("You cannot use the AddonManager in child processes!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-24 11:20:02 +00:00
|
|
|
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
|
2013-12-12 00:23:36 +00:00
|
|
|
const PREF_DEFAULT_PROVIDERS_ENABLED = "extensions.defaultProviders.enabled";
|
2011-05-19 18:04:44 +00:00
|
|
|
const PREF_EM_UPDATE_ENABLED = "extensions.update.enabled";
|
|
|
|
const PREF_EM_LAST_APP_VERSION = "extensions.lastAppVersion";
|
|
|
|
const PREF_EM_LAST_PLATFORM_VERSION = "extensions.lastPlatformVersion";
|
|
|
|
const PREF_EM_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault";
|
2011-11-01 05:48:45 +00:00
|
|
|
const PREF_EM_STRICT_COMPATIBILITY = "extensions.strictCompatibility";
|
2012-02-15 02:07:29 +00:00
|
|
|
const PREF_EM_CHECK_UPDATE_SECURITY = "extensions.checkUpdateSecurity";
|
2012-03-07 08:18:28 +00:00
|
|
|
const PREF_EM_UPDATE_BACKGROUND_URL = "extensions.update.background.url";
|
2011-12-16 20:04:50 +00:00
|
|
|
const PREF_APP_UPDATE_ENABLED = "app.update.enabled";
|
|
|
|
const PREF_APP_UPDATE_AUTO = "app.update.auto";
|
|
|
|
const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";
|
|
|
|
const PREF_EM_HOTFIX_LASTVERSION = "extensions.hotfix.lastVersion";
|
|
|
|
const PREF_EM_HOTFIX_URL = "extensions.hotfix.url";
|
2011-12-16 20:04:28 +00:00
|
|
|
const PREF_EM_CERT_CHECKATTRIBUTES = "extensions.hotfix.cert.checkAttributes";
|
|
|
|
const PREF_EM_HOTFIX_CERTS = "extensions.hotfix.certs.";
|
2011-12-16 20:04:50 +00:00
|
|
|
const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
|
|
|
|
const PREF_SELECTED_LOCALE = "general.useragent.locale";
|
2013-09-27 10:25:39 +00:00
|
|
|
const UNKNOWN_XPCOM_ABI = "unknownABI";
|
2011-12-16 20:04:50 +00:00
|
|
|
|
|
|
|
const UPDATE_REQUEST_VERSION = 2;
|
|
|
|
const CATEGORY_UPDATE_PARAMS = "extension-update-params";
|
2011-11-01 05:48:45 +00:00
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
const BRANCH_REGEXP = /^([^\.]+\.[0-9]+[a-z]*).*/gi;
|
|
|
|
const PREF_EM_CHECK_COMPATIBILITY_BASE = "extensions.checkCompatibility";
|
|
|
|
#ifdef MOZ_COMPATIBILITY_NIGHTLY
|
|
|
|
var PREF_EM_CHECK_COMPATIBILITY = PREF_EM_CHECK_COMPATIBILITY_BASE + ".nightly";
|
|
|
|
#else
|
|
|
|
var PREF_EM_CHECK_COMPATIBILITY;
|
|
|
|
#endif
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2011-12-02 02:28:15 +00:00
|
|
|
const TOOLKIT_ID = "toolkit@mozilla.org";
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
const VALID_TYPES_REGEXP = /^[\w\-]+$/;
|
|
|
|
|
2013-09-13 03:11:30 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/AsyncShutdown.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
|
|
|
"resource://gre/modules/Promise.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository",
|
2014-01-08 04:14:08 +00:00
|
|
|
"resource://gre/modules/addons/AddonRepository.jsm");
|
2012-05-10 02:28:45 +00:00
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "CertUtils", function certUtilsLazyGetter() {
|
2012-05-10 02:28:45 +00:00
|
|
|
let certUtils = {};
|
|
|
|
Components.utils.import("resource://gre/modules/CertUtils.jsm", certUtils);
|
|
|
|
return certUtils;
|
|
|
|
});
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = [ "AddonManager", "AddonManagerPrivate" ];
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-07-12 21:20:49 +00:00
|
|
|
const CATEGORY_PROVIDER_MODULE = "addon-provider-module";
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
// A list of providers to load by default
|
2010-07-12 21:20:49 +00:00
|
|
|
const DEFAULT_PROVIDERS = [
|
2014-01-08 04:14:08 +00:00
|
|
|
"resource://gre/modules/addons/XPIProvider.jsm",
|
2010-04-29 20:11:23 +00:00
|
|
|
"resource://gre/modules/LightweightThemeManager.jsm"
|
|
|
|
];
|
|
|
|
|
2014-02-23 17:27:59 +00:00
|
|
|
Cu.import("resource://gre/modules/Log.jsm");
|
|
|
|
// Configure a logger at the parent 'addons' level to format
|
|
|
|
// messages for all the modules under addons.*
|
|
|
|
const PARENT_LOGGER_ID = "addons";
|
|
|
|
let parentLogger = Log.repository.getLogger(PARENT_LOGGER_ID);
|
|
|
|
parentLogger.level = Log.Level.Warn;
|
|
|
|
let formatter = new Log.BasicFormatter();
|
|
|
|
// Set parent logger (and its children) to append to
|
|
|
|
// the Javascript section of the Browser Console
|
|
|
|
parentLogger.addAppender(new Log.ConsoleAppender(formatter));
|
|
|
|
// Set parent logger (and its children) to
|
|
|
|
// also append to standard out
|
|
|
|
parentLogger.addAppender(new Log.DumpAppender(formatter));
|
|
|
|
|
|
|
|
// Create a new logger (child of 'addons' logger)
|
|
|
|
// for use by the Addons Manager
|
|
|
|
const LOGGER_ID = "addons.manager";
|
|
|
|
let logger = Log.repository.getLogger(LOGGER_ID);
|
|
|
|
|
|
|
|
// Provide the ability to enable/disable logging
|
|
|
|
// messages at runtime.
|
|
|
|
// If the "extensions.logging.enabled" preference is
|
|
|
|
// missing or 'false', messages at the WARNING and higher
|
|
|
|
// severity should be logged to the JS console and standard error.
|
|
|
|
// If "extensions.logging.enabled" is set to 'true', messages
|
|
|
|
// at DEBUG and higher should go to JS console and standard error.
|
|
|
|
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
|
|
|
|
const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2014-02-23 17:27:59 +00:00
|
|
|
/**
|
|
|
|
* Preference listener which listens for a change in the
|
|
|
|
* "extensions.logging.enabled" preference and changes the logging level of the
|
|
|
|
* parent 'addons' level logger accordingly.
|
|
|
|
*/
|
|
|
|
var PrefObserver = {
|
|
|
|
init: function PrefObserver_init() {
|
|
|
|
Services.prefs.addObserver(PREF_LOGGING_ENABLED, this, false);
|
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
this.observe(null, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, PREF_LOGGING_ENABLED);
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function PrefObserver_observe(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "xpcom-shutdown") {
|
|
|
|
Services.prefs.removeObserver(PREF_LOGGING_ENABLED, this);
|
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
|
|
|
}
|
|
|
|
else if (aTopic == NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) {
|
|
|
|
let debugLogEnabled = false;
|
|
|
|
try {
|
|
|
|
debugLogEnabled = Services.prefs.getBoolPref(PREF_LOGGING_ENABLED);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
if (debugLogEnabled) {
|
|
|
|
parentLogger.level = Log.Level.Debug;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parentLogger.level = Log.Level.Warn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PrefObserver.init();
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls a callback method consuming any thrown exception. Any parameters after
|
|
|
|
* the callback parameter will be passed to the callback.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aCallback
|
|
|
|
* The callback method to call
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2012-06-20 09:12:11 +00:00
|
|
|
function safeCall(aCallback, ...aArgs) {
|
2010-04-29 20:11:23 +00:00
|
|
|
try {
|
2012-06-20 09:12:11 +00:00
|
|
|
aCallback.apply(null, aArgs);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("Exception calling callback", e);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls a method on a provider if it exists and consumes any thrown exception.
|
|
|
|
* Any parameters after the dflt parameter are passed to the provider's method.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aProvider
|
|
|
|
* The provider to call
|
|
|
|
* @param aMethod
|
|
|
|
* The method name to call
|
|
|
|
* @param aDefault
|
|
|
|
* A default return value if the provider does not implement the named
|
|
|
|
* method or throws an error.
|
|
|
|
* @return the return value from the provider or dflt if the provider does not
|
|
|
|
* implement method or throws an error
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2012-06-20 09:12:11 +00:00
|
|
|
function callProvider(aProvider, aMethod, aDefault, ...aArgs) {
|
2010-04-28 16:42:07 +00:00
|
|
|
if (!(aMethod in aProvider))
|
|
|
|
return aDefault;
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
try {
|
2012-06-20 09:12:11 +00:00
|
|
|
return aProvider[aMethod].apply(aProvider, aArgs);
|
2010-11-11 18:48:06 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.error("Exception calling provider " + aMethod, e);
|
2010-04-28 16:42:07 +00:00
|
|
|
return aDefault;
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 20:04:50 +00:00
|
|
|
/**
|
|
|
|
* Gets the currently selected locale for display.
|
|
|
|
* @return the selected locale or "en-US" if none is selected
|
|
|
|
*/
|
|
|
|
function getLocale() {
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref(PREF_MATCH_OS_LOCALE))
|
|
|
|
return Services.locale.getLocaleComponentForUserAgent();
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
try {
|
|
|
|
let locale = Services.prefs.getComplexValue(PREF_SELECTED_LOCALE,
|
|
|
|
Ci.nsIPrefLocalizedString);
|
|
|
|
if (locale)
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
try {
|
|
|
|
return Services.prefs.getCharPref(PREF_SELECTED_LOCALE);
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
return "en-US";
|
|
|
|
}
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* A helper class to repeatedly call a listener with each object in an array
|
|
|
|
* optionally checking whether the object has a method in it.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aObjects
|
|
|
|
* The array of objects to iterate through
|
|
|
|
* @param aMethod
|
|
|
|
* An optional method name, if not null any objects without this method
|
|
|
|
* will not be passed to the listener
|
|
|
|
* @param aListener
|
|
|
|
* A listener implementing nextObject and noMoreObjects methods. The
|
|
|
|
* former will be called with the AsyncObjectCaller as the first
|
|
|
|
* parameter and the object as the second. noMoreObjects will be passed
|
|
|
|
* just the AsyncObjectCaller
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
function AsyncObjectCaller(aObjects, aMethod, aListener) {
|
|
|
|
this.objects = aObjects.slice(0);
|
|
|
|
this.method = aMethod;
|
|
|
|
this.listener = aListener;
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
this.callNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
AsyncObjectCaller.prototype = {
|
|
|
|
objects: null,
|
|
|
|
method: null,
|
|
|
|
listener: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Passes the next object to the listener or calls noMoreObjects if there
|
|
|
|
* are none left.
|
|
|
|
*/
|
|
|
|
callNext: function AOC_callNext() {
|
|
|
|
if (this.objects.length == 0) {
|
|
|
|
this.listener.noMoreObjects(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let object = this.objects.shift();
|
|
|
|
if (!this.method || this.method in object)
|
|
|
|
this.listener.nextObject(this, object);
|
|
|
|
else
|
|
|
|
this.callNext();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-24 01:04:06 +00:00
|
|
|
/**
|
|
|
|
* This represents an author of an add-on (e.g. creator or developer)
|
|
|
|
*
|
|
|
|
* @param aName
|
|
|
|
* The name of the author
|
|
|
|
* @param aURL
|
|
|
|
* The URL of the author's profile page
|
|
|
|
*/
|
|
|
|
function AddonAuthor(aName, aURL) {
|
|
|
|
this.name = aName;
|
|
|
|
this.url = aURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonAuthor.prototype = {
|
|
|
|
name: null,
|
|
|
|
url: null,
|
|
|
|
|
|
|
|
// Returns the author's name, defaulting to the empty string
|
2012-10-24 09:58:00 +00:00
|
|
|
toString: function AddonAuthor_toString() {
|
2010-08-24 01:04:06 +00:00
|
|
|
return this.name || "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This represents an screenshot for an add-on
|
|
|
|
*
|
|
|
|
* @param aURL
|
|
|
|
* The URL to the full version of the screenshot
|
2011-09-05 10:26:06 +00:00
|
|
|
* @param aWidth
|
|
|
|
* The width in pixels of the screenshot
|
|
|
|
* @param aHeight
|
|
|
|
* The height in pixels of the screenshot
|
2010-08-24 01:04:06 +00:00
|
|
|
* @param aThumbnailURL
|
|
|
|
* The URL to the thumbnail version of the screenshot
|
2011-09-05 10:26:06 +00:00
|
|
|
* @param aThumbnailWidth
|
|
|
|
* The width in pixels of the thumbnail version of the screenshot
|
|
|
|
* @param aThumbnailHeight
|
|
|
|
* The height in pixels of the thumbnail version of the screenshot
|
2010-08-24 01:04:06 +00:00
|
|
|
* @param aCaption
|
|
|
|
* The caption of the screenshot
|
|
|
|
*/
|
2011-09-05 10:26:06 +00:00
|
|
|
function AddonScreenshot(aURL, aWidth, aHeight, aThumbnailURL,
|
|
|
|
aThumbnailWidth, aThumbnailHeight, aCaption) {
|
2010-08-24 01:04:06 +00:00
|
|
|
this.url = aURL;
|
2011-09-05 10:26:06 +00:00
|
|
|
if (aWidth) this.width = aWidth;
|
|
|
|
if (aHeight) this.height = aHeight;
|
|
|
|
if (aThumbnailURL) this.thumbnailURL = aThumbnailURL;
|
|
|
|
if (aThumbnailWidth) this.thumbnailWidth = aThumbnailWidth;
|
|
|
|
if (aThumbnailHeight) this.thumbnailHeight = aThumbnailHeight;
|
|
|
|
if (aCaption) this.caption = aCaption;
|
2010-08-24 01:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AddonScreenshot.prototype = {
|
|
|
|
url: null,
|
2011-09-05 10:26:06 +00:00
|
|
|
width: null,
|
|
|
|
height: null,
|
2010-08-24 01:04:06 +00:00
|
|
|
thumbnailURL: null,
|
2011-09-05 10:26:06 +00:00
|
|
|
thumbnailWidth: null,
|
|
|
|
thumbnailHeight: null,
|
2010-08-24 01:04:06 +00:00
|
|
|
caption: null,
|
|
|
|
|
|
|
|
// Returns the screenshot URL, defaulting to the empty string
|
2012-10-24 09:58:00 +00:00
|
|
|
toString: function AddonScreenshot_toString() {
|
2010-08-24 01:04:06 +00:00
|
|
|
return this.url || "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 02:28:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This represents a compatibility override for an addon.
|
|
|
|
*
|
|
|
|
* @param aType
|
|
|
|
* Overrride type - "compatible" or "incompatible"
|
|
|
|
* @param aMinVersion
|
|
|
|
* Minimum version of the addon to match
|
|
|
|
* @param aMaxVersion
|
|
|
|
* Maximum version of the addon to match
|
|
|
|
* @param aAppID
|
|
|
|
* Application ID used to match appMinVersion and appMaxVersion
|
|
|
|
* @param aAppMinVersion
|
|
|
|
* Minimum version of the application to match
|
|
|
|
* @param aAppMaxVersion
|
|
|
|
* Maximum version of the application to match
|
|
|
|
*/
|
|
|
|
function AddonCompatibilityOverride(aType, aMinVersion, aMaxVersion, aAppID,
|
|
|
|
aAppMinVersion, aAppMaxVersion) {
|
|
|
|
this.type = aType;
|
|
|
|
this.minVersion = aMinVersion;
|
|
|
|
this.maxVersion = aMaxVersion;
|
|
|
|
this.appID = aAppID;
|
|
|
|
this.appMinVersion = aAppMinVersion;
|
|
|
|
this.appMaxVersion = aAppMaxVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonCompatibilityOverride.prototype = {
|
|
|
|
/**
|
|
|
|
* Type of override - "incompatible" or "compatible".
|
|
|
|
* Only "incompatible" is supported for now.
|
|
|
|
*/
|
|
|
|
type: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Min version of the addon to match.
|
|
|
|
*/
|
|
|
|
minVersion: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Max version of the addon to match.
|
|
|
|
*/
|
|
|
|
maxVersion: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Application ID to match.
|
|
|
|
*/
|
|
|
|
appID: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Min version of the application to match.
|
|
|
|
*/
|
|
|
|
appMinVersion: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Max version of the application to match.
|
|
|
|
*/
|
|
|
|
appMaxVersion: null
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
/**
|
|
|
|
* A type of add-on, used by the UI to determine how to display different types
|
|
|
|
* of add-ons.
|
|
|
|
*
|
2012-05-30 06:34:32 +00:00
|
|
|
* @param aID
|
2011-05-20 17:36:28 +00:00
|
|
|
* The add-on type ID
|
|
|
|
* @param aLocaleURI
|
|
|
|
* The URI of a localized properties file to get the displayable name
|
|
|
|
* for the type from
|
|
|
|
* @param aLocaleKey
|
|
|
|
* The key for the string in the properties file or the actual display
|
|
|
|
* name if aLocaleURI is null. Include %ID% to include the type ID in
|
|
|
|
* the key
|
|
|
|
* @param aViewType
|
|
|
|
* The optional type of view to use in the UI
|
|
|
|
* @param aUIPriority
|
|
|
|
* The priority is used by the UI to list the types in order. Lower
|
|
|
|
* values push the type higher in the list.
|
|
|
|
* @param aFlags
|
|
|
|
* An option set of flags that customize the display of the add-on in
|
|
|
|
* the UI.
|
|
|
|
*/
|
2012-05-30 06:34:32 +00:00
|
|
|
function AddonType(aID, aLocaleURI, aLocaleKey, aViewType, aUIPriority, aFlags) {
|
|
|
|
if (!aID)
|
2012-07-30 10:46:45 +00:00
|
|
|
throw Components.Exception("An AddonType must have an ID", Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
if (aViewType && aUIPriority === undefined)
|
2012-07-30 10:46:45 +00:00
|
|
|
throw Components.Exception("An AddonType with a defined view must have a set UI priority",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
if (!aLocaleKey)
|
2012-07-30 10:46:45 +00:00
|
|
|
throw Components.Exception("An AddonType must have a displayable name",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2011-05-20 17:36:28 +00:00
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
this.id = aID;
|
2011-05-20 17:36:28 +00:00
|
|
|
this.uiPriority = aUIPriority;
|
|
|
|
this.viewType = aViewType;
|
|
|
|
this.flags = aFlags;
|
|
|
|
|
|
|
|
if (aLocaleURI) {
|
2012-10-24 09:58:00 +00:00
|
|
|
this.__defineGetter__("name", function nameGetter() {
|
2011-05-20 17:36:28 +00:00
|
|
|
delete this.name;
|
|
|
|
let bundle = Services.strings.createBundle(aLocaleURI);
|
2012-05-30 06:34:32 +00:00
|
|
|
this.name = bundle.GetStringFromName(aLocaleKey.replace("%ID%", aID));
|
2011-05-20 17:36:28 +00:00
|
|
|
return this.name;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.name = aLocaleKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 21:31:52 +00:00
|
|
|
var gStarted = false;
|
2012-05-10 18:33:02 +00:00
|
|
|
var gStartupComplete = false;
|
2012-02-15 02:07:29 +00:00
|
|
|
var gCheckCompatibility = true;
|
|
|
|
var gStrictCompatibility = true;
|
|
|
|
var gCheckUpdateSecurityDefault = true;
|
|
|
|
var gCheckUpdateSecurity = gCheckUpdateSecurityDefault;
|
|
|
|
var gUpdateEnabled = true;
|
|
|
|
var gAutoUpdateDefault = true;
|
2012-04-18 18:39:29 +00:00
|
|
|
var gHotfixID = null;
|
2010-10-12 21:31:52 +00:00
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* This is the real manager, kept here rather than in AddonManager to keep its
|
|
|
|
* contents hidden from API users.
|
|
|
|
*/
|
|
|
|
var AddonManagerInternal = {
|
2012-02-15 02:07:29 +00:00
|
|
|
managerListeners: [],
|
2010-10-12 21:31:52 +00:00
|
|
|
installListeners: [],
|
|
|
|
addonListeners: [],
|
2011-05-20 17:36:28 +00:00
|
|
|
typeListeners: [],
|
2010-04-29 20:11:23 +00:00
|
|
|
providers: [],
|
2011-05-20 17:36:28 +00:00
|
|
|
types: {},
|
2011-06-29 21:50:43 +00:00
|
|
|
startupChanges: {},
|
2013-10-11 17:13:31 +00:00
|
|
|
// Store telemetry details per addon provider
|
|
|
|
telemetryDetails: {},
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
|
|
|
|
// A read-only wrapper around the types dictionary
|
|
|
|
typesProxy: Proxy.create({
|
2012-10-24 09:58:00 +00:00
|
|
|
getOwnPropertyDescriptor: function typesProxy_getOwnPropertyDescriptor(aName) {
|
2011-05-20 17:36:28 +00:00
|
|
|
if (!(aName in AddonManagerInternal.types))
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
return {
|
|
|
|
value: AddonManagerInternal.types[aName].type,
|
|
|
|
writable: false,
|
|
|
|
configurable: false,
|
|
|
|
enumerable: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
getPropertyDescriptor: function typesProxy_getPropertyDescriptor(aName) {
|
2011-05-20 17:36:28 +00:00
|
|
|
return this.getOwnPropertyDescriptor(aName);
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
getOwnPropertyNames: function typesProxy_getOwnPropertyNames() {
|
2011-05-20 17:36:28 +00:00
|
|
|
return Object.keys(AddonManagerInternal.types);
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
getPropertyNames: function typesProxy_getPropertyNames() {
|
2011-05-20 17:36:28 +00:00
|
|
|
return this.getOwnPropertyNames();
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
delete: function typesProxy_delete(aName) {
|
2011-05-20 17:36:28 +00:00
|
|
|
// Not allowed to delete properties
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
defineProperty: function typesProxy_defineProperty(aName, aProperty) {
|
2011-05-20 17:36:28 +00:00
|
|
|
// Ignore attempts to define properties
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
fix: function typesProxy_fix(){
|
2011-05-20 17:36:28 +00:00
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Despite MDC's claims to the contrary, it is required that this trap
|
|
|
|
// be defined
|
2012-10-24 09:58:00 +00:00
|
|
|
enumerate: function typesProxy_enumerate() {
|
2011-05-20 17:36:28 +00:00
|
|
|
// All properties are enumerable
|
|
|
|
return this.getPropertyNames();
|
|
|
|
}
|
|
|
|
}),
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2013-02-07 21:47:33 +00:00
|
|
|
recordTimestamp: function AMI_recordTimestamp(name, value) {
|
|
|
|
this.TelemetryTimestamps.add(name, value);
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Initializes the AddonManager, loading any known providers and initializing
|
2010-08-24 01:04:06 +00:00
|
|
|
* them.
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
|
|
|
startup: function AMI_startup() {
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
if (gStarted)
|
|
|
|
return;
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
this.recordTimestamp("AMI_startup_begin");
|
2013-02-07 21:47:33 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
// clear this for xpcshell test restarts
|
|
|
|
for (let provider in this.telemetryDetails)
|
|
|
|
delete this.telemetryDetails[provider];
|
2013-10-11 17:13:31 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
let appChanged = undefined;
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
let oldAppVersion = null;
|
|
|
|
try {
|
|
|
|
oldAppVersion = Services.prefs.getCharPref(PREF_EM_LAST_APP_VERSION);
|
|
|
|
appChanged = Services.appinfo.version != oldAppVersion;
|
|
|
|
}
|
|
|
|
catch (e) { }
|
2011-05-19 18:04:44 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
let oldPlatformVersion = null;
|
|
|
|
try {
|
|
|
|
oldPlatformVersion = Services.prefs.getCharPref(PREF_EM_LAST_PLATFORM_VERSION);
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
if (appChanged !== false) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.debug("Application has been upgraded");
|
2014-01-09 20:00:27 +00:00
|
|
|
Services.prefs.setCharPref(PREF_EM_LAST_APP_VERSION,
|
|
|
|
Services.appinfo.version);
|
|
|
|
Services.prefs.setCharPref(PREF_EM_LAST_PLATFORM_VERSION,
|
|
|
|
Services.appinfo.platformVersion);
|
|
|
|
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION,
|
|
|
|
(appChanged === undefined ? 0 : -1));
|
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
#ifndef MOZ_COMPATIBILITY_NIGHTLY
|
2014-01-09 20:00:27 +00:00
|
|
|
PREF_EM_CHECK_COMPATIBILITY = PREF_EM_CHECK_COMPATIBILITY_BASE + "." +
|
|
|
|
Services.appinfo.version.replace(BRANCH_REGEXP, "$1");
|
2012-02-15 02:07:29 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
gCheckCompatibility = Services.prefs.getBoolPref(PREF_EM_CHECK_COMPATIBILITY);
|
|
|
|
} catch (e) {}
|
|
|
|
Services.prefs.addObserver(PREF_EM_CHECK_COMPATIBILITY, this, false);
|
2012-02-15 02:07:29 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
gStrictCompatibility = Services.prefs.getBoolPref(PREF_EM_STRICT_COMPATIBILITY);
|
|
|
|
} catch (e) {}
|
|
|
|
Services.prefs.addObserver(PREF_EM_STRICT_COMPATIBILITY, this, false);
|
2011-11-01 05:48:45 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
let defaultBranch = Services.prefs.getDefaultBranch("");
|
|
|
|
gCheckUpdateSecurityDefault = defaultBranch.getBoolPref(PREF_EM_CHECK_UPDATE_SECURITY);
|
|
|
|
} catch(e) {}
|
2012-02-15 02:07:29 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
gCheckUpdateSecurity = Services.prefs.getBoolPref(PREF_EM_CHECK_UPDATE_SECURITY);
|
|
|
|
} catch (e) {}
|
|
|
|
Services.prefs.addObserver(PREF_EM_CHECK_UPDATE_SECURITY, this, false);
|
2012-02-15 02:07:29 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
gUpdateEnabled = Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED);
|
|
|
|
} catch (e) {}
|
|
|
|
Services.prefs.addObserver(PREF_EM_UPDATE_ENABLED, this, false);
|
2012-02-15 02:07:29 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
gAutoUpdateDefault = Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT);
|
|
|
|
} catch (e) {}
|
|
|
|
Services.prefs.addObserver(PREF_EM_AUTOUPDATE_DEFAULT, this, false);
|
2012-02-15 02:07:29 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
try {
|
|
|
|
gHotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
|
|
|
|
} catch (e) {}
|
|
|
|
Services.prefs.addObserver(PREF_EM_HOTFIX_ID, this, false);
|
2012-04-18 18:39:29 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
let defaultProvidersEnabled = true;
|
|
|
|
try {
|
|
|
|
defaultProvidersEnabled = Services.prefs.getBoolPref(PREF_DEFAULT_PROVIDERS_ENABLED);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
// Ensure all default providers have had a chance to register themselves
|
|
|
|
if (defaultProvidersEnabled) {
|
|
|
|
DEFAULT_PROVIDERS.forEach(function(url) {
|
|
|
|
try {
|
|
|
|
Components.utils.import(url, {});
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
AddonManagerPrivate.recordException("AMI", "provider " + url + " load failed", e);
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.error("Exception loading default provider \"" + url + "\"", e);
|
2014-01-09 20:00:27 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load any providers registered in the category manager
|
|
|
|
let catman = Cc["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Ci.nsICategoryManager);
|
|
|
|
let entries = catman.enumerateCategory(CATEGORY_PROVIDER_MODULE);
|
|
|
|
while (entries.hasMoreElements()) {
|
|
|
|
let entry = entries.getNext().QueryInterface(Ci.nsISupportsCString).data;
|
|
|
|
let url = catman.getCategoryEntry(CATEGORY_PROVIDER_MODULE, entry);
|
2013-12-12 00:23:36 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
Components.utils.import(url, {});
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-01-09 20:00:27 +00:00
|
|
|
AddonManagerPrivate.recordException("AMI", "provider " + url + " load failed", e);
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.error("Exception loading provider " + entry + " from category \"" +
|
2014-01-09 20:00:27 +00:00
|
|
|
url + "\"", e);
|
2013-12-12 00:23:36 +00:00
|
|
|
}
|
2010-07-12 21:20:49 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
// Register our shutdown handler with the AsyncShutdown manager
|
|
|
|
AsyncShutdown.profileBeforeChange.addBlocker("AddonManager: shutting down providers",
|
|
|
|
this.shutdown.bind(this));
|
2013-09-13 03:11:30 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
// Once we start calling providers we must allow all normal methods to work.
|
|
|
|
gStarted = true;
|
2012-05-10 18:33:02 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
this.callProviders("startup", appChanged, oldAppVersion,
|
|
|
|
oldPlatformVersion);
|
2011-06-29 21:50:43 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
// If this is a new profile just pretend that there were no changes
|
|
|
|
if (appChanged === undefined) {
|
|
|
|
for (let type in this.startupChanges)
|
|
|
|
delete this.startupChanges[type];
|
|
|
|
}
|
2011-06-29 21:50:43 +00:00
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
gStartupComplete = true;
|
|
|
|
this.recordTimestamp("AMI_startup_end");
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.error("startup failed", e);
|
2014-01-09 20:00:27 +00:00
|
|
|
AddonManagerPrivate.recordException("AMI", "startup failed", e);
|
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a new AddonProvider.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aProvider
|
|
|
|
* The provider to register
|
2011-05-20 17:36:28 +00:00
|
|
|
* @param aTypes
|
2012-05-30 06:34:32 +00:00
|
|
|
* An optional array of add-on types
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2011-05-20 17:36:28 +00:00
|
|
|
registerProvider: function AMI_registerProvider(aProvider, aTypes) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aProvider || typeof aProvider != "object")
|
|
|
|
throw Components.Exception("aProvider must be specified",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
this.providers.push(aProvider);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
if (aTypes) {
|
|
|
|
aTypes.forEach(function(aType) {
|
|
|
|
if (!(aType.id in this.types)) {
|
|
|
|
if (!VALID_TYPES_REGEXP.test(aType.id)) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("Ignoring invalid type " + aType.id);
|
2011-05-20 17:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.types[aType.id] = {
|
|
|
|
type: aType,
|
|
|
|
providers: [aProvider]
|
|
|
|
};
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let typeListeners = this.typeListeners.slice(0);
|
|
|
|
for (let listener of typeListeners) {
|
2012-10-24 09:58:00 +00:00
|
|
|
safeCall(function listenerSafeCall() {
|
2012-06-01 06:12:26 +00:00
|
|
|
listener.onTypeAdded(aType);
|
2011-05-20 17:36:28 +00:00
|
|
|
});
|
2012-06-01 06:12:26 +00:00
|
|
|
}
|
2011-05-20 17:36:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.types[aType.id].providers.push(aProvider);
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
// If we're registering after startup call this provider's startup.
|
2010-10-12 21:31:52 +00:00
|
|
|
if (gStarted)
|
2010-04-28 16:42:07 +00:00
|
|
|
callProvider(aProvider, "startup");
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-06-17 03:13:54 +00:00
|
|
|
/**
|
|
|
|
* Unregisters an AddonProvider.
|
|
|
|
*
|
|
|
|
* @param aProvider
|
|
|
|
* The provider to unregister
|
|
|
|
*/
|
|
|
|
unregisterProvider: function AMI_unregisterProvider(aProvider) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aProvider || typeof aProvider != "object")
|
|
|
|
throw Components.Exception("aProvider must be specified",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-10-12 21:31:52 +00:00
|
|
|
let pos = 0;
|
|
|
|
while (pos < this.providers.length) {
|
|
|
|
if (this.providers[pos] == aProvider)
|
|
|
|
this.providers.splice(pos, 1);
|
|
|
|
else
|
|
|
|
pos++;
|
|
|
|
}
|
2010-06-17 03:13:54 +00:00
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
for (let type in this.types) {
|
2012-10-24 09:58:00 +00:00
|
|
|
this.types[type].providers = this.types[type].providers.filter(function filterProvider(p) p != aProvider);
|
2011-05-20 17:36:28 +00:00
|
|
|
if (this.types[type].providers.length == 0) {
|
|
|
|
let oldType = this.types[type].type;
|
|
|
|
delete this.types[type];
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let typeListeners = this.typeListeners.slice(0);
|
|
|
|
for (let listener of typeListeners) {
|
2012-10-24 09:58:00 +00:00
|
|
|
safeCall(function listenerSafeCall() {
|
2012-06-01 06:12:26 +00:00
|
|
|
listener.onTypeRemoved(oldType);
|
2011-05-20 17:36:28 +00:00
|
|
|
});
|
2012-06-01 06:12:26 +00:00
|
|
|
}
|
2011-05-20 17:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-17 03:13:54 +00:00
|
|
|
// If we're unregistering after startup call this provider's shutdown.
|
2010-10-12 21:31:52 +00:00
|
|
|
if (gStarted)
|
2010-06-17 03:13:54 +00:00
|
|
|
callProvider(aProvider, "shutdown");
|
|
|
|
},
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
/**
|
|
|
|
* Calls a method on all registered providers if it exists and consumes any
|
|
|
|
* thrown exception. Return values are ignored. Any parameters after the
|
|
|
|
* method parameter are passed to the provider's method.
|
|
|
|
*
|
|
|
|
* @param aMethod
|
|
|
|
* The method name to call
|
|
|
|
* @see callProvider
|
|
|
|
*/
|
|
|
|
callProviders: function AMI_callProviders(aMethod, ...aArgs) {
|
|
|
|
if (!aMethod || typeof aMethod != "string")
|
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
let providers = this.providers.slice(0);
|
|
|
|
for (let provider of providers) {
|
|
|
|
try {
|
|
|
|
if (aMethod in provider)
|
|
|
|
provider[aMethod].apply(provider, aArgs);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.error("Exception calling provider " + aMethod, e);
|
2012-06-01 06:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-13 03:11:30 +00:00
|
|
|
/**
|
|
|
|
* Calls a method on all registered providers, if the provider implements
|
|
|
|
* the method. The called method is expected to return a promise, and
|
|
|
|
* callProvidersAsync returns a promise that resolves when every provider
|
|
|
|
* method has either resolved or rejected. Rejection reasons are logged
|
|
|
|
* but otherwise ignored. Return values are ignored. Any parameters after the
|
|
|
|
* method parameter are passed to the provider's method.
|
|
|
|
*
|
|
|
|
* @param aMethod
|
|
|
|
* The method name to call
|
|
|
|
* @see callProvider
|
|
|
|
*/
|
|
|
|
callProvidersAsync: function AMI_callProviders(aMethod, ...aArgs) {
|
|
|
|
if (!aMethod || typeof aMethod != "string")
|
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
let allProviders = [];
|
|
|
|
|
|
|
|
let providers = this.providers.slice(0);
|
|
|
|
for (let provider of providers) {
|
|
|
|
try {
|
|
|
|
if (aMethod in provider) {
|
|
|
|
// Resolve a new promise with the result of the method, to handle both
|
|
|
|
// methods that return values (or nothing) and methods that return promises.
|
|
|
|
let providerResult = provider[aMethod].apply(provider, aArgs);
|
|
|
|
let nextPromise = Promise.resolve(providerResult);
|
|
|
|
// Log and swallow the errors from methods that do return promises.
|
|
|
|
nextPromise = nextPromise.then(
|
|
|
|
null,
|
2014-02-23 17:27:59 +00:00
|
|
|
e => logger.error("Exception calling provider " + aMethod, e));
|
2013-09-13 03:11:30 +00:00
|
|
|
allProviders.push(nextPromise);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.error("Exception calling provider " + aMethod, e);
|
2013-09-13 03:11:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Because we use promise.then to catch and log all errors above, Promise.all()
|
|
|
|
// will never exit early because of a rejection.
|
|
|
|
return Promise.all(allProviders);
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Shuts down the addon manager and all registered providers, this must clean
|
|
|
|
* up everything in order for automated tests to fake restarts.
|
2013-09-13 03:11:30 +00:00
|
|
|
* @return Promise{null} that resolves when all providers and dependent modules
|
|
|
|
* have finished shutting down
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2011-06-29 21:50:43 +00:00
|
|
|
shutdown: function AMI_shutdown() {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.debug("shutdown");
|
2013-09-13 03:11:30 +00:00
|
|
|
// Clean up listeners
|
2012-02-15 02:07:29 +00:00
|
|
|
Services.prefs.removeObserver(PREF_EM_CHECK_COMPATIBILITY, this);
|
2011-11-01 05:48:45 +00:00
|
|
|
Services.prefs.removeObserver(PREF_EM_STRICT_COMPATIBILITY, this);
|
2012-02-15 02:07:29 +00:00
|
|
|
Services.prefs.removeObserver(PREF_EM_CHECK_UPDATE_SECURITY, this);
|
|
|
|
Services.prefs.removeObserver(PREF_EM_UPDATE_ENABLED, this);
|
|
|
|
Services.prefs.removeObserver(PREF_EM_AUTOUPDATE_DEFAULT, this);
|
2012-04-18 18:39:29 +00:00
|
|
|
Services.prefs.removeObserver(PREF_EM_HOTFIX_ID, this);
|
2011-11-01 05:48:45 +00:00
|
|
|
|
2013-09-13 03:11:30 +00:00
|
|
|
// Only shut down providers if they've been started. Shut down
|
|
|
|
// AddonRepository after providers (if any).
|
|
|
|
let shuttingDown = null;
|
|
|
|
if (gStarted) {
|
|
|
|
shuttingDown = this.callProvidersAsync("shutdown")
|
|
|
|
.then(null,
|
2014-02-23 17:27:59 +00:00
|
|
|
err => logger.error("Failure during async provider shutdown", err))
|
2013-09-13 03:11:30 +00:00
|
|
|
.then(() => AddonRepository.shutdown());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
shuttingDown = AddonRepository.shutdown();
|
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2014-02-23 17:27:59 +00:00
|
|
|
shuttingDown.then(val => logger.debug("Async provider shutdown done"),
|
|
|
|
err => logger.error("Failure during AddonRepository shutdown", err))
|
2013-09-13 03:11:30 +00:00
|
|
|
.then(() => {
|
|
|
|
this.managerListeners.splice(0, this.managerListeners.length);
|
|
|
|
this.installListeners.splice(0, this.installListeners.length);
|
|
|
|
this.addonListeners.splice(0, this.addonListeners.length);
|
|
|
|
this.typeListeners.splice(0, this.typeListeners.length);
|
|
|
|
for (let type in this.startupChanges)
|
|
|
|
delete this.startupChanges[type];
|
|
|
|
gStarted = false;
|
|
|
|
gStartupComplete = false;
|
|
|
|
});
|
|
|
|
return shuttingDown;
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2011-11-01 05:48:45 +00:00
|
|
|
/**
|
|
|
|
* Notified when a preference we're interested in has changed.
|
|
|
|
*
|
|
|
|
* @see nsIObserver
|
|
|
|
*/
|
|
|
|
observe: function AMI_observe(aSubject, aTopic, aData) {
|
|
|
|
switch (aData) {
|
2012-02-15 02:07:29 +00:00
|
|
|
case PREF_EM_CHECK_COMPATIBILITY: {
|
|
|
|
let oldValue = gCheckCompatibility;
|
|
|
|
try {
|
|
|
|
gCheckCompatibility = Services.prefs.getBoolPref(PREF_EM_CHECK_COMPATIBILITY);
|
|
|
|
} catch(e) {
|
|
|
|
gCheckCompatibility = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.callManagerListeners("onCompatibilityModeChanged");
|
|
|
|
|
|
|
|
if (gCheckCompatibility != oldValue)
|
|
|
|
this.updateAddonAppDisabledStates();
|
|
|
|
|
|
|
|
break;
|
2011-11-01 05:48:45 +00:00
|
|
|
}
|
2012-02-15 02:07:29 +00:00
|
|
|
case PREF_EM_STRICT_COMPATIBILITY: {
|
|
|
|
let oldValue = gStrictCompatibility;
|
|
|
|
try {
|
|
|
|
gStrictCompatibility = Services.prefs.getBoolPref(PREF_EM_STRICT_COMPATIBILITY);
|
|
|
|
} catch(e) {
|
|
|
|
gStrictCompatibility = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.callManagerListeners("onCompatibilityModeChanged");
|
2011-11-01 05:48:45 +00:00
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
if (gStrictCompatibility != oldValue)
|
|
|
|
this.updateAddonAppDisabledStates();
|
2011-11-01 05:48:45 +00:00
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_EM_CHECK_UPDATE_SECURITY: {
|
|
|
|
let oldValue = gCheckUpdateSecurity;
|
|
|
|
try {
|
|
|
|
gCheckUpdateSecurity = Services.prefs.getBoolPref(PREF_EM_CHECK_UPDATE_SECURITY);
|
|
|
|
} catch(e) {
|
|
|
|
gCheckUpdateSecurity = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.callManagerListeners("onCheckUpdateSecurityChanged");
|
|
|
|
|
|
|
|
if (gCheckUpdateSecurity != oldValue)
|
|
|
|
this.updateAddonAppDisabledStates();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_EM_UPDATE_ENABLED: {
|
|
|
|
let oldValue = gUpdateEnabled;
|
|
|
|
try {
|
|
|
|
gUpdateEnabled = Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED);
|
|
|
|
} catch(e) {
|
|
|
|
gUpdateEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.callManagerListeners("onUpdateModeChanged");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_EM_AUTOUPDATE_DEFAULT: {
|
|
|
|
let oldValue = gAutoUpdateDefault;
|
|
|
|
try {
|
|
|
|
gAutoUpdateDefault = Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT);
|
|
|
|
} catch(e) {
|
|
|
|
gAutoUpdateDefault = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.callManagerListeners("onUpdateModeChanged");
|
|
|
|
break;
|
|
|
|
}
|
2012-04-18 18:39:29 +00:00
|
|
|
case PREF_EM_HOTFIX_ID: {
|
|
|
|
try {
|
|
|
|
gHotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
|
|
|
|
} catch(e) {
|
|
|
|
gHotfixID = null;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 05:48:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-16 20:04:50 +00:00
|
|
|
/**
|
|
|
|
* Replaces %...% strings in an addon url (update and updateInfo) with
|
|
|
|
* appropriate values.
|
|
|
|
*
|
|
|
|
* @param aAddon
|
2012-05-30 06:34:32 +00:00
|
|
|
* The Addon representing the add-on
|
2011-12-16 20:04:50 +00:00
|
|
|
* @param aUri
|
2012-05-30 06:34:32 +00:00
|
|
|
* The string representation of the URI to escape
|
2011-12-16 20:04:50 +00:00
|
|
|
* @param aAppVersion
|
|
|
|
* The optional application version to use for %APP_VERSION%
|
2012-05-30 06:34:32 +00:00
|
|
|
* @return The appropriately escaped URI.
|
2011-12-16 20:04:50 +00:00
|
|
|
*/
|
|
|
|
escapeAddonURI: function AMI_escapeAddonURI(aAddon, aUri, aAppVersion)
|
|
|
|
{
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aAddon || typeof aAddon != "object")
|
|
|
|
throw Components.Exception("aAddon must be an Addon object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (!aUri || typeof aUri != "string")
|
|
|
|
throw Components.Exception("aUri must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aAppVersion && typeof aAppVersion != "string")
|
|
|
|
throw Components.Exception("aAppVersion must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2011-12-16 20:04:50 +00:00
|
|
|
var addonStatus = aAddon.userDisabled || aAddon.softDisabled ? "userDisabled"
|
|
|
|
: "userEnabled";
|
|
|
|
|
|
|
|
if (!aAddon.isCompatible)
|
|
|
|
addonStatus += ",incompatible";
|
|
|
|
if (aAddon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
|
|
|
|
addonStatus += ",blocklisted";
|
|
|
|
if (aAddon.blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
|
|
|
addonStatus += ",softblocked";
|
|
|
|
|
|
|
|
try {
|
|
|
|
var xpcomABI = Services.appinfo.XPCOMABI;
|
|
|
|
} catch (ex) {
|
|
|
|
xpcomABI = UNKNOWN_XPCOM_ABI;
|
|
|
|
}
|
|
|
|
|
|
|
|
let uri = aUri.replace(/%ITEM_ID%/g, aAddon.id);
|
|
|
|
uri = uri.replace(/%ITEM_VERSION%/g, aAddon.version);
|
|
|
|
uri = uri.replace(/%ITEM_STATUS%/g, addonStatus);
|
|
|
|
uri = uri.replace(/%APP_ID%/g, Services.appinfo.ID);
|
|
|
|
uri = uri.replace(/%APP_VERSION%/g, aAppVersion ? aAppVersion :
|
|
|
|
Services.appinfo.version);
|
|
|
|
uri = uri.replace(/%REQ_VERSION%/g, UPDATE_REQUEST_VERSION);
|
|
|
|
uri = uri.replace(/%APP_OS%/g, Services.appinfo.OS);
|
|
|
|
uri = uri.replace(/%APP_ABI%/g, xpcomABI);
|
|
|
|
uri = uri.replace(/%APP_LOCALE%/g, getLocale());
|
|
|
|
uri = uri.replace(/%CURRENT_APP_VERSION%/g, Services.appinfo.version);
|
|
|
|
|
|
|
|
// Replace custom parameters (names of custom parameters must have at
|
|
|
|
// least 3 characters to prevent lookups for something like %D0%C8)
|
|
|
|
var catMan = null;
|
2012-10-24 09:58:00 +00:00
|
|
|
uri = uri.replace(/%(\w{3,})%/g, function parameterReplace(aMatch, aParam) {
|
2011-12-16 20:04:50 +00:00
|
|
|
if (!catMan) {
|
|
|
|
catMan = Cc["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Ci.nsICategoryManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var contractID = catMan.getCategoryEntry(CATEGORY_UPDATE_PARAMS, aParam);
|
|
|
|
var paramHandler = Cc[contractID].getService(Ci.nsIPropertyBag2);
|
|
|
|
return paramHandler.getPropertyAsAString(aParam);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return aMatch;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// escape() does not properly encode + symbols in any embedded FVF strings.
|
|
|
|
return uri.replace(/\+/g, "%2B");
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Performs a background update check by starting an update for all add-ons
|
|
|
|
* that can be updated.
|
|
|
|
*/
|
|
|
|
backgroundUpdateCheck: function AMI_backgroundUpdateCheck() {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-04-18 18:39:29 +00:00
|
|
|
let hotfixID = this.hotfixID;
|
2011-12-16 20:04:50 +00:00
|
|
|
|
|
|
|
let checkHotfix = hotfixID &&
|
|
|
|
Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED) &&
|
|
|
|
Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO);
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
if (!this.updateEnabled && !checkHotfix)
|
2010-04-29 20:11:23 +00:00
|
|
|
return;
|
|
|
|
|
2010-08-24 01:04:06 +00:00
|
|
|
Services.obs.notifyObservers(null, "addons-background-update-start", null);
|
2011-12-16 20:04:50 +00:00
|
|
|
|
|
|
|
// Start this from one to ensure the whole of this function completes before
|
|
|
|
// we can send the complete notification. Some parts can in some cases
|
|
|
|
// complete synchronously before later parts have a chance to increment
|
|
|
|
// pendingUpdates.
|
|
|
|
let pendingUpdates = 1;
|
2010-08-24 01:04:06 +00:00
|
|
|
|
|
|
|
function notifyComplete() {
|
2011-12-02 02:28:15 +00:00
|
|
|
if (--pendingUpdates == 0) {
|
2011-12-02 02:28:16 +00:00
|
|
|
Services.obs.notifyObservers(null,
|
|
|
|
"addons-background-update-complete",
|
|
|
|
null);
|
2011-12-02 02:28:15 +00:00
|
|
|
}
|
2010-08-24 01:04:06 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
if (this.updateEnabled) {
|
2011-12-16 20:04:50 +00:00
|
|
|
let scope = {};
|
|
|
|
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", scope);
|
|
|
|
scope.LightweightThemeManager.updateCurrentTheme();
|
|
|
|
|
|
|
|
pendingUpdates++;
|
|
|
|
this.getAllAddons(function getAddonsCallback(aAddons) {
|
|
|
|
// If there is a known hotfix then exclude it from the list of add-ons to update.
|
|
|
|
var ids = [a.id for each (a in aAddons) if (a.id != hotfixID)];
|
|
|
|
|
|
|
|
// Repopulate repository cache first, to ensure compatibility overrides
|
|
|
|
// are up to date before checking for addon updates.
|
2013-09-13 03:11:30 +00:00
|
|
|
AddonRepository.backgroundUpdateCheck(
|
2012-10-24 09:58:00 +00:00
|
|
|
ids, function BUC_backgroundUpdateCheckCallback() {
|
|
|
|
AddonManagerInternal.updateAddonRepositoryData(
|
|
|
|
function BUC_updateAddonCallback() {
|
2011-12-16 20:04:50 +00:00
|
|
|
|
|
|
|
pendingUpdates += aAddons.length;
|
|
|
|
aAddons.forEach(function BUC_forEachCallback(aAddon) {
|
|
|
|
if (aAddon.id == hotfixID) {
|
|
|
|
notifyComplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check all add-ons for updates so that any compatibility updates will
|
|
|
|
// be applied
|
|
|
|
aAddon.findUpdates({
|
|
|
|
onUpdateAvailable: function BUC_onUpdateAvailable(aAddon, aInstall) {
|
|
|
|
// Start installing updates when the add-on can be updated and
|
|
|
|
// background updates should be applied.
|
|
|
|
if (aAddon.permissions & AddonManager.PERM_CAN_UPGRADE &&
|
|
|
|
AddonManager.shouldAutoUpdate(aAddon)) {
|
|
|
|
aInstall.install();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onUpdateFinished: notifyComplete
|
|
|
|
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
|
|
|
});
|
|
|
|
|
|
|
|
notifyComplete();
|
2011-12-02 02:28:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2011-12-16 20:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (checkHotfix) {
|
|
|
|
var hotfixVersion = "";
|
|
|
|
try {
|
|
|
|
hotfixVersion = Services.prefs.getCharPref(PREF_EM_HOTFIX_LASTVERSION);
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
let url = null;
|
|
|
|
if (Services.prefs.getPrefType(PREF_EM_HOTFIX_URL) == Ci.nsIPrefBranch.PREF_STRING)
|
|
|
|
url = Services.prefs.getCharPref(PREF_EM_HOTFIX_URL);
|
|
|
|
else
|
2012-03-07 08:18:28 +00:00
|
|
|
url = Services.prefs.getCharPref(PREF_EM_UPDATE_BACKGROUND_URL);
|
2011-12-16 20:04:50 +00:00
|
|
|
|
|
|
|
// Build the URI from a fake add-on data.
|
|
|
|
url = AddonManager.escapeAddonURI({
|
|
|
|
id: hotfixID,
|
|
|
|
version: hotfixVersion,
|
|
|
|
userDisabled: false,
|
|
|
|
appDisabled: false
|
|
|
|
}, url);
|
|
|
|
|
|
|
|
pendingUpdates++;
|
2014-01-08 04:14:08 +00:00
|
|
|
Components.utils.import("resource://gre/modules/addons/AddonUpdateChecker.jsm");
|
2012-10-23 19:20:00 +00:00
|
|
|
AddonUpdateChecker.checkForUpdates(hotfixID, null, url, {
|
2012-10-24 09:58:00 +00:00
|
|
|
onUpdateCheckComplete: function BUC_onUpdateCheckComplete(aUpdates) {
|
2011-12-16 20:04:50 +00:00
|
|
|
let update = AddonUpdateChecker.getNewestCompatibleUpdate(aUpdates);
|
|
|
|
if (!update) {
|
|
|
|
notifyComplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the available version isn't newer than the last installed
|
|
|
|
// version then ignore it.
|
|
|
|
if (Services.vc.compare(hotfixVersion, update.version) >= 0) {
|
|
|
|
notifyComplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.debug("Downloading hotfix version " + update.version);
|
2012-10-24 09:58:00 +00:00
|
|
|
AddonManager.getInstallForURL(update.updateURL,
|
|
|
|
function BUC_getInstallForURL(aInstall) {
|
2011-12-16 20:04:50 +00:00
|
|
|
aInstall.addListener({
|
2012-10-24 09:58:00 +00:00
|
|
|
onDownloadEnded: function BUC_onDownloadEnded(aInstall) {
|
2011-12-16 20:04:28 +00:00
|
|
|
try {
|
|
|
|
if (!Services.prefs.getBoolPref(PREF_EM_CERT_CHECKATTRIBUTES))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// By default don't do certificate checks.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
CertUtils.validateCert(aInstall.certificate,
|
|
|
|
CertUtils.readCertPrefs(PREF_EM_HOTFIX_CERTS));
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("The hotfix add-on was not signed by the expected " +
|
2011-12-16 20:04:28 +00:00
|
|
|
"certificate and so will not be installed.");
|
|
|
|
aInstall.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
onInstallEnded: function BUC_onInstallEnded(aInstall) {
|
2011-12-16 20:04:50 +00:00
|
|
|
// Remember the last successfully installed version.
|
|
|
|
Services.prefs.setCharPref(PREF_EM_HOTFIX_LASTVERSION,
|
|
|
|
aInstall.version);
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
onInstallCancelled: function BUC_onInstallCancelled(aInstall) {
|
2011-12-16 20:04:50 +00:00
|
|
|
// Revert to the previous version if the installation was
|
|
|
|
// cancelled.
|
|
|
|
Services.prefs.setCharPref(PREF_EM_HOTFIX_LASTVERSION,
|
|
|
|
hotfixVersion);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
aInstall.install();
|
|
|
|
|
|
|
|
notifyComplete();
|
|
|
|
}, "application/x-xpinstall", update.updateHash, null,
|
|
|
|
null, update.version);
|
|
|
|
},
|
|
|
|
|
|
|
|
onUpdateCheckError: notifyComplete
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyComplete();
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2011-06-29 21:50:43 +00:00
|
|
|
/**
|
|
|
|
* Adds a add-on to the list of detected changes for this startup. If
|
|
|
|
* addStartupChange is called multiple times for the same add-on in the same
|
|
|
|
* startup then only the most recent change will be remembered.
|
|
|
|
*
|
|
|
|
* @param aType
|
|
|
|
* The type of change as a string. Providers can define their own
|
|
|
|
* types of changes or use the existing defined STARTUP_CHANGE_*
|
|
|
|
* constants
|
|
|
|
* @param aID
|
|
|
|
* The ID of the add-on
|
|
|
|
*/
|
|
|
|
addStartupChange: function AMI_addStartupChange(aType, aID) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aType || typeof aType != "string")
|
|
|
|
throw Components.Exception("aType must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (!aID || typeof aID != "string")
|
|
|
|
throw Components.Exception("aID must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-05-10 18:33:02 +00:00
|
|
|
if (gStartupComplete)
|
2011-06-29 21:50:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Ensure that an ID is only listed in one type of change
|
|
|
|
for (let type in this.startupChanges)
|
|
|
|
this.removeStartupChange(type, aID);
|
|
|
|
|
|
|
|
if (!(aType in this.startupChanges))
|
|
|
|
this.startupChanges[aType] = [];
|
|
|
|
this.startupChanges[aType].push(aID);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a startup change for an add-on.
|
|
|
|
*
|
|
|
|
* @param aType
|
|
|
|
* The type of change
|
|
|
|
* @param aID
|
|
|
|
* The ID of the add-on
|
|
|
|
*/
|
|
|
|
removeStartupChange: function AMI_removeStartupChange(aType, aID) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aType || typeof aType != "string")
|
|
|
|
throw Components.Exception("aType must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (!aID || typeof aID != "string")
|
|
|
|
throw Components.Exception("aID must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-05-10 18:33:02 +00:00
|
|
|
if (gStartupComplete)
|
2011-06-29 21:50:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(aType in this.startupChanges))
|
|
|
|
return;
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
this.startupChanges[aType] = this.startupChanges[aType].filter(
|
|
|
|
function filterItem(aItem) aItem != aID);
|
2011-06-29 21:50:43 +00:00
|
|
|
},
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
/**
|
|
|
|
* Calls all registered AddonManagerListeners with an event. Any parameters
|
|
|
|
* after the method parameter are passed to the listener.
|
|
|
|
*
|
|
|
|
* @param aMethod
|
|
|
|
* The method on the listeners to call
|
|
|
|
*/
|
2012-06-20 09:12:11 +00:00
|
|
|
callManagerListeners: function AMI_callManagerListeners(aMethod, ...aArgs) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
2012-05-30 06:34:32 +00:00
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let managerListeners = this.managerListeners.slice(0);
|
|
|
|
for (let listener of managerListeners) {
|
2012-02-15 02:07:29 +00:00
|
|
|
try {
|
|
|
|
if (aMethod in listener)
|
2012-06-20 09:12:11 +00:00
|
|
|
listener[aMethod].apply(listener, aArgs);
|
2012-02-15 02:07:29 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("AddonManagerListener threw exception when calling " + aMethod, e);
|
2012-02-15 02:07:29 +00:00
|
|
|
}
|
2012-06-01 06:12:26 +00:00
|
|
|
}
|
2012-02-15 02:07:29 +00:00
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Calls all registered InstallListeners with an event. Any parameters after
|
|
|
|
* the extraListeners parameter are passed to the listener.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aMethod
|
|
|
|
* The method on the listeners to call
|
|
|
|
* @param aExtraListeners
|
2012-05-30 06:34:32 +00:00
|
|
|
* An optional array of extra InstallListeners to also call
|
2010-04-28 16:42:07 +00:00
|
|
|
* @return false if any of the listeners returned false, true otherwise
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2013-09-13 03:11:30 +00:00
|
|
|
callInstallListeners: function AMI_callInstallListeners(aMethod,
|
2012-10-24 09:58:00 +00:00
|
|
|
aExtraListeners, ...aArgs) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
2012-05-30 06:34:32 +00:00
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aExtraListeners && !Array.isArray(aExtraListeners))
|
|
|
|
throw Components.Exception("aExtraListeners must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
let result = true;
|
2012-06-01 06:12:26 +00:00
|
|
|
let listeners;
|
2010-04-28 16:42:07 +00:00
|
|
|
if (aExtraListeners)
|
2012-06-01 06:12:26 +00:00
|
|
|
listeners = aExtraListeners.concat(this.installListeners);
|
|
|
|
else
|
|
|
|
listeners = this.installListeners.slice(0);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
for (let listener of listeners) {
|
2010-04-29 20:11:23 +00:00
|
|
|
try {
|
2010-04-28 16:42:07 +00:00
|
|
|
if (aMethod in listener) {
|
2012-06-20 09:12:11 +00:00
|
|
|
if (listener[aMethod].apply(listener, aArgs) === false)
|
2010-04-29 20:11:23 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("InstallListener threw exception when calling " + aMethod, e);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
2012-06-01 06:12:26 +00:00
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls all registered AddonListeners with an event. Any parameters after
|
|
|
|
* the method parameter are passed to the listener.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aMethod
|
|
|
|
* The method on the listeners to call
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2012-06-20 09:12:11 +00:00
|
|
|
callAddonListeners: function AMI_callAddonListeners(aMethod, ...aArgs) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
2012-05-30 06:34:32 +00:00
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let addonListeners = this.addonListeners.slice(0);
|
|
|
|
for (let listener of addonListeners) {
|
2010-04-29 20:11:23 +00:00
|
|
|
try {
|
2010-04-28 16:42:07 +00:00
|
|
|
if (aMethod in listener)
|
2012-06-20 09:12:11 +00:00
|
|
|
listener[aMethod].apply(listener, aArgs);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("AddonListener threw exception when calling " + aMethod, e);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
2012-06-01 06:12:26 +00:00
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies all providers that an add-on has been enabled when that type of
|
|
|
|
* add-on only supports a single add-on being enabled at a time. This allows
|
|
|
|
* the providers to disable theirs if necessary.
|
|
|
|
*
|
2012-05-30 06:34:32 +00:00
|
|
|
* @param aID
|
|
|
|
* The ID of the enabled add-on
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aType
|
|
|
|
* The type of the enabled add-on
|
|
|
|
* @param aPendingRestart
|
|
|
|
* A boolean indicating if the change will only take place the next
|
|
|
|
* time the application is restarted
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2012-05-30 06:34:32 +00:00
|
|
|
notifyAddonChanged: function AMI_notifyAddonChanged(aID, aType, aPendingRestart) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (aID && typeof aID != "string")
|
|
|
|
throw Components.Exception("aID must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (!aType || typeof aType != "string")
|
|
|
|
throw Components.Exception("aType must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
this.callProviders("addonChanged", aID, aType, aPendingRestart);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
/**
|
|
|
|
* Notifies all providers they need to update the appDisabled property for
|
|
|
|
* their add-ons in response to an application change such as a blocklist
|
|
|
|
* update.
|
|
|
|
*/
|
|
|
|
updateAddonAppDisabledStates: function AMI_updateAddonAppDisabledStates() {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
this.callProviders("updateAddonAppDisabledStates");
|
2010-04-26 18:45:22 +00:00
|
|
|
},
|
2013-09-13 03:11:30 +00:00
|
|
|
|
2011-12-02 02:28:15 +00:00
|
|
|
/**
|
|
|
|
* Notifies all providers that the repository has updated its data for
|
|
|
|
* installed add-ons.
|
|
|
|
*
|
|
|
|
* @param aCallback
|
|
|
|
* Function to call when operation is complete.
|
|
|
|
*/
|
|
|
|
updateAddonRepositoryData: function AMI_updateAddonRepositoryData(aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
2011-12-02 02:28:15 +00:00
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2011-12-02 02:28:15 +00:00
|
|
|
new AsyncObjectCaller(this.providers, "updateAddonRepositoryData", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function updateAddonRepositoryData_nextObject(aCaller, aProvider) {
|
2011-12-02 02:28:15 +00:00
|
|
|
callProvider(aProvider,
|
|
|
|
"updateAddonRepositoryData",
|
|
|
|
null,
|
|
|
|
aCaller.callNext.bind(aCaller));
|
|
|
|
},
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function updateAddonRepositoryData_noMoreObjects(aCaller) {
|
2011-12-02 02:28:15 +00:00
|
|
|
safeCall(aCallback);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-05-30 06:34:32 +00:00
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously gets an AddonInstall for a URL.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aUrl
|
2012-05-30 06:34:32 +00:00
|
|
|
* The string represenation of the URL the add-on is located at
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aCallback
|
|
|
|
* A callback to pass the AddonInstall to
|
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype of the add-on
|
|
|
|
* @param aHash
|
|
|
|
* An optional hash of the add-on
|
|
|
|
* @param aName
|
|
|
|
* An optional placeholder name while the add-on is being downloaded
|
2012-08-23 06:49:29 +00:00
|
|
|
* @param aIcons
|
|
|
|
* Optional placeholder icons while the add-on is being downloaded
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aVersion
|
|
|
|
* An optional placeholder version while the add-on is being downloaded
|
|
|
|
* @param aLoadGroup
|
|
|
|
* An optional nsILoadGroup to associate any network requests with
|
|
|
|
* @throws if the aUrl, aCallback or aMimetype arguments are not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
getInstallForURL: function AMI_getInstallForURL(aUrl, aCallback, aMimetype,
|
2012-08-23 06:49:29 +00:00
|
|
|
aHash, aName, aIcons,
|
2010-04-28 16:42:07 +00:00
|
|
|
aVersion, aLoadGroup) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aUrl || typeof aUrl != "string")
|
|
|
|
throw Components.Exception("aURL must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aHash && typeof aHash != "string")
|
|
|
|
throw Components.Exception("aHash must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aName && typeof aName != "string")
|
|
|
|
throw Components.Exception("aName must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-08-23 06:49:29 +00:00
|
|
|
if (aIcons) {
|
|
|
|
if (typeof aIcons == "string")
|
|
|
|
aIcons = { "32": aIcons };
|
|
|
|
else if (typeof aIcons != "object")
|
|
|
|
throw Components.Exception("aIcons must be a string, an object or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
} else {
|
|
|
|
aIcons = {};
|
|
|
|
}
|
2012-05-30 06:34:32 +00:00
|
|
|
|
|
|
|
if (aVersion && typeof aVersion != "string")
|
|
|
|
throw Components.Exception("aVersion must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aLoadGroup && (!(aLoadGroup instanceof Ci.nsILoadGroup)))
|
|
|
|
throw Components.Exception("aLoadGroup must be a nsILoadGroup or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let providers = this.providers.slice(0);
|
|
|
|
for (let provider of providers) {
|
2012-05-27 12:21:48 +00:00
|
|
|
if (callProvider(provider, "supportsMimetype", false, aMimetype)) {
|
|
|
|
callProvider(provider, "getInstallForURL", null,
|
2012-08-23 06:49:29 +00:00
|
|
|
aUrl, aHash, aName, aIcons, aVersion, aLoadGroup,
|
2012-10-24 09:58:00 +00:00
|
|
|
function getInstallForURL_safeCall(aInstall) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, aInstall);
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, null);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets an AddonInstall for an nsIFile.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aFile
|
2012-05-30 06:34:32 +00:00
|
|
|
* The nsIFile where the add-on is located
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aCallback
|
|
|
|
* A callback to pass the AddonInstall to
|
|
|
|
* @param aMimetype
|
|
|
|
* An optional mimetype hint for the add-on
|
|
|
|
* @throws if the aFile or aCallback arguments are not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
getInstallForFile: function AMI_getInstallForFile(aFile, aCallback, aMimetype) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!(aFile instanceof Ci.nsIFile))
|
|
|
|
throw Components.Exception("aFile must be a nsIFile",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aMimetype && typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
new AsyncObjectCaller(this.providers, "getInstallForFile", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getInstallForFile_nextObject(aCaller, aProvider) {
|
2010-04-28 16:42:07 +00:00
|
|
|
callProvider(aProvider, "getInstallForFile", null, aFile,
|
2012-10-24 09:58:00 +00:00
|
|
|
function getInstallForFile_safeCall(aInstall) {
|
2010-04-28 16:42:07 +00:00
|
|
|
if (aInstall)
|
|
|
|
safeCall(aCallback, aInstall);
|
2010-04-29 20:11:23 +00:00
|
|
|
else
|
2010-04-28 16:42:07 +00:00
|
|
|
aCaller.callNext();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getInstallForFile_noMoreObjects(aCaller) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, null);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets all current AddonInstalls optionally limiting to a list
|
|
|
|
* of types.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aTypes
|
|
|
|
* An optional array of types to retrieve. Each type is a string name
|
|
|
|
* @param aCallback
|
|
|
|
* A callback which will be passed an array of AddonInstalls
|
2012-05-30 06:34:32 +00:00
|
|
|
* @throws If the aCallback argument is not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-26 17:49:19 +00:00
|
|
|
getInstallsByTypes: function AMI_getInstallsByTypes(aTypes, aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
let installs = [];
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
new AsyncObjectCaller(this.providers, "getInstallsByTypes", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getInstallsByTypes_nextObject(aCaller, aProvider) {
|
2010-04-26 17:49:19 +00:00
|
|
|
callProvider(aProvider, "getInstallsByTypes", null, aTypes,
|
2012-10-24 09:58:00 +00:00
|
|
|
function getInstallsByTypes_safeCall(aProviderInstalls) {
|
2010-04-28 16:42:07 +00:00
|
|
|
installs = installs.concat(aProviderInstalls);
|
|
|
|
aCaller.callNext();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getInstallsByTypes_noMoreObjects(aCaller) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, installs);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously gets all current AddonInstalls.
|
|
|
|
*
|
|
|
|
* @param aCallback
|
|
|
|
* A callback which will be passed an array of AddonInstalls
|
|
|
|
*/
|
|
|
|
getAllInstalls: function AMI_getAllInstalls(aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
this.getInstallsByTypes(null, aCallback);
|
|
|
|
},
|
|
|
|
|
2013-06-15 02:48:06 +00:00
|
|
|
/**
|
|
|
|
* Synchronously map a URI to the corresponding Addon ID.
|
|
|
|
*
|
|
|
|
* Mappable URIs are limited to in-application resources belonging to the
|
|
|
|
* add-on, such as Javascript compartments, XUL windows, XBL bindings, etc.
|
|
|
|
* but do not include URIs from meta data, such as the add-on homepage.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* nsIURI to map to an addon id
|
|
|
|
* @return string containing the Addon ID or null
|
|
|
|
* @see amIAddonManager.mapURIToAddonID
|
|
|
|
*/
|
|
|
|
mapURIToAddonID: function AMI_mapURIToAddonID(aURI) {
|
|
|
|
if (!(aURI instanceof Ci.nsIURI)) {
|
|
|
|
throw Components.Exception("aURI is not a nsIURI",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
// Try all providers
|
|
|
|
let providers = this.providers.slice(0);
|
|
|
|
for (let provider of providers) {
|
|
|
|
var id = callProvider(provider, "mapURIToAddonID", null, aURI);
|
|
|
|
if (id !== null) {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Checks whether installation is enabled for a particular mimetype.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype to check
|
|
|
|
* @return true if installation is enabled for the mimetype
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
isInstallEnabled: function AMI_isInstallEnabled(aMimetype) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let providers = this.providers.slice(0);
|
|
|
|
for (let provider of providers) {
|
2012-05-27 12:21:48 +00:00
|
|
|
if (callProvider(provider, "supportsMimetype", false, aMimetype) &&
|
|
|
|
callProvider(provider, "isInstallEnabled"))
|
2010-04-29 20:11:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a particular source is allowed to install add-ons of a
|
|
|
|
* given mimetype.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype of the add-on
|
|
|
|
* @param aURI
|
2012-05-30 06:34:32 +00:00
|
|
|
* The optional nsIURI of the source
|
2010-04-28 16:42:07 +00:00
|
|
|
* @return true if the source is allowed to install this mimetype
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
isInstallAllowed: function AMI_isInstallAllowed(aMimetype, aURI) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aURI && !(aURI instanceof Ci.nsIURI))
|
|
|
|
throw Components.Exception("aURI must be a nsIURI or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-06-01 06:12:26 +00:00
|
|
|
let providers = this.providers.slice(0);
|
|
|
|
for (let provider of providers) {
|
2012-05-27 12:21:48 +00:00
|
|
|
if (callProvider(provider, "supportsMimetype", false, aMimetype) &&
|
|
|
|
callProvider(provider, "isInstallAllowed", null, aURI))
|
2010-04-29 20:11:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-04-26 19:19:18 +00:00
|
|
|
return false;
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts installation of an array of AddonInstalls notifying the registered
|
|
|
|
* web install listener of blocked or started installs.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype of add-ons being installed
|
|
|
|
* @param aSource
|
2012-05-30 06:34:32 +00:00
|
|
|
* The optional nsIDOMWindow that started the installs
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aURI
|
2012-05-30 06:34:32 +00:00
|
|
|
* The optional nsIURI that started the installs
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aInstalls
|
|
|
|
* The array of AddonInstalls to be installed
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
installAddonsFromWebpage: function AMI_installAddonsFromWebpage(aMimetype,
|
|
|
|
aSource,
|
|
|
|
aURI,
|
|
|
|
aInstalls) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aSource && !(aSource instanceof Ci.nsIDOMWindow))
|
|
|
|
throw Components.Exception("aSource must be a nsIDOMWindow or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (aURI && !(aURI instanceof Ci.nsIURI))
|
|
|
|
throw Components.Exception("aURI must be a nsIURI or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (!Array.isArray(aInstalls))
|
|
|
|
throw Components.Exception("aInstalls must be an array",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
if (!("@mozilla.org/addons/web-install-listener;1" in Cc)) {
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("No web installer available, cancelling all installs");
|
2010-04-28 16:42:07 +00:00
|
|
|
aInstalls.forEach(function(aInstall) {
|
|
|
|
aInstall.cancel();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let weblistener = Cc["@mozilla.org/addons/web-install-listener;1"].
|
|
|
|
getService(Ci.amIWebInstallListener);
|
|
|
|
|
2010-11-24 20:37:28 +00:00
|
|
|
if (!this.isInstallEnabled(aMimetype, aURI)) {
|
|
|
|
weblistener.onWebInstallDisabled(aSource, aURI, aInstalls,
|
|
|
|
aInstalls.length);
|
|
|
|
}
|
|
|
|
else if (!this.isInstallAllowed(aMimetype, aURI)) {
|
2010-04-28 16:42:07 +00:00
|
|
|
if (weblistener.onWebInstallBlocked(aSource, aURI, aInstalls,
|
|
|
|
aInstalls.length)) {
|
|
|
|
aInstalls.forEach(function(aInstall) {
|
|
|
|
aInstall.install();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2010-04-28 16:42:07 +00:00
|
|
|
else if (weblistener.onWebInstallRequested(aSource, aURI, aInstalls,
|
|
|
|
aInstalls.length)) {
|
|
|
|
aInstalls.forEach(function(aInstall) {
|
|
|
|
aInstall.install();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2014-01-09 20:00:27 +00:00
|
|
|
// In the event that the weblistener throws during instantiation or when
|
2010-04-29 20:11:23 +00:00
|
|
|
// calling onWebInstallBlocked or onWebInstallRequested all of the
|
|
|
|
// installs should get cancelled.
|
2014-02-23 17:27:59 +00:00
|
|
|
logger.warn("Failure calling web installer", e);
|
2010-04-28 16:42:07 +00:00
|
|
|
aInstalls.forEach(function(aInstall) {
|
|
|
|
aInstall.cancel();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new InstallListener if the listener is not already registered.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aListener
|
|
|
|
* The InstallListener to add
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
addInstallListener: function AMI_addInstallListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a InstallListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2013-09-13 03:11:30 +00:00
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
if (!this.installListeners.some(function addInstallListener_matchListener(i) {
|
|
|
|
return i == aListener; }))
|
2010-04-28 16:42:07 +00:00
|
|
|
this.installListeners.push(aListener);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an InstallListener if the listener is registered.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aListener
|
|
|
|
* The InstallListener to remove
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
removeInstallListener: function AMI_removeInstallListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a InstallListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-10-12 21:31:52 +00:00
|
|
|
let pos = 0;
|
|
|
|
while (pos < this.installListeners.length) {
|
|
|
|
if (this.installListeners[pos] == aListener)
|
|
|
|
this.installListeners.splice(pos, 1);
|
|
|
|
else
|
|
|
|
pos++;
|
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets an add-on with a specific ID.
|
|
|
|
*
|
2012-05-30 06:34:32 +00:00
|
|
|
* @param aID
|
2010-04-28 16:42:07 +00:00
|
|
|
* The ID of the add-on to retrieve
|
|
|
|
* @param aCallback
|
|
|
|
* The callback to pass the retrieved add-on to
|
2012-05-30 06:34:32 +00:00
|
|
|
* @throws if the aID or aCallback arguments are not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2012-05-30 06:34:32 +00:00
|
|
|
getAddonByID: function AMI_getAddonByID(aID, aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aID || typeof aID != "string")
|
|
|
|
throw Components.Exception("aID must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
new AsyncObjectCaller(this.providers, "getAddonByID", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getAddonByID_nextObject(aCaller, aProvider) {
|
|
|
|
callProvider(aProvider, "getAddonByID", null, aID,
|
|
|
|
function getAddonByID_safeCall(aAddon) {
|
2010-04-28 16:42:07 +00:00
|
|
|
if (aAddon)
|
|
|
|
safeCall(aCallback, aAddon);
|
2010-04-29 20:11:23 +00:00
|
|
|
else
|
2010-04-28 16:42:07 +00:00
|
|
|
aCaller.callNext();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getAddonByID_noMoreObjects(aCaller) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, null);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-11-05 01:04:15 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously get an add-on with a specific Sync GUID.
|
|
|
|
*
|
|
|
|
* @param aGUID
|
|
|
|
* String GUID of add-on to retrieve
|
|
|
|
* @param aCallback
|
|
|
|
* The callback to pass the retrieved add-on to.
|
|
|
|
* @throws if the aGUID or aCallback arguments are not specified
|
|
|
|
*/
|
|
|
|
getAddonBySyncGUID: function AMI_getAddonBySyncGUID(aGUID, aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aGUID || typeof aGUID != "string")
|
|
|
|
throw Components.Exception("aGUID must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2011-11-05 01:04:15 +00:00
|
|
|
|
|
|
|
new AsyncObjectCaller(this.providers, "getAddonBySyncGUID", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getAddonBySyncGUID_nextObject(aCaller, aProvider) {
|
|
|
|
callProvider(aProvider, "getAddonBySyncGUID", null, aGUID,
|
|
|
|
function getAddonBySyncGUID_safeCall(aAddon) {
|
2011-11-05 01:04:15 +00:00
|
|
|
if (aAddon) {
|
|
|
|
safeCall(aCallback, aAddon);
|
|
|
|
} else {
|
|
|
|
aCaller.callNext();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getAddonBySyncGUID_noMoreObjects(aCaller) {
|
2011-11-05 01:04:15 +00:00
|
|
|
safeCall(aCallback, null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously gets an array of add-ons.
|
|
|
|
*
|
2012-05-30 06:34:32 +00:00
|
|
|
* @param aIDs
|
2010-04-28 16:42:07 +00:00
|
|
|
* The array of IDs to retrieve
|
|
|
|
* @param aCallback
|
|
|
|
* The callback to pass an array of Addons to
|
2012-05-30 06:34:32 +00:00
|
|
|
* @throws if the aID or aCallback arguments are not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2012-05-30 06:34:32 +00:00
|
|
|
getAddonsByIDs: function AMI_getAddonsByIDs(aIDs, aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!Array.isArray(aIDs))
|
|
|
|
throw Components.Exception("aIDs must be an array",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
let addons = [];
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
new AsyncObjectCaller(aIDs, null, {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getAddonsByIDs_nextObject(aCaller, aID) {
|
2013-09-13 03:11:30 +00:00
|
|
|
AddonManagerInternal.getAddonByID(aID,
|
2012-10-24 09:58:00 +00:00
|
|
|
function getAddonsByIDs_getAddonByID(aAddon) {
|
2010-04-28 16:42:07 +00:00
|
|
|
addons.push(aAddon);
|
|
|
|
aCaller.callNext();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getAddonsByIDs_noMoreObjects(aCaller) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, addons);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets add-ons of specific types.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aTypes
|
|
|
|
* An optional array of types to retrieve. Each type is a string name
|
|
|
|
* @param aCallback
|
|
|
|
* The callback to pass an array of Addons to.
|
|
|
|
* @throws if the aCallback argument is not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
getAddonsByTypes: function AMI_getAddonsByTypes(aTypes, aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
let addons = [];
|
|
|
|
|
|
|
|
new AsyncObjectCaller(this.providers, "getAddonsByTypes", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getAddonsByTypes_nextObject(aCaller, aProvider) {
|
2010-04-28 16:42:07 +00:00
|
|
|
callProvider(aProvider, "getAddonsByTypes", null, aTypes,
|
2012-10-24 09:58:00 +00:00
|
|
|
function getAddonsByTypes_concatAddons(aProviderAddons) {
|
2010-04-28 16:42:07 +00:00
|
|
|
addons = addons.concat(aProviderAddons);
|
|
|
|
aCaller.callNext();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getAddonsByTypes_noMoreObjects(aCaller) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, addons);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously gets all installed add-ons.
|
|
|
|
*
|
|
|
|
* @param aCallback
|
|
|
|
* A callback which will be passed an array of Addons
|
|
|
|
*/
|
|
|
|
getAllAddons: function AMI_getAllAddons(aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
this.getAddonsByTypes(null, aCallback);
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously gets add-ons that have operations waiting for an application
|
|
|
|
* restart to complete.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aTypes
|
|
|
|
* An optional array of types to retrieve. Each type is a string name
|
|
|
|
* @param aCallback
|
|
|
|
* The callback to pass the array of Addons to
|
|
|
|
* @throws if the aCallback argument is not specified
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-26 17:49:19 +00:00
|
|
|
getAddonsWithOperationsByTypes:
|
|
|
|
function AMI_getAddonsWithOperationsByTypes(aTypes, aCallback) {
|
2012-05-10 18:33:02 +00:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
if (typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
let addons = [];
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
new AsyncObjectCaller(this.providers, "getAddonsWithOperationsByTypes", {
|
2012-10-24 09:58:00 +00:00
|
|
|
nextObject: function getAddonsWithOperationsByTypes_nextObject
|
|
|
|
(aCaller, aProvider) {
|
2010-04-26 17:49:19 +00:00
|
|
|
callProvider(aProvider, "getAddonsWithOperationsByTypes", null, aTypes,
|
2012-10-24 09:58:00 +00:00
|
|
|
function getAddonsWithOperationsByTypes_concatAddons
|
|
|
|
(aProviderAddons) {
|
2010-04-28 16:42:07 +00:00
|
|
|
addons = addons.concat(aProviderAddons);
|
|
|
|
aCaller.callNext();
|
2010-04-29 20:11:23 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
noMoreObjects: function getAddonsWithOperationsByTypes_noMoreObjects(caller) {
|
2010-04-28 16:42:07 +00:00
|
|
|
safeCall(aCallback, addons);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
/**
|
|
|
|
* Adds a new AddonManagerListener if the listener is not already registered.
|
|
|
|
*
|
|
|
|
* @param aListener
|
|
|
|
* The listener to add
|
|
|
|
*/
|
|
|
|
addManagerListener: function AMI_addManagerListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonManagerListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
if (!this.managerListeners.some(function addManagerListener_matchListener(i) {
|
|
|
|
return i == aListener; }))
|
2012-02-15 02:07:29 +00:00
|
|
|
this.managerListeners.push(aListener);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an AddonManagerListener if the listener is registered.
|
|
|
|
*
|
|
|
|
* @param aListener
|
|
|
|
* The listener to remove
|
|
|
|
*/
|
|
|
|
removeManagerListener: function AMI_removeManagerListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonManagerListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
let pos = 0;
|
|
|
|
while (pos < this.managerListeners.length) {
|
|
|
|
if (this.managerListeners[pos] == aListener)
|
|
|
|
this.managerListeners.splice(pos, 1);
|
|
|
|
else
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
/**
|
|
|
|
* Adds a new AddonListener if the listener is not already registered.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aListener
|
2012-05-30 06:34:32 +00:00
|
|
|
* The AddonListener to add
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
addAddonListener: function AMI_addAddonListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
if (!this.addonListeners.some(function addAddonListener_matchListener(i) {
|
|
|
|
return i == aListener; }))
|
2010-04-28 16:42:07 +00:00
|
|
|
this.addonListeners.push(aListener);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an AddonListener if the listener is registered.
|
|
|
|
*
|
2010-04-28 16:42:07 +00:00
|
|
|
* @param aListener
|
2012-05-30 06:34:32 +00:00
|
|
|
* The AddonListener to remove
|
2010-04-29 20:11:23 +00:00
|
|
|
*/
|
2010-04-28 16:42:07 +00:00
|
|
|
removeAddonListener: function AMI_removeAddonListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-10-12 21:31:52 +00:00
|
|
|
let pos = 0;
|
|
|
|
while (pos < this.addonListeners.length) {
|
|
|
|
if (this.addonListeners[pos] == aListener)
|
|
|
|
this.addonListeners.splice(pos, 1);
|
|
|
|
else
|
|
|
|
pos++;
|
|
|
|
}
|
2010-09-14 06:56:54 +00:00
|
|
|
},
|
2011-01-14 21:29:27 +00:00
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
/**
|
|
|
|
* Adds a new TypeListener if the listener is not already registered.
|
|
|
|
*
|
|
|
|
* @param aListener
|
|
|
|
* The TypeListener to add
|
|
|
|
*/
|
2011-05-20 17:36:28 +00:00
|
|
|
addTypeListener: function AMI_addTypeListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a TypeListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
if (!this.typeListeners.some(function addTypeListener_matchListener(i) {
|
|
|
|
return i == aListener; }))
|
2011-05-20 17:36:28 +00:00
|
|
|
this.typeListeners.push(aListener);
|
|
|
|
},
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
/**
|
|
|
|
* Removes an TypeListener if the listener is registered.
|
|
|
|
*
|
|
|
|
* @param aListener
|
|
|
|
* The TypeListener to remove
|
|
|
|
*/
|
2011-05-20 17:36:28 +00:00
|
|
|
removeTypeListener: function AMI_removeTypeListener(aListener) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a TypeListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
let pos = 0;
|
|
|
|
while (pos < this.typeListeners.length) {
|
|
|
|
if (this.typeListeners[pos] == aListener)
|
|
|
|
this.typeListeners.splice(pos, 1);
|
|
|
|
else
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get addonTypes() {
|
|
|
|
return this.typesProxy;
|
|
|
|
},
|
|
|
|
|
2010-09-14 06:56:54 +00:00
|
|
|
get autoUpdateDefault() {
|
2012-02-15 02:07:29 +00:00
|
|
|
return gAutoUpdateDefault;
|
|
|
|
},
|
|
|
|
|
|
|
|
set autoUpdateDefault(aValue) {
|
|
|
|
aValue = !!aValue;
|
|
|
|
if (aValue != gAutoUpdateDefault)
|
|
|
|
Services.prefs.setBoolPref(PREF_EM_AUTOUPDATE_DEFAULT, aValue);
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
get checkCompatibility() {
|
|
|
|
return gCheckCompatibility;
|
|
|
|
},
|
|
|
|
|
|
|
|
set checkCompatibility(aValue) {
|
|
|
|
aValue = !!aValue;
|
|
|
|
if (aValue != gCheckCompatibility) {
|
|
|
|
if (!aValue)
|
|
|
|
Services.prefs.setBoolPref(PREF_EM_CHECK_COMPATIBILITY, false);
|
|
|
|
else
|
|
|
|
Services.prefs.clearUserPref(PREF_EM_CHECK_COMPATIBILITY);
|
|
|
|
}
|
|
|
|
return aValue;
|
2011-11-01 05:48:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get strictCompatibility() {
|
|
|
|
return gStrictCompatibility;
|
2012-02-15 02:07:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set strictCompatibility(aValue) {
|
|
|
|
aValue = !!aValue;
|
|
|
|
if (aValue != gStrictCompatibility)
|
|
|
|
Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, aValue);
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
get checkUpdateSecurityDefault() {
|
|
|
|
return gCheckUpdateSecurityDefault;
|
|
|
|
},
|
|
|
|
|
|
|
|
get checkUpdateSecurity() {
|
|
|
|
return gCheckUpdateSecurity;
|
|
|
|
},
|
|
|
|
|
|
|
|
set checkUpdateSecurity(aValue) {
|
|
|
|
aValue = !!aValue;
|
|
|
|
if (aValue != gCheckUpdateSecurity) {
|
|
|
|
if (aValue != gCheckUpdateSecurityDefault)
|
|
|
|
Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, aValue);
|
|
|
|
else
|
|
|
|
Services.prefs.clearUserPref(PREF_EM_CHECK_UPDATE_SECURITY);
|
|
|
|
}
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
get updateEnabled() {
|
|
|
|
return gUpdateEnabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
set updateEnabled(aValue) {
|
|
|
|
aValue = !!aValue;
|
|
|
|
if (aValue != gUpdateEnabled)
|
|
|
|
Services.prefs.setBoolPref(PREF_EM_UPDATE_ENABLED, aValue);
|
|
|
|
return aValue;
|
2012-04-18 18:39:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get hotfixID() {
|
|
|
|
return gHotfixID;
|
|
|
|
},
|
2010-04-29 20:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should not be used outside of core Mozilla code. This is a private API for
|
|
|
|
* the startup and platform integration code to use. Refer to the methods on
|
|
|
|
* AddonManagerInternal for documentation however note that these methods are
|
|
|
|
* subject to change at any time.
|
|
|
|
*/
|
2012-10-31 16:13:28 +00:00
|
|
|
this.AddonManagerPrivate = {
|
2010-04-29 20:11:23 +00:00
|
|
|
startup: function AMP_startup() {
|
|
|
|
AddonManagerInternal.startup();
|
|
|
|
},
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
registerProvider: function AMP_registerProvider(aProvider, aTypes) {
|
|
|
|
AddonManagerInternal.registerProvider(aProvider, aTypes);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-06-17 03:13:54 +00:00
|
|
|
unregisterProvider: function AMP_unregisterProvider(aProvider) {
|
|
|
|
AddonManagerInternal.unregisterProvider(aProvider);
|
|
|
|
},
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
backgroundUpdateCheck: function AMP_backgroundUpdateCheck() {
|
|
|
|
AddonManagerInternal.backgroundUpdateCheck();
|
|
|
|
},
|
|
|
|
|
2011-06-29 21:50:43 +00:00
|
|
|
addStartupChange: function AMP_addStartupChange(aType, aID) {
|
|
|
|
AddonManagerInternal.addStartupChange(aType, aID);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeStartupChange: function AMP_removeStartupChange(aType, aID) {
|
|
|
|
AddonManagerInternal.removeStartupChange(aType, aID);
|
|
|
|
},
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
notifyAddonChanged: function AMP_notifyAddonChanged(aID, aType, aPendingRestart) {
|
|
|
|
AddonManagerInternal.notifyAddonChanged(aID, aType, aPendingRestart);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
updateAddonAppDisabledStates: function AMP_updateAddonAppDisabledStates() {
|
|
|
|
AddonManagerInternal.updateAddonAppDisabledStates();
|
|
|
|
},
|
|
|
|
|
2011-12-07 10:48:33 +00:00
|
|
|
updateAddonRepositoryData: function AMP_updateAddonRepositoryData(aCallback) {
|
|
|
|
AddonManagerInternal.updateAddonRepositoryData(aCallback);
|
|
|
|
},
|
|
|
|
|
2012-06-20 09:12:11 +00:00
|
|
|
callInstallListeners: function AMP_callInstallListeners(...aArgs) {
|
2010-04-29 20:11:23 +00:00
|
|
|
return AddonManagerInternal.callInstallListeners.apply(AddonManagerInternal,
|
2012-06-20 09:12:11 +00:00
|
|
|
aArgs);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2012-06-20 09:12:11 +00:00
|
|
|
callAddonListeners: function AMP_callAddonListeners(...aArgs) {
|
|
|
|
AddonManagerInternal.callAddonListeners.apply(AddonManagerInternal, aArgs);
|
2010-08-24 01:04:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
AddonAuthor: AddonAuthor,
|
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
AddonScreenshot: AddonScreenshot,
|
|
|
|
|
2011-12-02 02:28:15 +00:00
|
|
|
AddonCompatibilityOverride: AddonCompatibilityOverride,
|
|
|
|
|
2013-02-07 21:47:33 +00:00
|
|
|
AddonType: AddonType,
|
|
|
|
|
|
|
|
recordTimestamp: function AMP_recordTimestamp(name, value) {
|
|
|
|
AddonManagerInternal.recordTimestamp(name, value);
|
|
|
|
},
|
|
|
|
|
|
|
|
_simpleMeasures: {},
|
|
|
|
recordSimpleMeasure: function AMP_recordSimpleMeasure(name, value) {
|
|
|
|
this._simpleMeasures[name] = value;
|
|
|
|
},
|
|
|
|
|
2014-01-09 20:00:27 +00:00
|
|
|
recordException: function AMP_recordException(aModule, aContext, aException) {
|
|
|
|
let report = {
|
|
|
|
module: aModule,
|
|
|
|
context: aContext
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof aException == "number") {
|
|
|
|
report.message = Components.Exception("", aException).name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
report.message = aException.toString();
|
|
|
|
if (aException.fileName) {
|
|
|
|
report.file = aException.fileName;
|
|
|
|
report.line = aException.lineNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._simpleMeasures.exception = report;
|
|
|
|
},
|
|
|
|
|
2013-02-07 21:47:33 +00:00
|
|
|
getSimpleMeasures: function AMP_getSimpleMeasures() {
|
|
|
|
return this._simpleMeasures;
|
2013-08-22 15:56:28 +00:00
|
|
|
},
|
|
|
|
|
2013-10-11 17:13:31 +00:00
|
|
|
getTelemetryDetails: function AMP_getTelemetryDetails() {
|
|
|
|
return AddonManagerInternal.telemetryDetails;
|
|
|
|
},
|
|
|
|
|
|
|
|
setTelemetryDetails: function AMP_setTelemetryDetails(aProvider, aDetails) {
|
|
|
|
AddonManagerInternal.telemetryDetails[aProvider] = aDetails;
|
|
|
|
},
|
|
|
|
|
2013-08-22 15:56:28 +00:00
|
|
|
// Start a timer, record a simple measure of the time interval when
|
|
|
|
// timer.done() is called
|
|
|
|
simpleTimer: function(aName) {
|
|
|
|
let startTime = Date.now();
|
|
|
|
return {
|
2013-10-11 17:13:31 +00:00
|
|
|
done: () => this.recordSimpleMeasure(aName, Date.now() - startTime)
|
2013-08-22 15:56:28 +00:00
|
|
|
};
|
2013-02-07 21:47:33 +00:00
|
|
|
}
|
2010-04-29 20:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the public API that UI and developers should be calling. All methods
|
|
|
|
* just forward to AddonManagerInternal.
|
|
|
|
*/
|
2012-10-31 16:13:28 +00:00
|
|
|
this.AddonManager = {
|
2010-04-29 20:11:23 +00:00
|
|
|
// Constants for the AddonInstall.state property
|
|
|
|
// The install is available for download.
|
|
|
|
STATE_AVAILABLE: 0,
|
|
|
|
// The install is being downloaded.
|
|
|
|
STATE_DOWNLOADING: 1,
|
|
|
|
// The install is checking for compatibility information.
|
|
|
|
STATE_CHECKING: 2,
|
|
|
|
// The install is downloaded and ready to install.
|
|
|
|
STATE_DOWNLOADED: 3,
|
|
|
|
// The download failed.
|
|
|
|
STATE_DOWNLOAD_FAILED: 4,
|
|
|
|
// The add-on is being installed.
|
|
|
|
STATE_INSTALLING: 5,
|
|
|
|
// The add-on has been installed.
|
|
|
|
STATE_INSTALLED: 6,
|
|
|
|
// The install failed.
|
|
|
|
STATE_INSTALL_FAILED: 7,
|
|
|
|
// The install has been cancelled.
|
|
|
|
STATE_CANCELLED: 8,
|
|
|
|
|
|
|
|
// Constants representing different types of errors while downloading an
|
|
|
|
// add-on.
|
|
|
|
// The download failed due to network problems.
|
|
|
|
ERROR_NETWORK_FAILURE: -1,
|
|
|
|
// The downloaded file did not match the provided hash.
|
|
|
|
ERROR_INCORRECT_HASH: -2,
|
|
|
|
// The downloaded file seems to be corrupted in some way.
|
|
|
|
ERROR_CORRUPT_FILE: -3,
|
2010-06-10 23:39:47 +00:00
|
|
|
// An error occured trying to write to the filesystem.
|
|
|
|
ERROR_FILE_ACCESS: -4,
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-06-10 18:11:16 +00:00
|
|
|
// These must be kept in sync with AddonUpdateChecker.
|
|
|
|
// No error was encountered.
|
|
|
|
UPDATE_STATUS_NO_ERROR: 0,
|
|
|
|
// The update check timed out
|
|
|
|
UPDATE_STATUS_TIMEOUT: -1,
|
|
|
|
// There was an error while downloading the update information.
|
|
|
|
UPDATE_STATUS_DOWNLOAD_ERROR: -2,
|
|
|
|
// The update information was malformed in some way.
|
|
|
|
UPDATE_STATUS_PARSE_ERROR: -3,
|
|
|
|
// The update information was not in any known format.
|
|
|
|
UPDATE_STATUS_UNKNOWN_FORMAT: -4,
|
|
|
|
// The update information was not correctly signed or there was an SSL error.
|
|
|
|
UPDATE_STATUS_SECURITY_ERROR: -5,
|
2013-11-26 15:21:32 +00:00
|
|
|
// The update was cancelled.
|
|
|
|
UPDATE_STATUS_CANCELLED: -6,
|
2010-06-10 18:11:16 +00:00
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
// Constants to indicate why an update check is being performed
|
|
|
|
// Update check has been requested by the user.
|
|
|
|
UPDATE_WHEN_USER_REQUESTED: 1,
|
|
|
|
// Update check is necessary to see if the Addon is compatibile with a new
|
|
|
|
// version of the application.
|
|
|
|
UPDATE_WHEN_NEW_APP_DETECTED: 2,
|
|
|
|
// Update check is necessary because a new application has been installed.
|
|
|
|
UPDATE_WHEN_NEW_APP_INSTALLED: 3,
|
|
|
|
// Update check is a regular background update check.
|
|
|
|
UPDATE_WHEN_PERIODIC_UPDATE: 16,
|
|
|
|
// Update check is needed to check an Addon that is being installed.
|
|
|
|
UPDATE_WHEN_ADDON_INSTALLED: 17,
|
|
|
|
|
|
|
|
// Constants for operations in Addon.pendingOperations
|
2010-04-29 20:11:23 +00:00
|
|
|
// Indicates that the Addon has no pending operations.
|
|
|
|
PENDING_NONE: 0,
|
2010-04-29 20:11:23 +00:00
|
|
|
// Indicates that the Addon will be enabled after the application restarts.
|
|
|
|
PENDING_ENABLE: 1,
|
|
|
|
// Indicates that the Addon will be disabled after the application restarts.
|
|
|
|
PENDING_DISABLE: 2,
|
|
|
|
// Indicates that the Addon will be uninstalled after the application restarts.
|
|
|
|
PENDING_UNINSTALL: 4,
|
|
|
|
// Indicates that the Addon will be installed after the application restarts.
|
|
|
|
PENDING_INSTALL: 8,
|
2010-04-07 17:54:23 +00:00
|
|
|
PENDING_UPGRADE: 16,
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-07-26 17:34:06 +00:00
|
|
|
// Constants for operations in Addon.operationsRequiringRestart
|
|
|
|
// Indicates that restart isn't required for any operation.
|
|
|
|
OP_NEEDS_RESTART_NONE: 0,
|
|
|
|
// Indicates that restart is required for enabling the addon.
|
|
|
|
OP_NEEDS_RESTART_ENABLE: 1,
|
|
|
|
// Indicates that restart is required for disabling the addon.
|
|
|
|
OP_NEEDS_RESTART_DISABLE: 2,
|
|
|
|
// Indicates that restart is required for uninstalling the addon.
|
|
|
|
OP_NEEDS_RESTART_UNINSTALL: 4,
|
|
|
|
// Indicates that restart is required for installing the addon.
|
|
|
|
OP_NEEDS_RESTART_INSTALL: 8,
|
|
|
|
|
2010-04-29 20:11:23 +00:00
|
|
|
// Constants for permissions in Addon.permissions.
|
|
|
|
// Indicates that the Addon can be uninstalled.
|
|
|
|
PERM_CAN_UNINSTALL: 1,
|
|
|
|
// Indicates that the Addon can be enabled by the user.
|
|
|
|
PERM_CAN_ENABLE: 2,
|
|
|
|
// Indicates that the Addon can be disabled by the user.
|
|
|
|
PERM_CAN_DISABLE: 4,
|
|
|
|
// Indicates that the Addon can be upgraded.
|
|
|
|
PERM_CAN_UPGRADE: 8,
|
2013-04-23 23:21:22 +00:00
|
|
|
// Indicates that the Addon can be set to be optionally enabled
|
|
|
|
// on a case-by-case basis.
|
|
|
|
PERM_CAN_ASK_TO_ACTIVATE: 16,
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-04-07 18:08:32 +00:00
|
|
|
// General descriptions of where items are installed.
|
|
|
|
// Installed in this profile.
|
|
|
|
SCOPE_PROFILE: 1,
|
|
|
|
// Installed for all of this user's profiles.
|
|
|
|
SCOPE_USER: 2,
|
|
|
|
// Installed and owned by the application.
|
|
|
|
SCOPE_APPLICATION: 4,
|
|
|
|
// Installed for all users of the computer.
|
|
|
|
SCOPE_SYSTEM: 8,
|
|
|
|
// The combination of all scopes.
|
|
|
|
SCOPE_ALL: 15,
|
2011-01-14 21:29:27 +00:00
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
// 1-15 are different built-in views for the add-on type
|
|
|
|
VIEW_TYPE_LIST: "list",
|
|
|
|
|
|
|
|
TYPE_UI_HIDE_EMPTY: 16,
|
2013-04-23 23:21:22 +00:00
|
|
|
// Indicates that this add-on type supports the ask-to-activate state.
|
|
|
|
// That is, add-ons of this type can be set to be optionally enabled
|
|
|
|
// on a case-by-case basis.
|
|
|
|
TYPE_SUPPORTS_ASK_TO_ACTIVATE: 32,
|
2011-05-20 17:36:28 +00:00
|
|
|
|
2010-09-14 06:56:54 +00:00
|
|
|
// Constants for Addon.applyBackgroundUpdates.
|
|
|
|
// Indicates that the Addon should not update automatically.
|
|
|
|
AUTOUPDATE_DISABLE: 0,
|
|
|
|
// Indicates that the Addon should update automatically only if
|
|
|
|
// that's the global default.
|
|
|
|
AUTOUPDATE_DEFAULT: 1,
|
|
|
|
// Indicates that the Addon should update automatically.
|
|
|
|
AUTOUPDATE_ENABLE: 2,
|
2010-04-07 18:08:32 +00:00
|
|
|
|
2011-06-01 10:35:24 +00:00
|
|
|
// Constants for how Addon options should be shown.
|
|
|
|
// Options will be opened in a new window
|
|
|
|
OPTIONS_TYPE_DIALOG: 1,
|
|
|
|
// Options will be displayed within the AM detail view
|
|
|
|
OPTIONS_TYPE_INLINE: 2,
|
2011-06-10 23:11:32 +00:00
|
|
|
// Options will be displayed in a new tab, if possible
|
|
|
|
OPTIONS_TYPE_TAB: 3,
|
2013-04-01 09:07:23 +00:00
|
|
|
// Same as OPTIONS_TYPE_INLINE, but no Preferences button will be shown.
|
|
|
|
// Used to indicate that only non-interactive information will be shown.
|
|
|
|
OPTIONS_TYPE_INLINE_INFO: 4,
|
2011-06-01 10:35:24 +00:00
|
|
|
|
2012-09-26 19:42:00 +00:00
|
|
|
// Constants for displayed or hidden options notifications
|
|
|
|
// Options notification will be displayed
|
|
|
|
OPTIONS_NOTIFICATION_DISPLAYED: "addon-options-displayed",
|
|
|
|
// Options notification will be hidden
|
|
|
|
OPTIONS_NOTIFICATION_HIDDEN: "addon-options-hidden",
|
|
|
|
|
2011-06-29 21:50:43 +00:00
|
|
|
// Constants for getStartupChanges, addStartupChange and removeStartupChange
|
|
|
|
// Add-ons that were detected as installed during startup. Doesn't include
|
|
|
|
// add-ons that were pending installation the last time the application ran.
|
|
|
|
STARTUP_CHANGE_INSTALLED: "installed",
|
|
|
|
// Add-ons that were detected as changed during startup. This includes an
|
|
|
|
// add-on moving to a different location, changing version or just having
|
|
|
|
// been detected as possibly changed.
|
|
|
|
STARTUP_CHANGE_CHANGED: "changed",
|
|
|
|
// Add-ons that were detected as uninstalled during startup. Doesn't include
|
|
|
|
// add-ons that were pending uninstallation the last time the application ran.
|
|
|
|
STARTUP_CHANGE_UNINSTALLED: "uninstalled",
|
|
|
|
// Add-ons that were detected as disabled during startup, normally because of
|
|
|
|
// an application change making an add-on incompatible. Doesn't include
|
|
|
|
// add-ons that were pending being disabled the last time the application ran.
|
|
|
|
STARTUP_CHANGE_DISABLED: "disabled",
|
|
|
|
// Add-ons that were detected as enabled during startup, normally because of
|
|
|
|
// an application change making an add-on compatible. Doesn't include
|
|
|
|
// add-ons that were pending being enabled the last time the application ran.
|
|
|
|
STARTUP_CHANGE_ENABLED: "enabled",
|
|
|
|
|
2013-04-23 23:21:22 +00:00
|
|
|
// Constants for the Addon.userDisabled property
|
|
|
|
// Indicates that the userDisabled state of this add-on is currently
|
|
|
|
// ask-to-activate. That is, it can be conditionally enabled on a
|
|
|
|
// case-by-case basis.
|
|
|
|
STATE_ASK_TO_ACTIVATE: "askToActivate",
|
|
|
|
|
2012-08-13 02:19:37 +00:00
|
|
|
#ifdef MOZ_EM_DEBUG
|
|
|
|
get __AddonManagerInternal__() {
|
|
|
|
return AddonManagerInternal;
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
getInstallForURL: function AM_getInstallForURL(aUrl, aCallback, aMimetype,
|
2012-08-23 06:49:29 +00:00
|
|
|
aHash, aName, aIcons,
|
2010-04-28 16:42:07 +00:00
|
|
|
aVersion, aLoadGroup) {
|
|
|
|
AddonManagerInternal.getInstallForURL(aUrl, aCallback, aMimetype, aHash,
|
2012-08-23 06:49:29 +00:00
|
|
|
aName, aIcons, aVersion, aLoadGroup);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
getInstallForFile: function AM_getInstallForFile(aFile, aCallback, aMimetype) {
|
|
|
|
AddonManagerInternal.getInstallForFile(aFile, aCallback, aMimetype);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2011-06-29 21:50:43 +00:00
|
|
|
/**
|
|
|
|
* Gets an array of add-on IDs that changed during the most recent startup.
|
|
|
|
*
|
|
|
|
* @param aType
|
|
|
|
* The type of startup change to get
|
|
|
|
* @return An array of add-on IDs
|
|
|
|
*/
|
|
|
|
getStartupChanges: function AM_getStartupChanges(aType) {
|
|
|
|
if (!(aType in AddonManagerInternal.startupChanges))
|
|
|
|
return [];
|
|
|
|
return AddonManagerInternal.startupChanges[aType].slice(0);
|
|
|
|
},
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
getAddonByID: function AM_getAddonByID(aID, aCallback) {
|
|
|
|
AddonManagerInternal.getAddonByID(aID, aCallback);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
getAddonBySyncGUID: function AM_getAddonBySyncGUID(aGUID, aCallback) {
|
|
|
|
AddonManagerInternal.getAddonBySyncGUID(aGUID, aCallback);
|
2011-11-05 01:04:15 +00:00
|
|
|
},
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
getAddonsByIDs: function AM_getAddonsByIDs(aIDs, aCallback) {
|
|
|
|
AddonManagerInternal.getAddonsByIDs(aIDs, aCallback);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
getAddonsWithOperationsByTypes:
|
|
|
|
function AM_getAddonsWithOperationsByTypes(aTypes, aCallback) {
|
|
|
|
AddonManagerInternal.getAddonsWithOperationsByTypes(aTypes, aCallback);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
getAddonsByTypes: function AM_getAddonsByTypes(aTypes, aCallback) {
|
|
|
|
AddonManagerInternal.getAddonsByTypes(aTypes, aCallback);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-26 17:49:19 +00:00
|
|
|
getAllAddons: function AM_getAllAddons(aCallback) {
|
|
|
|
AddonManagerInternal.getAllAddons(aCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
getInstallsByTypes: function AM_getInstallsByTypes(aTypes, aCallback) {
|
|
|
|
AddonManagerInternal.getInstallsByTypes(aTypes, aCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
getAllInstalls: function AM_getAllInstalls(aCallback) {
|
|
|
|
AddonManagerInternal.getAllInstalls(aCallback);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2013-06-15 02:48:06 +00:00
|
|
|
mapURIToAddonID: function AM_mapURIToAddonID(aURI) {
|
|
|
|
return AddonManagerInternal.mapURIToAddonID(aURI);
|
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
isInstallEnabled: function AM_isInstallEnabled(aType) {
|
|
|
|
return AddonManagerInternal.isInstallEnabled(aType);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
isInstallAllowed: function AM_isInstallAllowed(aType, aUri) {
|
|
|
|
return AddonManagerInternal.isInstallAllowed(aType, aUri);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
installAddonsFromWebpage: function AM_installAddonsFromWebpage(aType, aSource,
|
|
|
|
aUri, aInstalls) {
|
|
|
|
AddonManagerInternal.installAddonsFromWebpage(aType, aSource, aUri, aInstalls);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
addManagerListener: function AM_addManagerListener(aListener) {
|
|
|
|
AddonManagerInternal.addManagerListener(aListener);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeManagerListener: function AM_removeManagerListener(aListener) {
|
|
|
|
AddonManagerInternal.removeManagerListener(aListener);
|
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
addInstallListener: function AM_addInstallListener(aListener) {
|
|
|
|
AddonManagerInternal.addInstallListener(aListener);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
removeInstallListener: function AM_removeInstallListener(aListener) {
|
|
|
|
AddonManagerInternal.removeInstallListener(aListener);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
addAddonListener: function AM_addAddonListener(aListener) {
|
|
|
|
AddonManagerInternal.addAddonListener(aListener);
|
2010-04-29 20:11:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-28 16:42:07 +00:00
|
|
|
removeAddonListener: function AM_removeAddonListener(aListener) {
|
|
|
|
AddonManagerInternal.removeAddonListener(aListener);
|
2010-09-14 06:56:54 +00:00
|
|
|
},
|
2011-01-14 21:29:27 +00:00
|
|
|
|
2011-05-20 17:36:28 +00:00
|
|
|
addTypeListener: function AM_addTypeListener(aListener) {
|
|
|
|
AddonManagerInternal.addTypeListener(aListener);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeTypeListener: function AM_removeTypeListener(aListener) {
|
|
|
|
AddonManagerInternal.removeTypeListener(aListener);
|
|
|
|
},
|
|
|
|
|
|
|
|
get addonTypes() {
|
|
|
|
return AddonManagerInternal.addonTypes;
|
|
|
|
},
|
|
|
|
|
2012-05-30 06:34:32 +00:00
|
|
|
/**
|
|
|
|
* Determines whether an Addon should auto-update or not.
|
|
|
|
*
|
|
|
|
* @param aAddon
|
|
|
|
* The Addon representing the add-on
|
|
|
|
* @return true if the addon should auto-update, false otherwise.
|
|
|
|
*/
|
2011-08-12 23:55:34 +00:00
|
|
|
shouldAutoUpdate: function AM_shouldAutoUpdate(aAddon) {
|
2012-05-30 06:34:32 +00:00
|
|
|
if (!aAddon || typeof aAddon != "object")
|
|
|
|
throw Components.Exception("aAddon must be specified",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2013-09-13 03:11:30 +00:00
|
|
|
|
2011-08-12 23:55:34 +00:00
|
|
|
if (!("applyBackgroundUpdates" in aAddon))
|
|
|
|
return false;
|
|
|
|
if (aAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_ENABLE)
|
|
|
|
return true;
|
|
|
|
if (aAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DISABLE)
|
|
|
|
return false;
|
|
|
|
return this.autoUpdateDefault;
|
2011-11-01 05:48:45 +00:00
|
|
|
},
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
get checkCompatibility() {
|
|
|
|
return AddonManagerInternal.checkCompatibility;
|
|
|
|
},
|
|
|
|
|
|
|
|
set checkCompatibility(aValue) {
|
|
|
|
AddonManagerInternal.checkCompatibility = aValue;
|
|
|
|
},
|
|
|
|
|
2011-11-01 05:48:45 +00:00
|
|
|
get strictCompatibility() {
|
|
|
|
return AddonManagerInternal.strictCompatibility;
|
2011-12-16 20:04:50 +00:00
|
|
|
},
|
|
|
|
|
2012-02-15 02:07:29 +00:00
|
|
|
set strictCompatibility(aValue) {
|
|
|
|
AddonManagerInternal.strictCompatibility = aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
get checkUpdateSecurityDefault() {
|
|
|
|
return AddonManagerInternal.checkUpdateSecurityDefault;
|
|
|
|
},
|
|
|
|
|
|
|
|
get checkUpdateSecurity() {
|
|
|
|
return AddonManagerInternal.checkUpdateSecurity;
|
|
|
|
},
|
|
|
|
|
|
|
|
set checkUpdateSecurity(aValue) {
|
|
|
|
AddonManagerInternal.checkUpdateSecurity = aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
get updateEnabled() {
|
|
|
|
return AddonManagerInternal.updateEnabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
set updateEnabled(aValue) {
|
|
|
|
AddonManagerInternal.updateEnabled = aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
get autoUpdateDefault() {
|
|
|
|
return AddonManagerInternal.autoUpdateDefault;
|
|
|
|
},
|
|
|
|
|
|
|
|
set autoUpdateDefault(aValue) {
|
|
|
|
AddonManagerInternal.autoUpdateDefault = aValue;
|
|
|
|
},
|
|
|
|
|
2012-04-18 18:39:29 +00:00
|
|
|
get hotfixID() {
|
|
|
|
return AddonManagerInternal.hotfixID;
|
|
|
|
},
|
|
|
|
|
2011-12-16 20:04:50 +00:00
|
|
|
escapeAddonURI: function AM_escapeAddonURI(aAddon, aUri, aAppVersion) {
|
|
|
|
return AddonManagerInternal.escapeAddonURI(aAddon, aUri, aAppVersion);
|
2010-04-29 20:11:23 +00:00
|
|
|
}
|
|
|
|
};
|
2010-10-12 21:31:52 +00:00
|
|
|
|
2013-02-07 21:47:33 +00:00
|
|
|
// load the timestamps module into AddonManagerInternal
|
2013-02-09 18:28:38 +00:00
|
|
|
Cu.import("resource://gre/modules/TelemetryTimestamps.jsm", AddonManagerInternal);
|
2010-10-12 21:31:52 +00:00
|
|
|
Object.freeze(AddonManagerInternal);
|
|
|
|
Object.freeze(AddonManagerPrivate);
|
|
|
|
Object.freeze(AddonManager);
|