2012-05-29 19:52:43 +04: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-30 00:11:23 +04:00
|
|
|
|
2011-07-20 00:16:35 +04:00
|
|
|
"use strict";
|
|
|
|
|
2013-10-28 08:52:00 +04: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) {
|
2017-11-22 16:35:52 +03:00
|
|
|
// eslint-disable-next-line mozilla/use-services
|
2013-10-28 08:52:00 +04:00
|
|
|
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!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
2015-11-20 02:30:47 +03:00
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
const MOZ_COMPATIBILITY_NIGHTLY = !["aurora", "beta", "release", "esr"].includes(AppConstants.MOZ_UPDATE_CHANNEL);
|
2013-10-28 08:52:00 +04:00
|
|
|
|
2011-02-24 14:20:02 +03:00
|
|
|
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
|
2011-05-19 22:04:44 +04: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 09:48:45 +04:00
|
|
|
const PREF_EM_STRICT_COMPATIBILITY = "extensions.strictCompatibility";
|
2012-02-15 06:07:29 +04:00
|
|
|
const PREF_EM_CHECK_UPDATE_SECURITY = "extensions.checkUpdateSecurity";
|
2018-05-15 00:43:25 +03:00
|
|
|
const PREF_SYS_ADDON_UPDATE_ENABLED = "extensions.systemAddon.update.enabled";
|
2011-12-17 00:04:50 +04:00
|
|
|
|
2015-11-04 01:49:46 +03:00
|
|
|
const PREF_MIN_WEBEXT_PLATFORM_VERSION = "extensions.webExtensionsMinPlatformVersion";
|
2016-07-15 21:40:45 +03:00
|
|
|
const PREF_WEBAPI_TESTING = "extensions.webapi.testing";
|
2017-01-06 03:35:07 +03:00
|
|
|
const PREF_WEBEXT_PERM_PROMPTS = "extensions.webextPermissionPrompts";
|
2015-11-04 01:49:46 +03:00
|
|
|
|
2011-12-17 00:04:50 +04:00
|
|
|
const UPDATE_REQUEST_VERSION = 2;
|
2011-11-01 09:48:45 +04:00
|
|
|
|
2014-04-15 04:44:56 +04:00
|
|
|
const XMLURI_BLOCKLIST = "http://www.mozilla.org/2006/addons-blocklist";
|
|
|
|
|
|
|
|
const KEY_PROFILEDIR = "ProfD";
|
|
|
|
const KEY_APPDIR = "XCurProcD";
|
|
|
|
const FILE_BLOCKLIST = "blocklist.xml";
|
|
|
|
|
2018-04-01 14:53:31 +03:00
|
|
|
const DEFAULT_THEME_ID = "default-theme@mozilla.org";
|
|
|
|
|
2012-02-15 06:07:29 +04:00
|
|
|
const BRANCH_REGEXP = /^([^\.]+\.[0-9]+[a-z]*).*/gi;
|
|
|
|
const PREF_EM_CHECK_COMPATIBILITY_BASE = "extensions.checkCompatibility";
|
2015-11-20 02:30:47 +03:00
|
|
|
var PREF_EM_CHECK_COMPATIBILITY = MOZ_COMPATIBILITY_NIGHTLY ?
|
|
|
|
PREF_EM_CHECK_COMPATIBILITY_BASE + ".nightly" :
|
|
|
|
undefined;
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2011-05-20 21:36:28 +04:00
|
|
|
const VALID_TYPES_REGEXP = /^[\w\-]+$/;
|
|
|
|
|
2016-10-11 22:50:38 +03:00
|
|
|
const WEBAPI_INSTALL_HOSTS = ["addons.mozilla.org", "testpilot.firefox.com"];
|
2016-07-15 21:40:45 +03:00
|
|
|
const WEBAPI_TEST_INSTALL_HOSTS = [
|
2016-10-11 22:50:38 +03:00
|
|
|
"addons.allizom.org", "addons-dev.allizom.org",
|
2016-08-10 01:15:01 +03:00
|
|
|
"testpilot.stage.mozaws.net", "testpilot.dev.mozaws.net",
|
2016-07-15 21:40:45 +03:00
|
|
|
"example.com",
|
|
|
|
];
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/AsyncShutdown.jsm");
|
2013-09-13 07:11:30 +04:00
|
|
|
|
2018-05-26 03:02:29 +03:00
|
|
|
XPCOMUtils.defineLazyGlobalGetters(this, ["DOMParser", "Element"]);
|
|
|
|
|
2017-08-09 23:03:36 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
|
|
|
AddonRepository: "resource://gre/modules/addons/AddonRepository.jsm",
|
|
|
|
Extension: "resource://gre/modules/Extension.jsm",
|
|
|
|
FileUtils: "resource://gre/modules/FileUtils.jsm",
|
2018-04-01 14:53:31 +03:00
|
|
|
LightweightThemeManager: "resource://gre/modules/LightweightThemeManager.jsm",
|
2017-08-09 23:03:36 +03:00
|
|
|
});
|
2012-05-10 06:28:45 +04:00
|
|
|
|
2017-01-06 03:35:07 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "WEBEXT_PERMISSION_PROMPTS",
|
|
|
|
PREF_WEBEXT_PERM_PROMPTS, false);
|
|
|
|
|
2017-06-05 01:38:11 +03:00
|
|
|
// Initialize the WebExtension process script service as early as possible,
|
|
|
|
// since it needs to be able to track things like new frameLoader globals that
|
|
|
|
// are created before other framework code has been initialized.
|
|
|
|
Services.ppmm.loadProcessScript(
|
|
|
|
"data:,Components.classes['@mozilla.org/webextensions/extension-process-script;1'].getService()",
|
|
|
|
true);
|
2017-04-16 18:42:03 +03:00
|
|
|
|
2015-11-24 20:20:26 +03:00
|
|
|
const INTEGER = /^[1-9]\d*$/;
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2018-09-19 19:43:11 +03:00
|
|
|
var EXPORTED_SYMBOLS = [ "AddonManager", "AddonManagerPrivate", "AMTelemetry" ];
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2010-07-13 01:20:49 +04:00
|
|
|
const CATEGORY_PROVIDER_MODULE = "addon-provider-module";
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
// A list of providers to load by default
|
2010-07-13 01:20:49 +04:00
|
|
|
const DEFAULT_PROVIDERS = [
|
2014-01-08 08:14:08 +04:00
|
|
|
"resource://gre/modules/addons/XPIProvider.jsm",
|
2018-08-31 08:59:17 +03:00
|
|
|
"resource://gre/modules/LightweightThemeManager.jsm",
|
2010-04-30 00:11:23 +04:00
|
|
|
];
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Log.jsm");
|
2014-02-23 21:27:59 +04:00
|
|
|
// Configure a logger at the parent 'addons' level to format
|
|
|
|
// messages for all the modules under addons.*
|
|
|
|
const PARENT_LOGGER_ID = "addons";
|
2015-09-15 21:19:45 +03:00
|
|
|
var parentLogger = Log.repository.getLogger(PARENT_LOGGER_ID);
|
2014-02-23 21:27:59 +04:00
|
|
|
parentLogger.level = Log.Level.Warn;
|
2015-09-15 21:19:45 +03:00
|
|
|
var formatter = new Log.BasicFormatter();
|
2014-02-23 21:27:59 +04:00
|
|
|
// 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";
|
2015-09-15 21:19:45 +03:00
|
|
|
var logger = Log.repository.getLogger(LOGGER_ID);
|
2014-02-23 21:27:59 +04:00
|
|
|
|
|
|
|
// 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-30 00:11:23 +04:00
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
const UNNAMED_PROVIDER = "<unnamed-provider>";
|
2014-09-29 21:01:50 +04:00
|
|
|
function providerName(aProvider) {
|
|
|
|
return aProvider.name || UNNAMED_PROVIDER;
|
|
|
|
}
|
2014-09-28 00:25:47 +04:00
|
|
|
|
2014-02-23 21:27:59 +04: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 = {
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_LOGGING_ENABLED, this);
|
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown");
|
2014-02-23 21:27:59 +04:00
|
|
|
this.observe(null, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, PREF_LOGGING_ENABLED);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
observe(aSubject, aTopic, aData) {
|
2014-02-23 21:27:59 +04:00
|
|
|
if (aTopic == "xpcom-shutdown") {
|
|
|
|
Services.prefs.removeObserver(PREF_LOGGING_ENABLED, this);
|
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (aTopic == NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) {
|
2017-03-07 17:29:48 +03:00
|
|
|
let debugLogEnabled = Services.prefs.getBoolPref(PREF_LOGGING_ENABLED, false);
|
2014-02-23 21:27:59 +04:00
|
|
|
if (debugLogEnabled) {
|
|
|
|
parentLogger.level = Log.Level.Debug;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2014-02-23 21:27:59 +04:00
|
|
|
parentLogger.level = Log.Level.Warn;
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2014-02-23 21:27:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
PrefObserver.init();
|
2010-04-30 00:11:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls a callback method consuming any thrown exception. Any parameters after
|
|
|
|
* the callback parameter will be passed to the callback.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aCallback
|
|
|
|
* The callback method to call
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2012-06-20 13:12:11 +04:00
|
|
|
function safeCall(aCallback, ...aArgs) {
|
2010-04-30 00:11:23 +04:00
|
|
|
try {
|
2012-06-20 13:12:11 +04:00
|
|
|
aCallback.apply(null, aArgs);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.warn("Exception calling callback", e);
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 21:01:50 +04:00
|
|
|
/**
|
|
|
|
* Report an exception thrown by a provider API method.
|
|
|
|
*/
|
|
|
|
function reportProviderError(aProvider, aMethod, aError) {
|
|
|
|
let method = `provider ${providerName(aProvider)}.${aMethod}`;
|
|
|
|
AddonManagerPrivate.recordException("AMI", method, aError);
|
|
|
|
logger.error("Exception calling " + method, aError);
|
|
|
|
}
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Calls a method on a provider if it exists and consumes any thrown exception.
|
2014-09-29 21:01:50 +04:00
|
|
|
* Any parameters after the aDefault parameter are passed to the provider's method.
|
2010-04-30 00:11:23 +04:00
|
|
|
*
|
2010-04-28 20:42:07 +04: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.
|
2014-09-29 21:01:50 +04:00
|
|
|
* @return the return value from the provider, or aDefault if the provider does not
|
2010-04-28 20:42:07 +04:00
|
|
|
* implement method or throws an error
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2012-06-20 13:12:11 +04:00
|
|
|
function callProvider(aProvider, aMethod, aDefault, ...aArgs) {
|
2010-04-28 20:42:07 +04:00
|
|
|
if (!(aMethod in aProvider))
|
|
|
|
return aDefault;
|
2010-04-30 00:11:23 +04:00
|
|
|
|
|
|
|
try {
|
2012-06-20 13:12:11 +04:00
|
|
|
return aProvider[aMethod].apply(aProvider, aArgs);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-09-29 21:01:50 +04:00
|
|
|
reportProviderError(aProvider, aMethod, e);
|
2010-04-28 20:42:07 +04:00
|
|
|
return aDefault;
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 21:01:50 +04:00
|
|
|
/**
|
|
|
|
* Calls a method on a provider if it exists and consumes any thrown exception.
|
|
|
|
* Parameters after aMethod are passed to aProvider.aMethod().
|
|
|
|
* If the provider does not implement the method, or the method throws, calls
|
|
|
|
* the callback with 'undefined'.
|
|
|
|
*
|
|
|
|
* @param aProvider
|
|
|
|
* The provider to call
|
|
|
|
* @param aMethod
|
|
|
|
* The method name to call
|
|
|
|
*/
|
2018-04-22 01:30:40 +03:00
|
|
|
async function promiseCallProvider(aProvider, aMethod, ...aArgs) {
|
2014-09-29 21:01:50 +04:00
|
|
|
if (!(aMethod in aProvider)) {
|
2016-02-04 00:12:18 +03:00
|
|
|
return undefined;
|
2014-09-29 21:01:50 +04:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
return aProvider[aMethod].apply(aProvider, aArgs);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-09-29 21:01:50 +04:00
|
|
|
reportProviderError(aProvider, aMethod, e);
|
2016-02-04 00:12:18 +03:00
|
|
|
return undefined;
|
2014-09-29 21:01:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 00:04:50 +04:00
|
|
|
/**
|
|
|
|
* Gets the currently selected locale for display.
|
|
|
|
* @return the selected locale or "en-US" if none is selected
|
|
|
|
*/
|
|
|
|
function getLocale() {
|
2018-09-21 18:30:37 +03:00
|
|
|
return Services.locale.requestedLocale || "en-US";
|
2011-12-17 00:04:50 +04:00
|
|
|
}
|
|
|
|
|
2018-05-04 01:56:26 +03:00
|
|
|
const WEB_EXPOSED_ADDON_PROPERTIES = [ "id", "version", "type", "name",
|
|
|
|
"description", "isActive" ];
|
|
|
|
|
2016-03-10 20:50:07 +03:00
|
|
|
function webAPIForAddon(addon) {
|
|
|
|
if (!addon) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-05-04 01:56:26 +03:00
|
|
|
// These web-exposed Addon properties (see AddonManager.webidl)
|
|
|
|
// just come directly from an Addon object.
|
2016-03-10 20:50:07 +03:00
|
|
|
let result = {};
|
2018-05-04 01:56:26 +03:00
|
|
|
for (let prop of WEB_EXPOSED_ADDON_PROPERTIES) {
|
|
|
|
result[prop] = addon[prop];
|
2016-03-10 20:50:07 +03:00
|
|
|
}
|
|
|
|
|
2018-05-04 01:56:26 +03:00
|
|
|
// These properties are computed.
|
2016-03-10 20:50:07 +03:00
|
|
|
result.isEnabled = !addon.userDisabled;
|
2016-08-24 05:24:15 +03:00
|
|
|
result.canUninstall = Boolean(addon.permissions & AddonManager.PERM_CAN_UNINSTALL);
|
2016-03-10 20:50:07 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-08-19 03:21:05 +03:00
|
|
|
/**
|
|
|
|
* Listens for a browser changing origin and cancels the installs that were
|
|
|
|
* started by it.
|
|
|
|
*/
|
2017-01-04 21:12:53 +03:00
|
|
|
function BrowserListener(aBrowser, aInstallingPrincipal, aInstall) {
|
2015-08-19 03:21:05 +03:00
|
|
|
this.browser = aBrowser;
|
|
|
|
this.principal = aInstallingPrincipal;
|
2017-01-04 21:12:53 +03:00
|
|
|
this.install = aInstall;
|
2015-08-19 03:21:05 +03:00
|
|
|
|
|
|
|
aBrowser.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_LOCATION);
|
|
|
|
Services.obs.addObserver(this, "message-manager-close", true);
|
|
|
|
|
2017-01-04 21:12:53 +03:00
|
|
|
aInstall.addListener(this);
|
2015-08-19 03:21:05 +03:00
|
|
|
|
|
|
|
this.registered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserListener.prototype = {
|
|
|
|
browser: null,
|
2017-01-04 21:12:53 +03:00
|
|
|
install: null,
|
2015-08-19 03:21:05 +03:00
|
|
|
registered: false,
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
unregister() {
|
2015-08-19 03:21:05 +03:00
|
|
|
if (!this.registered)
|
|
|
|
return;
|
|
|
|
this.registered = false;
|
|
|
|
|
|
|
|
Services.obs.removeObserver(this, "message-manager-close");
|
|
|
|
// The browser may have already been detached
|
|
|
|
if (this.browser.removeProgressListener)
|
|
|
|
this.browser.removeProgressListener(this);
|
|
|
|
|
2017-01-04 21:12:53 +03:00
|
|
|
this.install.removeListener(this);
|
|
|
|
this.install = null;
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2017-01-04 21:12:53 +03:00
|
|
|
cancelInstall() {
|
|
|
|
try {
|
|
|
|
this.install.cancel();
|
|
|
|
} catch (e) {
|
|
|
|
// install may have already failed or been cancelled, ignore these
|
2015-08-19 03:21:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
observe(subject, topic, data) {
|
2015-08-19 03:21:05 +03:00
|
|
|
if (subject != this.browser.messageManager)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The browser's message manager has closed and so the browser is
|
2017-01-04 21:12:53 +03:00
|
|
|
// going away, cancel the install
|
|
|
|
this.cancelInstall();
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onLocationChange(webProgress, request, location) {
|
2015-08-19 03:21:05 +03:00
|
|
|
if (this.browser.contentPrincipal && this.principal.subsumes(this.browser.contentPrincipal))
|
|
|
|
return;
|
|
|
|
|
2017-01-04 21:12:53 +03:00
|
|
|
// The browser has navigated to a new origin so cancel the install
|
|
|
|
this.cancelInstall();
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onDownloadCancelled(install) {
|
2017-01-04 21:12:53 +03:00
|
|
|
this.unregister();
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onDownloadFailed(install) {
|
2017-01-04 21:12:53 +03:00
|
|
|
this.unregister();
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onInstallFailed(install) {
|
2017-01-04 21:12:53 +03:00
|
|
|
this.unregister();
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onInstallEnded(install) {
|
2017-01-04 21:12:53 +03:00
|
|
|
this.unregister();
|
2015-08-19 03:21:05 +03:00
|
|
|
},
|
|
|
|
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIWebProgressListener,
|
2018-08-31 08:59:17 +03:00
|
|
|
Ci.nsIObserver]),
|
2015-08-19 03:21:05 +03:00
|
|
|
};
|
|
|
|
|
2010-08-24 05:04:06 +04: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
|
2016-12-30 02:34:54 +03:00
|
|
|
toString() {
|
2010-08-24 05:04:06 +04:00
|
|
|
return this.name || "";
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2010-08-24 05:04:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This represents an screenshot for an add-on
|
|
|
|
*
|
|
|
|
* @param aURL
|
|
|
|
* The URL to the full version of the screenshot
|
2011-09-05 14:26:06 +04:00
|
|
|
* @param aWidth
|
|
|
|
* The width in pixels of the screenshot
|
|
|
|
* @param aHeight
|
|
|
|
* The height in pixels of the screenshot
|
2010-08-24 05:04:06 +04:00
|
|
|
* @param aThumbnailURL
|
|
|
|
* The URL to the thumbnail version of the screenshot
|
2011-09-05 14:26:06 +04: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 05:04:06 +04:00
|
|
|
* @param aCaption
|
|
|
|
* The caption of the screenshot
|
|
|
|
*/
|
2011-09-05 14:26:06 +04:00
|
|
|
function AddonScreenshot(aURL, aWidth, aHeight, aThumbnailURL,
|
|
|
|
aThumbnailWidth, aThumbnailHeight, aCaption) {
|
2010-08-24 05:04:06 +04:00
|
|
|
this.url = aURL;
|
2011-09-05 14:26:06 +04: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 05:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
AddonScreenshot.prototype = {
|
|
|
|
url: null,
|
2011-09-05 14:26:06 +04:00
|
|
|
width: null,
|
|
|
|
height: null,
|
2010-08-24 05:04:06 +04:00
|
|
|
thumbnailURL: null,
|
2011-09-05 14:26:06 +04:00
|
|
|
thumbnailWidth: null,
|
|
|
|
thumbnailHeight: null,
|
2010-08-24 05:04:06 +04:00
|
|
|
caption: null,
|
|
|
|
|
|
|
|
// Returns the screenshot URL, defaulting to the empty string
|
2016-12-30 02:34:54 +03:00
|
|
|
toString() {
|
2010-08-24 05:04:06 +04:00
|
|
|
return this.url || "";
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2010-08-24 05:04:06 +04:00
|
|
|
|
2011-12-02 06:28:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This represents a compatibility override for an addon.
|
|
|
|
*
|
|
|
|
* @param aType
|
2018-04-04 08:22:07 +03:00
|
|
|
* Override type - "compatible" or "incompatible"
|
2011-12-02 06:28:15 +04:00
|
|
|
* @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.
|
|
|
|
*/
|
2018-08-31 08:59:17 +03:00
|
|
|
appMaxVersion: null,
|
2011-12-02 06:28:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-20 21:36:28 +04:00
|
|
|
/**
|
|
|
|
* A type of add-on, used by the UI to determine how to display different types
|
|
|
|
* of add-ons.
|
|
|
|
*
|
2012-05-30 10:34:32 +04:00
|
|
|
* @param aID
|
2011-05-20 21:36:28 +04: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
|
2017-08-24 21:16:37 +03:00
|
|
|
* The key for the string in the properties file.
|
2011-05-20 21:36:28 +04:00
|
|
|
* @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 10:34:32 +04:00
|
|
|
function AddonType(aID, aLocaleURI, aLocaleKey, aViewType, aUIPriority, aFlags) {
|
|
|
|
if (!aID)
|
2012-07-30 14:46:45 +04:00
|
|
|
throw Components.Exception("An AddonType must have an ID", Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2011-05-20 21:36:28 +04:00
|
|
|
if (aViewType && aUIPriority === undefined)
|
2012-07-30 14:46:45 +04:00
|
|
|
throw Components.Exception("An AddonType with a defined view must have a set UI priority",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2011-05-20 21:36:28 +04:00
|
|
|
if (!aLocaleKey)
|
2012-07-30 14:46:45 +04:00
|
|
|
throw Components.Exception("An AddonType must have a displayable name",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2011-05-20 21:36:28 +04:00
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
this.id = aID;
|
2011-05-20 21:36:28 +04:00
|
|
|
this.uiPriority = aUIPriority;
|
|
|
|
this.viewType = aViewType;
|
|
|
|
this.flags = aFlags;
|
|
|
|
|
|
|
|
if (aLocaleURI) {
|
2015-11-20 21:55:13 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "name", () => {
|
2011-05-20 21:36:28 +04:00
|
|
|
let bundle = Services.strings.createBundle(aLocaleURI);
|
2017-08-24 21:16:37 +03:00
|
|
|
return bundle.GetStringFromName(aLocaleKey);
|
2011-05-20 21:36:28 +04:00
|
|
|
});
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2011-05-20 21:36:28 +04:00
|
|
|
this.name = aLocaleKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-13 01:31:52 +04:00
|
|
|
var gStarted = false;
|
2012-05-10 22:33:02 +04:00
|
|
|
var gStartupComplete = false;
|
2012-02-15 06:07:29 +04:00
|
|
|
var gCheckCompatibility = true;
|
|
|
|
var gStrictCompatibility = true;
|
|
|
|
var gCheckUpdateSecurityDefault = true;
|
|
|
|
var gCheckUpdateSecurity = gCheckUpdateSecurityDefault;
|
|
|
|
var gUpdateEnabled = true;
|
|
|
|
var gAutoUpdateDefault = true;
|
2017-03-07 17:29:48 +03:00
|
|
|
var gWebExtensionsMinPlatformVersion = "";
|
2014-07-08 20:56:04 +04:00
|
|
|
var gShutdownBarrier = null;
|
2014-09-28 00:25:47 +04:00
|
|
|
var gRepoShutdownState = "";
|
|
|
|
var gShutdownInProgress = false;
|
2015-01-08 23:40:14 +03:00
|
|
|
var gPluginPageListener = null;
|
2017-04-15 20:13:39 +03:00
|
|
|
var gBrowserUpdated = null;
|
2010-10-13 01:31:52 +04:00
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* This is the real manager, kept here rather than in AddonManager to keep its
|
|
|
|
* contents hidden from API users.
|
2017-09-14 23:18:11 +03:00
|
|
|
* @class
|
|
|
|
* @lends AddonManager
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
|
|
|
var AddonManagerInternal = {
|
2017-05-19 07:56:05 +03:00
|
|
|
managerListeners: new Set(),
|
|
|
|
installListeners: new Set(),
|
|
|
|
addonListeners: new Set(),
|
|
|
|
typeListeners: new Set(),
|
2015-01-19 12:55:15 +03:00
|
|
|
pendingProviders: new Set(),
|
|
|
|
providers: new Set(),
|
2014-09-28 00:25:47 +04:00
|
|
|
providerShutdowns: new Map(),
|
2011-05-20 21:36:28 +04:00
|
|
|
types: {},
|
2011-06-30 01:50:43 +04:00
|
|
|
startupChanges: {},
|
2013-10-11 21:13:31 +04:00
|
|
|
// Store telemetry details per addon provider
|
|
|
|
telemetryDetails: {},
|
2016-06-08 01:57:14 +03:00
|
|
|
upgradeListeners: new Map(),
|
2013-10-11 21:13:31 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
recordTimestamp(name, value) {
|
2013-02-08 01:47:33 +04:00
|
|
|
this.TelemetryTimestamps.add(name, value);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
validateBlocklist() {
|
2014-04-15 04:44:56 +04:00
|
|
|
let appBlocklist = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
|
|
|
|
|
|
|
|
// If there is no application shipped blocklist then there is nothing to do
|
|
|
|
if (!appBlocklist.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let profileBlocklist = FileUtils.getFile(KEY_PROFILEDIR, [FILE_BLOCKLIST]);
|
|
|
|
|
|
|
|
// If there is no blocklist in the profile then copy the application shipped
|
|
|
|
// one there
|
|
|
|
if (!profileBlocklist.exists()) {
|
|
|
|
try {
|
|
|
|
appBlocklist.copyTo(profileBlocklist.parent, FILE_BLOCKLIST);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-04-15 04:44:56 +04:00
|
|
|
logger.warn("Failed to copy the application shipped blocklist to the profile", e);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
|
|
|
try {
|
|
|
|
let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIConverterInputStream);
|
|
|
|
fileStream.init(appBlocklist, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
|
|
|
|
cstream.init(fileStream, "UTF-8", 0, 0);
|
|
|
|
|
|
|
|
let data = "";
|
|
|
|
let str = {};
|
|
|
|
let read = 0;
|
|
|
|
do {
|
|
|
|
read = cstream.readString(0xffffffff, str);
|
|
|
|
data += str.value;
|
|
|
|
} while (read != 0);
|
|
|
|
|
2018-04-21 06:04:45 +03:00
|
|
|
let parser = new DOMParser();
|
2014-04-15 04:44:56 +04:00
|
|
|
var doc = parser.parseFromString(data, "text/xml");
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-04-15 04:44:56 +04:00
|
|
|
logger.warn("Application shipped blocklist could not be loaded", e);
|
|
|
|
return;
|
2016-12-31 05:47:25 +03:00
|
|
|
} finally {
|
2014-04-15 04:44:56 +04:00
|
|
|
try {
|
|
|
|
fileStream.close();
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-04-15 04:44:56 +04:00
|
|
|
logger.warn("Unable to close blocklist file stream", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the namespace is incorrect then ignore the application shipped
|
|
|
|
// blocklist
|
|
|
|
if (doc.documentElement.namespaceURI != XMLURI_BLOCKLIST) {
|
|
|
|
logger.warn("Application shipped blocklist has an unexpected namespace (" +
|
|
|
|
doc.documentElement.namespaceURI + ")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no lastupdate information then ignore the application shipped
|
|
|
|
// blocklist
|
|
|
|
if (!doc.documentElement.hasAttribute("lastupdate"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the application shipped blocklist is older than the profile blocklist
|
|
|
|
// then do nothing
|
|
|
|
if (doc.documentElement.getAttribute("lastupdate") <=
|
|
|
|
profileBlocklist.lastModifiedTime)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise copy the application shipped blocklist to the profile
|
|
|
|
try {
|
|
|
|
appBlocklist.copyTo(profileBlocklist.parent, FILE_BLOCKLIST);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-04-15 04:44:56 +04:00
|
|
|
logger.warn("Failed to copy the application shipped blocklist to the profile", e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
/**
|
|
|
|
* Start up a provider, and register its shutdown hook if it has one
|
2017-09-14 23:18:11 +03:00
|
|
|
*
|
|
|
|
* @param {string} aProvider - An add-on provider.
|
|
|
|
* @param {boolean} aAppChanged - Whether or not the app version has changed since last session.
|
|
|
|
* @param {string} aOldAppVersion - Previous application version, if changed.
|
|
|
|
* @param {string} aOldPlatformVersion - Previous platform version, if changed.
|
|
|
|
*
|
|
|
|
* @private
|
2014-09-28 00:25:47 +04:00
|
|
|
*/
|
|
|
|
_startProvider(aProvider, aAppChanged, aOldAppVersion, aOldPlatformVersion) {
|
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
logger.debug(`Starting provider: ${providerName(aProvider)}`);
|
2014-09-28 00:25:47 +04:00
|
|
|
callProvider(aProvider, "startup", null, aAppChanged, aOldAppVersion, aOldPlatformVersion);
|
2017-01-17 18:48:17 +03:00
|
|
|
if ("shutdown" in aProvider) {
|
2014-09-29 21:01:50 +04:00
|
|
|
let name = providerName(aProvider);
|
2014-09-28 00:25:47 +04:00
|
|
|
let AMProviderShutdown = () => {
|
2015-01-19 12:55:15 +03:00
|
|
|
// If the provider has been unregistered, it will have been removed from
|
|
|
|
// this.providers. If it hasn't been unregistered, then this is a normal
|
2018-04-04 08:22:07 +03:00
|
|
|
// shutdown - and we move it to this.pendingProviders in case we're
|
2015-01-19 12:55:15 +03:00
|
|
|
// running in a test that will start AddonManager again.
|
|
|
|
if (this.providers.has(aProvider)) {
|
|
|
|
this.providers.delete(aProvider);
|
|
|
|
this.pendingProviders.add(aProvider);
|
|
|
|
}
|
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
logger.debug("Calling shutdown blocker for " + name);
|
|
|
|
resolve(aProvider.shutdown());
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
logger.warn("Failure during shutdown of " + name, err);
|
|
|
|
AddonManagerPrivate.recordException("AMI", "Async shutdown of " + name, err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
logger.debug("Registering shutdown blocker for " + name);
|
|
|
|
this.providerShutdowns.set(aProvider, AMProviderShutdown);
|
|
|
|
AddonManager.shutdown.addBlocker(name, AMProviderShutdown);
|
|
|
|
}
|
2015-01-19 12:55:15 +03:00
|
|
|
|
|
|
|
this.pendingProviders.delete(aProvider);
|
|
|
|
this.providers.add(aProvider);
|
|
|
|
logger.debug(`Provider finished startup: ${providerName(aProvider)}`);
|
2014-09-28 00:25:47 +04:00
|
|
|
},
|
|
|
|
|
2015-09-10 20:57:39 +03:00
|
|
|
_getProviderByName(aName) {
|
|
|
|
for (let provider of this.providers) {
|
|
|
|
if (providerName(provider) == aName)
|
|
|
|
return provider;
|
|
|
|
}
|
2016-04-05 21:32:12 +03:00
|
|
|
return undefined;
|
2015-09-10 20:57:39 +03:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Initializes the AddonManager, loading any known providers and initializing
|
2010-08-24 05:04:06 +04:00
|
|
|
* them.
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
startup() {
|
2014-01-10 00:00:27 +04:00
|
|
|
try {
|
|
|
|
if (gStarted)
|
|
|
|
return;
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
this.recordTimestamp("AMI_startup_begin");
|
2013-02-08 01:47:33 +04:00
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
// clear this for xpcshell test restarts
|
|
|
|
for (let provider in this.telemetryDetails)
|
|
|
|
delete this.telemetryDetails[provider];
|
2013-10-11 21:13:31 +04:00
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
let appChanged = undefined;
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
let oldAppVersion = null;
|
|
|
|
try {
|
|
|
|
oldAppVersion = Services.prefs.getCharPref(PREF_EM_LAST_APP_VERSION);
|
|
|
|
appChanged = Services.appinfo.version != oldAppVersion;
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) { }
|
2011-05-19 22:04:44 +04:00
|
|
|
|
2017-04-15 20:13:39 +03:00
|
|
|
gBrowserUpdated = appChanged;
|
2016-10-19 12:38:29 +03:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
let oldPlatformVersion = Services.prefs.getCharPref(PREF_EM_LAST_PLATFORM_VERSION, "");
|
2014-01-10 00:00:27 +04:00
|
|
|
|
|
|
|
if (appChanged !== false) {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.debug("Application has been upgraded");
|
2014-01-10 00:00:27 +04: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));
|
2014-04-15 04:44:56 +04:00
|
|
|
this.validateBlocklist();
|
2014-01-10 00:00:27 +04:00
|
|
|
}
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2015-11-20 02:30:47 +03:00
|
|
|
if (!MOZ_COMPATIBILITY_NIGHTLY) {
|
|
|
|
PREF_EM_CHECK_COMPATIBILITY = PREF_EM_CHECK_COMPATIBILITY_BASE + "." +
|
|
|
|
Services.appinfo.version.replace(BRANCH_REGEXP, "$1");
|
|
|
|
}
|
2012-02-15 06:07:29 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
gCheckCompatibility = Services.prefs.getBoolPref(PREF_EM_CHECK_COMPATIBILITY,
|
|
|
|
gCheckCompatibility);
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_EM_CHECK_COMPATIBILITY, this);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
gStrictCompatibility = Services.prefs.getBoolPref(PREF_EM_STRICT_COMPATIBILITY,
|
|
|
|
gStrictCompatibility);
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_EM_STRICT_COMPATIBILITY, this);
|
2011-11-01 09:48:45 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
let defaultBranch = Services.prefs.getDefaultBranch("");
|
|
|
|
gCheckUpdateSecurityDefault = defaultBranch.getBoolPref(PREF_EM_CHECK_UPDATE_SECURITY,
|
|
|
|
gCheckUpdateSecurityDefault);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
gCheckUpdateSecurity = Services.prefs.getBoolPref(PREF_EM_CHECK_UPDATE_SECURITY,
|
|
|
|
gCheckUpdateSecurity);
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_EM_CHECK_UPDATE_SECURITY, this);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
gUpdateEnabled = Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED, gUpdateEnabled);
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_EM_UPDATE_ENABLED, this);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
gAutoUpdateDefault = Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT,
|
|
|
|
gAutoUpdateDefault);
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_EM_AUTOUPDATE_DEFAULT, this);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
gWebExtensionsMinPlatformVersion =
|
|
|
|
Services.prefs.getCharPref(PREF_MIN_WEBEXT_PLATFORM_VERSION,
|
|
|
|
gWebExtensionsMinPlatformVersion);
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.prefs.addObserver(PREF_MIN_WEBEXT_PLATFORM_VERSION, this);
|
2015-11-04 01:49:46 +03:00
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
// Ensure all default providers have had a chance to register themselves
|
2018-05-09 00:27:15 +03:00
|
|
|
for (let url of DEFAULT_PROVIDERS) {
|
|
|
|
try {
|
|
|
|
let scope = {};
|
|
|
|
ChromeUtils.import(url, scope);
|
|
|
|
// Sanity check - make sure the provider exports a symbol that
|
|
|
|
// has a 'startup' method
|
|
|
|
let syms = Object.keys(scope);
|
|
|
|
if ((syms.length < 1) ||
|
|
|
|
(typeof scope[syms[0]].startup != "function")) {
|
|
|
|
logger.warn("Provider " + url + " has no startup()");
|
|
|
|
AddonManagerPrivate.recordException("AMI", "provider " + url, "no startup()");
|
2014-01-10 00:00:27 +04:00
|
|
|
}
|
2018-05-09 00:27:15 +03:00
|
|
|
logger.debug("Loaded provider scope for " + url + ": " + Object.keys(scope).toSource());
|
|
|
|
} catch (e) {
|
|
|
|
AddonManagerPrivate.recordException("AMI", "provider " + url + " load failed", e);
|
|
|
|
logger.error("Exception loading default provider \"" + url + "\"", e);
|
2016-02-04 04:27:36 +03:00
|
|
|
}
|
2014-01-10 00:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load any providers registered in the category manager
|
2018-08-25 03:05:41 +03:00
|
|
|
for (let {entry, value: url} of Services.catMan.enumerateCategory(CATEGORY_PROVIDER_MODULE)) {
|
2013-12-12 04:23:36 +04:00
|
|
|
try {
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import(url, {});
|
2015-01-19 12:55:15 +03:00
|
|
|
logger.debug(`Loaded provider scope for ${url}`);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-01-10 00:00:27 +04:00
|
|
|
AddonManagerPrivate.recordException("AMI", "provider " + url + " load failed", e);
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.error("Exception loading provider " + entry + " from category \"" +
|
2014-01-10 00:00:27 +04:00
|
|
|
url + "\"", e);
|
2013-12-12 04:23:36 +04:00
|
|
|
}
|
2010-07-13 01:20:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
// Register our shutdown handler with the AsyncShutdown manager
|
2014-09-28 00:25:47 +04:00
|
|
|
gShutdownBarrier = new AsyncShutdown.Barrier("AddonManager: Waiting for providers to shut down.");
|
|
|
|
AsyncShutdown.profileBeforeChange.addBlocker("AddonManager: shutting down.",
|
|
|
|
this.shutdownManager.bind(this),
|
|
|
|
{fetchState: this.shutdownState.bind(this)});
|
2013-09-13 07:11:30 +04:00
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
// Once we start calling providers we must allow all normal methods to work.
|
|
|
|
gStarted = true;
|
2012-05-10 22:33:02 +04:00
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
for (let provider of this.pendingProviders) {
|
2014-09-28 00:25:47 +04:00
|
|
|
this._startProvider(provider, appChanged, oldAppVersion, oldPlatformVersion);
|
|
|
|
}
|
2011-06-30 01:50:43 +04:00
|
|
|
|
2014-01-10 00:00:27 +04: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-30 01:50:43 +04:00
|
|
|
|
2015-01-08 23:40:14 +03:00
|
|
|
// Support for remote about:plugins. Note that this module isn't loaded
|
|
|
|
// at the top because Services.appinfo is defined late in tests.
|
2018-07-27 04:09:12 +03:00
|
|
|
let { RemotePages } =
|
|
|
|
ChromeUtils.import("resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm", {});
|
2015-01-08 23:40:14 +03:00
|
|
|
|
|
|
|
gPluginPageListener = new RemotePages("about:plugins");
|
|
|
|
gPluginPageListener.addMessageListener("RequestPlugins", this.requestPlugins);
|
|
|
|
|
2014-01-10 00:00:27 +04:00
|
|
|
gStartupComplete = true;
|
|
|
|
this.recordTimestamp("AMI_startup_end");
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.error("startup failed", e);
|
2014-01-10 00:00:27 +04:00
|
|
|
AddonManagerPrivate.recordException("AMI", "startup failed", e);
|
|
|
|
}
|
2015-01-19 12:55:15 +03:00
|
|
|
|
2018-04-01 14:53:31 +03:00
|
|
|
let brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
let extensionsBundle = Services.strings.createBundle(
|
|
|
|
"chrome://global/locale/extensions.properties");
|
|
|
|
|
|
|
|
// When running in xpcshell tests, the default theme may already
|
|
|
|
// exist.
|
|
|
|
if (!LightweightThemeManager._builtInThemes.has(DEFAULT_THEME_ID)) {
|
|
|
|
let author = "Mozilla";
|
|
|
|
try {
|
|
|
|
author = brandBundle.GetStringFromName("vendorShortName");
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
LightweightThemeManager.addBuiltInTheme({
|
|
|
|
id: DEFAULT_THEME_ID,
|
|
|
|
name: extensionsBundle.GetStringFromName("defaultTheme.name"),
|
|
|
|
description: extensionsBundle.GetStringFromName("defaultTheme.description"),
|
|
|
|
iconURL: "chrome://mozapps/content/extensions/default-theme-icon.svg",
|
|
|
|
author,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
logger.debug("Completed startup sequence");
|
|
|
|
this.callManagerListeners("onStartup");
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a new AddonProvider.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @param {string} aProvider -The provider to register
|
|
|
|
* @param {string[]} [aTypes] - An optional array of add-on types
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
registerProvider(aProvider, aTypes) {
|
2012-05-30 10:34:32 +04: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);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
this.pendingProviders.add(aProvider);
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2011-05-20 21:36:28 +04:00
|
|
|
if (aTypes) {
|
2015-11-21 02:31:17 +03:00
|
|
|
for (let type of aTypes) {
|
|
|
|
if (!(type.id in this.types)) {
|
|
|
|
if (!VALID_TYPES_REGEXP.test(type.id)) {
|
|
|
|
logger.warn("Ignoring invalid type " + type.id);
|
2011-05-20 21:36:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-21 02:31:17 +03:00
|
|
|
this.types[type.id] = {
|
2016-12-30 02:34:54 +03:00
|
|
|
type,
|
2018-08-31 08:59:17 +03:00
|
|
|
providers: [aProvider],
|
2011-05-20 21:36:28 +04:00
|
|
|
};
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
let typeListeners = new Set(this.typeListeners);
|
2015-11-20 21:06:14 +03:00
|
|
|
for (let listener of typeListeners)
|
2015-11-21 02:31:17 +03:00
|
|
|
safeCall(() => listener.onTypeAdded(type));
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2015-11-21 02:31:17 +03:00
|
|
|
this.types[type.id].providers.push(aProvider);
|
2011-05-20 21:36:28 +04:00
|
|
|
}
|
2015-11-21 02:31:17 +03:00
|
|
|
}
|
2011-05-20 21:36:28 +04:00
|
|
|
}
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
// If we're registering after startup call this provider's startup.
|
2014-09-28 00:25:47 +04:00
|
|
|
if (gStarted) {
|
|
|
|
this._startProvider(aProvider);
|
|
|
|
}
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2010-06-17 07:13:54 +04:00
|
|
|
/**
|
|
|
|
* Unregisters an AddonProvider.
|
|
|
|
*
|
|
|
|
* @param aProvider
|
|
|
|
* The provider to unregister
|
2014-09-28 00:25:47 +04:00
|
|
|
* @return Whatever the provider's 'shutdown' method returns (if anything).
|
|
|
|
* For providers that have async shutdown methods returning Promises,
|
|
|
|
* the caller should wait for that Promise to resolve.
|
2010-06-17 07:13:54 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
unregisterProvider(aProvider) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aProvider || typeof aProvider != "object")
|
|
|
|
throw Components.Exception("aProvider must be specified",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
this.providers.delete(aProvider);
|
|
|
|
// The test harness will unregister XPIProvider *after* shutdown, which is
|
|
|
|
// after the provider will have been moved from providers to
|
|
|
|
// pendingProviders.
|
|
|
|
this.pendingProviders.delete(aProvider);
|
2010-06-17 07:13:54 +04:00
|
|
|
|
2011-05-20 21:36:28 +04:00
|
|
|
for (let type in this.types) {
|
2015-09-24 15:20:04 +03:00
|
|
|
this.types[type].providers = this.types[type].providers.filter(p => p != aProvider);
|
2011-05-20 21:36:28 +04:00
|
|
|
if (this.types[type].providers.length == 0) {
|
|
|
|
let oldType = this.types[type].type;
|
|
|
|
delete this.types[type];
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
let typeListeners = new Set(this.typeListeners);
|
2015-11-20 21:06:14 +03:00
|
|
|
for (let listener of typeListeners)
|
|
|
|
safeCall(() => listener.onTypeRemoved(oldType));
|
2011-05-20 21:36:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
// If we're unregistering after startup but before shutting down,
|
|
|
|
// remove the blocker for this provider's shutdown and call it.
|
|
|
|
// If we're already shutting down, just let gShutdownBarrier call it to avoid races.
|
|
|
|
if (gStarted && !gShutdownInProgress) {
|
2014-09-29 21:01:50 +04:00
|
|
|
logger.debug("Unregistering shutdown blocker for " + providerName(aProvider));
|
2014-09-28 00:25:47 +04:00
|
|
|
let shutter = this.providerShutdowns.get(aProvider);
|
|
|
|
if (shutter) {
|
|
|
|
this.providerShutdowns.delete(aProvider);
|
|
|
|
gShutdownBarrier.client.removeBlocker(shutter);
|
|
|
|
return shutter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
2010-06-17 07:13:54 +04:00
|
|
|
},
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
/**
|
|
|
|
* Mark a provider as safe to access via AddonManager APIs, before its
|
|
|
|
* startup has completed.
|
|
|
|
*
|
|
|
|
* Normally a provider isn't marked as safe until after its (synchronous)
|
|
|
|
* startup() method has returned. Until a provider has been marked safe,
|
|
|
|
* it won't be used by any of the AddonManager APIs. markProviderSafe()
|
|
|
|
* allows a provider to mark itself as safe during its startup; this can be
|
|
|
|
* useful if the provider wants to perform tasks that block startup, which
|
|
|
|
* happen after its required initialization tasks and therefore when the
|
|
|
|
* provider is in a safe state.
|
|
|
|
*
|
|
|
|
* @param aProvider Provider object to mark safe
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
markProviderSafe(aProvider) {
|
2015-01-19 12:55:15 +03:00
|
|
|
if (!gStarted) {
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aProvider || typeof aProvider != "object") {
|
|
|
|
throw Components.Exception("aProvider must be specified",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.pendingProviders.has(aProvider)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pendingProviders.delete(aProvider);
|
|
|
|
this.providers.add(aProvider);
|
|
|
|
},
|
|
|
|
|
2012-06-01 10:12:26 +04: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.
|
2014-09-29 21:01:50 +04:00
|
|
|
* WARNING: Do not use for asynchronous calls; callProviders() does not
|
|
|
|
* invoke callbacks if provider methods throw synchronous exceptions.
|
2012-06-01 10:12:26 +04:00
|
|
|
*
|
|
|
|
* @param aMethod
|
|
|
|
* The method name to call
|
|
|
|
* @see callProvider
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
callProviders(aMethod, ...aArgs) {
|
2012-06-01 10:12:26 +04:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
let providers = [...this.providers];
|
2012-06-01 10:12:26 +04:00
|
|
|
for (let provider of providers) {
|
|
|
|
try {
|
|
|
|
if (aMethod in provider)
|
|
|
|
provider[aMethod].apply(provider, aArgs);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2016-02-04 09:48:48 +03:00
|
|
|
reportProviderError(provider, aMethod, e);
|
2012-06-01 10:12:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-13 07:11:30 +04:00
|
|
|
/**
|
2014-09-28 00:25:47 +04:00
|
|
|
* Report the current state of asynchronous shutdown
|
2013-09-13 07:11:30 +04:00
|
|
|
*/
|
2014-09-28 00:25:47 +04:00
|
|
|
shutdownState() {
|
|
|
|
let state = [];
|
|
|
|
if (gShutdownBarrier) {
|
|
|
|
state.push({
|
|
|
|
name: gShutdownBarrier.client.name,
|
2018-08-31 08:59:17 +03:00
|
|
|
state: gShutdownBarrier.state,
|
2014-09-28 00:25:47 +04:00
|
|
|
});
|
2013-09-13 07:11:30 +04:00
|
|
|
}
|
2014-09-28 00:25:47 +04:00
|
|
|
state.push({
|
|
|
|
name: "AddonRepository: async shutdown",
|
2018-08-31 08:59:17 +03:00
|
|
|
state: gRepoShutdownState,
|
2014-09-28 00:25:47 +04:00
|
|
|
});
|
|
|
|
return state;
|
2013-09-13 07:11:30 +04:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04: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 07:11:30 +04:00
|
|
|
* @return Promise{null} that resolves when all providers and dependent modules
|
|
|
|
* have finished shutting down
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2017-05-12 15:42:39 +03:00
|
|
|
async shutdownManager() {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.debug("shutdown");
|
2015-01-19 12:55:15 +03:00
|
|
|
this.callManagerListeners("onShutdown");
|
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
gRepoShutdownState = "pending";
|
|
|
|
gShutdownInProgress = true;
|
2013-09-13 07:11:30 +04:00
|
|
|
// Clean up listeners
|
2012-02-15 06:07:29 +04:00
|
|
|
Services.prefs.removeObserver(PREF_EM_CHECK_COMPATIBILITY, this);
|
2011-11-01 09:48:45 +04:00
|
|
|
Services.prefs.removeObserver(PREF_EM_STRICT_COMPATIBILITY, this);
|
2012-02-15 06:07:29 +04: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);
|
2015-01-08 23:40:14 +03:00
|
|
|
gPluginPageListener.destroy();
|
|
|
|
gPluginPageListener = null;
|
2011-11-01 09:48:45 +04:00
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
let savedError = null;
|
|
|
|
// Only shut down providers if they've been started.
|
2013-09-13 07:11:30 +04:00
|
|
|
if (gStarted) {
|
2014-09-28 00:25:47 +04:00
|
|
|
try {
|
2017-05-12 15:42:39 +03:00
|
|
|
await gShutdownBarrier.wait();
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (err) {
|
2014-09-28 00:25:47 +04:00
|
|
|
savedError = err;
|
|
|
|
logger.error("Failure during wait for shutdown barrier", err);
|
2014-09-29 21:01:50 +04:00
|
|
|
AddonManagerPrivate.recordException("AMI", "Async shutdown of AddonManager providers", err);
|
2014-09-28 00:25:47 +04:00
|
|
|
}
|
2013-09-13 07:11:30 +04:00
|
|
|
}
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
// Shut down AddonRepository after providers (if any).
|
|
|
|
try {
|
|
|
|
gRepoShutdownState = "in progress";
|
2017-05-12 15:42:39 +03:00
|
|
|
await AddonRepository.shutdown();
|
2014-09-28 00:25:47 +04:00
|
|
|
gRepoShutdownState = "done";
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (err) {
|
2014-09-28 00:25:47 +04:00
|
|
|
savedError = err;
|
|
|
|
logger.error("Failure during AddonRepository shutdown", err);
|
|
|
|
AddonManagerPrivate.recordException("AMI", "Async shutdown of AddonRepository", err);
|
|
|
|
}
|
2014-07-08 20:56:04 +04:00
|
|
|
|
2014-09-28 00:25:47 +04:00
|
|
|
logger.debug("Async provider shutdown done");
|
2017-05-19 07:56:05 +03:00
|
|
|
this.managerListeners.clear();
|
|
|
|
this.installListeners.clear();
|
|
|
|
this.addonListeners.clear();
|
|
|
|
this.typeListeners.clear();
|
2014-09-28 00:25:47 +04:00
|
|
|
this.providerShutdowns.clear();
|
|
|
|
for (let type in this.startupChanges)
|
|
|
|
delete this.startupChanges[type];
|
|
|
|
gStarted = false;
|
|
|
|
gStartupComplete = false;
|
|
|
|
gShutdownBarrier = null;
|
|
|
|
gShutdownInProgress = false;
|
|
|
|
if (savedError) {
|
|
|
|
throw savedError;
|
|
|
|
}
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2018-04-15 05:38:18 +03:00
|
|
|
async requestPlugins({ target: port }) {
|
2015-01-08 23:40:14 +03:00
|
|
|
// Lists all the properties that plugins.html needs
|
|
|
|
const NEEDED_PROPS = ["name", "pluginLibraries", "pluginFullpath", "version",
|
|
|
|
"isActive", "blocklistState", "description",
|
|
|
|
"pluginMimeTypes"];
|
|
|
|
function filterProperties(plugin) {
|
|
|
|
let filtered = {};
|
|
|
|
for (let prop of NEEDED_PROPS) {
|
|
|
|
filtered[prop] = plugin[prop];
|
|
|
|
}
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
|
2018-04-15 05:38:18 +03:00
|
|
|
let aPlugins = await AddonManager.getAddonsByTypes(["plugin"]);
|
|
|
|
port.sendAsyncMessage("PluginList", aPlugins.map(filterProperties));
|
2015-01-08 23:40:14 +03:00
|
|
|
},
|
|
|
|
|
2011-11-01 09:48:45 +04:00
|
|
|
/**
|
|
|
|
* Notified when a preference we're interested in has changed.
|
|
|
|
*
|
|
|
|
* @see nsIObserver
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
observe(aSubject, aTopic, aData) {
|
2011-11-01 09:48:45 +04:00
|
|
|
switch (aData) {
|
2012-02-15 06:07:29 +04:00
|
|
|
case PREF_EM_CHECK_COMPATIBILITY: {
|
|
|
|
let oldValue = gCheckCompatibility;
|
2017-03-07 17:29:48 +03:00
|
|
|
gCheckCompatibility = Services.prefs.getBoolPref(PREF_EM_CHECK_COMPATIBILITY, true);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
|
|
|
this.callManagerListeners("onCompatibilityModeChanged");
|
|
|
|
|
|
|
|
if (gCheckCompatibility != oldValue)
|
|
|
|
this.updateAddonAppDisabledStates();
|
|
|
|
|
|
|
|
break;
|
2011-11-01 09:48:45 +04:00
|
|
|
}
|
2012-02-15 06:07:29 +04:00
|
|
|
case PREF_EM_STRICT_COMPATIBILITY: {
|
|
|
|
let oldValue = gStrictCompatibility;
|
2017-03-07 17:29:48 +03:00
|
|
|
gStrictCompatibility = Services.prefs.getBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
|
|
|
this.callManagerListeners("onCompatibilityModeChanged");
|
2011-11-01 09:48:45 +04:00
|
|
|
|
2012-02-15 06:07:29 +04:00
|
|
|
if (gStrictCompatibility != oldValue)
|
|
|
|
this.updateAddonAppDisabledStates();
|
2011-11-01 09:48:45 +04:00
|
|
|
|
2012-02-15 06:07:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_EM_CHECK_UPDATE_SECURITY: {
|
|
|
|
let oldValue = gCheckUpdateSecurity;
|
2017-03-07 17:29:48 +03:00
|
|
|
gCheckUpdateSecurity = Services.prefs.getBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, true);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
|
|
|
this.callManagerListeners("onCheckUpdateSecurityChanged");
|
|
|
|
|
|
|
|
if (gCheckUpdateSecurity != oldValue)
|
|
|
|
this.updateAddonAppDisabledStates();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_EM_UPDATE_ENABLED: {
|
2017-03-07 17:29:48 +03:00
|
|
|
gUpdateEnabled = Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED, true);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
|
|
|
this.callManagerListeners("onUpdateModeChanged");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_EM_AUTOUPDATE_DEFAULT: {
|
2017-03-07 17:29:48 +03:00
|
|
|
gAutoUpdateDefault = Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT, true);
|
2012-02-15 06:07:29 +04:00
|
|
|
|
|
|
|
this.callManagerListeners("onUpdateModeChanged");
|
|
|
|
break;
|
|
|
|
}
|
2015-11-04 01:49:46 +03:00
|
|
|
case PREF_MIN_WEBEXT_PLATFORM_VERSION: {
|
|
|
|
gWebExtensionsMinPlatformVersion = Services.prefs.getCharPref(PREF_MIN_WEBEXT_PLATFORM_VERSION);
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 09:48:45 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-17 00:04:50 +04:00
|
|
|
/**
|
|
|
|
* Replaces %...% strings in an addon url (update and updateInfo) with
|
|
|
|
* appropriate values.
|
|
|
|
*
|
|
|
|
* @param aAddon
|
2012-05-30 10:34:32 +04:00
|
|
|
* The Addon representing the add-on
|
2011-12-17 00:04:50 +04:00
|
|
|
* @param aUri
|
2012-05-30 10:34:32 +04:00
|
|
|
* The string representation of the URI to escape
|
2011-12-17 00:04:50 +04:00
|
|
|
* @param aAppVersion
|
|
|
|
* The optional application version to use for %APP_VERSION%
|
2012-05-30 10:34:32 +04:00
|
|
|
* @return The appropriately escaped URI.
|
2011-12-17 00:04:50 +04:00
|
|
|
*/
|
2016-12-31 05:47:25 +03:00
|
|
|
escapeAddonURI(aAddon, aUri, aAppVersion) {
|
2012-05-30 10:34:32 +04: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-17 00:04:50 +04:00
|
|
|
var addonStatus = aAddon.userDisabled || aAddon.softDisabled ? "userDisabled"
|
|
|
|
: "userEnabled";
|
|
|
|
|
|
|
|
if (!aAddon.isCompatible)
|
|
|
|
addonStatus += ",incompatible";
|
2018-03-27 23:03:50 +03:00
|
|
|
|
|
|
|
let {blocklistState} = aAddon;
|
|
|
|
if (blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
|
2011-12-17 00:04:50 +04:00
|
|
|
addonStatus += ",blocklisted";
|
2018-03-27 23:03:50 +03:00
|
|
|
if (blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
2011-12-17 00:04:50 +04:00
|
|
|
addonStatus += ",softblocked";
|
|
|
|
|
2018-03-27 23:03:50 +03:00
|
|
|
let params = new Map(Object.entries({
|
|
|
|
ITEM_ID: aAddon.id,
|
|
|
|
ITEM_VERSION: aAddon.version,
|
|
|
|
ITEM_STATUS: addonStatus,
|
|
|
|
APP_ID: Services.appinfo.ID,
|
|
|
|
APP_VERSION: aAppVersion ? aAppVersion : Services.appinfo.version,
|
|
|
|
REQ_VERSION: UPDATE_REQUEST_VERSION,
|
|
|
|
APP_OS: Services.appinfo.OS,
|
|
|
|
APP_ABI: Services.appinfo.XPCOMABI,
|
|
|
|
APP_LOCALE: getLocale(),
|
|
|
|
CURRENT_APP_VERSION: Services.appinfo.version,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let uri = aUri.replace(/%([A-Z_]+)%/g, (m0, m1) => params.get(m1) || m0);
|
2011-12-17 00:04:50 +04:00
|
|
|
|
|
|
|
// escape() does not properly encode + symbols in any embedded FVF strings.
|
|
|
|
return uri.replace(/\+/g, "%2B");
|
|
|
|
},
|
|
|
|
|
2017-01-20 06:28:08 +03:00
|
|
|
_updatePromptHandler(info) {
|
2017-02-16 20:17:52 +03:00
|
|
|
let oldPerms = info.existingAddon.userPermissions;
|
|
|
|
if (!oldPerms) {
|
|
|
|
// Updating from a legacy add-on, just let it proceed
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2017-01-20 06:28:08 +03:00
|
|
|
let newPerms = info.addon.userPermissions;
|
|
|
|
|
2017-02-03 03:57:29 +03:00
|
|
|
let difference = Extension.comparePermissions(oldPerms, newPerms);
|
2017-01-20 06:28:08 +03:00
|
|
|
|
|
|
|
// If there are no new permissions, just go ahead with the update
|
2017-03-24 07:45:25 +03:00
|
|
|
if (difference.origins.length == 0 && difference.permissions.length == 0) {
|
2017-01-20 06:28:08 +03:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let subject = {wrappedJSObject: {
|
|
|
|
addon: info.addon,
|
|
|
|
permissions: difference,
|
2018-08-31 08:59:17 +03:00
|
|
|
resolve, reject,
|
2018-09-19 19:43:11 +03:00
|
|
|
// Reference to the related AddonInstall object (used in AMTelemetry to
|
|
|
|
// link the recorded event to the other events from the same install flow).
|
|
|
|
install: info.install,
|
2017-01-20 06:28:08 +03:00
|
|
|
}};
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(subject, "webextension-update-permissions");
|
2017-01-20 06:28:08 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-02-12 21:44:43 +03:00
|
|
|
// Returns true if System Addons should be updated
|
|
|
|
systemUpdateEnabled() {
|
2018-05-15 00:43:25 +03:00
|
|
|
if (!Services.prefs.getBoolPref(PREF_SYS_ADDON_UPDATE_ENABLED)) {
|
2018-02-12 21:44:43 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Services.policies && !Services.policies.isAllowed("SysAddonUpdate")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Performs a background update check by starting an update for all add-ons
|
|
|
|
* that can be updated.
|
2014-05-07 19:04:25 +04:00
|
|
|
* @return Promise{null} Resolves when the background update check is complete
|
|
|
|
* (the resulting addon installations may still be in progress).
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
backgroundUpdateCheck() {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2017-05-12 15:47:41 +03:00
|
|
|
let buPromise = (async () => {
|
2014-09-02 19:47:11 +04:00
|
|
|
logger.debug("Background update check beginning");
|
2011-12-17 00:04:50 +04:00
|
|
|
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(null, "addons-background-update-start");
|
2010-08-24 05:04:06 +04:00
|
|
|
|
2014-05-07 18:48:10 +04:00
|
|
|
if (this.updateEnabled) {
|
2018-06-05 23:17:39 +03:00
|
|
|
// Keep track of all the async add-on updates happening in parallel
|
|
|
|
let updates = [];
|
|
|
|
|
|
|
|
updates.push(LightweightThemeManager.updateThemes());
|
2010-08-24 05:04:06 +04:00
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
let allAddons = await this.getAllAddons();
|
2011-12-17 00:04:50 +04:00
|
|
|
|
|
|
|
// Repopulate repository cache first, to ensure compatibility overrides
|
|
|
|
// are up to date before checking for addon updates.
|
2017-05-12 15:42:39 +03:00
|
|
|
await AddonRepository.backgroundUpdateCheck();
|
2014-05-07 18:48:10 +04:00
|
|
|
|
2014-05-20 21:16:37 +04:00
|
|
|
for (let addon of allAddons) {
|
2014-05-07 18:48:10 +04:00
|
|
|
// Check all add-ons for updates so that any compatibility updates will
|
|
|
|
// be applied
|
|
|
|
updates.push(new Promise((resolve, reject) => {
|
2014-05-20 21:16:37 +04:00
|
|
|
addon.findUpdates({
|
2016-12-30 02:34:54 +03:00
|
|
|
onUpdateAvailable(aAddon, aInstall) {
|
2014-03-14 16:52:55 +04:00
|
|
|
// Start installing updates when the add-on can be updated and
|
|
|
|
// background updates should be applied.
|
2014-05-20 21:16:37 +04:00
|
|
|
logger.debug("Found update for add-on ${id}", aAddon);
|
2014-03-14 16:52:55 +04:00
|
|
|
if (aAddon.permissions & AddonManager.PERM_CAN_UPGRADE &&
|
|
|
|
AddonManager.shouldAutoUpdate(aAddon)) {
|
2014-05-07 18:48:10 +04:00
|
|
|
// XXX we really should resolve when this install is done,
|
|
|
|
// not when update-available check completes, no?
|
2016-06-08 01:57:14 +03:00
|
|
|
logger.debug(`Starting upgrade install of ${aAddon.id}`);
|
2017-01-20 06:28:08 +03:00
|
|
|
if (WEBEXT_PERMISSION_PROMPTS) {
|
|
|
|
aInstall.promptHandler = (...args) => AddonManagerInternal._updatePromptHandler(...args);
|
|
|
|
}
|
2014-03-14 16:52:55 +04:00
|
|
|
aInstall.install();
|
|
|
|
}
|
|
|
|
},
|
2011-12-17 00:04:50 +04:00
|
|
|
|
2018-08-31 08:59:17 +03:00
|
|
|
onUpdateFinished: aAddon => { logger.debug("onUpdateFinished for ${id}", aAddon); resolve(); },
|
2014-03-14 16:52:55 +04:00
|
|
|
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
2014-05-07 18:48:10 +04:00
|
|
|
}));
|
|
|
|
}
|
2017-05-12 15:42:39 +03:00
|
|
|
await Promise.all(updates);
|
2011-12-17 00:04:50 +04:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:44:43 +03:00
|
|
|
if (AddonManagerInternal.systemUpdateEnabled()) {
|
2015-09-10 20:57:39 +03:00
|
|
|
try {
|
2017-05-12 15:42:39 +03:00
|
|
|
await AddonManagerInternal._getProviderByName("XPIProvider").updateSystemAddons();
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2015-09-10 20:57:39 +03:00
|
|
|
logger.warn("Failed to update system addons", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 19:04:25 +04:00
|
|
|
logger.debug("Background update check complete");
|
2014-05-07 18:48:10 +04:00
|
|
|
Services.obs.notifyObservers(null,
|
2017-04-14 22:51:39 +03:00
|
|
|
"addons-background-update-complete");
|
2017-05-12 15:47:41 +03:00
|
|
|
})();
|
2014-09-02 19:47:11 +04:00
|
|
|
// Fork the promise chain so we can log the error and let our caller see it too.
|
2017-06-19 13:32:37 +03:00
|
|
|
buPromise.catch(e => logger.warn("Error in background update", e));
|
2014-09-02 19:47:11 +04:00
|
|
|
return buPromise;
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2011-06-30 01:50:43 +04: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
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
addStartupChange(aType, aID) {
|
2012-05-30 10:34:32 +04: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 22:33:02 +04:00
|
|
|
if (gStartupComplete)
|
2011-06-30 01:50:43 +04:00
|
|
|
return;
|
2015-08-22 02:49:56 +03:00
|
|
|
logger.debug("Registering startup change '" + aType + "' for " + aID);
|
2011-06-30 01:50:43 +04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeStartupChange(aType, aID) {
|
2012-05-30 10:34:32 +04: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 22:33:02 +04:00
|
|
|
if (gStartupComplete)
|
2011-06-30 01:50:43 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(aType in this.startupChanges))
|
|
|
|
return;
|
|
|
|
|
2015-09-24 15:20:04 +03:00
|
|
|
this.startupChanges[aType] = this.startupChanges[aType].filter(aItem => aItem != aID);
|
2011-06-30 01:50:43 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 06:07:29 +04: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
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
callManagerListeners(aMethod, ...aArgs) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 10:12:26 +04:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
2012-05-30 10:34:32 +04:00
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
let managerListeners = new Set(this.managerListeners);
|
2012-06-01 10:12:26 +04:00
|
|
|
for (let listener of managerListeners) {
|
2012-02-15 06:07:29 +04:00
|
|
|
try {
|
|
|
|
if (aMethod in listener)
|
2012-06-20 13:12:11 +04:00
|
|
|
listener[aMethod].apply(listener, aArgs);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.warn("AddonManagerListener threw exception when calling " + aMethod, e);
|
2012-02-15 06:07:29 +04:00
|
|
|
}
|
2012-06-01 10:12:26 +04:00
|
|
|
}
|
2012-02-15 06:07:29 +04:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Calls all registered InstallListeners with an event. Any parameters after
|
|
|
|
* the extraListeners parameter are passed to the listener.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aMethod
|
|
|
|
* The method on the listeners to call
|
|
|
|
* @param aExtraListeners
|
2012-05-30 10:34:32 +04:00
|
|
|
* An optional array of extra InstallListeners to also call
|
2010-04-28 20:42:07 +04:00
|
|
|
* @return false if any of the listeners returned false, true otherwise
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
callInstallListeners(aMethod,
|
2012-10-24 13:58:00 +04:00
|
|
|
aExtraListeners, ...aArgs) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 10:12:26 +04:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
2012-05-30 10:34:32 +04: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-30 00:11:23 +04:00
|
|
|
let result = true;
|
2012-06-01 10:12:26 +04:00
|
|
|
let listeners;
|
2010-04-28 20:42:07 +04:00
|
|
|
if (aExtraListeners)
|
2017-05-19 07:56:05 +03:00
|
|
|
listeners = new Set(aExtraListeners.concat(Array.from(this.installListeners)));
|
2012-06-01 10:12:26 +04:00
|
|
|
else
|
2017-05-19 07:56:05 +03:00
|
|
|
listeners = new Set(this.installListeners);
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2012-06-01 10:12:26 +04:00
|
|
|
for (let listener of listeners) {
|
2010-04-30 00:11:23 +04:00
|
|
|
try {
|
2010-04-28 20:42:07 +04:00
|
|
|
if (aMethod in listener) {
|
2012-06-20 13:12:11 +04:00
|
|
|
if (listener[aMethod].apply(listener, aArgs) === false)
|
2010-04-30 00:11:23 +04:00
|
|
|
result = false;
|
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.warn("InstallListener threw exception when calling " + aMethod, e);
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
2012-06-01 10:12:26 +04:00
|
|
|
}
|
2010-04-30 00:11:23 +04:00
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls all registered AddonListeners with an event. Any parameters after
|
|
|
|
* the method parameter are passed to the listener.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aMethod
|
|
|
|
* The method on the listeners to call
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
callAddonListeners(aMethod, ...aArgs) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 10:12:26 +04:00
|
|
|
if (!aMethod || typeof aMethod != "string")
|
2012-05-30 10:34:32 +04:00
|
|
|
throw Components.Exception("aMethod must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
let addonListeners = new Set(this.addonListeners);
|
2012-06-01 10:12:26 +04:00
|
|
|
for (let listener of addonListeners) {
|
2010-04-30 00:11:23 +04:00
|
|
|
try {
|
2010-04-28 20:42:07 +04:00
|
|
|
if (aMethod in listener)
|
2012-06-20 13:12:11 +04:00
|
|
|
listener[aMethod].apply(listener, aArgs);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.warn("AddonListener threw exception when calling " + aMethod, e);
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
2012-06-01 10:12:26 +04:00
|
|
|
}
|
2010-04-30 00:11:23 +04: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 10:34:32 +04:00
|
|
|
* @param aID
|
|
|
|
* The ID of the enabled add-on
|
2010-04-28 20:42:07 +04: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-30 00:11:23 +04:00
|
|
|
*/
|
2018-06-08 23:02:43 +03:00
|
|
|
async notifyAddonChanged(aID, aType, aPendingRestart) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04: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);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
// Temporary hack until bug 520124 lands.
|
|
|
|
// We can get here during synchronous startup, at which point it's
|
|
|
|
// considered unsafe (and therefore disallowed by AddonManager.jsm) to
|
|
|
|
// access providers that haven't been initialized yet. Since this is when
|
|
|
|
// XPIProvider is starting up, XPIProvider can't access itself via APIs
|
|
|
|
// going through AddonManager.jsm. Furthermore, LightweightThemeManager may
|
|
|
|
// not be initialized until after XPIProvider is, and therefore would also
|
|
|
|
// be unaccessible during XPIProvider startup. Thankfully, these are the
|
|
|
|
// only two uses of this API, and we know it's safe to use this API with
|
|
|
|
// both providers; so we have this hack to allow bypassing the normal
|
|
|
|
// safetey guard.
|
|
|
|
// The notifyAddonChanged/addonChanged API will be unneeded and therefore
|
|
|
|
// removed by bug 520124, so this is a temporary quick'n'dirty hack.
|
|
|
|
let providers = [...this.providers, ...this.pendingProviders];
|
|
|
|
for (let provider of providers) {
|
2018-06-08 23:02:43 +03:00
|
|
|
let result = callProvider(provider, "addonChanged", null, aID, aType, aPendingRestart);
|
|
|
|
if (result) {
|
|
|
|
await result;
|
|
|
|
}
|
2015-01-19 12:55:15 +03:00
|
|
|
}
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2010-04-26 22:45:22 +04: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.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
updateAddonAppDisabledStates() {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-06-01 10:12:26 +04:00
|
|
|
this.callProviders("updateAddonAppDisabledStates");
|
2010-04-26 22:45:22 +04:00
|
|
|
},
|
2013-09-13 07:11:30 +04:00
|
|
|
|
2011-12-02 06:28:15 +04:00
|
|
|
/**
|
|
|
|
* Notifies all providers that the repository has updated its data for
|
|
|
|
* installed add-ons.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
updateAddonRepositoryData() {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2017-05-12 15:47:41 +03:00
|
|
|
return (async () => {
|
2016-12-17 21:52:42 +03:00
|
|
|
for (let provider of this.providers) {
|
2017-05-12 15:42:39 +03:00
|
|
|
await promiseCallProvider(provider, "updateAddonRepositoryData");
|
2011-12-02 06:28:15 +04:00
|
|
|
}
|
2016-12-17 21:52:42 +03:00
|
|
|
|
|
|
|
// only tests should care about this
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(null, "TEST:addon-repository-data-updated");
|
2017-05-12 15:47:41 +03:00
|
|
|
})();
|
2011-12-02 06:28:15 +04:00
|
|
|
},
|
2012-05-30 10:34:32 +04:00
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously gets an AddonInstall for a URL.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aUrl
|
2012-05-30 10:34:32 +04:00
|
|
|
* The string represenation of the URL the add-on is located at
|
2010-04-28 20:42:07 +04:00
|
|
|
* @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 10:49:29 +04:00
|
|
|
* @param aIcons
|
|
|
|
* Optional placeholder icons while the add-on is being downloaded
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aVersion
|
|
|
|
* An optional placeholder version while the add-on is being downloaded
|
2016-11-16 19:53:56 +03:00
|
|
|
* @param aBrowser
|
|
|
|
* An optional <browser> element for download permissions prompts.
|
2018-09-07 22:08:14 +03:00
|
|
|
* @param aTelemetryInfo
|
|
|
|
* An optional object which provides details about the installation source
|
|
|
|
* included in the addon manager telemetry events.
|
2010-04-28 20:42:07 +04:00
|
|
|
* @throws if the aUrl, aCallback or aMimetype arguments are not specified
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getInstallForURL(aUrl, aMimetype, aHash, aName,
|
2018-09-07 22:08:14 +03:00
|
|
|
aIcons, aVersion, aBrowser, aTelemetryInfo) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aUrl || typeof aUrl != "string")
|
|
|
|
throw Components.Exception("aURL must be a non-empty string",
|
|
|
|
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 10:49:29 +04: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 10:34:32 +04:00
|
|
|
|
|
|
|
if (aVersion && typeof aVersion != "string")
|
|
|
|
throw Components.Exception("aVersion must be a string or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
if (aBrowser && !Element.isInstance(aBrowser))
|
|
|
|
throw Components.Exception("aBrowser must be an Element or null",
|
2012-05-30 10:34:32 +04:00
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2016-12-18 00:49:41 +03:00
|
|
|
for (let provider of this.providers) {
|
2012-05-27 16:21:48 +04:00
|
|
|
if (callProvider(provider, "supportsMimetype", false, aMimetype)) {
|
2016-12-18 00:49:41 +03:00
|
|
|
return promiseCallProvider(
|
|
|
|
provider, "getInstallForURL", aUrl, aHash, aName, aIcons,
|
2018-09-07 22:08:14 +03:00
|
|
|
aVersion, aBrowser, aTelemetryInfo);
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
|
|
|
}
|
2016-12-18 00:49:41 +03:00
|
|
|
|
|
|
|
return Promise.resolve(null);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets an AddonInstall for an nsIFile.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aFile
|
2012-05-30 10:34:32 +04:00
|
|
|
* The nsIFile where the add-on is located
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aMimetype
|
|
|
|
* An optional mimetype hint for the add-on
|
2018-09-07 22:08:14 +03:00
|
|
|
* @param aTelemetryInfo
|
|
|
|
* An optional object which provides details about the installation source
|
|
|
|
* included in the addon manager telemetry events.
|
2010-04-28 20:42:07 +04:00
|
|
|
* @throws if the aFile or aCallback arguments are not specified
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2018-09-07 22:08:14 +03:00
|
|
|
getInstallForFile(aFile, aMimetype, aTelemetryInfo) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!(aFile instanceof Ci.nsIFile))
|
|
|
|
throw Components.Exception("aFile must be a nsIFile",
|
|
|
|
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-30 00:11:23 +04:00
|
|
|
|
2017-05-12 15:47:41 +03:00
|
|
|
return (async () => {
|
2016-12-17 21:52:42 +03:00
|
|
|
for (let provider of this.providers) {
|
2017-05-12 15:42:39 +03:00
|
|
|
let install = await promiseCallProvider(
|
2018-09-07 22:08:14 +03:00
|
|
|
provider, "getInstallForFile", aFile, aTelemetryInfo);
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
if (install)
|
|
|
|
return install;
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
2016-12-17 21:52:42 +03:00
|
|
|
|
|
|
|
return null;
|
2017-05-12 15:47:41 +03:00
|
|
|
})();
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets all current AddonInstalls optionally limiting to a list
|
|
|
|
* of types.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aTypes
|
|
|
|
* An optional array of types to retrieve. Each type is a string name
|
2012-05-30 10:34:32 +04:00
|
|
|
* @throws If the aCallback argument is not specified
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getInstallsByTypes(aTypes) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-12 15:47:41 +03:00
|
|
|
return (async () => {
|
2016-12-17 21:52:42 +03:00
|
|
|
let installs = [];
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
for (let provider of this.providers) {
|
2017-05-12 15:42:39 +03:00
|
|
|
let providerInstalls = await promiseCallProvider(
|
2016-12-17 21:52:42 +03:00
|
|
|
provider, "getInstallsByTypes", aTypes);
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
if (providerInstalls)
|
|
|
|
installs.push(...providerInstalls);
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
2016-12-17 21:52:42 +03:00
|
|
|
|
|
|
|
return installs;
|
2017-05-12 15:47:41 +03:00
|
|
|
})();
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2010-04-26 21:49:19 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously gets all current AddonInstalls.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getAllInstalls() {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
return this.getInstallsByTypes(null);
|
2010-04-26 21:49:19 +04:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Checks whether installation is enabled for a particular mimetype.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype to check
|
|
|
|
* @return true if installation is enabled for the mimetype
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
isInstallEnabled(aMimetype) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
let providers = [...this.providers];
|
2012-06-01 10:12:26 +04:00
|
|
|
for (let provider of providers) {
|
2012-05-27 16:21:48 +04:00
|
|
|
if (callProvider(provider, "supportsMimetype", false, aMimetype) &&
|
|
|
|
callProvider(provider, "isInstallEnabled"))
|
2010-04-30 00:11:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a particular source is allowed to install add-ons of a
|
|
|
|
* given mimetype.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype of the add-on
|
2015-08-19 03:21:05 +03:00
|
|
|
* @param aInstallingPrincipal
|
|
|
|
* The nsIPrincipal that initiated the install
|
2010-04-28 20:42:07 +04:00
|
|
|
* @return true if the source is allowed to install this mimetype
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
isInstallAllowed(aMimetype, aInstallingPrincipal) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-08-19 03:21:05 +03:00
|
|
|
if (!aInstallingPrincipal || !(aInstallingPrincipal instanceof Ci.nsIPrincipal))
|
|
|
|
throw Components.Exception("aInstallingPrincipal must be a nsIPrincipal",
|
2012-05-30 10:34:32 +04:00
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-01-19 12:55:15 +03:00
|
|
|
let providers = [...this.providers];
|
2012-06-01 10:12:26 +04:00
|
|
|
for (let provider of providers) {
|
2012-05-27 16:21:48 +04:00
|
|
|
if (callProvider(provider, "supportsMimetype", false, aMimetype) &&
|
2015-08-19 03:21:05 +03:00
|
|
|
callProvider(provider, "isInstallAllowed", null, aInstallingPrincipal))
|
2010-04-30 00:11:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
2010-04-26 23:19:18 +04:00
|
|
|
return false;
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2017-01-06 03:35:07 +03:00
|
|
|
installNotifyObservers(aTopic, aBrowser, aUri, aInstall, aInstallFn) {
|
|
|
|
let info = {
|
|
|
|
wrappedJSObject: {
|
|
|
|
browser: aBrowser,
|
|
|
|
originatingURI: aUri,
|
|
|
|
installs: [aInstall],
|
|
|
|
install: aInstallFn,
|
|
|
|
},
|
|
|
|
};
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(info, aTopic);
|
2017-01-06 03:35:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
startInstall(browser, url, install) {
|
|
|
|
this.installNotifyObservers("addon-install-started", browser, url, install);
|
|
|
|
|
2017-03-02 03:32:38 +03:00
|
|
|
// Local installs may already be in a failed state in which case
|
|
|
|
// we won't get any further events, detect those cases now.
|
|
|
|
if (install.state == AddonManager.STATE_DOWNLOADED && install.addon.appDisabled) {
|
2017-09-23 00:27:20 +03:00
|
|
|
install.cancel();
|
|
|
|
this.installNotifyObservers("addon-install-failed", browser, url, install);
|
|
|
|
return;
|
2017-03-02 03:32:38 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 03:35:07 +03:00
|
|
|
let self = this;
|
|
|
|
let listener = {
|
|
|
|
onDownloadCancelled() {
|
|
|
|
install.removeListener(listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadFailed() {
|
|
|
|
install.removeListener(listener);
|
|
|
|
self.installNotifyObservers("addon-install-failed", browser, url, install);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadEnded() {
|
|
|
|
if (install.addon.appDisabled) {
|
|
|
|
// App disabled items are not compatible and so fail to install
|
|
|
|
install.removeListener(listener);
|
|
|
|
install.cancel();
|
|
|
|
self.installNotifyObservers("addon-install-failed", browser, url, install);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallCancelled() {
|
|
|
|
install.removeListener(listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallFailed() {
|
|
|
|
install.removeListener(listener);
|
|
|
|
self.installNotifyObservers("addon-install-failed", browser, url, install);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallEnded() {
|
|
|
|
install.removeListener(listener);
|
|
|
|
|
|
|
|
// If installing a theme that is disabled and can be enabled
|
|
|
|
// then enable it
|
|
|
|
if (install.addon.type == "theme" &&
|
2018-02-08 20:57:31 +03:00
|
|
|
!!install.addon.userDisabled &&
|
|
|
|
!install.addon.appDisabled) {
|
2018-06-01 21:45:25 +03:00
|
|
|
install.addon.enable();
|
2017-01-06 03:35:07 +03:00
|
|
|
}
|
2017-01-20 21:28:47 +03:00
|
|
|
|
2017-02-03 01:29:34 +03:00
|
|
|
let needsRestart = (install.addon.pendingOperations != AddonManager.PENDING_NONE);
|
|
|
|
|
|
|
|
if (WEBEXT_PERMISSION_PROMPTS && !needsRestart) {
|
2017-01-20 21:28:47 +03:00
|
|
|
let subject = {wrappedJSObject: {target: browser, addon: install.addon}};
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(subject, "webextension-install-notify");
|
2017-01-20 21:28:47 +03:00
|
|
|
} else {
|
|
|
|
self.installNotifyObservers("addon-install-complete", browser, url, install);
|
|
|
|
}
|
2017-01-06 03:35:07 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
install.addListener(listener);
|
|
|
|
|
|
|
|
// Start downloading if it hasn't already begun
|
|
|
|
install.install();
|
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
2017-01-04 21:12:53 +03:00
|
|
|
* Starts installation of an AddonInstall notifying the registered
|
2010-04-30 00:11:23 +04:00
|
|
|
* web install listener of blocked or started installs.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aMimetype
|
|
|
|
* The mimetype of add-ons being installed
|
2014-11-05 06:20:52 +03:00
|
|
|
* @param aBrowser
|
|
|
|
* The optional browser element that started the installs
|
2015-08-19 03:21:05 +03:00
|
|
|
* @param aInstallingPrincipal
|
|
|
|
* The nsIPrincipal that initiated the install
|
2017-01-04 21:12:53 +03:00
|
|
|
* @param aInstall
|
|
|
|
* The AddonInstall to be installed
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2017-01-04 21:12:53 +03:00
|
|
|
installAddonFromWebpage(aMimetype, aBrowser,
|
|
|
|
aInstallingPrincipal, aInstall) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aMimetype || typeof aMimetype != "string")
|
|
|
|
throw Components.Exception("aMimetype must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
if (aBrowser && !Element.isInstance(aBrowser))
|
|
|
|
throw Components.Exception("aSource must be an Element, or null",
|
2012-05-30 10:34:32 +04:00
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-08-19 03:21:05 +03:00
|
|
|
if (!aInstallingPrincipal || !(aInstallingPrincipal instanceof Ci.nsIPrincipal))
|
|
|
|
throw Components.Exception("aInstallingPrincipal must be a nsIPrincipal",
|
2012-05-30 10:34:32 +04:00
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-08-31 21:23:39 +03:00
|
|
|
// When a chrome in-content UI has loaded a <browser> inside to host a
|
|
|
|
// website we want to do our security checks on the inner-browser but
|
|
|
|
// notify front-end that install events came from the outer-browser (the
|
|
|
|
// main tab's browser). Check this by seeing if the browser we've been
|
|
|
|
// passed is in a content type docshell and if so get the outer-browser.
|
|
|
|
let topBrowser = aBrowser;
|
2018-08-01 20:07:09 +03:00
|
|
|
let docShell = aBrowser.ownerGlobal.docShell;
|
2015-08-31 21:23:39 +03:00
|
|
|
if (docShell.itemType == Ci.nsIDocShellTreeItem.typeContent)
|
|
|
|
topBrowser = docShell.chromeEventHandler;
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
try {
|
2015-08-19 03:21:05 +03:00
|
|
|
if (!this.isInstallEnabled(aMimetype)) {
|
2017-01-04 21:12:53 +03:00
|
|
|
aInstall.cancel();
|
2015-08-19 03:21:05 +03:00
|
|
|
|
2017-01-06 03:35:07 +03:00
|
|
|
this.installNotifyObservers("addon-install-disabled", topBrowser,
|
|
|
|
aInstallingPrincipal.URI, aInstall);
|
2015-08-19 03:21:05 +03:00
|
|
|
return;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (!aBrowser.contentPrincipal || !aInstallingPrincipal.subsumes(aBrowser.contentPrincipal)) {
|
2017-01-04 21:12:53 +03:00
|
|
|
aInstall.cancel();
|
2015-08-19 03:21:05 +03:00
|
|
|
|
2017-01-06 03:35:07 +03:00
|
|
|
this.installNotifyObservers("addon-install-origin-blocked", topBrowser,
|
|
|
|
aInstallingPrincipal.URI, aInstall);
|
2015-08-19 03:21:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-04 21:12:53 +03:00
|
|
|
// The install may start now depending on the web install listener,
|
2015-08-19 03:21:05 +03:00
|
|
|
// listen for the browser navigating to a new origin and cancel the
|
2017-01-04 21:12:53 +03:00
|
|
|
// install in that case.
|
|
|
|
new BrowserListener(aBrowser, aInstallingPrincipal, aInstall);
|
2015-08-19 03:21:05 +03:00
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
let startInstall = (source) => {
|
|
|
|
AddonManagerInternal.setupPromptHandler(aBrowser, aInstallingPrincipal.URI, aInstall, true, source);
|
2017-01-06 03:35:07 +03:00
|
|
|
|
|
|
|
AddonManagerInternal.startInstall(aBrowser, aInstallingPrincipal.URI, aInstall);
|
|
|
|
};
|
2015-08-19 03:21:05 +03:00
|
|
|
if (!this.isInstallAllowed(aMimetype, aInstallingPrincipal)) {
|
2017-01-06 03:35:07 +03:00
|
|
|
this.installNotifyObservers("addon-install-blocked", topBrowser,
|
|
|
|
aInstallingPrincipal.URI, aInstall,
|
2017-02-28 20:08:49 +03:00
|
|
|
() => startInstall("other"));
|
2017-01-04 07:37:31 +03:00
|
|
|
} else {
|
2017-02-28 20:08:49 +03:00
|
|
|
startInstall("AMO");
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2014-01-10 00:00:27 +04:00
|
|
|
// In the event that the weblistener throws during instantiation or when
|
2017-01-04 21:12:53 +03:00
|
|
|
// calling onWebInstallBlocked or onWebInstallRequested the
|
|
|
|
// install should get cancelled.
|
2014-02-23 21:27:59 +04:00
|
|
|
logger.warn("Failure calling web installer", e);
|
2017-01-04 21:12:53 +03:00
|
|
|
aInstall.cancel();
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-01-04 21:13:16 +03:00
|
|
|
/**
|
|
|
|
* Starts installation of an AddonInstall created from add-ons manager
|
|
|
|
* front-end code (e.g., drag-and-drop of xpis or "Install Add-on from File"
|
|
|
|
*
|
|
|
|
* @param browser
|
|
|
|
* The browser element where the installation was initiated
|
|
|
|
* @param uri
|
|
|
|
* The URI of the page where the installation was initiated
|
|
|
|
* @param install
|
|
|
|
* The AddonInstall to be installed
|
|
|
|
*/
|
|
|
|
installAddonFromAOM(browser, uri, install) {
|
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
AddonManagerInternal.setupPromptHandler(browser, uri, install, true, "local");
|
2017-01-06 03:35:07 +03:00
|
|
|
AddonManagerInternal.startInstall(browser, uri, install);
|
2017-01-04 21:13:16 +03:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Adds a new InstallListener if the listener is not already registered.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aListener
|
|
|
|
* The InstallListener to add
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
addInstallListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a InstallListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2013-09-13 07:11:30 +04:00
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.installListeners.add(aListener);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an InstallListener if the listener is registered.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aListener
|
|
|
|
* The InstallListener to remove
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeInstallListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a InstallListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.installListeners.delete(aListener);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
2017-09-14 23:18:11 +03:00
|
|
|
/**
|
2016-06-08 01:57:14 +03:00
|
|
|
* Adds new or overrides existing UpgradeListener.
|
|
|
|
*
|
|
|
|
* @param aInstanceID
|
2016-08-02 19:37:01 +03:00
|
|
|
* The instance ID of an addon to register a listener for.
|
2016-06-08 01:57:14 +03:00
|
|
|
* @param aCallback
|
|
|
|
* The callback to invoke when updates are available for this addon.
|
|
|
|
* @throws if there is no addon matching the instanceID
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
addUpgradeListener(aInstanceID, aCallback) {
|
2018-04-22 01:15:10 +03:00
|
|
|
if (!aInstanceID || typeof aInstanceID != "symbol")
|
|
|
|
throw Components.Exception("aInstanceID must be a symbol",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2016-06-08 01:57:14 +03:00
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
if (!aCallback || typeof aCallback != "function")
|
|
|
|
throw Components.Exception("aCallback must be a function",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2016-06-08 01:57:14 +03:00
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
let addonId = this.syncGetAddonIDByInstanceID(aInstanceID);
|
|
|
|
if (!addonId) {
|
|
|
|
throw Error(`No addon matching instanceID: ${String(aInstanceID)}`);
|
|
|
|
}
|
|
|
|
logger.debug(`Registering upgrade listener for ${addonId}`);
|
|
|
|
this.upgradeListeners.set(addonId, aCallback);
|
2016-06-08 01:57:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an UpgradeListener if the listener is registered.
|
|
|
|
*
|
|
|
|
* @param aInstanceID
|
|
|
|
* The instance ID of the addon to remove
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeUpgradeListener(aInstanceID) {
|
2016-06-08 01:57:14 +03:00
|
|
|
if (!aInstanceID || typeof aInstanceID != "symbol")
|
|
|
|
throw Components.Exception("aInstanceID must be a symbol",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
let addonId = this.syncGetAddonIDByInstanceID(aInstanceID);
|
|
|
|
if (!addonId) {
|
|
|
|
throw Error(`No addon for instanceID: ${aInstanceID}`);
|
|
|
|
}
|
|
|
|
if (this.upgradeListeners.has(addonId)) {
|
|
|
|
this.upgradeListeners.delete(addonId);
|
|
|
|
} else {
|
|
|
|
throw Error(`No upgrade listener registered for addon ID: ${addonId}`);
|
|
|
|
}
|
2016-06-08 01:57:14 +03:00
|
|
|
},
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2015-11-03 21:07:08 +03:00
|
|
|
/**
|
2015-12-07 22:53:11 +03:00
|
|
|
* Installs a temporary add-on from a local file or directory.
|
2017-09-14 23:18:11 +03:00
|
|
|
*
|
2015-12-07 22:53:11 +03:00
|
|
|
* @param aFile
|
|
|
|
* An nsIFile for the file or directory of the add-on to be
|
|
|
|
* temporarily installed.
|
2017-09-14 23:18:11 +03:00
|
|
|
* @returns a Promise that rejects if the add-on is not a valid restartless
|
|
|
|
* add-on or if the same ID is already temporarily installed.
|
2015-11-03 21:07:08 +03:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
installTemporaryAddon(aFile) {
|
2015-11-03 21:07:08 +03:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
if (!(aFile instanceof Ci.nsIFile))
|
|
|
|
throw Components.Exception("aFile must be a nsIFile",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
return AddonManagerInternal._getProviderByName("XPIProvider")
|
|
|
|
.installTemporaryAddon(aFile);
|
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
syncGetAddonIDByInstanceID(aInstanceID) {
|
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
if (!aInstanceID || typeof aInstanceID != "symbol")
|
|
|
|
throw Components.Exception("aInstanceID must be a Symbol()",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
return AddonManagerInternal._getProviderByName("XPIProvider")
|
|
|
|
.getAddonIDByInstanceID(aInstanceID);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2015-10-14 12:03:40 +03:00
|
|
|
/**
|
|
|
|
* Gets an icon from the icon set provided by the add-on
|
|
|
|
* that is closest to the specified size.
|
|
|
|
*
|
|
|
|
* The optional window parameter will be used to determine
|
|
|
|
* the screen resolution and select a more appropriate icon.
|
|
|
|
* Calling this method with 48px on retina screens will try to
|
|
|
|
* match an icon of size 96px.
|
|
|
|
*
|
|
|
|
* @param aAddon
|
2015-11-24 20:20:26 +03:00
|
|
|
* An addon object, meaning:
|
|
|
|
* An object with either an icons property that is a key-value
|
|
|
|
* list of icon size and icon URL, or an object having an iconURL
|
|
|
|
* and icon64URL property.
|
2015-10-14 12:03:40 +03:00
|
|
|
* @param aSize
|
|
|
|
* Ideal icon size in pixels
|
|
|
|
* @param aWindow
|
|
|
|
* Optional window object for determining the correct scale.
|
|
|
|
* @return {String} The absolute URL of the icon or null if the addon doesn't have icons
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getPreferredIconURL(aAddon, aSize, aWindow = undefined) {
|
2015-10-14 12:03:40 +03:00
|
|
|
if (aWindow && aWindow.devicePixelRatio) {
|
|
|
|
aSize *= aWindow.devicePixelRatio;
|
|
|
|
}
|
|
|
|
|
|
|
|
let icons = aAddon.icons;
|
|
|
|
|
|
|
|
// certain addon-types only have iconURLs
|
|
|
|
if (!icons) {
|
|
|
|
icons = {};
|
|
|
|
if (aAddon.iconURL) {
|
|
|
|
icons[32] = aAddon.iconURL;
|
|
|
|
icons[48] = aAddon.iconURL;
|
|
|
|
}
|
|
|
|
if (aAddon.icon64URL) {
|
|
|
|
icons[64] = aAddon.icon64URL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// quick return if the exact size was found
|
|
|
|
if (icons[aSize]) {
|
|
|
|
return icons[aSize];
|
|
|
|
}
|
|
|
|
|
|
|
|
let bestSize = null;
|
|
|
|
|
|
|
|
for (let size of Object.keys(icons)) {
|
2015-11-24 20:20:26 +03:00
|
|
|
if (!INTEGER.test(size)) {
|
2015-10-14 12:03:40 +03:00
|
|
|
throw Components.Exception("Invalid icon size, must be an integer",
|
|
|
|
Cr.NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
}
|
|
|
|
|
2015-11-24 20:20:26 +03:00
|
|
|
size = parseInt(size, 10);
|
|
|
|
|
2015-10-14 12:03:40 +03:00
|
|
|
if (!bestSize) {
|
|
|
|
bestSize = size;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > aSize && bestSize > aSize) {
|
|
|
|
// If both best size and current size are larger than the wanted size then choose
|
|
|
|
// the one closest to the wanted size
|
|
|
|
bestSize = Math.min(bestSize, size);
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2015-10-14 12:03:40 +03:00
|
|
|
// Otherwise choose the largest of the two so we'll prefer sizes as close to below aSize
|
|
|
|
// or above aSize
|
|
|
|
bestSize = Math.max(bestSize, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return icons[bestSize] || null;
|
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously gets an add-on with a specific ID.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @type {function}
|
|
|
|
* @param {string} aID
|
2010-04-28 20:42:07 +04:00
|
|
|
* The ID of the add-on to retrieve
|
2017-09-14 23:18:11 +03:00
|
|
|
* @returns {Promise} resolves with the found Addon or null if no such add-on exists. Never rejects.
|
2015-05-12 22:39:52 +03:00
|
|
|
* @throws if the aID argument is not specified
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getAddonByID(aID) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aID || typeof aID != "string")
|
|
|
|
throw Components.Exception("aID must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-12-03 05:40:59 +03:00
|
|
|
let promises = Array.from(this.providers,
|
|
|
|
p => promiseCallProvider(p, "getAddonByID", aID));
|
2015-05-12 22:39:52 +03:00
|
|
|
return Promise.all(promises).then(aAddons => {
|
|
|
|
return aAddons.find(a => !!a) || null;
|
2010-04-30 00:11:23 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-11-05 05:04:15 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously get an add-on with a specific Sync GUID.
|
|
|
|
*
|
|
|
|
* @param aGUID
|
|
|
|
* String GUID of add-on to retrieve
|
2016-12-17 21:52:42 +03:00
|
|
|
* @throws if the aGUID argument is not specified
|
2011-11-05 05:04:15 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getAddonBySyncGUID(aGUID) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aGUID || typeof aGUID != "string")
|
|
|
|
throw Components.Exception("aGUID must be a non-empty string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-12 15:47:41 +03:00
|
|
|
return (async () => {
|
2016-12-17 21:52:42 +03:00
|
|
|
for (let provider of this.providers) {
|
2017-05-12 15:42:39 +03:00
|
|
|
let addon = await promiseCallProvider(
|
2016-12-17 21:52:42 +03:00
|
|
|
provider, "getAddonBySyncGUID", aGUID);
|
2011-11-05 05:04:15 +04:00
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
if (addon)
|
|
|
|
return addon;
|
2011-11-05 05:04:15 +04:00
|
|
|
}
|
2016-12-17 21:52:42 +03:00
|
|
|
|
|
|
|
return null;
|
2017-05-12 15:47:41 +03:00
|
|
|
})();
|
2011-11-05 05:04:15 +04:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously gets an array of add-ons.
|
|
|
|
*
|
2012-05-30 10:34:32 +04:00
|
|
|
* @param aIDs
|
2010-04-28 20:42:07 +04:00
|
|
|
* The array of IDs to retrieve
|
2015-05-12 22:39:52 +03:00
|
|
|
* @return {Promise}
|
|
|
|
* @resolves The array of found add-ons.
|
|
|
|
* @rejects Never
|
|
|
|
* @throws if the aIDs argument is not specified
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getAddonsByIDs(aIDs) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!Array.isArray(aIDs))
|
|
|
|
throw Components.Exception("aIDs must be an array",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2015-12-03 05:40:59 +03:00
|
|
|
let promises = aIDs.map(a => AddonManagerInternal.getAddonByID(a));
|
2015-05-12 22:39:52 +03:00
|
|
|
return Promise.all(promises);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously gets add-ons of specific types.
|
|
|
|
*
|
2010-04-28 20:42:07 +04:00
|
|
|
* @param aTypes
|
|
|
|
* An optional array of types to retrieve. Each type is a string name
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getAddonsByTypes(aTypes) {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-12 15:47:41 +03:00
|
|
|
return (async () => {
|
2016-12-17 21:52:42 +03:00
|
|
|
let addons = [];
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
for (let provider of this.providers) {
|
2017-05-12 15:42:39 +03:00
|
|
|
let providerAddons = await promiseCallProvider(
|
2016-12-17 21:52:42 +03:00
|
|
|
provider, "getAddonsByTypes", aTypes);
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
if (providerAddons)
|
|
|
|
addons.push(...providerAddons);
|
2010-04-30 00:11:23 +04:00
|
|
|
}
|
2016-12-17 21:52:42 +03:00
|
|
|
|
|
|
|
return addons;
|
2017-05-12 15:47:41 +03:00
|
|
|
})();
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2017-05-18 23:07:14 +03:00
|
|
|
/**
|
|
|
|
* Gets active add-ons of specific types.
|
|
|
|
*
|
|
|
|
* This is similar to getAddonsByTypes() but it may return a limited
|
|
|
|
* amount of information about only active addons. Consequently, it
|
|
|
|
* can be implemented by providers using only immediately available
|
|
|
|
* data as opposed to getAddonsByTypes which may require I/O).
|
|
|
|
*
|
|
|
|
* @param aTypes
|
|
|
|
* An optional array of types to retrieve. Each type is a string name
|
2017-11-21 22:00:07 +03:00
|
|
|
*
|
|
|
|
* @resolve {addons: Array, fullData: bool}
|
|
|
|
* fullData is true if addons contains all the data we have on those
|
|
|
|
* addons. It is false if addons only contains partial data.
|
2017-05-18 23:07:14 +03:00
|
|
|
*/
|
|
|
|
async getActiveAddons(aTypes) {
|
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
if (aTypes && !Array.isArray(aTypes))
|
|
|
|
throw Components.Exception("aTypes must be an array or null",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-11-21 22:00:07 +03:00
|
|
|
let addons = [], fullData = true;
|
2017-05-18 23:07:14 +03:00
|
|
|
|
|
|
|
for (let provider of this.providers) {
|
2017-11-21 22:00:07 +03:00
|
|
|
let providerAddons, providerFullData;
|
2017-05-18 23:07:14 +03:00
|
|
|
if ("getActiveAddons" in provider) {
|
2017-11-21 22:00:07 +03:00
|
|
|
({addons: providerAddons, fullData: providerFullData} = await callProvider(provider, "getActiveAddons", null, aTypes));
|
2017-05-18 23:07:14 +03:00
|
|
|
} else {
|
|
|
|
providerAddons = await promiseCallProvider(provider, "getAddonsByTypes", aTypes);
|
|
|
|
providerAddons = providerAddons.filter(a => a.isActive);
|
2017-11-21 22:00:07 +03:00
|
|
|
providerFullData = true;
|
2017-05-18 23:07:14 +03:00
|
|
|
}
|
|
|
|
|
2017-11-21 22:00:07 +03:00
|
|
|
if (providerAddons) {
|
2017-05-18 23:07:14 +03:00
|
|
|
addons.push(...providerAddons);
|
2017-11-21 22:00:07 +03:00
|
|
|
fullData = fullData && providerFullData;
|
|
|
|
}
|
2017-05-18 23:07:14 +03:00
|
|
|
}
|
|
|
|
|
2017-11-21 22:00:07 +03:00
|
|
|
return {addons, fullData};
|
2017-05-18 23:07:14 +03:00
|
|
|
},
|
|
|
|
|
2010-04-26 21:49:19 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously gets all installed add-ons.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getAllAddons() {
|
2012-05-10 22:33:02 +04:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2016-12-17 21:52:42 +03:00
|
|
|
return this.getAddonsByTypes(null);
|
2010-04-26 21:49:19 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 06:07:29 +04:00
|
|
|
/**
|
|
|
|
* Adds a new AddonManagerListener if the listener is not already registered.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @param {AddonManagerListener} aListener
|
2012-02-15 06:07:29 +04:00
|
|
|
* The listener to add
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
addManagerListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonManagerListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.managerListeners.add(aListener);
|
2012-02-15 06:07:29 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an AddonManagerListener if the listener is registered.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @param {AddonManagerListener} aListener
|
2012-02-15 06:07:29 +04:00
|
|
|
* The listener to remove
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeManagerListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonManagerListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.managerListeners.delete(aListener);
|
2012-02-15 06:07:29 +04:00
|
|
|
},
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
/**
|
|
|
|
* Adds a new AddonListener if the listener is not already registered.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @param {AddonManagerListener} aListener
|
|
|
|
* The AddonListener to add.
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
addAddonListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.addonListeners.add(aListener);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an AddonListener if the listener is registered.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @param {object} aListener
|
2012-05-30 10:34:32 +04:00
|
|
|
* The AddonListener to remove
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeAddonListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be an AddonListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.addonListeners.delete(aListener);
|
2010-09-14 10:56:54 +04:00
|
|
|
},
|
2011-01-15 00:29:27 +03:00
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
/**
|
|
|
|
* Adds a new TypeListener if the listener is not already registered.
|
|
|
|
*
|
2017-09-14 23:18:11 +03:00
|
|
|
* @param {TypeListener} aListener
|
2012-05-30 10:34:32 +04:00
|
|
|
* The TypeListener to add
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
addTypeListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a TypeListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.typeListeners.add(aListener);
|
2011-05-20 21:36:28 +04:00
|
|
|
},
|
|
|
|
|
2012-05-30 10:34:32 +04:00
|
|
|
/**
|
|
|
|
* Removes an TypeListener if the listener is registered.
|
|
|
|
*
|
|
|
|
* @param aListener
|
|
|
|
* The TypeListener to remove
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeTypeListener(aListener) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aListener || typeof aListener != "object")
|
|
|
|
throw Components.Exception("aListener must be a TypeListener object",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
2017-05-19 07:56:05 +03:00
|
|
|
this.typeListeners.delete(aListener);
|
2011-05-20 21:36:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get addonTypes() {
|
2016-02-05 21:31:08 +03:00
|
|
|
// A read-only wrapper around the types dictionary
|
|
|
|
return new Proxy(this.types, {
|
|
|
|
defineProperty(target, property, descriptor) {
|
|
|
|
// Not allowed to define properties
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteProperty(target, property) {
|
|
|
|
// Not allowed to delete properties
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
get(target, property, receiver) {
|
|
|
|
if (!target.hasOwnProperty(property))
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
return target[property].type;
|
|
|
|
},
|
|
|
|
|
|
|
|
getOwnPropertyDescriptor(target, property) {
|
|
|
|
if (!target.hasOwnProperty(property))
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
return {
|
|
|
|
value: target[property].type,
|
|
|
|
writable: false,
|
|
|
|
// Claim configurability to maintain the proxy invariants.
|
|
|
|
configurable: true,
|
2018-08-31 08:59:17 +03:00
|
|
|
enumerable: true,
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2016-02-05 21:31:08 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
preventExtensions(target) {
|
|
|
|
// Not allowed to prevent adding new properties
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
set(target, property, value, receiver) {
|
|
|
|
// Not allowed to set properties
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPrototypeOf(target, prototype) {
|
|
|
|
// Not allowed to change prototype
|
|
|
|
return false;
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2016-02-05 21:31:08 +03:00
|
|
|
});
|
2011-05-20 21:36:28 +04:00
|
|
|
},
|
|
|
|
|
2010-09-14 10:56:54 +04:00
|
|
|
get autoUpdateDefault() {
|
2012-02-15 06:07:29 +04: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 09:48:45 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get strictCompatibility() {
|
|
|
|
return gStrictCompatibility;
|
2012-02-15 06:07:29 +04: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 22:39:29 +04:00
|
|
|
},
|
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
setupPromptHandler(browser, url, install, requireConfirm, source) {
|
2017-01-06 03:35:07 +03:00
|
|
|
install.promptHandler = info => new Promise((resolve, _reject) => {
|
|
|
|
let reject = () => {
|
|
|
|
this.installNotifyObservers("addon-install-cancelled",
|
|
|
|
browser, url, install);
|
|
|
|
_reject();
|
|
|
|
};
|
|
|
|
|
|
|
|
// All installs end up in this callback when the add-on is available
|
|
|
|
// for installation. There are numerous different things that can
|
|
|
|
// happen from here though. For webextensions, if the application
|
|
|
|
// implements webextension permission prompts, those always take
|
|
|
|
// precedence.
|
|
|
|
// If this add-on is not a webextension or if the application does not
|
|
|
|
// implement permission prompts, no confirmation is displayed for
|
|
|
|
// installs created with mozAddonManager (in which case requireConfirm
|
|
|
|
// is false).
|
|
|
|
// In the remaining cases, a confirmation prompt is displayed but the
|
|
|
|
// application may override it either by implementing the
|
|
|
|
// "@mozilla.org/addons/web-install-prompt;1" contract or by setting
|
|
|
|
// the customConfirmationUI preference and responding to the
|
|
|
|
// "addon-install-confirmation" notification. If the application
|
|
|
|
// does not implement its own prompt, use the built-in xul dialog.
|
|
|
|
if (info.addon.userPermissions && WEBEXT_PERMISSION_PROMPTS) {
|
2017-02-03 03:57:29 +03:00
|
|
|
let subject = {
|
|
|
|
wrappedJSObject: {
|
|
|
|
target: browser,
|
2017-02-28 20:08:49 +03:00
|
|
|
info: Object.assign({resolve, reject, source}, info),
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-01-06 03:35:07 +03:00
|
|
|
};
|
2017-02-17 00:31:50 +03:00
|
|
|
subject.wrappedJSObject.info.permissions = info.addon.userPermissions;
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(subject, "webextension-permission-prompt");
|
2017-01-06 03:35:07 +03:00
|
|
|
} else if (requireConfirm) {
|
|
|
|
// The methods below all want to call the install() or cancel()
|
|
|
|
// method on the provided AddonInstall object to either accept
|
|
|
|
// or reject the confirmation. Fit that into our promise-based
|
|
|
|
// control flow by wrapping the install object. However,
|
|
|
|
// xpInstallConfirm.xul matches the install object it is passed
|
|
|
|
// with the argument passed to an InstallListener, so give it
|
|
|
|
// access to the underlying object through the .wrapped property.
|
|
|
|
let proxy = new Proxy(install, {
|
|
|
|
get(target, property) {
|
|
|
|
if (property == "install") {
|
|
|
|
return resolve;
|
|
|
|
} else if (property == "cancel") {
|
|
|
|
return reject;
|
|
|
|
} else if (property == "wrapped") {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
let result = target[property];
|
|
|
|
return (typeof result == "function") ? result.bind(target) : result;
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-01-06 03:35:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Check for a custom installation prompt that may be provided by the
|
|
|
|
// applicaton
|
|
|
|
if ("@mozilla.org/addons/web-install-prompt;1" in Cc) {
|
|
|
|
try {
|
|
|
|
let prompt = Cc["@mozilla.org/addons/web-install-prompt;1"].
|
|
|
|
getService(Ci.amIWebInstallPrompt);
|
|
|
|
prompt.confirm(browser, url, [proxy]);
|
|
|
|
return;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
2018-09-26 04:06:28 +03:00
|
|
|
this.installNotifyObservers("addon-install-confirmation",
|
|
|
|
browser, url, proxy);
|
2017-01-06 03:35:07 +03:00
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-03-10 20:50:07 +03:00
|
|
|
webAPI: {
|
2016-04-18 23:48:12 +03:00
|
|
|
// installs maps integer ids to AddonInstall instances.
|
|
|
|
installs: new Map(),
|
|
|
|
nextInstall: 0,
|
|
|
|
|
|
|
|
sendEvent: null,
|
|
|
|
setEventHandler(fn) {
|
|
|
|
this.sendEvent = fn;
|
|
|
|
},
|
|
|
|
|
2018-04-15 05:38:18 +03:00
|
|
|
async getAddonByID(target, id) {
|
|
|
|
return webAPIForAddon(await AddonManager.getAddonByID(id));
|
2016-04-18 23:48:12 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// helper to copy (and convert) the properties we care about
|
|
|
|
copyProps(install, obj) {
|
|
|
|
obj.state = AddonManager.stateToString(install.state);
|
|
|
|
obj.error = AddonManager.errorToString(install.error);
|
|
|
|
obj.progress = install.progress;
|
|
|
|
obj.maxProgress = install.maxProgress;
|
|
|
|
},
|
|
|
|
|
2016-10-12 02:40:24 +03:00
|
|
|
makeListener(id, mm) {
|
2016-04-18 23:48:12 +03:00
|
|
|
const events = [
|
|
|
|
"onDownloadStarted",
|
|
|
|
"onDownloadProgress",
|
|
|
|
"onDownloadEnded",
|
|
|
|
"onDownloadCancelled",
|
|
|
|
"onDownloadFailed",
|
|
|
|
"onInstallStarted",
|
|
|
|
"onInstallEnded",
|
|
|
|
"onInstallCancelled",
|
|
|
|
"onInstallFailed",
|
|
|
|
];
|
|
|
|
|
|
|
|
let listener = {};
|
2017-01-20 08:26:23 +03:00
|
|
|
let installPromise = new Promise((resolve, reject) => {
|
|
|
|
events.forEach(event => {
|
|
|
|
listener[event] = (install, addon) => {
|
|
|
|
let data = {event, id};
|
|
|
|
AddonManager.webAPI.copyProps(install, data);
|
|
|
|
this.sendEvent(mm, data);
|
|
|
|
if (event == "onInstallEnded") {
|
|
|
|
resolve(addon);
|
|
|
|
} else if (event == "onDownloadFailed" || event == "onInstallFailed") {
|
|
|
|
reject({message: "install failed"});
|
|
|
|
} else if (event == "onDownloadCancelled" || event == "onInstallCancelled") {
|
|
|
|
reject({message: "install cancelled"});
|
|
|
|
}
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2017-01-20 08:26:23 +03:00
|
|
|
});
|
2016-04-18 23:48:12 +03:00
|
|
|
});
|
2017-01-20 08:26:23 +03:00
|
|
|
|
|
|
|
// We create the promise here since this is where we're setting
|
|
|
|
// up the InstallListener, but if the install is never started,
|
|
|
|
// no handlers will be attached so make sure we terminate errors.
|
|
|
|
installPromise.catch(() => {});
|
|
|
|
|
|
|
|
return {listener, installPromise};
|
2016-04-18 23:48:12 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
forgetInstall(id) {
|
|
|
|
let info = this.installs.get(id);
|
|
|
|
if (!info) {
|
|
|
|
throw new Error(`forgetInstall cannot find ${id}`);
|
|
|
|
}
|
|
|
|
info.install.removeListener(info.listener);
|
|
|
|
this.installs.delete(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
createInstall(target, options) {
|
2016-07-15 21:40:45 +03:00
|
|
|
// Throw an appropriate error if the given URL is not valid
|
|
|
|
// as an installation source. Return silently if it is okay.
|
|
|
|
function checkInstallUrl(url) {
|
2017-01-09 22:27:25 +03:00
|
|
|
let host = Services.io.newURI(options.url).host;
|
2016-07-15 21:40:45 +03:00
|
|
|
if (WEBAPI_INSTALL_HOSTS.includes(host)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Services.prefs.getBoolPref(PREF_WEBAPI_TESTING)
|
|
|
|
&& WEBAPI_TEST_INSTALL_HOSTS.includes(host)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Install from ${host} not permitted`);
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:49:41 +03:00
|
|
|
try {
|
|
|
|
checkInstallUrl(options.url);
|
|
|
|
} catch (err) {
|
|
|
|
return Promise.reject({message: err.message});
|
|
|
|
}
|
2016-07-15 21:40:45 +03:00
|
|
|
|
2018-09-07 22:08:14 +03:00
|
|
|
let installTelemetryInfo = {
|
|
|
|
source: AddonManager.getInstallSourceFromHost(options.sourceHost),
|
|
|
|
method: "amWebAPI",
|
|
|
|
};
|
|
|
|
|
|
|
|
return AddonManagerInternal.getInstallForURL(options.url, "application/x-xpinstall", options.hash,
|
|
|
|
null, null, null, null, installTelemetryInfo)
|
2017-01-20 08:26:23 +03:00
|
|
|
.then(install => {
|
2017-02-28 20:08:49 +03:00
|
|
|
AddonManagerInternal.setupPromptHandler(target, null, install, false, "AMO");
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2016-12-18 00:49:41 +03:00
|
|
|
let id = this.nextInstall++;
|
2017-01-20 08:26:23 +03:00
|
|
|
let {listener, installPromise} = this.makeListener(id, target.messageManager);
|
2016-12-18 00:49:41 +03:00
|
|
|
install.addListener(listener);
|
2016-04-18 23:48:12 +03:00
|
|
|
|
2017-01-20 08:26:23 +03:00
|
|
|
this.installs.set(id, {install, target, listener, installPromise});
|
2016-04-18 23:48:12 +03:00
|
|
|
|
2016-12-18 00:49:41 +03:00
|
|
|
let result = {id};
|
|
|
|
this.copyProps(install, result);
|
|
|
|
return result;
|
2016-04-18 23:48:12 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-08-31 05:03:39 +03:00
|
|
|
async addonUninstall(target, id) {
|
|
|
|
let addon = await AddonManager.getAddonByID(id);
|
|
|
|
if (!addon) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-21 19:59:14 +03:00
|
|
|
|
2017-08-31 05:03:39 +03:00
|
|
|
try {
|
|
|
|
addon.uninstall();
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError(err);
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-21 19:59:14 +03:00
|
|
|
},
|
|
|
|
|
2017-08-31 05:03:39 +03:00
|
|
|
async addonSetEnabled(target, id, value) {
|
|
|
|
let addon = await AddonManager.getAddonByID(id);
|
|
|
|
if (!addon) {
|
|
|
|
throw new Error(`No such addon ${id}`);
|
|
|
|
}
|
|
|
|
|
2018-06-06 23:08:34 +03:00
|
|
|
if (value)
|
|
|
|
await addon.enable();
|
|
|
|
else
|
|
|
|
await addon.disable();
|
2016-06-24 22:54:18 +03:00
|
|
|
},
|
|
|
|
|
2018-08-04 01:37:16 +03:00
|
|
|
async addonInstallDoInstall(target, id) {
|
2016-04-18 23:48:12 +03:00
|
|
|
let state = this.installs.get(id);
|
|
|
|
if (!state) {
|
2018-08-04 01:37:16 +03:00
|
|
|
throw new Error(`invalid id ${id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
let addon = await state.install.install();
|
|
|
|
|
|
|
|
if (addon.type == "theme" && !addon.appDisabled) {
|
|
|
|
await addon.enable();
|
2016-04-18 23:48:12 +03:00
|
|
|
}
|
2017-01-20 08:26:23 +03:00
|
|
|
|
2018-08-04 01:37:16 +03:00
|
|
|
if (Services.prefs.getBoolPref(PREF_WEBEXT_PERM_PROMPTS, false)) {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
let subject = {wrappedJSObject: {target, addon, callback: resolve}};
|
2017-10-15 21:50:30 +03:00
|
|
|
Services.obs.notifyObservers(subject, "webextension-install-notify");
|
2018-08-04 01:37:16 +03:00
|
|
|
});
|
|
|
|
}
|
2016-04-18 23:48:12 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
addonInstallCancel(target, id) {
|
|
|
|
let state = this.installs.get(id);
|
|
|
|
if (!state) {
|
|
|
|
return Promise.reject(`invalid id ${id}`);
|
|
|
|
}
|
|
|
|
return Promise.resolve(state.install.cancel());
|
|
|
|
},
|
|
|
|
|
|
|
|
clearInstalls(ids) {
|
|
|
|
for (let id of ids) {
|
|
|
|
this.forgetInstall(id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearInstallsFrom(mm) {
|
|
|
|
for (let [id, info] of this.installs) {
|
2016-10-12 02:40:24 +03:00
|
|
|
if (info.target.messageManager == mm) {
|
2016-04-18 23:48:12 +03:00
|
|
|
this.forgetInstall(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-03-10 20:50:07 +03:00
|
|
|
},
|
2010-04-30 00:11:23 +04: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.
|
|
|
|
*/
|
2018-02-23 22:50:01 +03:00
|
|
|
var AddonManagerPrivate = {
|
2016-12-30 02:34:54 +03:00
|
|
|
startup() {
|
2010-04-30 00:11:23 +04:00
|
|
|
AddonManagerInternal.startup();
|
|
|
|
},
|
|
|
|
|
2017-04-16 02:23:54 +03:00
|
|
|
addonIsActive(addonId) {
|
|
|
|
return AddonManagerInternal._getProviderByName("XPIProvider")
|
|
|
|
.addonIsActive(addonId);
|
|
|
|
},
|
|
|
|
|
2017-05-10 22:34:17 +03:00
|
|
|
/**
|
|
|
|
* Gets an array of add-ons which were side-loaded prior to the last
|
|
|
|
* startup, and are currently disabled.
|
|
|
|
*
|
|
|
|
* @returns {Promise<Array<Addon>>}
|
|
|
|
*/
|
|
|
|
getNewSideloads() {
|
|
|
|
return AddonManagerInternal._getProviderByName("XPIProvider")
|
|
|
|
.getNewSideloads();
|
|
|
|
},
|
|
|
|
|
2017-04-15 20:13:39 +03:00
|
|
|
get browserUpdated() {
|
|
|
|
return gBrowserUpdated;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
registerProvider(aProvider, aTypes) {
|
2011-05-20 21:36:28 +04:00
|
|
|
AddonManagerInternal.registerProvider(aProvider, aTypes);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
unregisterProvider(aProvider) {
|
2010-06-17 07:13:54 +04:00
|
|
|
AddonManagerInternal.unregisterProvider(aProvider);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
markProviderSafe(aProvider) {
|
2015-01-19 12:55:15 +03:00
|
|
|
AddonManagerInternal.markProviderSafe(aProvider);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
backgroundUpdateCheck() {
|
2014-05-07 19:04:25 +04:00
|
|
|
return AddonManagerInternal.backgroundUpdateCheck();
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2014-09-02 19:47:11 +04:00
|
|
|
backgroundUpdateTimerHandler() {
|
|
|
|
// Don't return the promise here, since the caller doesn't care.
|
|
|
|
AddonManagerInternal.backgroundUpdateCheck();
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addStartupChange(aType, aID) {
|
2011-06-30 01:50:43 +04:00
|
|
|
AddonManagerInternal.addStartupChange(aType, aID);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeStartupChange(aType, aID) {
|
2011-06-30 01:50:43 +04:00
|
|
|
AddonManagerInternal.removeStartupChange(aType, aID);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
notifyAddonChanged(aID, aType, aPendingRestart) {
|
2012-05-30 10:34:32 +04:00
|
|
|
AddonManagerInternal.notifyAddonChanged(aID, aType, aPendingRestart);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
updateAddonAppDisabledStates() {
|
2010-04-26 22:45:22 +04:00
|
|
|
AddonManagerInternal.updateAddonAppDisabledStates();
|
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
updateAddonRepositoryData() {
|
|
|
|
return AddonManagerInternal.updateAddonRepositoryData();
|
2011-12-07 14:48:33 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
callInstallListeners(...aArgs) {
|
2010-04-30 00:11:23 +04:00
|
|
|
return AddonManagerInternal.callInstallListeners.apply(AddonManagerInternal,
|
2012-06-20 13:12:11 +04:00
|
|
|
aArgs);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
callAddonListeners(...aArgs) {
|
2012-06-20 13:12:11 +04:00
|
|
|
AddonManagerInternal.callAddonListeners.apply(AddonManagerInternal, aArgs);
|
2010-08-24 05:04:06 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
AddonAuthor,
|
2010-08-24 05:04:06 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
AddonScreenshot,
|
2011-05-20 21:36:28 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
AddonCompatibilityOverride,
|
2011-12-02 06:28:15 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
AddonType,
|
2013-02-08 01:47:33 +04:00
|
|
|
|
2017-08-05 09:12:24 +03:00
|
|
|
get BOOTSTRAP_REASONS() {
|
|
|
|
return AddonManagerInternal._getProviderByName("XPIProvider")
|
|
|
|
.BOOTSTRAP_REASONS;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
recordTimestamp(name, value) {
|
2013-02-08 01:47:33 +04:00
|
|
|
AddonManagerInternal.recordTimestamp(name, value);
|
|
|
|
},
|
|
|
|
|
|
|
|
_simpleMeasures: {},
|
2016-12-30 02:34:54 +03:00
|
|
|
recordSimpleMeasure(name, value) {
|
2013-02-08 01:47:33 +04:00
|
|
|
this._simpleMeasures[name] = value;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
recordException(aModule, aContext, aException) {
|
2014-01-10 00:00:27 +04:00
|
|
|
let report = {
|
|
|
|
module: aModule,
|
2018-08-31 08:59:17 +03:00
|
|
|
context: aContext,
|
2014-01-10 00:00:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof aException == "number") {
|
|
|
|
report.message = Components.Exception("", aException).name;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2014-01-10 00:00:27 +04:00
|
|
|
report.message = aException.toString();
|
|
|
|
if (aException.fileName) {
|
|
|
|
report.file = aException.fileName;
|
|
|
|
report.line = aException.lineNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._simpleMeasures.exception = report;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getSimpleMeasures() {
|
2013-02-08 01:47:33 +04:00
|
|
|
return this._simpleMeasures;
|
2013-08-22 19:56:28 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getTelemetryDetails() {
|
2013-10-11 21:13:31 +04:00
|
|
|
return AddonManagerInternal.telemetryDetails;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
setTelemetryDetails(aProvider, aDetails) {
|
2013-10-11 21:13:31 +04:00
|
|
|
AddonManagerInternal.telemetryDetails[aProvider] = aDetails;
|
|
|
|
},
|
|
|
|
|
2013-08-22 19:56:28 +04:00
|
|
|
// Start a timer, record a simple measure of the time interval when
|
|
|
|
// timer.done() is called
|
2016-12-30 02:34:54 +03:00
|
|
|
simpleTimer(aName) {
|
2014-09-19 22:04:49 +04:00
|
|
|
let startTime = Cu.now();
|
2013-08-22 19:56:28 +04:00
|
|
|
return {
|
2018-08-31 08:59:17 +03:00
|
|
|
done: () => this.recordSimpleMeasure(aName, Math.round(Cu.now() - startTime)),
|
2013-08-22 19:56:28 +04:00
|
|
|
};
|
2014-03-28 23:17:04 +04:00
|
|
|
},
|
|
|
|
|
2018-05-19 02:36:04 +03:00
|
|
|
async recordTiming(name, task) {
|
2018-05-13 00:14:56 +03:00
|
|
|
let timer = this.simpleTimer(name);
|
|
|
|
try {
|
2018-05-19 02:36:04 +03:00
|
|
|
return await task();
|
2018-05-13 00:14:56 +03:00
|
|
|
} finally {
|
|
|
|
timer.done();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-28 23:17:04 +04:00
|
|
|
/**
|
|
|
|
* Helper to call update listeners when no update is available.
|
|
|
|
*
|
|
|
|
* This can be used as an implementation for Addon.findUpdates() when
|
|
|
|
* no update mechanism is available.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
callNoUpdateListeners(addon, listener, reason, appVersion, platformVersion) {
|
2014-03-28 23:17:04 +04:00
|
|
|
if ("onNoCompatibilityUpdateAvailable" in listener) {
|
|
|
|
safeCall(listener.onNoCompatibilityUpdateAvailable.bind(listener), addon);
|
|
|
|
}
|
|
|
|
if ("onNoUpdateAvailable" in listener) {
|
|
|
|
safeCall(listener.onNoUpdateAvailable.bind(listener), addon);
|
|
|
|
}
|
|
|
|
if ("onUpdateFinished" in listener) {
|
|
|
|
safeCall(listener.onUpdateFinished.bind(listener), addon);
|
|
|
|
}
|
|
|
|
},
|
2015-11-04 01:49:46 +03:00
|
|
|
|
|
|
|
get webExtensionsMinPlatformVersion() {
|
|
|
|
return gWebExtensionsMinPlatformVersion;
|
|
|
|
},
|
2016-06-08 01:57:14 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
hasUpgradeListener(aId) {
|
2016-06-08 01:57:14 +03:00
|
|
|
return AddonManagerInternal.upgradeListeners.has(aId);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getUpgradeListener(aId) {
|
2016-06-08 01:57:14 +03:00
|
|
|
return AddonManagerInternal.upgradeListeners.get(aId);
|
|
|
|
},
|
2016-12-20 02:06:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Predicate that returns true if we think the given extension ID
|
|
|
|
* might have been generated by XPIProvider.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
isTemporaryInstallID(extensionId) {
|
2016-12-20 02:06:05 +03:00
|
|
|
if (!gStarted)
|
|
|
|
throw Components.Exception("AddonManager is not initialized",
|
|
|
|
Cr.NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
if (!extensionId || typeof extensionId != "string")
|
|
|
|
throw Components.Exception("extensionId must be a string",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
return AddonManagerInternal._getProviderByName("XPIProvider")
|
|
|
|
.isTemporaryInstallID(extensionId);
|
|
|
|
},
|
2017-04-19 21:30:24 +03:00
|
|
|
|
2017-05-18 23:07:14 +03:00
|
|
|
isDBLoaded() {
|
|
|
|
let provider = AddonManagerInternal._getProviderByName("XPIProvider");
|
|
|
|
return provider ? provider.isDBLoaded : false;
|
|
|
|
},
|
2010-04-30 00:11:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the public API that UI and developers should be calling. All methods
|
|
|
|
* just forward to AddonManagerInternal.
|
2017-09-14 23:18:11 +03:00
|
|
|
* @class
|
2010-04-30 00:11:23 +04:00
|
|
|
*/
|
2018-02-23 22:50:01 +03:00
|
|
|
var AddonManager = {
|
2018-09-07 22:08:14 +03:00
|
|
|
// Map used to convert the known install source hostnames into the value to set into the
|
|
|
|
// telemetry events.
|
|
|
|
_installHostSource: new Map([
|
|
|
|
["addons.mozilla.org", "amo"],
|
|
|
|
["discovery.addons.mozilla.org", "disco"],
|
|
|
|
["testpilot.firefox.com", "testpilot"],
|
|
|
|
]),
|
|
|
|
|
2010-04-30 00:11:23 +04:00
|
|
|
// Constants for the AddonInstall.state property
|
2016-04-18 23:48:12 +03:00
|
|
|
// These will show up as AddonManager.STATE_* (eg, STATE_AVAILABLE)
|
|
|
|
_states: new Map([
|
|
|
|
// 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],
|
2016-12-30 18:52:23 +03:00
|
|
|
// The install may not proceed until the user accepts a prompt
|
|
|
|
["STATE_AWAITING_PROMPT", 5],
|
|
|
|
// Any prompts are done
|
|
|
|
["STATE_PROMPTS_DONE", 6],
|
2016-06-08 01:57:14 +03:00
|
|
|
// The install has been postponed.
|
2016-11-16 19:53:56 +03:00
|
|
|
["STATE_POSTPONED", 7],
|
|
|
|
// The install is ready to be applied.
|
|
|
|
["STATE_READY", 8],
|
2016-04-18 23:48:12 +03:00
|
|
|
// The add-on is being installed.
|
2016-11-16 19:53:56 +03:00
|
|
|
["STATE_INSTALLING", 9],
|
2016-04-18 23:48:12 +03:00
|
|
|
// The add-on has been installed.
|
2016-11-16 19:53:56 +03:00
|
|
|
["STATE_INSTALLED", 10],
|
2016-04-18 23:48:12 +03:00
|
|
|
// The install failed.
|
2016-11-16 19:53:56 +03:00
|
|
|
["STATE_INSTALL_FAILED", 11],
|
2016-04-18 23:48:12 +03:00
|
|
|
// The install has been cancelled.
|
2016-11-16 19:53:56 +03:00
|
|
|
["STATE_CANCELLED", 12],
|
2016-04-18 23:48:12 +03:00
|
|
|
]),
|
2010-04-30 00:11:23 +04:00
|
|
|
|
|
|
|
// Constants representing different types of errors while downloading an
|
|
|
|
// add-on.
|
2016-04-18 23:48:12 +03:00
|
|
|
// These will show up as AddonManager.ERROR_* (eg, ERROR_NETWORK_FAILURE)
|
|
|
|
_errors: new Map([
|
|
|
|
// 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],
|
2018-04-04 08:22:07 +03:00
|
|
|
// An error occurred trying to write to the filesystem.
|
2016-04-18 23:48:12 +03:00
|
|
|
["ERROR_FILE_ACCESS", -4],
|
|
|
|
// The add-on must be signed and isn't.
|
|
|
|
["ERROR_SIGNEDSTATE_REQUIRED", -5],
|
|
|
|
// The downloaded add-on had a different type than expected.
|
|
|
|
["ERROR_UNEXPECTED_ADDON_TYPE", -6],
|
2016-09-17 01:00:18 +03:00
|
|
|
// The addon did not have the expected ID
|
|
|
|
["ERROR_INCORRECT_ID", -7],
|
2016-04-18 23:48:12 +03:00
|
|
|
]),
|
2017-07-27 19:00:32 +03:00
|
|
|
// The update check timed out
|
|
|
|
ERROR_TIMEOUT: -1,
|
|
|
|
// There was an error while downloading the update information.
|
|
|
|
ERROR_DOWNLOAD_ERROR: -2,
|
|
|
|
// The update information was malformed in some way.
|
|
|
|
ERROR_PARSE_ERROR: -3,
|
|
|
|
// The update information was not in any known format.
|
|
|
|
ERROR_UNKNOWN_FORMAT: -4,
|
|
|
|
// The update information was not correctly signed or there was an SSL error.
|
|
|
|
ERROR_SECURITY_ERROR: -5,
|
|
|
|
// The update was cancelled
|
|
|
|
ERROR_CANCELLED: -6,
|
2010-06-10 22:11:16 +04: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 19:21:32 +04:00
|
|
|
// The update was cancelled.
|
|
|
|
UPDATE_STATUS_CANCELLED: -6,
|
2010-04-30 00:11:23 +04: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-30 00:11:23 +04:00
|
|
|
// Indicates that the Addon has no pending operations.
|
|
|
|
PENDING_NONE: 0,
|
2010-04-30 00:11:23 +04: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 21:54:23 +04:00
|
|
|
PENDING_UPGRADE: 16,
|
2010-04-30 00:11:23 +04:00
|
|
|
|
2010-07-26 21:34:06 +04: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-30 00:11:23 +04: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-24 03:21:22 +04: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-30 00:11:23 +04:00
|
|
|
|
2010-04-07 22:08:32 +04: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,
|
2015-11-03 21:07:08 +03:00
|
|
|
// Installed temporarily
|
|
|
|
SCOPE_TEMPORARY: 16,
|
2010-04-07 22:08:32 +04:00
|
|
|
// The combination of all scopes.
|
2015-11-03 21:07:08 +03:00
|
|
|
SCOPE_ALL: 31,
|
2011-01-15 00:29:27 +03:00
|
|
|
|
2016-02-06 02:06:48 +03:00
|
|
|
// Add-on type is expected to be displayed in the UI in a list.
|
2011-05-20 21:36:28 +04:00
|
|
|
VIEW_TYPE_LIST: "list",
|
|
|
|
|
2016-02-06 02:06:48 +03:00
|
|
|
// Constants describing how add-on types behave.
|
|
|
|
|
|
|
|
// If no add-ons of a type are installed, then the category for that add-on
|
|
|
|
// type should be hidden in the UI.
|
2011-05-20 21:36:28 +04:00
|
|
|
TYPE_UI_HIDE_EMPTY: 16,
|
2013-04-24 03:21:22 +04: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,
|
2016-02-06 02:06:48 +03:00
|
|
|
// The add-on type natively supports undo for restartless uninstalls.
|
|
|
|
// If this flag is not specified, the UI is expected to handle this via
|
|
|
|
// disabling the add-on, and performing the actual uninstall at a later time.
|
|
|
|
TYPE_SUPPORTS_UNDO_RESTARTLESS_UNINSTALL: 64,
|
2011-05-20 21:36:28 +04:00
|
|
|
|
2010-09-14 10:56:54 +04: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 22:08:32 +04:00
|
|
|
|
2011-06-01 14:35:24 +04:00
|
|
|
// Constants for how Addon options should be shown.
|
2011-06-11 03:11:32 +04:00
|
|
|
// Options will be displayed in a new tab, if possible
|
|
|
|
OPTIONS_TYPE_TAB: 3,
|
2016-03-10 03:50:08 +03:00
|
|
|
// Similar to OPTIONS_TYPE_INLINE, but rather than generating inline
|
|
|
|
// options from a specially-formatted XUL file, the contents of the
|
|
|
|
// file are simply displayed in an inline <browser> element.
|
|
|
|
OPTIONS_TYPE_INLINE_BROWSER: 5,
|
2011-06-01 14:35:24 +04:00
|
|
|
|
2012-09-26 23:42:00 +04: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-30 01:50:43 +04: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",
|
|
|
|
|
2015-03-31 21:32:40 +03:00
|
|
|
// Constants for Addon.signedState. Any states that should cause an add-on
|
|
|
|
// to be unusable in builds that require signing should have negative values.
|
2015-09-01 13:48:12 +03:00
|
|
|
// Add-on signing is not required, e.g. because the pref is disabled.
|
|
|
|
SIGNEDSTATE_NOT_REQUIRED: undefined,
|
2015-03-31 21:32:40 +03:00
|
|
|
// Add-on is signed but signature verification has failed.
|
|
|
|
SIGNEDSTATE_BROKEN: -2,
|
|
|
|
// Add-on may be signed but by an certificate that doesn't chain to our
|
|
|
|
// our trusted certificate.
|
|
|
|
SIGNEDSTATE_UNKNOWN: -1,
|
|
|
|
// Add-on is unsigned.
|
|
|
|
SIGNEDSTATE_MISSING: 0,
|
|
|
|
// Add-on is preliminarily reviewed.
|
|
|
|
SIGNEDSTATE_PRELIMINARY: 1,
|
|
|
|
// Add-on is fully reviewed.
|
|
|
|
SIGNEDSTATE_SIGNED: 2,
|
2015-08-27 02:14:00 +03:00
|
|
|
// Add-on is system add-on.
|
|
|
|
SIGNEDSTATE_SYSTEM: 3,
|
2017-04-20 03:02:42 +03:00
|
|
|
// Add-on is signed with a "Mozilla Extensions" certificate
|
|
|
|
SIGNEDSTATE_PRIVILEGED: 4,
|
2015-03-31 21:32:40 +03:00
|
|
|
|
2013-04-24 03:21:22 +04: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 06:19:37 +04:00
|
|
|
get __AddonManagerInternal__() {
|
2015-11-20 02:30:47 +03:00
|
|
|
return AppConstants.DEBUG ? AddonManagerInternal : undefined;
|
2012-08-13 06:19:37 +04:00
|
|
|
},
|
|
|
|
|
2017-09-14 23:18:11 +03:00
|
|
|
/** Boolean indicating whether AddonManager startup has completed. */
|
2015-01-19 12:55:15 +03:00
|
|
|
get isReady() {
|
|
|
|
return gStartupComplete && !gShutdownInProgress;
|
|
|
|
},
|
|
|
|
|
2017-09-14 23:18:11 +03:00
|
|
|
/** @constructor */
|
2016-04-18 23:48:12 +03:00
|
|
|
init() {
|
|
|
|
this._stateToString = new Map();
|
|
|
|
for (let [name, value] of this._states) {
|
|
|
|
this[name] = value;
|
|
|
|
this._stateToString.set(value, name);
|
|
|
|
}
|
|
|
|
this._errorToString = new Map();
|
|
|
|
for (let [name, value] of this._errors) {
|
|
|
|
this[name] = value;
|
|
|
|
this._errorToString.set(value, name);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
stateToString(state) {
|
|
|
|
return this._stateToString.get(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
errorToString(err) {
|
|
|
|
return err ? this._errorToString.get(err) : null;
|
|
|
|
},
|
|
|
|
|
2018-09-07 22:08:14 +03:00
|
|
|
getInstallSourceFromHost(host) {
|
|
|
|
if (this._installHostSource.has(host)) {
|
|
|
|
return this._installHostSource.get(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WEBAPI_TEST_INSTALL_HOSTS.includes(host)) {
|
|
|
|
return "test-host";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
},
|
|
|
|
|
2018-04-16 00:22:55 +03:00
|
|
|
getInstallForURL(aUrl, aMimetype, aHash, aName, aIcons,
|
2018-09-07 22:08:14 +03:00
|
|
|
aVersion, aBrowser, aTelemetryInfo) {
|
|
|
|
return AddonManagerInternal.getInstallForURL(
|
|
|
|
aUrl, aMimetype, aHash, aName, aIcons, aVersion, aBrowser, aTelemetryInfo);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2018-09-07 22:08:14 +03:00
|
|
|
getInstallForFile(aFile, aMimetype, aTelemetryInfo) {
|
|
|
|
return AddonManagerInternal.getInstallForFile(aFile, aMimetype, aTelemetryInfo);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2011-06-30 01:50:43 +04: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
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getStartupChanges(aType) {
|
2011-06-30 01:50:43 +04:00
|
|
|
if (!(aType in AddonManagerInternal.startupChanges))
|
|
|
|
return [];
|
|
|
|
return AddonManagerInternal.startupChanges[aType].slice(0);
|
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getAddonByID(aID) {
|
|
|
|
return AddonManagerInternal.getAddonByID(aID);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getAddonBySyncGUID(aGUID) {
|
|
|
|
return AddonManagerInternal.getAddonBySyncGUID(aGUID);
|
2011-11-05 05:04:15 +04:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getAddonsByIDs(aIDs) {
|
|
|
|
return AddonManagerInternal.getAddonsByIDs(aIDs);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getAddonsByTypes(aTypes) {
|
|
|
|
return AddonManagerInternal.getAddonsByTypes(aTypes);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getActiveAddons(aTypes) {
|
|
|
|
return AddonManagerInternal.getActiveAddons(aTypes);
|
2017-05-18 23:07:14 +03:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getAllAddons() {
|
|
|
|
return AddonManagerInternal.getAllAddons();
|
2010-04-26 21:49:19 +04:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getInstallsByTypes(aTypes) {
|
|
|
|
return AddonManagerInternal.getInstallsByTypes(aTypes);
|
2010-04-26 21:49:19 +04:00
|
|
|
},
|
|
|
|
|
2018-04-22 01:15:10 +03:00
|
|
|
getAllInstalls() {
|
|
|
|
return AddonManagerInternal.getAllInstalls();
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
isInstallEnabled(aType) {
|
2010-04-28 20:42:07 +04:00
|
|
|
return AddonManagerInternal.isInstallEnabled(aType);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
isInstallAllowed(aType, aInstallingPrincipal) {
|
2016-02-23 23:11:37 +03:00
|
|
|
return AddonManagerInternal.isInstallAllowed(aType, aInstallingPrincipal);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2017-01-04 21:12:53 +03:00
|
|
|
installAddonFromWebpage(aType, aBrowser, aInstallingPrincipal, aInstall) {
|
|
|
|
AddonManagerInternal.installAddonFromWebpage(aType, aBrowser,
|
|
|
|
aInstallingPrincipal,
|
|
|
|
aInstall);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2017-01-04 21:13:16 +03:00
|
|
|
installAddonFromAOM(aBrowser, aUri, aInstall) {
|
|
|
|
AddonManagerInternal.installAddonFromAOM(aBrowser, aUri, aInstall);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
installTemporaryAddon(aDirectory) {
|
2015-11-03 21:07:08 +03:00
|
|
|
return AddonManagerInternal.installTemporaryAddon(aDirectory);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addManagerListener(aListener) {
|
2012-02-15 06:07:29 +04:00
|
|
|
AddonManagerInternal.addManagerListener(aListener);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeManagerListener(aListener) {
|
2012-02-15 06:07:29 +04:00
|
|
|
AddonManagerInternal.removeManagerListener(aListener);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addInstallListener(aListener) {
|
2010-04-28 20:42:07 +04:00
|
|
|
AddonManagerInternal.addInstallListener(aListener);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeInstallListener(aListener) {
|
2010-04-28 20:42:07 +04:00
|
|
|
AddonManagerInternal.removeInstallListener(aListener);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getUpgradeListener(aId) {
|
2016-06-08 01:57:14 +03:00
|
|
|
return AddonManagerInternal.upgradeListeners.get(aId);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addUpgradeListener(aInstanceID, aCallback) {
|
2016-06-08 01:57:14 +03:00
|
|
|
AddonManagerInternal.addUpgradeListener(aInstanceID, aCallback);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeUpgradeListener(aInstanceID) {
|
2017-05-11 06:26:01 +03:00
|
|
|
return AddonManagerInternal.removeUpgradeListener(aInstanceID);
|
2016-06-08 01:57:14 +03:00
|
|
|
},
|
2016-12-30 02:34:54 +03:00
|
|
|
addAddonListener(aListener) {
|
2010-04-28 20:42:07 +04:00
|
|
|
AddonManagerInternal.addAddonListener(aListener);
|
2010-04-30 00:11:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeAddonListener(aListener) {
|
2010-04-28 20:42:07 +04:00
|
|
|
AddonManagerInternal.removeAddonListener(aListener);
|
2010-09-14 10:56:54 +04:00
|
|
|
},
|
2011-01-15 00:29:27 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addTypeListener(aListener) {
|
2011-05-20 21:36:28 +04:00
|
|
|
AddonManagerInternal.addTypeListener(aListener);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeTypeListener(aListener) {
|
2011-05-20 21:36:28 +04:00
|
|
|
AddonManagerInternal.removeTypeListener(aListener);
|
|
|
|
},
|
|
|
|
|
|
|
|
get addonTypes() {
|
|
|
|
return AddonManagerInternal.addonTypes;
|
|
|
|
},
|
|
|
|
|
2012-05-30 10:34:32 +04: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.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
shouldAutoUpdate(aAddon) {
|
2012-05-30 10:34:32 +04:00
|
|
|
if (!aAddon || typeof aAddon != "object")
|
|
|
|
throw Components.Exception("aAddon must be specified",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
2013-09-13 07:11:30 +04:00
|
|
|
|
2011-08-13 03:55:34 +04: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 09:48:45 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 06:07:29 +04:00
|
|
|
get checkCompatibility() {
|
|
|
|
return AddonManagerInternal.checkCompatibility;
|
|
|
|
},
|
|
|
|
|
|
|
|
set checkCompatibility(aValue) {
|
|
|
|
AddonManagerInternal.checkCompatibility = aValue;
|
|
|
|
},
|
|
|
|
|
2011-11-01 09:48:45 +04:00
|
|
|
get strictCompatibility() {
|
|
|
|
return AddonManagerInternal.strictCompatibility;
|
2011-12-17 00:04:50 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 06:07:29 +04: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;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
escapeAddonURI(aAddon, aUri, aAppVersion) {
|
2011-12-17 00:04:50 +04:00
|
|
|
return AddonManagerInternal.escapeAddonURI(aAddon, aUri, aAppVersion);
|
2014-07-08 20:56:04 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getPreferredIconURL(aAddon, aSize, aWindow = undefined) {
|
2015-10-14 12:03:40 +03:00
|
|
|
return AddonManagerInternal.getPreferredIconURL(aAddon, aSize, aWindow);
|
|
|
|
},
|
|
|
|
|
2016-03-10 20:50:07 +03:00
|
|
|
get webAPI() {
|
|
|
|
return AddonManagerInternal.webAPI;
|
|
|
|
},
|
|
|
|
|
2014-07-08 20:56:04 +04:00
|
|
|
get shutdown() {
|
|
|
|
return gShutdownBarrier.client;
|
|
|
|
},
|
2010-04-30 00:11:23 +04:00
|
|
|
};
|
2010-10-13 01:31:52 +04:00
|
|
|
|
2018-09-19 19:43:11 +03:00
|
|
|
/**
|
|
|
|
* Listens to the AddonManager install and addon events and send telemetry events.
|
|
|
|
*/
|
|
|
|
var AMTelemetry = {
|
|
|
|
telemetrySetupDone: false,
|
|
|
|
|
|
|
|
// This method is called by the AddonManager, once it has been started, so that we can
|
|
|
|
// init the telemetry event category and start listening for the events related to the
|
|
|
|
// addons installation and management.
|
|
|
|
onStartup() {
|
|
|
|
if (this.telemetrySetupDone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.telemetrySetupDone = true;
|
|
|
|
|
|
|
|
Services.telemetry.setEventRecordingEnabled("addonsManager", true);
|
|
|
|
|
|
|
|
Services.obs.addObserver(this, "addon-install-origin-blocked");
|
|
|
|
Services.obs.addObserver(this, "addon-install-disabled");
|
|
|
|
Services.obs.addObserver(this, "addon-install-blocked");
|
|
|
|
|
|
|
|
Services.obs.addObserver(this, "webextension-permission-prompt");
|
|
|
|
Services.obs.addObserver(this, "webextension-update-permissions");
|
|
|
|
|
|
|
|
AddonManager.addInstallListener(this);
|
|
|
|
AddonManager.addAddonListener(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Observer Service notification callback.
|
|
|
|
|
|
|
|
observe(subject, topic, data) {
|
|
|
|
switch (topic) {
|
|
|
|
case "addon-install-blocked": {
|
|
|
|
const {installs} = subject.wrappedJSObject;
|
|
|
|
this.recordInstallEvent(installs[0], {step: "site_warning"});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "addon-install-origin-blocked": {
|
|
|
|
const {installs} = subject.wrappedJSObject;
|
|
|
|
this.recordInstallEvent(installs[0], {step: "site_blocked"});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "addon-install-disabled": {
|
|
|
|
const {installs} = subject.wrappedJSObject;
|
|
|
|
this.recordInstallEvent(installs[0], {step: "install_disabled_warning"});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webextension-permission-prompt": {
|
|
|
|
const {info} = subject.wrappedJSObject;
|
|
|
|
const {permissions, origins} = info.permissions || {permissions: [], origins: []};
|
|
|
|
if (info.type === "sideload") {
|
|
|
|
// When extension.js notifies a webextension-permission-prompt for a sideload,
|
|
|
|
// there is no AddonInstall instance available.
|
|
|
|
this.recordManageEvent(info.addon, "sideload_prompt", {
|
|
|
|
num_perms: permissions.length,
|
|
|
|
num_origins: origins.length,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.recordInstallEvent(info.install, {
|
|
|
|
step: "permissions_prompt",
|
|
|
|
num_perms: permissions.length,
|
|
|
|
num_origins: origins.length,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webextension-update-permissions": {
|
|
|
|
const update = subject.wrappedJSObject;
|
|
|
|
const {permissions, origins} = update.permissions || {permissions: [], origins: []};
|
|
|
|
this.recordInstallEvent(update.install, {
|
|
|
|
step: "permissions_prompt",
|
|
|
|
num_perms: permissions.length,
|
|
|
|
num_origins: origins.length,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// AddonManager install listener callbacks.
|
|
|
|
|
|
|
|
onNewInstall(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "started"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallCancelled(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "cancelled"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallPostponed(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "postponed"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallFailed(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "failed"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallEnded(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "completed"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadStarted(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "download_started"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadCancelled(install) {
|
|
|
|
this.recordInstallEvent(install, {step: "cancelled"});
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadEnded(install) {
|
|
|
|
let download_time = Math.round(Cu.now() - install.downloadStartedAt);
|
|
|
|
this.recordInstallEvent(install, {step: "download_completed", download_time});
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadFailed(install) {
|
|
|
|
let download_time = Math.round(Cu.now() - install.downloadStartedAt);
|
|
|
|
this.recordInstallEvent(install, {step: "download_failed", download_time});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Addon listeners callbacks.
|
|
|
|
|
|
|
|
onUninstalled(addon) {
|
|
|
|
this.recordManageEvent(addon, "uninstall");
|
|
|
|
},
|
|
|
|
|
|
|
|
onEnabled(addon) {
|
|
|
|
this.recordManageEvent(addon, "enable");
|
|
|
|
},
|
|
|
|
|
|
|
|
onDisabled(addon) {
|
|
|
|
this.recordManageEvent(addon, "disable");
|
|
|
|
},
|
|
|
|
|
|
|
|
// Internal helpers methods.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a trimmed version of the given string if it is longer than 80 chars.
|
|
|
|
*
|
|
|
|
* @param {string} str
|
|
|
|
* The original string content.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
* The trimmed version of the string when longer than 80 chars, or the given string
|
|
|
|
* unmodified otherwise.
|
|
|
|
*/
|
|
|
|
getTrimmedString(str) {
|
|
|
|
if (str.length <= 80) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const length = str.length;
|
|
|
|
|
|
|
|
// Trim the string to prevent a flood of warnings messages logged internally by recordEvent,
|
|
|
|
// the trimmed version is going to be composed by the first 40 chars and the last 37 and 3 dots
|
|
|
|
// that joins the two parts, to visually indicate that the string has been trimmed.
|
|
|
|
return `${str.slice(0, 40)}...${str.slice(length - 37, length)}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the addonId for the given AddonInstall instance.
|
|
|
|
*
|
|
|
|
* @param {AddonInstall} install
|
|
|
|
* The AddonInstall instance to retrieve the addonId from.
|
|
|
|
*
|
|
|
|
* @returns {string | null}
|
|
|
|
* The addonId for the given AddonInstall instance (if any).
|
|
|
|
*/
|
|
|
|
getAddonIdFromInstall(install) {
|
|
|
|
// Returns the id of the extension that is being installed, as soon as the
|
|
|
|
// addon is available in the AddonInstall instance (after being downloaded
|
|
|
|
// and validated successfully).
|
|
|
|
if (install.addon) {
|
|
|
|
return install.addon.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// While updating an addon, the existing addon can be
|
|
|
|
// used to retrieve the addon id since the first update event.
|
|
|
|
if (install.existingAddon) {
|
|
|
|
return install.existingAddon.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the telemetry event's object property value for the given
|
|
|
|
* AddonInstall instance.
|
|
|
|
*
|
|
|
|
* @param {AddonInstall} install
|
|
|
|
* The AddonInstall instance to retrieve the event object from.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
* The object for the given AddonInstall instance.
|
|
|
|
*/
|
|
|
|
getEventObjectFromInstall(install) {
|
|
|
|
let addonType;
|
|
|
|
|
|
|
|
if (install.type) {
|
|
|
|
// The AddonInstall wrapper already provides a type (if it was known when the
|
|
|
|
// install object has been created).
|
|
|
|
addonType = install.type;
|
|
|
|
} else if (install.addon) {
|
|
|
|
// The install flow has reached a step that has an addon instance which we can
|
|
|
|
// check to know the extension type (e.g. after download for the DownloadAddonInstall).
|
|
|
|
addonType = install.addon.type;
|
|
|
|
} else if (install.existingAddon) {
|
|
|
|
// The install flow is an update and we can look the existingAddon to check which was
|
|
|
|
// the add-on type that is being installed.
|
|
|
|
addonType = install.existingAddon.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.getEventObjectFromAddonType(addonType);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the telemetry event source for the given AddonInstall instance.
|
|
|
|
*
|
|
|
|
* @param {AddonInstall} install
|
|
|
|
* The AddonInstall instance to retrieve the source from.
|
|
|
|
*
|
|
|
|
* @returns {Object | null}
|
|
|
|
* The telemetry infor ({source, method}) from the given AddonInstall instance.
|
|
|
|
*/
|
|
|
|
getInstallTelemetryInfo(install) {
|
|
|
|
if (install.installTelemetryInfo) {
|
|
|
|
return install.installTelemetryInfo;
|
|
|
|
} else if (install.existingAddon && install.existingAddon.installTelemetryInfo) {
|
|
|
|
// Get the install source from the existing addon (e.g. for an extension update).
|
|
|
|
return install.existingAddon.installTelemetryInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the telemetry event's object property for the given addon type
|
|
|
|
*
|
|
|
|
* @param {string} addonType
|
|
|
|
* The addon type to convert into the related telemetry event object.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
* The object for the given addon type.
|
|
|
|
*/
|
|
|
|
getEventObjectFromAddonType(addonType) {
|
|
|
|
switch (addonType) {
|
|
|
|
case undefined:
|
|
|
|
return "unknown";
|
|
|
|
case "extension":
|
|
|
|
case "theme":
|
|
|
|
case "locale":
|
|
|
|
case "dictionary":
|
|
|
|
return addonType;
|
|
|
|
default:
|
|
|
|
// Currently this should only include plugins and gmp-plugins
|
|
|
|
return "other";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert all the telemetry event's extra_vars into strings, if needed.
|
|
|
|
*
|
|
|
|
* @param {object} extraVars
|
|
|
|
*/
|
|
|
|
formatExtraVars(extraVars) {
|
|
|
|
// All the extra_vars in a telemetry event have to be strings.
|
|
|
|
for (var key of Object.keys(extraVars)) {
|
|
|
|
if (typeof(extraVars[key]) !== "string") {
|
|
|
|
extraVars[key] = String(extraVars[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record an install or update event for the given AddonInstall instance.
|
|
|
|
*
|
|
|
|
* @param {AddonInstall} install
|
|
|
|
* The AddonInstall instance to record an install or update event for.
|
|
|
|
* @param {object} extraVars
|
|
|
|
* The additional extra_vars to include in the recorded event.
|
|
|
|
* @param {string} extraVars.step
|
|
|
|
* The current step in the install or update flow.
|
|
|
|
* @param {string} extraVars.download_time
|
|
|
|
* The number of ms needed to download the extension.
|
|
|
|
* @param {string} extraVars.num_perms
|
|
|
|
* The number of permissions for the extensions.
|
|
|
|
* @param {string} extraVars.num_origins
|
|
|
|
* The number of origins for the extensions.
|
|
|
|
*/
|
|
|
|
recordInstallEvent(install, extraVars) {
|
|
|
|
// Early exit if AMTelemetry's telemetry setup has not been done yet.
|
|
|
|
if (!this.telemetrySetupDone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let extra = {};
|
|
|
|
|
|
|
|
let telemetryInfo = this.getInstallTelemetryInfo(install);
|
|
|
|
if (telemetryInfo && typeof telemetryInfo.source === "string") {
|
|
|
|
extra.source = telemetryInfo.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra.source === "internal") {
|
|
|
|
// Do not record the telemetry event for installation sources
|
|
|
|
// that are marked as "internal".
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also include the install source's method when applicable (e.g. install events with
|
|
|
|
// source "about:addons" may have "install-from-file" or "url" as their source method).
|
|
|
|
if (telemetryInfo && typeof telemetryInfo.method === "string") {
|
|
|
|
extra.method = telemetryInfo.method;
|
|
|
|
}
|
|
|
|
|
|
|
|
let addonId = this.getAddonIdFromInstall(install);
|
|
|
|
let object = this.getEventObjectFromInstall(install);
|
|
|
|
|
|
|
|
let installId = String(install.installId);
|
|
|
|
let eventMethod = install.existingAddon ? "update" : "install";
|
|
|
|
|
|
|
|
if (addonId) {
|
|
|
|
extra.addon_id = this.getTrimmedString(addonId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (install.error) {
|
|
|
|
extra.error = AddonManager.errorToString(install.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventMethod === "update") {
|
|
|
|
// For "update" telemetry events, also include an extra var which determine
|
|
|
|
// if the update has been requested by the user.
|
|
|
|
extra.updated_from = install.isUserRequestedUpdate ? "user" : "app";
|
|
|
|
}
|
|
|
|
|
|
|
|
// All the extra vars in a telemetry event have to be strings.
|
|
|
|
extra = {...extraVars, ...extra};
|
|
|
|
this.formatExtraVars(extra);
|
|
|
|
|
|
|
|
this.recordEvent({method: eventMethod, object, value: installId, extra});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record a manage event for the given addon.
|
|
|
|
*
|
|
|
|
* @param {AddonWrapper} addon
|
|
|
|
* The AddonWrapper instance.
|
|
|
|
* @param {object} extra
|
|
|
|
* The additional extra_vars to include in the recorded event.
|
|
|
|
* @param {string} extraVars.num_perms
|
|
|
|
* The number of permissions for the extensions.
|
|
|
|
* @param {string} extraVars.num_origins
|
|
|
|
* The number of origins for the extensions.
|
|
|
|
*/
|
|
|
|
recordManageEvent(addon, method, extraVars) {
|
|
|
|
// Early exit if AMTelemetry's telemetry setup has not been done yet.
|
|
|
|
if (!this.telemetrySetupDone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let extra = {};
|
|
|
|
|
|
|
|
if (addon.installTelemetryInfo) {
|
|
|
|
if ("source" in addon.installTelemetryInfo) {
|
|
|
|
extra.source = addon.installTelemetryInfo.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also include the install source's method when applicable (e.g. install events with
|
|
|
|
// source "about:addons" may have "install-from-file" or "url" as their source method).
|
|
|
|
if ("method" in addon.installTelemetryInfo) {
|
|
|
|
extra.method = addon.installTelemetryInfo.method;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra.source === "internal") {
|
|
|
|
// Do not record the telemetry event for installation sources
|
|
|
|
// that are marked as "internal".
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let object = this.getEventObjectFromAddonType(addon.type);
|
|
|
|
let value = this.getTrimmedString(addon.id);
|
|
|
|
|
|
|
|
extra = {...extraVars, ...extra};
|
|
|
|
|
|
|
|
let hasExtraVars = Object.keys(extra).length > 0;
|
|
|
|
this.formatExtraVars(extra);
|
|
|
|
|
|
|
|
this.recordEvent({method, object, value, extra: hasExtraVars ? extra : null});
|
|
|
|
},
|
|
|
|
|
|
|
|
recordEvent({method, object, value, extra}) {
|
|
|
|
Services.telemetry.recordEvent("addonsManager", method, object, value, extra);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-04-18 23:48:12 +03:00
|
|
|
this.AddonManager.init();
|
|
|
|
|
2018-09-19 19:43:11 +03:00
|
|
|
// Setup the AMTelemetry once the AddonManager has been started.
|
|
|
|
this.AddonManager.addManagerListener(AMTelemetry);
|
|
|
|
|
2013-02-08 01:47:33 +04:00
|
|
|
// load the timestamps module into AddonManagerInternal
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/TelemetryTimestamps.jsm", AddonManagerInternal);
|
2018-09-14 04:26:48 +03:00
|
|
|
Object.freeze(AddonManagerInternal);
|
2010-10-13 01:31:52 +04:00
|
|
|
Object.freeze(AddonManagerPrivate);
|
|
|
|
Object.freeze(AddonManager);
|