diff options
Diffstat (limited to 'toolkit/mozapps/extensions/internal')
17 files changed, 3316 insertions, 8533 deletions
diff --git a/toolkit/mozapps/extensions/internal/APIExtensionBootstrap.js b/toolkit/mozapps/extensions/internal/APIExtensionBootstrap.js deleted file mode 100644 index 0eae2475c..000000000 --- a/toolkit/mozapps/extensions/internal/APIExtensionBootstrap.js +++ /dev/null @@ -1,39 +0,0 @@ -/* 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/. */ - -"use strict"; - -Components.utils.import("resource://gre/modules/ExtensionManagement.jsm"); -Components.utils.import("resource://gre/modules/Services.jsm"); - -var namespace; -var resource; -var resProto; - -function install(data, reason) { -} - -function startup(data, reason) { - namespace = data.id.replace(/@.*/, ""); - resource = `extension-${namespace}-api`; - - resProto = Services.io.getProtocolHandler("resource") - .QueryInterface(Components.interfaces.nsIResProtocolHandler); - - resProto.setSubstitution(resource, data.resourceURI); - - ExtensionManagement.registerAPI( - namespace, - `resource://${resource}/schema.json`, - `resource://${resource}/api.js`); -} - -function shutdown(data, reason) { - resProto.setSubstitution(resource, null); - - ExtensionManagement.unregisterAPI(namespace); -} - -function uninstall(data, reason) { -} diff --git a/toolkit/mozapps/extensions/internal/AddonConstants.jsm b/toolkit/mozapps/extensions/internal/AddonConstants.jsm deleted file mode 100644 index 22d91fdf5..000000000 --- a/toolkit/mozapps/extensions/internal/AddonConstants.jsm +++ /dev/null @@ -1,31 +0,0 @@ -/* 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/. */ - -"use strict"; - -this.EXPORTED_SYMBOLS = [ "ADDON_SIGNING", "REQUIRE_SIGNING" ]; - -// Make these non-changable properties so they can't be manipulated from other -// code in the app. -Object.defineProperty(this, "ADDON_SIGNING", { - configurable: false, - enumerable: false, - writable: false, -#ifdef MOZ_ADDON_SIGNING - value: true, -#else - value: false, -#endif -}); - -Object.defineProperty(this, "REQUIRE_SIGNING", { - configurable: false, - enumerable: false, - writable: false, -#ifdef MOZ_REQUIRE_SIGNING - value: true, -#else - value: false, -#endif -}); diff --git a/toolkit/mozapps/extensions/internal/AddonLogging.jsm b/toolkit/mozapps/extensions/internal/AddonLogging.jsm index f05a6fe6c..362439bae 100644 --- a/toolkit/mozapps/extensions/internal/AddonLogging.jsm +++ b/toolkit/mozapps/extensions/internal/AddonLogging.jsm @@ -81,7 +81,7 @@ function AddonLogger(aName) { AddonLogger.prototype = { name: null, - error: function(aStr, aException) { + error: function AddonLogger_error(aStr, aException) { let message = formatLogMessage("error", this.name, aStr, aException); let stack = getStackDetails(aException); @@ -95,18 +95,6 @@ AddonLogger.prototype = { // Always dump errors, in case the Console Service isn't listening yet dump("*** " + message + "\n"); - function formatTimestamp(date) { - // Format timestamp as: "%Y-%m-%d %H:%M:%S" - let year = String(date.getFullYear()); - let month = String(date.getMonth() + 1).padStart(2, "0"); - let day = String(date.getDate()).padStart(2, "0"); - let hours = String(date.getHours()).padStart(2, "0"); - let minutes = String(date.getMinutes()).padStart(2, "0"); - let seconds = String(date.getSeconds()).padStart(2, "0"); - - return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; - } - try { var tstamp = new Date(); var logfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_EXTENSIONS_LOG]); @@ -116,7 +104,7 @@ AddonLogger.prototype = { var writer = Cc["@mozilla.org/intl/converter-output-stream;1"]. createInstance(Ci.nsIConverterOutputStream); writer.init(stream, "UTF-8", 0, 0x0000); - writer.writeString(formatTimestamp(tstamp) + " " + + writer.writeString(tstamp.toLocaleFormat("%Y-%m-%d %H:%M:%S ") + message + " at " + stack.sourceName + ":" + stack.lineNumber + "\n"); writer.close(); @@ -124,7 +112,7 @@ AddonLogger.prototype = { catch (e) { } }, - warn: function(aStr, aException) { + warn: function AddonLogger_warn(aStr, aException) { let message = formatLogMessage("warn", this.name, aStr, aException); let stack = getStackDetails(aException); @@ -139,7 +127,7 @@ AddonLogger.prototype = { dump("*** " + message + "\n"); }, - log: function(aStr, aException) { + log: function AddonLogger_log(aStr, aException) { if (gDebugLogEnabled) { let message = formatLogMessage("log", this.name, aStr, aException); dump("*** " + message + "\n"); @@ -149,14 +137,14 @@ AddonLogger.prototype = { }; this.LogManager = { - getLogger: function(aName, aTarget) { + getLogger: function LogManager_getLogger(aName, aTarget) { let logger = new AddonLogger(aName); if (aTarget) { ["error", "warn", "log"].forEach(function(name) { let fname = name.toUpperCase(); delete aTarget[fname]; - aTarget[fname] = function(aStr, aException) { + aTarget[fname] = function LogManager_targetName(aStr, aException) { logger[name](aStr, aException); }; }); @@ -167,13 +155,13 @@ this.LogManager = { }; var PrefObserver = { - init: function() { + init: function PrefObserver_init() { Services.prefs.addObserver(PREF_LOGGING_ENABLED, this, false); Services.obs.addObserver(this, "xpcom-shutdown", false); this.observe(null, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, PREF_LOGGING_ENABLED); }, - observe: function(aSubject, aTopic, aData) { + observe: function PrefObserver_observe(aSubject, aTopic, aData) { if (aTopic == "xpcom-shutdown") { Services.prefs.removeObserver(PREF_LOGGING_ENABLED, this); Services.obs.removeObserver(this, "xpcom-shutdown"); diff --git a/toolkit/mozapps/extensions/internal/AddonRepository.jsm b/toolkit/mozapps/extensions/internal/AddonRepository.jsm index 7f88d44ad..76a7528c7 100644 --- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm @@ -11,7 +11,6 @@ const Cr = Components.results; Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/AddonManager.jsm"); -/* globals AddonManagerPrivate*/ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", @@ -24,8 +23,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository_SQLiteMigrator", "resource://gre/modules/addons/AddonRepository_SQLiteMigrator.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Promise", "resource://gre/modules/Promise.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest", - "resource://gre/modules/ServiceRequest.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm"); @@ -67,7 +64,9 @@ const BLANK_DB = function() { } const TOOLKIT_ID = "toolkit@mozilla.org"; - +#ifdef MOZ_PHOENIX_EXTENSIONS +const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; +#endif Cu.import("resource://gre/modules/Log.jsm"); const LOGGER_ID = "addons.repository"; @@ -101,6 +100,10 @@ const INTEGER_KEY_MAP = { daily_users: "dailyUsers" }; +// Wrap the XHR factory so that tests can override with a mock +var XHRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1", + "nsIXMLHttpRequest"); + function convertHTMLToPlainText(html) { if (!html) return html; @@ -130,14 +133,14 @@ function getAddonsToCache(aIds, aCallback) { types = types.split(","); - AddonManager.getAddonsByIDs(aIds, function(aAddons) { + AddonManager.getAddonsByIDs(aIds, function getAddonsToCache_getAddonsByIDs(aAddons) { let enabledIds = []; for (var i = 0; i < aIds.length; i++) { var preference = PREF_GETADDONS_CACHE_ID_ENABLED.replace("%ID%", aIds[i]); try { if (!Services.prefs.getBoolPref(preference)) continue; - } catch (e) { + } catch(e) { // If the preference doesn't exist caching is enabled by default } @@ -398,7 +401,7 @@ AddonSearchResult.prototype = { * A platform version to test against * @return Boolean representing if the add-on is compatible */ - isCompatibleWith: function(aAppVersion, aPlatformVersion) { + isCompatibleWith: function ASR_isCompatibleWith(aAppVerison, aPlatformVersion) { return true; }, @@ -415,7 +418,7 @@ AddonSearchResult.prototype = { * @param aPlatformVersion * A platform version to check for updates for */ - findUpdates: function(aListener, aReason, aAppVersion, aPlatformVersion) { + findUpdates: function ASR_findUpdates(aListener, aReason, aAppVersion, aPlatformVersion) { if ("onNoCompatibilityUpdateAvailable" in aListener) aListener.onNoCompatibilityUpdateAvailable(this); if ("onNoUpdateAvailable" in aListener) @@ -427,8 +430,7 @@ AddonSearchResult.prototype = { toJSON: function() { let json = {}; - for (let property of Object.keys(this)) { - let value = this[property]; + for (let [property, value] of Iterator(this)) { if (property.startsWith("_") || typeof(value) === "function") continue; @@ -451,8 +453,7 @@ AddonSearchResult.prototype = { } } - for (let property of Object.keys(this._unsupportedProperties)) { - let value = this._unsupportedProperties[property]; + for (let [property, value] of Iterator(this._unsupportedProperties)) { if (!property.startsWith("_")) json[property] = value; } @@ -477,11 +478,18 @@ this.AddonRepository = { * Whether caching is currently enabled */ get cacheEnabled() { + // Act as though caching is disabled if there was an unrecoverable error + // openning the database. + if (!AddonDatabase.databaseOk) { + logger.warn("Cache is disabled because database is not OK"); + return false; + } + let preference = PREF_GETADDONS_CACHE_ENABLED; let enabled = false; try { enabled = Services.prefs.getBoolPref(preference); - } catch (e) { + } catch(e) { logger.warn("cacheEnabled: Couldn't get pref: " + preference); } @@ -524,7 +532,7 @@ this.AddonRepository = { * return: promise{integer} resolves with the result of flushing * the AddonRepository database */ - shutdown: function() { + shutdown: function AddonRepo_shutdown() { this.cancelSearch(); this._addons = null; @@ -546,7 +554,7 @@ this.AddonRepository = { return now - lastUpdate; }, - isMetadataStale: function() { + isMetadataStale: function AddonRepo_isMetadataStale() { let threshold = DEFAULT_METADATA_UPDATETHRESHOLD_SEC; try { threshold = Services.prefs.getIntPref(PREF_METADATA_UPDATETHRESHOLD_SEC); @@ -564,7 +572,7 @@ this.AddonRepository = { * @param aCallback * The callback to pass the result back to */ - getCachedAddonByID: Task.async(function*(aId, aCallback) { + getCachedAddonByID: Task.async(function* (aId, aCallback) { if (!aId || !this.cacheEnabled) { aCallback(null); return; @@ -605,7 +613,7 @@ this.AddonRepository = { * Clear and delete the AddonRepository database * @return Promise{null} resolves when the database is deleted */ - _clearCache: function() { + _clearCache: function () { this._addons = null; return AddonDatabase.delete().then(() => new Promise((resolve, reject) => @@ -613,43 +621,44 @@ this.AddonRepository = { ); }, - _repopulateCacheInternal: Task.async(function*(aSendPerformance, aTimeout) { + _repopulateCacheInternal: Task.async(function* (aSendPerformance, aTimeout) { let allAddons = yield new Promise((resolve, reject) => AddonManager.getAllAddons(resolve)); - // Filter the hotfix out of our list of add-ons - allAddons = allAddons.filter(a => a.id != AddonManager.hotfixID); - // Completely remove cache if caching is not enabled if (!this.cacheEnabled) { logger.debug("Clearing cache because it is disabled"); - yield this._clearCache(); - return; + return this._clearCache(); } - let ids = allAddons.map(a => a.id); + // Tycho: let ids = [a.id for (a of allAddons)]; + let ids = []; + for (let a of allAddons) { + ids.push(a.id); + } + logger.debug("Repopulate add-on cache with " + ids.toSource()); + let self = this; let addonsToCache = yield new Promise((resolve, reject) => getAddonsToCache(ids, resolve)); // Completely remove cache if there are no add-ons to cache if (addonsToCache.length == 0) { logger.debug("Clearing cache because 0 add-ons were requested"); - yield this._clearCache(); - return; + return this._clearCache(); } yield new Promise((resolve, reject) => - this._beginGetAddons(addonsToCache, { - searchSucceeded: aAddons => { - this._addons = new Map(); + self._beginGetAddons(addonsToCache, { + searchSucceeded: function repopulateCacheInternal_searchSucceeded(aAddons) { + self._addons = new Map(); for (let addon of aAddons) { - this._addons.set(addon.id, addon); + self._addons.set(addon.id, addon); } AddonDatabase.repopulate(aAddons, resolve); }, - searchFailed: () => { + searchFailed: function repopulateCacheInternal_searchFailed() { logger.warn("Search failed when repopulating cache"); resolve(); } @@ -670,7 +679,7 @@ this.AddonRepository = { * @param aCallback * The optional callback to call once complete */ - cacheAddons: function(aIds, aCallback) { + cacheAddons: function AddonRepo_cacheAddons(aIds, aCallback) { logger.debug("cacheAddons: enabled " + this.cacheEnabled + " IDs " + aIds.toSource()); if (!this.cacheEnabled) { if (aCallback) @@ -678,7 +687,8 @@ this.AddonRepository = { return; } - getAddonsToCache(aIds, aAddons => { + let self = this; + getAddonsToCache(aIds, function cacheAddons_getAddonsToCache(aAddons) { // If there are no add-ons to cache, act as if caching is disabled if (aAddons.length == 0) { if (aCallback) @@ -686,14 +696,14 @@ this.AddonRepository = { return; } - this.getAddonsByIDs(aAddons, { - searchSucceeded: aAddons => { + self.getAddonsByIDs(aAddons, { + searchSucceeded: function cacheAddons_searchSucceeded(aAddons) { for (let addon of aAddons) { - this._addons.set(addon.id, addon); + self._addons.set(addon.id, addon); } AddonDatabase.insertAddons(aAddons, aCallback); }, - searchFailed: () => { + searchFailed: function cacheAddons_searchFailed() { logger.warn("Search failed when adding add-ons to cache"); if (aCallback) aCallback(); @@ -723,7 +733,7 @@ this.AddonRepository = { * The url that can be visited to see recommended add-ons in this repository. * If the corresponding preference is not defined, defaults to about:blank. */ - getRecommendedURL: function() { + getRecommendedURL: function AddonRepo_getRecommendedURL() { let url = this._formatURLPref(PREF_GETADDONS_BROWSERECOMMENDED, {}); return (url != null) ? url : "about:blank"; }, @@ -736,7 +746,7 @@ this.AddonRepository = { * @param aSearchTerms * Search terms used to search the repository */ - getSearchURL: function(aSearchTerms) { + getSearchURL: function AddonRepo_getSearchURL(aSearchTerms) { let url = this._formatURLPref(PREF_GETADDONS_BROWSESEARCHRESULTS, { TERMS : encodeURIComponent(aSearchTerms) }); @@ -747,7 +757,7 @@ this.AddonRepository = { * Cancels the search in progress. If there is no search in progress this * does nothing. */ - cancelSearch: function() { + cancelSearch: function AddonRepo_cancelSearch() { this._searching = false; if (this._request) { this._request.abort(); @@ -765,7 +775,7 @@ this.AddonRepository = { * @param aCallback * The callback to pass results to */ - getAddonsByIDs: function(aIDs, aCallback) { + getAddonsByIDs: function AddonRepo_getAddonsByIDs(aIDs, aCallback) { return this._beginGetAddons(aIDs, aCallback, false); }, @@ -823,12 +833,13 @@ this.AddonRepository = { let url = this._formatURLPref(pref, params); - let handleResults = (aElements, aTotalResults, aCompatData) => { + let self = this; + function handleResults(aElements, aTotalResults, aCompatData) { // Don't use this._parseAddons() so that, for example, // incompatible add-ons are not filtered out let results = []; - for (let i = 0; i < aElements.length && results.length < this._maxResults; i++) { - let result = this._parseAddon(aElements[i], null, aCompatData); + for (let i = 0; i < aElements.length && results.length < self._maxResults; i++) { + let result = self._parseAddon(aElements[i], null, aCompatData); if (result == null) continue; @@ -849,8 +860,7 @@ this.AddonRepository = { // Include any compatibility overrides for addons not hosted by the // remote repository. - for (let id in aCompatData) { - let addonCompat = aCompatData[id]; + for each (let addonCompat in aCompatData) { if (addonCompat.hosted) continue; @@ -867,7 +877,7 @@ this.AddonRepository = { } // aTotalResults irrelevant - this._reportSuccess(results, -1); + self._reportSuccess(results, -1); } this._beginSearch(url, ids.length, aCallback, handleResults, aTimeout); @@ -882,7 +892,7 @@ this.AddonRepository = { * * @return Promise{null} Resolves when the metadata update is complete. */ - backgroundUpdateCheck: function() { + backgroundUpdateCheck: function () { return this._repopulateCacheInternal(true); }, @@ -895,7 +905,7 @@ this.AddonRepository = { * @param aCallback * The callback to pass results to */ - retrieveRecommendedAddons: function(aMaxResults, aCallback) { + retrieveRecommendedAddons: function AddonRepo_retrieveRecommendedAddons(aMaxResults, aCallback) { let url = this._formatURLPref(PREF_GETADDONS_GETRECOMMENDED, { API_VERSION : API_VERSION, @@ -903,10 +913,11 @@ this.AddonRepository = { MAX_RESULTS : 2 * aMaxResults }); - let handleResults = (aElements, aTotalResults) => { - this._getLocalAddonIds(aLocalAddonIds => { + let self = this; + function handleResults(aElements, aTotalResults) { + self._getLocalAddonIds(function retrieveRecommendedAddons_getLocalAddonIds(aLocalAddonIds) { // aTotalResults irrelevant - this._parseAddons(aElements, -1, aLocalAddonIds); + self._parseAddons(aElements, -1, aLocalAddonIds); }); } @@ -924,7 +935,7 @@ this.AddonRepository = { * @param aCallback * The callback to pass results to */ - searchAddons: function(aSearchTerms, aMaxResults, aCallback) { + searchAddons: function AddonRepo_searchAddons(aSearchTerms, aMaxResults, aCallback) { let compatMode = "normal"; if (!AddonManager.checkCompatibility) compatMode = "ignore"; @@ -941,9 +952,10 @@ this.AddonRepository = { let url = this._formatURLPref(PREF_GETADDONS_GETSEARCHRESULTS, substitutions); - let handleResults = (aElements, aTotalResults) => { - this._getLocalAddonIds(aLocalAddonIds => { - this._parseAddons(aElements, aTotalResults, aLocalAddonIds); + let self = this; + function handleResults(aElements, aTotalResults) { + self._getLocalAddonIds(function searchAddons_getLocalAddonIds(aLocalAddonIds) { + self._parseAddons(aElements, aTotalResults, aLocalAddonIds); }); } @@ -951,18 +963,23 @@ this.AddonRepository = { }, // Posts results to the callback - _reportSuccess: function(aResults, aTotalResults) { + _reportSuccess: function AddonRepo_reportSuccess(aResults, aTotalResults) { this._searching = false; this._request = null; // The callback may want to trigger a new search so clear references early - let addons = aResults.map(result => result.addon); + // Tycho: let addons = [result.addon for each(result in aResults)]; + let addons = []; + for each(let result in aResults) { + addons.push(result.addon); + } + let callback = this._callback; this._callback = null; callback.searchSucceeded(addons, addons.length, aTotalResults); }, // Notifies the callback of a failure - _reportFailure: function() { + _reportFailure: function AddonRepo_reportFailure() { this._searching = false; this._request = null; // The callback may want to trigger a new search so clear references early @@ -972,28 +989,28 @@ this.AddonRepository = { }, // Get descendant by unique tag name. Returns null if not unique tag name. - _getUniqueDescendant: function(aElement, aTagName) { + _getUniqueDescendant: function AddonRepo_getUniqueDescendant(aElement, aTagName) { let elementsList = aElement.getElementsByTagName(aTagName); return (elementsList.length == 1) ? elementsList[0] : null; }, // Get direct descendant by unique tag name. // Returns null if not unique tag name. - _getUniqueDirectDescendant: function(aElement, aTagName) { + _getUniqueDirectDescendant: function AddonRepo_getUniqueDirectDescendant(aElement, aTagName) { let elementsList = Array.filter(aElement.children, - aChild => aChild.tagName == aTagName); + function arrayFiltering(aChild) aChild.tagName == aTagName); return (elementsList.length == 1) ? elementsList[0] : null; }, // Parse out trimmed text content. Returns null if text content empty. - _getTextContent: function(aElement) { + _getTextContent: function AddonRepo_getTextContent(aElement) { let textContent = aElement.textContent.trim(); return (textContent.length > 0) ? textContent : null; }, // Parse out trimmed text content of a descendant with the specified tag name // Returns null if the parsing unsuccessful. - _getDescendantTextContent: function(aElement, aTagName) { + _getDescendantTextContent: function AddonRepo_getDescendantTextContent(aElement, aTagName) { let descendant = this._getUniqueDescendant(aElement, aTagName); return (descendant != null) ? this._getTextContent(descendant) : null; }, @@ -1001,7 +1018,7 @@ this.AddonRepository = { // Parse out trimmed text content of a direct descendant with the specified // tag name. // Returns null if the parsing unsuccessful. - _getDirectDescendantTextContent: function(aElement, aTagName) { + _getDirectDescendantTextContent: function AddonRepo_getDirectDescendantTextContent(aElement, aTagName) { let descendant = this._getUniqueDirectDescendant(aElement, aTagName); return (descendant != null) ? this._getTextContent(descendant) : null; }, @@ -1019,7 +1036,7 @@ this.AddonRepository = { * @return Result object containing the parsed AddonSearchResult, xpiURL and * xpiHash if the parsing was successful. Otherwise returns null. */ - _parseAddon: function(aElement, aSkip, aCompatData) { + _parseAddon: function AddonRepo_parseAddon(aElement, aSkip, aCompatData) { let skipIDs = (aSkip && aSkip.ids) ? aSkip.ids : []; let skipSourceURIs = (aSkip && aSkip.sourceURIs) ? aSkip.sourceURIs : []; @@ -1037,6 +1054,7 @@ this.AddonRepository = { if (aCompatData && guid in aCompatData) addon.compatibilityOverrides = aCompatData[guid].compatRanges; + let self = this; for (let node = aElement.firstChild; node; node = node.nextSibling) { if (!(node instanceof Ci.nsIDOMElement)) continue; @@ -1107,8 +1125,8 @@ this.AddonRepository = { case "authors": let authorNodes = node.getElementsByTagName("author"); for (let authorNode of authorNodes) { - let name = this._getDescendantTextContent(authorNode, "name"); - let link = this._getDescendantTextContent(authorNode, "link"); + let name = self._getDescendantTextContent(authorNode, "name"); + let link = self._getDescendantTextContent(authorNode, "link"); if (name == null || link == null) continue; @@ -1126,22 +1144,22 @@ this.AddonRepository = { case "previews": let previewNodes = node.getElementsByTagName("preview"); for (let previewNode of previewNodes) { - let full = this._getUniqueDescendant(previewNode, "full"); + let full = self._getUniqueDescendant(previewNode, "full"); if (full == null) continue; - let fullURL = this._getTextContent(full); + let fullURL = self._getTextContent(full); let fullWidth = full.getAttribute("width"); let fullHeight = full.getAttribute("height"); let thumbnailURL, thumbnailWidth, thumbnailHeight; - let thumbnail = this._getUniqueDescendant(previewNode, "thumbnail"); + let thumbnail = self._getUniqueDescendant(previewNode, "thumbnail"); if (thumbnail) { - thumbnailURL = this._getTextContent(thumbnail); + thumbnailURL = self._getTextContent(thumbnail); thumbnailWidth = thumbnail.getAttribute("width"); thumbnailHeight = thumbnail.getAttribute("height"); } - let caption = this._getDescendantTextContent(previewNode, "caption"); + let caption = self._getDescendantTextContent(previewNode, "caption"); let screenshot = new AddonManagerPrivate.AddonScreenshot(fullURL, fullWidth, fullHeight, thumbnailURL, thumbnailWidth, thumbnailHeight, caption); @@ -1198,7 +1216,7 @@ this.AddonRepository = { break; case "all_compatible_os": let nodes = node.getElementsByTagName("os"); - addon.isPlatformCompatible = Array.some(nodes, function(aNode) { + addon.isPlatformCompatible = Array.some(nodes, function parseAddon_platformCompatFilter(aNode) { let text = aNode.textContent.toLowerCase().trim(); return text == "all" || text == Services.appinfo.OS.toLowerCase(); }); @@ -1244,10 +1262,21 @@ this.AddonRepository = { return result; }, - _parseAddons: function(aElements, aTotalResults, aSkip) { + _parseAddons: function AddonRepo_parseAddons(aElements, aTotalResults, aSkip) { + let self = this; let results = []; - let isSameApplication = aAppNode => this._getTextContent(aAppNode) == Services.appinfo.ID; + function isSameApplication(aAppNode) { +#ifdef MOZ_PHOENIX_EXTENSIONS + if (self._getTextContent(aAppNode) == Services.appinfo.ID || + self._getTextContent(aAppNode) == FIREFOX_ID) { +#else + if (self._getTextContent(aAppNode) == Services.appinfo.ID) { +#endif + return true; + } + return false; + } for (let i = 0; i < aElements.length && results.length < this._maxResults; i++) { let element = aElements[i]; @@ -1257,13 +1286,13 @@ this.AddonRepository = { continue; let applications = tags.getElementsByTagName("appID"); - let compatible = Array.some(applications, aAppNode => { + let compatible = Array.some(applications, function parseAddons_applicationsCompatFilter(aAppNode) { if (!isSameApplication(aAppNode)) return false; let parent = aAppNode.parentNode; - let minVersion = this._getDescendantTextContent(parent, "min_version"); - let maxVersion = this._getDescendantTextContent(parent, "max_version"); + let minVersion = self._getDescendantTextContent(parent, "min_version"); + let maxVersion = self._getDescendantTextContent(parent, "max_version"); if (minVersion == null || maxVersion == null) return false; @@ -1291,7 +1320,7 @@ this.AddonRepository = { // Ignore add-on missing a required attribute let requiredAttributes = ["id", "name", "version", "type", "creator"]; - if (requiredAttributes.some(aAttribute => !result.addon[aAttribute])) + if (requiredAttributes.some(function parseAddons_attributeFilter(aAttribute) !result.addon[aAttribute])) continue; // Ignore add-on with a type AddonManager doesn't understand: @@ -1322,28 +1351,28 @@ this.AddonRepository = { } // Create an AddonInstall for each result - for (let result of results) { - let addon = result.addon; - let callback = aInstall => { + results.forEach(function(aResult) { + let addon = aResult.addon; + let callback = function addonInstallCallback(aInstall) { addon.install = aInstall; pendingResults--; if (pendingResults == 0) - this._reportSuccess(results, aTotalResults); + self._reportSuccess(results, aTotalResults); } - if (result.xpiURL) { - AddonManager.getInstallForURL(result.xpiURL, callback, - "application/x-xpinstall", result.xpiHash, + if (aResult.xpiURL) { + AddonManager.getInstallForURL(aResult.xpiURL, callback, + "application/x-xpinstall", aResult.xpiHash, addon.name, addon.icons, addon.version); } else { callback(null); } - } + }); }, // Parses addon_compatibility nodes, that describe compatibility overrides. - _parseAddonCompatElement: function(aResultObj, aElement) { + _parseAddonCompatElement: function AddonRepo_parseAddonCompatElement(aResultObj, aElement) { let guid = this._getDescendantTextContent(aElement, "guid"); if (!guid) { logger.debug("Compatibility override is missing guid."); @@ -1416,7 +1445,7 @@ this.AddonRepository = { let rangeNodes = aElement.querySelectorAll("version_ranges > version_range"); compat.compatRanges = Array.map(rangeNodes, parseRangeNode.bind(this)) - .filter(aItem => !!aItem); + .filter(function compatRangesFilter(aItem) !!aItem); if (compat.compatRanges.length == 0) return; @@ -1424,7 +1453,7 @@ this.AddonRepository = { }, // Parses addon_compatibility elements. - _parseAddonCompatData: function(aElements) { + _parseAddonCompatData: function AddonRepo_parseAddonCompatData(aElements) { let compatData = {}; Array.forEach(aElements, this._parseAddonCompatElement.bind(this, compatData)); return compatData; @@ -1445,7 +1474,7 @@ this.AddonRepository = { logger.debug("Requesting " + aURI); - this._request = new ServiceRequest(); + this._request = new XHRequest(); this._request.mozBackgroundRequest = true; this._request.open("GET", aURI, true); this._request.overrideMimeType("text/xml"); @@ -1484,21 +1513,28 @@ this.AddonRepository = { // Gets the id's of local add-ons, and the sourceURI's of local installs, // passing the results to aCallback - _getLocalAddonIds: function(aCallback) { + _getLocalAddonIds: function AddonRepo_getLocalAddonIds(aCallback) { + let self = this; let localAddonIds = {ids: null, sourceURIs: null}; - AddonManager.getAllAddons(function(aAddons) { - localAddonIds.ids = aAddons.map(a => a.id); + AddonManager.getAllAddons(function getLocalAddonIds_getAllAddons(aAddons) { + // Tycho: localAddonIds.ids = [a.id for each (a in aAddons)]; + localAddonIds.ids = []; + + for each(let a in aAddons) { + localAddonIds.ids.push(a.id); + } + if (localAddonIds.sourceURIs) aCallback(localAddonIds); }); - AddonManager.getAllInstalls(function(aInstalls) { + AddonManager.getAllInstalls(function getLocalAddonIds_getAllInstalls(aInstalls) { localAddonIds.sourceURIs = []; - for (let install of aInstalls) { - if (install.state != AddonManager.STATE_AVAILABLE) - localAddonIds.sourceURIs.push(install.sourceURI.spec); - } + aInstalls.forEach(function(aInstall) { + if (aInstall.state != AddonManager.STATE_AVAILABLE) + localAddonIds.sourceURIs.push(aInstall.sourceURI.spec); + }); if (localAddonIds.ids) aCallback(localAddonIds); @@ -1506,16 +1542,16 @@ this.AddonRepository = { }, // Create url from preference, returning null if preference does not exist - _formatURLPref: function(aPreference, aSubstitutions) { + _formatURLPref: function AddonRepo_formatURLPref(aPreference, aSubstitutions) { let url = null; try { url = Services.prefs.getCharPref(aPreference); - } catch (e) { + } catch(e) { logger.warn("_formatURLPref: Couldn't get pref: " + aPreference); return null; } - url = url.replace(/%([A-Z_]+)%/g, function(aMatch, aKey) { + url = url.replace(/%([A-Z_]+)%/g, function urlSubstitution(aMatch, aKey) { return (aKey in aSubstitutions) ? aSubstitutions[aKey] : aMatch; }); @@ -1524,7 +1560,7 @@ this.AddonRepository = { // Find a AddonCompatibilityOverride that matches a given aAddonVersion and // application/platform version. - findMatchingCompatOverride: function(aAddonVersion, + findMatchingCompatOverride: function AddonRepo_findMatchingCompatOverride(aAddonVersion, aCompatOverrides, aAppVersion, aPlatformVersion) { @@ -1552,6 +1588,9 @@ this.AddonRepository = { }; var AddonDatabase = { + // false if there was an unrecoverable error opening the database + databaseOk: true, + connectionPromise: null, // the in-memory database DB: BLANK_DB(), @@ -1594,12 +1633,8 @@ var AddonDatabase = { schema < DB_MIN_JSON_SCHEMA) { throw new Error("Invalid schema value."); } - } catch (e) { - if (e instanceof OS.File.Error && e.becauseNoSuchFile) { - logger.debug("No " + FILE_DATABASE + " found."); - } else { - logger.error(`Malformed ${FILE_DATABASE}: ${e} - resetting to empty`); - } + } catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) { + logger.debug("No " + FILE_DATABASE + " found."); // Create a blank addons.json file this._saveDBToDisk(); @@ -1618,9 +1653,14 @@ var AddonDatabase = { yield this._insertAddons(results); } + Services.prefs.setIntPref(PREF_GETADDONS_DB_SCHEMA, DB_SCHEMA); } - Services.prefs.setIntPref(PREF_GETADDONS_DB_SCHEMA, DB_SCHEMA); + return this.DB; + } catch (e) { + logger.error("Malformed " + FILE_DATABASE + ": " + e); + this.databaseOk = false; + return this.DB; } @@ -1657,7 +1697,9 @@ var AddonDatabase = { * An optional boolean to skip flushing data to disk. Useful * when the database is going to be deleted afterwards. */ - shutdown: function(aSkipFlush) { + shutdown: function AD_shutdown(aSkipFlush) { + this.databaseOk = true; + if (!this.connectionPromise) { return Promise.resolve(); } @@ -1666,8 +1708,9 @@ var AddonDatabase = { if (aSkipFlush) { return Promise.resolve(); + } else { + return this.Writer.flush(); } - return this.Writer.flush(); }, /** @@ -1678,7 +1721,7 @@ var AddonDatabase = { * An optional callback to call once complete * @return Promise{null} resolves when the database has been deleted */ - delete: function(aCallback) { + delete: function AD_delete(aCallback) { this.DB = BLANK_DB(); this._deleting = this.Writer.flush() @@ -1693,7 +1736,7 @@ var AddonDatabase = { return this._deleting; }, - toJSON: function() { + toJSON: function AD_toJSON() { let json = { schema: this.DB.schema, addons: [] @@ -1738,7 +1781,7 @@ var AddonDatabase = { * @return: Promise{Map} * Resolves when the add-ons are retrieved from the database */ - retrieveStoredData: function() { + retrieveStoredData: function (){ return this.openConnection().then(db => db.addons); }, @@ -1751,9 +1794,9 @@ var AddonDatabase = { * @param aCallback * An optional callback to call once complete */ - repopulate: function(aAddons, aCallback) { + repopulate: function AD_repopulate(aAddons, aCallback) { this.DB.addons.clear(); - this.insertAddons(aAddons, function() { + this.insertAddons(aAddons, function repopulate_insertAddons() { let now = Math.round(Date.now() / 1000); logger.debug("Cache repopulated, setting " + PREF_METADATA_LASTUPDATE + " to " + now); Services.prefs.setIntPref(PREF_METADATA_LASTUPDATE, now); @@ -1770,12 +1813,12 @@ var AddonDatabase = { * @param aCallback * An optional callback to call once complete */ - insertAddons: Task.async(function*(aAddons, aCallback) { + insertAddons: Task.async(function* (aAddons, aCallback) { yield this.openConnection(); yield this._insertAddons(aAddons, aCallback); }), - _insertAddons: Task.async(function*(aAddons, aCallback) { + _insertAddons: Task.async(function* (aAddons, aCallback) { for (let addon of aAddons) { this._insertAddon(addon); } @@ -1794,7 +1837,7 @@ var AddonDatabase = { * @param aCallback * The callback to call once complete */ - _insertAddon: function(aAddon) { + _insertAddon: function AD__insertAddon(aAddon) { let newAddon = this._parseAddon(aAddon); if (!newAddon || !newAddon.id || @@ -1812,7 +1855,7 @@ var AddonDatabase = { * The object to parse * @return Returns an AddonSearchResult object. */ - _parseAddon: function(aObj) { + _parseAddon: function (aObj) { if (aObj instanceof AddonSearchResult) return aObj; @@ -1822,7 +1865,7 @@ var AddonDatabase = { let addon = new AddonSearchResult(id); - for (let expectedProperty of Object.keys(AddonSearchResult.prototype)) { + for (let [expectedProperty,] of Iterator(AddonSearchResult.prototype)) { if (!(expectedProperty in aObj) || typeof(aObj[expectedProperty]) === "function") continue; @@ -1870,8 +1913,8 @@ var AddonDatabase = { case "icons": if (!addon.icons) addon.icons = {}; - for (let size of Object.keys(aObj.icons)) { - addon.icons[size] = aObj.icons[size]; + for (let [size, url] of Iterator(aObj.icons)) { + addon.icons[size] = url; } break; @@ -1937,7 +1980,7 @@ var AddonDatabase = { * The JS object to use * @return The created developer */ - _makeDeveloper: function(aObj) { + _makeDeveloper: function (aObj) { let name = aObj.name; let url = aObj.url; return new AddonManagerPrivate.AddonAuthor(name, url); @@ -1951,7 +1994,7 @@ var AddonDatabase = { * The JS object to use * @return The created screenshot */ - _makeScreenshot: function(aObj) { + _makeScreenshot: function (aObj) { let url = aObj.url; let width = aObj.width; let height = aObj.height; @@ -1971,7 +2014,7 @@ var AddonDatabase = { * The JS object to use * @return The created CompatibilityOverride */ - _makeCompatOverride: function(aObj) { + _makeCompatOverride: function (aObj) { let type = aObj.type; let minVersion = aObj.minVersion; let maxVersion = aObj.maxVersion; diff --git a/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm b/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm index e3479643b..66147b9aa 100644 --- a/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm +++ b/toolkit/mozapps/extensions/internal/AddonRepository_SQLiteMigrator.jsm @@ -10,7 +10,6 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/AddonManager.jsm"); -/* globals AddonManagerPrivate*/ Cu.import("resource://gre/modules/FileUtils.jsm"); const KEY_PROFILEDIR = "ProfD"; @@ -61,7 +60,11 @@ this.AddonRepository_SQLiteMigrator = { this._retrieveStoredData((results) => { this._closeConnection(); - let resultArray = Object.keys(results).map(k => results[k]); + // Tycho: let resultArray = [addon for ([,addon] of Iterator(results))]; + let resultArray = []; + for (let [,addon] of Iterator(results)) { + resultArray.push(addon); + } logger.debug(resultArray.length + " addons imported.") aCallback(resultArray); }); @@ -74,7 +77,7 @@ this.AddonRepository_SQLiteMigrator = { * * @return bool Whether the DB was opened successfully. */ - _openConnection: function() { + _openConnection: function AD_openConnection() { delete this.connection; let dbfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_DATABASE], true); @@ -142,10 +145,8 @@ this.AddonRepository_SQLiteMigrator = { }, _closeConnection: function() { - for (let key in this.asyncStatementsCache) { - let stmt = this.asyncStatementsCache[key]; + for each (let stmt in this.asyncStatementsCache) stmt.finalize(); - } this.asyncStatementsCache = {}; if (this.connection) @@ -161,23 +162,24 @@ this.AddonRepository_SQLiteMigrator = { * @param aCallback * The callback to pass the add-ons back to */ - _retrieveStoredData: function(aCallback) { + _retrieveStoredData: function AD_retrieveStoredData(aCallback) { + let self = this; let addons = {}; // Retrieve all data from the addon table - let getAllAddons = () => { - this.getAsyncStatement("getAllAddons").executeAsync({ - handleResult: aResults => { + function getAllAddons() { + self.getAsyncStatement("getAllAddons").executeAsync({ + handleResult: function getAllAddons_handleResult(aResults) { let row = null; while ((row = aResults.getNextRow())) { let internal_id = row.getResultByName("internal_id"); - addons[internal_id] = this._makeAddonFromAsyncRow(row); + addons[internal_id] = self._makeAddonFromAsyncRow(row); } }, - handleError: this.asyncErrorLogger, + handleError: self.asyncErrorLogger, - handleCompletion: function(aReason) { + handleCompletion: function getAllAddons_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { logger.error("Error retrieving add-ons from database. Returning empty results"); aCallback({}); @@ -190,9 +192,9 @@ this.AddonRepository_SQLiteMigrator = { } // Retrieve all data from the developer table - let getAllDevelopers = () => { - this.getAsyncStatement("getAllDevelopers").executeAsync({ - handleResult: aResults => { + function getAllDevelopers() { + self.getAsyncStatement("getAllDevelopers").executeAsync({ + handleResult: function getAllDevelopers_handleResult(aResults) { let row = null; while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); @@ -205,13 +207,13 @@ this.AddonRepository_SQLiteMigrator = { if (!addon.developers) addon.developers = []; - addon.developers.push(this._makeDeveloperFromAsyncRow(row)); + addon.developers.push(self._makeDeveloperFromAsyncRow(row)); } }, - handleError: this.asyncErrorLogger, + handleError: self.asyncErrorLogger, - handleCompletion: function(aReason) { + handleCompletion: function getAllDevelopers_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { logger.error("Error retrieving developers from database. Returning empty results"); aCallback({}); @@ -224,9 +226,9 @@ this.AddonRepository_SQLiteMigrator = { } // Retrieve all data from the screenshot table - let getAllScreenshots = () => { - this.getAsyncStatement("getAllScreenshots").executeAsync({ - handleResult: aResults => { + function getAllScreenshots() { + self.getAsyncStatement("getAllScreenshots").executeAsync({ + handleResult: function getAllScreenshots_handleResult(aResults) { let row = null; while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); @@ -238,13 +240,13 @@ this.AddonRepository_SQLiteMigrator = { let addon = addons[addon_internal_id]; if (!addon.screenshots) addon.screenshots = []; - addon.screenshots.push(this._makeScreenshotFromAsyncRow(row)); + addon.screenshots.push(self._makeScreenshotFromAsyncRow(row)); } }, - handleError: this.asyncErrorLogger, + handleError: self.asyncErrorLogger, - handleCompletion: function(aReason) { + handleCompletion: function getAllScreenshots_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { logger.error("Error retrieving screenshots from database. Returning empty results"); aCallback({}); @@ -256,9 +258,9 @@ this.AddonRepository_SQLiteMigrator = { }); } - let getAllCompatOverrides = () => { - this.getAsyncStatement("getAllCompatOverrides").executeAsync({ - handleResult: aResults => { + function getAllCompatOverrides() { + self.getAsyncStatement("getAllCompatOverrides").executeAsync({ + handleResult: function getAllCompatOverrides_handleResult(aResults) { let row = null; while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); @@ -270,13 +272,13 @@ this.AddonRepository_SQLiteMigrator = { let addon = addons[addon_internal_id]; if (!addon.compatibilityOverrides) addon.compatibilityOverrides = []; - addon.compatibilityOverrides.push(this._makeCompatOverrideFromAsyncRow(row)); + addon.compatibilityOverrides.push(self._makeCompatOverrideFromAsyncRow(row)); } }, - handleError: this.asyncErrorLogger, + handleError: self.asyncErrorLogger, - handleCompletion: function(aReason) { + handleCompletion: function getAllCompatOverrides_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { logger.error("Error retrieving compatibility overrides from database. Returning empty results"); aCallback({}); @@ -288,9 +290,9 @@ this.AddonRepository_SQLiteMigrator = { }); } - let getAllIcons = () => { - this.getAsyncStatement("getAllIcons").executeAsync({ - handleResult: aResults => { + function getAllIcons() { + self.getAsyncStatement("getAllIcons").executeAsync({ + handleResult: function getAllIcons_handleResult(aResults) { let row = null; while ((row = aResults.getNextRow())) { let addon_internal_id = row.getResultByName("addon_internal_id"); @@ -300,16 +302,16 @@ this.AddonRepository_SQLiteMigrator = { } let addon = addons[addon_internal_id]; - let { size, url } = this._makeIconFromAsyncRow(row); + let { size, url } = self._makeIconFromAsyncRow(row); addon.icons[size] = url; if (size == 32) addon.iconURL = url; } }, - handleError: this.asyncErrorLogger, + handleError: self.asyncErrorLogger, - handleCompletion: function(aReason) { + handleCompletion: function getAllIcons_handleCompletion(aReason) { if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) { logger.error("Error retrieving icons from database. Returning empty results"); aCallback({}); @@ -317,10 +319,8 @@ this.AddonRepository_SQLiteMigrator = { } let returnedAddons = {}; - for (let id in addons) { - let addon = addons[id]; + for each (let addon in addons) returnedAddons[addon.id] = addon; - } aCallback(returnedAddons); } }); @@ -342,7 +342,7 @@ this.AddonRepository_SQLiteMigrator = { * @return a mozIStorageAsyncStatement for the SQL corresponding to the * unique key */ - getAsyncStatement: function(aKey) { + getAsyncStatement: function AD_getAsyncStatement(aKey) { if (aKey in this.asyncStatementsCache) return this.asyncStatementsCache[aKey]; @@ -389,7 +389,7 @@ this.AddonRepository_SQLiteMigrator = { * The asynchronous row to use * @return The created add-on */ - _makeAddonFromAsyncRow: function(aRow) { + _makeAddonFromAsyncRow: function AD__makeAddonFromAsyncRow(aRow) { // This is intentionally not an AddonSearchResult object in order // to allow AddonDatabase._parseAddon to parse it, same as if it // was read from the JSON database. @@ -398,7 +398,7 @@ this.AddonRepository_SQLiteMigrator = { for (let prop of PROP_SINGLE) { addon[prop] = aRow.getResultByName(prop) - } + }; return addon; }, @@ -410,7 +410,7 @@ this.AddonRepository_SQLiteMigrator = { * The asynchronous row to use * @return The created developer */ - _makeDeveloperFromAsyncRow: function(aRow) { + _makeDeveloperFromAsyncRow: function AD__makeDeveloperFromAsyncRow(aRow) { let name = aRow.getResultByName("name"); let url = aRow.getResultByName("url") return new AddonManagerPrivate.AddonAuthor(name, url); @@ -423,7 +423,7 @@ this.AddonRepository_SQLiteMigrator = { * The asynchronous row to use * @return The created screenshot */ - _makeScreenshotFromAsyncRow: function(aRow) { + _makeScreenshotFromAsyncRow: function AD__makeScreenshotFromAsyncRow(aRow) { let url = aRow.getResultByName("url"); let width = aRow.getResultByName("width"); let height = aRow.getResultByName("height"); @@ -442,7 +442,7 @@ this.AddonRepository_SQLiteMigrator = { * The asynchronous row to use * @return The created CompatibilityOverride */ - _makeCompatOverrideFromAsyncRow: function(aRow) { + _makeCompatOverrideFromAsyncRow: function AD_makeCompatOverrideFromAsyncRow(aRow) { let type = aRow.getResultByName("type"); let minVersion = aRow.getResultByName("minVersion"); let maxVersion = aRow.getResultByName("maxVersion"); @@ -464,7 +464,7 @@ this.AddonRepository_SQLiteMigrator = { * The asynchronous row to use * @return An object containing the size and URL of the icon */ - _makeIconFromAsyncRow: function(aRow) { + _makeIconFromAsyncRow: function AD_makeIconFromAsyncRow(aRow) { let size = aRow.getResultByName("size"); let url = aRow.getResultByName("url"); return { size: size, url: url }; @@ -478,7 +478,7 @@ this.AddonRepository_SQLiteMigrator = { * @param aErrorString * An error message */ - logSQLError: function(aError, aErrorString) { + logSQLError: function AD_logSQLError(aError, aErrorString) { logger.error("SQL error " + aError + ": " + aErrorString); }, @@ -488,14 +488,14 @@ this.AddonRepository_SQLiteMigrator = { * @param aError * A mozIStorageError to log */ - asyncErrorLogger: function(aError) { + asyncErrorLogger: function AD_asyncErrorLogger(aError) { logger.error("Async SQL error " + aError.result + ": " + aError.message); }, /** * Synchronously creates the triggers in the database. */ - _createTriggers: function() { + _createTriggers: function AD__createTriggers() { this.connection.executeSimpleSQL("DROP TRIGGER IF EXISTS delete_addon"); this.connection.executeSimpleSQL("CREATE TRIGGER delete_addon AFTER DELETE " + "ON addon BEGIN " + @@ -509,7 +509,7 @@ this.AddonRepository_SQLiteMigrator = { /** * Synchronously creates the indices in the database. */ - _createIndices: function() { + _createIndices: function AD__createIndices() { this.connection.executeSimpleSQL("CREATE INDEX IF NOT EXISTS developer_idx " + "ON developer (addon_internal_id)"); this.connection.executeSimpleSQL("CREATE INDEX IF NOT EXISTS screenshot_idx " + diff --git a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm deleted file mode 100644 index 6422929b1..000000000 --- a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm +++ /dev/null @@ -1,1231 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* eslint "mozilla/no-aArgs": 1 */ -/* eslint "no-unused-vars": [2, {"args": "none", "varsIgnorePattern": "^(Cc|Ci|Cr|Cu|EXPORTED_SYMBOLS)$"}] */ -/* eslint "semi": [2, "always"] */ -/* eslint "valid-jsdoc": [2, {requireReturn: false}] */ - -var EXPORTED_SYMBOLS = ["AddonTestUtils", "MockAsyncShutdown"]; - -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; - -const CERTDB_CONTRACTID = "@mozilla.org/security/x509certdb;1"; -const CERTDB_CID = Components.ID("{fb0bbc5c-452e-4783-b32c-80124693d871}"); - - -Cu.importGlobalProperties(["fetch", "TextEncoder"]); - -Cu.import("resource://gre/modules/AsyncShutdown.jsm"); -Cu.import("resource://gre/modules/FileUtils.jsm"); -Cu.import("resource://gre/modules/NetUtil.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/Task.jsm"); -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); - -const {EventEmitter} = Cu.import("resource://devtools/shared/event-emitter.js", {}); -const {OS} = Cu.import("resource://gre/modules/osfile.jsm", {}); - -XPCOMUtils.defineLazyModuleGetter(this, "Extension", - "resource://gre/modules/Extension.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "rdfService", - "@mozilla.org/rdf/rdf-service;1", "nsIRDFService"); -XPCOMUtils.defineLazyServiceGetter(this, "uuidGen", - "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator"); - - -XPCOMUtils.defineLazyGetter(this, "AppInfo", () => { - let AppInfo = {}; - Cu.import("resource://testing-common/AppInfo.jsm", AppInfo); - return AppInfo; -}); - - -const ArrayBufferInputStream = Components.Constructor( - "@mozilla.org/io/arraybuffer-input-stream;1", - "nsIArrayBufferInputStream", "setData"); - -const nsFile = Components.Constructor( - "@mozilla.org/file/local;1", - "nsIFile", "initWithPath"); - -const RDFXMLParser = Components.Constructor( - "@mozilla.org/rdf/xml-parser;1", - "nsIRDFXMLParser", "parseString"); - -const RDFDataSource = Components.Constructor( - "@mozilla.org/rdf/datasource;1?name=in-memory-datasource", - "nsIRDFDataSource"); - -const ZipReader = Components.Constructor( - "@mozilla.org/libjar/zip-reader;1", - "nsIZipReader", "open"); - -const ZipWriter = Components.Constructor( - "@mozilla.org/zipwriter;1", - "nsIZipWriter", "open"); - - -// We need some internal bits of AddonManager -var AMscope = Cu.import("resource://gre/modules/AddonManager.jsm", {}); -var {AddonManager, AddonManagerPrivate} = AMscope; - - -// Mock out AddonManager's reference to the AsyncShutdown module so we can shut -// down AddonManager from the test -var MockAsyncShutdown = { - hook: null, - status: null, - profileBeforeChange: { - addBlocker: function(name, blocker, options) { - MockAsyncShutdown.hook = blocker; - MockAsyncShutdown.status = options.fetchState; - } - }, - // We can use the real Barrier - Barrier: AsyncShutdown.Barrier, -}; - -AMscope.AsyncShutdown = MockAsyncShutdown; - - -/** - * Escapes any occurances of &, ", < or > with XML entities. - * - * @param {string} str - * The string to escape. - * @return {string} The escaped string. - */ -function escapeXML(str) { - let replacements = {"&": "&", '"': """, "'": "'", "<": "<", ">": ">"}; - return String(str).replace(/[&"''<>]/g, m => replacements[m]); -} - -/** - * A tagged template function which escapes any XML metacharacters in - * interpolated values. - * - * @param {Array<string>} strings - * An array of literal strings extracted from the templates. - * @param {Array} values - * An array of interpolated values extracted from the template. - * @returns {string} - * The result of the escaped values interpolated with the literal - * strings. - */ -function escaped(strings, ...values) { - let result = []; - - for (let [i, string] of strings.entries()) { - result.push(string); - if (i < values.length) - result.push(escapeXML(values[i])); - } - - return result.join(""); -} - - -class AddonsList { - constructor(extensionsINI) { - this.multiprocessIncompatibleIDs = new Set(); - - if (!extensionsINI.exists()) { - this.extensions = []; - this.themes = []; - return; - } - - let factory = Cc["@mozilla.org/xpcom/ini-parser-factory;1"] - .getService(Ci.nsIINIParserFactory); - - let parser = factory.createINIParser(extensionsINI); - - function readDirectories(section) { - var dirs = []; - var keys = parser.getKeys(section); - for (let key of XPCOMUtils.IterStringEnumerator(keys)) { - let descriptor = parser.getString(section, key); - - let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - try { - file.persistentDescriptor = descriptor; - } catch (e) { - // Throws if the directory doesn't exist, we can ignore this since the - // platform will too. - continue; - } - dirs.push(file); - } - return dirs; - } - - this.extensions = readDirectories("ExtensionDirs"); - this.themes = readDirectories("ThemeDirs"); - - var keys = parser.getKeys("MultiprocessIncompatibleExtensions"); - for (let key of XPCOMUtils.IterStringEnumerator(keys)) { - let id = parser.getString("MultiprocessIncompatibleExtensions", key); - this.multiprocessIncompatibleIDs.add(id); - } - } - - hasItem(type, dir, id) { - var path = dir.clone(); - path.append(id); - - var xpiPath = dir.clone(); - xpiPath.append(`${id}.xpi`); - - return this[type].some(file => { - if (!file.exists()) - throw new Error(`Non-existent path found in extensions.ini: ${file.path}`); - - if (file.isDirectory()) - return file.equals(path); - if (file.isFile()) - return file.equals(xpiPath); - return false; - }); - } - - isMultiprocessIncompatible(id) { - return this.multiprocessIncompatibleIDs.has(id); - } - - hasTheme(dir, id) { - return this.hasItem("themes", dir, id); - } - - hasExtension(dir, id) { - return this.hasItem("extensions", dir, id); - } -} - -var AddonTestUtils = { - addonIntegrationService: null, - addonsList: null, - appInfo: null, - extensionsINI: null, - testUnpacked: false, - useRealCertChecks: false, - - init(testScope) { - this.testScope = testScope; - - // Get the profile directory for tests to use. - this.profileDir = testScope.do_get_profile(); - - this.extensionsINI = this.profileDir.clone(); - this.extensionsINI.append("extensions.ini"); - - // Register a temporary directory for the tests. - this.tempDir = this.profileDir.clone(); - this.tempDir.append("temp"); - this.tempDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - this.registerDirectory("TmpD", this.tempDir); - - // Create a replacement app directory for the tests. - const appDirForAddons = this.profileDir.clone(); - appDirForAddons.append("appdir-addons"); - appDirForAddons.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - this.registerDirectory("XREAddonAppDir", appDirForAddons); - - - // Enable more extensive EM logging - Services.prefs.setBoolPref("extensions.logging.enabled", true); - - // By default only load extensions from the profile install location - Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_PROFILE); - - // By default don't disable add-ons from any scope - Services.prefs.setIntPref("extensions.autoDisableScopes", 0); - - // By default, don't cache add-ons in AddonRepository.jsm - Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false); - - // Disable the compatibility updates window by default - Services.prefs.setBoolPref("extensions.showMismatchUI", false); - - // Point update checks to the local machine for fast failures - Services.prefs.setCharPref("extensions.update.url", "http://127.0.0.1/updateURL"); - Services.prefs.setCharPref("extensions.update.background.url", "http://127.0.0.1/updateBackgroundURL"); - Services.prefs.setCharPref("extensions.blocklist.url", "http://127.0.0.1/blocklistURL"); - - // By default ignore bundled add-ons - Services.prefs.setBoolPref("extensions.installDistroAddons", false); - - // By default don't check for hotfixes - Services.prefs.setCharPref("extensions.hotfix.id", ""); - - // Ensure signature checks are enabled by default - Services.prefs.setBoolPref("xpinstall.signatures.required", true); - - - // Write out an empty blocklist.xml file to the profile to ensure nothing - // is blocklisted by default - var blockFile = OS.Path.join(this.profileDir.path, "blocklist.xml"); - - var data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + - "<blocklist xmlns=\"http://www.mozilla.org/2006/addons-blocklist\">\n" + - "</blocklist>\n"; - - this.awaitPromise(OS.File.writeAtomic(blockFile, new TextEncoder().encode(data))); - - - // Make sure that a given path does not exist - function pathShouldntExist(file) { - if (file.exists()) { - throw new Error(`Test cleanup: path ${file.path} exists when it should not`); - } - } - - testScope.do_register_cleanup(() => { - for (let file of this.tempXPIs) { - if (file.exists()) - file.remove(false); - } - - // Check that the temporary directory is empty - var dirEntries = this.tempDir.directoryEntries - .QueryInterface(Ci.nsIDirectoryEnumerator); - var entries = []; - while (dirEntries.hasMoreElements()) - entries.push(dirEntries.nextFile.leafName); - if (entries.length) - throw new Error(`Found unexpected files in temporary directory: ${entries.join(", ")}`); - - dirEntries.close(); - - try { - appDirForAddons.remove(true); - } catch (ex) { - testScope.do_print(`Got exception removing addon app dir: ${ex}`); - } - - // ensure no leftover files in the system addon upgrade location - let featuresDir = this.profileDir.clone(); - featuresDir.append("features"); - // upgrade directories will be in UUID folders under features/ - let systemAddonDirs = []; - if (featuresDir.exists()) { - let featuresDirEntries = featuresDir.directoryEntries - .QueryInterface(Ci.nsIDirectoryEnumerator); - while (featuresDirEntries.hasMoreElements()) { - let entry = featuresDirEntries.getNext(); - entry.QueryInterface(Components.interfaces.nsIFile); - systemAddonDirs.push(entry); - } - - systemAddonDirs.map(dir => { - dir.append("stage"); - pathShouldntExist(dir); - }); - } - - // ensure no leftover files in the user addon location - let testDir = this.profileDir.clone(); - testDir.append("extensions"); - testDir.append("trash"); - pathShouldntExist(testDir); - - testDir.leafName = "staged"; - pathShouldntExist(testDir); - - return this.promiseShutdownManager(); - }); - }, - - /** - * Helper to spin the event loop until a promise resolves or rejects - * - * @param {Promise} promise - * The promise to wait on. - * @returns {*} The promise's resolution value. - * @throws The promise's rejection value, if it rejects. - */ - awaitPromise(promise) { - let done = false; - let result; - let error; - promise.then( - val => { result = val; }, - err => { error = err; } - ).then(() => { - done = true; - }); - - while (!done) - Services.tm.mainThread.processNextEvent(true); - - if (error !== undefined) - throw error; - return result; - }, - - createAppInfo(ID, name, version, platformVersion = "1.0") { - AppInfo.updateAppInfo({ - ID, name, version, platformVersion, - crashReporter: true, - extraProps: { - browserTabsRemoteAutostart: false, - }, - }); - this.appInfo = AppInfo.getAppInfo(); - }, - - getManifestURI(file) { - if (file.isDirectory()) { - file.append("install.rdf"); - if (file.exists()) { - return NetUtil.newURI(file); - } - - file.leafName = "manifest.json"; - if (file.exists()) - return NetUtil.newURI(file); - - throw new Error("No manifest file present"); - } - - let zip = ZipReader(file); - try { - let uri = NetUtil.newURI(file); - - if (zip.hasEntry("install.rdf")) { - return NetUtil.newURI(`jar:${uri.spec}!/install.rdf`); - } - - if (zip.hasEntry("manifest.json")) { - return NetUtil.newURI(`jar:${uri.spec}!/manifest.json`); - } - - throw new Error("No manifest file present"); - } finally { - zip.close(); - } - }, - - getIDFromManifest: Task.async(function*(manifestURI) { - let body = yield fetch(manifestURI.spec); - - if (manifestURI.spec.endsWith(".rdf")) { - let data = yield body.text(); - - let ds = new RDFDataSource(); - new RDFXMLParser(ds, manifestURI, data); - - let rdfID = ds.GetTarget(rdfService.GetResource("urn:mozilla:install-manifest"), - rdfService.GetResource("http://www.mozilla.org/2004/em-rdf#id"), - true); - return rdfID.QueryInterface(Ci.nsIRDFLiteral).Value; - } - - let manifest = yield body.json(); - try { - return manifest.applications.gecko.id; - } catch (e) { - // IDs for WebExtensions are extracted from the certificate when - // not present in the manifest, so just generate a random one. - return uuidGen.generateUUID().number; - } - }), - - overrideCertDB() { - // Unregister the real database. This only works because the add-ons manager - // hasn't started up and grabbed the certificate database yet. - let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - let factory = registrar.getClassObject(CERTDB_CID, Ci.nsIFactory); - registrar.unregisterFactory(CERTDB_CID, factory); - - // Get the real DB - let realCertDB = factory.createInstance(null, Ci.nsIX509CertDB); - - - let verifyCert = Task.async(function*(file, result, cert, callback) { - if (result == Cr.NS_ERROR_SIGNED_JAR_NOT_SIGNED && - !this.useRealCertChecks && callback.wrappedJSObject) { - // Bypassing XPConnect allows us to create a fake x509 certificate from JS - callback = callback.wrappedJSObject; - - try { - let manifestURI = this.getManifestURI(file); - - let id = yield this.getIDFromManifest(manifestURI); - - let fakeCert = {commonName: id}; - - return [callback, Cr.NS_OK, fakeCert]; - } catch (e) { - // If there is any error then just pass along the original results - } finally { - // Make sure to close the open zip file or it will be locked. - if (file.isFile()) - Services.obs.notifyObservers(file, "flush-cache-entry", "cert-override"); - } - } - - return [callback, result, cert]; - }).bind(this); - - - function FakeCertDB() { - for (let property of Object.keys(realCertDB)) { - if (property in this) - continue; - - if (typeof realCertDB[property] == "function") - this[property] = realCertDB[property].bind(realCertDB); - } - } - FakeCertDB.prototype = { - openSignedAppFileAsync(root, file, callback) { - // First try calling the real cert DB - realCertDB.openSignedAppFileAsync(root, file, (result, zipReader, cert) => { - verifyCert(file.clone(), result, cert, callback) - .then(([callback, result, cert]) => { - callback.openSignedAppFileFinished(result, zipReader, cert); - }); - }); - }, - - verifySignedDirectoryAsync(root, dir, callback) { - // First try calling the real cert DB - realCertDB.verifySignedDirectoryAsync(root, dir, (result, cert) => { - verifyCert(dir.clone(), result, cert, callback) - .then(([callback, result, cert]) => { - callback.verifySignedDirectoryFinished(result, cert); - }); - }); - }, - - QueryInterface: XPCOMUtils.generateQI([Ci.nsIX509CertDB]), - }; - - let certDBFactory = XPCOMUtils.generateSingletonFactory(FakeCertDB); - registrar.registerFactory(CERTDB_CID, "CertDB", - CERTDB_CONTRACTID, certDBFactory); - }, - - /** - * Starts up the add-on manager as if it was started by the application. - * - * @param {boolean} [appChanged = true] - * An optional boolean parameter to simulate the case where the - * application has changed version since the last run. If not passed it - * defaults to true - * @returns {Promise} - * Resolves when the add-on manager's startup has completed. - */ - promiseStartupManager(appChanged = true) { - if (this.addonIntegrationService) - throw new Error("Attempting to startup manager that was already started."); - - if (appChanged && this.extensionsINI.exists()) - this.extensionsINI.remove(true); - - this.addonIntegrationService = Cc["@mozilla.org/addons/integration;1"] - .getService(Ci.nsIObserver); - - this.addonIntegrationService.observe(null, "addons-startup", null); - - this.emit("addon-manager-started"); - - // Load the add-ons list as it was after extension registration - this.loadAddonsList(); - - return Promise.resolve(); - }, - - promiseShutdownManager() { - if (!this.addonIntegrationService) - return Promise.resolve(false); - - Services.obs.notifyObservers(null, "quit-application-granted", null); - return MockAsyncShutdown.hook() - .then(() => { - this.emit("addon-manager-shutdown"); - - this.addonIntegrationService = null; - - // Load the add-ons list as it was after application shutdown - this.loadAddonsList(); - - // Clear any crash report annotations - this.appInfo.annotations = {}; - - // Force the XPIProvider provider to reload to better - // simulate real-world usage. - let XPIscope = Cu.import("resource://gre/modules/addons/XPIProvider.jsm"); - // This would be cleaner if I could get it as the rejection reason from - // the AddonManagerInternal.shutdown() promise - let shutdownError = XPIscope.XPIProvider._shutdownError; - - AddonManagerPrivate.unregisterProvider(XPIscope.XPIProvider); - Cu.unload("resource://gre/modules/addons/XPIProvider.jsm"); - - if (shutdownError) - throw shutdownError; - - return true; - }); - }, - - promiseRestartManager(newVersion) { - return this.promiseShutdownManager() - .then(() => { - if (newVersion) - this.appInfo.version = newVersion; - - return this.promiseStartupManager(!!newVersion); - }); - }, - - loadAddonsList() { - this.addonsList = new AddonsList(this.extensionsINI); - }, - - /** - * Creates an update.rdf structure as a string using for the update data passed. - * - * @param {Object} data - * The update data as a JS object. Each property name is an add-on ID, - * the property value is an array of each version of the add-on. Each - * array value is a JS object containing the data for the version, at - * minimum a "version" and "targetApplications" property should be - * included to create a functional update manifest. - * @return {string} The update.rdf structure as a string. - */ - createUpdateRDF(data) { - var rdf = '<?xml version="1.0"?>\n'; - rdf += '<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' + - ' xmlns:em="http://www.mozilla.org/2004/em-rdf#">\n'; - - for (let addon in data) { - rdf += escaped` <Description about="urn:mozilla:extension:${addon}"><em:updates><Seq>\n`; - - for (let versionData of data[addon]) { - rdf += ' <li><Description>\n'; - rdf += this._writeProps(versionData, ["version", "multiprocessCompatible"], - ` `); - for (let app of versionData.targetApplications || []) { - rdf += " <em:targetApplication><Description>\n"; - rdf += this._writeProps(app, ["id", "minVersion", "maxVersion", "updateLink", "updateHash"], - ` `); - rdf += " </Description></em:targetApplication>\n"; - } - rdf += ' </Description></li>\n'; - } - rdf += ' </Seq></em:updates></Description>\n'; - } - rdf += "</RDF>\n"; - - return rdf; - }, - - _writeProps(obj, props, indent = " ") { - let items = []; - for (let prop of props) { - if (prop in obj) - items.push(escaped`${indent}<em:${prop}>${obj[prop]}</em:${prop}>\n`); - } - return items.join(""); - }, - - _writeArrayProps(obj, props, indent = " ") { - let items = []; - for (let prop of props) { - for (let val of obj[prop] || []) - items.push(escaped`${indent}<em:${prop}>${val}</em:${prop}>\n`); - } - return items.join(""); - }, - - _writeLocaleStrings(data) { - let items = []; - - items.push(this._writeProps(data, ["name", "description", "creator", "homepageURL"])); - items.push(this._writeArrayProps(data, ["developer", "translator", "contributor"])); - - return items.join(""); - }, - - createInstallRDF(data) { - var rdf = '<?xml version="1.0"?>\n'; - rdf += '<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' + - ' xmlns:em="http://www.mozilla.org/2004/em-rdf#">\n'; - - rdf += '<Description about="urn:mozilla:install-manifest">\n'; - - let props = ["id", "version", "type", "internalName", "updateURL", "updateKey", - "optionsURL", "optionsType", "aboutURL", "iconURL", "icon64URL", - "skinnable", "bootstrap", "unpack", "strictCompatibility", - "multiprocessCompatible", "hasEmbeddedWebExtension"]; - rdf += this._writeProps(data, props); - - rdf += this._writeLocaleStrings(data); - - for (let platform of data.targetPlatforms || []) - rdf += escaped`<em:targetPlatform>${platform}</em:targetPlatform>\n`; - - for (let app of data.targetApplications || []) { - rdf += "<em:targetApplication><Description>\n"; - rdf += this._writeProps(app, ["id", "minVersion", "maxVersion"]); - rdf += "</Description></em:targetApplication>\n"; - } - - for (let localized of data.localized || []) { - rdf += "<em:localized><Description>\n"; - rdf += this._writeArrayProps(localized, ["locale"]); - rdf += this._writeLocaleStrings(localized); - rdf += "</Description></em:localized>\n"; - } - - for (let dep of data.dependencies || []) - rdf += escaped`<em:dependency><Description em:id="${dep}"/></em:dependency>\n`; - - rdf += "</Description>\n</RDF>\n"; - return rdf; - }, - - /** - * Recursively create all directories upto and including the given - * path, if they do not exist. - * - * @param {string} path The path of the directory to create. - * @returns {Promise} Resolves when all directories have been created. - */ - recursiveMakeDir(path) { - let paths = []; - for (let lastPath; path != lastPath; lastPath = path, path = OS.Path.dirname(path)) - paths.push(path); - - return Promise.all(paths.reverse().map(path => - OS.File.makeDir(path, {ignoreExisting: true}).catch(() => {}))); - }, - - /** - * Writes the given data to a file in the given zip file. - * - * @param {string|nsIFile} zipFile - * The zip file to write to. - * @param {Object} files - * An object containing filenames and the data to write to the - * corresponding paths in the zip file. - * @param {integer} [flags = 0] - * Additional flags to open the file with. - */ - writeFilesToZip(zipFile, files, flags = 0) { - if (typeof zipFile == "string") - zipFile = nsFile(zipFile); - - var zipW = ZipWriter(zipFile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | flags); - - for (let [path, data] of Object.entries(files)) { - if (!(data instanceof ArrayBuffer)) - data = new TextEncoder("utf-8").encode(data).buffer; - - let stream = ArrayBufferInputStream(data, 0, data.byteLength); - - // Note these files are being created in the XPI archive with date "0" which is 1970-01-01. - zipW.addEntryStream(path, 0, Ci.nsIZipWriter.COMPRESSION_NONE, - stream, false); - } - - zipW.close(); - }, - - promiseWriteFilesToZip: Task.async(function*(zip, files, flags) { - yield this.recursiveMakeDir(OS.Path.dirname(zip)); - - this.writeFilesToZip(zip, files, flags); - - return Promise.resolve(nsFile(zip)); - }), - - promiseWriteFilesToDir: Task.async(function*(dir, files) { - yield this.recursiveMakeDir(dir); - - for (let [path, data] of Object.entries(files)) { - path = path.split("/"); - let leafName = path.pop(); - - // Create parent directories, if necessary. - let dirPath = dir; - for (let subDir of path) { - dirPath = OS.Path.join(dirPath, subDir); - yield OS.Path.makeDir(dirPath, {ignoreExisting: true}); - } - - if (typeof data == "string") - data = new TextEncoder("utf-8").encode(data); - - yield OS.File.writeAtomic(OS.Path.join(dirPath, leafName), data); - } - - return nsFile(dir); - }), - - promiseWriteFilesToExtension(dir, id, files, unpacked = this.testUnpacked) { - if (typeof files["install.rdf"] === "object") - files["install.rdf"] = this.createInstallRDF(files["install.rdf"]); - - if (unpacked) { - let path = OS.Path.join(dir, id); - - return this.promiseWriteFilesToDir(path, files); - } - - let xpi = OS.Path.join(dir, `${id}.xpi`); - - return this.promiseWriteFilesToZip(xpi, files); - }, - - tempXPIs: [], - /** - * Creates an XPI file for some manifest data in the temporary directory and - * returns the nsIFile for it. The file will be deleted when the test completes. - * - * @param {object} files - * The object holding data about the add-on - * @return {nsIFile} A file pointing to the created XPI file - */ - createTempXPIFile(files) { - var file = this.tempDir.clone(); - let uuid = uuidGen.generateUUID().number.slice(1, -1); - file.append(`${uuid}.xpi`); - - this.tempXPIs.push(file); - - if (typeof files["install.rdf"] === "object") - files["install.rdf"] = this.createInstallRDF(files["install.rdf"]); - - this.writeFilesToZip(file.path, files); - return file; - }, - - /** - * Creates an XPI file for some WebExtension data in the temporary directory and - * returns the nsIFile for it. The file will be deleted when the test completes. - * - * @param {Object} data - * The object holding data about the add-on, as expected by - * |Extension.generateXPI|. - * @return {nsIFile} A file pointing to the created XPI file - */ - createTempWebExtensionFile(data) { - let file = Extension.generateXPI(data); - this.tempXPIs.push(file); - return file; - }, - - /** - * Creates an extension proxy file. - * See: https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment#Firefox_extension_proxy_file - * - * @param {nsIFile} dir - * The directory to add the proxy file to. - * @param {nsIFile} addon - * An nsIFile for the add-on file that this is a proxy file for. - * @param {string} id - * A string to use for the add-on ID. - * @returns {Promise} Resolves when the file has been created. - */ - promiseWriteProxyFileToDir(dir, addon, id) { - let files = { - [id]: addon.path, - }; - - return this.promiseWriteFilesToDir(dir.path, files); - }, - - /** - * Manually installs an XPI file into an install location by either copying the - * XPI there or extracting it depending on whether unpacking is being tested - * or not. - * - * @param {nsIFile} xpiFile - * The XPI file to install. - * @param {nsIFile} installLocation - * The install location (an nsIFile) to install into. - * @param {string} id - * The ID to install as. - * @param {boolean} [unpacked = this.testUnpacked] - * If true, install as an unpacked directory, rather than a - * packed XPI. - * @returns {nsIFile} - * A file pointing to the installed location of the XPI file or - * unpacked directory. - */ - manuallyInstall(xpiFile, installLocation, id, unpacked = this.testUnpacked) { - if (unpacked) { - let dir = installLocation.clone(); - dir.append(id); - dir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - - let zip = ZipReader(xpiFile); - let entries = zip.findEntries(null); - while (entries.hasMore()) { - let entry = entries.getNext(); - let target = dir.clone(); - for (let part of entry.split("/")) - target.append(part); - zip.extract(entry, target); - } - zip.close(); - - return dir; - } - - let target = installLocation.clone(); - target.append(`${id}.xpi`); - xpiFile.copyTo(target.parent, target.leafName); - return target; - }, - - /** - * Manually uninstalls an add-on by removing its files from the install - * location. - * - * @param {nsIFile} installLocation - * The nsIFile of the install location to remove from. - * @param {string} id - * The ID of the add-on to remove. - * @param {boolean} [unpacked = this.testUnpacked] - * If true, uninstall an unpacked directory, rather than a - * packed XPI. - */ - manuallyUninstall(installLocation, id, unpacked = this.testUnpacked) { - let file = this.getFileForAddon(installLocation, id, unpacked); - - // In reality because the app is restarted a flush isn't necessary for XPIs - // removed outside the app, but for testing we must flush manually. - if (file.isFile()) - Services.obs.notifyObservers(file, "flush-cache-entry", null); - - file.remove(true); - }, - - /** - * Gets the nsIFile for where an add-on is installed. It may point to a file or - * a directory depending on whether add-ons are being installed unpacked or not. - * - * @param {nsIFile} dir - * The nsIFile for the install location - * @param {string} id - * The ID of the add-on - * @param {boolean} [unpacked = this.testUnpacked] - * If true, return the path to an unpacked directory, rather than a - * packed XPI. - * @returns {nsIFile} - * A file pointing to the XPI file or unpacked directory where - * the add-on should be installed. - */ - getFileForAddon(dir, id, unpacked = this.testUnpacked) { - dir = dir.clone(); - if (unpacked) - dir.append(id); - else - dir.append(`${id}.xpi`); - return dir; - }, - - /** - * Sets the last modified time of the extension, usually to trigger an update - * of its metadata. If the extension is unpacked, this function assumes that - * the extension contains only the install.rdf file. - * - * @param {nsIFile} ext A file pointing to either the packed extension or its unpacked directory. - * @param {number} time The time to which we set the lastModifiedTime of the extension - * - * @deprecated Please use promiseSetExtensionModifiedTime instead - */ - setExtensionModifiedTime(ext, time) { - ext.lastModifiedTime = time; - if (ext.isDirectory()) { - let entries = ext.directoryEntries - .QueryInterface(Ci.nsIDirectoryEnumerator); - while (entries.hasMoreElements()) - this.setExtensionModifiedTime(entries.nextFile, time); - entries.close(); - } - }, - - promiseSetExtensionModifiedTime: Task.async(function*(path, time) { - yield OS.File.setDates(path, time, time); - - let iterator = new OS.File.DirectoryIterator(path); - try { - yield iterator.forEach(entry => { - return this.promiseSetExtensionModifiedTime(entry.path, time); - }); - } catch (ex) { - if (ex instanceof OS.File.Error) - return; - throw ex; - } finally { - iterator.close().catch(() => {}); - } - }), - - registerDirectory(key, dir) { - var dirProvider = { - getFile(prop, persistent) { - persistent.value = false; - if (prop == key) - return dir.clone(); - return null; - }, - - QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider]), - }; - Services.dirsvc.registerProvider(dirProvider); - }, - - /** - * Returns a promise that resolves when the given add-on event is fired. The - * resolved value is an array of arguments passed for the event. - * - * @param {string} event - * The name of the AddonListener event handler method for which - * an event is expected. - * @returns {Promise<Array>} - * Resolves to an array containing the event handler's - * arguments the first time it is called. - */ - promiseAddonEvent(event) { - return new Promise(resolve => { - let listener = { - [event](...args) { - AddonManager.removeAddonListener(listener); - resolve(args); - }, - }; - - AddonManager.addAddonListener(listener); - }); - }, - - /** - * A helper method to install AddonInstall and wait for completion. - * - * @param {AddonInstall} install - * The add-on to install. - * @returns {Promise} - * Resolves when the install completes, either successfully or - * in failure. - */ - promiseCompleteInstall(install) { - let listener; - return new Promise(resolve => { - listener = { - onDownloadFailed: resolve, - onDownloadCancelled: resolve, - onInstallFailed: resolve, - onInstallCancelled: resolve, - onInstallEnded: resolve, - onInstallPostponed: resolve, - }; - - install.addListener(listener); - install.install(); - }).then(() => { - install.removeListener(listener); - }); - }, - - /** - * A helper method to install a file. - * - * @param {nsIFile} file - * The file to install - * @param {boolean} [ignoreIncompatible = false] - * Optional parameter to ignore add-ons that are incompatible - * with the application - * @returns {Promise} - * Resolves when the install has completed. - */ - promiseInstallFile(file, ignoreIncompatible = false) { - return new Promise((resolve, reject) => { - AddonManager.getInstallForFile(file, install => { - if (!install) - reject(new Error(`No AddonInstall created for ${file.path}`)); - else if (install.state != AddonManager.STATE_DOWNLOADED) - reject(new Error(`Expected file to be downloaded for install of ${file.path}`)); - else if (ignoreIncompatible && install.addon.appDisabled) - resolve(); - else - resolve(this.promiseCompleteInstall(install)); - }); - }); - }, - - /** - * A helper method to install an array of files. - * - * @param {Iterable<nsIFile>} files - * The files to install - * @param {boolean} [ignoreIncompatible = false] - * Optional parameter to ignore add-ons that are incompatible - * with the application - * @returns {Promise} - * Resolves when the installs have completed. - */ - promiseInstallAllFiles(files, ignoreIncompatible = false) { - return Promise.all(Array.from( - files, - file => this.promiseInstallFile(file, ignoreIncompatible))); - }, - - promiseCompleteAllInstalls(installs) { - return Promise.all(Array.from(installs, this.promiseCompleteInstall)); - }, - - /** - * A promise-based variant of AddonManager.getAddonsByIDs. - * - * @param {Array<string>} list - * As the first argument of AddonManager.getAddonsByIDs - * @return {Promise<Array<Addon>>} - * Resolves to the array of add-ons for the given IDs. - */ - promiseAddonsByIDs(list) { - return new Promise(resolve => AddonManager.getAddonsByIDs(list, resolve)); - }, - - /** - * A promise-based variant of AddonManager.getAddonByID. - * - * @param {string} id - * The ID of the add-on. - * @return {Promise<Addon>} - * Resolves to the add-on with the given ID. - */ - promiseAddonByID(id) { - return new Promise(resolve => AddonManager.getAddonByID(id, resolve)); - }, - - /** - * Returns a promise that will be resolved when an add-on update check is - * complete. The value resolved will be an AddonInstall if a new version was - * found. - * - * @param {object} addon The add-on to find updates for. - * @param {integer} reason The type of update to find. - * @return {Promise<object>} an object containing information about the update. - */ - promiseFindAddonUpdates(addon, reason = AddonManager.UPDATE_WHEN_PERIODIC_UPDATE) { - let equal = this.testScope.equal; - return new Promise((resolve, reject) => { - let result = {}; - addon.findUpdates({ - onNoCompatibilityUpdateAvailable: function(addon2) { - if ("compatibilityUpdate" in result) { - throw new Error("Saw multiple compatibility update events"); - } - equal(addon, addon2, "onNoCompatibilityUpdateAvailable"); - result.compatibilityUpdate = false; - }, - - onCompatibilityUpdateAvailable: function(addon2) { - if ("compatibilityUpdate" in result) { - throw new Error("Saw multiple compatibility update events"); - } - equal(addon, addon2, "onCompatibilityUpdateAvailable"); - result.compatibilityUpdate = true; - }, - - onNoUpdateAvailable: function(addon2) { - if ("updateAvailable" in result) { - throw new Error("Saw multiple update available events"); - } - equal(addon, addon2, "onNoUpdateAvailable"); - result.updateAvailable = false; - }, - - onUpdateAvailable: function(addon2, install) { - if ("updateAvailable" in result) { - throw new Error("Saw multiple update available events"); - } - equal(addon, addon2, "onUpdateAvailable"); - result.updateAvailable = install; - }, - - onUpdateFinished: function(addon2, error) { - equal(addon, addon2, "onUpdateFinished"); - if (error == AddonManager.UPDATE_STATUS_NO_ERROR) { - resolve(result); - } else { - result.error = error; - reject(result); - } - } - }, reason); - }); - }, - - /** - * A promise-based variant of AddonManager.getAddonsWithOperationsByTypes - * - * @param {Array<string>} types - * The first argument to AddonManager.getAddonsWithOperationsByTypes - * @return {Promise<Array<Addon>>} - * Resolves to an array of add-ons with the given operations - * pending. - */ - promiseAddonsWithOperationsByTypes(types) { - return new Promise(resolve => AddonManager.getAddonsWithOperationsByTypes(types, resolve)); - }, - - /** - * Monitors console output for the duration of a task, and returns a promise - * which resolves to a tuple containing a list of all console messages - * generated during the task's execution, and the result of the task itself. - * - * @param {function} task - * The task to run while monitoring console output. May be - * either a generator function, per Task.jsm, or an ordinary - * function which returns promose. - * @return {Promise<[Array<nsIConsoleMessage>, *]>} - * Resolves to an object containing a `messages` property, with - * the array of console messages emitted during the execution - * of the task, and a `result` property, containing the task's - * return value. - */ - promiseConsoleOutput: Task.async(function*(task) { - const DONE = "=== xpcshell test console listener done ==="; - - let listener, messages = []; - let awaitListener = new Promise(resolve => { - listener = msg => { - if (msg == DONE) { - resolve(); - } else { - msg instanceof Ci.nsIScriptError; - messages.push(msg); - } - }; - }); - - Services.console.registerListener(listener); - try { - let result = yield task(); - - Services.console.logStringMessage(DONE); - yield awaitListener; - - return {messages, result}; - } finally { - Services.console.unregisterListener(listener); - } - }), -}; - -for (let [key, val] of Object.entries(AddonTestUtils)) { - if (typeof val == "function") - AddonTestUtils[key] = val.bind(AddonTestUtils); -} - -EventEmitter.decorate(AddonTestUtils); diff --git a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm index 63c16737c..939e2e269 100644 --- a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm +++ b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm @@ -22,6 +22,9 @@ const PREFIX_ITEM = "urn:mozilla:item:"; const PREFIX_EXTENSION = "urn:mozilla:extension:"; const PREFIX_THEME = "urn:mozilla:theme:"; const TOOLKIT_ID = "toolkit@mozilla.org" +#ifdef MOZ_PHOENIX_EXTENSIONS +const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" +#endif const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml" const PREF_UPDATE_REQUIREBUILTINCERTS = "extensions.update.requireBuiltInCerts"; @@ -31,16 +34,11 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate", - "resource://gre/modules/AddonManager.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository", "resource://gre/modules/addons/AddonRepository.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest", - "resource://gre/modules/ServiceRequest.jsm"); - // Shared code for suppressing bad cert dialogs. -XPCOMUtils.defineLazyGetter(this, "CertUtils", function() { +XPCOMUtils.defineLazyGetter(this, "CertUtils", function certUtilsLazyGetter() { let certUtils = {}; Components.utils.import("resource://gre/modules/CertUtils.jsm", certUtils); return certUtils; @@ -82,7 +80,7 @@ RDFSerializer.prototype = { * @return a string with all characters invalid in XML character data * converted to entity references. */ - escapeEntities: function(aString) { + escapeEntities: function RDFS_escapeEntities(aString) { aString = aString.replace(/&/g, "&"); aString = aString.replace(/</g, "<"); aString = aString.replace(/>/g, ">"); @@ -100,7 +98,8 @@ RDFSerializer.prototype = { * The current level of indent for pretty-printing * @return a string containing the serialized elements. */ - serializeContainerItems: function(aDs, aContainer, aIndent) { + serializeContainerItems: function RDFS_serializeContainerItems(aDs, aContainer, + aIndent) { var result = ""; var items = aContainer.GetElements(); while (items.hasMoreElements()) { @@ -126,7 +125,9 @@ RDFSerializer.prototype = { * @return a string containing the serialized properties. * @throws if the resource contains a property that cannot be serialized */ - serializeResourceProperties: function(aDs, aResource, aIndent) { + serializeResourceProperties: function RDFS_serializeResourceProperties(aDs, + aResource, + aIndent) { var result = ""; var items = []; var arcs = aDs.ArcLabelsOut(aResource); @@ -180,7 +181,7 @@ RDFSerializer.prototype = { * @return a string containing the serialized resource. * @throws if the RDF data contains multiple references to the same resource. */ - serializeResource: function(aDs, aResource, aIndent) { + serializeResource: function RDFS_serializeResource(aDs, aResource, aIndent) { if (this.resources.indexOf(aResource) != -1 ) { // We cannot output multiple references to the same resource. throw Components.Exception("Cannot serialize multiple references to " + aResource.Value); @@ -220,48 +221,6 @@ RDFSerializer.prototype = { } /** - * Sanitizes the update URL in an update item, as returned by - * parseRDFManifest and parseJSONManifest. Ensures that: - * - * - The URL is secure, or secured by a strong enough hash. - * - The security principal of the update manifest has permission to - * load the URL. - * - * @param aUpdate - * The update item to sanitize. - * @param aRequest - * The XMLHttpRequest used to load the manifest. - * @param aHashPattern - * The regular expression used to validate the update hash. - * @param aHashString - * The human-readable string specifying which hash functions - * are accepted. - */ -function sanitizeUpdateURL(aUpdate, aRequest, aHashPattern, aHashString) { - if (aUpdate.updateURL) { - let scriptSecurity = Services.scriptSecurityManager; - let principal = scriptSecurity.getChannelURIPrincipal(aRequest.channel); - try { - // This logs an error on failure, so no need to log it a second time - scriptSecurity.checkLoadURIStrWithPrincipal(principal, aUpdate.updateURL, - scriptSecurity.DISALLOW_SCRIPT); - } catch (e) { - delete aUpdate.updateURL; - return; - } - - if (AddonManager.checkUpdateSecurity && - !aUpdate.updateURL.startsWith("https:") && - !aHashPattern.test(aUpdate.updateHash)) { - logger.warn(`Update link ${aUpdate.updateURL} is not secure and is not verified ` + - `by a strong enough hash (needs to be ${aHashString}).`); - delete aUpdate.updateURL; - delete aUpdate.updateHash; - } - } -} - -/** * Parses an RDF style update manifest into an array of update objects. * * @param aId @@ -270,17 +229,10 @@ function sanitizeUpdateURL(aUpdate, aRequest, aHashPattern, aHashString) { * An optional update key for the add-on * @param aRequest * The XMLHttpRequest that has retrieved the update manifest - * @param aManifestData - * The pre-parsed manifest, as a bare XML DOM document * @return an array of update objects * @throws if the update manifest is invalid in any way */ -function parseRDFManifest(aId, aUpdateKey, aRequest, aManifestData) { - if (aManifestData.documentElement.namespaceURI != PREFIX_NS_RDF) { - throw Components.Exception("Update manifest had an unrecognised namespace: " + - aManifestData.documentElement.namespaceURI); - } - +function parseRDFManifest(aId, aUpdateKey, aRequest) { function EM_R(aProp) { return gRDF.GetResource(PREFIX_NS_EM + aProp); } @@ -323,13 +275,9 @@ function parseRDFManifest(aId, aUpdateKey, aRequest, aManifestData) { let extensionRes = gRDF.GetResource(PREFIX_EXTENSION + aId); let themeRes = gRDF.GetResource(PREFIX_THEME + aId); let itemRes = gRDF.GetResource(PREFIX_ITEM + aId); - let addonRes; - if (ds.ArcLabelsOut(extensionRes).hasMoreElements()) - addonRes = extensionRes; - else if (ds.ArcLabelsOut(themeRes).hasMoreElements()) - addonRes = themeRes; - else - addonRes = itemRes; + let addonRes = ds.ArcLabelsOut(extensionRes).hasMoreElements() ? extensionRes + : ds.ArcLabelsOut(themeRes).hasMoreElements() ? themeRes + : itemRes; // If we have an update key then the update manifest must be signed if (aUpdateKey) { @@ -421,134 +369,16 @@ function parseRDFManifest(aId, aUpdateKey, aRequest, aManifestData) { targetApplications: [appEntry] }; - // The JSON update protocol requires an SHA-2 hash. RDF still - // supports SHA-1, for compatibility reasons. - sanitizeUpdateURL(result, aRequest, /^sha/, "sha1 or stronger"); - - results.push(result); - } - } - return results; -} - -/** - * Parses an JSON update manifest into an array of update objects. - * - * @param aId - * The ID of the add-on being checked for updates - * @param aUpdateKey - * An optional update key for the add-on - * @param aRequest - * The XMLHttpRequest that has retrieved the update manifest - * @param aManifestData - * The pre-parsed manifest, as a JSON object tree - * @return an array of update objects - * @throws if the update manifest is invalid in any way - */ -function parseJSONManifest(aId, aUpdateKey, aRequest, aManifestData) { - if (aUpdateKey) - throw Components.Exception("Update keys are not supported for JSON update manifests"); - - let TYPE_CHECK = { - "array": val => Array.isArray(val), - "object": val => val && typeof val == "object" && !Array.isArray(val), - }; - - function getProperty(aObj, aProperty, aType, aDefault = undefined) { - if (!(aProperty in aObj)) - return aDefault; - - let value = aObj[aProperty]; - - let matchesType = aType in TYPE_CHECK ? TYPE_CHECK[aType](value) : typeof value == aType; - if (!matchesType) - throw Components.Exception(`Update manifest property '${aProperty}' has incorrect type (expected ${aType})`); - - return value; - } - - function getRequiredProperty(aObj, aProperty, aType) { - let value = getProperty(aObj, aProperty, aType); - if (value === undefined) - throw Components.Exception(`Update manifest is missing a required ${aProperty} property.`); - return value; - } - - let manifest = aManifestData; - - if (!TYPE_CHECK["object"](manifest)) - throw Components.Exception("Root element of update manifest must be a JSON object literal"); - - // The set of add-ons this manifest has updates for - let addons = getRequiredProperty(manifest, "addons", "object"); - - // The entry for this particular add-on - let addon = getProperty(addons, aId, "object"); - - // A missing entry doesn't count as a failure, just as no avialable update - // information - if (!addon) { - logger.warn("Update manifest did not contain an entry for " + aId); - return []; - } - - // The list of available updates - let updates = getProperty(addon, "updates", "array", []); - - let results = []; - - for (let update of updates) { - let version = getRequiredProperty(update, "version", "string"); - - logger.debug(`Found an update entry for ${aId} version ${version}`); - - let applications = getProperty(update, "applications", "object", - { gecko: {} }); - - // "gecko" is currently the only supported application entry. If - // it's missing, skip this update. - if (!("gecko" in applications)) { - logger.debug("gecko not in application entry, skipping update of ${addon}") - continue; - } - - let app = getProperty(applications, "gecko", "object"); - - let appEntry = { - id: TOOLKIT_ID, - minVersion: getProperty(app, "strict_min_version", "string", - AddonManagerPrivate.webExtensionsMinPlatformVersion), - maxVersion: "*", - }; - - let result = { - id: aId, - version: version, - multiprocessCompatible: getProperty(update, "multiprocess_compatible", "boolean", true), - updateURL: getProperty(update, "update_link", "string"), - updateHash: getProperty(update, "update_hash", "string"), - updateInfoURL: getProperty(update, "update_info_url", "string"), - strictCompatibility: false, - targetApplications: [appEntry], - }; - - if ("strict_max_version" in app) { - if ("advisory_max_version" in app) { - logger.warn("Ignoring 'advisory_max_version' update manifest property for " + - aId + " property since 'strict_max_version' also present"); + if (result.updateURL && AddonManager.checkUpdateSecurity && + result.updateURL.substring(0, 6) != "https:" && + (!result.updateHash || result.updateHash.substring(0, 3) != "sha")) { + logger.warn("updateLink " + result.updateURL + " is not secure and is not verified" + + " by a strong enough hash (needs to be sha1 or stronger)."); + delete result.updateURL; + delete result.updateHash; } - - appEntry.maxVersion = getProperty(app, "strict_max_version", "string"); - result.strictCompatibility = appEntry.maxVersion != "*"; - } else if ("advisory_max_version" in app) { - appEntry.maxVersion = getProperty(app, "advisory_max_version", "string"); + results.push(result); } - - // The JSON update protocol requires an SHA-2 hash. RDF still - // supports SHA-1, for compatibility reasons. - sanitizeUpdateURL(result, aRequest, /^sha(256|512):/, "sha256 or sha512"); - - results.push(result); } return results; } @@ -581,18 +411,20 @@ function UpdateParser(aId, aUpdateKey, aUrl, aObserver) { logger.debug("Requesting " + aUrl); try { - this.request = new ServiceRequest(); + this.request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. + createInstance(Ci.nsIXMLHttpRequest); this.request.open("GET", this.url, true); this.request.channel.notificationCallbacks = new CertUtils.BadCertHandler(!requireBuiltIn); this.request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE; // Prevent the request from writing to cache. this.request.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING; - this.request.overrideMimeType("text/plain"); + this.request.overrideMimeType("text/xml"); this.request.setRequestHeader("Moz-XPI-Update", "1", true); this.request.timeout = TIMEOUT; - this.request.addEventListener("load", () => this.onLoad(), false); - this.request.addEventListener("error", () => this.onError(), false); - this.request.addEventListener("timeout", () => this.onTimeout(), false); + var self = this; + this.request.addEventListener("load", function loadEventListener(event) { self.onLoad() }, false); + this.request.addEventListener("error", function errorEventListener(event) { self.onError() }, false); + this.request.addEventListener("timeout", function timeoutEventListener(event) { self.onTimeout() }, false); this.request.send(null); } catch (e) { @@ -610,7 +442,7 @@ UpdateParser.prototype = { /** * Called when the manifest has been successfully loaded. */ - onLoad: function() { + onLoad: function UP_onLoad() { let request = this.request; this.request = null; this._doneAt = new Error("place holder"); @@ -626,7 +458,6 @@ UpdateParser.prototype = { CertUtils.checkCert(request.channel, !requireBuiltIn); } catch (e) { - logger.warn("Request failed: " + this.url + " - " + e); this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR); return; } @@ -645,52 +476,41 @@ UpdateParser.prototype = { return; } - // Detect the manifest type by first attempting to parse it as - // JSON, and falling back to parsing it as XML if that fails. - let parser; - try { - try { - let json = JSON.parse(request.responseText); - - parser = () => parseJSONManifest(this.id, this.updateKey, request, json); - } catch (e) { - if (!(e instanceof SyntaxError)) - throw e; - let domParser = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser); - let xml = domParser.parseFromString(request.responseText, "text/xml"); - - if (xml.documentElement.namespaceURI == XMLURI_PARSE_ERROR) - throw new Error("Update manifest was not valid XML or JSON"); - - parser = () => parseRDFManifest(this.id, this.updateKey, request, xml); - } - } catch (e) { - logger.warn("onUpdateCheckComplete failed to determine manifest type"); - this.notifyError(AddonUpdateChecker.ERROR_UNKNOWN_FORMAT); - return; - } - - let results; - try { - results = parser(); - } - catch (e) { - logger.warn("onUpdateCheckComplete failed to parse update manifest", e); + let xml = request.responseXML; + if (!xml || xml.documentElement.namespaceURI == XMLURI_PARSE_ERROR) { + logger.warn("Update manifest was not valid XML"); this.notifyError(AddonUpdateChecker.ERROR_PARSE_ERROR); return; } - if ("onUpdateCheckComplete" in this.observer) { + // We currently only know about RDF update manifests + if (xml.documentElement.namespaceURI == PREFIX_NS_RDF) { + let results = null; + try { - this.observer.onUpdateCheckComplete(results); + results = parseRDFManifest(this.id, this.updateKey, request); } catch (e) { - logger.warn("onUpdateCheckComplete notification failed", e); + logger.warn("onUpdateCheckComplete failed to parse RDF manifest", e); + this.notifyError(AddonUpdateChecker.ERROR_PARSE_ERROR); + return; } + if ("onUpdateCheckComplete" in this.observer) { + try { + this.observer.onUpdateCheckComplete(results); + } + catch (e) { + logger.warn("onUpdateCheckComplete notification failed", e); + } + } + else { + logger.warn("onUpdateCheckComplete may not properly cancel", new Error("stack marker")); + } + return; } - else { - logger.warn("onUpdateCheckComplete may not properly cancel", new Error("stack marker")); - } + + logger.warn("Update manifest had an unrecognised namespace: " + xml.documentElement.namespaceURI); + this.notifyError(AddonUpdateChecker.ERROR_UNKNOWN_FORMAT); }, /** @@ -706,7 +526,7 @@ UpdateParser.prototype = { /** * Called when the manifest failed to load. */ - onError: function() { + onError: function UP_onError() { if (!Components.isSuccessCode(this.request.status)) { logger.warn("Request failed: " + this.url + " - " + this.request.status); } @@ -735,7 +555,7 @@ UpdateParser.prototype = { /** * Helper method to notify the observer that an error occured. */ - notifyError: function(aStatus) { + notifyError: function UP_notifyError(aStatus) { if ("onUpdateCheckError" in this.observer) { try { this.observer.onUpdateCheckError(aStatus); @@ -749,7 +569,7 @@ UpdateParser.prototype = { /** * Called to cancel an in-progress update check. */ - cancel: function() { + cancel: function UP_cancel() { if (!this.request) { logger.error("Trying to cancel already-complete request", this._doneAt); return; @@ -799,6 +619,12 @@ function matchesVersions(aUpdate, aAppVersion, aPlatformVersion, return (Services.vc.compare(aAppVersion, app.minVersion) >= 0) && (aIgnoreMaxVersion || (Services.vc.compare(aAppVersion, app.maxVersion) <= 0)); } +#ifdef MOZ_PHOENIX_EXTENSIONS + if (app.id == FIREFOX_ID) { + return (Services.vc.compare(aAppVersion, app.minVersion) >= 0) && + (aIgnoreMaxVersion || (Services.vc.compare(aAppVersion, app.maxVersion) <= 0)); + } +#endif if (app.id == TOOLKIT_ID) { result = (Services.vc.compare(aPlatformVersion, app.minVersion) >= 0) && (aIgnoreMaxVersion || (Services.vc.compare(aPlatformVersion, app.maxVersion) <= 0)); @@ -843,9 +669,12 @@ this.AddonUpdateChecker = { * Ignore strictCompatibility when testing if an update matches. Optional. * @return an update object if one matches or null if not */ - getCompatibilityUpdate: function(aUpdates, aVersion, aIgnoreCompatibility, - aAppVersion, aPlatformVersion, - aIgnoreMaxVersion, aIgnoreStrictCompat) { + getCompatibilityUpdate: function AUC_getCompatibilityUpdate(aUpdates, aVersion, + aIgnoreCompatibility, + aAppVersion, + aPlatformVersion, + aIgnoreMaxVersion, + aIgnoreStrictCompat) { if (!aAppVersion) aAppVersion = Services.appinfo.version; if (!aPlatformVersion) @@ -856,7 +685,12 @@ this.AddonUpdateChecker = { if (aIgnoreCompatibility) { for (let targetApp of update.targetApplications) { let id = targetApp.id; +#ifdef MOZ_PHOENIX_EXTENSIONS + if (id == Services.appinfo.ID || id == FIREFOX_ID || + id == TOOLKIT_ID) +#else if (id == Services.appinfo.ID || id == TOOLKIT_ID) +#endif return update; } } @@ -886,9 +720,12 @@ this.AddonUpdateChecker = { * Array of AddonCompatibilityOverride to take into account. Optional. * @return an update object if one matches or null if not */ - getNewestCompatibleUpdate: function(aUpdates, aAppVersion, aPlatformVersion, - aIgnoreMaxVersion, aIgnoreStrictCompat, - aCompatOverrides) { + getNewestCompatibleUpdate: function AUC_getNewestCompatibleUpdate(aUpdates, + aAppVersion, + aPlatformVersion, + aIgnoreMaxVersion, + aIgnoreStrictCompat, + aCompatOverrides) { if (!aAppVersion) aAppVersion = Services.appinfo.version; if (!aPlatformVersion) @@ -928,7 +765,9 @@ this.AddonUpdateChecker = { * @return UpdateParser so that the caller can use UpdateParser.cancel() to shut * down in-progress update requests */ - checkForUpdates: function(aId, aUpdateKey, aUrl, aObserver) { - return new UpdateParser(aId, aUpdateKey, aUrl, aObserver); + checkForUpdates: function AUC_checkForUpdates(aId, aUpdateKey, aUrl, aObserver) { + // Exclude default theme + if (aId != "{972ce4c6-7e08-4474-a285-3208198ce6fd}") + return new UpdateParser(aId, aUpdateKey, aUrl, aObserver); } }; diff --git a/toolkit/mozapps/extensions/internal/Content.js b/toolkit/mozapps/extensions/internal/Content.js index 9f366ba32..61a8b0323 100644 --- a/toolkit/mozapps/extensions/internal/Content.js +++ b/toolkit/mozapps/extensions/internal/Content.js @@ -2,13 +2,11 @@ * 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/. */ -/* globals addMessageListener*/ - "use strict"; (function() { -var {classes: Cc, interfaces: Ci, utils: Cu} = Components; +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; var {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); @@ -16,22 +14,17 @@ var nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile", "initWithPath"); const MSG_JAR_FLUSH = "AddonJarFlush"; -const MSG_MESSAGE_MANAGER_CACHES_FLUSH = "AddonMessageManagerCachesFlush"; try { if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) { - // Propagate JAR cache flush notifications across process boundaries. - addMessageListener(MSG_JAR_FLUSH, function(message) { + // Propagate JAR cache flush notifications across process boundaries. + addMessageListener(MSG_JAR_FLUSH, function jar_flushMessageListener(message) { let file = new nsIFile(message.data); Services.obs.notifyObservers(file, "flush-cache-entry", null); }); - // Propagate message manager caches flush notifications across processes. - addMessageListener(MSG_MESSAGE_MANAGER_CACHES_FLUSH, function() { - Services.obs.notifyObservers(null, "message-manager-flush-caches", null); - }); } -} catch (e) { +} catch(e) { Cu.reportError(e); } diff --git a/toolkit/mozapps/extensions/internal/E10SAddonsRollout.jsm b/toolkit/mozapps/extensions/internal/E10SAddonsRollout.jsm deleted file mode 100644 index 3bcee44d3..000000000 --- a/toolkit/mozapps/extensions/internal/E10SAddonsRollout.jsm +++ /dev/null @@ -1,982 +0,0 @@ -/* 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/. */ - -"use strict"; - -this.EXPORTED_SYMBOLS = [ "isAddonPartOfE10SRollout" ]; - -const Cu = Components.utils; -Cu.import("resource://gre/modules/Preferences.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); - -const PREF_E10S_ADDON_BLOCKLIST = "extensions.e10s.rollout.blocklist"; -const PREF_E10S_ADDON_POLICY = "extensions.e10s.rollout.policy"; - -const ADDONS = { - "Greasemonkey": { // Greasemonkey - id: "{e4a8a97b-f2ed-450b-b12d-ee082ba24781}", minVersion: "3.8", - }, - - "DYTV": { // Download YouTube Videos as MP4 - id: "{b9bfaf1c-a63f-47cd-8b9a-29526ced9060}", minVersion: "1.8.7", - }, - - "VDH": { // Video Download Helper - id: "{b9db16a4-6edc-47ec-a1f4-b86292ed211d}", minVersion: "5.6.1", - }, - - "Lightbeam": { // Lightbeam - id: "jid1-F9UJ2thwoAm5gQ@jetpack", minVersion: "1.3.0.1", - }, - - "ABP": { // Adblock Plus - id: "{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}", minVersion: "2.7.3", - }, - - "uBlockOrigin": { // uBlock Origin - id: "uBlock0@raymondhill.net", minVersion: "1.7.6", - }, - - "Emoji": { // Emoji Cheatsheet - id: "jid1-Xo5SuA6qc1DFpw@jetpack", minVersion: "1.1.1", - }, - - "ASP": { // Awesome Screenshot Plus - id: "jid0-GXjLLfbCoAx0LcltEdFrEkQdQPI@jetpack", minVersion: "3.0.10", - }, - - "PersonasPlus": { // PersonasPlus - id: "personas@christopher.beard", minVersion: "1.8.0", - }, - - "ACR": { // Add-on Compatibility Reporter - id: "compatibility@addons.mozilla.org", minVersion: "2.2.0", - }, - - // Add-ons used for testing - "test1": { - id: "bootstrap1@tests.mozilla.org", minVersion: "1.0", - }, - - "test2": { - id: "bootstrap2@tests.mozilla.org", minVersion: "1.0", - }, -}; - -// NOTE: Do not modify sets or policies after they have already been -// published to users. They must remain unchanged to provide valid data. - -// Set 2 used during 48 Beta cycle. Kept here for historical reasons. -const set2 = [ADDONS.Greasemonkey, - ADDONS.DYTV, - ADDONS.VDH, - ADDONS.Lightbeam, - ADDONS.ABP, - ADDONS.uBlockOrigin, - ADDONS.Emoji, - ADDONS.ASP, - ADDONS.PersonasPlus]; - -const set49Release = [ - ADDONS.Greasemonkey, - ADDONS.DYTV, - ADDONS.VDH, - ADDONS.Lightbeam, - ADDONS.ABP, - ADDONS.uBlockOrigin, - ADDONS.Emoji, - ADDONS.ASP, - ADDONS.PersonasPlus, - ADDONS.ACR -]; - -// These are only the add-ons in the Add-Ons Manager Discovery -// pane. This set is here in case we need to reduce add-ons -// exposure live on Release. -const set49PaneOnly = [ - ADDONS.ABP, - ADDONS.VDH, - ADDONS.Emoji, - ADDONS.ASP, - ADDONS.ACR -] - -// ================== ADDONS FOR 51 RELEASE ================== -// -// During the 51 beta cycle, we tested e10s with all addons -// except those explicitly marked as being incompatible. -// For release, instead of opening this up, we assembled -// the lists below with all addons that were seen on beta -// and had over 50 installs. -// -// This list is in a new format to allow fast access and also -// to allow controlling by the number of addons installed. - -const set51Release = { - "_65Members_@download.fromdoctopdf.com": {minVersion: "7.102.10.4221", installs: 32092}, - "light_plugin_ACF0E80077C511E59DED005056C00008@kaspersky.com": {minVersion: "4.6.3-15", installs: 27758}, - "_ceMembers_@free.easypdfcombine.com": {minVersion: "7.102.10.4117", installs: 17797}, - "caa1-aDOiCAxFFMOVIX@jetpack": {minVersion: "0.1.7", installs: 13150}, - "{4ED1F68A-5463-4931-9384-8FFF5ED91D92}": {minVersion: "5.0.248.0", installs: 12774}, - "_dbMembers_@free.getformsonline.com": {minVersion: "7.102.10.4251", installs: 11909}, - "_4zMembers_@www.videodownloadconverter.com": {minVersion: "7.102.10.5033", installs: 11612}, - "light_plugin_F6F079488B53499DB99380A7E11A93F6@kaspersky.com": {minVersion: "5.0.141-4-20161031140250", installs: 10944}, - "YoutubeDownloader@PeterOlayev.com": {minVersion: "2.4.1", installs: 10722}, - "{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}": {minVersion: "8.0.0.9103", installs: 8856}, - "client@anonymox.net": {minVersion: "2.5.2", installs: 8225}, - "_8hMembers_@download.allin1convert.com": {minVersion: "7.102.10.3584", installs: 7681}, - "light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com": {minVersion: "4.6.2-42-20160922074409", installs: 7177}, - "_dzMembers_@www.pconverter.com": {minVersion: "7.102.10.4851", installs: 7115}, - "fxdevtools-adapters@mozilla.org": {minVersion: "0.3.5", installs: 6926}, - "_9pMembers_@free.onlinemapfinder.com": {minVersion: "7.102.10.4836", installs: 6583}, - "@DownloadManager": {minVersion: "0.2.1", installs: 6412}, - "ar1er-ewrgfdgomusix@jetpack": {minVersion: "1.0.6", installs: 5975}, - "_agMembers_@free.premierdownloadmanager.com": {minVersion: "7.102.10.4846", installs: 5605}, - "_paMembers_@www.filmfanatic.com": {minVersion: "7.102.10.4163", installs: 5448}, - "_gtMembers_@free.gamingwonderland.com": {minVersion: "7.102.10.4263", installs: 5241}, - "LVD-SAE@iacsearchandmedia.com": {minVersion: "8.5", installs: 4694}, - "_fsMembers_@free.pdfconverterhq.com": {minVersion: "7.102.10.4849", installs: 4526}, - "_6xMembers_@www.readingfanatic.com": {minVersion: "7.102.10.4914", installs: 4417}, - "@mysmartprice-ff": {minVersion: "0.0.6", installs: 4381}, - "jid1-YcMV6ngYmQRA2w@jetpack": {minVersion: "1.37.9", installs: 3899}, - "{58d735b4-9d6c-4e37-b146-7b9f7e79e318}": {minVersion: "1.6", installs: 3733}, - "anttoolbar@ant.com": {minVersion: "2.4.7.47", installs: 3720}, - "adblockpopups@jessehakanen.net": {minVersion: "0.9.2.1-signed.1-signed", installs: 3602}, - "ERAIL.IN.FFPLUGIN@jetpack": {minVersion: "6.0.rev142", installs: 3545}, - "WebProtection@360safe.com": {minVersion: "5.0.0.1005", installs: 3475}, - "yasearch@yandex.ru": {minVersion: "8.20.4", installs: 3299}, - "{19503e42-ca3c-4c27-b1e2-9cdb2170ee34}": {minVersion: "1.5.6.14", installs: 3106}, - "{C1A2A613-35F1-4FCF-B27F-2840527B6556}": {minVersion: "2016.8.1.9", installs: 3083}, - "_b7Members_@free.mytransitguide.com": {minVersion: "7.102.10.4812", installs: 3011}, - "_9tMembers_@free.internetspeedtracker.com": {minVersion: "7.102.10.4339", installs: 2828}, - "_64Members_@www.televisionfanatic.com": {minVersion: "7.102.10.4968", installs: 2821}, - "info@youtube-mp3.org": {minVersion: "1.0.9.1-signed.1-signed", installs: 2717}, - "ffext_basicvideoext@startpage24": {minVersion: "1.97.37.1-signed.1-signed", installs: 2663}, - "MUB-SAE@iacsearchandmedia.com": {minVersion: "8.7", installs: 2650}, - "_4jMembers_@www.radiorage.com": {minVersion: "7.102.10.4916", installs: 2631}, - "@Email": {minVersion: "4.0.12", installs: 2583}, - "_gcMembers_@www.weatherblink.com": {minVersion: "7.38.8.56523", installs: 2519}, - "_dqMembers_@www.downspeedtest.com": {minVersion: "7.102.10.3827", installs: 2445}, - "translator@zoli.bod": {minVersion: "2.1.0.5.1.1-signed", installs: 2310}, - "{a38384b3-2d1d-4f36-bc22-0f7ae402bcd7}": {minVersion: "1.0.0.51", installs: 2190}, - "_1eMembers_@www.videoscavenger.com": {minVersion: "7.38.8.45273", installs: 2185}, - "tvplusnewtab-the-extension1@mozilla.com": {minVersion: "0.1.5", installs: 2155}, - "homepage@mail.ru": {minVersion: "1.0.2", installs: 2124}, - "search@mail.ru": {minVersion: "1.0.7", installs: 2038}, - "_69Members_@www.packagetracer.com": {minVersion: "7.102.10.4831", installs: 2036}, - "{7b8a500a-a464-4624-bd4f-73eaafe0f766}": {minVersion: "3", installs: 2027}, - "paulsaintuzb@gmail.com": {minVersion: "8.2.1", installs: 2005}, - "k7srff_enUS@k7computing.com": {minVersion: "2.4", installs: 1929}, - "_e5Members_@www.productivityboss.com": {minVersion: "7.38.8.46590", installs: 1892}, - "vdpure@link64": {minVersion: "1.97.43", installs: 1860}, - "_9tMembers_@download.internetspeedtracker.com": {minVersion: "7.38.8.56171", installs: 1824}, - "_g3Members_@free.easyphotoedit.com": {minVersion: "7.102.10.4108", installs: 1822}, - "_64Members_@download.televisionfanatic.com": {minVersion: "7.38.9.3004", installs: 1730}, - "_8iMembers_@download.audiotoaudio.com": {minVersion: "7.102.10.3585", installs: 1704}, - "adblockultimate@adblockultimate.net": {minVersion: "2.25", installs: 1648}, - "eagleget_ffext@eagleget.com": {minVersion: "3.8", installs: 1640}, - "_9eMembers_@free.findmefreebies.com": {minVersion: "7.102.10.4193", installs: 1638}, - "content_blocker_663BE8@kaspersky.com": {minVersion: "4.5.4.19.1", installs: 1625}, - "virtual_keyboard_074028@kaspersky.com": {minVersion: "4.5.4.19.1", installs: 1624}, - "browsec@browsec.com": {minVersion: "2.0.3", installs: 1610}, - "@Maps": {minVersion: "4.0.0", installs: 1587}, - "_exMembers_@free.easydocmerge.com": {minVersion: "7.102.10.4137", installs: 1493}, - "{635abd67-4fe9-1b23-4f01-e679fa7484c1}": {minVersion: "5.0.2", installs: 1490}, - "abb@amazon.com": {minVersion: "10.1612.1.304", installs: 1463}, - "{1BC9BA34-1EED-42ca-A505-6D2F1A935BBB}": {minVersion: "6.2.18.1", installs: 1436}, - "mp4downloader@jeff.net": {minVersion: "1.3.3.1-signed.1-signed", installs: 1410}, - "jid1-16aeif9OQIRKxA@jetpack": {minVersion: "1.1.4", installs: 1399}, - "{c45c406e-ab73-11d8-be73-000a95be3b12}": {minVersion: "1.2.11", installs: 1367}, - "online_banking_08806E@kaspersky.com": {minVersion: "4.5.4.19.1", installs: 1356}, - "_ewMembers_@free.mergedocsonline.com": {minVersion: "7.102.10.4710", installs: 1337}, - "@DiscreteSearch": {minVersion: "0.2.1", installs: 1306}, - "{6AC85730-7D0F-4de0-B3FA-21142DD85326}": {minVersion: "2.8.2", installs: 1286}, - "{063DA41A-2561-401B-91FA-AC75E460F4EB}": {minVersion: "1.0.7.1", installs: 1280}, - "netvideohunter@netvideohunter.com": {minVersion: "1.2", installs: 1260}, - "_8eMembers_@download.howtosimplified.com": {minVersion: "7.102.10.4285", installs: 1230}, - "FGZ-SAE@iacsearchandmedia.com": {minVersion: "8.5", installs: 1220}, - "adguardadblocker@adguard.com": {minVersion: "2.4.14", installs: 1172}, - "_39Members_@www.mapsgalaxy.com": {minVersion: "7.102.10.4730", installs: 1171}, - "_euMembers_@free.filesendsuite.com": {minVersion: "7.102.10.4154", installs: 1166}, - "_brMembers_@free.yourtemplatefinder.com": {minVersion: "7.102.10.5047", installs: 1159}, - "_8jMembers_@download.myimageconverter.com": {minVersion: "7.102.10.4778", installs: 1150}, - "_12Members_@free.myscrapnook.com": {minVersion: "7.102.10.4739", installs: 1113}, - "_7eMembers_@www.homeworksimplified.com": {minVersion: "7.102.10.4290", installs: 1109}, - "{fe272bd1-5f76-4ea4-8501-a05d35d823fc}": {minVersion: "2.1.9.1-signed.1-let-fixed.1-signed", installs: 1108}, - "_frMembers_@free.testforspeed.com": {minVersion: "7.102.10.4993", installs: 1107}, - "{068e178c-61a9-4a63-b74f-87404a6f5ea1}": {minVersion: "2", installs: 1104}, - "@Package": {minVersion: "0.2.0", installs: 1092}, - "6asa42dfa4784fsf368g@youtubeconverter.me": {minVersion: "0.1", installs: 1071}, - "_diMembers_@www.free.easymaillogin.com": {minVersion: "7.102.10.4112", installs: 1043}, - "_v4Members_@www.dictionaryboss.com": {minVersion: "7.102.10.3797", installs: 1035}, - "colorPicker@colorPicker": {minVersion: "3.0.1-signed.1-signed", installs: 1023}, - "hotspot-shield@anchorfree.com": {minVersion: "1.2.87", installs: 1000}, - "manishjain9@hotmail.com_easiestyoutube": {minVersion: "7.2.1-signed.1-let-fixed.1-signed", installs: 993}, - "{cd617375-6743-4ee8-bac4-fbf10f35729e}": {minVersion: "2.9.6", installs: 987}, - "@Converter": {minVersion: "4.1.0", installs: 986}, - "{dd3d7613-0246-469d-bc65-2a3cc1668adc}": {minVersion: "1.1.8.1-signed.1-signed", installs: 983}, - "ubufox@ubuntu.com": {minVersion: "3.2", installs: 950}, - "jid1-lpoiffmusixlib@jetpack": {minVersion: "0.1.9", installs: 945}, - "_5aMembers_@download.mywebface.com": {minVersion: "7.102.10.4837", installs: 930}, - "leethax@leethax.net": {minVersion: "2016.12.02", installs: 930}, - "{1A2D0EC4-75F5-4c91-89C4-3656F6E44B68}": {minVersion: "0.6.3.1-signed.1-signed", installs: 885}, - "{64161300-e22b-11db-8314-0800200c9a66}": {minVersion: "0.9.6.18", installs: 875}, - "_bfMembers_@free.snapmyscreen.com": {minVersion: "7.102.10.4951", installs: 827}, - "uriloader@pdf.js": {minVersion: "1.0.277.1-signed.1-signed", installs: 815}, - "{e968fc70-8f95-4ab9-9e79-304de2a71ee1}": {minVersion: "0.7.3.1-signed.1-signed", installs: 805}, - "save-as-pdf-ff@pdfcrowd.com": {minVersion: "1.5.1-signed.1-signed", installs: 804}, - "{75CEEE46-9B64-46f8-94BF-54012DE155F0}": {minVersion: "0.4.15", installs: 794}, - "safesearchplus2@avira.com": {minVersion: "1.4.1.371", installs: 786}, - "easyscreenshot@mozillaonline.com": {minVersion: "1.2.8", installs: 785}, - "_eeMembers_@download.freeradiocast.com": {minVersion: "7.38.8.46366", installs: 783}, - "_89Members_@download.safepcrepair.com": {minVersion: "7.39.8.51080", installs: 777}, - "{a3a5c777-f583-4fef-9380-ab4add1bc2a5}": {minVersion: "2.4.2.1-signed", installs: 771}, - "content_blocker@kaspersky.com": {minVersion: "4.0.10.15", installs: 770}, - "safesearch@avira.com": {minVersion: "1.4.1.371", installs: 767}, - "youtube2mp3@mondayx.de": {minVersion: "1.2.3.1-signed.1-signed", installs: 748}, - "2020Player_IKEA@2020Technologies.com": {minVersion: "5.0.94.1", installs: 736}, - "_edMembers_@free.myradioaccess.com": {minVersion: "7.102.10.4797", installs: 734}, - "_dmMembers_@free.gounzip.com": {minVersion: "7.102.10.4277", installs: 733}, - "Media-Newtab-the-extension1@mozilla.com": {minVersion: "0.1.6", installs: 732}, - "foxmarks@kei.com": {minVersion: "4.3.19", installs: 728}, - "{e8deb9e5-5688-4655-838a-b7a121a9f16e}": {minVersion: "48.4", installs: 726}, - "{195A3098-0BD5-4e90-AE22-BA1C540AFD1E}": {minVersion: "4.1.0.1-signed.1-signed", installs: 722}, - "jid1-4P0kohSJxU1qGg@jetpack": {minVersion: "1.22.550", installs: 719}, - "DailymotionVideoDownloader@PeterOlayev.com": {minVersion: "1.0.6.1-signed.1-signed", installs: 717}, - "jid1-P34HaABBBpOerQ@jetpack": {minVersion: "0.2.1-signed.1-signed", installs: 715}, - "SQLiteManager@mrinalkant.blogspot.com": {minVersion: "0.8.3.1-signed.1-signed", installs: 700}, - "2.0@disconnect.me": {minVersion: "3.15.3.1-signed.1-signed", installs: 693}, - "multifox@hultmann": {minVersion: "3.2.3", installs: 690}, - "_5mMembers_@download.myfuncards.com": {minVersion: "7.102.10.4783", installs: 679}, - "_btMembers_@free.catsandcatapults.com": {minVersion: "7.102.10.3677", installs: 673}, - "pavel.sherbakov@gmail.com": {minVersion: "19.1.1", installs: 666}, - "_fbMembers_@free.smarterpassword.com": {minVersion: "7.102.10.4936", installs: 644}, - "jid2-l8SPBzHJWBIiHQ@jetpack": {minVersion: "3.1", installs: 639}, - "{B17C1C5A-04B1-11DB-9804-B622A1EF5492}": {minVersion: "1.3.2", installs: 633}, - "myplaycitycom@gametab": {minVersion: "1.6", installs: 616}, - "{ad0d925d-88f8-47f1-85ea-8463569e756e}": {minVersion: "2.0.5", installs: 604}, - "{37964A3C-4EE8-47b1-8321-34DE2C39BA4D}": {minVersion: "2.5.4.174", installs: 603}, - "youtubemp3podcaster@jeremy.d.gregorio.com": {minVersion: "3.9.0", installs: 601}, - "caa1-aDOiCAxFFPRIVATE@jetpack": {minVersion: "0.2.0", installs: 598}, - "_f5Members_@free.typingfanatic.com": {minVersion: "7.102.10.5014", installs: 595}, - "_94Members_@www.motitags.com": {minVersion: "7.102.10.4744", installs: 594}, - "{888d99e7-e8b5-46a3-851e-1ec45da1e644}": {minVersion: "45.0.0", installs: 581}, - "_1cMembers_@www.bringmesports.com": {minVersion: "7.102.10.3646", installs: 580}, - "{a6fd85ed-e919-4a43-a5af-8da18bda539f}": {minVersion: "2.9.1.1-signed", installs: 572}, - "{0fc22c4c-93ed-48ea-ad12-dc8039cf3795}": {minVersion: "1.3", installs: 568}, - "homeutil@yandex.ru": {minVersion: "1.0.13", installs: 565}, - "_doMembers_@free.convertanyfile.com": {minVersion: "7.38.8.45860", installs: 563}, - "SocialNewPages-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 561}, - "wappalyzer@crunchlabz.com": {minVersion: "3.2.7", installs: 557}, - "_5qMembers_@www.zwinky.com": {minVersion: "7.38.8.45270", installs: 551}, - "{0545b830-f0aa-4d7e-8820-50a4629a56fe}": {minVersion: "31.0.9", installs: 531}, - "vk@sergeykolosov.mp": {minVersion: "0.3.9.5", installs: 522}, - "{77b819fa-95ad-4f2c-ac7c-486b356188a9}": {minVersion: "4.0.20130422.1-signed.1-signed", installs: 505}, - "@true-key": {minVersion: "1.23.0.2433", installs: 501}, - "_1pMembers_@www.referenceboss.com": {minVersion: "7.102.10.4932", installs: 499}, - "{C7AE725D-FA5C-4027-BB4C-787EF9F8248A}": {minVersion: "1.0.0.4", installs: 494}, - "alx-ffdeveloper@amazon.com": {minVersion: "3.0.2", installs: 493}, - "{3d7eb24f-2740-49df-8937-200b1cc08f8a}": {minVersion: "1.5.20", installs: 491}, - "_1gMembers_@www.inboxace.com": {minVersion: "7.38.8.56535", installs: 488}, - "{7DD78D43-0962-4d9b-BC76-ABF13B3B2ED1}": {minVersion: "3.5.0.1428", installs: 484}, - "imageblock@hemantvats.com": {minVersion: "3.1", installs: 472}, - "online_banking@kaspersky.com": {minVersion: "4.0.10.15", installs: 463}, - "virtual_keyboard@kaspersky.com": {minVersion: "4.0.10.15", installs: 463}, - "button@scholar.google.com": {minVersion: "1.1.1-signed.1-signed", installs: 463}, - "anti_banner@kaspersky.com": {minVersion: "4.0.10.15", installs: 462}, - "url_advisor@kaspersky.com": {minVersion: "4.0.10.15", installs: 461}, - "{6d96bb5e-1175-4ebf-8ab5-5f56f1c79f65}": {minVersion: "0.9.8", installs: 457}, - "_14Members_@download.totalrecipesearch.com": {minVersion: "7.102.10.4983", installs: 456}, - "{394DCBA4-1F92-4f8e-8EC9-8D2CB90CB69B}": {minVersion: "5.1.1", installs: 447}, - "_57Members_@free.marineaquariumfree.com": {minVersion: "7.102.10.4716", installs: 446}, - "e67f8350-7edf-11e3-baa7-0800200c9a66@fri-gate.org": {minVersion: "2.2.1.1-signed", installs: 446}, - "FireXPath@pierre.tholence.com": {minVersion: "0.9.7.1.1-signed.1-signed", installs: 442}, - "@youtube_downloader": {minVersion: "0.0.9", installs: 435}, - "ff_hpset@jetpack": {minVersion: "1.0.8", installs: 428}, - "{d0bfdcce-52c7-4b32-bb45-948f62db8d3f}": {minVersion: "49.1", installs: 406}, - "_j2Members_@www.soccerinferno.com": {minVersion: "7.102.10.4948", installs: 405}, - "autoform@olifozzy": {minVersion: "1.2.4.1-signed.1-signed", installs: 405}, - "FunSafeTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 405}, - "testpilot@labs.mozilla.com": {minVersion: "1.2.3.1-signed", installs: 405}, - "vwof@drev.com": {minVersion: "3.1.2", installs: 401}, - "_ftMembers_@free.mytelevisionhq.com": {minVersion: "7.102.10.4817", installs: 397}, - "{e001c731-5e37-4538-a5cb-8168736a2360}": {minVersion: "0.9.9.152", installs: 396}, - "{95E84BD3-3604-4AAC-B2CA-D9AC3E55B64B}": {minVersion: "2.0.0.78", installs: 393}, - "_8lMembers_@free.filesharefanatic.com": {minVersion: "7.102.10.4171", installs: 389}, - "clipconverter@clipconverter.cc": {minVersion: "1.5.2", installs: 387}, - "_7jMembers_@download.gardeningenthusiast.com": {minVersion: "7.102.10.4260", installs: 383}, - "antmark@ant.com": {minVersion: "1.1.14", installs: 383}, - "_flMembers_@free.myformsfinder.com": {minVersion: "7.102.10.4784", installs: 381}, - "{c36177c0-224a-11da-8cd6-0800200c9a91}": {minVersion: "3.9.85.1-signed.1-signed", installs: 375}, - "@searchincognito": {minVersion: "0.1.0", installs: 375}, - "{f13b157f-b174-47e7-a34d-4815ddfdfeb8}": {minVersion: "0.9.89.1-signed.1-signed", installs: 373}, - "_5eMembers_@www.translationbuddy.com": {minVersion: "7.38.8.45962", installs: 372}, - "{9c51bd27-6ed8-4000-a2bf-36cb95c0c947}": {minVersion: "11.0.1.1-signed.1-signed", installs: 370}, - "clickclean@hotcleaner.com": {minVersion: "4.1.1-signed.1-signed", installs: 366}, - "jid1-xKH0EoS44u1a2w@jetpack": {minVersion: "0.1.1-signed.1-signed", installs: 366}, - "{c2056674-a37f-4b29-9300-2004759d74fe}": {minVersion: "2.0.0.1090", installs: 361}, - "newtab-tv-the-extension1@mozilla.com": {minVersion: "0.1.5", installs: 359}, - "ascsurfingprotectionnew@iobit.com": {minVersion: "2.1.3", installs: 355}, - "FunTabSafe-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 353}, - "d.lehr@chello.at": {minVersion: "1.2", installs: 350}, - "anticontainer@downthemall.net": {minVersion: "1.5", installs: 348}, - "{F8A55C97-3DB6-4961-A81D-0DE0080E53CB}": {minVersion: "1.0.10", installs: 347}, - "@FormsApp": {minVersion: "0.2.0", installs: 346}, - "multilinksplus@hugsmile.eu": {minVersion: "3.9.3", installs: 343}, - "jid1-KWFaW5zc0EbtBQ@jetpack": {minVersion: "0.2.0", installs: 335}, - "{e8f509f0-b677-11de-8a39-0800200c9a66}": {minVersion: "1.12.1-signed.1-let-fixed.1-signed", installs: 334}, - "{37E4D8EA-8BDA-4831-8EA1-89053939A250}": {minVersion: "3.0.0.2.1-signed.1-signed", installs: 333}, - "{c8d3bc80-0810-4d21-a2c2-be5f2b2832ac}": {minVersion: "0.98", installs: 332}, - "{cb40da56-497a-4add-955d-3377cae4c33b}": {minVersion: "10.2.0.271", installs: 331}, - "{5546F97E-11A5-46b0-9082-32AD74AAA920}": {minVersion: "0.76.1-signed.1-signed", installs: 325}, - "_14Members_@www.totalrecipesearch.com": {minVersion: "7.38.8.45925", installs: 324}, - "info@mp3it.eu": {minVersion: "1.4.1.1-signed.1-signed", installs: 324}, - "firefox-autofill@googlegroups.com": {minVersion: "3.6.1-signed.1-signed", installs: 317}, - "jid1-TQvJxTBYHA8qXg@jetpack": {minVersion: "0.4.1-signed.1-signed", installs: 315}, - "{8f8fe09b-0bd3-4470-bc1b-8cad42b8203a}": {minVersion: "0.17.1-signed.1-signed", installs: 311}, - "{D4DD63FA-01E4-46a7-B6B1-EDAB7D6AD389}": {minVersion: "0.9.10.1-signed.1-signed", installs: 311}, - "{d7f46ca0-899d-11da-a72b-0800200c9a65}": {minVersion: "0.1.2.1-signed.1-signed", installs: 311}, - "twoo@twoo.com": {minVersion: "1.6.0.1-signed", installs: 303}, - "_29Members_@www.headlinealley.com": {minVersion: "7.38.8.56537", installs: 302}, - "_e2Members_@free.coolpopulargames.com": {minVersion: "7.38.8.45873", installs: 300}, - "TopTVTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 300}, - "tmbepff@trendmicro.com": {minVersion: "9.2.0.1026", installs: 293}, - "_2vMembers_@www.dailybibleguide.com": {minVersion: "7.38.8.52880", installs: 289}, - "{54e46280-0211-11e3-b778-0800200c9a66}": {minVersion: "0.3", installs: 285}, - "_49Members_@www.utilitychest.com": {minVersion: "7.38.8.45977", installs: 284}, - "amcontextmenu@loucypher": {minVersion: "0.4.2.1-signed.1-signed", installs: 284}, - "jid1-r1tDuNiNb4SEww@jetpack": {minVersion: "1.1.2673", installs: 283}, - "_erMembers_@free.getvideoconvert.com": {minVersion: "7.102.10.5038", installs: 281}, - "{b1df372d-8b32-4c7d-b6b4-9c5b78cf6fb1}": {minVersion: "0.87.1-signed.1-signed", installs: 281}, - "jid1-cHKBMlArKdIVEg@jetpack": {minVersion: "1.24.1-signed.1-signed", installs: 281}, - "@90B817C8-8A5C-413B-9DDD-B2C61ED6E79A": {minVersion: "1.09", installs: 278}, - "smarterwiki@wikiatic.com": {minVersion: "5.2.1.1-signed.1-signed", installs: 278}, - "whatsapppanel@alejandrobrizuela.com.ar": {minVersion: "1.1.1.1-signed.1-signed", installs: 277}, - "lazarus@interclue.com": {minVersion: "2.3.1-signed.1-signed", installs: 275}, - "{DEDA1132-B316-11DD-8BC1-4E5D56D89593}": {minVersion: "0.18", installs: 274}, - "_h2Members_@free.calendarspark.com": {minVersion: "7.102.10.3641", installs: 273}, - "@youtubedownloadere": {minVersion: "0.0.1", installs: 273}, - "multirevenue@googlemail.com": {minVersion: "6.1.1", installs: 272}, - "_d9Members_@www.everydaylookup.com": {minVersion: "7.102.10.4140", installs: 271}, - "belgiumeid@eid.belgium.be": {minVersion: "1.0.21", installs: 271}, - "{62DD0A97-FDD4-421b-94A5-D1A9434450C7}": {minVersion: "3.1", installs: 270}, - "the-addon-bar@GeekInTraining-GiT": {minVersion: "3.2.9-compat-fixed-4", installs: 264}, - "@phextension": {minVersion: "6.0.2", installs: 262}, - "FunMediaTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 262}, - "{7f57cf46-4467-4c2d-adfa-0cba7c507e54}": {minVersion: "4.0.1", installs: 259}, - "safefacebook@bkav": {minVersion: "1.0.4", installs: 255}, - "content_blocker_6418E0D362104DADA084DC312DFA8ABC@kaspersky.com": {minVersion: "4.5.3.8", installs: 254}, - "virtual_keyboard_294FF26A1D5B455495946778FDE7CEDB@kaspersky.com": {minVersion: "4.5.3.8", installs: 254}, - "{B821BF60-5C2D-41EB-92DC-3E4CCD3A22E4}": {minVersion: "4.3.1.10", installs: 252}, - "@E9438230-A7DF-4D1F-8F2D-CA1D0F0F7924": {minVersion: "1.08.8.66", installs: 252}, - "jid1-6MGm94JnyY2VkA@jetpack": {minVersion: "2.1.8", installs: 250}, - "{20a82645-c095-46ed-80e3-08825760534b}": {minVersion: "1.3.1.1-signed", installs: 246}, - "{a192bf54-089f-4325-ac25-7eafcd17a342}": {minVersion: "3.2", installs: 246}, - "e389d8c2-5554-4ba2-a36e-ac7a57093130@gmail.com": {minVersion: "1.44.275", installs: 244}, - "yslow@yahoo-inc.com": {minVersion: "3.1.8.1-signed.1-signed", installs: 244}, - "avg@safeguard": {minVersion: "19.6.0.592", installs: 243}, - "@windscribeff": {minVersion: "0.1.43", installs: 242}, - "jid1-PBNne26X1Kn6hQ@jetpack": {minVersion: "3.3.3", installs: 240}, - "{53A03D43-5363-4669-8190-99061B2DEBA5}": {minVersion: "1.5.14", installs: 239}, - "@offersolymp": {minVersion: "0.0.2", installs: 238}, - "firefox@dotvpn.com": {minVersion: "1.0.2", installs: 238}, - "{62760FD6-B943-48C9-AB09-F99C6FE96088}": {minVersion: "4.2.9", installs: 236}, - "jid1-sNL73VCI4UB0Fw@jetpack": {minVersion: "2.1.4", installs: 236}, - "low_quality_flash@pie2k.com": {minVersion: "0.2.1-signed.1-signed", installs: 236}, - "jid1-l6VQSR2FeKnliQ@jetpack": {minVersion: "2.0.1-signed", installs: 235}, - "_5zMembers_@www.couponxplorer.com": {minVersion: "7.102.10.3738", installs: 234}, - "adonis.cuhk@gmail.com": {minVersion: "1.8.9.1-signed.1-signed", installs: 234}, - "_e1Members_@free.actionclassicgames.com": {minVersion: "7.38.8.45834", installs: 232}, - "{ea4637dc-e014-4c17-9c2c-879322d23268}": {minVersion: "2.1.1-signed.1-signed", installs: 229}, - "{4DC70064-89E2-4a55-8FC6-E8CDEAE3618C}": {minVersion: "0.7.7.1-signed.1-signed", installs: 228}, - "odyssey_crypto_control@odysseytec.com": {minVersion: "3.5", installs: 228}, - "seostatus@rubyweb": {minVersion: "1.5.9.1-signed.1-signed", installs: 228}, - "_apMembers_@free.puzzlegamesdaily.com": {minVersion: "7.102.10.4865", installs: 227}, - "@safesearchincognito": {minVersion: "0.1.8", installs: 226}, - "jid1-HfCj61J5q2gaGQ@jetpack": {minVersion: "1.0.3", installs: 224}, - "@stopads": {minVersion: "0.0.4", installs: 224}, - "dta3noaero@vano": {minVersion: "1.0.1", installs: 224}, - "rainbow@colors.org": {minVersion: "1.6.1-signed.1-signed", installs: 223}, - "{146f1820-2b0d-49ef-acbf-d85a6986e10c}": {minVersion: "0.1.9.3.1-signed.1-signed", installs: 222}, - "{b2bfe60c-eef8-4e20-8334-c53afdc1ffdd}": {minVersion: "3.2", installs: 222}, - "{b7870b41-bfb3-44cd-8cc2-e392e51b0874}": {minVersion: "3.8", installs: 222}, - "printPages2Pdf@reinhold.ripper": {minVersion: "0.1.9.3.1-signed", installs: 221}, - "YouTubetoALL@ALLPlayer.org": {minVersion: "0.8.5.1-signed.1-signed", installs: 221}, - "{7a526449-3a92-426f-8ca4-47439918f2b1}": {minVersion: "3.2", installs: 219}, - "jdwimqhayu@yahoo.com": {minVersion: "0.0.0.6", installs: 219}, - "{54FBE89E-C878-46bb-A064-AB327EE26EBC}": {minVersion: "3.8", installs: 214}, - "modernDownloadManager@teo.pl": {minVersion: "0.2.2", installs: 214}, - "{eb8fff7e-1dce-4f3f-a51d-d9513ed6bab4}": {minVersion: "3.8", installs: 211}, - "jid0-YQz0l1jthOIz179ehuitYAOdBEs@jetpack": {minVersion: "2.0.2", installs: 211}, - "{7e80e173-7e63-464e-8252-fe170b15c15a}": {minVersion: "2.3", installs: 210}, - "{35d6291e-1d4b-f9b4-c52f-77e6410d1326}": {minVersion: "4.11.1.0", installs: 209}, - "{3c59c791-aeec-44bb-af60-ff112eea18e3}": {minVersion: "3.2", installs: 209}, - "{90477448-b59c-48cd-98af-6a298cbc15d2}": {minVersion: "3.8", installs: 209}, - "{24d26487-6274-48b1-b500-22f24884f971}": {minVersion: "2.3", installs: 208}, - "{b7389dbc-6646-412f-bbd5-53168ee68a98}": {minVersion: "49", installs: 208}, - "{22181a4d-af90-4ca3-a569-faed9118d6bc}": {minVersion: "11.0.0.1181", installs: 207}, - "printpdf@pavlov.net": {minVersion: "0.76.1-signed.1-signed", installs: 207}, - "@com.virtualjame.disableads": {minVersion: "0.1.0", installs: 206}, - "{9AA46F4F-4DC7-4c06-97AF-6665170634FE}": {minVersion: "1.11.6.1-signed.1-signed", installs: 205}, - "tinyjsdebugger@enigmail.net": {minVersion: "1.1.5", installs: 204}, - "_foMembers_@free.flightsearchapp.com": {minVersion: "7.102.10.4176", installs: 202}, - "jid1-rs90nxQtPi3Asg@jetpack": {minVersion: "1.8.1-signed.1-signed", installs: 201}, - "vlcplaylist@helgatauscher.de": {minVersion: "0.8.1-signed.1-signed", installs: 201}, - "jid1-G80Ec8LLEbK5fQ@jetpack": {minVersion: "1.3.8", installs: 200}, - "_gpMembers_@free.mymapswizard.com": {minVersion: "7.102.10.4775", installs: 199}, - "BestMediaTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 199}, - "info@convert2mp3.net": {minVersion: "2.5.1-signed.1-signed", installs: 199}, - "partnerdefaults@mozilla.com": {minVersion: "1.0.1", installs: 199}, - "qwantcomforfirefox@jetpack": {minVersion: "3.0.28", installs: 199}, - "{65e41d20-f092-41b7-bb83-c6e8a9ab0f57}": {minVersion: "1.2.6", installs: 198}, - "amznUWL2@amazon.com": {minVersion: "1.11", installs: 197}, - "{1b80ae74-4912-44fc-9f27-30f9252a5ad7}": {minVersion: "2.3", installs: 197}, - "{c9b4cd26-6f0e-4972-a9e0-8b77e811aa8f}": {minVersion: "2.3", installs: 197}, - "shopcbtoolbar2@befrugal.com": {minVersion: "2013.3.23.1", installs: 197}, - "trafficlight@bitdefender.com": {minVersion: "0.2.23.1-signed.1-signed", installs: 197}, - "webrank-toolbar@probcomp.com": {minVersion: "4.4.1.1-signed.1-signed", installs: 197}, - "_4lMembers_@www.bibletriviatime.com": {minVersion: "7.102.10.4330", installs: 196}, - "xthunder@lshai.com": {minVersion: "1.3.4.1-signed.1-signed", installs: 196}, - "extension@hidemyass.com": {minVersion: "1.3.2", installs: 195}, - "jid1-MIAJd5BiK7V4Pw@jetpack": {minVersion: "0.9.1-signed.1-signed", installs: 195}, - "{51aa69f8-8825-4def-916a-a766c5e3c0fd}": {minVersion: "3.8", installs: 194}, - "{2bc72c53-9bde-4db2-8479-eda9a5e71f4e}": {minVersion: "3.2", installs: 193}, - "{a95d8332-e4b4-6e7f-98ac-20b733364387}": {minVersion: "1.0.5", installs: 191}, - "ocr@babylon.com": {minVersion: "1.1", installs: 191}, - "{d3b9472c-f8b1-4a10-935b-1087bac8417f}": {minVersion: "3.8", installs: 189}, - "windowpromo@dm73.net": {minVersion: "1.6", installs: 188}, - "alldownloader@link64": {minVersion: "1.00.17.1-signed.1-signed", installs: 187}, - "{3e0e7d2a-070f-4a47-b019-91fe5385ba79}": {minVersion: "3.6.5.2", installs: 185}, - "jid1-vFmnfCkyf5VeSA@jetpack": {minVersion: "0.4.0", installs: 185}, - "@greatdealz": {minVersion: "0.0.3", installs: 184}, - "superstart@enjoyfreeware.org": {minVersion: "7.4.0.1-signed", installs: 183}, - "{c2fc3c2b-a65a-453c-bf95-101fde56ed1d}": {minVersion: "2.3", installs: 182}, - "{53152e75-fd90-472f-9d30-5cba3679eab9}": {minVersion: "48.3", installs: 180}, - "jid0-raWjElI57dRa4jx9CCiYm5qZUQU@jetpack": {minVersion: "3.0.12.1.1-signed.1-signed", installs: 180}, - "_ivMembers_@free.simplepictureedit.com": {minVersion: "7.102.10.14166", installs: 179}, - "jid1-wKRSK9TpFpr9Hw@jetpack": {minVersion: "0.92", installs: 179}, - "emailExtractor@penzil.com": {minVersion: "1.3.1-signed.1-signed", installs: 178}, - "{60B7679C-BED9-11E5-998D-8526BB8E7F8B}": {minVersion: "6.3", installs: 177}, - "@pdfit": {minVersion: "0.1.9", installs: 177}, - "jid1-6AyZ1PQXsR9LgQ@jetpack": {minVersion: "0.2.1", installs: 177}, - "_6oMembers_@free.heroicplay.com": {minVersion: "7.38.8.46626", installs: 175}, - "{4BBDD651-70CF-4821-84F8-2B918CF89CA3}": {minVersion: "8.9.3.1", installs: 173}, - "jid1-GeRCnsiDhZiTvA@jetpack": {minVersion: "1.0.3", installs: 172}, - "jid0-zs24wecdcQo0Lp18D7QOV4WSZFo@jetpack": {minVersion: "0.2.1-signed.1-signed", installs: 171}, - "{c50ca3c4-5656-43c2-a061-13e717f73fc8}": {minVersion: "5.0.1.48.1-signed.1-signed", installs: 170}, - "selenium_ide_buttons@egarracingteam.com.ar": {minVersion: "1.2.0.1-signed.1-signed", installs: 170}, - "WSVCU@Wondershare.com": {minVersion: "7.1.0", installs: 169}, - "{4cc4a13b-94a6-7568-370d-5f9de54a9c7f}": {minVersion: "2.7.1-signed.1-signed", installs: 168}, - "{aa84ce40-4253-a00a-8cd6-0800200f9a67}": {minVersion: "3.12.0", installs: 168}, - "FasterFox_Lite@BigRedBrent": {minVersion: "3.9.9Lite.1-signed.1-signed", installs: 167}, - "{6cc0f0f7-a6e2-4834-9682-24de2229b51e}": {minVersion: "23.6", installs: 166}, - "{b749fc7c-e949-447f-926c-3f4eed6accfe}": {minVersion: "0.7.1.1.1-signed.1-signed", installs: 166}, - "@mendeleyimporter": {minVersion: "1.6.8", installs: 166}, - "ALone-live@ya.ru": {minVersion: "1.4.11", installs: 166}, - "{4093c4de-454a-4329-8aff-c6b0b123c386}": {minVersion: "0.8.14.1-signed.1-signed", installs: 165}, - "cookiemgr@jayapal.com": {minVersion: "5.12", installs: 164}, - "touchenex@raon.co.kr": {minVersion: "1.0.1.11", installs: 163}, - "{b0e1b4a6-2c6f-4e99-94f2-8e625d7ae255}": {minVersion: "3.5.0.1-signed.1-signed", installs: 162}, - "isreaditlater@ideashower.com": {minVersion: "3.0.6.1-signed", installs: 161}, - "safesearchplus@avira.com": {minVersion: "1.4.1.371", installs: 161}, - "_e0Members_@www.downshotfree.com": {minVersion: "7.102.10.3833", installs: 159}, - "LDSI_plashcor@gmail.com": {minVersion: "1.1.0.3", installs: 159}, - "jid1-9ETkKdBARv7Iww@jetpack": {minVersion: "0.20.1-signed.1-signed", installs: 157}, - "jid1-CGxMej0nDJTjwQ@jetpack": {minVersion: "1.0.1-signed.1-signed", installs: 157}, - "{00f7ab9f-62f4-4145-b2f9-38d579d639f6}": {minVersion: "49", installs: 156}, - "googledictionary@toptip.ca": {minVersion: "7.5", installs: 156}, - "shopearn@prodege.com": {minVersion: "219", installs: 156}, - "fvdmedia@gmail.com": {minVersion: "11.0.1", installs: 155}, - "magicplayer_unlisted@acestream.org": {minVersion: "1.1.42", installs: 155}, - "{0538E3E3-7E9B-4d49-8831-A227C80A7AD3}": {minVersion: "2.2.2.1-signed.1-let-fixed.1-signed", installs: 154}, - "{73007fef-a6e0-47d3-b4e7-dfc116ed6f65}": {minVersion: "1.15.1-signed.1-signed", installs: 153}, - "{cd617372-6743-4ee4-bac4-fbf60f35719e}": {minVersion: "2.0.1-signed.1-signed", installs: 152}, - "TopSecurityTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 152}, - "jid1-hDf2iQXGiUjzGQ@jetpack": {minVersion: "2.5.0", installs: 151}, - "_dnMembers_@www.free.webmailworld.com": {minVersion: "7.102.10.5052", installs: 149}, - "jid1-rrMTK7JqsxNOeQ@jetpack": {minVersion: "2.1.0", installs: 149}, - "jid1-XgC5trUcILmXBw@jetpack": {minVersion: "2.0.3", installs: 149}, - "online_banking_69A4E213815F42BD863D889007201D82@kaspersky.com": {minVersion: "4.5.3.8", installs: 148}, - "jid1-AXn9cXcB4fD1QQ@jetpack": {minVersion: "0.7.4", installs: 148}, - "feedly@devhd": {minVersion: "16.0.528.1-signed.1-signed", installs: 147}, - "{6E727987-C8EA-44DA-8749-310C0FBE3C3E}": {minVersion: "2.0.0.11", installs: 146}, - "{1082eb84-f0f2-11e5-8e18-9bb85ab7992e}": {minVersion: "1.07", installs: 146}, - "{c151d79e-e61b-4a90-a887-5a46d38fba99}": {minVersion: "2.8.8", installs: 146}, - "public.proartex@gmail.com": {minVersion: "1.1.3", installs: 145}, - "jid1-8J7ayxTha4KqKQ@jetpack": {minVersion: "1.1.1-signed.1-signed", installs: 144}, - "stealthyextension@gmail.com": {minVersion: "3.0.1.1-signed", installs: 144}, - "_beMembers_@free.dailylocalguide.com": {minVersion: "7.38.9.7920", installs: 143}, - "mytube@ashishmishra.in": {minVersion: "0.979.1-signed.1-signed", installs: 142}, - "@A3592ADB-854A-443A-854E-EB92130D470D": {minVersion: "1.08.8.88", installs: 139}, - "FunkyTVTabs-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 139}, - "jid1-QpHD8URtZWJC2A@jetpack": {minVersion: "4.3.0", installs: 138}, - "savedeo-video-downloader@fczbkk.com": {minVersion: "0.4.1.1-signed.1-signed", installs: 137}, - "toolbar@shopathome.com": {minVersion: "8.20.3.1", installs: 137}, - "_dyMembers_@www.dezipper.com": {minVersion: "7.102.10.3775", installs: 135}, - "jid0-zXo3XFGyiDalgkeEO4UYJTUwo2I@jetpack": {minVersion: "1.0.0", installs: 134}, - "{d57c9ff1-6389-48fc-b770-f78bd89b6e8a}": {minVersion: "1.46.1-signed.1-signed", installs: 133}, - "@searchlock-fx": {minVersion: "1.1.6", installs: 133}, - "dm@jetpack": {minVersion: "0.0.2", installs: 133}, - "proxyselector@mozilla.org": {minVersion: "1.31.1-signed.1-signed", installs: 133}, - "{065829BC-17B5-4C0B-9429-3173C361092E}": {minVersion: "1.0.8", installs: 132}, - "{ada4b710-8346-4b82-8199-5de2b400a6ae}": {minVersion: "2.1.5.5.3", installs: 132}, - "readable@evernote.com": {minVersion: "10.2.1.7.1-signed", installs: 131}, - "{d48a39ba-8f80-4fce-8ee1-bc710561c55d}": {minVersion: "3.1.0.1-signed.1-signed", installs: 131}, - "autorefresh@plugin": {minVersion: "1.0.2.1-signed.1-signed", installs: 130}, - "SafeBrowseSearch-the-extension1@mozilla.com": {minVersion: "0.1.2", installs: 130}, - "browsermodulecorp@browcorporation.org": {minVersion: "2.3", installs: 129}, - "wisestamp@wisestamp.com": {minVersion: "4.14.20", installs: 127}, - "_63Members_@www.aplusgamer.com": {minVersion: "7.38.8.45832", installs: 126}, - "bestproxyswitcher@bestproxyswitcher.com": {minVersion: "3.4.6.1-signed.1-signed", installs: 126}, - "jid1-AVgCeF1zoVzMjA@jetpack": {minVersion: "0.9.5.6", installs: 126}, - "{ce7e73df-6a44-4028-8079-5927a588c948}": {minVersion: "1.1.4", installs: 125}, - "{E71B541F-5E72-5555-A47C-E47863195841}": {minVersion: "3.0.3", installs: 125}, - "{F5DDF39C-9293-4d5e-9AA8-E04E6DD5E9B4}": {minVersion: "1.6.3.1-signed.1-signed", installs: 125}, - "@simplepopupblocker": {minVersion: "1.2.1", installs: 125}, - "commonfix@mozillaonline.com": {minVersion: "0.13", installs: 125}, - "searchme@mybrowserbar.com": {minVersion: "2.8", installs: 125}, - "_4wMembers_@www.retrogamer.com": {minVersion: "7.38.8.46604", installs: 124}, - "{71328583-3CA7-4809-B4BA-570A85818FBB}": {minVersion: "0.8.6.3.1-let-fixed", installs: 123}, - "dmremote@westbyte.com": {minVersion: "1.9.3", installs: 123}, - "@google-translate-menu": {minVersion: "1.0.1", installs: 122}, - "_aaMembers_@free.eliteunzip.com": {minVersion: "7.39.8.50909", installs: 121}, - "{8620c15f-30dc-4dba-a131-7c5d20cf4a29}": {minVersion: "3.9", installs: 121}, - "{eb4b28c8-7f2d-4327-a00c-40de4299ba44}": {minVersion: "1.7", installs: 121}, - "flashlight@stephennolan.com.au": {minVersion: "1.2.1-signed.1-signed", installs: 121}, - "useragentoverrider@qixinglu.com": {minVersion: "0.4.1", installs: 121}, - "{1B33E42F-EF14-4cd3-B6DC-174571C4349C}": {minVersion: "4.7", installs: 120}, - "_dxMembers_@www.download-freemaps.com": {minVersion: "7.38.8.46371", installs: 120}, - "{95ab36d4-fb6f-47b0-8b8d-e5f3bd547953}": {minVersion: "4.20.13.1-signed.1-signed", installs: 120}, - "FirefoxAddon@similarWeb.com": {minVersion: "4.0.6", installs: 120}, - "flashstopper@byo.co.il": {minVersion: "1.4.2", installs: 120}, - "{15e67a59-bd3d-49ae-90dd-b3d3fd14c2ed}": {minVersion: "1.0.3.1-signed.1-signed", installs: 119}, - "{c37bac34-849a-4d28-be41-549b2c76c64e}": {minVersion: "2.6", installs: 119}, - "{03B08592-E5B4-45ff-A0BE-C1D975458688}": {minVersion: "1.1.1-signed.1-signed", installs: 118}, - "newtabgoogle@graememcc.co.uk": {minVersion: "1.0.2.1-signed.1-signed", installs: 118}, - "SocialNewtabs-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 118}, - "@kikikokicicidada": {minVersion: "2.1.2", installs: 117}, - "{9D6218B8-03C7-4b91-AA43-680B305DD35C}": {minVersion: "4.0.5", installs: 116}, - "extension@one-tab.com": {minVersion: "1.17.0", installs: 116}, - "{22119944-ED35-4ab1-910B-E619EA06A115}": {minVersion: "7.9.21.5", installs: 115}, - "admin@hide-my-ip.org": {minVersion: "9.6.3", installs: 115}, - "bdwteffv19@bitdefender.com": {minVersion: "2.2.1", installs: 115}, - "exif_viewer@mozilla.doslash.org": {minVersion: "2.00.1-signed.1-signed", installs: 115}, - "MyStartab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 115}, - "coralietab@mozdev.org": {minVersion: "2.04.20110724.1-signed.1-signed", installs: 113}, - "gaurangnshah@gmail.com": {minVersion: "1.3.2.1-signed.1-signed", installs: 113}, - "ImagePicker@topolog.org": {minVersion: "1.9.4", installs: 113}, - "{d49a148e-817e-4025-bee3-5d541376de3b}": {minVersion: "3.1.1-signed.1-signed", installs: 112}, - "firebug@tools.sitepoint.com": {minVersion: "1.6.1-signed.1-signed", installs: 111}, - "add-to-searchbox@maltekraus.de": {minVersion: "2.9", installs: 110}, - "captiondownloader@hiephm.com": {minVersion: "2.3.1-signed.1-signed", installs: 110}, - "jid1-LYopfl0r00ZV5k@jetpack": {minVersion: "1.0.1-signed.1-signed", installs: 110}, - "{7CA9CF31-1C73-46CD-8377-85AB71EA771F}": {minVersion: "5.0.12", installs: 109}, - "jid1-HdwPLukcGQeOSh@jetpack": {minVersion: "1.2.3", installs: 108}, - "{0AA9101C-D3C1-4129-A9B7-D778C6A17F82}": {minVersion: "2.09.1-signed", installs: 107}, - "CookiesIE@yahoo.com": {minVersion: "1.0.1-signed.1-signed", installs: 107}, - "selenium-expert_selenium-ide@Samit.Badle": {minVersion: "0.25.1-signed.1-signed", installs: 107}, - "{19EB90DC-A456-458b-8AAC-616D91AAFCE1}": {minVersion: "1.0.1-signed", installs: 105}, - "application@itineraire.info": {minVersion: "4.5.0", installs: 105}, - "rest-easy@quickmediasolutions.com": {minVersion: "0.3.1.1-signed", installs: 105}, - "TopSocialHub-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 105}, - "{7affbfae-c4e2-4915-8c0f-00fa3ec610a1}": {minVersion: "6.36.32", installs: 104}, - "azhang@cloudacl.com": {minVersion: "0.19.6.9.1-signed.1-signed", installs: 104}, - "FunCyberTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 104}, - "SkipScreen@SkipScreen": {minVersion: "0.7.2.1-signed.1-signed", installs: 104}, - "toolbar@seomoz.org": {minVersion: "3.1.18", installs: 104}, - "{8b86149f-01fb-4842-9dd8-4d7eb02fd055}": {minVersion: "0.26.1-signed.1-signed", installs: 103}, - "fbp@fbpurity.com": {minVersion: "9.3.2.1-signed", installs: 103}, - "jid1-V8ev2melBDV3qQ@jetpack": {minVersion: "1.0.12.1-signed.1-signed", installs: 103}, - "_fvMembers_@free.directionsace.com": {minVersion: "7.102.10.3790", installs: 102}, - "{b6b1a201-b252-484f-b9fe-68efbb273fbd}": {minVersion: "1.10.1-signed.1-signed", installs: 102}, - "flashfirebug@o-minds.com": {minVersion: "4.9.1", installs: 102}, - "_ebMembers_@download.metrohotspot.com": {minVersion: "7.102.10.4735", installs: 101}, - "{2e17e2b2-b8d4-4a67-8d7b-fafa6cc9d1d0}": {minVersion: "1.2.7.0.1-signed.1-signed", installs: 101}, - "{ea61041c-1e22-4400-99a0-aea461e69d04}": {minVersion: "0.2.4.1-signed.1-signed", installs: 101}, - "rapportive@rapportive.com": {minVersion: "1.4.0.1.1-signed.1-signed", installs: 101}, - "_dvMembers_@www.testinetspeed.com": {minVersion: "7.38.8.45918", installs: 100}, - "{9aad3da6-6c46-4ef0-9109-6df5eaaf597c}": {minVersion: "1.4.1.1-signed.1-signed", installs: 100}, - "{c2b1f3ae-5cd5-49b7-8a0c-2c3bcbbbb294}": {minVersion: "1.1.1-signed.1-signed", installs: 100}, - "jid0-w1UVmoLd6VGudaIERuRJCPQx1dQ@jetpack": {minVersion: "1.6.8.1-signed", installs: 100}, - "_cxMembers_@www.autopcbackup.com": {minVersion: "7.102.10.3597", installs: 99}, - "vpn@hide-my-ip.org": {minVersion: "10.6.2", installs: 99}, - "{1a5dabbd-0e74-41da-b532-a364bb552cab}": {minVersion: "1.0.9.1-signed", installs: 98}, - "FirePHPExtension-Build@firephp.org": {minVersion: "0.7.4.1-signed.1-signed", installs: 98}, - "jid1-UXDr6c69BeyPVw@jetpack": {minVersion: "0.8.2", installs: 98}, - "TopSafeTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 98}, - "{3b56bcc7-54e5-44a2-9b44-66c3ef58c13e}": {minVersion: "0.9.7.4", installs: 97}, - "autoreload@yz.com": {minVersion: "1.21", installs: 97}, - "manish.p05@gmail.com": {minVersion: "12.9", installs: 97}, - "videoresumer@jetpack": {minVersion: "1.1.4", installs: 97}, - "@Radio": {minVersion: "0.2.0", installs: 96}, - "_hfMembers_@free.everydaymanuals.com": {minVersion: "7.102.10.4142", installs: 96}, - "jid0-jJRRRBMgoShUhb07IvnxTBAl29w@jetpack": {minVersion: "2.0.4", installs: 96}, - "rikaichan-jpen@polarcloud.com": {minVersion: "2.01.160101", installs: 96}, - "{7c6cdf7c-8ea8-4be7-ae5a-0b3effe14d66}": {minVersion: "49.1", installs: 95}, - "{FDBAD97E-A258-4fe3-9CF6-60CF386C4422}": {minVersion: "2.0.1.6", installs: 95}, - "intgcal@egarracingteam.com.ar": {minVersion: "1.5.1", installs: 95}, - "MediaNewTab-the-extension1@mozilla.com": {minVersion: "0.1.6", installs: 95}, - "{9EB34849-81D3-4841-939D-666D522B889A}": {minVersion: "2.4.0.157", installs: 94}, - "{158d7cb3-7039-4a75-8e0b-3bd0a464edd2}": {minVersion: "2.7.1-signed.1-signed", installs: 94}, - "jid1-ach2kaGSshPJCg@jetpack": {minVersion: "0.1.1-signed.1-signed", installs: 94}, - "jid1-cwbvBTE216jjpg@jetpack": {minVersion: "2.1.0.1-signed.1-signed", installs: 94}, - "{f36c6cd1-da73-491d-b290-8fc9115bfa55}": {minVersion: "3.0.9.1-signed.1-let-fixed.1-signed", installs: 93}, - "dmpluginff@westbyte.com": {minVersion: "1.4.12", installs: 93}, - "firefox@serptrends.com": {minVersion: "0.8.14", installs: 93}, - "panel-plugin@effectivemeasure.com": {minVersion: "4.0.0", installs: 93}, - "_evMembers_@www.free.bestbackground.com": {minVersion: "7.102.10.3607", installs: 92}, - "canitbecheaper@trafficbroker.co.uk": {minVersion: "3.9.78", installs: 92}, - "favorites_selenium-ide@Samit.Badle": {minVersion: "2.0.1-signed.1-signed", installs: 92}, - "{5F590AA2-1221-4113-A6F4-A4BB62414FAC}": {minVersion: "0.45.8.20130519.3.1-signed.1-signed", installs: 90}, - "{3e9bb2a7-62ca-4efa-a4e6-f6f6168a652d}": {minVersion: "2.7.7.1-signed.1-signed", installs: 90}, - "{ab4b5718-3998-4a2c-91ae-18a7c2db513e}": {minVersion: "1.2.0.1-signed.1-signed", installs: 90}, - "2020Player_WEB@2020Technologies.com": {minVersion: "5.0.94.0", installs: 90}, - "translator@dontfollowme.net": {minVersion: "2.0.5", installs: 90}, - "YouTubeAutoReplay@arikv.com": {minVersion: "3.3.1-signed.1-signed", installs: 90}, - "{a949831f-d9c0-45ae-8c60-91c2a86fbfb6}": {minVersion: "0.2.1-signed.1-signed", installs: 89}, - "@vpn-unlimited-secure-proxy": {minVersion: "4.4", installs: 89}, - "jid1-JcGokIiQyjoBAQ@jetpack": {minVersion: "0.6.1-signed.1-signed", installs: 89}, - "_73Members_@www.easyhomedecorating.com": {minVersion: "7.102.10.4129", installs: 88}, - "{065ee92a-ad57-42a2-b6d5-466b6fd8e24d}": {minVersion: "0.11.6.1-signed.1-signed", installs: 88}, - "{455D905A-D37C-4643-A9E2-F6FEFAA0424A}": {minVersion: "0.8.17.1-signed.1-signed", installs: 88}, - "{7eb3f691-25b4-4a85-9038-9e57e2bcd537}": {minVersion: "0.4.4.1-signed.1-signed", installs: 88}, - "FunSocialTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 88}, - "Lucifox@lucidor.org": {minVersion: "0.9.13", installs: 88}, - "YourMediaTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 88}, - "youtube-video-player@lejenome.me": {minVersion: "0.2.38.1-signed.1-signed", installs: 88}, - "_hgMembers_@free.atozmanuals.com": {minVersion: "7.102.10.3604", installs: 87}, - "abb-acer@amazon.com": {minVersion: "10.161.13.1002", installs: 87}, - "gmail_panel@alejandrobrizuela.com.ar": {minVersion: "1.2.0", installs: 87}, - "izer@camelcamelcamel.com": {minVersion: "2.8.2", installs: 87}, - "tvnewtab-the-extension1@mozilla.com": {minVersion: "0.1.5", installs: 87}, - "vlc_shortcut@kosan.kosan": {minVersion: "0.8.3.0", installs: 87}, - "youtubeunblocker@unblocker.yt": {minVersion: "0.6.20", installs: 86}, - "email@jetpack": {minVersion: "0.0.16", installs: 86}, - "extensions@gismeteo.com": {minVersion: "5.1.0.2", installs: 86}, - "idaremote@westbyte.com": {minVersion: "1.6.3", installs: 86}, - "{725fc0a6-1f6b-4cf9-ae17-748d111dc16d}": {minVersion: "1.1.0", installs: 85}, - "jid1-461B0PwxL3oTt1@jetpack": {minVersion: "0.2.1-signed.1-signed", installs: 85}, - "webdavlauncher@benryan.com": {minVersion: "1.1.0", installs: 85}, - "jid1-ZM3BerwS6FsQAg@jetpack": {minVersion: "0.4.1-signed", installs: 84}, - "_fwMembers_@free.howtosuite.com": {minVersion: "7.102.10.4280", installs: 84}, - "{023e9ca0-63f3-47b1-bcb2-9badf9d9ef28}": {minVersion: "4.4.3.1-signed.1-signed", installs: 84}, - "{25A1388B-6B18-46c3-BEBA-A81915D0DE8F}": {minVersion: "1.7.8.5.1-signed.1-signed", installs: 84}, - "{75493B06-1504-4976-9A55-B6FE240FF0BF}": {minVersion: "3.4.0.0", installs: 84}, - "facepaste.firefox.addon@azabani.com": {minVersion: "2.91", installs: 84}, - "jid1-cplLTTY501TB2Q@jetpack": {minVersion: "0.5.1", installs: 84}, - "_d1Members_@free.mysocialshortcut.com": {minVersion: "7.102.10.4792", installs: 83}, - "{761a54f1-8ccf-4112-9e48-dbf72adf6244}": {minVersion: "2.3.1-signed.1-signed", installs: 83}, - "{BBB77B49-9FF4-4d5c-8FE2-92B1D6CD696C}": {minVersion: "2.0.0.1083", installs: 83}, - "{a3a5c777-f583-4fef-9380-ab4add1bc2a2}": {minVersion: "2.1.4", installs: 82}, - "{eb80b076-a444-444c-a590-5aee5d977d80}": {minVersion: "2.6.18", installs: 82}, - "KVAllmytube@KeepVid.com": {minVersion: "4.10.0", installs: 82}, - "lumerias-instagram@lumerias.com": {minVersion: "1.3", installs: 82}, - "omnibar@ajitk.com": {minVersion: "0.7.28.20141004.1-signed.1-signed", installs: 81}, - "@autofillanyforms-easytatkal": {minVersion: "7.51.0", installs: 81}, - "@youtuberightclick": {minVersion: "0.0.3", installs: 81}, - "autoproxy@autoproxy.org": {minVersion: "0.4b2.2013051811.1-signed.1-let-fixed.1-signed", installs: 80}, - "{e33788ea-0bb9-4502-9c77-bdc551afc8ad}": {minVersion: "1.0.4", installs: 80}, - "dmmm@westbyte.com": {minVersion: "1.3.4", installs: 80}, - "easycopy@smokyink.com": {minVersion: "2.7.0", installs: 80}, - "jid1-LelsJ0Oz0rt71A@jetpack": {minVersion: "2.0.0", installs: 80}, - "_f7Members_@download.smsfrombrowser.com": {minVersion: "7.38.8.45917", installs: 79}, - "{6614d11d-d21d-b211-ae23-815234e1ebb5}": {minVersion: "3.9.13", installs: 79}, - "FunTvTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 79}, - "{4204c864-50bf-467a-95b3-0912b7f15869}": {minVersion: "1.2.00.1-signed.1-signed", installs: 78}, - "{987311C6-B504-4aa2-90BF-60CC49808D42}": {minVersion: "3.1-signed.1-signed", installs: 78}, - "uploader@adblockfilters.mozdev.org": {minVersion: "2.1.1-signed.1-let-fixed.1-signed", installs: 77}, - "PageRank@addonfactory.in": {minVersion: "2.0.1-signed.1-signed", installs: 77}, - "restartbutton@strk.jp": {minVersion: "0.1.5.1-signed.1-signed", installs: 77}, - "text2voice@vik.josh": {minVersion: "1.15", installs: 77}, - "_dpMembers_@free.findyourmaps.com": {minVersion: "7.102.10.4185", installs: 76}, - "53ffxtbr@www.dailyfitnesscenter.com": {minVersion: "7.36.8.15623", installs: 76}, - "gary@builtwith.com": {minVersion: "1.9.6.1-signed.1-signed", installs: 76}, - "idamm@westbyte.com": {minVersion: "1.3.2", installs: 76}, - "jid1-3gu11JeYBiIuJA@jetpack": {minVersion: "3.1.1", installs: 76}, - "jid1-zV8eHYwTDNUtwQ@jetpack": {minVersion: "1.0.4", installs: 76}, - "nst@neiron.ru": {minVersion: "7.3.0.2", installs: 76}, - "service@touchpdf.com": {minVersion: "1.15.1-signed.1-signed", installs: 76}, - "{02450954-cdd9-410f-b1da-db804e18c671}": {minVersion: "0.96.3.1-signed.1-signed", installs: 75}, - "{4176DFF4-4698-11DE-BEEB-45DA55D89593}": {minVersion: "0.8.50.1-signed.1-signed", installs: 75}, - "{DAD0F81A-CF67-4eed-98D6-26F6E47274CA}": {minVersion: "1.8.1-signed.1-signed", installs: 75}, - "dealxplorermysites770@yahoo.com": {minVersion: "0.0.0.1", installs: 75}, - "firefox@online-convert.com": {minVersion: "1.4.1-signed.1-signed", installs: 75}, - "jid1-zmgYgiQPXJtjNA@jetpack": {minVersion: "1.23", installs: 75}, - "_evMembers_@www.bestbackground.com": {minVersion: "7.38.9.7654", installs: 74}, - "dmbarff@westbyte.com": {minVersion: "1.5.11", installs: 74}, - "inf@youtube-mp3.video": {minVersion: "0.1", installs: 74}, - "jid1-e7w0SHT82Gv9qA@jetpack": {minVersion: "1.2", installs: 74}, - "NewTabTVCool-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 74}, - "{E173B749-DB5B-4fd2-BA0E-94ECEA0CA55B}": {minVersion: "7.4.1-signed", installs: 73}, - "{9BAE5926-8513-417d-8E47-774955A7C60D}": {minVersion: "1.1.1d.1-signed.1-signed", installs: 73}, - "{3cc6c6ba-654c-417e-a8af-6997ac388ae1}": {minVersion: "49", installs: 72}, - "{daf44bf7-a45e-4450-979c-91cf07434c3d}": {minVersion: "2.0.5", installs: 72}, - "{dbac9680-d559-4cd4-9765-059879e8c467}": {minVersion: "5.0.5", installs: 72}, - "application@recettes.net": {minVersion: "4.5.0", installs: 72}, - "idapluginff@westbyte.com": {minVersion: "1.5.9", installs: 71}, - "imgflashblocker@shimon.chohen": {minVersion: "0.7.1-signed.1-signed", installs: 71}, - "inspector@mozilla.org": {minVersion: "2.0.16.1-signed", installs: 71}, - "jid1-ReWlW1efOwaQJQ@jetpack": {minVersion: "1.1.2", installs: 71}, - "youtubedownloader@trafficterminal.com": {minVersion: "1.0.1.1-signed.1-signed", installs: 71}, - "FavIconReloader@mozilla.org": {minVersion: "0.8.1-signed", installs: 70}, - "_2bMembers_@www.bettercareersearch.com": {minVersion: "7.38.8.45828", installs: 70}, - "{5e594888-3e8e-47da-b2c6-b0b545112f84}": {minVersion: "1.3.18", installs: 70}, - "@greatdealzu": {minVersion: "0.0.3", installs: 70}, - "86ffxtbr@download.yourvideochat.com": {minVersion: "7.36.8.15938", installs: 70}, - "google@hitachi.com": {minVersion: "0.3.1-signed.1-signed", installs: 70}, - "{6e84150a-d526-41f1-a480-a67d3fed910d}": {minVersion: "1.5.6.1-signed.1-signed", installs: 69}, - "firepicker@thedarkone": {minVersion: "1.4.3.1-signed.1-signed", installs: 69}, - "jid0-AocRXUCRsLTCYvn6bgJERnwfuqw@jetpack": {minVersion: "2.8.3.1-signed.1-signed", installs: 69}, - "nortonsecurity@symantec.com": {minVersion: "7.2.0f90", installs: 69}, - "{ef4e370e-d9f0-4e00-b93e-a4f274cfdd5a}": {minVersion: "1.4.10.1-signed", installs: 68}, - "{d4e0dc9c-c356-438e-afbe-dca439f4399d}": {minVersion: "49.1", installs: 68}, - "{E6C93316-271E-4b3d-8D7E-FE11B4350AEB}": {minVersion: "2.1.25.1-signed.1-signed", installs: 68}, - "{fa8476cf-a98c-4e08-99b4-65a69cb4b7d4}": {minVersion: "1.7.6.1", installs: 68}, - "simplesiteblocker@example.com": {minVersion: "1.1.1-signed.1-signed", installs: 68}, - "_fpMembers_@free.passwordlogic.com": {minVersion: "7.102.10.4853", installs: 67}, - "{6e764c17-863a-450f-bdd0-6772bd5aaa18}": {minVersion: "1.0.3.1-signed.1-signed", installs: 67}, - "adbeaver@adbeaver.org": {minVersion: "0.7.2.9", installs: 67}, - "application2@allo-pages.fr": {minVersion: "4.5.0", installs: 67}, - "arf3@getcartt.com": {minVersion: "1.2.3", installs: 67}, - "clearcache@michel.de.almeida": {minVersion: "2.0.1.1-signed.1-signed", installs: 67}, - "fbmessengerpanel@alejandrobrizuela.com.ar": {minVersion: "1.0.3.1-signed.1-signed", installs: 67}, - "tilt@mozilla.com": {minVersion: "1.0.1.1-signed.1-signed", installs: 67}, - "toolbar_AVIRA-V7@apn.ask.com": {minVersion: "127.25", installs: 67}, - "{524B8EF8-C312-11DB-8039-536F56D89593}": {minVersion: "4.91.0.0", installs: 66}, - "{9d1f059c-cada-4111-9696-41a62d64e3ba}": {minVersion: "0.17.0.1", installs: 66}, - "{B068AC18-0121-4e67-9A7E-6386F93F4F7A}": {minVersion: "2.4", installs: 66}, - "@lottadealsun": {minVersion: "0.0.1", installs: 66}, - "@thebestyoutubedownloader": {minVersion: "1.0.0.7", installs: 66}, - "TopSocialTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 66}, - "{11483926-db67-4190-91b1-ef20fcec5f33}": {minVersion: "0.4.9.1", installs: 65}, - "{8AA36F4F-6DC7-4c06-77AF-5035170634FE}": {minVersion: "2016.9.16", installs: 65}, - "dam@tensons.com": {minVersion: "5.0.7", installs: 65}, - "jid1-D7momAzRw417Ag@jetpack": {minVersion: "4.5.13", installs: 65}, - "support@videoadd.ru": {minVersion: "2.8.1.1-signed.1-signed", installs: 65}, - "{95322c08-05ff-4f3c-85fd-8ceb821988dd}": {minVersion: "49", installs: 64}, - "AllMyTube@Wondershare.com": {minVersion: "4.9.1", installs: 64}, - "azan-times@hamid.net": {minVersion: "1.2.3.1-signed.1-signed", installs: 64}, - "check-compatibility@dactyl.googlecode.com": {minVersion: "1.3.1-signed.1-signed", installs: 64}, - "ifamebook@stormvision.it": {minVersion: "4.03.1-signed", installs: 64}, - "jid1-vRJA7N8VwBoiXw@jetpack": {minVersion: "1.1.1.1-signed", installs: 64}, - "{04426594-bce6-4705-b811-bcdba2fd9c7b}": {minVersion: "1.7.1-signed.1-signed", installs: 63}, - "{f3f219f9-cbce-467e-b8fe-6e076d29665c}": {minVersion: "50", installs: 63}, - "fireforce@scrt.ch": {minVersion: "2.2.1-signed.1-signed", installs: 63}, - "FunkyMediaTab-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 63}, - "TopTabTV-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 63}, - "{018f3160-1a6f-4650-84fd-aad8c13609c8}": {minVersion: "0.1.1-signed.1-signed", installs: 62}, - "{2e710e6b-5e9d-44ba-8f4e-09a040978b49}": {minVersion: "1.7", installs: 62}, - "{c1970c0d-dbe6-4d91-804f-c9c0de643a57}": {minVersion: "1.3.2.13.1-signed.1-signed", installs: 62}, - "{c9b4529a-eeba-4e48-976e-f3d3f9026e04}": {minVersion: "1.1.1-signed.1-signed", installs: 62}, - "{df4e4df5-5cb7-46b0-9aef-6c784c3249f8}": {minVersion: "1.3.0.1-signed.1-signed", installs: 62}, - "@stremio": {minVersion: "1.0.2", installs: 62}, - "application@les-pages.com": {minVersion: "4.4.0", installs: 62}, - "ffvkontaktemusic@chupakabr.ru": {minVersion: "2.2.1-signed.1-signed", installs: 62}, - "firefinder@robertnyman.com": {minVersion: "1.4.1-signed.1-signed", installs: 62}, - "formhistory@yahoo.com": {minVersion: "1.4.0.6", installs: 62}, - "fxclickonce@rushyo.com": {minVersion: "0.1.1-signed.1-signed", installs: 62}, - "gmail@borsosfisoft.com": {minVersion: "1.0.1.1-signed.1-signed", installs: 62}, - "HighlightedTextToFile@bobbyrne01.org": {minVersion: "2.7.1", installs: 62}, - "jid1-n85lxPv1NAWVTQ@jetpack": {minVersion: "0.96.1.1-signed", installs: 62}, - "ramback@pavlov.net": {minVersion: "1.0.1-signed.1-signed", installs: 62}, - "VacuumPlacesImproved@lultimouomo-gmail.com": {minVersion: "1.2.1-signed.1-signed", installs: 62}, - "@News": {minVersion: "0.2.0", installs: 61}, - "{45d8ff86-d909-11db-9705-005056c00008}": {minVersion: "1.3.4.8", installs: 61}, - "{686fc9c5-c339-43db-b93a-5181a217f9a6}": {minVersion: "1.11", installs: 61}, - "{ea2b95c2-9be8-48ed-bdd1-5fcd2ad0ff99}": {minVersion: "0.3.8.1.1-signed.1-signed", installs: 61}, - "@chomikuj": {minVersion: "1.2.0", installs: 61}, - "avg@wtu3": {minVersion: "3.7.0.0", installs: 61}, - "jid1-f7dnBeTj8ElpWQ@jetpack": {minVersion: "1.34.1-signed.1-signed", installs: 61}, - "jid1-OY8Xu5BsKZQa6A@jetpack": {minVersion: "2.0.21", installs: 61}, - "jid1-u9RbFp9JcoEGGw@jetpack": {minVersion: "1.2.2.1-signed.1-signed", installs: 61}, - "plugin@okta.com": {minVersion: "5.8.0", installs: 61}, - "showpassword@pratikpoddar": {minVersion: "1.7.1-signed.1-signed", installs: 61}, - "IGF.F3@igufei.com": {minVersion: "3.2.11", installs: 60}, - "{12b6fdcd-4423-4276-82a3-73fdbff5f7e4}": {minVersion: "50", installs: 60}, - "{8F6A6FD9-0619-459f-B9D0-81DE065D4E21}": {minVersion: "1.13", installs: 60}, - "jid1-mW7iuA66Ny8Ziw@jetpack": {minVersion: "0.9.1-signed.1-signed", installs: 60}, - "nishan.naseer.googimagesearch@gmail.com": {minVersion: "0.5.1-signed.1-signed", installs: 60}, - "quicksearch@yandex.ru": {minVersion: "1.0.13", installs: 60}, - "{902D2C4A-457A-4EF9-AD43-7014562929FF}": {minVersion: "0.6.4", installs: 59}, - "@yset": {minVersion: "0.0.10", installs: 59}, - "csscoverage@spaghetticoder.org": {minVersion: "0.3.4.1-signed.1-signed", installs: 59}, - "dgnria2@nuance.com": {minVersion: "15.00.000.058", installs: 59}, - "firequery@binaryage.com": {minVersion: "2.0.4", installs: 59}, - "IBM-cck@firefox-extensions.ibm.com": {minVersion: "2.3.0", installs: 59}, - "trackmenot@mrl.nyu.edu": {minVersion: "0.9.2", installs: 59}, - "_chMembers_@free.discoverancestry.com": {minVersion: "7.102.10.3818", installs: 58}, - "{338e0b96-2285-4424-b4c8-e25560750fa3}": {minVersion: "3.1-signed.1-signed", installs: 58}, - "{8b5bea8c-6194-4c7c-a440-d5ca181480c3}": {minVersion: "1.500.000.11", installs: 58}, - "{e30e9060-21d5-11e3-8224-0800200c9a66}": {minVersion: "1.2.12", installs: 58}, - "LDshowpicture_plashcor@gmail.com": {minVersion: "3.2", installs: 58}, - "open.about.permissions@jasnapaka.com": {minVersion: "1.2.1-signed.1-signed", installs: 58}, - "sqlime@security.compass": {minVersion: "0.4.7.1-signed.1-signed", installs: 58}, - "@jetpack-easy-turism2": {minVersion: "7.1.0", installs: 57}, - "check4change-owner@mozdev.org": {minVersion: "1.9.8.1", installs: 57}, - "jid1-SDFC9fEAZRW7ab@jetpack": {minVersion: "0.1.3.1-signed.1-signed", installs: 57}, - "linkgopher@oooninja.com": {minVersion: "1.3.3.1-signed.1-signed", installs: 57}, - "pixelperfectplugin@openhouseconcepts.com": {minVersion: "2.0.14", installs: 57}, - "YoutubeDownloader@huangho.net76.net": {minVersion: "1.6.5.1-signed.1-signed", installs: 57}, - "lwthemes-manager@loucypher": {minVersion: "0.2.1-signed.1-let-fixed.1-signed", installs: 56}, - "_eiMembers_@www.100sofrecipes.com": {minVersion: "7.102.10.3580", installs: 56}, - "{068c594c-1a69-4f51-888d-1e231eac59a3}": {minVersion: "1", installs: 56}, - "{139C4B80-60ED-11E4-80EC-84041E5D46B0}": {minVersion: "1.3", installs: 56}, - "{4c7097f7-08f2-4ef2-9b9f-f95fa4cbb064}": {minVersion: "1.1", installs: 56}, - "{776f38cb-6255-4b92-b5cf-e5c71ff2b688}": {minVersion: "1.6", installs: 56}, - "{79c50f9a-2ffe-4ee0-8a37-fae4f5dacd4f}": {minVersion: "5.1.3", installs: 56}, - "{8BCA0E8A-E57B-425b-A05B-CD3868EB577E}": {minVersion: "1.4.1-signed.1-signed", installs: 56}, - "easycopypaste@everhelper.me": {minVersion: "1.1.0.1-signed.1-signed", installs: 56}, - "NoiaFoxoption@davidvincent.tld": {minVersion: "3.0.2.1-signed", installs: 56}, - "r2d2b2g@mozilla.org": {minVersion: "4.0.4.1-signed", installs: 56}, - "TFToolbarX@torrent-finder": {minVersion: "1.3.1.1-signed.1-signed", installs: 56}, - "{E4091D66-127C-11DB-903A-DE80D2EFDFE8}": {minVersion: "1.6.5.5.1-signed.1-signed", installs: 55}, - "downintab@max.max": {minVersion: "1.00.1-signed.1-signed", installs: 55}, - "flv2mp3@hotger.com": {minVersion: "2.3.2-signed", installs: 55}, - "ISVCU@iSkysoft.com": {minVersion: "5.1.0", installs: 55}, - "jid1-n5ARdBzHkUEdAA@jetpack": {minVersion: "3.8.7", installs: 55}, - "rpnetdownloadhelper@gmail.com": {minVersion: "3.0.1-signed.1-signed", installs: 55}, - "shpassword@shpassword.fr": {minVersion: "0.3.1-signed.1-signed", installs: 55}, - "snt@simplenewtab.com": {minVersion: "1.3", installs: 55}, - "admin@djamol.com": {minVersion: "4.31.1-signed.1-signed", installs: 54}, - "{22870005-adef-4c9d-ae36-d0e1f2f27e5a}": {minVersion: "0.4.0.9.1.1-signed.1-signed", installs: 54}, - "{DBBB3167-6E81-400f-BBFD-BD8921726F52}": {minVersion: "7125.2016.0115.2213", installs: 54}, - "{e4f94d1e-2f53-401e-8885-681602c0ddd8}": {minVersion: "1.0.1-signed.1-signed", installs: 54}, - "{FBF6D7FB-F305-4445-BB3D-FEF66579A033}": {minVersion: "6", installs: 54}, - "5aa55fd5-6e61-4896-b186-fdc6f298ec92@mozilla": {minVersion: "0.1.2.1-signed", installs: 54}, - "fireml@sirma.bg": {minVersion: "1.1.11.1-signed.1-signed", installs: 54}, - "info@priceblink.com": {minVersion: "4.8", installs: 54}, - "jid0-f82gosWvE8oeGQt6WDCGRF1Dy7Q@jetpack": {minVersion: "1.0.003", installs: 54}, - "jid0-hyjN250ZzTOOX3evFwwAQBxE4ik@jetpack": {minVersion: "6.0.1-signed.1-signed", installs: 54}, - "restart@restart.org": {minVersion: "0.5.1-signed.1-signed", installs: 54}, - "webmaster@keep-tube.com": {minVersion: "1.2.1-signed.1-signed", installs: 54}, - "eliteproxyswitcher@my-proxy.com": {minVersion: "1.2.0.2.1-signed.1-signed", installs: 53}, - "foxfilter@inspiredeffect.net": {minVersion: "7.7.1-signed.1-signed", installs: 53}, - "searchprivacy@searchprivacy.co": {minVersion: "1.15", installs: 53}, - "SignPlugin@pekao.pl": {minVersion: "1.4.0.73", installs: 53}, - "{15fe27f3-e5ab-2d59-4c5c-dadc7945bdbd}": {minVersion: "2.1.1.1-signed.1-signed", installs: 52}, - "ipfuck@p4ul.info": {minVersion: "1.2.1.1-signed.1-signed", installs: 52}, - "jyboy.yy@gmail.com": {minVersion: "1.0.4.1-signed.1-signed", installs: 52}, - "MySafeTabs-the-extension1@mozilla.com": {minVersion: "0.1.9", installs: 52}, - "saiful.neo@gmail.com": {minVersion: "3.0.1-signed.1-signed", installs: 52}, - "sendtokindle@amazon.com": {minVersion: "1.0.2.76", installs: 52}, - "smile1Button@amazon.com": {minVersion: "1.0.1-signed.1-signed", installs: 52}, - "whodeletedme@deleted.io": {minVersion: "0.3.3", installs: 52}, - "{C0CB8BA3-6C1B-47e8-A6AB-1FAB889562D9}": {minVersion: "0.7.6", installs: 51}, - "@irctctatkal": {minVersion: "2.0.0", installs: 51}, - "antgroup@antdownloadmanager.com": {minVersion: "0.1.7", installs: 51}, - "downloadplan@firefoxmania.uci.cu": {minVersion: "1.3.1-signed.1-signed", installs: 51}, - "jid1-AoXeeOB4j7kFdA@jetpack": {minVersion: "8.1", installs: 51}, - "memoryrestart@teamextension.com": {minVersion: "1.18.1-signed.1-signed", installs: 51}, - "multifox-toolbar-button@rbaldwin": {minVersion: "4.28.1-signed.1-signed", installs: 51}, - "soaclient@santoso": {minVersion: "0.2.1-signed.1-signed", installs: 51}, - "speeddns@gmail.com": {minVersion: "0.2.1-signed.1-signed", installs: 51}, - "windowandtablimiter@weintraut.net": {minVersion: "4.28.1-signed.1-signed", installs: 51}, - "@Recipes": {minVersion: "0.2.0", installs: 50}, - "{e6a9a96e-4a08-4719-b9bd-0e91c35aaabc}": {minVersion: "1.3.1.1-signed.1-signed", installs: 50}, - "autopager@mozilla.org": {minVersion: "0.8.0.10.1-signed.1-signed", installs: 50}, - "btpersonas@brandthunder.com": {minVersion: "2.0.4.7", installs: 50}, - "gdrivepanel@alejandrobrizuela.com.ar": {minVersion: "1.0.2.1-signed.1-signed", installs: 50}, - "jid1-m3kqTBs1zKXXaA@jetpack": {minVersion: "0.2.6.1-signed.1-signed", installs: 50}, - "qqmail_plugin_for_firefox@tencent.com": {minVersion: "1.0.0.22", installs: 50}, - "savefileto@mozdev.org": {minVersion: "2.5.5", installs: 50}, - "seodoctor@prelovac.com": {minVersion: "1.6.5.1-signed.1-signed", installs: 50}, - "support@todoist.com": {minVersion: "4.0.5", installs: 50}, - "toolbar_TeoMediaTB@apn.ask.com": {minVersion: "135.3", installs: 50}, - "txftn@tencent.com": {minVersion: "1.0.0.7", installs: 50}, -}; - -// ================== END OF LIST FOR 51 ====================== - -// We use these named policies to correlate the telemetry -// data with them, in order to understand how each set -// is behaving in the wild. -const RolloutPolicy = { - // Used during 48 Beta cycle - "2a": { addons: set2, webextensions: true }, - "2b": { addons: set2, webextensions: false }, - - // Set agreed for Release 49 - "49a": { addons: set49Release, webextensions: true }, - "49b": { addons: set49Release, webextensions: false }, - - // Smaller set that can be used for Release 49 - "49limiteda": { addons: set49PaneOnly, webextensions: true }, - "49limitedb": { addons: set49PaneOnly, webextensions: false }, - - // Beta testing on 50 - "50allmpc": { addons: [], webextensions: true, mpc: true }, - - // Beta testing on 51 - "51alladdons": { addons: [], webextensions: true, alladdons: true }, - - // 51 release - "51set1": { addonsv2: set51Release, installs: 50, webextensions: true, mpc: true }, - "51set2": { addonsv2: set51Release, installs: 100, webextensions: true, mpc: true }, - "51set3": { addonsv2: set51Release, installs: 300, webextensions: true, mpc: true }, - "51set4": { addonsv2: set51Release, installs: 1000, webextensions: true, mpc: true }, - - // ESR - "esrA": { addons: [], mpc: true, webextensions: true }, - "esrB": { addons: [], mpc: true, webextensions: false }, - "esrC": { addons: [], mpc: false, webextensions: true }, - - "xpcshell-test": { addons: [ADDONS.test1, ADDONS.test2], webextensions: false }, -}; - -Object.defineProperty(this, "isAddonPartOfE10SRollout", { - configurable: false, - enumerable: false, - writable: false, - value: function isAddonPartOfE10SRollout(aAddon) { - let blocklist = Preferences.get(PREF_E10S_ADDON_BLOCKLIST, ""); - let policyId = Preferences.get(PREF_E10S_ADDON_POLICY, ""); - - if (!policyId || !RolloutPolicy.hasOwnProperty(policyId)) { - return false; - } - - if (blocklist && blocklist.indexOf(aAddon.id) > -1) { - return false; - } - - let policy = RolloutPolicy[policyId]; - - if (aAddon.mpcOptedOut == true) { - return false; - } - - if (policy.alladdons) { - return true; - } - - if (policy.webextensions && aAddon.type == "webextension") { - return true; - } - - if (policy.mpc && aAddon.multiprocessCompatible) { - return true; - } - - if (policy.addonsv2) { - if (aAddon.id in policy.addonsv2) { - let rolloutAddon = policy.addonsv2[aAddon.id]; - - if (rolloutAddon.installs >= policy.installs && - Services.vc.compare(aAddon.version, rolloutAddon.minVersion) >= 0) { - return true; - } - } - return false; - } - - for (let rolloutAddon of policy.addons) { - if (aAddon.id == rolloutAddon.id && - Services.vc.compare(aAddon.version, rolloutAddon.minVersion) >= 0) { - return true; - } - } - - return false; - }, -}); diff --git a/toolkit/mozapps/extensions/internal/GMPProvider.jsm b/toolkit/mozapps/extensions/internal/GMPProvider.jsm index 9bb34a7af..52affa9ba 100644 --- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm +++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm @@ -12,17 +12,12 @@ this.EXPORTED_SYMBOLS = []; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/AddonManager.jsm"); -/* globals AddonManagerPrivate*/ Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Preferences.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); -/* globals OS*/ Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://gre/modules/Task.jsm"); Cu.import("resource://gre/modules/GMPUtils.jsm"); -/* globals EME_ADOBE_ID, GMP_PLUGIN_IDS, GMPPrefs, GMPUtils, OPEN_H264_ID, WIDEVINE_ID */ -Cu.import("resource://gre/modules/AppConstants.jsm"); -Cu.import("resource://gre/modules/UpdateUtils.jsm"); XPCOMUtils.defineLazyModuleGetter( this, "GMPInstallManager", "resource://gre/modules/GMPInstallManager.jsm"); @@ -41,8 +36,6 @@ const CLEARKEY_PLUGIN_ID = "gmp-clearkey"; const CLEARKEY_VERSION = "0.1"; const GMP_LICENSE_INFO = "gmp_license_info"; -const GMP_PRIVACY_INFO = "gmp_privacy_info"; -const GMP_LEARN_MORE = "learn_more_label"; const GMP_PLUGINS = [ { @@ -54,33 +47,17 @@ const GMP_PLUGINS = [ // localisation. licenseURL: "chrome://mozapps/content/extensions/OpenH264-license.txt", homepageURL: "http://www.openh264.org/", - optionsURL: "chrome://mozapps/content/extensions/gmpPrefs.xul", + optionsURL: "chrome://mozapps/content/extensions/gmpPrefs.xul" }, { id: EME_ADOBE_ID, name: "eme-adobe_name", description: "eme-adobe_description", - // The following learnMoreURL is another hack to be able to support a SUMO page for this - // feature. - get learnMoreURL() { - return Services.urlFormatter.formatURLPref("app.support.baseURL") + "drm-content"; - }, licenseURL: "http://help.adobe.com/en_US/primetime/drm/HTML5_CDM_EULA/index.html", homepageURL: "http://help.adobe.com/en_US/primetime/drm/HTML5_CDM", optionsURL: "chrome://mozapps/content/extensions/gmpPrefs.xul", - isEME: true, - }, - { - id: WIDEVINE_ID, - name: "widevine_description", - // Describe the purpose of both CDMs in the same way. - description: "eme-adobe_description", - licenseURL: "https://www.google.com/policies/privacy/", - homepageURL: "https://www.widevine.com/", - optionsURL: "chrome://mozapps/content/extensions/gmpPrefs.xul", isEME: true }]; -XPCOMUtils.defineConstant(this, "GMP_PLUGINS", GMP_PLUGINS); XPCOMUtils.defineLazyGetter(this, "pluginsBundle", () => Services.strings.createBundle("chrome://global/locale/plugins.properties")); @@ -170,17 +147,13 @@ GMPWrapper.prototype = { get version() { return GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VERSION, null, this._plugin.id); }, - get isActive() { - return !this.appDisabled && - !this.userDisabled && - !GMPUtils.isPluginHidden(this._plugin); - }, + get isActive() { return !this.appDisabled && !this.userDisabled; }, get appDisabled() { if (this._plugin.isEME && !GMPPrefs.get(GMPPrefs.KEY_EME_ENABLED, true)) { // If "media.eme.enabled" is false, all EME plugins are disabled. return true; } - return false; + return false; }, get userDisabled() { @@ -210,7 +183,7 @@ GMPWrapper.prototype = { get updateDate() { let time = Number(GMPPrefs.get(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, null, this._plugin.id)); - if (!isNaN(time) && this.isInstalled) { + if (time !== NaN && this.isInstalled) { return new Date(time * 1000) } return null; @@ -287,12 +260,14 @@ GMPWrapper.prototype = { return this._updateTask; } - this._updateTask = Task.spawn(function*() { + this._updateTask = Task.spawn(function* GMPProvider_updateTask() { this._log.trace("findUpdates() - updateTask"); try { let installManager = new GMPInstallManager(); - let res = yield installManager.checkForAddons(); - let update = res.gmpAddons.find(addon => addon.id === this._plugin.id); + let gmpAddons = yield installManager.checkForAddons(); + let update = gmpAddons.find(function(aAddon) { + return aAddon.id === this._plugin.id; + }, this); if (update && update.isValid && !update.isInstalled) { this._log.trace("findUpdates() - found update for " + this._plugin.id + ", installing"); @@ -338,9 +313,6 @@ GMPWrapper.prototype = { }, _handleEnabledChanged: function() { - this._log.info("_handleEnabledChanged() id=" + - this._plugin.id + " isActive=" + this.isActive); - AddonManagerPrivate.callAddonListeners(this.isActive ? "onEnabling" : "onDisabling", this, false); @@ -361,17 +333,11 @@ GMPWrapper.prototype = { }, onPrefEMEGlobalEnabledChanged: function() { - this._log.info("onPrefEMEGlobalEnabledChanged() id=" + this._plugin.id + - " appDisabled=" + this.appDisabled + " isActive=" + this.isActive + - " hidden=" + GMPUtils.isPluginHidden(this._plugin)); - AddonManagerPrivate.callAddonListeners("onPropertyChanged", this, ["appDisabled"]); - // If EME or the GMP itself are disabled, uninstall the GMP. - // Otherwise, check for updates, so we download and install the GMP. if (this.appDisabled) { this.uninstallPlugin(); - } else if (!GMPUtils.isPluginHidden(this._plugin)) { + } else { AddonManagerPrivate.callInstallListeners("onExternalInstall", null, this, null, false); AddonManagerPrivate.callAddonListeners("onInstalling", this, false); @@ -407,12 +373,12 @@ GMPWrapper.prototype = { let parsedData; try { parsedData = JSON.parse(data); - } catch (ex) { + } catch(ex) { this._log.error("Malformed EME video message with data: " + data); return; } let {status: status, keySystem: keySystem} = parsedData; - if (status == "cdm-not-installed") { + if (status == "cdm-not-installed" || status == "cdm-insufficient-version") { this.checkForUpdates(0); } }, @@ -458,8 +424,6 @@ GMPWrapper.prototype = { gmpService.removeAndDeletePluginDirectory(this.gmpPath); } GMPPrefs.reset(GMPPrefs.KEY_PLUGIN_VERSION, this.id); - GMPPrefs.reset(GMPPrefs.KEY_PLUGIN_ABI, this.id); - GMPPrefs.reset(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, this.id); AddonManagerPrivate.callAddonListeners("onUninstalled", this); }, @@ -477,56 +441,6 @@ GMPWrapper.prototype = { } return this._updateTask; }, - - _arePluginFilesOnDisk: function() { - let fileExists = function(aGmpPath, aFileName) { - let f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - let path = OS.Path.join(aGmpPath, aFileName); - f.initWithPath(path); - return f.exists(); - }; - - let id = this._plugin.id.substring(4); - let libName = AppConstants.DLL_PREFIX + id + AppConstants.DLL_SUFFIX; - let infoName; - if (this._plugin.id == WIDEVINE_ID) { - infoName = "manifest.json"; - } else { - infoName = id + ".info"; - } - - return fileExists(this.gmpPath, libName) && - fileExists(this.gmpPath, infoName) && - (this._plugin.id != EME_ADOBE_ID || fileExists(this.gmpPath, id + ".voucher")); - }, - - validate: function() { - if (!this.isInstalled) { - // Not installed -> Valid. - return { - installed: false, - valid: true - }; - } - - let abi = GMPPrefs.get(GMPPrefs.KEY_PLUGIN_ABI, UpdateUtils.ABI, this._plugin.id); - if (abi != UpdateUtils.ABI) { - // ABI doesn't match. Possibly this is a profile migrated across platforms - // or from 32 -> 64 bit. - return { - installed: true, - mismatchedABI: true, - valid: false - }; - } - - // Installed -> Check if files are missing. - let filesOnDisk = this._arePluginFilesOnDisk(); - return { - installed: true, - valid: filesOnDisk - }; - }, }; var GMPProvider = { @@ -538,6 +452,7 @@ var GMPProvider = { configureLogging(); this._log = Log.repository.getLoggerWithMessagePrefix("Toolkit.GMP", "GMPProvider."); + let telemetry = {}; this.buildPluginList(); this.ensureProperCDMInstallState(); @@ -551,50 +466,47 @@ var GMPProvider = { gmpPath); if (gmpPath && isEnabled) { - let validation = wrapper.validate(); - if (validation.mismatchedABI) { - this._log.info("startup - gmp " + plugin.id + - " mismatched ABI, uninstalling"); - wrapper.uninstallPlugin(); - continue; - } - if (!validation.valid) { - this._log.info("startup - gmp " + plugin.id + - " invalid, uninstalling"); - wrapper.uninstallPlugin(); - continue; - } this._log.info("startup - adding gmp directory " + gmpPath); try { gmpService.addPluginDirectory(gmpPath); - } catch (e) { - if (e.name != 'NS_ERROR_NOT_AVAILABLE') - throw e; + } catch (e if e.name == 'NS_ERROR_NOT_AVAILABLE') { this._log.warn("startup - adding gmp directory failed with " + e.name + " - sandboxing not available?", e); } } + + if (this.isEnabled) { + telemetry[id] = { + userDisabled: wrapper.userDisabled, + version: wrapper.version, + applyBackgroundUpdates: wrapper.applyBackgroundUpdates, + }; + } } - try { - let greDir = Services.dirsvc.get(NS_GRE_DIR, - Ci.nsILocalFile); - let clearkeyPath = OS.Path.join(greDir.path, - CLEARKEY_PLUGIN_ID, - CLEARKEY_VERSION); - this._log.info("startup - adding clearkey CDM directory " + - clearkeyPath); - gmpService.addPluginDirectory(clearkeyPath); - } catch (e) { - this._log.warn("startup - adding clearkey CDM failed", e); + if (Preferences.get(GMPPrefs.KEY_EME_ENABLED, false)) { + try { + let greDir = Services.dirsvc.get(NS_GRE_DIR, + Ci.nsILocalFile); + let clearkeyPath = OS.Path.join(greDir.path, + CLEARKEY_PLUGIN_ID, + CLEARKEY_VERSION); + this._log.info("startup - adding clearkey CDM directory " + + clearkeyPath); + gmpService.addPluginDirectory(clearkeyPath); + } catch (e) { + this._log.warn("startup - adding clearkey CDM failed", e); + } } + + AddonManagerPrivate.setTelemetryDetails("GMP", telemetry); }, shutdown: function() { this._log.trace("shutdown"); Preferences.ignore(GMPPrefs.KEY_LOG_BASE, configureLogging); - let shutdownTask = Task.spawn(function*() { + let shutdownTask = Task.spawn(function* GMPProvider_shutdownTask() { this._log.trace("shutdown - shutdownTask"); let shutdownSucceeded = true; @@ -637,10 +549,16 @@ var GMPProvider = { return; } - let results = Array.from(this._plugins.values()) - .filter(p => !GMPUtils.isPluginHidden(p)) - .map(p => p.wrapper); - + // Tycho: + // let results = [p.wrapper for ([id, p] of this._plugins) + // if (!GMPUtils.isPluginHidden(p))]; + let results = []; + for (let [id, p] of this._plugins) { + if (!GMPUtils.isPluginHidden(p)) { + results.push(p.wrapper); + } + } + aCallback(results); }, @@ -648,20 +566,14 @@ var GMPProvider = { return GMPPrefs.get(GMPPrefs.KEY_PROVIDER_ENABLED, false); }, - generateFullDescription: function(aPlugin) { - let rv = []; - for (let [urlProp, labelId] of [["learnMoreURL", GMP_LEARN_MORE], - ["licenseURL", aPlugin.id == WIDEVINE_ID ? - GMP_PRIVACY_INFO : GMP_LICENSE_INFO]]) { - if (aPlugin[urlProp]) { - let label = pluginsBundle.GetStringFromName(labelId); - rv.push(`<xhtml:a href="${aPlugin[urlProp]}" target="_blank">${label}</xhtml:a>.`); - } - } - return rv.length ? rv.join("<xhtml:br /><xhtml:br />") : undefined; + generateFullDescription: function(aLicenseURL, aLicenseInfo) { + return "<xhtml:a href=\"" + aLicenseURL + "\" target=\"_blank\">" + + aLicenseInfo + "</xhtml:a>." }, buildPluginList: function() { + let licenseInfo = pluginsBundle.GetStringFromName(GMP_LICENSE_INFO); + this._plugins = new Map(); for (let aPlugin of GMP_PLUGINS) { let plugin = { @@ -673,7 +585,10 @@ var GMPProvider = { wrapper: null, isEME: aPlugin.isEME, }; - plugin.fullDescription = this.generateFullDescription(aPlugin); + if (aPlugin.licenseURL) { + plugin.fullDescription = + this.generateFullDescription(aPlugin.licenseURL, licenseInfo); + } plugin.wrapper = new GMPWrapper(plugin); this._plugins.set(plugin.id, plugin); } diff --git a/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm b/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm index 49dfa237f..1e7d6b0d8 100644 --- a/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm +++ b/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm @@ -21,8 +21,8 @@ const ORIGIN_TOP_RIGHT = 1; const ORIGIN_BOTTOM_LEFT = 2; this.LightweightThemeImageOptimizer = { - optimize: function(aThemeData, aScreen) { - let data = Object.assign({}, aThemeData); + optimize: function LWTIO_optimize(aThemeData, aScreen) { + let data = Utils.createCopy(aThemeData); if (!data.headerURL) { return data; } @@ -38,7 +38,7 @@ this.LightweightThemeImageOptimizer = { return data; }, - purge: function() { + purge: function LWTIO_purge() { let dir = FileUtils.getDir("ProfD", ["lwtheme"]); dir.followLinks = false; try { @@ -52,12 +52,18 @@ Object.freeze(LightweightThemeImageOptimizer); var ImageCropper = { _inProgress: {}, - getCroppedImageURL: function(aImageURL, aScreen, aOrigin) { + getCroppedImageURL: + function ImageCropper_getCroppedImageURL(aImageURL, aScreen, aOrigin) { // We can crop local files, only. if (!aImageURL.startsWith("file://")) { return aImageURL; } + if (Services.prefs.getBoolPref("lightweightThemes.animation.enabled")) { + //Don't crop if animated + return aImageURL; + } + // Generate the cropped image's file name using its // base name and the current screen size. let uri = Services.io.newURI(aImageURL, null, null); @@ -88,7 +94,7 @@ var ImageCropper = { return aImageURL; }, - _crop: function(aURI, aTargetFile, aScreen, aOrigin) { + _crop: function ImageCropper_crop(aURI, aTargetFile, aScreen, aOrigin) { let inProgress = this._inProgress; inProgress[aTargetFile.path] = true; @@ -96,7 +102,7 @@ var ImageCropper = { delete inProgress[aTargetFile.path]; } - ImageFile.read(aURI, function(aInputStream, aContentType) { + ImageFile.read(aURI, function crop_readImageFile(aInputStream, aContentType) { if (aInputStream && aContentType) { let image = ImageTools.decode(aInputStream, aContentType); if (image && image.width && image.height) { @@ -114,24 +120,27 @@ var ImageCropper = { }; var ImageFile = { - read: function(aURI, aCallback) { - this._netUtil.asyncFetch({ - uri: aURI, - loadUsingSystemPrincipal: true, - contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE - }, function(aInputStream, aStatus, aRequest) { + read: function ImageFile_read(aURI, aCallback) { + this._netUtil.asyncFetch2( + aURI, + function read_asyncFetch(aInputStream, aStatus, aRequest) { if (Components.isSuccessCode(aStatus) && aRequest instanceof Ci.nsIChannel) { let channel = aRequest.QueryInterface(Ci.nsIChannel); aCallback(aInputStream, channel.contentType); } else { aCallback(); } - }); + }, + null, // aLoadingNode + Services.scriptSecurityManager.getSystemPrincipal(), + null, // aTriggeringPrincipal + Ci.nsILoadInfo.SEC_NORMAL, + Ci.nsIContentPolicy.TYPE_IMAGE); }, - write: function(aFile, aInputStream, aCallback) { + write: function ImageFile_write(aFile, aInputStream, aCallback) { let fos = FileUtils.openSafeFileOutputStream(aFile); - this._netUtil.asyncCopy(aInputStream, fos, function(aResult) { + this._netUtil.asyncCopy(aInputStream, fos, function write_asyncCopy(aResult) { FileUtils.closeSafeFileOutputStream(fos); // Remove the file if writing was not successful. @@ -150,7 +159,7 @@ XPCOMUtils.defineLazyModuleGetter(ImageFile, "_netUtil", "resource://gre/modules/NetUtil.jsm", "NetUtil"); var ImageTools = { - decode: function(aInputStream, aContentType) { + decode: function ImageTools_decode(aInputStream, aContentType) { let outParam = {value: null}; try { @@ -160,7 +169,7 @@ var ImageTools = { return outParam.value; }, - encode: function(aImage, aScreen, aOrigin, aContentType) { + encode: function ImageTools_encode(aImage, aScreen, aOrigin, aContentType) { let stream; let width = Math.min(aImage.width, aScreen.width); let height = Math.min(aImage.height, aScreen.height); @@ -178,3 +187,12 @@ var ImageTools = { XPCOMUtils.defineLazyServiceGetter(ImageTools, "_imgTools", "@mozilla.org/image/tools;1", "imgITools"); +var Utils = { + createCopy: function Utils_createCopy(aData) { + let copy = {}; + for (let [k, v] in Iterator(aData)) { + copy[k] = v; + } + return copy; + } +}; diff --git a/toolkit/mozapps/extensions/internal/PluginProvider.jsm b/toolkit/mozapps/extensions/internal/PluginProvider.jsm index 075159a9a..cb07dcb12 100644 --- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm +++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm @@ -11,7 +11,6 @@ const Cu = Components.utils; this.EXPORTED_SYMBOLS = []; Cu.import("resource://gre/modules/AddonManager.jsm"); -/* globals AddonManagerPrivate*/ Cu.import("resource://gre/modules/Services.jsm"); const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties"; @@ -28,7 +27,8 @@ var logger = Log.repository.getLogger(LOGGER_ID); function getIDHashForString(aStr) { // return the two-digit hexadecimal code for a byte - let toHexString = charCode => ("0" + charCode.toString(16)).slice(-2); + function toHexString(charCode) + ("0" + charCode.toString(16)).slice(-2); let hasher = Cc["@mozilla.org/security/hash;1"]. createInstance(Ci.nsICryptoHash); @@ -40,8 +40,16 @@ function getIDHashForString(aStr) { // convert the binary hash data to a hex string. let binary = hasher.finish(false); - let hash = Array.from(binary, c => toHexString(c.charCodeAt(0))); + + // Tycho: let hash = [toHexString(binary.charCodeAt(i)) for (i in binary)].join("").toLowerCase(); + let hash = []; + + for (let i in binary) { + hash.push(toHexString(binary.charCodeAt(i))); + } + hash = hash.join("").toLowerCase(); + return "{" + hash.substr(0, 8) + "-" + hash.substr(8, 4) + "-" + hash.substr(12, 4) + "-" + @@ -50,14 +58,12 @@ function getIDHashForString(aStr) { } var PluginProvider = { - get name() { - return "PluginProvider"; - }, + get name() "PluginProvider", // A dictionary mapping IDs to names and descriptions plugins: null, - startup: function() { + startup: function PL_startup() { Services.obs.addObserver(this, LIST_UPDATED_TOPIC, false); Services.obs.addObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, false); }, @@ -66,7 +72,7 @@ var PluginProvider = { * Called when the application is shutting down. Only necessary for tests * to be able to simulate a shutdown. */ - shutdown: function() { + shutdown: function PL_shutdown() { this.plugins = null; Services.obs.removeObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED); Services.obs.removeObserver(this, LIST_UPDATED_TOPIC); @@ -75,7 +81,7 @@ var PluginProvider = { observe: function(aSubject, aTopic, aData) { switch (aTopic) { case AddonManager.OPTIONS_NOTIFICATION_DISPLAYED: - this.getAddonByID(aData, function(plugin) { + this.getAddonByID(aData, function PL_displayPluginInfo(plugin) { if (!plugin) return; @@ -85,7 +91,7 @@ var PluginProvider = { let typeLabel = aSubject.getElementById("pluginMimeTypes"), types = []; for (let type of plugin.pluginMimeTypes) { let extras = [type.description.trim(), type.suffixes]. - filter(x => x).join(": "); + filter(function(x) x).join(": "); types.push(type.type + (extras ? " (" + extras + ")" : "")); } typeLabel.textContent = types.join(",\n"); @@ -104,7 +110,7 @@ var PluginProvider = { /** * Creates a PluginWrapper for a plugin object. */ - buildWrapper: function(aPlugin) { + buildWrapper: function PL_buildWrapper(aPlugin) { return new PluginWrapper(aPlugin.id, aPlugin.name, aPlugin.description, @@ -119,7 +125,7 @@ var PluginProvider = { * @param aCallback * A callback to pass the Addon to */ - getAddonByID: function(aId, aCallback) { + getAddonByID: function PL_getAddon(aId, aCallback) { if (!this.plugins) this.buildPluginList(); @@ -137,7 +143,7 @@ var PluginProvider = { * @param callback * A callback to pass an array of Addons to */ - getAddonsByTypes: function(aTypes, aCallback) { + getAddonsByTypes: function PL_getAddonsByTypes(aTypes, aCallback) { if (aTypes && aTypes.indexOf("plugin") < 0) { aCallback([]); return; @@ -148,8 +154,11 @@ var PluginProvider = { let results = []; - for (let id in this.plugins) - this.getAddonByID(id, (addon) => results.push(addon)); + for (let id in this.plugins) { + this.getAddonByID(id, function(aAddon) { + results.push(aAddon); + }); + } aCallback(results); }, @@ -162,7 +171,7 @@ var PluginProvider = { * @param aCallback * A callback to pass an array of Addons to */ - getAddonsWithOperationsByTypes: function(aTypes, aCallback) { + getAddonsWithOperationsByTypes: function PL_getAddonsWithOperationsByTypes(aTypes, aCallback) { aCallback([]); }, @@ -174,7 +183,7 @@ var PluginProvider = { * @param aCallback * A callback to pass the array of AddonInstalls to */ - getInstallsByTypes: function(aTypes, aCallback) { + getInstallsByTypes: function PL_getInstallsByTypes(aTypes, aCallback) { aCallback([]); }, @@ -183,7 +192,7 @@ var PluginProvider = { * * @return a dictionary of plugins indexed by our generated ID */ - getPluginList: function() { + getPluginList: function PL_getPluginList() { let tags = Cc["@mozilla.org/plugin/host;1"]. getService(Ci.nsIPluginHost). getPluginTags({}); @@ -196,7 +205,8 @@ var PluginProvider = { if (!(tag.description in seenPlugins[tag.name])) { let plugin = { id: getIDHashForString(tag.name + tag.description), - name: tag.name, + // XXX Flash name substitution like in browser-plugins.js, aboutPermissions.js, permissions.js + name: tag.name == "Shockwave Flash" ? "Adobe Flash" : tag.name, description: tag.description, tags: [tag] }; @@ -215,7 +225,7 @@ var PluginProvider = { /** * Builds the list of known plugins from the plugin host */ - buildPluginList: function() { + buildPluginList: function PL_buildPluginList() { this.plugins = this.getPluginList(); }, @@ -224,14 +234,40 @@ var PluginProvider = { * to the last known list sending out any necessary API notifications for * changes. */ - updatePluginList: function() { + updatePluginList: function PL_updatePluginList() { let newList = this.getPluginList(); - let lostPlugins = Object.keys(this.plugins).filter(id => !(id in newList)). - map(id => this.buildWrapper(this.plugins[id])); - let newPlugins = Object.keys(newList).filter(id => !(id in this.plugins)). - map(id => this.buildWrapper(newList[id])); - let matchedIDs = Object.keys(newList).filter(id => id in this.plugins); + // Tycho: + // let lostPlugins = [this.buildWrapper(this.plugins[id]) + // for each (id in Object.keys(this.plugins)) if (!(id in newList))]; + + // let newPlugins = [this.buildWrapper(newList[id]) + // for each (id in Object.keys(newList)) if (!(id in this.plugins))]; + + // let matchedIDs = [id for each (id in Object.keys(newList)) if (id in this.plugins)]; + + let lostPlugins = []; + let newPlugins = []; + let matchedIDs = []; + + // lostPlugins + for each(let id in Object.keys(this.plugins)) { + if (!(id in newList)) { + lostPlugins.push(this.buildWrapper(this.plugins[id])); + } + } + + // newPlugins and matchedIDs + for each(let id in Object.keys(newList)) { + if (!(id in this.plugins)) { + newPlugins.push(this.buildWrapper(newList[id])); + } + + if (id in this.plugins) { + matchedIDs.push(id); + } + } + // The plugin host generates new tags for every plugin after a scan and // if the plugin's filename has changed then the disabled state won't have @@ -293,99 +329,63 @@ function canDisableFlashProtectedMode(aPlugin) { return isFlashPlugin(aPlugin) && Services.appinfo.XPCOMABI == "x86-msvc"; } -const wrapperMap = new WeakMap(); -let pluginFor = wrapper => wrapperMap.get(wrapper); - /** * The PluginWrapper wraps a set of nsIPluginTags to provide the data visible to * public callers through the API. */ -function PluginWrapper(id, name, description, tags) { - wrapperMap.set(this, { id, name, description, tags }); -} - -PluginWrapper.prototype = { - get id() { - return pluginFor(this).id; - }, - - get type() { - return "plugin"; - }, - - get name() { - return pluginFor(this).name; - }, - - get creator() { - return null; - }, - - get description() { - return pluginFor(this).description.replace(/<\/?[a-z][^>]*>/gi, " "); - }, - - get version() { - let { tags: [tag] } = pluginFor(this); - return tag.version; - }, - - get homepageURL() { - let { description } = pluginFor(this); - if (/<A\s+HREF=[^>]*>/i.test(description)) - return /<A\s+HREF=["']?([^>"'\s]*)/i.exec(description)[1]; - return null; - }, - - get isActive() { - let { tags: [tag] } = pluginFor(this); - return !tag.blocklisted && !tag.disabled; - }, - - get appDisabled() { - let { tags: [tag] } = pluginFor(this); - return tag.blocklisted; - }, - - get userDisabled() { - let { tags: [tag] } = pluginFor(this); - if (tag.disabled) +function PluginWrapper(aId, aName, aDescription, aTags) { + let safedesc = aDescription.replace(/<\/?[a-z][^>]*>/gi, " "); + let homepageURL = null; + if (/<A\s+HREF=[^>]*>/i.test(aDescription)) + homepageURL = /<A\s+HREF=["']?([^>"'\s]*)/i.exec(aDescription)[1]; + + this.__defineGetter__("id", function() aId); + this.__defineGetter__("type", function() "plugin"); + this.__defineGetter__("name", function() aName); + this.__defineGetter__("creator", function() null); + this.__defineGetter__("description", function() safedesc); + this.__defineGetter__("version", function() aTags[0].version); + this.__defineGetter__("homepageURL", function() homepageURL); + + this.__defineGetter__("isActive", function() !aTags[0].blocklisted && !aTags[0].disabled); + this.__defineGetter__("appDisabled", function() aTags[0].blocklisted); + + this.__defineGetter__("userDisabled", function() { + if (aTags[0].disabled) return true; - if ((Services.prefs.getBoolPref("plugins.click_to_play") && tag.clicktoplay) || + if ((Services.prefs.getBoolPref("plugins.click_to_play") && aTags[0].clicktoplay) || this.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE || this.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE) return AddonManager.STATE_ASK_TO_ACTIVATE; return false; - }, + }); - set userDisabled(val) { + this.__defineSetter__("userDisabled", function(aVal) { let previousVal = this.userDisabled; - if (val === previousVal) - return val; + if (aVal === previousVal) + return aVal; - let { tags } = pluginFor(this); - - for (let tag of tags) { - if (val === true) + for (let tag of aTags) { + if (aVal === true) tag.enabledState = Ci.nsIPluginTag.STATE_DISABLED; - else if (val === false) + else if (aVal === false) tag.enabledState = Ci.nsIPluginTag.STATE_ENABLED; - else if (val == AddonManager.STATE_ASK_TO_ACTIVATE) + else if (aVal == AddonManager.STATE_ASK_TO_ACTIVATE) tag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; } // If 'userDisabled' was 'true' and we're going to a state that's not // that, we're enabling, so call those listeners. - if (previousVal === true && val !== true) { + if (previousVal === true && aVal !== true) { AddonManagerPrivate.callAddonListeners("onEnabling", this, false); AddonManagerPrivate.callAddonListeners("onEnabled", this); } // If 'userDisabled' was not 'true' and we're going to a state where // it is, we're disabling, so call those listeners. - if (previousVal !== true && val === true) { + if (previousVal !== true && aVal === true) { AddonManagerPrivate.callAddonListeners("onDisabling", this, false); AddonManagerPrivate.callAddonListeners("onDisabled", this); } @@ -393,28 +393,27 @@ PluginWrapper.prototype = { // If the 'userDisabled' value involved AddonManager.STATE_ASK_TO_ACTIVATE, // call the onPropertyChanged listeners. if (previousVal == AddonManager.STATE_ASK_TO_ACTIVATE || - val == AddonManager.STATE_ASK_TO_ACTIVATE) { + aVal == AddonManager.STATE_ASK_TO_ACTIVATE) { AddonManagerPrivate.callAddonListeners("onPropertyChanged", this, ["userDisabled"]); } - return val; - }, + return aVal; + }); - get blocklistState() { - let { tags: [tag] } = pluginFor(this); + + this.__defineGetter__("blocklistState", function() { let bs = Cc["@mozilla.org/extensions/blocklist;1"]. getService(Ci.nsIBlocklistService); - return bs.getPluginBlocklistState(tag); - }, + return bs.getPluginBlocklistState(aTags[0]); + }); - get blocklistURL() { - let { tags: [tag] } = pluginFor(this); + this.__defineGetter__("blocklistURL", function() { let bs = Cc["@mozilla.org/extensions/blocklist;1"]. getService(Ci.nsIBlocklistService); - return bs.getPluginBlocklistURL(tag); - }, + return bs.getPluginBlocklistURL(aTags[0]); + }); - get size() { + this.__defineGetter__("size", function() { function getDirectorySize(aFile) { let size = 0; let entries = aFile.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator); @@ -431,7 +430,7 @@ PluginWrapper.prototype = { let size = 0; let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - for (let tag of pluginFor(this).tags) { + for (let tag of aTags) { file.initWithPath(tag.fullpath); if (file.isDirectory()) size += getDirectorySize(file); @@ -439,25 +438,25 @@ PluginWrapper.prototype = { size += file.fileSize; } return size; - }, + }); - get pluginLibraries() { + this.__defineGetter__("pluginLibraries", function() { let libs = []; - for (let tag of pluginFor(this).tags) + for (let tag of aTags) libs.push(tag.filename); return libs; - }, + }); - get pluginFullpath() { + this.__defineGetter__("pluginFullpath", function() { let paths = []; - for (let tag of pluginFor(this).tags) + for (let tag of aTags) paths.push(tag.fullpath); return paths; - }, + }) - get pluginMimeTypes() { + this.__defineGetter__("pluginMimeTypes", function() { let types = []; - for (let tag of pluginFor(this).tags) { + for (let tag of aTags) { let mimeTypes = tag.getMimeTypes({}); let mimeDescriptions = tag.getMimeDescriptions({}); let extensions = tag.getExtensions({}); @@ -471,19 +470,18 @@ PluginWrapper.prototype = { } } return types; - }, + }); - get installDate() { + this.__defineGetter__("installDate", function() { let date = 0; - for (let tag of pluginFor(this).tags) { + for (let tag of aTags) { date = Math.max(date, tag.lastModifiedTime); } return new Date(date); - }, + }); - get scope() { - let { tags: [tag] } = pluginFor(this); - let path = tag.fullpath; + this.__defineGetter__("scope", function() { + let path = aTags[0].fullpath; // Plugins inside the application directory are in the application scope let dir = Services.dirsvc.get("APlugns", Ci.nsIFile); if (path.startsWith(dir.path)) @@ -500,28 +498,25 @@ PluginWrapper.prototype = { dir = Services.dirsvc.get("Home", Ci.nsIFile); if (path.startsWith(dir.path)) return AddonManager.SCOPE_USER; - } catch (e) { - if (!e.result || e.result != Components.results.NS_ERROR_FAILURE) - throw e; + } catch (e if (e.result && e.result == Components.results.NS_ERROR_FAILURE)) { // Do nothing: missing "Home". } // Any other locations are system scope return AddonManager.SCOPE_SYSTEM; - }, + }); - get pendingOperations() { + this.__defineGetter__("pendingOperations", function() { return AddonManager.PENDING_NONE; - }, + }); - get operationsRequiringRestart() { + this.__defineGetter__("operationsRequiringRestart", function() { return AddonManager.OP_NEEDS_RESTART_NONE; - }, + }); - get permissions() { - let { tags: [tag] } = pluginFor(this); + this.__defineGetter__("permissions", function() { let permissions = 0; - if (tag.isEnabledStateLocked) { + if (aTags[0].isEnabledStateLocked) { return permissions; } if (!this.appDisabled) { @@ -545,18 +540,18 @@ PluginWrapper.prototype = { } } return permissions; - }, + }); - get optionsType() { + this.__defineGetter__("optionsType", function() { if (canDisableFlashProtectedMode(this)) { return AddonManager.OPTIONS_TYPE_INLINE; } return AddonManager.OPTIONS_TYPE_INLINE_INFO; - }, + }); +} - get optionsURL() { - return "chrome://mozapps/content/extensions/pluginPrefs.xul"; - }, +PluginWrapper.prototype = { + optionsURL: "chrome://mozapps/content/extensions/pluginPrefs.xul", get updateDate() { return this.installDate; @@ -578,7 +573,7 @@ PluginWrapper.prototype = { return true; }, - isCompatibleWith: function(aAppVersion, aPlatformVersion) { + isCompatibleWith: function(aAppVerison, aPlatformVersion) { return true; }, diff --git a/toolkit/mozapps/extensions/internal/ProductAddonChecker.jsm b/toolkit/mozapps/extensions/internal/ProductAddonChecker.jsm deleted file mode 100644 index f98dd2a94..000000000 --- a/toolkit/mozapps/extensions/internal/ProductAddonChecker.jsm +++ /dev/null @@ -1,467 +0,0 @@ -/* 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/. */ - -"use strict"; - -const { classes: Cc, interfaces: Ci, utils: Cu } = Components; - -const LOCAL_EME_SOURCES = [{ - "id": "gmp-eme-adobe", - "src": "chrome://global/content/gmp-sources/eme-adobe.json" -}, { - "id": "gmp-gmpopenh264", - "src": "chrome://global/content/gmp-sources/openh264.json" -}, { - "id": "gmp-widevinecdm", - "src": "chrome://global/content/gmp-sources/widevinecdm.json" -}]; - -this.EXPORTED_SYMBOLS = [ "ProductAddonChecker" ]; - -Cu.importGlobalProperties(["XMLHttpRequest"]); - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/Task.jsm"); -Cu.import("resource://gre/modules/Log.jsm"); -Cu.import("resource://gre/modules/CertUtils.jsm"); -/* globals checkCert, BadCertHandler*/ -Cu.import("resource://gre/modules/FileUtils.jsm"); -Cu.import("resource://gre/modules/NetUtil.jsm"); -Cu.import("resource://gre/modules/osfile.jsm"); - -/* globals GMPPrefs */ -XPCOMUtils.defineLazyModuleGetter(this, "GMPPrefs", - "resource://gre/modules/GMPUtils.jsm"); - -/* globals OS */ - -XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils", - "resource://gre/modules/UpdateUtils.jsm"); - -XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest", - "resource://gre/modules/ServiceRequest.jsm"); - -// This exists so that tests can override the XHR behaviour for downloading -// the addon update XML file. -var CreateXHR = function() { - return Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. - createInstance(Ci.nsISupports); -} - -var logger = Log.repository.getLogger("addons.productaddons"); - -/** - * Number of milliseconds after which we need to cancel `downloadXML`. - * - * Bug 1087674 suggests that the XHR we use in `downloadXML` may - * never terminate in presence of network nuisances (e.g. strange - * antivirus behavior). This timeout is a defensive measure to ensure - * that we fail cleanly in such case. - */ -const TIMEOUT_DELAY_MS = 20000; -// Chunk size for the incremental downloader -const DOWNLOAD_CHUNK_BYTES_SIZE = 300000; -// Incremental downloader interval -const DOWNLOAD_INTERVAL = 0; -// How much of a file to read into memory at a time for hashing -const HASH_CHUNK_SIZE = 8192; - -/** - * Gets the status of an XMLHttpRequest either directly or from its underlying - * channel. - * - * @param request - * The XMLHttpRequest. - * @return an integer status value. - */ -function getRequestStatus(request) { - let status = null; - try { - status = request.status; - } - catch (e) { - } - - if (status != null) { - return status; - } - - return request.channel.QueryInterface(Ci.nsIRequest).status; -} - -/** - * Downloads an XML document from a URL optionally testing the SSL certificate - * for certain attributes. - * - * @param url - * The url to download from. - * @param allowNonBuiltIn - * Whether to trust SSL certificates without a built-in CA issuer. - * @param allowedCerts - * The list of certificate attributes to match the SSL certificate - * against or null to skip checks. - * @return a promise that resolves to the DOM document downloaded or rejects - * with a JS exception in case of error. - */ -function downloadXML(url, allowNonBuiltIn = false, allowedCerts = null) { - return new Promise((resolve, reject) => { - let request = CreateXHR(); - // This is here to let unit test code override XHR - if (request.wrappedJSObject) { - request = request.wrappedJSObject; - } - request.open("GET", url, true); - request.channel.notificationCallbacks = new BadCertHandler(allowNonBuiltIn); - // Prevent the request from reading from the cache. - request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE; - // Prevent the request from writing to the cache. - request.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING; - // Use conservative TLS settings. See bug 1325501. - // TODO move to ServiceRequest. - if (request.channel instanceof Ci.nsIHttpChannelInternal) { - request.channel.QueryInterface(Ci.nsIHttpChannelInternal).beConservative = true; - } - request.timeout = TIMEOUT_DELAY_MS; - - request.overrideMimeType("text/xml"); - // The Cache-Control header is only interpreted by proxies and the - // final destination. It does not help if a resource is already - // cached locally. - request.setRequestHeader("Cache-Control", "no-cache"); - // HTTP/1.0 servers might not implement Cache-Control and - // might only implement Pragma: no-cache - request.setRequestHeader("Pragma", "no-cache"); - - let fail = (event) => { - let request = event.target; - let status = getRequestStatus(request); - let message = "Failed downloading XML, status: " + status + ", reason: " + event.type; - logger.warn(message); - let ex = new Error(message); - ex.status = status; - reject(ex); - }; - - let success = (event) => { - logger.info("Completed downloading document"); - let request = event.target; - - try { - checkCert(request.channel, allowNonBuiltIn, allowedCerts); - } catch (ex) { - logger.error("Request failed certificate checks: " + ex); - ex.status = getRequestStatus(request); - reject(ex); - return; - } - - resolve(request.responseXML); - }; - - request.addEventListener("error", fail, false); - request.addEventListener("abort", fail, false); - request.addEventListener("timeout", fail, false); - request.addEventListener("load", success, false); - - logger.info("sending request to: " + url); - request.send(null); - }); -} - -function downloadJSON(uri) { - logger.info("fetching config from: " + uri); - return new Promise((resolve, reject) => { - let xmlHttp = new ServiceRequest({mozAnon: true}); - - xmlHttp.onload = function(aResponse) { - resolve(JSON.parse(this.responseText)); - }; - - xmlHttp.onerror = function(e) { - reject("Fetching " + uri + " results in error code: " + e.target.status); - }; - - xmlHttp.open("GET", uri); - xmlHttp.overrideMimeType("application/json"); - xmlHttp.send(); - }); -} - - -/** - * Parses a list of add-ons from a DOM document. - * - * @param document - * The DOM document to parse. - * @return null if there is no <addons> element otherwise an object containing - * an array of the addons listed and a field notifying whether the - * fallback was used. - */ -function parseXML(document) { - // Check that the root element is correct - if (document.documentElement.localName != "updates") { - throw new Error("got node name: " + document.documentElement.localName + - ", expected: updates"); - } - - // Check if there are any addons elements in the updates element - let addons = document.querySelector("updates:root > addons"); - if (!addons) { - return null; - } - - let results = []; - let addonList = document.querySelectorAll("updates:root > addons > addon"); - for (let addonElement of addonList) { - let addon = {}; - - for (let name of ["id", "URL", "hashFunction", "hashValue", "version", "size"]) { - if (addonElement.hasAttribute(name)) { - addon[name] = addonElement.getAttribute(name); - } - } - addon.size = Number(addon.size) || undefined; - - results.push(addon); - } - - return { - usedFallback: false, - gmpAddons: results - }; -} - -/** - * If downloading from the network fails (AUS server is down), - * load the sources from local build configuration. - */ -function downloadLocalConfig() { - - if (!GMPPrefs.get(GMPPrefs.KEY_UPDATE_ENABLED, true)) { - logger.info("Updates are disabled via media.gmp-manager.updateEnabled"); - return Promise.resolve({usedFallback: true, gmpAddons: []}); - } - - return Promise.all(LOCAL_EME_SOURCES.map(conf => { - return downloadJSON(conf.src).then(addons => { - - let platforms = addons.vendors[conf.id].platforms; - let target = Services.appinfo.OS + "_" + UpdateUtils.ABI; - let details = null; - - while (!details) { - if (!(target in platforms)) { - // There was no matching platform so return false, this addon - // will be filtered from the results below - logger.info("no details found for: " + target); - return false; - } - // Field either has the details of the binary or is an alias - // to another build target key that does - if (platforms[target].alias) { - target = platforms[target].alias; - } else { - details = platforms[target]; - } - } - - logger.info("found plugin: " + conf.id); - return { - "id": conf.id, - "URL": details.fileUrl, - "hashFunction": addons.hashFunction, - "hashValue": details.hashValue, - "version": addons.vendors[conf.id].version, - "size": details.filesize - }; - }); - })).then(addons => { - - // Some filters may not match this platform so - // filter those out - addons = addons.filter(x => x !== false); - - return { - usedFallback: true, - gmpAddons: addons - }; - }); -} - -/** - * Downloads file from a URL using XHR. - * - * @param url - * The url to download from. - * @return a promise that resolves to the path of a temporary file or rejects - * with a JS exception in case of error. - */ -function downloadFile(url) { - return new Promise((resolve, reject) => { - let xhr = new XMLHttpRequest(); - xhr.onload = function(response) { - logger.info("downloadXHR File download. status=" + xhr.status); - if (xhr.status != 200 && xhr.status != 206) { - reject(Components.Exception("File download failed", xhr.status)); - return; - } - Task.spawn(function* () { - let f = yield OS.File.openUnique(OS.Path.join(OS.Constants.Path.tmpDir, "tmpaddon")); - let path = f.path; - logger.info(`Downloaded file will be saved to ${path}`); - yield f.file.close(); - yield OS.File.writeAtomic(path, new Uint8Array(xhr.response)); - return path; - }).then(resolve, reject); - }; - - let fail = (event) => { - let request = event.target; - let status = getRequestStatus(request); - let message = "Failed downloading via XHR, status: " + status + ", reason: " + event.type; - logger.warn(message); - let ex = new Error(message); - ex.status = status; - reject(ex); - }; - xhr.addEventListener("error", fail); - xhr.addEventListener("abort", fail); - - xhr.responseType = "arraybuffer"; - try { - xhr.open("GET", url); - // Use conservative TLS settings. See bug 1325501. - // TODO move to ServiceRequest. - if (xhr.channel instanceof Ci.nsIHttpChannelInternal) { - xhr.channel.QueryInterface(Ci.nsIHttpChannelInternal).beConservative = true; - } - xhr.send(null); - } catch (ex) { - reject(ex); - } - }); -} - -/** - * Convert a string containing binary values to hex. - */ -function binaryToHex(input) { - let result = ""; - for (let i = 0; i < input.length; ++i) { - let hex = input.charCodeAt(i).toString(16); - if (hex.length == 1) { - hex = "0" + hex; - } - result += hex; - } - return result; -} - -/** - * Calculates the hash of a file. - * - * @param hashFunction - * The type of hash function to use, must be supported by nsICryptoHash. - * @param path - * The path of the file to hash. - * @return a promise that resolves to hash of the file or rejects with a JS - * exception in case of error. - */ -var computeHash = Task.async(function*(hashFunction, path) { - let file = yield OS.File.open(path, { existing: true, read: true }); - try { - let hasher = Cc["@mozilla.org/security/hash;1"]. - createInstance(Ci.nsICryptoHash); - hasher.initWithString(hashFunction); - - let bytes; - do { - bytes = yield file.read(HASH_CHUNK_SIZE); - hasher.update(bytes, bytes.length); - } while (bytes.length == HASH_CHUNK_SIZE); - - return binaryToHex(hasher.finish(false)); - } - finally { - yield file.close(); - } -}); - -/** - * Verifies that a downloaded file matches what was expected. - * - * @param properties - * The properties to check, `size` and `hashFunction` with `hashValue` - * are supported. Any properties missing won't be checked. - * @param path - * The path of the file to check. - * @return a promise that resolves if the file matched or rejects with a JS - * exception in case of error. - */ -var verifyFile = Task.async(function*(properties, path) { - if (properties.size !== undefined) { - let stat = yield OS.File.stat(path); - if (stat.size != properties.size) { - throw new Error("Downloaded file was " + stat.size + " bytes but expected " + properties.size + " bytes."); - } - } - - if (properties.hashFunction !== undefined) { - let expectedDigest = properties.hashValue.toLowerCase(); - let digest = yield computeHash(properties.hashFunction, path); - if (digest != expectedDigest) { - throw new Error("Hash was `" + digest + "` but expected `" + expectedDigest + "`."); - } - } -}); - -const ProductAddonChecker = { - /** - * Downloads a list of add-ons from a URL optionally testing the SSL - * certificate for certain attributes. - * - * @param url - * The url to download from. - * @param allowNonBuiltIn - * Whether to trust SSL certificates without a built-in CA issuer. - * @param allowedCerts - * The list of certificate attributes to match the SSL certificate - * against or null to skip checks. - * @return a promise that resolves to an object containing the list of add-ons - * and whether the local fallback was used, or rejects with a JS - * exception in case of error. - */ - getProductAddonList: function(url, allowNonBuiltIn = false, allowedCerts = null) { - if (!GMPPrefs.get(GMPPrefs.KEY_UPDATE_ENABLED, true)) { - logger.info("Updates are disabled via media.gmp-manager.updateEnabled"); - return Promise.resolve({usedFallback: true, gmpAddons: []}); - } - - return downloadXML(url, allowNonBuiltIn, allowedCerts) - .then(parseXML) - .catch(downloadLocalConfig); - }, - - /** - * Downloads an add-on to a local file and checks that it matches the expected - * file. The caller is responsible for deleting the temporary file returned. - * - * @param addon - * The addon to download. - * @return a promise that resolves to the temporary file downloaded or rejects - * with a JS exception in case of error. - */ - downloadAddon: Task.async(function*(addon) { - let path = yield downloadFile(addon.URL); - try { - yield verifyFile(addon, path); - return path; - } - catch (e) { - yield OS.File.remove(path); - throw e; - } - }) -} diff --git a/toolkit/mozapps/extensions/internal/WebExtensionBootstrap.js b/toolkit/mozapps/extensions/internal/WebExtensionBootstrap.js deleted file mode 100644 index a920c2eae..000000000 --- a/toolkit/mozapps/extensions/internal/WebExtensionBootstrap.js +++ /dev/null @@ -1,39 +0,0 @@ -/* 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/. */ - -"use strict"; - -Components.utils.import("resource://gre/modules/Extension.jsm"); - -var extension; - -const BOOTSTRAP_REASON_TO_STRING_MAP = { - 1: "APP_STARTUP", - 2: "APP_SHUTDOWN", - 3: "ADDON_ENABLE", - 4: "ADDON_DISABLE", - 5: "ADDON_INSTALL", - 6: "ADDON_UNINSTALL", - 7: "ADDON_UPGRADE", - 8: "ADDON_DOWNGRADE", -} - -function install(data, reason) -{ -} - -function startup(data, reason) -{ - extension = new Extension(data, BOOTSTRAP_REASON_TO_STRING_MAP[reason]); - extension.startup(); -} - -function shutdown(data, reason) -{ - extension.shutdown(); -} - -function uninstall(data, reason) -{ -} diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index 87e09cef1..8b49c6600 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -1,4 +1,4 @@ - /* This Source Code Form is subject to the terms of the Mozilla Public +/* 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/. */ @@ -11,14 +11,10 @@ const Cu = Components.utils; this.EXPORTED_SYMBOLS = ["XPIProvider"]; -const CONSTANTS = {}; -Cu.import("resource://gre/modules/addons/AddonConstants.jsm", CONSTANTS); -const { ADDON_SIGNING, REQUIRE_SIGNING } = CONSTANTS - -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/AddonManager.jsm"); -Cu.import("resource://gre/modules/Preferences.jsm"); +Components.utils.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +Components.utils.import("resource://gre/modules/AddonManager.jsm"); +Components.utils.import("resource://gre/modules/Preferences.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository", "resource://gre/modules/addons/AddonRepository.jsm"); @@ -26,12 +22,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "ChromeManifestParser", "resource://gre/modules/ChromeManifestParser.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager", "resource://gre/modules/LightweightThemeManager.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "ExtensionData", - "resource://gre/modules/Extension.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "ExtensionManagement", - "resource://gre/modules/ExtensionManagement.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "Locale", - "resource://gre/modules/Locale.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "ZipUtils", @@ -50,16 +40,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "BrowserToolboxProcess", "resource://devtools/client/framework/ToolboxProcess.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "ConsoleAPI", "resource://gre/modules/Console.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "ProductAddonChecker", - "resource://gre/modules/addons/ProductAddonChecker.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils", - "resource://gre/modules/UpdateUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "AppConstants", - "resource://gre/modules/AppConstants.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "isAddonPartOfE10SRollout", - "resource://gre/modules/addons/E10SAddonsRollout.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "LegacyExtensionsUtils", - "resource://gre/modules/LegacyExtensionsUtils.jsm"); XPCOMUtils.defineLazyServiceGetter(this, "Blocklist", "@mozilla.org/extensions/blocklist;1", @@ -73,22 +53,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "@mozilla.org/network/protocol;1?name=resource", "nsIResProtocolHandler"); XPCOMUtils.defineLazyServiceGetter(this, - "AddonPolicyService", - "@mozilla.org/addons/policy-service;1", - "nsIAddonPolicyService"); -XPCOMUtils.defineLazyServiceGetter(this, "AddonPathService", "@mozilla.org/addon-path-service;1", "amIAddonPathService"); -XPCOMUtils.defineLazyGetter(this, "CertUtils", function() { - let certUtils = {}; - Components.utils.import("resource://gre/modules/CertUtils.jsm", certUtils); - return certUtils; -}); - -Cu.importGlobalProperties(["URL"]); - const nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile", "initWithPath"); @@ -97,6 +65,8 @@ const PREF_INSTALL_CACHE = "extensions.installCache"; const PREF_XPI_STATE = "extensions.xpiState"; const PREF_BOOTSTRAP_ADDONS = "extensions.bootstrappedAddons"; const PREF_PENDING_OPERATIONS = "extensions.pendingOperations"; +const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; +const PREF_SELECTED_LOCALE = "general.useragent.locale"; const PREF_EM_DSS_ENABLED = "extensions.dss.enabled"; const PREF_DSS_SWITCHPENDING = "extensions.dss.switchPending"; const PREF_DSS_SKIN_TO_SELECT = "extensions.lastSelectedSkin"; @@ -106,67 +76,53 @@ const PREF_EM_UPDATE_BACKGROUND_URL = "extensions.update.background.url"; const PREF_EM_ENABLED_ADDONS = "extensions.enabledAddons"; const PREF_EM_EXTENSION_FORMAT = "extensions."; const PREF_EM_ENABLED_SCOPES = "extensions.enabledScopes"; +const PREF_EM_AUTO_DISABLED_SCOPES = "extensions.autoDisableScopes"; const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI"; const PREF_XPI_ENABLED = "xpinstall.enabled"; const PREF_XPI_WHITELIST_REQUIRED = "xpinstall.whitelist.required"; const PREF_XPI_DIRECT_WHITELISTED = "xpinstall.whitelist.directRequest"; const PREF_XPI_FILE_WHITELISTED = "xpinstall.whitelist.fileRequest"; -// xpinstall.signatures.required only supported in dev builds -const PREF_XPI_SIGNATURES_REQUIRED = "xpinstall.signatures.required"; -const PREF_XPI_SIGNATURES_DEV_ROOT = "xpinstall.signatures.dev-root"; const PREF_XPI_PERMISSIONS_BRANCH = "xpinstall."; const PREF_XPI_UNPACK = "extensions.alwaysUnpack"; const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts"; const PREF_INSTALL_REQUIRESECUREORIGIN = "extensions.install.requireSecureOrigin"; const PREF_INSTALL_DISTRO_ADDONS = "extensions.installDistroAddons"; const PREF_BRANCH_INSTALLED_ADDON = "extensions.installedDistroAddon."; +const PREF_SHOWN_SELECTION_UI = "extensions.shownSelectionUI"; const PREF_INTERPOSITION_ENABLED = "extensions.interposition.enabled"; -const PREF_SYSTEM_ADDON_SET = "extensions.systemAddonSet"; -const PREF_SYSTEM_ADDON_UPDATE_URL = "extensions.systemAddon.update.url"; -const PREF_E10S_BLOCK_ENABLE = "extensions.e10sBlocksEnabling"; -const PREF_E10S_ADDON_BLOCKLIST = "extensions.e10s.rollout.blocklist"; -const PREF_E10S_ADDON_POLICY = "extensions.e10s.rollout.policy"; -const PREF_E10S_HAS_NONEXEMPT_ADDON = "extensions.e10s.rollout.hasAddon"; const PREF_EM_MIN_COMPAT_APP_VERSION = "extensions.minCompatibleAppVersion"; const PREF_EM_MIN_COMPAT_PLATFORM_VERSION = "extensions.minCompatiblePlatformVersion"; const PREF_CHECKCOMAT_THEMEOVERRIDE = "extensions.checkCompatibility.temporaryThemeOverride_minAppVersion"; -const PREF_EM_HOTFIX_ID = "extensions.hotfix.id"; -const PREF_EM_CERT_CHECKATTRIBUTES = "extensions.hotfix.cert.checkAttributes"; -const PREF_EM_HOTFIX_CERTS = "extensions.hotfix.certs."; - +const URI_EXTENSION_SELECT_DIALOG = "chrome://mozapps/content/extensions/selectAddons.xul"; const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul"; const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties"; const STRING_TYPE_NAME = "type.%ID%.name"; const DIR_EXTENSIONS = "extensions"; -const DIR_SYSTEM_ADDONS = "features"; const DIR_STAGE = "staged"; +const DIR_XPI_STAGE = "staged-xpis"; const DIR_TRASH = "trash"; const FILE_DATABASE = "extensions.json"; const FILE_OLD_CACHE = "extensions.cache"; -const FILE_RDF_MANIFEST = "install.rdf"; -const FILE_WEB_MANIFEST = "manifest.json"; +const FILE_INSTALL_MANIFEST = "install.rdf"; +const FILE_WEBEXT_MANIFEST = "manifest.json"; const FILE_XPI_ADDONS_LIST = "extensions.ini"; const KEY_PROFILEDIR = "ProfD"; -const KEY_ADDON_APP_DIR = "XREAddonAppDir"; +const KEY_APPDIR = "XCurProcD"; const KEY_TEMPDIR = "TmpD"; const KEY_APP_DISTRIBUTION = "XREAppDist"; -const KEY_APP_FEATURES = "XREAppFeat"; const KEY_APP_PROFILE = "app-profile"; -const KEY_APP_SYSTEM_ADDONS = "app-system-addons"; -const KEY_APP_SYSTEM_DEFAULTS = "app-system-defaults"; const KEY_APP_GLOBAL = "app-global"; const KEY_APP_SYSTEM_LOCAL = "app-system-local"; const KEY_APP_SYSTEM_SHARE = "app-system-share"; const KEY_APP_SYSTEM_USER = "app-system-user"; -const KEY_APP_TEMPORARY = "app-temporary"; const NOTIFICATION_FLUSH_PERMISSIONS = "flush-pending-permissions"; const XPI_PERMISSION = "install"; @@ -175,11 +131,13 @@ const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest"; const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#"; const TOOLKIT_ID = "toolkit@mozilla.org"; +#ifdef MOZ_PHOENIX_EXTENSIONS +const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" +const FIREFOX_APPCOMPATVERSION = "56.9" +#endif -const XPI_SIGNATURE_CHECK_PERIOD = 24 * 60 * 60; - -XPCOMUtils.defineConstant(this, "DB_SCHEMA", 19); - +// The value for this is in Makefile.in +#expand const DB_SCHEMA = __MOZ_EXTENSIONS_DB_SCHEMA__; const NOTIFICATION_TOOLBOXPROCESS_LOADED = "ToolboxProcessLoaded"; // Properties that exist in the install manifest @@ -190,6 +148,12 @@ const PROP_LOCALE_SINGLE = ["name", "description", "creator", "homepageURL"]; const PROP_LOCALE_MULTI = ["developers", "translators", "contributors"]; const PROP_TARGETAPP = ["id", "minVersion", "maxVersion"]; +// Properties that should be migrated where possible from an old database. These +// shouldn't include properties that can be read directly from install.rdf files +// or calculated +const DB_MIGRATE_METADATA= ["installDate", "userDisabled", "softDisabled", + "sourceURI", "applyBackgroundUpdates", + "releaseNotesURI", "foreignInstall", "syncGUID"]; // Properties to cache and reload when an addon installation is pending const PENDING_INSTALL_METADATA = ["syncGUID", "targetApplications", "userDisabled", "softDisabled", @@ -229,51 +193,12 @@ const TYPES = { experiment: 128, }; -if (!AppConstants.RELEASE_OR_BETA) - TYPES.apiextension = 256; - -// Some add-on types that we track internally are presented as other types -// externally -const TYPE_ALIASES = { - "webextension": "extension", - "apiextension": "extension", -}; - -const CHROME_TYPES = new Set([ - "extension", - "locale", - "experiment", -]); - const RESTARTLESS_TYPES = new Set([ - "webextension", "dictionary", "experiment", "locale", - "apiextension", ]); -const SIGNED_TYPES = new Set([ - "webextension", - "extension", - "experiment", - "apiextension", -]); - -// This is a random number array that can be used as "salt" when generating -// an automatic ID based on the directory path of an add-on. It will prevent -// someone from creating an ID for a permanent add-on that could be replaced -// by a temporary add-on (because that would be confusing, I guess). -const TEMP_INSTALL_ID_GEN_SESSION = - new Uint8Array(Float64Array.of(Math.random()).buffer); - -// Whether add-on signing is required. -function mustSign(aType) { - if (!SIGNED_TYPES.has(aType)) - return false; - return REQUIRE_SIGNING || Preferences.get(PREF_XPI_SIGNATURES_REQUIRED, false); -} - // Keep track of where we are in startup for telemetry // event happened during XPIDatabase.startup() const XPI_STARTING = "XPIStarting"; @@ -288,7 +213,6 @@ const COMPATIBLE_BY_DEFAULT_TYPES = { }; const MSG_JAR_FLUSH = "AddonJarFlush"; -const MSG_MESSAGE_MANAGER_CACHES_FLUSH = "AddonMessageManagerCachesFlush"; var gGlobalScope = this; @@ -304,38 +228,17 @@ const LOGGER_ID = "addons.xpi"; // (Requires AddonManager.jsm) var logger = Log.repository.getLogger(LOGGER_ID); -const LAZY_OBJECTS = ["XPIDatabase", "XPIDatabaseReconcile"]; -/* globals XPIDatabase, XPIDatabaseReconcile*/ +const LAZY_OBJECTS = ["XPIDatabase"]; var gLazyObjectsLoaded = false; function loadLazyObjects() { - let uri = "resource://gre/modules/addons/XPIProviderUtils.js"; - let scope = Cu.Sandbox(Services.scriptSecurityManager.getSystemPrincipal(), { - sandboxName: uri, - wantGlobalProperties: ["TextDecoder"], - }); - - let shared = { - ADDON_SIGNING, - SIGNED_TYPES, - BOOTSTRAP_REASONS, - DB_SCHEMA, - AddonInternal, - XPIProvider, - XPIStates, - syncLoadManifestFromFile, - isUsableAddon, - recordAddonTelemetry, - applyBlocklistChanges, - flushChromeCaches, - canRunInSafeMode, - } - - for (let key of Object.keys(shared)) - scope[key] = shared[key]; - - Services.scriptloader.loadSubScript(uri, scope); + let scope = {}; + scope.AddonInternal = AddonInternal; + scope.XPIProvider = XPIProvider; + scope.XPIStates = XPIStates; + Services.scriptloader.loadSubScript("resource://gre/modules/addons/XPIProviderUtils.js", + scope); for (let name of LAZY_OBJECTS) { delete gGlobalScope[name]; @@ -345,35 +248,17 @@ function loadLazyObjects() { return scope; } -LAZY_OBJECTS.forEach(name => { +for (let name of LAZY_OBJECTS) { Object.defineProperty(gGlobalScope, name, { - get: function() { + get: function lazyObjectGetter() { let objs = loadLazyObjects(); return objs[name]; }, configurable: true }); -}); - - -// Behaves like Promise.all except waits for all promises to resolve/reject -// before resolving/rejecting itself -function waitForAllPromises(promises) { - return new Promise((resolve, reject) => { - let shouldReject = false; - let rejectValue = null; - - let newPromises = promises.map( - p => p.catch(value => { - shouldReject = true; - rejectValue = value; - }) - ); - Promise.all(newPromises) - .then((results) => shouldReject ? reject(rejectValue) : resolve(results)); - }); } + function findMatchingStaticBlocklistItem(aAddon) { for (let item of STATIC_BLOCKLIST_PATTERNS) { if ("creator" in item && typeof item.creator == "string") { @@ -386,12 +271,6 @@ function findMatchingStaticBlocklistItem(aAddon) { return null; } -/** - * Converts an iterable of addon objects into a map with the add-on's ID as key. - */ -function addonMap(addons) { - return new Map(addons.map(a => [a.id, a])); -} /** * Sets permissions on a file @@ -412,33 +291,6 @@ function setFilePermissions(aFile, aPermissions) { } /** - * Write a given string to a file - * - * @param file - * The nsIFile instance to write into - * @param string - * The string to write - */ -function writeStringToFile(file, string) { - let stream = Cc["@mozilla.org/network/file-output-stream;1"]. - createInstance(Ci.nsIFileOutputStream); - let converter = Cc["@mozilla.org/intl/converter-output-stream;1"]. - createInstance(Ci.nsIConverterOutputStream); - - try { - stream.init(file, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | - FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, - 0); - converter.init(stream, "UTF-8", 0, 0x0000); - converter.writeString(string); - } - finally { - converter.close(); - stream.close(); - } -} - -/** * A safe way to install a file or the contents of a directory to a new * directory. The file or directory is moved or copied recursively and if * anything fails an attempt is made to rollback the entire operation. The @@ -457,22 +309,14 @@ SafeInstallOperation.prototype = { _installedFiles: null, _createdDirs: null, - _installFile: function(aFile, aTargetDirectory, aCopy) { + _installFile: function SIO_installFile(aFile, aTargetDirectory, aCopy) { let oldFile = aCopy ? null : aFile.clone(); let newFile = aFile.clone(); try { - if (aCopy) { + if (aCopy) newFile.copyTo(aTargetDirectory, null); - // copyTo does not update the nsIFile with the new. - newFile = aTargetDirectory.clone(); - newFile.append(aFile.leafName); - // Windows roaming profiles won't properly sync directories if a new file - // has an older lastModifiedTime than a previous file, so update. - newFile.lastModifiedTime = Date.now(); - } - else { + else newFile.moveTo(aTargetDirectory, null); - } } catch (e) { logger.error("Failed to " + (aCopy ? "copy" : "move") + " file " + aFile.path + @@ -482,13 +326,7 @@ SafeInstallOperation.prototype = { this._installedFiles.push({ oldFile: oldFile, newFile: newFile }); }, - _installDirectory: function(aDirectory, aTargetDirectory, aCopy) { - if (aDirectory.contains(aTargetDirectory)) { - let err = new Error(`Not installing ${aDirectory} into its own descendent ${aTargetDirectory}`); - logger.error(err); - throw err; - } - + _installDirectory: function SIO_installDirectory(aDirectory, aTargetDirectory, aCopy) { let newDir = aTargetDirectory.clone(); newDir.append(aDirectory.leafName); try { @@ -505,16 +343,16 @@ SafeInstallOperation.prototype = { // embedded filesystem has this issue, see bug 772238), and to remove // normal files before their resource forks on OSX (see bug 733436). let entries = getDirectoryEntries(aDirectory, true); - for (let entry of entries) { + entries.forEach(function(aEntry) { try { - this._installDirEntry(entry, newDir, aCopy); + this._installDirEntry(aEntry, newDir, aCopy); } catch (e) { logger.error("Failed to " + (aCopy ? "copy" : "move") + " entry " + - entry.path, e); + aEntry.path, e); throw e; } - } + }, this); // If this is only a copy operation then there is nothing else to do if (aCopy) @@ -536,11 +374,11 @@ SafeInstallOperation.prototype = { this._installedFiles.push({ oldFile: aDirectory, newFile: newDir }); }, - _installDirEntry: function(aDirEntry, aTargetDirectory, aCopy) { + _installDirEntry: function SIO_installDirEntry(aDirEntry, aTargetDirectory, aCopy) { let isDir = null; try { - isDir = aDirEntry.isDirectory() && !aDirEntry.isSymlink(); + isDir = aDirEntry.isDirectory(); } catch (e) { // If the file has already gone away then don't worry about it, this can @@ -577,7 +415,7 @@ SafeInstallOperation.prototype = { * The directory to move into, this is expected to be an empty * directory. */ - moveUnder: function(aFile, aTargetDirectory) { + moveUnder: function SIO_move(aFile, aTargetDirectory) { try { this._installDirEntry(aFile, aTargetDirectory, false); } @@ -602,7 +440,7 @@ SafeInstallOperation.prototype = { oldFile.moveTo(newFile.parent, newFile.leafName); this._installedFiles.push({ oldFile: oldFile, newFile: newFile, isMoveTo: true}); } - catch (e) { + catch(e) { this.rollback(); throw e; } @@ -618,7 +456,7 @@ SafeInstallOperation.prototype = { * The directory to copy into, this is expected to be an empty * directory. */ - copy: function(aFile, aTargetDirectory) { + copy: function SIO_copy(aFile, aTargetDirectory) { try { this._installDirEntry(aFile, aTargetDirectory, true); } @@ -633,13 +471,13 @@ SafeInstallOperation.prototype = { * occurs here then both old and new directories are left in an indeterminate * state */ - rollback: function() { + rollback: function SIO_rollback() { while (this._installedFiles.length > 0) { let move = this._installedFiles.pop(); if (move.isMoveTo) { - move.newFile.moveTo(move.oldDir.parent, move.oldDir.leafName); + move.newFile.moveTo(oldDir.parent, oldDir.leafName); } - else if (move.newFile.isDirectory() && !move.newFile.isSymlink()) { + else if (move.newFile.isDirectory()) { let oldDir = move.oldFile.parent.clone(); oldDir.append(move.oldFile.leafName); oldDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); @@ -659,6 +497,84 @@ SafeInstallOperation.prototype = { }; /** + * Gets the currently selected locale for display. + * @return the selected locale or "en-US" if none is selected + */ +function getLocale() { + if (Preferences.get(PREF_MATCH_OS_LOCALE, false)) + return Services.locale.getLocaleComponentForUserAgent(); + try { + let locale = Preferences.get(PREF_SELECTED_LOCALE, null, Ci.nsIPrefLocalizedString); + if (locale) + return locale; + } + catch (e) {} + return Preferences.get(PREF_SELECTED_LOCALE, "en-US"); +} + +/** + * Selects the closest matching locale from a list of locales. + * + * @param aLocales + * An array of locales + * @return the best match for the currently selected locale + */ +function findClosestLocale(aLocales) { + let appLocale = getLocale(); + + // Holds the best matching localized resource + var bestmatch = null; + // The number of locale parts it matched with + var bestmatchcount = 0; + // The number of locale parts in the match + var bestpartcount = 0; + + var matchLocales = [appLocale.toLowerCase()]; + /* If the current locale is English then it will find a match if there is + a valid match for en-US so no point searching that locale too. */ + if (matchLocales[0].substring(0, 3) != "en-") + matchLocales.push("en-us"); + + for each (var locale in matchLocales) { + var lparts = locale.split("-"); + for each (var localized in aLocales) { + for each (let found in localized.locales) { + found = found.toLowerCase(); + // Exact match is returned immediately + if (locale == found) + return localized; + + var fparts = found.split("-"); + /* If we have found a possible match and this one isn't any longer + then we dont need to check further. */ + if (bestmatch && fparts.length < bestmatchcount) + continue; + + // Count the number of parts that match + var maxmatchcount = Math.min(fparts.length, lparts.length); + var matchcount = 0; + while (matchcount < maxmatchcount && + fparts[matchcount] == lparts[matchcount]) + matchcount++; + + /* If we matched more than the last best match or matched the same and + this locale is less specific than the last best match. */ + if (matchcount > bestmatchcount || + (matchcount == bestmatchcount && fparts.length < bestpartcount)) { + bestmatch = localized; + bestmatchcount = matchcount; + bestpartcount = fparts.length; + } + } + } + // If we found a valid match for this locale return it + if (bestmatch) + return bestmatch; + } + return null; +} + +/** * Sets the userDisabled and softDisabled properties of an add-on based on what * values those properties had for a previous instance of the add-on. The * previous instance may be a previous install or in the case of an application @@ -684,10 +600,10 @@ function applyBlocklistChanges(aOldAddon, aNewAddon, aOldAppVersion, aNewAddon.userDisabled = aOldAddon.userDisabled; aNewAddon.softDisabled = aOldAddon.softDisabled; - let oldBlocklistState = Blocklist.getAddonBlocklistState(aOldAddon.wrapper, + let oldBlocklistState = Blocklist.getAddonBlocklistState(createWrapper(aOldAddon), aOldAppVersion, aOldPlatformVersion); - let newBlocklistState = Blocklist.getAddonBlocklistState(aNewAddon.wrapper); + let newBlocklistState = Blocklist.getAddonBlocklistState(createWrapper(aNewAddon)); // If the blocklist state hasn't changed then the properties don't need to // change @@ -712,27 +628,6 @@ function applyBlocklistChanges(aOldAddon, aNewAddon, aOldAppVersion, } /** - * Evaluates whether an add-on is allowed to run in safe mode. - * - * @param aAddon - * The add-on to check - * @return true if the add-on should run in safe mode - */ -function canRunInSafeMode(aAddon) { - // Even though the updated system add-ons aren't generally run in safe mode we - // include them here so their uninstall functions get called when switching - // back to the default set. - - // TODO product should make the call about temporary add-ons running - // in safe mode. assuming for now that they are. - if (aAddon._installLocation.name == KEY_APP_TEMPORARY) - return true; - - return aAddon._installLocation.name == KEY_APP_SYSTEM_DEFAULTS || - aAddon._installLocation.name == KEY_APP_SYSTEM_ADDONS; -} - -/** * Calculates whether an add-on should be appDisabled or not. * * @param aAddon @@ -744,59 +639,23 @@ function isUsableAddon(aAddon) { if (aAddon.type == "theme" && aAddon.internalName == XPIProvider.defaultSkin) return true; - if (mustSign(aAddon.type) && !aAddon.isCorrectlySigned) { - logger.warn(`Add-on ${aAddon.id} is not correctly signed.`); + if (aAddon.blocklistState == Blocklist.STATE_BLOCKED) return false; - } - if (aAddon.blocklistState == Blocklist.STATE_BLOCKED) { - logger.warn(`Add-on ${aAddon.id} is blocklisted.`); + if (AddonManager.checkUpdateSecurity && !aAddon.providesUpdatesSecurely) return false; - } - - // Experiments are installed through an external mechanism that - // limits target audience to compatible clients. We trust it knows what - // it's doing and skip compatibility checks. - // - // This decision does forfeit defense in depth. If the experiments system - // is ever wrong about targeting an add-on to a specific application - // or platform, the client will likely see errors. - if (aAddon.type == "experiment") - return true; - if (AddonManager.checkUpdateSecurity && !aAddon.providesUpdatesSecurely) { - logger.warn(`Updates for add-on ${aAddon.id} must be provided over HTTPS.`); + if (!aAddon.isPlatformCompatible) return false; - } - - - if (!aAddon.isPlatformCompatible) { - logger.warn(`Add-on ${aAddon.id} is not compatible with platform.`); - return false; - } - - if (aAddon.dependencies.length) { - let isActive = id => { - let active = XPIProvider.activeAddons.get(id); - return active && !active.disable; - }; - - if (aAddon.dependencies.some(id => !isActive(id))) - return false; - } if (AddonManager.checkCompatibility) { - if (!aAddon.isCompatible) { - logger.warn(`Add-on ${aAddon.id} is not compatible with application version.`); + if (!aAddon.isCompatible) return false; - } } else { let app = aAddon.matchingTargetApplication; - if (!app) { - logger.warn(`Add-on ${aAddon.id} is not compatible with target application.`); + if (!app) return false; - } // XXX Temporary solution to let applications opt-in to make themes safer // following significant UI changes even if checkCompatibility=false has @@ -806,7 +665,6 @@ function isUsableAddon(aAddon) { let minCompatVersion = Services.prefs.getCharPref(PREF_CHECKCOMAT_THEMEOVERRIDE); if (minCompatVersion && Services.vc.compare(minCompatVersion, app.maxVersion) > 0) { - logger.warn(`Theme ${aAddon.id} is not compatible with application version.`); return false; } } catch (e) {} @@ -827,75 +685,11 @@ function createAddonDetails(id, aAddon) { return { id: id || aAddon.id, type: aAddon.type, - version: aAddon.version, - multiprocessCompatible: aAddon.multiprocessCompatible, - mpcOptedOut: aAddon.mpcOptedOut, - runInSafeMode: aAddon.runInSafeMode, - dependencies: aAddon.dependencies, - hasEmbeddedWebExtension: aAddon.hasEmbeddedWebExtension, + version: aAddon.version }; } /** - * Converts an internal add-on type to the type presented through the API. - * - * @param aType - * The internal add-on type - * @return an external add-on type - */ -function getExternalType(aType) { - if (aType in TYPE_ALIASES) - return TYPE_ALIASES[aType]; - return aType; -} - -function getManifestFileForDir(aDir) { - let file = aDir.clone(); - file.append(FILE_RDF_MANIFEST); - if (file.exists() && file.isFile()) - return file; - file.leafName = FILE_WEB_MANIFEST; - if (file.exists() && file.isFile()) - return file; - return null; -} - -function getManifestEntryForZipReader(aZipReader) { - if (aZipReader.hasEntry(FILE_RDF_MANIFEST)) - return FILE_RDF_MANIFEST; - if (aZipReader.hasEntry(FILE_WEB_MANIFEST)) - return FILE_WEB_MANIFEST; - return null; -} - -/** - * Converts a list of API types to a list of API types and any aliases for those - * types. - * - * @param aTypes - * An array of types or null for all types - * @return an array of types or null for all types - */ -function getAllAliasesForTypes(aTypes) { - if (!aTypes) - return null; - - // Build a set of all requested types and their aliases - let typeset = new Set(aTypes); - - for (let alias of Object.keys(TYPE_ALIASES)) { - // Ignore any requested internal types - typeset.delete(alias); - - // Add any alias for the internal type - if (typeset.has(TYPE_ALIASES[alias])) - typeset.add(alias); - } - - return [...typeset]; -} - -/** * Converts an RDF literal, resource or integer into a string. * * @param aLiteral @@ -928,128 +722,6 @@ function getRDFProperty(aDs, aResource, aProperty) { } /** - * Reads an AddonInternal object from a manifest stream. - * - * @param aUri - * A |file:| or |jar:| URL for the manifest - * @return an AddonInternal object - * @throws if the install manifest in the stream is corrupt or could not - * be read - */ -var loadManifestFromWebManifest = Task.async(function*(aUri) { - // We're passed the URI for the manifest file. Get the URI for its - // parent directory. - let uri = NetUtil.newURI("./", null, aUri); - - let extension = new ExtensionData(uri); - - let manifest = yield extension.readManifest(); - - // Read the list of available locales, and pre-load messages for - // all locales. - let locales = yield extension.initAllLocales(); - - // If there were any errors loading the extension, bail out now. - if (extension.errors.length) - throw new Error("Extension is invalid"); - - let bss = (manifest.browser_specific_settings && manifest.browser_specific_settings.gecko) - || (manifest.applications && manifest.applications.gecko) || {}; - if (manifest.browser_specific_settings && manifest.applications) { - logger.warn("Ignoring applications property in manifest"); - } - - // A * is illegal in strict_min_version - if (bss.strict_min_version && bss.strict_min_version.split(".").some(part => part == "*")) { - throw new Error("The use of '*' in strict_min_version is invalid"); - } - - let addon = new AddonInternal(); - addon.id = bss.id; - addon.version = manifest.version; - addon.type = "webextension"; - addon.unpack = false; - addon.strictCompatibility = true; - addon.bootstrap = true; - addon.hasBinaryComponents = false; - addon.multiprocessCompatible = true; - addon.internalName = null; - addon.updateURL = bss.update_url; - addon.updateKey = null; - addon.optionsURL = null; - addon.optionsType = null; - addon.aboutURL = null; - addon.dependencies = Object.freeze(Array.from(extension.dependencies)); - - if (manifest.options_ui) { - // Store just the relative path here, the AddonWrapper getURL - // wrapper maps this to a full URL. - addon.optionsURL = manifest.options_ui.page; - if (manifest.options_ui.open_in_tab) - addon.optionsType = AddonManager.OPTIONS_TYPE_TAB; - else - addon.optionsType = AddonManager.OPTIONS_TYPE_INLINE_BROWSER; - } - - // WebExtensions don't use iconURLs - addon.iconURL = null; - addon.icon64URL = null; - addon.icons = manifest.icons || {}; - - addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT; - - function getLocale(aLocale) { - // Use the raw manifest, here, since we need values with their - // localization placeholders still in place. - let rawManifest = extension.rawManifest; - - // As a convenience, allow author to be set if its a string bug 1313567. - let creator = typeof(rawManifest.author) === 'string' ? rawManifest.author : null; - let homepageURL = rawManifest.homepage_url; - - // Allow developer to override creator and homepage_url. - if (rawManifest.developer) { - if (rawManifest.developer.name) { - creator = rawManifest.developer.name; - } - if (rawManifest.developer.url) { - homepageURL = rawManifest.developer.url; - } - } - - let result = { - name: extension.localize(rawManifest.name, aLocale), - description: extension.localize(rawManifest.description, aLocale), - creator: extension.localize(creator, aLocale), - homepageURL: extension.localize(homepageURL, aLocale), - - developers: null, - translators: null, - contributors: null, - locales: [aLocale], - }; - return result; - } - - addon.defaultLocale = getLocale(extension.defaultLocale); - addon.locales = Array.from(locales.keys(), getLocale); - - delete addon.defaultLocale.locales; - - addon.targetApplications = [{ - id: TOOLKIT_ID, - minVersion: bss.strict_min_version, - maxVersion: bss.strict_max_version, - }]; - - addon.targetPlatforms = []; - addon.userDisabled = false; - addon.softDisabled = addon.blocklistState == Blocklist.STATE_SOFTBLOCKED; - - return addon; -}); - -/** * Reads an AddonInternal object from an RDF stream. * * @param aUri @@ -1060,7 +732,7 @@ var loadManifestFromWebManifest = Task.async(function*(aUri) { * @throws if the install manifest in the RDF stream is corrupt or could not * be read */ -let loadManifestFromRDF = Task.async(function*(aUri, aStream) { +function loadManifestFromRDF(aUri, aStream) { function getPropertyArray(aDs, aSource, aProperty) { let values = []; let targets = aDs.GetTargets(aSource, EM_R(aProperty), true); @@ -1112,17 +784,17 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { } } - for (let prop of PROP_LOCALE_SINGLE) { - locale[prop] = getRDFProperty(aDs, aSource, prop); - } + PROP_LOCALE_SINGLE.forEach(function(aProp) { + locale[aProp] = getRDFProperty(aDs, aSource, aProp); + }); - for (let prop of PROP_LOCALE_MULTI) { + PROP_LOCALE_MULTI.forEach(function(aProp) { // Don't store empty arrays let props = getPropertyArray(aDs, aSource, - prop.substring(0, prop.length - 1)); + aProp.substring(0, aProp.length - 1)); if (props.length > 0) - locale[prop] = props; - } + locale[aProp] = props; + }); return locale; } @@ -1158,9 +830,9 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { let root = gRDF.GetResource(RDFURI_INSTALL_MANIFEST_ROOT); let addon = new AddonInternal(); - for (let prop of PROP_METADATA) { - addon[prop] = getRDFProperty(ds, root, prop); - } + PROP_METADATA.forEach(function(aProp) { + addon[aProp] = getRDFProperty(ds, root, aProp); + }); addon.unpack = getRDFProperty(ds, root, "unpack") == "true"; if (!addon.type) { @@ -1195,13 +867,7 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { // Only read these properties for extensions. if (addon.type == "extension") { addon.bootstrap = getRDFProperty(ds, root, "bootstrap") == "true"; - - let mpcValue = getRDFProperty(ds, root, "multiprocessCompatible"); - addon.multiprocessCompatible = mpcValue == "true"; - addon.mpcOptedOut = mpcValue == "false"; - - addon.hasEmbeddedWebExtension = getRDFProperty(ds, root, "hasEmbeddedWebExtension") == "true"; - + addon.multiprocessCompatible = getRDFProperty(ds, root, "multiprocessCompatible") == "true"; if (addon.optionsType && addon.optionsType != AddonManager.OPTIONS_TYPE_DIALOG && addon.optionsType != AddonManager.OPTIONS_TYPE_INLINE && @@ -1209,19 +875,6 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { addon.optionsType != AddonManager.OPTIONS_TYPE_INLINE_INFO) { throw new Error("Install manifest specifies unknown type: " + addon.optionsType); } - - if (addon.hasEmbeddedWebExtension) { - let uri = NetUtil.newURI("webextension/manifest.json", null, aUri); - let embeddedAddon = yield loadManifestFromWebManifest(uri); - if (embeddedAddon.optionsURL) { - if (addon.optionsType || addon.optionsURL) - logger.warn(`Addon ${addon.id} specifies optionsType or optionsURL ` + - `in both install.rdf and manifest.json`); - - addon.optionsURL = embeddedAddon.optionsURL; - addon.optionsType = embeddedAddon.optionsType; - } - } } else { // Some add-on types are always restartless. @@ -1254,24 +907,15 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { addon.locales.push(locale); } - let dependencies = new Set(); - targets = ds.GetTargets(root, EM_R("dependency"), true); - while (targets.hasMoreElements()) { - let target = targets.getNext().QueryInterface(Ci.nsIRDFResource); - let id = getRDFProperty(ds, target, "id"); - dependencies.add(id); - } - addon.dependencies = Object.freeze(Array.from(dependencies)); - let seenApplications = []; addon.targetApplications = []; targets = ds.GetTargets(root, EM_R("targetApplication"), true); while (targets.hasMoreElements()) { let target = targets.getNext().QueryInterface(Ci.nsIRDFResource); let targetAppInfo = {}; - for (let prop of PROP_TARGETAPP) { - targetAppInfo[prop] = getRDFProperty(ds, target, prop); - } + PROP_TARGETAPP.forEach(function(aProp) { + targetAppInfo[aProp] = getRDFProperty(ds, target, aProp); + }); if (!targetAppInfo.id || !targetAppInfo.minVersion || !targetAppInfo.maxVersion) { logger.warn("Ignoring invalid targetApplication entry in install manifest"); @@ -1290,23 +934,23 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { // the RDF service coalesces them for us. let targetPlatforms = getPropertyArray(ds, root, "targetPlatform"); addon.targetPlatforms = []; - for (let targetPlatform of targetPlatforms) { + targetPlatforms.forEach(function(aPlatform) { let platform = { os: null, abi: null }; - let pos = targetPlatform.indexOf("_"); + let pos = aPlatform.indexOf("_"); if (pos != -1) { - platform.os = targetPlatform.substring(0, pos); - platform.abi = targetPlatform.substring(pos + 1); + platform.os = aPlatform.substring(0, pos); + platform.abi = aPlatform.substring(pos + 1); } else { - platform.os = targetPlatform; + platform.os = aPlatform; } addon.targetPlatforms.push(platform); - } + }); // A theme's userDisabled value is true if the theme is not the selected skin // or if there is an active lightweight theme. We ignore whether softblocking @@ -1315,16 +959,16 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { addon.userDisabled = !!LightweightThemeManager.currentTheme || addon.internalName != XPIProvider.selectedSkin; } + // Experiments are disabled by default. It is up to the Experiments Manager + // to enable them (it drives installation). else if (addon.type == "experiment") { - // Experiments are disabled by default. It is up to the Experiments Manager - // to enable them (it drives installation). addon.userDisabled = true; } else { addon.userDisabled = false; + addon.softDisabled = addon.blocklistState == Blocklist.STATE_SOFTBLOCKED; } - addon.softDisabled = addon.blocklistState == Blocklist.STATE_SOFTBLOCKED; addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT; // Experiments are managed and updated through an external "experiments @@ -1333,49 +977,23 @@ let loadManifestFromRDF = Task.async(function*(aUri, aStream) { addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; addon.updateURL = null; addon.updateKey = null; + + addon.targetApplications = []; + addon.targetPlatforms = []; } - // icons will be filled by the calling function - addon.icons = {}; + // Load the storage service before NSS (nsIRandomGenerator), + // to avoid a SQLite initialization error (bug 717904). + let storage = Services.storage; - return addon; -}); - -function defineSyncGUID(aAddon) { - // Define .syncGUID as a lazy property which is also settable - Object.defineProperty(aAddon, "syncGUID", { - get: () => { - // Generate random GUID used for Sync. - let guid = Cc["@mozilla.org/uuid-generator;1"] - .getService(Ci.nsIUUIDGenerator) - .generateUUID().toString(); - - delete aAddon.syncGUID; - aAddon.syncGUID = guid; - return guid; - }, - set: (val) => { - delete aAddon.syncGUID; - aAddon.syncGUID = val; - }, - configurable: true, - enumerable: true, - }); -} + // Generate random GUID used for Sync. + // This was lifted from util.js:makeGUID() from services-sync. + let guid = Cc["@mozilla.org/uuid-generator;1"] + .getService(Ci.nsIUUIDGenerator) + .generateUUID().toString(); + addon.syncGUID = guid; -// Generate a unique ID based on the path to this temporary add-on location. -function generateTemporaryInstallID(aFile) { - const hasher = Cc["@mozilla.org/security/hash;1"] - .createInstance(Ci.nsICryptoHash); - hasher.init(hasher.SHA1); - const data = new TextEncoder().encode(aFile.path); - // Make it so this ID cannot be guessed. - const sess = TEMP_INSTALL_ID_GEN_SESSION; - hasher.update(sess, sess.length); - hasher.update(data, data.length); - let id = `${getHashStringForCrypto(hasher)}@temporary-addon`; - logger.info(`Generated temp id ${id} (${sess.join("")}) for ${aFile.path}`); - return id; + return addon; } /** @@ -1386,7 +1004,7 @@ function generateTemporaryInstallID(aFile) { * @return an AddonInternal object * @throws if the directory does not contain a valid install manifest */ -var loadManifestFromDir = Task.async(function*(aDir, aInstallLocation) { +function loadManifestFromDir(aDir) { function getFileSize(aFile) { if (aFile.isSymlink()) return 0; @@ -1403,76 +1021,38 @@ var loadManifestFromDir = Task.async(function*(aDir, aInstallLocation) { return size; } - function* loadFromRDF(aUri) { - let fis = Cc["@mozilla.org/network/file-input-stream;1"]. - createInstance(Ci.nsIFileInputStream); - fis.init(aUri.file, -1, -1, false); - let bis = Cc["@mozilla.org/network/buffered-input-stream;1"]. - createInstance(Ci.nsIBufferedInputStream); - bis.init(fis, 4096); - try { - var addon = yield loadManifestFromRDF(aUri, bis); - } finally { - bis.close(); - fis.close(); - } - - let iconFile = aDir.clone(); - iconFile.append("icon.png"); - - if (iconFile.exists()) { - addon.icons[32] = "icon.png"; - addon.icons[48] = "icon.png"; - } + let file = aDir.clone(); + file.append(FILE_INSTALL_MANIFEST); + if (!file.exists() || !file.isFile()) + throw new Error("Directory " + aDir.path + " does not contain a valid " + + "install manifest"); - let icon64File = aDir.clone(); - icon64File.append("icon64.png"); + let fis = Cc["@mozilla.org/network/file-input-stream;1"]. + createInstance(Ci.nsIFileInputStream); + fis.init(file, -1, -1, false); + let bis = Cc["@mozilla.org/network/buffered-input-stream;1"]. + createInstance(Ci.nsIBufferedInputStream); + bis.init(fis, 4096); - if (icon64File.exists()) { - addon.icons[64] = "icon64.png"; - } + try { + let addon = loadManifestFromRDF(Services.io.newFileURI(file), bis); + addon._sourceBundle = aDir.clone(); + addon.size = getFileSize(aDir); - let file = aDir.clone(); + file = aDir.clone(); file.append("chrome.manifest"); let chromeManifest = ChromeManifestParser.parseSync(Services.io.newFileURI(file)); addon.hasBinaryComponents = ChromeManifestParser.hasType(chromeManifest, "binary-component"); - return addon; - } - let file = getManifestFileForDir(aDir); - if (!file) { - throw new Error("Directory " + aDir.path + " does not contain a valid " + - "install manifest"); + addon.appDisabled = !isUsableAddon(addon); + return addon; } - - let uri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL); - - let addon; - if (file.leafName == FILE_WEB_MANIFEST) { - addon = yield loadManifestFromWebManifest(uri); - if (!addon.id) { - if (aInstallLocation == TemporaryInstallLocation) { - addon.id = generateTemporaryInstallID(aDir); - } else { - addon.id = aDir.leafName; - } - } - } else { - addon = yield loadFromRDF(uri); + finally { + bis.close(); + fis.close(); } - - addon._sourceBundle = aDir.clone(); - addon._installLocation = aInstallLocation; - addon.size = getFileSize(aDir); - addon.signedState = yield verifyDirSignedState(aDir, addon) - .then(({signedState}) => signedState); - addon.appDisabled = !isUsableAddon(addon); - - defineSyncGUID(addon); - - return addon; -}); +} /** * Loads an AddonInternal object from an nsIZipReader for an add-on. @@ -1480,84 +1060,72 @@ var loadManifestFromDir = Task.async(function*(aDir, aInstallLocation) { * @param aZipReader * An open nsIZipReader for the add-on's files * @return an AddonInternal object - * @throws if the XPI file does not contain a valid install manifest + * @throws if the XPI file does not contain a valid install manifest. + * Throws with |webext:true| if a WebExtension manifest was found + * to distinguish between WebExtensions and corrupt files. */ -var loadManifestFromZipReader = Task.async(function*(aZipReader, aInstallLocation) { - function* loadFromRDF(aUri) { - let zis = aZipReader.getInputStream(entry); - let bis = Cc["@mozilla.org/network/buffered-input-stream;1"]. - createInstance(Ci.nsIBufferedInputStream); - bis.init(zis, 4096); +function loadManifestFromZipReader(aZipReader) { + let zis; + try { + zis = aZipReader.getInputStream(FILE_INSTALL_MANIFEST); + } catch (e) { + // We're going to throw here, but depending on whether we have a + // WebExtension manifest in the XPI, we'll throw with the webext flag. try { - var addon = yield loadManifestFromRDF(aUri, bis); - } finally { - bis.close(); - zis.close(); + let zws = aZipReader.getInputStream(FILE_WEBEXT_MANIFEST); + zws.close(); + } catch(e2) { + // We have neither an install manifest nor a WebExtension manifest; + // this means the extension file has a structural problem. + // Just pass the original error up the chain in that case. + throw { + name: e.name, + message: e.message + }; } + // If we get here, we have a WebExtension manifest but no install + // manifest. Pass the error up the chain with the webext flag. + throw { + name: e.name, + message: e.message, + webext: true + }; + } + + // We found an install manifest, so it's either a regular or hybrid + // extension. Continue processing. + let bis = Cc["@mozilla.org/network/buffered-input-stream;1"]. + createInstance(Ci.nsIBufferedInputStream); + bis.init(zis, 4096); - if (aZipReader.hasEntry("icon.png")) { - addon.icons[32] = "icon.png"; - addon.icons[48] = "icon.png"; - } + try { + let uri = buildJarURI(aZipReader.file, FILE_INSTALL_MANIFEST); + let addon = loadManifestFromRDF(uri, bis); + addon._sourceBundle = aZipReader.file; - if (aZipReader.hasEntry("icon64.png")) { - addon.icons[64] = "icon64.png"; - } + addon.size = 0; + let entries = aZipReader.findEntries(null); + while (entries.hasMore()) + addon.size += aZipReader.getEntry(entries.getNext()).realSize; // Binary components can only be loaded from unpacked addons. if (addon.unpack) { - let uri = buildJarURI(aZipReader.file, "chrome.manifest"); + uri = buildJarURI(aZipReader.file, "chrome.manifest"); let chromeManifest = ChromeManifestParser.parseSync(uri); addon.hasBinaryComponents = ChromeManifestParser.hasType(chromeManifest, "binary-component"); } else { addon.hasBinaryComponents = false; } - + + addon.appDisabled = !isUsableAddon(addon); return addon; } - - let entry = getManifestEntryForZipReader(aZipReader); - if (!entry) { - throw new Error("File " + aZipReader.file.path + " does not contain a valid " + - "install manifest"); - } - - let uri = buildJarURI(aZipReader.file, entry); - - let isWebExtension = (entry == FILE_WEB_MANIFEST); - - let addon = isWebExtension ? - yield loadManifestFromWebManifest(uri) : - yield loadFromRDF(uri); - - addon._sourceBundle = aZipReader.file; - addon._installLocation = aInstallLocation; - - addon.size = 0; - let entries = aZipReader.findEntries(null); - while (entries.hasMore()) - addon.size += aZipReader.getEntry(entries.getNext()).realSize; - - let {signedState, cert} = yield verifyZipSignedState(aZipReader.file, addon); - addon.signedState = signedState; - if (isWebExtension && !addon.id) { - if (cert) { - addon.id = cert.commonName; - if (!gIDTest.test(addon.id)) { - throw new Error(`Webextension is signed with an invalid id (${addon.id})`); - } - } - if (!addon.id && aInstallLocation == TemporaryInstallLocation) { - addon.id = generateTemporaryInstallID(aZipReader.file); - } + finally { + bis.close(); + zis.close(); } - addon.appDisabled = !isUsableAddon(addon); - - defineSyncGUID(addon); - - return addon; -}); +} /** * Loads an AddonInternal object from an add-on in an XPI file. @@ -1567,53 +1135,24 @@ var loadManifestFromZipReader = Task.async(function*(aZipReader, aInstallLocatio * @return an AddonInternal object * @throws if the XPI file does not contain a valid install manifest */ -var loadManifestFromZipFile = Task.async(function*(aXPIFile, aInstallLocation) { +function loadManifestFromZipFile(aXPIFile) { let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]. createInstance(Ci.nsIZipReader); try { zipReader.open(aXPIFile); - // Can't return this promise because that will make us close the zip reader - // before it has finished loading the manifest. Wait for the result and then - // return. - let manifest = yield loadManifestFromZipReader(zipReader, aInstallLocation); - return manifest; + return loadManifestFromZipReader(zipReader); } finally { zipReader.close(); } -}); - -function loadManifestFromFile(aFile, aInstallLocation) { - if (aFile.isFile()) - return loadManifestFromZipFile(aFile, aInstallLocation); - return loadManifestFromDir(aFile, aInstallLocation); } -/** - * A synchronous method for loading an add-on's manifest. This should only ever - * be used during startup or a sync load of the add-ons DB - */ -function syncLoadManifestFromFile(aFile, aInstallLocation) { - let success = undefined; - let result = null; - - loadManifestFromFile(aFile, aInstallLocation).then(val => { - success = true; - result = val; - }, val => { - success = false; - result = val - }); - - let thread = Services.tm.currentThread; - - while (success === undefined) - thread.processNextEvent(true); - - if (!success) - throw result; - return result; +function loadManifestFromFile(aFile) { + if (aFile.isFile()) + return loadManifestFromZipFile(aFile); + else + return loadManifestFromDir(aFile); } /** @@ -1632,9 +1171,11 @@ function syncLoadManifestFromFile(aFile, aInstallLocation) { function getURIForResourceInFile(aFile, aPath) { if (aFile.isDirectory()) { let resource = aFile.clone(); - if (aPath) - aPath.split("/").forEach(part => resource.append(part)); - + if (aPath) { + aPath.split("/").forEach(function(aPart) { + resource.append(aPart); + }); + } return NetUtil.newURI(resource); } @@ -1664,16 +1205,13 @@ function buildJarURI(aJarfile, aPath) { */ function flushJarCache(aJarFile) { Services.obs.notifyObservers(aJarFile, "flush-cache-entry", null); - Services.mm.broadcastAsyncMessage(MSG_JAR_FLUSH, aJarFile.path); + Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageBroadcaster) + .broadcastAsyncMessage(MSG_JAR_FLUSH, aJarFile.path); } -function flushChromeCaches() { +function flushStartupCache() { // Init this, so it will get the notification. Services.obs.notifyObservers(null, "startupcache-invalidate", null); - // Flush message manager cached scripts - Services.obs.notifyObservers(null, "message-manager-flush-caches", null); - // Also dispatch this event to child processes - Services.mm.broadcastAsyncMessage(MSG_MESSAGE_MANAGER_CACHES_FLUSH, null); } /** @@ -1724,186 +1262,6 @@ function verifyZipSigning(aZip, aCertificate) { } /** - * Returns the signedState for a given return code and certificate by verifying - * it against the expected ID. - */ -function getSignedStatus(aRv, aCert, aAddonID) { - let expectedCommonName = aAddonID; - if (aAddonID && aAddonID.length > 64) { - let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. - createInstance(Ci.nsIScriptableUnicodeConverter); - converter.charset = "UTF-8"; - let data = converter.convertToByteArray(aAddonID, {}); - - let crypto = Cc["@mozilla.org/security/hash;1"]. - createInstance(Ci.nsICryptoHash); - crypto.init(Ci.nsICryptoHash.SHA256); - crypto.update(data, data.length); - expectedCommonName = getHashStringForCrypto(crypto); - } - - switch (aRv) { - case Cr.NS_OK: - if (expectedCommonName && expectedCommonName != aCert.commonName) - return AddonManager.SIGNEDSTATE_BROKEN; - - let hotfixID = Preferences.get(PREF_EM_HOTFIX_ID, undefined); - if (hotfixID && hotfixID == aAddonID && Preferences.get(PREF_EM_CERT_CHECKATTRIBUTES, false)) { - // The hotfix add-on has some more rigorous certificate checks - try { - CertUtils.validateCert(aCert, - CertUtils.readCertPrefs(PREF_EM_HOTFIX_CERTS)); - } - catch (e) { - logger.warn("The hotfix add-on was not signed by the expected " + - "certificate and so will not be installed.", e); - return AddonManager.SIGNEDSTATE_BROKEN; - } - } - - if (aCert.organizationalUnit == "Mozilla Components") - return AddonManager.SIGNEDSTATE_SYSTEM; - - return /preliminary/i.test(aCert.organizationalUnit) - ? AddonManager.SIGNEDSTATE_PRELIMINARY - : AddonManager.SIGNEDSTATE_SIGNED; - case Cr.NS_ERROR_SIGNED_JAR_NOT_SIGNED: - return AddonManager.SIGNEDSTATE_MISSING; - case Cr.NS_ERROR_SIGNED_JAR_MANIFEST_INVALID: - case Cr.NS_ERROR_SIGNED_JAR_ENTRY_INVALID: - case Cr.NS_ERROR_SIGNED_JAR_ENTRY_MISSING: - case Cr.NS_ERROR_SIGNED_JAR_ENTRY_TOO_LARGE: - case Cr.NS_ERROR_SIGNED_JAR_UNSIGNED_ENTRY: - case Cr.NS_ERROR_SIGNED_JAR_MODIFIED_ENTRY: - return AddonManager.SIGNEDSTATE_BROKEN; - default: - // Any other error indicates that either the add-on isn't signed or it - // is signed by a signature that doesn't chain to the trusted root. - return AddonManager.SIGNEDSTATE_UNKNOWN; - } -} - -function shouldVerifySignedState(aAddon) { - // Updated system add-ons should always have their signature checked - if (aAddon._installLocation.name == KEY_APP_SYSTEM_ADDONS) - return true; - - // We don't care about signatures for default system add-ons - if (aAddon._installLocation.name == KEY_APP_SYSTEM_DEFAULTS) - return false; - - // Hotfixes should always have their signature checked - let hotfixID = Preferences.get(PREF_EM_HOTFIX_ID, undefined); - if (hotfixID && aAddon.id == hotfixID) - return true; - - // Otherwise only check signatures if signing is enabled and the add-on is one - // of the signed types. - return ADDON_SIGNING && SIGNED_TYPES.has(aAddon.type); -} - -let gCertDB = Cc["@mozilla.org/security/x509certdb;1"] - .getService(Ci.nsIX509CertDB); - -/** - * Verifies that a zip file's contents are all correctly signed by an - * AMO-issued certificate - * - * @param aFile - * the xpi file to check - * @param aAddon - * the add-on object to verify - * @return a Promise that resolves to an object with properties: - * signedState: an AddonManager.SIGNEDSTATE_* constant - * cert: an nsIX509Cert - */ -function verifyZipSignedState(aFile, aAddon) { - if (!shouldVerifySignedState(aAddon)) - return Promise.resolve({ - signedState: AddonManager.SIGNEDSTATE_NOT_REQUIRED, - cert: null - }); - - let root = Ci.nsIX509CertDB.AddonsPublicRoot; - if (!REQUIRE_SIGNING && Preferences.get(PREF_XPI_SIGNATURES_DEV_ROOT, false)) - root = Ci.nsIX509CertDB.AddonsStageRoot; - - return new Promise(resolve => { - let callback = { - openSignedAppFileFinished: function(aRv, aZipReader, aCert) { - if (aZipReader) - aZipReader.close(); - resolve({ - signedState: getSignedStatus(aRv, aCert, aAddon.id), - cert: aCert - }); - } - }; - // This allows the certificate DB to get the raw JS callback object so the - // test code can pass through objects that XPConnect would reject. - callback.wrappedJSObject = callback; - - gCertDB.openSignedAppFileAsync(root, aFile, callback); - }); -} - -/** - * Verifies that a directory's contents are all correctly signed by an - * AMO-issued certificate - * - * @param aDir - * the directory to check - * @param aAddon - * the add-on object to verify - * @return a Promise that resolves to an object with properties: - * signedState: an AddonManager.SIGNEDSTATE_* constant - * cert: an nsIX509Cert - */ -function verifyDirSignedState(aDir, aAddon) { - if (!shouldVerifySignedState(aAddon)) - return Promise.resolve({ - signedState: AddonManager.SIGNEDSTATE_NOT_REQUIRED, - cert: null, - }); - - let root = Ci.nsIX509CertDB.AddonsPublicRoot; - if (!REQUIRE_SIGNING && Preferences.get(PREF_XPI_SIGNATURES_DEV_ROOT, false)) - root = Ci.nsIX509CertDB.AddonsStageRoot; - - return new Promise(resolve => { - let callback = { - verifySignedDirectoryFinished: function(aRv, aCert) { - resolve({ - signedState: getSignedStatus(aRv, aCert, aAddon.id), - cert: null, - }); - } - }; - // This allows the certificate DB to get the raw JS callback object so the - // test code can pass through objects that XPConnect would reject. - callback.wrappedJSObject = callback; - - gCertDB.verifySignedDirectoryAsync(root, aDir, callback); - }); -} - -/** - * Verifies that a bundle's contents are all correctly signed by an - * AMO-issued certificate - * - * @param aBundle - * the nsIFile for the bundle to check, either a directory or zip file - * @param aAddon - * the add-on object to verify - * @return a Promise that resolves to an AddonManager.SIGNEDSTATE_* constant. - */ -function verifyBundleSignedState(aBundle, aAddon) { - let promise = aBundle.isFile() ? verifyZipSignedState(aBundle, aAddon) - : verifyDirSignedState(aBundle, aAddon); - return promise.then(({signedState}) => signedState); -} - -/** * Replaces %...% strings in an addon url (update and updateInfo) with * appropriate values. * @@ -1947,7 +1305,7 @@ function escapeAddonURI(aAddon, aUri, aUpdateType, aAppVersion) } function removeAsync(aFile) { - return Task.spawn(function*() { + return Task.spawn(function () { let info = null; try { info = yield OS.File.stat(aFile.path); @@ -1956,9 +1314,7 @@ function removeAsync(aFile) { else yield OS.File.remove(aFile.path); } - catch (e) { - if (!(e instanceof OS.File.Error) || ! e.becauseNoSuchFile) - throw e; + catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) { // The file has already gone away return; } @@ -1997,7 +1353,7 @@ function recursiveRemove(aFile) { return; } catch (e) { - if (!aFile.isDirectory() || aFile.isSymlink()) { + if (!aFile.isDirectory()) { logger.error("Failed to remove file " + aFile.path, e); throw e; } @@ -2078,7 +1434,7 @@ function getDirectoryEntries(aDir, aSortEntries) { entries.push(dirEnum.nextFile); if (aSortEntries) { - entries.sort(function(a, b) { + entries.sort(function sortDirEntries(a, b) { return a.path > b.path ? -1 : 1; }); } @@ -2097,16 +1453,21 @@ function getDirectoryEntries(aDir, aSortEntries) { } /** - * Record a bit of per-addon telemetry - * @param aAddon the addon to record + * Wraps a function in an exception handler to protect against exceptions inside callbacks + * @param aFunction function(args...) + * @return function(args...), a function that takes the same arguments as aFunction + * and returns the same result unless aFunction throws, in which case it logs + * a warning and returns undefined. */ -function recordAddonTelemetry(aAddon) { - let locale = aAddon.defaultLocale; - if (locale) { - if (locale.name) - XPIProvider.setTelemetry(aAddon.id, "name", locale.name); - if (locale.creator) - XPIProvider.setTelemetry(aAddon.id, "creator", locale.creator); +function makeSafe(aFunction) { + return function(...aArgs) { + try { + return aFunction(...aArgs); + } + catch(ex) { + logger.warn("XPIProvider callback failed", ex); + } + return undefined; } } @@ -2162,18 +1523,20 @@ XPIState.prototype = { logger.debug('getModTime: Recursive scan of ' + aId); let [modFile, modTime, items] = recursiveLastModifiedTime(aFile); XPIProvider._mostRecentlyModifiedFile[aId] = modFile; - XPIProvider.setTelemetry(aId, "scan_items", items); if (modTime != this.scanTime) { this.scanTime = modTime; changed = true; } } - // if the add-on is disabled, modified time is the install manifest time, if - // any. If no manifest exists, we assume this is a packed .xpi and use + // if the add-on is disabled, modified time is the install.rdf time, if any. + // If {path}/install.rdf doesn't exist, we assume this is a packed .xpi and use // the time stamp of {path} try { - // Get the install manifest update time, if any. - let maniFile = getManifestFileForDir(aFile); + // Get the install.rdf update time, if any. + // XXX This will eventually also need to check for package.json or whatever + // the new manifest is named. + let maniFile = aFile.clone(); + maniFile.append(FILE_INSTALL_MANIFEST); if (!(aId in XPIProvider._mostRecentlyModifiedFile)) { XPIProvider._mostRecentlyModifiedFile[aId] = maniFile.leafName; } @@ -2197,9 +1560,6 @@ XPIState.prototype = { this.scanTime = 0; } } - // Record duration of file-modified check - XPIProvider.setTelemetry(aId, "scan_MS", Math.round(Cu.now() - scanStarted)); - return changed; }, @@ -2295,7 +1655,7 @@ this.XPIStates = { for (let location of XPIProvider.installLocations) { // The list of add-on like file/directory names in the install location. - let addons = location.getAddonLocations(); + let addons = location.addonLocations; // The results of scanning this location. let foundAddons = new SerializableMap(); @@ -2307,7 +1667,9 @@ this.XPIStates = { delete oldState[location.name]; } - for (let [id, file] of addons) { + for (let file of addons) { + let id = location.getIDForLocation(file); + if (!(id in locState)) { logger.debug("New add-on ${id} in ${location}", {id: id, location: location.name}); let xpiState = new XPIState({d: file.persistentDescriptor}); @@ -2327,12 +1689,8 @@ this.XPIStates = { if (changed) { logger.debug("Changed add-on ${id} in ${location}", {id: id, location: location.name}); } - else { - logger.debug("Existing add-on ${id} in ${location}", {id: id, location: location.name}); - } foundAddons.set(id, xpiState); } - XPIProvider.setTelemetry(id, "location", location.name); } // Anything left behind in oldState was removed from the file system. @@ -2415,7 +1773,6 @@ this.XPIStates = { let xpiState = new XPIState({d: aAddon.descriptor}); location.set(aAddon.id, xpiState); xpiState.syncWithDB(aAddon, true); - XPIProvider.setTelemetry(aAddon.id, "location", aAddon.location); }, /** @@ -2447,9 +1804,7 @@ this.XPIStates = { }; this.XPIProvider = { - get name() { - return "XPIProvider"; - }, + get name() "XPIProvider", // An array of known install locations installLocations: null, @@ -2471,8 +1826,8 @@ this.XPIProvider = { minCompatiblePlatformVersion: null, // A dictionary of the file descriptors for bootstrappable add-ons by ID bootstrappedAddons: {}, - // A Map of active addons to their bootstrapScope by ID - activeAddons: new Map(), + // A dictionary of JS scopes of loaded bootstrappable add-ons by ID + bootstrapScopes: {}, // True if the platform could have activated extensions extensionsActive: false, // True if all of the add-ons found during startup were installed in the @@ -2487,6 +1842,8 @@ this.XPIProvider = { _mostRecentlyModifiedFile: {}, // Per-addon telemetry information _telemetryDetails: {}, + // Experiments are disabled by default. Track ones that are locally enabled. + _enabledExperiments: null, // A Map from an add-on install to its ID _addonFileMap: new Map(), // Flag to know if ToolboxProcess.jsm has already been loaded by someone or not @@ -2494,62 +1851,14 @@ this.XPIProvider = { // Have we started shutting down bootstrap add-ons? _closing: false, - /** - * Returns an array of the add-on values in `bootstrappedAddons`, - * sorted so that all of an add-on's dependencies appear in the array - * before itself. - * - * @returns {Array<object>} - * A sorted array of add-on objects. Each value is a copy of the - * corresponding value in the `bootstrappedAddons` object, with an - * additional `id` property, which corresponds to the key in that - * object, which is the same as the add-ons ID. - */ - sortBootstrappedAddons: function() { - let addons = {}; - - // Sort the list of IDs so that the ordering is deterministic. - for (let id of Object.keys(this.bootstrappedAddons).sort()) { - addons[id] = Object.assign({id}, this.bootstrappedAddons[id]); - } - - let res = new Set(); - let seen = new Set(); - - let add = addon => { - seen.add(addon.id); - - for (let id of addon.dependencies || []) { - if (id in addons && !seen.has(id)) { - add(addons[id]); - } - } - - res.add(addon.id); - } - - Object.values(addons).forEach(add); - - return Array.from(res, id => addons[id]); - }, - - /* - * Set a value in the telemetry hash for a given ID - */ - setTelemetry: function(aId, aName, aValue) { - if (!this._telemetryDetails[aId]) - this._telemetryDetails[aId] = {}; - this._telemetryDetails[aId][aName] = aValue; - }, - // Keep track of in-progress operations that support cancel() _inProgress: [], - doing: function(aCancellable) { + doing: function XPI_doing(aCancellable) { this._inProgress.push(aCancellable); }, - done: function(aCancellable) { + done: function XPI_done(aCancellable) { let i = this._inProgress.indexOf(aCancellable); if (i != -1) { this._inProgress.splice(i, 1); @@ -2558,7 +1867,7 @@ this.XPIProvider = { return false; }, - cancelAll: function() { + cancelAll: function XPI_cancelAll() { // Cancelling one may alter _inProgress, so don't use a simple iterator while (this._inProgress.length > 0) { let c = this._inProgress.shift(); @@ -2578,7 +1887,7 @@ this.XPIProvider = { * will be still valid after an add-on gets disabled or uninstalled, as * consumers may still have URIs of (leaked) resources they want to map. */ - _addURIMapping: function(aID, aFile) { + _addURIMapping: function XPI__addURIMapping(aID, aFile) { logger.info("Mapping " + aID + " to " + aFile.path); this._addonFileMap.set(aID, aFile.path); @@ -2595,7 +1904,7 @@ this.XPIProvider = { * @return * resolved nsIFileURL */ - _resolveURIToFile: function(aURI) { + _resolveURIToFile: function XPI__resolveURIToFile(aURI) { switch (aURI.scheme) { case "jar": case "file": @@ -2663,7 +1972,7 @@ this.XPIProvider = { * The version of the platform last run with this profile or null * if it is a new profile or the version is unknown */ - startup: function(aAppChanged, aOldAppVersion, aOldPlatformVersion) { + startup: function XPI_startup(aAppChanged, aOldAppVersion, aOldPlatformVersion) { function addDirectoryInstallLocation(aName, aKey, aPaths, aScope, aLocked) { try { var dir = FileUtils.getDir(aKey, aPaths); @@ -2675,8 +1984,7 @@ this.XPIProvider = { } try { - var location = aLocked ? new DirectoryInstallLocation(aName, dir, aScope) - : new MutableDirectoryInstallLocation(aName, dir, aScope); + var location = new DirectoryInstallLocation(aName, dir, aScope, aLocked); } catch (e) { logger.warn("Failed to add directory install location " + aName, e); @@ -2687,28 +1995,6 @@ this.XPIProvider = { XPIProvider.installLocationsByName[location.name] = location; } - function addSystemAddonInstallLocation(aName, aKey, aPaths, aScope) { - try { - var dir = FileUtils.getDir(aKey, aPaths); - } - catch (e) { - // Some directories aren't defined on some platforms, ignore them - logger.debug("Skipping unavailable install location " + aName); - return; - } - - try { - var location = new SystemAddonInstallLocation(aName, dir, aScope, aAppChanged !== false); - } - catch (e) { - logger.warn("Failed to add system add-on install location " + aName, e); - return; - } - - XPIProvider.installLocations.push(location); - XPIProvider.installLocationsByName[location.name] = location; - } - function addRegistryInstallLocation(aName, aRootkey, aScope) { try { var location = new WinRegInstallLocation(aName, aRootkey, aScope); @@ -2727,15 +2013,15 @@ this.XPIProvider = { logger.debug("startup"); this.runPhase = XPI_STARTING; - this.installs = new Set(); + this.installs = []; this.installLocations = []; this.installLocationsByName = {}; // Hook for tests to detect when saving database at shutdown time fails this._shutdownError = null; // Clear this at startup for xpcshell test restarts this._telemetryDetails = {}; - // Register our details structure with AddonManager - AddonManagerPrivate.setTelemetryDetails("XPI", this._telemetryDetails); + // Clear the set of enabled experiments (experiments disabled by default). + this._enabledExperiments = new Set(); let hasRegistry = ("nsIWindowsRegKey" in Ci); @@ -2744,23 +2030,11 @@ this.XPIProvider = { // These must be in order of priority, highest to lowest, // for processFileChanges etc. to work - - XPIProvider.installLocations.push(TemporaryInstallLocation); - XPIProvider.installLocationsByName[TemporaryInstallLocation.name] = - TemporaryInstallLocation; - // The profile location is always enabled addDirectoryInstallLocation(KEY_APP_PROFILE, KEY_PROFILEDIR, [DIR_EXTENSIONS], AddonManager.SCOPE_PROFILE, false); - addSystemAddonInstallLocation(KEY_APP_SYSTEM_ADDONS, KEY_PROFILEDIR, - [DIR_SYSTEM_ADDONS], - AddonManager.SCOPE_PROFILE); - - addDirectoryInstallLocation(KEY_APP_SYSTEM_DEFAULTS, KEY_APP_FEATURES, - [], AddonManager.SCOPE_PROFILE, true); - if (enabledScopes & AddonManager.SCOPE_USER) { addDirectoryInstallLocation(KEY_APP_SYSTEM_USER, "XREUSysExt", [Services.appinfo.ID], @@ -2772,9 +2046,11 @@ this.XPIProvider = { } } - addDirectoryInstallLocation(KEY_APP_GLOBAL, KEY_ADDON_APP_DIR, - [DIR_EXTENSIONS], - AddonManager.SCOPE_APPLICATION, true); + if (enabledScopes & AddonManager.SCOPE_APPLICATION) { + addDirectoryInstallLocation(KEY_APP_GLOBAL, KEY_APPDIR, + [DIR_EXTENSIONS], + AddonManager.SCOPE_APPLICATION, true); + } if (enabledScopes & AddonManager.SCOPE_SYSTEM) { addDirectoryInstallLocation(KEY_APP_SYSTEM_SHARE, "XRESysSExtPD", @@ -2806,25 +2082,17 @@ this.XPIProvider = { Services.prefs.addObserver(PREF_EM_MIN_COMPAT_APP_VERSION, this, false); Services.prefs.addObserver(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, this, false); - Services.prefs.addObserver(PREF_E10S_ADDON_BLOCKLIST, this, false); - Services.prefs.addObserver(PREF_E10S_ADDON_POLICY, this, false); - if (!REQUIRE_SIGNING) - Services.prefs.addObserver(PREF_XPI_SIGNATURES_REQUIRED, this, false); Services.obs.addObserver(this, NOTIFICATION_FLUSH_PERMISSIONS, false); - - // Cu.isModuleLoaded can fail here for external XUL apps where there is - // no chrome.manifest that defines resource://devtools. - if (ResProtocolHandler.hasSubstitution("devtools")) { - if (Cu.isModuleLoaded("resource://devtools/client/framework/ToolboxProcess.jsm")) { - // If BrowserToolboxProcess is already loaded, set the boolean to true - // and do whatever is needed - this._toolboxProcessLoaded = true; - BrowserToolboxProcess.on("connectionchange", - this.onDebugConnectionChange.bind(this)); - } else { - // Else, wait for it to load - Services.obs.addObserver(this, NOTIFICATION_TOOLBOXPROCESS_LOADED, false); - } + if (Cu.isModuleLoaded("resource://devtools/client/framework/ToolboxProcess.jsm")) { + // If BrowserToolboxProcess is already loaded, set the boolean to true + // and do whatever is needed + this._toolboxProcessLoaded = true; + BrowserToolboxProcess.on("connectionchange", + this.onDebugConnectionChange.bind(this)); + } + else { + // Else, wait for it to load + Services.obs.addObserver(this, NOTIFICATION_TOOLBOXPROCESS_LOADED, false); } let flushCaches = this.checkForChanges(aAppChanged, aOldAppVersion, @@ -2835,17 +2103,34 @@ this.XPIProvider = { AddonManagerPrivate.markProviderSafe(this); - if (aAppChanged && !this.allAppGlobal && - Preferences.get(PREF_EM_SHOW_MISMATCH_UI, true)) { - let addonsToUpdate = this.shouldForceUpdateCheck(aAppChanged); - if (addonsToUpdate) { - this.showUpgradeUI(addonsToUpdate); - flushCaches = true; + if (aAppChanged === undefined) { + // For new profiles we will never need to show the add-on selection UI + Services.prefs.setBoolPref(PREF_SHOWN_SELECTION_UI, true); + } + else if (aAppChanged && !this.allAppGlobal && + Preferences.get(PREF_EM_SHOW_MISMATCH_UI, true)) { + if (!Preferences.get(PREF_SHOWN_SELECTION_UI, false)) { + // Flip a flag to indicate that we interrupted startup with an interactive prompt + Services.startup.interrupted = true; + // This *must* be modal as it has to block startup. + var features = "chrome,centerscreen,dialog,titlebar,modal"; + Services.ww.openWindow(null, URI_EXTENSION_SELECT_DIALOG, "", features, null); + Services.prefs.setBoolPref(PREF_SHOWN_SELECTION_UI, true); + // Ensure any changes to the add-ons list are flushed to disk + Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, + !XPIDatabase.writeAddonsList()); + } + else { + let addonsToUpdate = this.shouldForceUpdateCheck(aAppChanged); + if (addonsToUpdate) { + this.showUpgradeUI(addonsToUpdate); + flushCaches = true; + } } } if (flushCaches) { - Services.obs.notifyObservers(null, "startupcache-invalidate", null); + flushStartupCache(); // UI displayed early in startup (like the compatibility UI) may have // caused us to cache parts of the skin or locale in memory. These must // be flushed to allow extension provided skins and locales to take full @@ -2871,23 +2156,22 @@ this.XPIProvider = { try { AddonManagerPrivate.recordTimestamp("XPI_bootstrap_addons_begin"); - - for (let addon of this.sortBootstrappedAddons()) { + for (let id in this.bootstrappedAddons) { try { let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file.persistentDescriptor = addon.descriptor; + file.persistentDescriptor = this.bootstrappedAddons[id].descriptor; let reason = BOOTSTRAP_REASONS.APP_STARTUP; // Eventually set INSTALLED reason when a bootstrap addon // is dropped in profile folder and automatically installed if (AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED) - .indexOf(addon.id) !== -1) + .indexOf(id) !== -1) reason = BOOTSTRAP_REASONS.ADDON_INSTALL; - this.callBootstrapMethod(createAddonDetails(addon.id, addon), + this.callBootstrapMethod(createAddonDetails(id, this.bootstrappedAddons[id]), file, "startup", reason); } catch (e) { - logger.error("Failed to load bootstrap addon " + addon.id + " from " + - addon.descriptor, e); + logger.error("Failed to load bootstrap addon " + id + " from " + + this.bootstrappedAddons[id].descriptor, e); } } AddonManagerPrivate.recordTimestamp("XPI_bootstrap_addons_end"); @@ -2900,30 +2184,14 @@ this.XPIProvider = { // Let these shutdown a little earlier when they still have access to most // of XPCOM Services.obs.addObserver({ - observe: function(aSubject, aTopic, aData) { + observe: function shutdownObserver(aSubject, aTopic, aData) { XPIProvider._closing = true; - for (let addon of XPIProvider.sortBootstrappedAddons().reverse()) { - // If no scope has been loaded for this add-on then there is no need - // to shut it down (should only happen when a bootstrapped add-on is - // pending enable) - if (!XPIProvider.activeAddons.has(addon.id)) - continue; - + for (let id in XPIProvider.bootstrappedAddons) { let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file.persistentDescriptor = addon.descriptor; - let addonDetails = createAddonDetails(addon.id, addon); - - // If the add-on was pending disable then shut it down and remove it - // from the persisted data. - if (addon.disable) { - XPIProvider.callBootstrapMethod(addonDetails, file, "shutdown", - BOOTSTRAP_REASONS.ADDON_DISABLE); - delete XPIProvider.bootstrappedAddons[addon.id]; - } - else { - XPIProvider.callBootstrapMethod(addonDetails, file, "shutdown", - BOOTSTRAP_REASONS.APP_SHUTDOWN); - } + file.persistentDescriptor = XPIProvider.bootstrappedAddons[id].descriptor; + let addon = createAddonDetails(id, XPIProvider.bootstrappedAddons[id]); + XPIProvider.callBootstrapMethod(addon, file, "shutdown", + BOOTSTRAP_REASONS.APP_SHUTDOWN); } Services.obs.removeObserver(this, "quit-application-granted"); } @@ -2931,7 +2199,7 @@ this.XPIProvider = { // Detect final-ui-startup for telemetry reporting Services.obs.addObserver({ - observe: function(aSubject, aTopic, aData) { + observe: function uiStartupObserver(aSubject, aTopic, aData) { AddonManagerPrivate.recordTimestamp("XPI_finalUIStartup"); XPIProvider.runPhase = XPI_AFTER_UI_STARTUP; Services.obs.removeObserver(this, "final-ui-startup"); @@ -2942,12 +2210,6 @@ this.XPIProvider = { this.extensionsActive = true; this.runPhase = XPI_BEFORE_UI_STARTUP; - - let timerManager = Cc["@mozilla.org/updates/timer-manager;1"]. - getService(Ci.nsIUpdateTimerManager); - timerManager.registerTimer("xpi-signature-verification", () => { - this.verifySignatures(); - }, XPI_SIGNATURE_CHECK_PERIOD); } catch (e) { logger.error("startup failed", e); @@ -2961,14 +2223,14 @@ this.XPIProvider = { * flushing the XPI Database if it was loaded, * 0 otherwise. */ - shutdown: function() { + shutdown: function XPI_shutdown() { logger.debug("shutdown"); // Stop anything we were doing asynchronously this.cancelAll(); this.bootstrappedAddons = {}; - this.activeAddons.clear(); + this.bootstrapScopes = {}; this.enabledAddons = null; this.allAppGlobal = true; @@ -3004,15 +2266,16 @@ this.XPIProvider = { ); return done; } - logger.debug("Notifying XPI shutdown observers"); - Services.obs.notifyObservers(null, "xpi-provider-shutdown", null); - return undefined; + else { + logger.debug("Notifying XPI shutdown observers"); + Services.obs.notifyObservers(null, "xpi-provider-shutdown", null); + } }, /** * Applies any pending theme change to the preferences. */ - applyThemeChange: function() { + applyThemeChange: function XPI_applyThemeChange() { if (!Preferences.get(PREF_DSS_SWITCHPENDING, false)) return; @@ -3040,7 +2303,7 @@ this.XPIProvider = { * IDs to check for updates. Array may be empty if no add-ons can be/need * to be updated, but the metadata check needs to be performed. */ - shouldForceUpdateCheck: function(aAppChanged) { + shouldForceUpdateCheck: function XPI_shouldForceUpdateCheck(aAppChanged) { AddonManagerPrivate.recordSimpleMeasure("XPIDB_metadata_age", AddonRepository.metadataAge()); let startupChanges = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_DISABLED); @@ -3052,8 +2315,7 @@ this.XPIProvider = { let addons = XPIDatabase.getAddons(); for (let addon of addons) { if ((startupChanges.indexOf(addon.id) != -1) && - (addon.permissions() & AddonManager.PERM_CAN_UPGRADE) && - !addon.isCompatible) { + (addon.permissions() & AddonManager.PERM_CAN_UPGRADE)) { logger.debug("shouldForceUpdateCheck: can upgrade disabled add-on " + addon.id); forceUpdate.push(addon.id); } @@ -3078,10 +2340,8 @@ this.XPIProvider = { * Array opf addon IDs that were disabled by the application update, and * should therefore be checked for updates. */ - showUpgradeUI: function(aAddonIDs) { + showUpgradeUI: function XPI_showUpgradeUI(aAddonIDs) { logger.debug("XPI_showUpgradeUI: " + aAddonIDs.toSource()); - Services.telemetry.getHistogramById("ADDON_MANAGER_UPGRADE_UI_SHOWN").add(1); - // Flip a flag to indicate that we interrupted startup with an interactive prompt Services.startup.interrupted = true; @@ -3100,184 +2360,10 @@ this.XPIProvider = { !XPIDatabase.writeAddonsList()); }, - updateSystemAddons: Task.async(function*() { - let systemAddonLocation = XPIProvider.installLocationsByName[KEY_APP_SYSTEM_ADDONS]; - if (!systemAddonLocation) - return; - - // Don't do anything in safe mode - if (Services.appinfo.inSafeMode) - return; - - // Download the list of system add-ons - let url = Preferences.get(PREF_SYSTEM_ADDON_UPDATE_URL, null); - if (!url) { - yield systemAddonLocation.cleanDirectories(); - return; - } - - url = UpdateUtils.formatUpdateURL(url); - - logger.info(`Starting system add-on update check from ${url}.`); - let res = yield ProductAddonChecker.getProductAddonList(url); - - // If there was no list then do nothing. - if (!res || !res.gmpAddons) { - logger.info("No system add-ons list was returned."); - yield systemAddonLocation.cleanDirectories(); - return; - } - - let addonList = new Map( - res.gmpAddons.map(spec => [spec.id, { spec, path: null, addon: null }])); - - let getAddonsInLocation = (location) => { - return new Promise(resolve => { - XPIDatabase.getAddonsInLocation(location, resolve); - }); - }; - - let setMatches = (wanted, existing) => { - if (wanted.size != existing.size) - return false; - - for (let [id, addon] of existing) { - let wantedInfo = wanted.get(id); - - if (!wantedInfo) - return false; - if (wantedInfo.spec.version != addon.version) - return false; - } - - return true; - }; - - // If this matches the current set in the profile location then do nothing. - let updatedAddons = addonMap(yield getAddonsInLocation(KEY_APP_SYSTEM_ADDONS)); - if (setMatches(addonList, updatedAddons)) { - logger.info("Retaining existing updated system add-ons."); - yield systemAddonLocation.cleanDirectories(); - return; - } - - // If this matches the current set in the default location then reset the - // updated set. - let defaultAddons = addonMap(yield getAddonsInLocation(KEY_APP_SYSTEM_DEFAULTS)); - if (setMatches(addonList, defaultAddons)) { - logger.info("Resetting system add-ons."); - systemAddonLocation.resetAddonSet(); - yield systemAddonLocation.cleanDirectories(); - return; - } - - // Download all the add-ons - let downloadAddon = Task.async(function*(item) { - try { - let sourceAddon = updatedAddons.get(item.spec.id); - if (sourceAddon && sourceAddon.version == item.spec.version) { - // Copying the file to a temporary location has some benefits. If the - // file is locked and cannot be read then we'll fall back to - // downloading a fresh copy. It also means we don't have to remember - // whether to delete the temporary copy later. - try { - let path = OS.Path.join(OS.Constants.Path.tmpDir, "tmpaddon"); - let unique = yield OS.File.openUnique(path); - unique.file.close(); - yield OS.File.copy(sourceAddon._sourceBundle.path, unique.path); - // Make sure to update file modification times so this is detected - // as a new add-on. - yield OS.File.setDates(unique.path); - item.path = unique.path; - } - catch (e) { - logger.warn(`Failed make temporary copy of ${sourceAddon._sourceBundle.path}.`, e); - } - } - if (!item.path) { - item.path = yield ProductAddonChecker.downloadAddon(item.spec); - } - item.addon = yield loadManifestFromFile(nsIFile(item.path), systemAddonLocation); - } - catch (e) { - logger.error(`Failed to download system add-on ${item.spec.id}`, e); - } - }); - yield Promise.all(Array.from(addonList.values()).map(downloadAddon)); - - // The download promises all resolve regardless, now check if they all - // succeeded - let validateAddon = (item) => { - if (item.spec.id != item.addon.id) { - logger.warn(`Downloaded system add-on expected to be ${item.spec.id} but was ${item.addon.id}.`); - return false; - } - - if (item.spec.version != item.addon.version) { - logger.warn(`Expected system add-on ${item.spec.id} to be version ${item.spec.version} but was ${item.addon.version}.`); - return false; - } - - if (!systemAddonLocation.isValidAddon(item.addon)) - return false; - - return true; - } - - if (!Array.from(addonList.values()).every(item => item.path && item.addon && validateAddon(item))) { - throw new Error("Rejecting updated system add-on set that either could not " + - "be downloaded or contained unusable add-ons."); - } - - // Install into the install location - logger.info("Installing new system add-on set"); - yield systemAddonLocation.installAddonSet(Array.from(addonList.values()) - .map(a => a.addon)); - }), - - /** - * Verifies that all installed add-ons are still correctly signed. - */ - verifySignatures: function() { - XPIDatabase.getAddonList(a => true, (addons) => { - Task.spawn(function*() { - let changes = { - enabled: [], - disabled: [] - }; - - for (let addon of addons) { - // The add-on might have vanished, we'll catch that on the next startup - if (!addon._sourceBundle.exists()) - continue; - - let signedState = yield verifyBundleSignedState(addon._sourceBundle, addon); - - if (signedState != addon.signedState) { - addon.signedState = signedState; - AddonManagerPrivate.callAddonListeners("onPropertyChanged", - addon.wrapper, - ["signedState"]); - } - - let disabled = XPIProvider.updateAddonDisabledState(addon); - if (disabled !== undefined) - changes[disabled ? "disabled" : "enabled"].push(addon.id); - } - - XPIDatabase.saveChanges(); - - Services.obs.notifyObservers(null, "xpi-signature-changed", JSON.stringify(changes)); - }).then(null, err => { - logger.error("XPI_verifySignature: " + err); - }) - }); - }, - /** * Persists changes to XPIProvider.bootstrappedAddons to its store (a pref). */ - persistBootstrappedAddons: function() { + persistBootstrappedAddons: function XPI_persistBootstrappedAddons() { // Experiments are disabled upon app load, so don't persist references. let filtered = {}; for (let id in this.bootstrappedAddons) { @@ -3296,7 +2382,7 @@ this.XPIProvider = { /** * Adds a list of currently active add-ons to the next crash report. */ - addAddonsToCrashReporter: function() { + addAddonsToCrashReporter: function XPI_addAddonsToCrashReporter() { if (!("nsICrashReporter" in Ci) || !(Services.appinfo instanceof Ci.nsICrashReporter)) return; @@ -3331,24 +2417,110 @@ this.XPIProvider = { * of passing through updated compatibility information * @return true if an add-on was installed or uninstalled */ - processPendingFileChanges: function(aManifests) { + processPendingFileChanges: function XPI_processPendingFileChanges(aManifests) { let changed = false; - for (let location of this.installLocations) { - aManifests[location.name] = {}; + this.installLocations.forEach(function(aLocation) { + aManifests[aLocation.name] = {}; // We can't install or uninstall anything in locked locations - if (location.locked) { - continue; + if (aLocation.locked) + return; + + let stagedXPIDir = aLocation.getXPIStagingDir(); + let stagingDir = aLocation.getStagingDir(); + + if (stagedXPIDir.exists() && stagedXPIDir.isDirectory()) { + let entries = stagedXPIDir.directoryEntries + .QueryInterface(Ci.nsIDirectoryEnumerator); + while (entries.hasMoreElements()) { + let stageDirEntry = entries.nextFile; + + if (!stageDirEntry.isDirectory()) { + logger.warn("Ignoring file in XPI staging directory: " + stageDirEntry.path); + continue; + } + + // Find the last added XPI file in the directory + let stagedXPI = null; + var xpiEntries = stageDirEntry.directoryEntries + .QueryInterface(Ci.nsIDirectoryEnumerator); + while (xpiEntries.hasMoreElements()) { + let file = xpiEntries.nextFile; + if (file.isDirectory()) + continue; + + let extension = file.leafName; + extension = extension.substring(extension.length - 4); + + if (extension != ".xpi" && extension != ".jar") + continue; + + stagedXPI = file; + } + xpiEntries.close(); + + if (!stagedXPI) + continue; + + let addon = null; + try { + addon = loadManifestFromZipFile(stagedXPI); + } + catch (e) { + logger.error("Unable to read add-on manifest from " + stagedXPI.path, e); + continue; + } + + logger.debug("Migrating staged install of " + addon.id + " in " + aLocation.name); + + if (addon.unpack || Preferences.get(PREF_XPI_UNPACK, false)) { + let targetDir = stagingDir.clone(); + targetDir.append(addon.id); + try { + targetDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); + } + catch (e) { + logger.error("Failed to create staging directory for add-on " + addon.id, e); + continue; + } + + try { + ZipUtils.extractFiles(stagedXPI, targetDir); + } + catch (e) { + logger.error("Failed to extract staged XPI for add-on " + addon.id + " in " + + aLocation.name, e); + } + } + else { + try { + stagedXPI.moveTo(stagingDir, addon.id + ".xpi"); + } + catch (e) { + logger.error("Failed to move staged XPI for add-on " + addon.id + " in " + + aLocation.name, e); + } + } + } + entries.close(); } - let stagingDir = location.getStagingDir(); + if (stagedXPIDir.exists()) { + try { + recursiveRemove(stagedXPIDir); + } + catch (e) { + // Non-critical, just saves some perf on startup if we clean this up. + logger.debug("Error removing XPI staging dir " + stagedXPIDir.path, e); + } + } try { if (!stagingDir || !stagingDir.exists() || !stagingDir.isDirectory()) - continue; + return; } catch (e) { logger.warn("Failed to find staging directory", e); - continue; + return; } let seenFiles = []; @@ -3364,9 +2536,7 @@ this.XPIProvider = { try { isDir = stageDirEntry.isDirectory(); } - catch (e) { - if (e.result != Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) - throw e; + catch (e if e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) { // If the file has already gone away then don't worry about it, this // can happen on OSX where the resource fork is automatically moved // with the data fork for the file. See bug 733436. @@ -3398,16 +2568,17 @@ this.XPIProvider = { if (isDir) { // Check if the directory contains an install manifest. - let manifest = getManifestFileForDir(stageDirEntry); + let manifest = stageDirEntry.clone(); + manifest.append(FILE_INSTALL_MANIFEST); // If the install manifest doesn't exist uninstall this add-on in this // install location. - if (!manifest) { - logger.debug("Processing uninstall of " + id + " in " + location.name); + if (!manifest.exists()) { + logger.debug("Processing uninstall of " + id + " in " + aLocation.name); try { - let addonFile = location.getLocationForID(id); - let addonToUninstall = syncLoadManifestFromFile(addonFile, location); + let addonFile = aLocation.getLocationForID(id); + let addonToUninstall = loadManifestFromFile(addonFile, aLocation); if (addonToUninstall.bootstrap) { this.callBootstrapMethod(addonToUninstall, addonToUninstall._sourceBundle, "uninstall", BOOTSTRAP_REASONS.ADDON_UNINSTALL); @@ -3418,28 +2589,25 @@ this.XPIProvider = { } try { - location.uninstallAddon(id); + aLocation.uninstallAddon(id); seenFiles.push(stageDirEntry.leafName); } catch (e) { - logger.error("Failed to uninstall add-on " + id + " in " + location.name, e); + logger.error("Failed to uninstall add-on " + id + " in " + aLocation.name, e); } // The file check later will spot the removal and cleanup the database continue; } } - aManifests[location.name][id] = null; + aManifests[aLocation.name][id] = null; let existingAddonID = id; let jsonfile = stagingDir.clone(); jsonfile.append(id + ".json"); - // Assume this was a foreign install if there is no cached metadata file - let foreignInstall = !jsonfile.exists(); - let addon; try { - addon = syncLoadManifestFromFile(stageDirEntry, location); + aManifests[aLocation.name][id] = loadManifestFromFile(stageDirEntry); } catch (e) { logger.error("Unable to read add-on manifest from " + stageDirEntry.path, e); @@ -3449,18 +2617,10 @@ this.XPIProvider = { continue; } - if (mustSign(addon.type) && - addon.signedState <= AddonManager.SIGNEDSTATE_MISSING) { - logger.warn("Refusing to install staged add-on " + id + " with signed state " + addon.signedState); - seenFiles.push(stageDirEntry.leafName); - seenFiles.push(jsonfile.leafName); - continue; - } - // Check for a cached metadata for this add-on, it may contain updated // compatibility information - if (!foreignInstall) { - logger.debug("Found updated metadata for " + id + " in " + location.name); + if (jsonfile.exists()) { + logger.debug("Found updated metadata for " + id + " in " + aLocation.name); let fis = Cc["@mozilla.org/network/file-input-stream;1"]. createInstance(Ci.nsIFileInputStream); let json = Cc["@mozilla.org/dom/json;1"]. @@ -3469,16 +2629,12 @@ this.XPIProvider = { try { fis.init(jsonfile, -1, 0, 0); let metadata = json.decodeFromStream(fis, jsonfile.fileSize); - addon.importMetadata(metadata); - - // Pass this through to addMetadata so it knows this add-on was - // likely installed through the UI - aManifests[location.name][id] = addon; + aManifests[aLocation.name][id].importMetadata(metadata); } catch (e) { // If some data can't be recovered from the cached metadata then it // is unlikely to be a problem big enough to justify throwing away - // the install, just log an error and continue + // the install, just log and error and continue logger.error("Unable to read metadata from " + jsonfile.path, e); } finally { @@ -3487,20 +2643,20 @@ this.XPIProvider = { } seenFiles.push(jsonfile.leafName); - existingAddonID = addon.existingAddonID || id; + existingAddonID = aManifests[aLocation.name][id].existingAddonID || id; var oldBootstrap = null; - logger.debug("Processing install of " + id + " in " + location.name); + logger.debug("Processing install of " + id + " in " + aLocation.name); if (existingAddonID in this.bootstrappedAddons) { try { - var existingAddon = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - existingAddon.persistentDescriptor = this.bootstrappedAddons[existingAddonID].descriptor; - if (existingAddon.exists()) { + var existingAddon = aLocation.getLocationForID(existingAddonID); + if (this.bootstrappedAddons[existingAddonID].descriptor == + existingAddon.persistentDescriptor) { oldBootstrap = this.bootstrappedAddons[existingAddonID]; // We'll be replacing a currently active bootstrapped add-on so // call its uninstall method - let newVersion = addon.version; + let newVersion = aManifests[aLocation.name][id].version; let oldVersion = oldBootstrap.version; let uninstallReason = Services.vc.compare(oldVersion, newVersion) < 0 ? BOOTSTRAP_REASONS.ADDON_UPGRADE : @@ -3510,7 +2666,7 @@ this.XPIProvider = { existingAddon, "uninstall", uninstallReason, { newVersion: newVersion }); this.unloadBootstrapScope(existingAddonID); - flushChromeCaches(); + flushStartupCache(); } } catch (e) { @@ -3518,21 +2674,21 @@ this.XPIProvider = { } try { - addon._sourceBundle = location.installAddon({ - id, - source: stageDirEntry, - existingAddonID - }); + var addonInstallLocation = aLocation.installAddon(id, stageDirEntry, + existingAddonID); + if (aManifests[aLocation.name][id]) + aManifests[aLocation.name][id]._sourceBundle = addonInstallLocation; } catch (e) { - logger.error("Failed to install staged add-on " + id + " in " + location.name, + logger.error("Failed to install staged add-on " + id + " in " + aLocation.name, e); // Re-create the staged install - new StagedAddonInstall(location, stageDirEntry, addon); + AddonInstall.createStagedInstall(aLocation, stageDirEntry, + aManifests[aLocation.name][id]); // Make sure not to delete the cached manifest json file seenFiles.pop(); - delete aManifests[location.name][id]; + delete aManifests[aLocation.name][id]; if (oldBootstrap) { // Re-install the old add-on @@ -3545,13 +2701,13 @@ this.XPIProvider = { } try { - location.cleanStagingDir(seenFiles); + aLocation.cleanStagingDir(seenFiles); } catch (e) { // Non-critical, just saves some perf on startup if we clean this up. logger.debug("Error cleaning staging dir " + stagingDir.path, e); } - } + }, this); return changed; }, @@ -3564,11 +2720,9 @@ this.XPIProvider = { * @param aManifests * A dictionary to add new install manifests to to save having to * reload them later - * @param aAppChanged - * See checkForChanges * @return true if any new add-ons were installed */ - installDistributionAddons: function(aManifests, aAppChanged) { + installDistributionAddons: function XPI_installDistributionAddons(aManifests) { let distroDir; try { distroDir = FileUtils.getDir(KEY_APP_DISTRIBUTION, [DIR_EXTENSIONS]); @@ -3614,15 +2768,9 @@ this.XPIProvider = { continue; } - /* If this is not an upgrade and we've already handled this extension - * just continue */ - if (!aAppChanged && Preferences.isSet(PREF_BRANCH_INSTALLED_ADDON + id)) { - continue; - } - let addon; try { - addon = syncLoadManifestFromFile(entry, profileLocation); + addon = loadManifestFromFile(entry); } catch (e) { logger.warn("File entry " + entry.path + " contains an invalid add-on", e); @@ -3645,7 +2793,7 @@ this.XPIProvider = { if (existingEntry) { let existingAddon; try { - existingAddon = syncLoadManifestFromFile(existingEntry, profileLocation); + existingAddon = loadManifestFromFile(existingEntry); if (Services.vc.compare(addon.version, existingAddon.version) <= 0) continue; @@ -3662,7 +2810,7 @@ this.XPIProvider = { // Install the add-on try { - addon._sourceBundle = profileLocation.installAddon({ id, source: entry, action: "copy" }); + profileLocation.installAddon(id, entry, null, true); logger.debug("Installed distribution add-on " + id); Services.prefs.setBoolPref(PREF_BRANCH_INSTALLED_ADDON + id, true) @@ -3686,19 +2834,657 @@ this.XPIProvider = { }, /** + * Compares the add-ons that are currently installed to those that were + * known to be installed when the application last ran and applies any + * changes found to the database. Also sends "startupcache-invalidate" signal to + * observerservice if it detects that data may have changed. + * Always called after XPIProviderUtils.js and extensions.json have been loaded. + * + * @param aManifests + * A dictionary of cached AddonInstalls for add-ons that have been + * installed + * @param aUpdateCompatibility + * true to update add-ons appDisabled property when the application + * version has changed + * @param aOldAppVersion + * The version of the application last run with this profile or null + * if it is a new profile or the version is unknown + * @param aOldPlatformVersion + * The version of the platform last run with this profile or null + * if it is a new profile or the version is unknown + * @return a boolean indicating if a change requiring flushing the caches was + * detected + */ + processFileChanges: function XPI_processFileChanges(aManifests, + aUpdateCompatibility, + aOldAppVersion, + aOldPlatformVersion) { + let visibleAddons = {}; + let oldBootstrappedAddons = this.bootstrappedAddons; + this.bootstrappedAddons = {}; + + /** + * Updates an add-on's metadata and determines if a restart of the + * application is necessary. This is called when either the add-on's + * install directory path or last modified time has changed. + * + * @param aInstallLocation + * The install location containing the add-on + * @param aOldAddon + * The AddonInternal as it appeared the last time the application + * ran + * @param aAddonState + * The new state of the add-on + * @return a boolean indicating if flushing caches is required to complete + * changing this add-on + */ + function updateMetadata(aInstallLocation, aOldAddon, aAddonState) { + logger.debug("Add-on " + aOldAddon.id + " modified in " + aInstallLocation.name); + + // Check if there is an updated install manifest for this add-on + let newAddon = aManifests[aInstallLocation.name][aOldAddon.id]; + + try { + // If not load it + if (!newAddon) { + let file = aInstallLocation.getLocationForID(aOldAddon.id); + newAddon = loadManifestFromFile(file); + applyBlocklistChanges(aOldAddon, newAddon); + + // Carry over any pendingUninstall state to add-ons modified directly + // in the profile. This is important when the attempt to remove the + // add-on in processPendingFileChanges failed and caused an mtime + // change to the add-ons files. + newAddon.pendingUninstall = aOldAddon.pendingUninstall; + } + + // The ID in the manifest that was loaded must match the ID of the old + // add-on. + if (newAddon.id != aOldAddon.id) + throw new Error("Incorrect id in install manifest for existing add-on " + aOldAddon.id); + } + catch (e) { + logger.warn("updateMetadata: Add-on " + aOldAddon.id + " is invalid", e); + XPIDatabase.removeAddonMetadata(aOldAddon); + XPIStates.removeAddon(aOldAddon.location, aOldAddon.id); + if (!aInstallLocation.locked) + aInstallLocation.uninstallAddon(aOldAddon.id); + else + logger.warn("Could not uninstall invalid item from locked install location"); + // If this was an active add-on then we must force a restart + if (aOldAddon.active) + return true; + + return false; + } + + // Set the additional properties on the new AddonInternal + newAddon._installLocation = aInstallLocation; + newAddon.updateDate = aAddonState.mtime; + newAddon.visible = !(newAddon.id in visibleAddons); + + // Update the database + let newDBAddon = XPIDatabase.updateAddonMetadata(aOldAddon, newAddon, + aAddonState.descriptor); + if (newDBAddon.visible) { + visibleAddons[newDBAddon.id] = newDBAddon; + // Remember add-ons that were changed during startup + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED, + newDBAddon.id); + + // If this was the active theme and it is now disabled then enable the + // default theme + if (aOldAddon.active && newDBAddon.disabled) + XPIProvider.enableDefaultTheme(); + + // If the new add-on is bootstrapped and active then call its install method + if (newDBAddon.active && newDBAddon.bootstrap) { + // Startup cache must be flushed before calling the bootstrap script + flushStartupCache(); + + let installReason = Services.vc.compare(aOldAddon.version, newDBAddon.version) < 0 ? + BOOTSTRAP_REASONS.ADDON_UPGRADE : + BOOTSTRAP_REASONS.ADDON_DOWNGRADE; + + let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); + file.persistentDescriptor = aAddonState.descriptor; + XPIProvider.callBootstrapMethod(newDBAddon, file, "install", + installReason, { oldVersion: aOldAddon.version }); + return false; + } + + return true; + } + + return false; + } + + /** + * Updates an add-on's descriptor for when the add-on has moved in the + * filesystem but hasn't changed in any other way. + * + * @param aInstallLocation + * The install location containing the add-on + * @param aOldAddon + * The AddonInternal as it appeared the last time the application + * ran + * @param aAddonState + * The new state of the add-on + * @return a boolean indicating if flushing caches is required to complete + * changing this add-on + */ + function updateDescriptor(aInstallLocation, aOldAddon, aAddonState) { + logger.debug("Add-on " + aOldAddon.id + " moved to " + aAddonState.descriptor); + + aOldAddon.descriptor = aAddonState.descriptor; + aOldAddon.visible = !(aOldAddon.id in visibleAddons); + XPIDatabase.saveChanges(); + + if (aOldAddon.visible) { + visibleAddons[aOldAddon.id] = aOldAddon; + + if (aOldAddon.bootstrap && aOldAddon.active) { + let bootstrap = oldBootstrappedAddons[aOldAddon.id]; + bootstrap.descriptor = aAddonState.descriptor; + XPIProvider.bootstrappedAddons[aOldAddon.id] = bootstrap; + } + + return true; + } + + return false; + } + + /** + * Called when no change has been detected for an add-on's metadata. The + * add-on may have become visible due to other add-ons being removed or + * the add-on may need to be updated when the application version has + * changed. + * + * @param aInstallLocation + * The install location containing the add-on + * @param aOldAddon + * The AddonInternal as it appeared the last time the application + * ran + * @param aAddonState + * The new state of the add-on + * @return a boolean indicating if flushing caches is required to complete + * changing this add-on + */ + function updateVisibilityAndCompatibility(aInstallLocation, aOldAddon, + aAddonState) { + let changed = false; + + // This add-ons metadata has not changed but it may have become visible + if (!(aOldAddon.id in visibleAddons)) { + visibleAddons[aOldAddon.id] = aOldAddon; + + if (!aOldAddon.visible) { + // Remember add-ons that were changed during startup. + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED, + aOldAddon.id); + XPIDatabase.makeAddonVisible(aOldAddon); + + if (aOldAddon.bootstrap) { + // The add-on is bootstrappable so call its install script + let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); + file.persistentDescriptor = aAddonState.descriptor; + XPIProvider.callBootstrapMethod(aOldAddon, file, + "install", + BOOTSTRAP_REASONS.ADDON_INSTALL); + + // If it should be active then mark it as active otherwise unload + // its scope + if (!aOldAddon.disabled) { + XPIDatabase.updateAddonActive(aOldAddon, true); + } + else { + XPIProvider.unloadBootstrapScope(newAddon.id); + } + } + else { + // Otherwise a restart is necessary + changed = true; + } + } + } + + // App version changed, we may need to update the appDisabled property. + if (aUpdateCompatibility) { + let wasDisabled = aOldAddon.disabled; + let wasAppDisabled = aOldAddon.appDisabled; + let wasUserDisabled = aOldAddon.userDisabled; + let wasSoftDisabled = aOldAddon.softDisabled; + + // This updates the addon's JSON cached data in place + applyBlocklistChanges(aOldAddon, aOldAddon, aOldAppVersion, + aOldPlatformVersion); + aOldAddon.appDisabled = !isUsableAddon(aOldAddon); + + let isDisabled = aOldAddon.disabled; + + // If either property has changed update the database. + if (wasAppDisabled != aOldAddon.appDisabled || + wasUserDisabled != aOldAddon.userDisabled || + wasSoftDisabled != aOldAddon.softDisabled) { + logger.debug("Add-on " + aOldAddon.id + " changed appDisabled state to " + + aOldAddon.appDisabled + ", userDisabled state to " + + aOldAddon.userDisabled + " and softDisabled state to " + + aOldAddon.softDisabled); + XPIDatabase.saveChanges(); + } + + // If this is a visible add-on and it has changed disabled state then we + // may need a restart or to update the bootstrap list. + if (aOldAddon.visible && wasDisabled != isDisabled) { + // Remember add-ons that became disabled or enabled by the application + // change + let change = isDisabled ? AddonManager.STARTUP_CHANGE_DISABLED + : AddonManager.STARTUP_CHANGE_ENABLED; + AddonManagerPrivate.addStartupChange(change, aOldAddon.id); + if (aOldAddon.bootstrap) { + // Update the add-ons active state + XPIDatabase.updateAddonActive(aOldAddon, !isDisabled); + } + else { + changed = true; + } + } + } + + if (aOldAddon.visible && aOldAddon.active && aOldAddon.bootstrap) { + XPIProvider.bootstrappedAddons[aOldAddon.id] = { + version: aOldAddon.version, + type: aOldAddon.type, + descriptor: aAddonState.descriptor, + multiprocessCompatible: aOldAddon.multiprocessCompatible + }; + } + + return changed; + } + + /** + * Called when an add-on has been removed. + * + * @param aOldAddon + * The AddonInternal as it appeared the last time the application + * ran + * @return a boolean indicating if flushing caches is required to complete + * changing this add-on + */ + function removeMetadata(aOldAddon) { + // This add-on has disappeared + logger.debug("Add-on " + aOldAddon.id + " removed from " + aOldAddon.location); + XPIDatabase.removeAddonMetadata(aOldAddon); + + // Remember add-ons that were uninstalled during startup + if (aOldAddon.visible) { + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_UNINSTALLED, + aOldAddon.id); + } + else if (AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED) + .indexOf(aOldAddon.id) != -1) { + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED, + aOldAddon.id); + } + + if (aOldAddon.active) { + // Enable the default theme if the previously active theme has been + // removed + if (aOldAddon.type == "theme") + XPIProvider.enableDefaultTheme(); + + return true; + } + + return false; + } + + /** + * Called to add the metadata for an add-on in one of the install locations + * to the database. This can be called in three different cases. Either an + * add-on has been dropped into the location from outside of Firefox, or + * an add-on has been installed through the application, or the database + * has been upgraded or become corrupt and add-on data has to be reloaded + * into it. + * + * @param aInstallLocation + * The install location containing the add-on + * @param aId + * The ID of the add-on + * @param aAddonState + * The new state of the add-on + * @param aMigrateData + * If during startup the database had to be upgraded this will + * contain data that used to be held about this add-on + * @return a boolean indicating if flushing caches is required to complete + * changing this add-on + */ + function addMetadata(aInstallLocation, aId, aAddonState, aMigrateData) { + logger.debug("New add-on " + aId + " installed in " + aInstallLocation.name); + + let newAddon = null; + let sameVersion = false; + // Check the updated manifests lists for the install location, If there + // is no manifest for the add-on ID then newAddon will be undefined + if (aInstallLocation.name in aManifests) + newAddon = aManifests[aInstallLocation.name][aId]; + + // If we had staged data for this add-on or we aren't recovering from a + // corrupt database and we don't have migration data for this add-on then + // this must be a new install. + let isNewInstall = (!!newAddon) || (!XPIDatabase.activeBundles && !aMigrateData); + + // If it's a new install and we haven't yet loaded the manifest then it + // must be something dropped directly into the install location + let isDetectedInstall = isNewInstall && !newAddon; + + // Load the manifest if necessary and sanity check the add-on ID + try { + if (!newAddon) { + // Load the manifest from the add-on. + let file = aInstallLocation.getLocationForID(aId); + newAddon = loadManifestFromFile(file); + } + // The add-on in the manifest should match the add-on ID. + if (newAddon.id != aId) { + throw new Error("Invalid addon ID: expected addon ID " + aId + + ", found " + newAddon.id + " in manifest"); + } + } + catch (e) { + logger.warn("addMetadata: Add-on " + aId + " is invalid", e); + + // Remove the invalid add-on from the install location if the install + // location isn't locked, no restart will be necessary + if (!aInstallLocation.locked) + aInstallLocation.uninstallAddon(aId); + else + logger.warn("Could not uninstall invalid item from locked install location"); + return false; + } + + // Update the AddonInternal properties. + newAddon._installLocation = aInstallLocation; + newAddon.visible = !(newAddon.id in visibleAddons); + newAddon.installDate = aAddonState.mtime; + newAddon.updateDate = aAddonState.mtime; + newAddon.foreignInstall = isDetectedInstall; + + if (aMigrateData) { + // If there is migration data then apply it. + logger.debug("Migrating data from old database"); + + DB_MIGRATE_METADATA.forEach(function(aProp) { + // A theme's disabled state is determined by the selected theme + // preference which is read in loadManifestFromRDF + if (aProp == "userDisabled" && newAddon.type == "theme") + return; + + if (aProp in aMigrateData) + newAddon[aProp] = aMigrateData[aProp]; + }); + + // Force all non-profile add-ons to be foreignInstalls since they can't + // have been installed through the API + newAddon.foreignInstall |= aInstallLocation.name != KEY_APP_PROFILE; + + // Some properties should only be migrated if the add-on hasn't changed. + // The version property isn't a perfect check for this but covers the + // vast majority of cases. + if (aMigrateData.version == newAddon.version) { + logger.debug("Migrating compatibility info"); + sameVersion = true; + if ("targetApplications" in aMigrateData) + newAddon.applyCompatibilityUpdate(aMigrateData, true); + } + + // Since the DB schema has changed make sure softDisabled is correct + applyBlocklistChanges(newAddon, newAddon, aOldAppVersion, + aOldPlatformVersion); + } + + // The default theme is never a foreign install + if (newAddon.type == "theme" && newAddon.internalName == XPIProvider.defaultSkin) + newAddon.foreignInstall = false; + + if (isDetectedInstall && newAddon.foreignInstall) { + // If the add-on is a foreign install and is in a scope where add-ons + // that were dropped in should default to disabled then disable it + let disablingScopes = Preferences.get(PREF_EM_AUTO_DISABLED_SCOPES, 0); + if (aInstallLocation.scope & disablingScopes) { + logger.warn("Disabling foreign installed add-on " + newAddon.id + " in " + + aInstallLocation.name); + newAddon.userDisabled = true; + } + } + + // If we have a list of what add-ons should be marked as active then use + // it to guess at migration data. + if (!isNewInstall && XPIDatabase.activeBundles) { + // For themes we know which is active by the current skin setting + if (newAddon.type == "theme") + newAddon.active = newAddon.internalName == XPIProvider.currentSkin; + else + newAddon.active = XPIDatabase.activeBundles.indexOf(aAddonState.descriptor) != -1; + + // If the add-on wasn't active and it isn't already disabled in some way + // then it was probably either softDisabled or userDisabled + if (!newAddon.active && newAddon.visible && !newAddon.disabled) { + // If the add-on is softblocked then assume it is softDisabled + if (newAddon.blocklistState == Blocklist.STATE_SOFTBLOCKED) + newAddon.softDisabled = true; + else + newAddon.userDisabled = true; + } + } + else { + newAddon.active = (newAddon.visible && !newAddon.disabled); + } + + let newDBAddon = XPIDatabase.addAddonMetadata(newAddon, aAddonState.descriptor); + + if (newDBAddon.visible) { + // Remember add-ons that were first detected during startup. + if (isDetectedInstall) { + // If a copy from a higher priority location was removed then this + // add-on has changed + if (AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_UNINSTALLED) + .indexOf(newDBAddon.id) != -1) { + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED, + newDBAddon.id); + } + else { + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_INSTALLED, + newDBAddon.id); + } + } + + // Note if any visible add-on is not in the application install location + if (newDBAddon._installLocation.name != KEY_APP_GLOBAL) + XPIProvider.allAppGlobal = false; + + visibleAddons[newDBAddon.id] = newDBAddon; + + let installReason = BOOTSTRAP_REASONS.ADDON_INSTALL; + let extraParams = {}; + + // Copy add-on details (enabled, bootstrap, version, etc) to XPIState. + aAddonState.syncWithDB(newDBAddon); + + // If we're hiding a bootstrapped add-on then call its uninstall method + if (newDBAddon.id in oldBootstrappedAddons) { + let oldBootstrap = oldBootstrappedAddons[newDBAddon.id]; + extraParams.oldVersion = oldBootstrap.version; + XPIProvider.bootstrappedAddons[newDBAddon.id] = oldBootstrap; + + // If the old version is the same as the new version, or we're + // recovering from a corrupt DB, don't call uninstall and install + // methods. + if (sameVersion || !isNewInstall) { + logger.debug("addMetadata: early return, sameVersion " + sameVersion + + ", isNewInstall " + isNewInstall); + return false; + } + + installReason = Services.vc.compare(oldBootstrap.version, newDBAddon.version) < 0 ? + BOOTSTRAP_REASONS.ADDON_UPGRADE : + BOOTSTRAP_REASONS.ADDON_DOWNGRADE; + + let oldAddonFile = Cc["@mozilla.org/file/local;1"]. + createInstance(Ci.nsIFile); + oldAddonFile.persistentDescriptor = oldBootstrap.descriptor; + + XPIProvider.callBootstrapMethod(createAddonDetails(newDBAddon.id, oldBootstrap), + oldAddonFile, "uninstall", installReason, + { newVersion: newDBAddon.version }); + + XPIProvider.unloadBootstrapScope(newDBAddon.id); + + // If the new add-on is bootstrapped then we must flush the caches + // before calling the new bootstrap script + if (newDBAddon.bootstrap) + flushStartupCache(); + } + + if (!newDBAddon.bootstrap) + return true; + + // Visible bootstrapped add-ons need to have their install method called + let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); + file.persistentDescriptor = aAddonState.descriptor; + XPIProvider.callBootstrapMethod(newDBAddon, file, + "install", installReason, extraParams); + if (!newDBAddon.active) + XPIProvider.unloadBootstrapScope(newDBAddon.id); + } + + return false; + } + + let changed = false; + + // Get all the add-ons in the existing DB and Map them into Sets by install location + let allDBAddons = new Map(); + for (let a of XPIDatabase.getAddons()) { + let locationSet = allDBAddons.get(a.location); + if (!locationSet) { + locationSet = new Set(); + allDBAddons.set(a.location, locationSet); + } + locationSet.add(a); + } + + for (let installLocation of this.installLocations) { + // Get all the on-disk XPI states for this location, and keep track of which + // ones we see in the database. + let states = XPIStates.getLocation(installLocation.name); + let seen = new Set(); + // Iterate through the add-ons installed the last time the application + // ran + let dbAddons = allDBAddons.get(installLocation.name); + if (dbAddons) { + // we've processed this location + allDBAddons.delete(installLocation.name); + + logger.debug("processFileChanges reconciling DB for location ${l} state ${s} db ${d}", + {l: installLocation.name, s: states, d: [for (a of dbAddons) a.id]}); + for (let aOldAddon of dbAddons) { + // If a version of this add-on has been installed in an higher + // priority install location then count it as changed + if (AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED) + .indexOf(aOldAddon.id) != -1) { + AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED, + aOldAddon.id); + } + + // Check if the add-on is still installed + let xpiState = states && states.get(aOldAddon.id); + if (xpiState) { + // in this block, the add-on is in both XPIStates and the DB + seen.add(xpiState); + + // The add-on has changed if the modification time has changed, or + // we have an updated manifest for it. Also reload the metadata for + // add-ons in the application directory when the application version + // has changed + if (aOldAddon.id in aManifests[installLocation.name] || + aOldAddon.updateDate != xpiState.mtime || + (aUpdateCompatibility && installLocation.name == KEY_APP_GLOBAL)) { + changed = updateMetadata(installLocation, aOldAddon, xpiState) || + changed; + } + else if (aOldAddon.descriptor != xpiState.descriptor) { + changed = updateDescriptor(installLocation, aOldAddon, xpiState) || + changed; + } + else { + changed = updateMetadata(installLocation, aOldAddon, xpiState) || + changed; + + changed = updateVisibilityAndCompatibility(installLocation, + aOldAddon, xpiState) || + changed; + } + if (aOldAddon.visible && aOldAddon._installLocation.name != KEY_APP_GLOBAL) + XPIProvider.allAppGlobal = false; + // Copy add-on details (enabled, bootstrap, version, etc) to XPIState. + xpiState.syncWithDB(aOldAddon); + } + else { + // The add-on is in the DB, but not in xpiState (and thus not on disk). + changed = removeMetadata(aOldAddon) || changed; + } + } + } + + // Any add-on in our current location that we haven't seen needs to + // be added to the database. + // Get the migration data for this install location so we can include that as + // we add, in case this is a database upgrade or rebuild. + let locMigrateData = {}; + if (XPIDatabase.migrateData && installLocation.name in XPIDatabase.migrateData) + locMigrateData = XPIDatabase.migrateData[installLocation.name]; + if (states) { + for (let [id, xpiState] of states) { + if (!seen.has(xpiState)) { + changed = addMetadata(installLocation, id, xpiState, + (locMigrateData[id] || null)) || changed; + } + } + } + } + + // Anything left in allDBAddons is a location where the database contains add-ons, + // but the browser is no longer configured to use that location. The metadata for those + // add-ons must be removed from the database. + for (let [locationName, addons] of allDBAddons) { + logger.debug("Removing orphaned DB add-on entries from " + locationName); + for (let a of addons) { + logger.debug("Remove ${location}:${id}", a); + changed = removeMetadata(a) || changed; + } + } + + XPIStates.save(); + this.persistBootstrappedAddons(); + + // Clear out any cached migration data. + XPIDatabase.migrateData = null; + + return changed; + }, + + /** * Imports the xpinstall permissions from preferences into the permissions * manager for the user to change later. */ - importPermissions: function() { + importPermissions: function XPI_importPermissions() { PermissionsUtils.importFromPrefs(PREF_XPI_PERMISSIONS_BRANCH, XPI_PERMISSION); }, - getDependentAddons: function(aAddon) { - return Array.from(XPIDatabase.getAddons()) - .filter(addon => addon.dependencies.includes(aAddon.id)); - }, - /** * Checks for any changes that have occurred since the last time the * application was launched. @@ -3717,7 +3503,7 @@ this.XPIProvider = { * if it is a new profile or the version is unknown * @return true if a change requiring a restart was detected */ - checkForChanges: function(aAppChanged, aOldAppVersion, + checkForChanges: function XPI_checkForChanges(aAppChanged, aOldAppVersion, aOldPlatformVersion) { logger.debug("checkForChanges"); @@ -3756,9 +3542,10 @@ this.XPIProvider = { } // If the application has changed then check for new distribution add-ons - if (Preferences.get(PREF_INSTALL_DISTRO_ADDONS, true)) + if (aAppChanged !== false && + Preferences.get(PREF_INSTALL_DISTRO_ADDONS, true)) { - updated = this.installDistributionAddons(manifests, aAppChanged); + updated = this.installDistributionAddons(manifests); if (updated) { updateReasons.push("installDistributionAddons"); } @@ -3798,8 +3585,8 @@ this.XPIProvider = { // XXX This will go away when we fold bootstrappedAddons into XPIStates. if (updateReasons.length == 0) { - let bootstrapDescriptors = new Set(Object.keys(this.bootstrappedAddons) - .map(b => this.bootstrappedAddons[b].descriptor)); + let bootstrapDescriptors = new Set([for (b of Object.keys(this.bootstrappedAddons)) + this.bootstrappedAddons[b].descriptor]); for (let location of XPIStates.db.values()) { for (let state of location.values()) { @@ -3809,7 +3596,7 @@ this.XPIProvider = { if (bootstrapDescriptors.size > 0) { logger.warn("Bootstrap state is invalid (missing add-ons: " - + Array.from(bootstrapDescriptors).join(", ") + ")"); + + [for (b of bootstrapDescriptors) b] + ")"); updateReasons.push("missingBootstrapAddon"); } } @@ -3823,11 +3610,10 @@ this.XPIProvider = { AddonManagerPrivate.recordSimpleMeasure("XPIDB_startup_load_reasons", updateReasons); XPIDatabase.syncLoadDB(false); try { - extensionListChanged = XPIDatabaseReconcile.processFileChanges(manifests, - aAppChanged, - aOldAppVersion, - aOldPlatformVersion, - updateReasons.includes("schemaChanged")); + extensionListChanged = this.processFileChanges(manifests, + aAppChanged, + aOldAppVersion, + aOldPlatformVersion); } catch (e) { logger.error("Failed to process extension changes at startup", e); @@ -3845,8 +3631,8 @@ this.XPIProvider = { // When upgrading remove the old extensions cache to force older // versions to rescan the entire list of extensions - let oldCache = FileUtils.getFile(KEY_PROFILEDIR, [FILE_OLD_CACHE], true); try { + let oldCache = FileUtils.getFile(KEY_PROFILEDIR, [FILE_OLD_CACHE], true); if (oldCache.exists()) oldCache.remove(true); } @@ -3893,7 +3679,7 @@ this.XPIProvider = { * The mimetype to check for * @return true if the mimetype is application/x-xpinstall */ - supportsMimetype: function(aMimetype) { + supportsMimetype: function XPI_supportsMimetype(aMimetype) { return aMimetype == "application/x-xpinstall"; }, @@ -3902,7 +3688,7 @@ this.XPIProvider = { * * @return true if installing is enabled */ - isInstallEnabled: function() { + isInstallEnabled: function XPI_isInstallEnabled() { // Default to enabled if the preference does not exist return Preferences.get(PREF_XPI_ENABLED, true); }, @@ -3913,7 +3699,7 @@ this.XPIProvider = { * * @return true if installing by direct requests is whitelisted */ - isDirectRequestWhitelisted: function() { + isDirectRequestWhitelisted: function XPI_isDirectRequestWhitelisted() { // Default to whitelisted if the preference does not exist. return Preferences.get(PREF_XPI_DIRECT_WHITELISTED, true); }, @@ -3924,7 +3710,7 @@ this.XPIProvider = { * * @return true if installing from file referrers is whitelisted */ - isFileRequestWhitelisted: function() { + isFileRequestWhitelisted: function XPI_isFileRequestWhitelisted() { // Default to whitelisted if the preference does not exist. return Preferences.get(PREF_XPI_FILE_WHITELISTED, true); }, @@ -3936,7 +3722,7 @@ this.XPIProvider = { * The nsIPrincipal that initiated the install * @return true if installing is allowed */ - isInstallAllowed: function(aInstallingPrincipal) { + isInstallAllowed: function XPI_isInstallAllowed(aInstallingPrincipal) { if (!this.isInstallEnabled()) return false; @@ -3987,9 +3773,9 @@ this.XPIProvider = { * @param aCallback * A callback to pass the AddonInstall to */ - getInstallForURL: function(aUrl, aHash, aName, aIcons, aVersion, aBrowser, - aCallback) { - createDownloadInstall(function(aInstall) { + getInstallForURL: function XPI_getInstallForURL(aUrl, aHash, aName, aIcons, + aVersion, aBrowser, aCallback) { + AddonInstall.createDownload(function getInstallForURL_createDownload(aInstall) { aCallback(aInstall.wrapper); }, aUrl, aHash, aName, aIcons, aVersion, aBrowser); }, @@ -4002,190 +3788,29 @@ this.XPIProvider = { * @param aCallback * A callback to pass the AddonInstall to */ - getInstallForFile: function(aFile, aCallback) { - createLocalInstall(aFile).then(install => { - aCallback(install ? install.wrapper : null); - }); - }, - - /** - * Temporarily installs add-on from a local XPI file or directory. - * As this is intended for development, the signature is not checked and - * the add-on does not persist on application restart. - * - * @param aFile - * An nsIFile for the unpacked add-on directory or XPI file. - * - * @return See installAddonFromLocation return value. - */ - installTemporaryAddon: function(aFile) { - return this.installAddonFromLocation(aFile, TemporaryInstallLocation); + getInstallForFile: function XPI_getInstallForFile(aFile, aCallback) { + AddonInstall.createInstall(function getInstallForFile_createInstall(aInstall) { + if (aInstall) + aCallback(aInstall.wrapper); + else + aCallback(null); + }, aFile); }, /** - * Permanently installs add-on from a local XPI file or directory. - * The signature is checked but the add-on persist on application restart. - * - * @param aFile - * An nsIFile for the unpacked add-on directory or XPI file. - * - * @return See installAddonFromLocation return value. - */ - installAddonFromSources: Task.async(function*(aFile) { - let location = XPIProvider.installLocationsByName[KEY_APP_PROFILE]; - return this.installAddonFromLocation(aFile, location, "proxy"); - }), - - /** - * Installs add-on from a local XPI file or directory. - * - * @param aFile - * An nsIFile for the unpacked add-on directory or XPI file. - * @param aInstallLocation - * Define a custom install location object to use for the install. - * @param aInstallAction - * Optional action mode to use when installing the addon - * (see MutableDirectoryInstallLocation.installAddon) - * - * @return a Promise that resolves to an Addon object on success, or rejects - * if the add-on is not a valid restartless add-on or if the - * same ID is already installed. - */ - installAddonFromLocation: Task.async(function*(aFile, aInstallLocation, aInstallAction) { - if (aFile.exists() && aFile.isFile()) { - flushJarCache(aFile); - } - let addon = yield loadManifestFromFile(aFile, aInstallLocation); - - aInstallLocation.installAddon({ id: addon.id, source: aFile, action: aInstallAction }); - - if (addon.appDisabled) { - let message = `Add-on ${addon.id} is not compatible with application version.`; - - let app = addon.matchingTargetApplication; - if (app) { - if (app.minVersion) { - message += ` add-on minVersion: ${app.minVersion}.`; - } - if (app.maxVersion) { - message += ` add-on maxVersion: ${app.maxVersion}.`; - } - } - throw new Error(message); - } - - if (!addon.bootstrap) { - throw new Error("Only restartless (bootstrap) add-ons" - + " can be installed from sources:", addon.id); - } - let installReason = BOOTSTRAP_REASONS.ADDON_INSTALL; - let oldAddon = yield new Promise( - resolve => XPIDatabase.getVisibleAddonForID(addon.id, resolve)); - if (oldAddon) { - if (!oldAddon.bootstrap) { - logger.warn("Non-restartless Add-on is already installed", addon.id); - throw new Error("Non-restartless add-on with ID " - + oldAddon.id + " is already installed"); - } - else { - logger.warn("Addon with ID " + oldAddon.id + " already installed," - + " older version will be disabled"); - - let existingAddonID = oldAddon.id; - let existingAddon = oldAddon._sourceBundle; - - // We'll be replacing a currently active bootstrapped add-on so - // call its uninstall method - let newVersion = addon.version; - let oldVersion = oldAddon.version; - if (Services.vc.compare(newVersion, oldVersion) >= 0) { - installReason = BOOTSTRAP_REASONS.ADDON_UPGRADE; - } else { - installReason = BOOTSTRAP_REASONS.ADDON_DOWNGRADE; - } - let uninstallReason = installReason; - - if (oldAddon.active) { - XPIProvider.callBootstrapMethod(oldAddon, existingAddon, - "shutdown", uninstallReason, - { newVersion }); - } - this.callBootstrapMethod(oldAddon, existingAddon, - "uninstall", uninstallReason, { newVersion }); - this.unloadBootstrapScope(existingAddonID); - flushChromeCaches(); - } - } - - let file = addon._sourceBundle; - - XPIProvider._addURIMapping(addon.id, file); - XPIProvider.callBootstrapMethod(addon, file, "install", installReason); - addon.state = AddonManager.STATE_INSTALLED; - logger.debug("Install of temporary addon in " + aFile.path + " completed."); - addon.visible = true; - addon.enabled = true; - addon.active = true; - - addon = XPIDatabase.addAddonMetadata(addon, file.persistentDescriptor); - - XPIStates.addAddon(addon); - XPIDatabase.saveChanges(); - XPIStates.save(); - - AddonManagerPrivate.callAddonListeners("onInstalling", addon.wrapper, - false); - XPIProvider.callBootstrapMethod(addon, file, "startup", - BOOTSTRAP_REASONS.ADDON_ENABLE); - AddonManagerPrivate.callInstallListeners("onExternalInstall", - null, addon.wrapper, - oldAddon ? oldAddon.wrapper : null, - false); - AddonManagerPrivate.callAddonListeners("onInstalled", addon.wrapper); - - return addon.wrapper; - }), - - /** - * Returns an Addon corresponding to an instance ID. - * @param aInstanceID - * An Addon Instance ID - * @return {Promise} - * @resolves The found Addon or null if no such add-on exists. - * @rejects Never - * @throws if the aInstanceID argument is not specified - */ - getAddonByInstanceID: function(aInstanceID) { - if (!aInstanceID || typeof aInstanceID != "symbol") - throw Components.Exception("aInstanceID must be a Symbol()", - Cr.NS_ERROR_INVALID_ARG); - - for (let [id, val] of this.activeAddons) { - if (aInstanceID == val.instanceID) { - if (val.safeWrapper) { - return Promise.resolve(val.safeWrapper); - } - - return new Promise(resolve => { - this.getAddonByID(id, function(addon) { - val.safeWrapper = new PrivateWrapper(addon); - resolve(val.safeWrapper); - }); - }); - } - } - - return Promise.resolve(null); - }, - - /** * Removes an AddonInstall from the list of active installs. * * @param install * The AddonInstall to remove */ - removeActiveInstall: function(aInstall) { - this.installs.delete(aInstall); + removeActiveInstall: function XPI_removeActiveInstall(aInstall) { + let where = this.installs.indexOf(aInstall); + if (where == -1) { + logger.warn("removeActiveInstall: could not find active install for " + + aInstall.sourceURI.spec); + return; + } + this.installs.splice(where, 1); }, /** @@ -4196,9 +3821,9 @@ this.XPIProvider = { * @param aCallback * A callback to pass the Addon to */ - getAddonByID: function(aId, aCallback) { - XPIDatabase.getVisibleAddonForID (aId, function(aAddon) { - aCallback(aAddon ? aAddon.wrapper : null); + getAddonByID: function XPI_getAddonByID(aId, aCallback) { + XPIDatabase.getVisibleAddonForID (aId, function getAddonByID_getVisibleAddonForID(aAddon) { + aCallback(createWrapper(aAddon)); }); }, @@ -4210,11 +3835,14 @@ this.XPIProvider = { * @param aCallback * A callback to pass an array of Addons to */ - getAddonsByTypes: function(aTypes, aCallback) { - let typesToGet = getAllAliasesForTypes(aTypes); - - XPIDatabase.getVisibleAddons(typesToGet, function(aAddons) { - aCallback(aAddons.map(a => a.wrapper)); + getAddonsByTypes: function XPI_getAddonsByTypes(aTypes, aCallback) { + XPIDatabase.getVisibleAddons(aTypes, function getAddonsByTypes_getVisibleAddons(aAddons) { + // Tycho: aCallback([createWrapper(a) for each (a in aAddons)]); + let result = []; + for each(let a in aAddons) { + result.push(createWrapper(a)); + } + aCallback(result); }); }, @@ -4226,9 +3854,9 @@ this.XPIProvider = { * @param aCallback * A callback to pass the Addon to. Receives null if not found. */ - getAddonBySyncGUID: function(aGUID, aCallback) { - XPIDatabase.getAddonBySyncGUID(aGUID, function(aAddon) { - aCallback(aAddon ? aAddon.wrapper : null); + getAddonBySyncGUID: function XPI_getAddonBySyncGUID(aGUID, aCallback) { + XPIDatabase.getAddonBySyncGUID(aGUID, function getAddonBySyncGUID_getAddonBySyncGUID(aAddon) { + aCallback(createWrapper(aAddon)); }); }, @@ -4240,16 +3868,21 @@ this.XPIProvider = { * @param aCallback * A callback to pass an array of Addons to */ - getAddonsWithOperationsByTypes: function(aTypes, aCallback) { - let typesToGet = getAllAliasesForTypes(aTypes); - - XPIDatabase.getVisibleAddonsWithPendingOperations(typesToGet, function(aAddons) { - let results = aAddons.map(a => a.wrapper); - for (let install of XPIProvider.installs) { - if (install.state == AddonManager.STATE_INSTALLED && - !(install.addon.inDatabase)) - results.push(install.addon.wrapper); - } + getAddonsWithOperationsByTypes: + function XPI_getAddonsWithOperationsByTypes(aTypes, aCallback) { + XPIDatabase.getVisibleAddonsWithPendingOperations(aTypes, + function getAddonsWithOpsByTypes_getVisibleAddonsWithPendingOps(aAddons) { + // Tycho: let results = [createWrapper(a) for each (a in aAddons)]; + let results = []; + for each(let a in aAddons) { + results.push(createWrapper(a)); + } + + XPIProvider.installs.forEach(function(aInstall) { + if (aInstall.state == AddonManager.STATE_INSTALLED && + !(aInstall.addon.inDatabase)) + results.push(createWrapper(aInstall.addon)); + }); aCallback(results); }); }, @@ -4263,15 +3896,13 @@ this.XPIProvider = { * @param aCallback * A callback to pass the array of AddonInstalls to */ - getInstallsByTypes: function(aTypes, aCallback) { - let results = [...this.installs]; - if (aTypes) { - results = results.filter(install => { - return aTypes.includes(getExternalType(install.type)); - }); - } - - aCallback(results.map(install => install.wrapper)); + getInstallsByTypes: function XPI_getInstallsByTypes(aTypes, aCallback) { + let results = []; + this.installs.forEach(function(aInstall) { + if (!aTypes || aTypes.indexOf(aInstall.type) >= 0) + results.push(aInstall.wrapper); + }); + aCallback(results); }, /** @@ -4287,7 +3918,7 @@ this.XPIProvider = { * @see AddonManager.mapURIToAddonID * @see amIAddonManager.mapURIToAddonID */ - mapURIToAddonID: function(aURI) { + mapURIToAddonID: function XPI_mapURIToAddonID(aURI) { // Returns `null` instead of empty string if the URI can't be mapped. return AddonPathService.mapURIToAddonId(aURI) || null; }, @@ -4304,7 +3935,7 @@ this.XPIProvider = { * true if the newly enabled add-on will only become enabled after a * restart */ - addonChanged: function(aId, aType, aPendingRestart) { + addonChanged: function XPI_addonChanged(aId, aType, aPendingRestart) { // We only care about themes in this provider if (aType != "theme") return; @@ -4320,14 +3951,14 @@ this.XPIProvider = { let previousTheme = null; let newSkin = this.defaultSkin; let addons = XPIDatabase.getAddonsByType("theme"); - for (let theme of addons) { - if (!theme.visible) + addons.forEach(function(aTheme) { + if (!aTheme.visible) return; - if (theme.id == aId) - newSkin = theme.internalName; - else if (theme.userDisabled == false && !theme.pendingUninstall) - previousTheme = theme; - } + if (aTheme.id == aId) + newSkin = aTheme.internalName; + else if (aTheme.userDisabled == false && !aTheme.pendingUninstall) + previousTheme = aTheme; + }, this); if (aPendingRestart) { Services.prefs.setBoolPref(PREF_DSS_SWITCHPENDING, true); @@ -4362,11 +3993,11 @@ this.XPIProvider = { /** * Update the appDisabled property for all add-ons. */ - updateAddonAppDisabledStates: function() { + updateAddonAppDisabledStates: function XPI_updateAddonAppDisabledStates() { let addons = XPIDatabase.getAddons(); - for (let addon of addons) { - this.updateAddonDisabledState(addon); - } + addons.forEach(function(aAddon) { + this.updateAddonDisabledState(aAddon); + }, this); }, /** @@ -4375,8 +4006,9 @@ this.XPIProvider = { * @param aCallback * Function to call when operation is complete. */ - updateAddonRepositoryData: function(aCallback) { - XPIDatabase.getVisibleAddons(null, aAddons => { + updateAddonRepositoryData: function XPI_updateAddonRepositoryData(aCallback) { + let self = this; + XPIDatabase.getVisibleAddons(null, function UARD_getVisibleAddonsCallback(aAddons) { let pending = aAddons.length; logger.debug("updateAddonRepositoryData found " + pending + " visible add-ons"); if (pending == 0) { @@ -4390,17 +4022,18 @@ this.XPIProvider = { } for (let addon of aAddons) { - AddonRepository.getCachedAddonByID(addon.id, aRepoAddon => { + AddonRepository.getCachedAddonByID(addon.id, + function UARD_getCachedAddonCallback(aRepoAddon) { if (aRepoAddon) { logger.debug("updateAddonRepositoryData got info for " + addon.id); addon._repositoryAddon = aRepoAddon; addon.compatibilityOverrides = aRepoAddon.compatibilityOverrides; - this.updateAddonDisabledState(addon); + self.updateAddonDisabledState(addon); } notifyComplete(); }); - } + }; }); }, @@ -4408,7 +4041,7 @@ this.XPIProvider = { * When the previously selected theme is removed this method will be called * to enable the default theme. */ - enableDefaultTheme: function() { + enableDefaultTheme: function XPI_enableDefaultTheme() { logger.debug("Activating default theme"); let addon = XPIDatabase.getVisibleAddonForInternalName(this.defaultSkin); if (addon) { @@ -4438,9 +4071,8 @@ this.XPIProvider = { if (aWhat != "opened") return; - for (let [id, val] of this.activeAddons) { - aConnection.setAddonOptions( - id, { global: val.debugGlobal || val.bootstrapScope }); + for (let id of Object.keys(this.bootstrapScopes)) { + aConnection.setAddonOptions(id, { global: this.bootstrapScopes[id] }); } }, @@ -4449,7 +4081,7 @@ this.XPIProvider = { * * @see nsIObserver */ - observe: function(aSubject, aTopic, aData) { + observe: function XPI_observe(aSubject, aTopic, aData) { if (aTopic == NOTIFICATION_FLUSH_PERMISSIONS) { if (!aData || aData == XPI_PERMISSION) { this.importPermissions(); @@ -4466,95 +4098,25 @@ this.XPIProvider = { if (aTopic == "nsPref:changed") { switch (aData) { case PREF_EM_MIN_COMPAT_APP_VERSION: + case PREF_EM_MIN_COMPAT_PLATFORM_VERSION: this.minCompatibleAppVersion = Preferences.get(PREF_EM_MIN_COMPAT_APP_VERSION, null); - this.updateAddonAppDisabledStates(); - break; - case PREF_EM_MIN_COMPAT_PLATFORM_VERSION: this.minCompatiblePlatformVersion = Preferences.get(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, null); this.updateAddonAppDisabledStates(); break; - case PREF_XPI_SIGNATURES_REQUIRED: - this.updateAddonAppDisabledStates(); - break; - - case PREF_E10S_ADDON_BLOCKLIST: - case PREF_E10S_ADDON_POLICY: - XPIDatabase.updateAddonsBlockingE10s(); - break; } } }, /** - * Determine if an add-on should be blocking e10s if enabled. - * - * @param aAddon - * The add-on to test - * @return true if enabling the add-on should block e10s - */ - isBlockingE10s: function(aAddon) { - if (aAddon.type != "extension" && - aAddon.type != "webextension" && - aAddon.type != "theme") - return false; - - // The hotfix is exempt - let hotfixID = Preferences.get(PREF_EM_HOTFIX_ID, undefined); - if (hotfixID && hotfixID == aAddon.id) - return false; - - // The default theme is exempt - if (aAddon.type == "theme" && - aAddon.internalName == XPIProvider.defaultSkin) - return false; - - // System add-ons are exempt - let locName = aAddon._installLocation ? aAddon._installLocation.name - : undefined; - if (locName == KEY_APP_SYSTEM_DEFAULTS || - locName == KEY_APP_SYSTEM_ADDONS) - return false; - - if (isAddonPartOfE10SRollout(aAddon)) { - Preferences.set(PREF_E10S_HAS_NONEXEMPT_ADDON, true); - return false; - } - - logger.debug("Add-on " + aAddon.id + " blocks e10s rollout."); - return true; - }, - - /** - * In some cases having add-ons active blocks e10s but turning off e10s - * requires a restart so some add-ons that are normally restartless will - * require a restart to install or enable. - * - * @param aAddon - * The add-on to test - * @return true if enabling the add-on requires a restart - */ - e10sBlocksEnabling: function(aAddon) { - // If the preference isn't set then don't block anything - if (!Preferences.get(PREF_E10S_BLOCK_ENABLE, false)) - return false; - - // If e10s isn't active then don't block anything - if (!Services.appinfo.browserTabsRemoteAutostart) - return false; - - return this.isBlockingE10s(aAddon); - }, - - /** * Tests whether enabling an add-on will require a restart. * * @param aAddon * The add-on to test * @return true if the operation requires a restart */ - enableRequiresRestart: function(aAddon) { + enableRequiresRestart: function XPI_enableRequiresRestart(aAddon) { // If the platform couldn't have activated extensions then we can make // changes without any restart. if (!this.extensionsActive) @@ -4581,9 +4143,6 @@ this.XPIProvider = { return aAddon.internalName != this.currentSkin; } - if (this.e10sBlocksEnabling(aAddon)) - return true; - return !aAddon.bootstrap; }, @@ -4594,7 +4153,7 @@ this.XPIProvider = { * The add-on to test * @return true if the operation requires a restart */ - disableRequiresRestart: function(aAddon) { + disableRequiresRestart: function XPI_disableRequiresRestart(aAddon) { // If the platform couldn't have activated up extensions then we can make // changes without any restart. if (!this.extensionsActive) @@ -4640,7 +4199,7 @@ this.XPIProvider = { * The add-on to test * @return true if the operation requires a restart */ - installRequiresRestart: function(aAddon) { + installRequiresRestart: function XPI_installRequiresRestart(aAddon) { // If the platform couldn't have activated up extensions then we can make // changes without any restart. if (!this.extensionsActive) @@ -4674,9 +4233,6 @@ this.XPIProvider = { if (aAddon.disabled) return false; - if (this.e10sBlocksEnabling(aAddon)) - return true; - // Themes will require a restart (even if dynamic switching is enabled due // to some caching issues) and non-bootstrapped add-ons will require a // restart @@ -4690,7 +4246,7 @@ this.XPIProvider = { * The add-on to test * @return true if the operation requires a restart */ - uninstallRequiresRestart: function(aAddon) { + uninstallRequiresRestart: function XPI_uninstallRequiresRestart(aAddon) { // If the platform couldn't have activated up extensions then we can make // changes without any restart. if (!this.extensionsActive) @@ -4722,41 +4278,23 @@ this.XPIProvider = { * The type for the add-on * @param aMultiprocessCompatible * Boolean indicating whether the add-on is compatible with electrolysis. - * @param aRunInSafeMode - * Boolean indicating whether the add-on can run in safe mode. - * @param aDependencies - * An array of add-on IDs on which this add-on depends. - * @param hasEmbeddedWebExtension - * Boolean indicating whether the add-on has an embedded webextension. * @return a JavaScript scope */ - loadBootstrapScope: function(aId, aFile, aVersion, aType, - aMultiprocessCompatible, aRunInSafeMode, - aDependencies, hasEmbeddedWebExtension) { + loadBootstrapScope: function XPI_loadBootstrapScope(aId, aFile, aVersion, aType, + aMultiprocessCompatible) { // Mark the add-on as active for the crash reporter before loading this.bootstrappedAddons[aId] = { version: aVersion, type: aType, descriptor: aFile.persistentDescriptor, - multiprocessCompatible: aMultiprocessCompatible, - runInSafeMode: aRunInSafeMode, - dependencies: aDependencies, - hasEmbeddedWebExtension, + multiprocessCompatible: aMultiprocessCompatible }; this.persistBootstrappedAddons(); this.addAddonsToCrashReporter(); - this.activeAddons.set(aId, { - debugGlobal: null, - safeWrapper: null, - bootstrapScope: null, - // a Symbol passed to this add-on, which it can use to identify itself - instanceID: Symbol(aId), - }); - let activeAddon = this.activeAddons.get(aId); - // Locales only contain chrome and can't have bootstrap scripts if (aType == "locale") { + this.bootstrapScopes[aId] = null; return; } @@ -4768,11 +4306,10 @@ this.XPIProvider = { let interposition = Cc["@mozilla.org/addons/multiprocess-shims;1"]. getService(Ci.nsIAddonInterposition); Cu.setAddonInterposition(aId, interposition); - Cu.allowCPOWsInAddon(aId, true); } if (!aFile.exists()) { - activeAddon.bootstrapScope = + this.bootstrapScopes[aId] = new Cu.Sandbox(principal, { sandboxName: aFile.path, wantGlobalProperties: ["indexedDB"], addonId: aId, @@ -4784,12 +4321,8 @@ this.XPIProvider = { let uri = getURIForResourceInFile(aFile, "bootstrap.js").spec; if (aType == "dictionary") uri = "resource://gre/modules/addons/SpellCheckDictionaryBootstrap.js" - else if (aType == "webextension") - uri = "resource://gre/modules/addons/WebExtensionBootstrap.js" - else if (aType == "apiextension") - uri = "resource://gre/modules/addons/APIExtensionBootstrap.js" - activeAddon.bootstrapScope = + this.bootstrapScopes[aId] = new Cu.Sandbox(principal, { sandboxName: uri, wantGlobalProperties: ["indexedDB"], addonId: aId, @@ -4801,27 +4334,25 @@ this.XPIProvider = { try { // Copy the reason values from the global object into the bootstrap scope. for (let name in BOOTSTRAP_REASONS) - activeAddon.bootstrapScope[name] = BOOTSTRAP_REASONS[name]; + this.bootstrapScopes[aId][name] = BOOTSTRAP_REASONS[name]; // Add other stuff that extensions want. const features = [ "Worker", "ChromeWorker" ]; for (let feature of features) - activeAddon.bootstrapScope[feature] = gGlobalScope[feature]; + this.bootstrapScopes[aId][feature] = gGlobalScope[feature]; // Define a console for the add-on - activeAddon.bootstrapScope["console"] = new ConsoleAPI( - { consoleID: "addon/" + aId }); + this.bootstrapScopes[aId]["console"] = new ConsoleAPI({ consoleID: "addon/" + aId }); // As we don't want our caller to control the JS version used for the // bootstrap file, we run loadSubScript within the context of the // sandbox with the latest JS version set explicitly. - activeAddon.bootstrapScope.__SCRIPT_URI_SPEC__ = uri; + this.bootstrapScopes[aId].__SCRIPT_URI_SPEC__ = uri; Components.utils.evalInSandbox( "Components.classes['@mozilla.org/moz/jssubscript-loader;1'] \ .createInstance(Components.interfaces.mozIJSSubScriptLoader) \ - .loadSubScript(__SCRIPT_URI_SPEC__);", - activeAddon.bootstrapScope, "ECMAv5"); + .loadSubScript(__SCRIPT_URI_SPEC__);", this.bootstrapScopes[aId], "ECMAv5"); } catch (e) { logger.warn("Error loading bootstrap.js for " + aId, e); @@ -4831,8 +4362,7 @@ this.XPIProvider = { // initialized as otherwise, when it will be initialized, all addons' // globals will be added anyways if (this._toolboxProcessLoaded) { - BrowserToolboxProcess.setAddonOptions(aId, - { global: activeAddon.bootstrapScope }); + BrowserToolboxProcess.setAddonOptions(aId, { global: this.bootstrapScopes[aId] }); } }, @@ -4843,13 +4373,12 @@ this.XPIProvider = { * @param aId * The add-on's ID */ - unloadBootstrapScope: function(aId) { + unloadBootstrapScope: function XPI_unloadBootstrapScope(aId) { // In case the add-on was not multiprocess-compatible, deregister // any interpositions for it. Cu.setAddonInterposition(aId, null); - Cu.allowCPOWsInAddon(aId, false); - this.activeAddons.delete(aId); + delete this.bootstrapScopes[aId]; delete this.bootstrappedAddons[aId]; this.persistBootstrappedAddons(); this.addAddonsToCrashReporter(); @@ -4876,39 +4405,27 @@ this.XPIProvider = { * An object of additional key/value pairs to pass to the method in * the params argument */ - callBootstrapMethod: function(aAddon, aFile, aMethod, aReason, aExtraParams) { - if (!aAddon.id || !aAddon.version || !aAddon.type) { - throw new Error("aAddon must include an id, version, and type"); - } + callBootstrapMethod: function XPI_callBootstrapMethod(aAddon, aFile, aMethod, aReason, aExtraParams) { + // Never call any bootstrap methods in safe mode + if (Services.appinfo.inSafeMode) + return; - // Only run in safe mode if allowed to - let runInSafeMode = "runInSafeMode" in aAddon ? aAddon.runInSafeMode : canRunInSafeMode(aAddon); - if (Services.appinfo.inSafeMode && !runInSafeMode) + if (!aAddon.id || !aAddon.version || !aAddon.type) { + logger.error(new Error("aAddon must include an id, version, and type")); return; + } let timeStart = new Date(); - if (CHROME_TYPES.has(aAddon.type) && aMethod == "startup") { + if (aMethod == "startup") { logger.debug("Registering manifest for " + aFile.path); Components.manager.addBootstrappedManifestLocation(aFile); } try { // Load the scope if it hasn't already been loaded - let activeAddon = this.activeAddons.get(aAddon.id); - if (!activeAddon) { + if (!(aAddon.id in this.bootstrapScopes)) this.loadBootstrapScope(aAddon.id, aFile, aAddon.version, aAddon.type, - aAddon.multiprocessCompatible || false, - runInSafeMode, aAddon.dependencies, - aAddon.hasEmbeddedWebExtension || false); - activeAddon = this.activeAddons.get(aAddon.id); - } - - if (aMethod == "startup" || aMethod == "shutdown") { - if (!aExtraParams) { - aExtraParams = {}; - } - aExtraParams["instanceID"] = this.activeAddons.get(aAddon.id).instanceID; - } + aAddon.multiprocessCompatible || false); // Nothing to call for locales if (aAddon.type == "locale") @@ -4917,7 +4434,8 @@ this.XPIProvider = { let method = undefined; try { method = Components.utils.evalInSandbox(`${aMethod};`, - activeAddon.bootstrapScope, "ECMAv5"); + this.bootstrapScopes[aAddon.id], + "ECMAv5"); } catch (e) { // An exception will be caught if the expected method is not defined. @@ -4929,15 +4447,6 @@ this.XPIProvider = { return; } - // Extensions are automatically deinitialized in the correct order at shutdown. - if (aMethod == "shutdown" && aReason != BOOTSTRAP_REASONS.APP_SHUTDOWN) { - activeAddon.disable = true; - for (let addon of this.getDependentAddons(aAddon)) { - if (addon.active) - this.updateAddonDisabledState(addon); - } - } - let params = { id: aAddon.id, version: aAddon.version, @@ -4951,19 +4460,8 @@ this.XPIProvider = { } } - if (aAddon.hasEmbeddedWebExtension) { - if (aMethod == "startup") { - const webExtension = LegacyExtensionsUtils.getEmbeddedExtensionFor(params); - params.webExtension = { - startup: () => webExtension.startup(), - }; - } else if (aMethod == "shutdown") { - LegacyExtensionsUtils.getEmbeddedExtensionFor(params).shutdown(); - } - } - logger.debug("Calling bootstrap method " + aMethod + " on " + aAddon.id + " version " + - aAddon.version); + aAddon.version); try { method(params, aReason); } @@ -4972,13 +4470,7 @@ this.XPIProvider = { } } finally { - // Extensions are automatically initialized in the correct order at startup. - if (aMethod == "startup" && aReason != BOOTSTRAP_REASONS.APP_STARTUP) { - for (let addon of this.getDependentAddons(aAddon)) - this.updateAddonDisabledState(addon); - } - - if (CHROME_TYPES.has(aAddon.type) && aMethod == "shutdown" && aReason != BOOTSTRAP_REASONS.APP_SHUTDOWN) { + if (aMethod == "shutdown" && aReason != BOOTSTRAP_REASONS.APP_SHUTDOWN) { logger.debug("Removing manifest for " + aFile.path); Components.manager.removeBootstrappedManifestLocation(aFile); @@ -4989,7 +4481,6 @@ this.XPIProvider = { } } } - this.setTelemetry(aAddon.id, aMethod + "_MS", new Date() - timeStart); } }, @@ -5006,13 +4497,11 @@ this.XPIProvider = { * @param aSoftDisabled * Value for the softDisabled property. If undefined the value will * not change. If true this will force userDisabled to be true - * @return a tri-state indicating the action taken for the add-on: - * - undefined: The add-on did not change state - * - true: The add-on because disabled - * - false: The add-on became enabled * @throws if addon is not a DBAddonInternal */ - updateAddonDisabledState: function(aAddon, aUserDisabled, aSoftDisabled) { + updateAddonDisabledState: function XPI_updateAddonDisabledState(aAddon, + aUserDisabled, + aSoftDisabled) { if (!(aAddon.inDatabase)) throw new Error("Can only update addon states for installed addons."); if (aUserDisabled !== undefined && aSoftDisabled !== undefined) { @@ -5038,7 +4527,7 @@ this.XPIProvider = { if (aAddon.userDisabled == aUserDisabled && aAddon.appDisabled == appDisabled && aAddon.softDisabled == aSoftDisabled) - return undefined; + return; let wasDisabled = aAddon.disabled; let isDisabled = aUserDisabled || aSoftDisabled || appDisabled; @@ -5048,28 +4537,31 @@ this.XPIProvider = { let appDisabledChanged = aAddon.appDisabled != appDisabled; // Update the properties in the database. - XPIDatabase.setAddonProperties(aAddon, { - userDisabled: aUserDisabled, - appDisabled: appDisabled, - softDisabled: aSoftDisabled - }); - - let wrapper = aAddon.wrapper; + // We never persist this for experiments because the disabled flags + // are controlled by the Experiments Manager. + if (aAddon.type != "experiment") { + XPIDatabase.setAddonProperties(aAddon, { + userDisabled: aUserDisabled, + appDisabled: appDisabled, + softDisabled: aSoftDisabled + }); + } if (appDisabledChanged) { AddonManagerPrivate.callAddonListeners("onPropertyChanged", - wrapper, - ["appDisabled"]); + aAddon, + ["appDisabled"]); } // If the add-on is not visible or the add-on is not changing state then // there is no need to do anything else if (!aAddon.visible || (wasDisabled == isDisabled)) - return undefined; + return; // Flag that active states in the database need to be updated on shutdown Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, true); + let wrapper = createWrapper(aAddon); // Have we just gone back to the current state? if (isDisabled != aAddon.active) { AddonManagerPrivate.callAddonListeners("onOperationCancelled", wrapper); @@ -5088,10 +4580,10 @@ this.XPIProvider = { if (!needsRestart) { XPIDatabase.updateAddonActive(aAddon, !isDisabled); - if (isDisabled) { if (aAddon.bootstrap) { - this.callBootstrapMethod(aAddon, aAddon._sourceBundle, "shutdown", + let file = aAddon._installLocation.getLocationForID(aAddon.id); + this.callBootstrapMethod(aAddon, file, "shutdown", BOOTSTRAP_REASONS.ADDON_DISABLE); this.unloadBootstrapScope(aAddon.id); } @@ -5099,31 +4591,13 @@ this.XPIProvider = { } else { if (aAddon.bootstrap) { - this.callBootstrapMethod(aAddon, aAddon._sourceBundle, "startup", + let file = aAddon._installLocation.getLocationForID(aAddon.id); + this.callBootstrapMethod(aAddon, file, "startup", BOOTSTRAP_REASONS.ADDON_ENABLE); } AddonManagerPrivate.callAddonListeners("onEnabled", wrapper); } } - else if (aAddon.bootstrap) { - // Something blocked the restartless add-on from enabling or disabling - // make sure it happens on the next startup - if (isDisabled) { - this.bootstrappedAddons[aAddon.id].disable = true; - } - else { - this.bootstrappedAddons[aAddon.id] = { - version: aAddon.version, - type: aAddon.type, - descriptor: aAddon._sourceBundle.persistentDescriptor, - multiprocessCompatible: aAddon.multiprocessCompatible, - runInSafeMode: canRunInSafeMode(aAddon), - dependencies: aAddon.dependencies, - hasEmbeddedWebExtension: aAddon.hasEmbeddedWebExtension, - }; - this.persistBootstrappedAddons(); - } - } } // Sync with XPIStates. @@ -5139,8 +4613,6 @@ this.XPIProvider = { // Notify any other providers that a new theme has been enabled if (aAddon.type == "theme" && !isDisabled) AddonManagerPrivate.notifyAddonChanged(aAddon.id, aAddon.type, needsRestart); - - return isDisabled; }, /** @@ -5156,7 +4628,7 @@ this.XPIProvider = { * @throws if the addon cannot be uninstalled because it is in an install * location that does not allow it */ - uninstallAddon: function(aAddon, aForcePending) { + uninstallAddon: function XPI_uninstallAddon(aAddon, aForcePending) { if (!(aAddon.inDatabase)) throw new Error("Cannot uninstall addon " + aAddon.id + " because it is not installed"); @@ -5174,7 +4646,8 @@ this.XPIProvider = { if (makePending && aAddon.pendingUninstall) throw new Error("Add-on is already marked to be uninstalled"); - aAddon._hasResourceCache.clear(); + if ("_hasResourceCache" in aAddon) + aAddon._hasResourceCache = new Map(); if (aAddon._updateCheck) { logger.debug("Cancel in-progress update check for " + aAddon.id); @@ -5185,15 +4658,11 @@ this.XPIProvider = { if (makePending) { // We create an empty directory in the staging directory to indicate - // that an uninstall is necessary on next startup. Temporary add-ons are - // automatically uninstalled on shutdown anyway so there is no need to - // do this for them. - if (aAddon._installLocation.name != KEY_APP_TEMPORARY) { - let stage = aAddon._installLocation.getStagingDir(); - stage.append(aAddon.id); - if (!stage.exists()) - stage.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - } + // that an uninstall is necessary on next startup. + let stage = aAddon._installLocation.getStagingDir(); + stage.append(aAddon.id); + if (!stage.exists()) + stage.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); XPIDatabase.setAddonProperties(aAddon, { pendingUninstall: true @@ -5212,7 +4681,7 @@ this.XPIProvider = { if (!aAddon.visible) return; - let wrapper = aAddon.wrapper; + let wrapper = createWrapper(aAddon); // If the add-on wasn't already pending uninstall then notify listeners. if (!wasPending) { @@ -5228,7 +4697,7 @@ this.XPIProvider = { function revealAddon(aAddon) { XPIDatabase.makeAddonVisible(aAddon); - let wrappedAddon = aAddon.wrapper; + let wrappedAddon = createWrapper(aAddon); AddonManagerPrivate.callAddonListeners("onInstalling", wrappedAddon, false); if (!aAddon.disabled && !XPIProvider.enableRequiresRestart(aAddon)) { @@ -5236,11 +4705,12 @@ this.XPIProvider = { } if (aAddon.bootstrap) { - XPIProvider.callBootstrapMethod(aAddon, aAddon._sourceBundle, + let file = aAddon._installLocation.getLocationForID(aAddon.id); + XPIProvider.callBootstrapMethod(aAddon, file, "install", BOOTSTRAP_REASONS.ADDON_INSTALL); if (aAddon.active) { - XPIProvider.callBootstrapMethod(aAddon, aAddon._sourceBundle, + XPIProvider.callBootstrapMethod(aAddon, file, "startup", BOOTSTRAP_REASONS.ADDON_INSTALL); } else { @@ -5262,15 +4732,16 @@ this.XPIProvider = { if (!makePending) { if (aAddon.bootstrap) { + let file = aAddon._installLocation.getLocationForID(aAddon.id); if (aAddon.active) { - this.callBootstrapMethod(aAddon, aAddon._sourceBundle, "shutdown", + this.callBootstrapMethod(aAddon, file, "shutdown", BOOTSTRAP_REASONS.ADDON_UNINSTALL); } - this.callBootstrapMethod(aAddon, aAddon._sourceBundle, "uninstall", + this.callBootstrapMethod(aAddon, file, "uninstall", BOOTSTRAP_REASONS.ADDON_UNINSTALL); this.unloadBootstrapScope(aAddon.id); - flushChromeCaches(); + flushStartupCache(); } aAddon._installLocation.uninstallAddon(aAddon.id); XPIDatabase.removeAddonMetadata(aAddon); @@ -5297,14 +4768,14 @@ this.XPIProvider = { * @param aAddon * The DBAddonInternal to cancel uninstall for */ - cancelUninstallAddon: function(aAddon) { + cancelUninstallAddon: function XPI_cancelUninstallAddon(aAddon) { if (!(aAddon.inDatabase)) throw new Error("Can only cancel uninstall for installed addons."); + if (!aAddon.pendingUninstall) throw new Error("Add-on is not marked to be uninstalled"); - if (aAddon._installLocation.name != KEY_APP_TEMPORARY) - aAddon._installLocation.cleanStagingDir([aAddon.id]); + aAddon._installLocation.cleanStagingDir([aAddon.id]); XPIDatabase.setAddonProperties(aAddon, { pendingUninstall: false @@ -5316,7 +4787,7 @@ this.XPIProvider = { Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, true); // TODO hide hidden add-ons (bug 557710) - let wrapper = aAddon.wrapper; + let wrapper = createWrapper(aAddon); AddonManagerPrivate.callAddonListeners("onOperationCancelled", wrapper); if (aAddon.bootstrap && !aAddon.disabled && !this.enableRequiresRestart(aAddon)) { @@ -5342,81 +4813,262 @@ function getHashStringForCrypto(aCrypto) { } /** - * Base class for objects that manage the installation of an addon. - * This class isn't instantiated directly, see the derived classes below. + * Instantiates an AddonInstall. + * + * @param aInstallLocation + * The install location the add-on will be installed into + * @param aUrl + * The nsIURL to get the add-on from. If this is an nsIFileURL then + * the add-on will not need to be downloaded + * @param aHash + * An optional hash for the add-on + * @param aReleaseNotesURI + * An optional nsIURI of release notes for the add-on + * @param aExistingAddon + * The add-on this install will update if known + * @param aBrowser + * The browser performing the install + * @throws if the url is the url of a local file and the hash does not match + * or the add-on does not contain an valid install manifest */ -class AddonInstall { +function AddonInstall(aInstallLocation, aUrl, aHash, aReleaseNotesURI, + aExistingAddon, aBrowser) { + this.wrapper = new AddonInstallWrapper(this); + this.installLocation = aInstallLocation; + this.sourceURI = aUrl; + this.releaseNotesURI = aReleaseNotesURI; + if (aHash) { + let hashSplit = aHash.toLowerCase().split(":"); + this.originalHash = { + algorithm: hashSplit[0], + data: hashSplit[1] + }; + } + this.hash = this.originalHash; + this.browser = aBrowser; + this.listeners = []; + this.icons = {}; + this.existingAddon = aExistingAddon; + this.error = 0; + this.window = aBrowser ? aBrowser.contentWindow : null; + + // Giving each instance of AddonInstall a reference to the logger. + this.logger = logger; +} + +AddonInstall.prototype = { + installLocation: null, + wrapper: null, + stream: null, + crypto: null, + originalHash: null, + hash: null, + browser: null, + badCertHandler: null, + listeners: null, + restartDownload: false, + + name: null, + type: null, + version: null, + icons: null, + releaseNotesURI: null, + sourceURI: null, + file: null, + ownsTempFile: false, + certificate: null, + certName: null, + + linkedInstalls: null, + existingAddon: null, + addon: null, + + state: null, + error: null, + progress: null, + maxProgress: null, + /** - * Instantiates an AddonInstall. + * Initialises this install to be a staged install waiting to be applied * - * @param aInstallLocation - * The install location the add-on will be installed into - * @param aUrl - * The nsIURL to get the add-on from. If this is an nsIFileURL then - * the add-on will not need to be downloaded - * @param aHash - * An optional hash for the add-on - * @param aExistingAddon - * The add-on this install will update if known + * @param aManifest + * The cached manifest for the staged install + */ + initStagedInstall: function AI_initStagedInstall(aManifest) { + this.name = aManifest.name; + this.type = aManifest.type; + this.version = aManifest.version; + this.icons = aManifest.icons; + this.releaseNotesURI = aManifest.releaseNotesURI ? + NetUtil.newURI(aManifest.releaseNotesURI) : + null + this.sourceURI = aManifest.sourceURI ? + NetUtil.newURI(aManifest.sourceURI) : + null; + this.file = null; + this.addon = aManifest; + + this.state = AddonManager.STATE_INSTALLED; + + XPIProvider.installs.push(this); + }, + + /** + * Initialises this install to be an install from a local file. + * + * @param aCallback + * The callback to pass the initialised AddonInstall to */ - constructor(aInstallLocation, aUrl, aHash, aExistingAddon) { - this.wrapper = new AddonInstallWrapper(this); - this.installLocation = aInstallLocation; - this.sourceURI = aUrl; - - if (aHash) { - let hashSplit = aHash.toLowerCase().split(":"); - this.originalHash = { - algorithm: hashSplit[0], - data: hashSplit[1] - }; + initLocalInstall: function AI_initLocalInstall(aCallback) { + aCallback = makeSafe(aCallback); + this.file = this.sourceURI.QueryInterface(Ci.nsIFileURL).file; + + if (!this.file.exists()) { + logger.warn("XPI file " + this.file.path + " does not exist"); + this.state = AddonManager.STATE_DOWNLOAD_FAILED; + this.error = AddonManager.ERROR_NETWORK_FAILURE; + aCallback(this); + return; } - this.hash = this.originalHash; - this.existingAddon = aExistingAddon; - this.releaseNotesURI = null; - this.listeners = []; - this.icons = {}; - this.error = 0; + this.state = AddonManager.STATE_DOWNLOADED; + this.progress = this.file.fileSize; + this.maxProgress = this.file.fileSize; - this.progress = 0; - this.maxProgress = -1; + if (this.hash) { + let crypto = Cc["@mozilla.org/security/hash;1"]. + createInstance(Ci.nsICryptoHash); + try { + crypto.initWithString(this.hash.algorithm); + } + catch (e) { + logger.warn("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e); + this.state = AddonManager.STATE_DOWNLOAD_FAILED; + this.error = AddonManager.ERROR_INCORRECT_HASH; + aCallback(this); + return; + } - // Giving each instance of AddonInstall a reference to the logger. - this.logger = logger; + let fis = Cc["@mozilla.org/network/file-input-stream;1"]. + createInstance(Ci.nsIFileInputStream); + fis.init(this.file, -1, -1, false); + crypto.updateFromStream(fis, this.file.fileSize); + let calculatedHash = getHashStringForCrypto(crypto); + if (calculatedHash != this.hash.data) { + logger.warn("File hash (" + calculatedHash + ") did not match provided hash (" + + this.hash.data + ")"); + this.state = AddonManager.STATE_DOWNLOAD_FAILED; + this.error = AddonManager.ERROR_INCORRECT_HASH; + aCallback(this); + return; + } + } - this.name = null; - this.type = null; - this.version = null; + try { + let self = this; + this.loadManifest(function initLocalInstall_loadManifest() { + XPIDatabase.getVisibleAddonForID(self.addon.id, function initLocalInstall_getVisibleAddon(aAddon) { + self.existingAddon = aAddon; + if (aAddon) + applyBlocklistChanges(aAddon, self.addon); + self.addon.updateDate = Date.now(); + self.addon.installDate = aAddon ? aAddon.installDate : self.addon.updateDate; + + if (!self.addon.isCompatible) { + // TODO Should we send some event here? + self.state = AddonManager.STATE_CHECKING; + new UpdateChecker(self.addon, { + onUpdateFinished: function updateChecker_onUpdateFinished(aAddon) { + self.state = AddonManager.STATE_DOWNLOADED; + XPIProvider.installs.push(self); + AddonManagerPrivate.callInstallListeners("onNewInstall", + self.listeners, + self.wrapper); + + aCallback(self); + } + }, AddonManager.UPDATE_WHEN_ADDON_INSTALLED); + } + else { + XPIProvider.installs.push(self); + AddonManagerPrivate.callInstallListeners("onNewInstall", + self.listeners, + self.wrapper); - this.file = null; - this.ownsTempFile = null; - this.certificate = null; - this.certName = null; + aCallback(self); + } + }); + }); + } + catch (e) { + this.state = AddonManager.STATE_DOWNLOAD_FAILED; + if (e.webext) { + logger.warn("WebExtension XPI", e); + this.error = AddonManager.ERROR_WEBEXT_FILE; + } else { + logger.warn("Invalid XPI", e); + this.error = AddonManager.ERROR_CORRUPT_FILE; + } + aCallback(this); + return; + } + }, - this.linkedInstalls = null; - this.addon = null; - this.state = null; + /** + * Initialises this install to be a download from a remote url. + * + * @param aCallback + * The callback to pass the initialised AddonInstall to + * @param aName + * An optional name for the add-on + * @param aType + * An optional type for the add-on + * @param aIcons + * Optional icons for the add-on + * @param aVersion + * An optional version for the add-on + */ + initAvailableDownload: function AI_initAvailableDownload(aName, aType, aIcons, aVersion, aCallback) { + this.state = AddonManager.STATE_AVAILABLE; + this.name = aName; + this.type = aType; + this.version = aVersion; + this.icons = aIcons; + this.progress = 0; + this.maxProgress = -1; - XPIProvider.installs.add(this); - } + XPIProvider.installs.push(this); + AddonManagerPrivate.callInstallListeners("onNewInstall", this.listeners, + this.wrapper); + + makeSafe(aCallback)(this); + }, /** * Starts installation of this add-on from whatever state it is currently at * if possible. * - * Note this method is overridden to handle additional state in - * the subclassses below. - * * @throws if installation cannot proceed from the current state */ - install() { + install: function AI_install() { switch (this.state) { + case AddonManager.STATE_AVAILABLE: + this.startDownload(); + break; case AddonManager.STATE_DOWNLOADED: this.startInstall(); break; - case AddonManager.STATE_POSTPONED: - logger.debug(`Postponing install of ${this.addon.id}`); + case AddonManager.STATE_DOWNLOAD_FAILED: + case AddonManager.STATE_INSTALL_FAILED: + case AddonManager.STATE_CANCELLED: + this.removeTemporaryFile(); + this.state = AddonManager.STATE_AVAILABLE; + this.error = 0; + this.progress = 0; + this.maxProgress = -1; + this.hash = this.originalHash; + XPIProvider.installs.push(this); + this.startDownload(); break; case AddonManager.STATE_DOWNLOADING: case AddonManager.STATE_CHECKING: @@ -5426,18 +5078,21 @@ class AddonInstall { default: throw new Error("Cannot start installing from this state"); } - } + }, /** * Cancels installation of this add-on. * - * Note this method is overridden to handle additional state in - * the subclass DownloadAddonInstall. - * * @throws if installation cannot be cancelled from the current state */ - cancel() { + cancel: function AI_cancel() { switch (this.state) { + case AddonManager.STATE_DOWNLOADING: + if (this.channel) { + logger.debug("Cancelling download of " + this.sourceURI.spec); + this.channel.cancel(Cr.NS_BINDING_ABORTED); + } + break; case AddonManager.STATE_AVAILABLE: case AddonManager.STATE_DOWNLOADED: logger.debug("Cancelling download of " + this.sourceURI.spec); @@ -5462,28 +5117,16 @@ class AddonInstall { this.existingAddon.pendingUpgrade = null; } - AddonManagerPrivate.callAddonListeners("onOperationCancelled", this.addon.wrapper); + AddonManagerPrivate.callAddonListeners("onOperationCancelled", createWrapper(this.addon)); AddonManagerPrivate.callInstallListeners("onInstallCancelled", this.listeners, this.wrapper); break; - case AddonManager.STATE_POSTPONED: - logger.debug(`Cancelling postponed install of ${this.addon.id}`); - this.state = AddonManager.STATE_CANCELLED; - XPIProvider.removeActiveInstall(this); - AddonManagerPrivate.callInstallListeners("onInstallCancelled", - this.listeners, this.wrapper); - this.removeTemporaryFile(); - - let stagingDir = this.installLocation.getStagingDir(); - let stagedAddon = stagingDir.clone(); - - this.unstageInstall(stagedAddon); default: throw new Error("Cannot cancel install of " + this.sourceURI.spec + " from this state (" + this.state + ")"); } - } + }, /** * Adds an InstallListener for this instance if the listener is not already @@ -5492,10 +5135,10 @@ class AddonInstall { * @param aListener * The InstallListener to add */ - addListener(aListener) { - if (!this.listeners.some(function(i) { return i == aListener; })) + addListener: function AI_addListener(aListener) { + if (!this.listeners.some(function addListener_matchListener(i) { return i == aListener; })) this.listeners.push(aListener); - } + }, /** * Removes an InstallListener for this instance if it is registered. @@ -5503,16 +5146,16 @@ class AddonInstall { * @param aListener * The InstallListener to remove */ - removeListener(aListener) { - this.listeners = this.listeners.filter(function(i) { + removeListener: function AI_removeListener(aListener) { + this.listeners = this.listeners.filter(function removeListener_filterListener(i) { return i != aListener; }); - } + }, /** * Removes the temporary file owned by this AddonInstall if there is one. */ - removeTemporaryFile() { + removeTemporaryFile: function AI_removeTemporaryFile() { // Only proceed if this AddonInstall owns its XPI file if (!this.ownsTempFile) { this.logger.debug("removeTemporaryFile: " + this.sourceURI.spec + " does not own temp file"); @@ -5530,58 +5173,17 @@ class AddonInstall { this.sourceURI.spec, e); } - } + }, /** * Updates the sourceURI and releaseNotesURI values on the Addon being * installed by this AddonInstall instance. */ - updateAddonURIs() { + updateAddonURIs: function AI_updateAddonURIs() { this.addon.sourceURI = this.sourceURI.spec; if (this.releaseNotesURI) this.addon.releaseNotesURI = this.releaseNotesURI.spec; - } - - /** - * Fills out linkedInstalls with AddonInstall instances for the other files - * in a multi-package XPI. - * - * @param aFiles - * An array of { entryName, file } for each remaining file from the - * multi-package XPI. - */ - _createLinkedInstalls(aFiles) { - return Task.spawn((function*() { - if (aFiles.length == 0) - return; - - // Create new AddonInstall instances for every remaining file - if (!this.linkedInstalls) - this.linkedInstalls = []; - - for (let { entryName, file } of aFiles) { - logger.debug("Creating linked install from " + entryName); - let install = yield createLocalInstall(file); - - // Make the new install own its temporary file - install.ownsTempFile = true; - - this.linkedInstalls.push(install); - - // If one of the internal XPIs was multipackage then move its linked - // installs to the outer install - if (install.linkedInstalls) { - this.linkedInstalls.push(...install.linkedInstalls); - install.linkedInstalls = null; - } - - install.sourceURI = this.sourceURI; - install.releaseNotesURI = this.releaseNotesURI; - if (install.state != AddonManager.STATE_DOWNLOAD_FAILED) - install.updateAddonURIs(); - } - }).bind(this)); - } + }, /** * Loads add-on manifests from a multi-package XPI file. Each of the @@ -5593,683 +5195,216 @@ class AddonInstall { * @param aZipReader * An open nsIZipReader for the multi-package XPI's files. This will * be closed before this method returns. - */ - _loadMultipackageManifests(aZipReader) { - return Task.spawn((function*() { - let files = []; - let entries = aZipReader.findEntries("(*.[Xx][Pp][Ii]|*.[Jj][Aa][Rr])"); - while (entries.hasMore()) { - let entryName = entries.getNext(); - let file = getTemporaryFile(); - try { - aZipReader.extract(entryName, file); - files.push({ entryName, file }); - } - catch (e) { - logger.warn("Failed to extract " + entryName + " from multi-package " + - "XPI", e); - file.remove(false); - } - } - - aZipReader.close(); - - if (files.length == 0) { - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, - "Multi-package XPI does not contain any packages to install"]); - } - - let addon = null; - - // Find the first file that is a valid install and use it for - // the add-on that this AddonInstall instance will install. - for (let { entryName, file } of files) { - this.removeTemporaryFile(); - try { - yield this.loadManifest(file); - logger.debug("Base multi-package XPI install came from " + entryName); - this.file = file; - this.ownsTempFile = true; - - yield this._createLinkedInstalls(files.filter(f => f.file != file)); - return undefined; - } - catch (e) { - // _createLinkedInstalls will log errors when it tries to process this - // file - } - } - - // No valid add-on was found, delete all the temporary files - for (let { file } of files) { - try { - file.remove(true); - } catch (e) { - this.logger.warn("Could not remove temp file " + file.path); - } - } - - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, - "Multi-package XPI does not contain any valid packages to install"]); - }).bind(this)); - } - - /** - * Called after the add-on is a local file and the signature and install - * manifest can be read. - * * @param aCallback - * A function to call when the manifest has been loaded - * @throws if the add-on does not contain a valid install manifest or the - * XPI is incorrectly signed - */ - loadManifest(file) { - return Task.spawn((function*() { - let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"]. - createInstance(Ci.nsIZipReader); + * A function to call when all of the add-on manifests have been + * loaded. Because this loadMultipackageManifests is an internal API + * we don't exception-wrap this callback + */ + _loadMultipackageManifests: function AI_loadMultipackageManifests(aZipReader, + aCallback) { + let files = []; + let entries = aZipReader.findEntries("(*.[Xx][Pp][Ii]|*.[Jj][Aa][Rr])"); + while (entries.hasMore()) { + let entryName = entries.getNext(); + var target = getTemporaryFile(); try { - zipreader.open(file); + aZipReader.extract(entryName, target); + files.push(target); } catch (e) { - zipreader.close(); - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, e]); - } - - try { - // loadManifestFromZipReader performs the certificate verification for us - this.addon = yield loadManifestFromZipReader(zipreader, this.installLocation); - } - catch (e) { - zipreader.close(); - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, e]); - } - - // A multi-package XPI is a container, the add-ons it holds each - // have their own id. Everything else had better have an id here. - if (!this.addon.id && this.addon.type != "multipackage") { - let err = new Error(`Cannot find id for addon ${file.path}`); - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, err]); + logger.warn("Failed to extract " + entryName + " from multi-package " + + "XPI", e); + target.remove(false); } + } - if (this.existingAddon) { - // Check various conditions related to upgrades - if (this.addon.id != this.existingAddon.id) { - zipreader.close(); - return Promise.reject([AddonManager.ERROR_INCORRECT_ID, - `Refusing to upgrade addon ${this.existingAddon.id} to different ID {this.addon.id}`]); - } - - if (this.addon.type == "multipackage") { - zipreader.close(); - return Promise.reject([AddonManager.ERROR_UNEXPECTED_ADDON_TYPE, - `Refusing to upgrade addon ${this.existingAddon.id} to a multi-package xpi`]); - } - - if (this.existingAddon.type == "webextension" && this.addon.type != "webextension") { - zipreader.close(); - return Promise.reject([AddonManager.ERROR_UNEXPECTED_ADDON_TYPE, - "WebExtensions may not be upated to other extension types"]); - } - } + aZipReader.close(); - if (mustSign(this.addon.type)) { - if (this.addon.signedState <= AddonManager.SIGNEDSTATE_MISSING) { - // This add-on isn't properly signed by a signature that chains to the - // trusted root. - let state = this.addon.signedState; - this.addon = null; - zipreader.close(); + if (files.length == 0) { + throw new Error("Multi-package XPI does not contain any packages " + + "to install"); + } - if (state == AddonManager.SIGNEDSTATE_MISSING) - return Promise.reject([AddonManager.ERROR_SIGNEDSTATE_REQUIRED, - "signature is required but missing"]) + let addon = null; - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, - "signature verification failed"]) - } + // Find the first file that has a valid install manifest and use it for + // the add-on that this AddonInstall instance will install. + while (files.length > 0) { + this.removeTemporaryFile(); + this.file = files.shift(); + this.ownsTempFile = true; + try { + addon = loadManifestFromZipFile(this.file); + break; } - else if (this.addon.signedState == AddonManager.SIGNEDSTATE_UNKNOWN || - this.addon.signedState == AddonManager.SIGNEDSTATE_NOT_REQUIRED) { - // Check object signing certificate, if any - let x509 = zipreader.getSigningCert(null); - if (x509) { - logger.debug("Verifying XPI signature"); - if (verifyZipSigning(zipreader, x509)) { - this.certificate = x509; - if (this.certificate.commonName.length > 0) { - this.certName = this.certificate.commonName; - } else { - this.certName = this.certificate.organization; - } - } else { - zipreader.close(); - return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, - "XPI is incorrectly signed"]); - } - } + catch (e) { + logger.warn(this.file.leafName + " cannot be installed from multi-package " + + "XPI", e); } - - if (this.addon.type == "multipackage") - return this._loadMultipackageManifests(zipreader); - - zipreader.close(); - - this.updateAddonURIs(); - - this.addon._install = this; - this.name = this.addon.selectedLocale.name; - this.type = this.addon.type; - this.version = this.addon.version; - - // Setting the iconURL to something inside the XPI locks the XPI and - // makes it impossible to delete on Windows. - - // Try to load from the existing cache first - let repoAddon = yield new Promise(resolve => AddonRepository.getCachedAddonByID(this.addon.id, resolve)); - - // It wasn't there so try to re-download it - if (!repoAddon) { - yield new Promise(resolve => AddonRepository.cacheAddons([this.addon.id], resolve)); - repoAddon = yield new Promise(resolve => AddonRepository.getCachedAddonByID(this.addon.id, resolve)); - } - - this.addon._repositoryAddon = repoAddon; - this.name = this.name || this.addon._repositoryAddon.name; - this.addon.compatibilityOverrides = repoAddon ? - repoAddon.compatibilityOverrides : - null; - this.addon.appDisabled = !isUsableAddon(this.addon); - return undefined; - }).bind(this)); - } - - // TODO This relies on the assumption that we are always installing into the - // highest priority install location so the resulting add-on will be visible - // overriding any existing copy in another install location (bug 557710). - /** - * Installs the add-on into the install location. - */ - startInstall() { - this.state = AddonManager.STATE_INSTALLING; - if (!AddonManagerPrivate.callInstallListeners("onInstallStarted", - this.listeners, this.wrapper)) { - this.state = AddonManager.STATE_DOWNLOADED; - XPIProvider.removeActiveInstall(this); - AddonManagerPrivate.callInstallListeners("onInstallCancelled", - this.listeners, this.wrapper) - return; } - // Find and cancel any pending installs for the same add-on in the same - // install location - for (let aInstall of XPIProvider.installs) { - if (aInstall.state == AddonManager.STATE_INSTALLED && - aInstall.installLocation == this.installLocation && - aInstall.addon.id == this.addon.id) { - logger.debug("Cancelling previous pending install of " + aInstall.addon.id); - aInstall.cancel(); - } + if (!addon) { + // No valid add-on was found + aCallback(); + return; } - let isUpgrade = this.existingAddon && - this.existingAddon._installLocation == this.installLocation; - let requiresRestart = XPIProvider.installRequiresRestart(this.addon); - - logger.debug("Starting install of " + this.addon.id + " from " + this.sourceURI.spec); - AddonManagerPrivate.callAddonListeners("onInstalling", - this.addon.wrapper, - requiresRestart); - - let stagedAddon = this.installLocation.getStagingDir(); - - Task.spawn((function*() { - let installedUnpacked = 0; - - yield this.installLocation.requestStagingDir(); - - // remove any previously staged files - yield this.unstageInstall(stagedAddon); - - stagedAddon.append(this.addon.id); - stagedAddon.leafName = this.addon.id + ".xpi"; - - installedUnpacked = yield this.stageInstall(requiresRestart, stagedAddon, isUpgrade); - - if (requiresRestart) { - this.state = AddonManager.STATE_INSTALLED; - AddonManagerPrivate.callInstallListeners("onInstallEnded", - this.listeners, this.wrapper, - this.addon.wrapper); - } - else { - // The install is completed so it should be removed from the active list - XPIProvider.removeActiveInstall(this); - - // Deactivate and remove the old add-on as necessary - let reason = BOOTSTRAP_REASONS.ADDON_INSTALL; - if (this.existingAddon) { - if (Services.vc.compare(this.existingAddon.version, this.addon.version) < 0) - reason = BOOTSTRAP_REASONS.ADDON_UPGRADE; - else - reason = BOOTSTRAP_REASONS.ADDON_DOWNGRADE; - - if (this.existingAddon.bootstrap) { - let file = this.existingAddon._sourceBundle; - if (this.existingAddon.active) { - XPIProvider.callBootstrapMethod(this.existingAddon, file, - "shutdown", reason, - { newVersion: this.addon.version }); - } - - XPIProvider.callBootstrapMethod(this.existingAddon, file, - "uninstall", reason, - { newVersion: this.addon.version }); - XPIProvider.unloadBootstrapScope(this.existingAddon.id); - flushChromeCaches(); - } - - if (!isUpgrade && this.existingAddon.active) { - XPIDatabase.updateAddonActive(this.existingAddon, false); - } - } - - // Install the new add-on into its final location - let existingAddonID = this.existingAddon ? this.existingAddon.id : null; - let file = this.installLocation.installAddon({ - id: this.addon.id, - source: stagedAddon, - existingAddonID - }); - - // Update the metadata in the database - this.addon._sourceBundle = file; - this.addon.visible = true; - - if (isUpgrade) { - this.addon = XPIDatabase.updateAddonMetadata(this.existingAddon, this.addon, - file.persistentDescriptor); - let state = XPIStates.getAddon(this.installLocation.name, this.addon.id); - if (state) { - state.syncWithDB(this.addon, true); - } else { - logger.warn("Unexpected missing XPI state for add-on ${id}", this.addon); + this.addon = addon; + + this.updateAddonURIs(); + + this.addon._install = this; + this.name = this.addon.selectedLocale.name || this.addon.defaultLocale.name; + this.type = this.addon.type; + this.version = this.addon.version; + + // Setting the iconURL to something inside the XPI locks the XPI and + // makes it impossible to delete on Windows. + //let newIcon = createWrapper(this.addon).iconURL; + //if (newIcon) + // this.iconURL = newIcon; + + // Create new AddonInstall instances for every remaining file + if (files.length > 0) { + this.linkedInstalls = []; + let count = 0; + let self = this; + files.forEach(function(file) { + AddonInstall.createInstall(function loadMultipackageManifests_createInstall(aInstall) { + // Ignore bad add-ons (createInstall will have logged the error) + if (aInstall.state == AddonManager.STATE_DOWNLOAD_FAILED) { + // Manually remove the temporary file + file.remove(true); } - } - else { - this.addon.active = (this.addon.visible && !this.addon.disabled); - this.addon = XPIDatabase.addAddonMetadata(this.addon, file.persistentDescriptor); - XPIStates.addAddon(this.addon); - this.addon.installDate = this.addon.updateDate; - XPIDatabase.saveChanges(); - } - XPIStates.save(); - - let extraParams = {}; - if (this.existingAddon) { - extraParams.oldVersion = this.existingAddon.version; - } - - if (this.addon.bootstrap) { - XPIProvider.callBootstrapMethod(this.addon, file, "install", - reason, extraParams); - } - - AddonManagerPrivate.callAddonListeners("onInstalled", - this.addon.wrapper); + else { + // Make the new install own its temporary file + aInstall.ownsTempFile = true; - logger.debug("Install of " + this.sourceURI.spec + " completed."); - this.state = AddonManager.STATE_INSTALLED; - AddonManagerPrivate.callInstallListeners("onInstallEnded", - this.listeners, this.wrapper, - this.addon.wrapper); + self.linkedInstalls.push(aInstall) - if (this.addon.bootstrap) { - if (this.addon.active) { - XPIProvider.callBootstrapMethod(this.addon, file, "startup", - reason, extraParams); + aInstall.sourceURI = self.sourceURI; + aInstall.releaseNotesURI = self.releaseNotesURI; + aInstall.updateAddonURIs(); } - else { - // XXX this makes it dangerous to do some things in onInstallEnded - // listeners because important cleanup hasn't been done yet - XPIProvider.unloadBootstrapScope(this.addon.id); - } - } - XPIProvider.setTelemetry(this.addon.id, "unpacked", installedUnpacked); - recordAddonTelemetry(this.addon); - } - }).bind(this)).then(null, (e) => { - logger.warn(`Failed to install ${this.file.path} from ${this.sourceURI.spec} to ${stagedAddon.path}`, e); - if (stagedAddon.exists()) - recursiveRemove(stagedAddon); - this.state = AddonManager.STATE_INSTALL_FAILED; - this.error = AddonManager.ERROR_FILE_ACCESS; - XPIProvider.removeActiveInstall(this); - AddonManagerPrivate.callAddonListeners("onOperationCancelled", - this.addon.wrapper); - AddonManagerPrivate.callInstallListeners("onInstallFailed", - this.listeners, - this.wrapper); - }).then(() => { - this.removeTemporaryFile(); - return this.installLocation.releaseStagingDir(); - }); - } + count++; + if (count == files.length) + aCallback(); + }, file); + }, this); + } + else { + aCallback(); + } + }, /** - * Stages an upgrade for next application restart. + * Called after the add-on is a local file and the signature and install + * manifest can be read. + * + * @param aCallback + * A function to call when the manifest has been loaded + * @throws if the add-on does not contain a valid install manifest or the + * XPI is incorrectly signed */ - stageInstall(restartRequired, stagedAddon, isUpgrade) { - return Task.spawn((function*() { - let stagedJSON = stagedAddon.clone(); - stagedJSON.leafName = this.addon.id + ".json"; - - let installedUnpacked = 0; - - // First stage the file regardless of whether restarting is necessary - if (this.addon.unpack || Preferences.get(PREF_XPI_UNPACK, false)) { - logger.debug("Addon " + this.addon.id + " will be installed as " + - "an unpacked directory"); - stagedAddon.leafName = this.addon.id; - yield OS.File.makeDir(stagedAddon.path); - yield ZipUtils.extractFilesAsync(this.file, stagedAddon); - installedUnpacked = 1; - } - else { - logger.debug(`Addon ${this.addon.id} will be installed as a packed xpi`); - stagedAddon.leafName = this.addon.id + ".xpi"; - - yield OS.File.copy(this.file.path, stagedAddon.path); - } - - if (restartRequired) { - // Point the add-on to its extracted files as the xpi may get deleted - this.addon._sourceBundle = stagedAddon; - - // Cache the AddonInternal as it may have updated compatibility info - writeStringToFile(stagedJSON, JSON.stringify(this.addon)); - - logger.debug("Staged install of " + this.addon.id + " from " + this.sourceURI.spec + " ready; waiting for restart."); - if (isUpgrade) { - delete this.existingAddon.pendingUpgrade; - this.existingAddon.pendingUpgrade = this.addon; + loadManifest: function AI_loadManifest(aCallback) { + aCallback = makeSafe(aCallback); + let self = this; + function addRepositoryData(aAddon) { + // Try to load from the existing cache first + AddonRepository.getCachedAddonByID(aAddon.id, function loadManifest_getCachedAddonByID(aRepoAddon) { + if (aRepoAddon) { + aAddon._repositoryAddon = aRepoAddon; + self.name = self.name || aAddon._repositoryAddon.name; + aAddon.compatibilityOverrides = aRepoAddon.compatibilityOverrides; + aAddon.appDisabled = !isUsableAddon(aAddon); + aCallback(); + return; } - } - - return installedUnpacked; - }).bind(this)); - } - - /** - * Removes any previously staged upgrade. - */ - unstageInstall(stagedAddon) { - return Task.spawn((function*() { - let stagedJSON = stagedAddon.clone(); - let removedAddon = stagedAddon.clone(); - - stagedJSON.append(this.addon.id + ".json"); - - if (stagedJSON.exists()) { - stagedJSON.remove(true); - } - removedAddon.append(this.addon.id); - yield removeAsync(removedAddon); - removedAddon.leafName = this.addon.id + ".xpi"; - yield removeAsync(removedAddon); - }).bind(this)); - } - - /** - * Postone a pending update, until restart or until the add-on resumes. - * - * @param {Function} resumeFunction - a function for the add-on to run - * when resuming. - */ - postpone(resumeFunction) { - return Task.spawn((function*() { - this.state = AddonManager.STATE_POSTPONED; - - let stagingDir = this.installLocation.getStagingDir(); - let stagedAddon = stagingDir.clone(); - - yield this.installLocation.requestStagingDir(); - yield this.unstageInstall(stagedAddon); - - stagedAddon.append(this.addon.id); - stagedAddon.leafName = this.addon.id + ".xpi"; - - yield this.stageInstall(true, stagedAddon, true); - - AddonManagerPrivate.callInstallListeners("onInstallPostponed", - this.listeners, this.wrapper) - - // upgrade has been staged for restart, provide a way for it to call the - // resume function. - if (resumeFunction) { - let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id); - if (callback) { - callback({ - version: this.version, - install: () => { - switch (this.state) { - case AddonManager.STATE_POSTPONED: - resumeFunction(); - break; - default: - logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`); - break; - } - }, + // It wasn't there so try to re-download it + AddonRepository.cacheAddons([aAddon.id], function loadManifest_cacheAddons() { + AddonRepository.getCachedAddonByID(aAddon.id, function loadManifest_getCachedAddonByID(aRepoAddon) { + aAddon._repositoryAddon = aRepoAddon; + self.name = self.name || aAddon._repositoryAddon.name; + aAddon.compatibilityOverrides = aRepoAddon ? + aRepoAddon.compatibilityOverrides : + null; + aAddon.appDisabled = !isUsableAddon(aAddon); + aCallback(); }); - } - } - this.installLocation.releaseStagingDir(); - }).bind(this)); - } -} - -class LocalAddonInstall extends AddonInstall { - /** - * Initialises this install to be an install from a local file. - * - * @returns Promise - * A Promise that resolves when the object is ready to use. - */ - init() { - return Task.spawn((function*() { - this.file = this.sourceURI.QueryInterface(Ci.nsIFileURL).file; - - if (!this.file.exists()) { - logger.warn("XPI file " + this.file.path + " does not exist"); - this.state = AddonManager.STATE_DOWNLOAD_FAILED; - this.error = AddonManager.ERROR_NETWORK_FAILURE; - XPIProvider.removeActiveInstall(this); - return; - } - - this.state = AddonManager.STATE_DOWNLOADED; - this.progress = this.file.fileSize; - this.maxProgress = this.file.fileSize; + }); + }); + } - if (this.hash) { - let crypto = Cc["@mozilla.org/security/hash;1"]. - createInstance(Ci.nsICryptoHash); - try { - crypto.initWithString(this.hash.algorithm); - } - catch (e) { - logger.warn("Unknown hash algorithm '" + this.hash.algorithm + "' for addon " + this.sourceURI.spec, e); - this.state = AddonManager.STATE_DOWNLOAD_FAILED; - this.error = AddonManager.ERROR_INCORRECT_HASH; - XPIProvider.removeActiveInstall(this); - return; - } + let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"]. + createInstance(Ci.nsIZipReader); + try { + zipreader.open(this.file); + } + catch (e) { + zipreader.close(); + throw e; + } - let fis = Cc["@mozilla.org/network/file-input-stream;1"]. - createInstance(Ci.nsIFileInputStream); - fis.init(this.file, -1, -1, false); - crypto.updateFromStream(fis, this.file.fileSize); - let calculatedHash = getHashStringForCrypto(crypto); - if (calculatedHash != this.hash.data) { - logger.warn("File hash (" + calculatedHash + ") did not match provided hash (" + - this.hash.data + ")"); - this.state = AddonManager.STATE_DOWNLOAD_FAILED; - this.error = AddonManager.ERROR_INCORRECT_HASH; - XPIProvider.removeActiveInstall(this); - return; + let x509 = zipreader.getSigningCert(null); + if (x509) { + logger.debug("Verifying XPI signature"); + if (verifyZipSigning(zipreader, x509)) { + this.certificate = x509; + if (this.certificate.commonName.length > 0) { + this.certName = this.certificate.commonName; + } else { + this.certName = this.certificate.organization; } + } else { + zipreader.close(); + throw new Error("XPI is incorrectly signed"); } + } - try { - yield this.loadManifest(this.file); - } catch ([error, message]) { - logger.warn("Invalid XPI", message); - this.state = AddonManager.STATE_DOWNLOAD_FAILED; - this.error = error; - XPIProvider.removeActiveInstall(this); - AddonManagerPrivate.callInstallListeners("onNewInstall", - this.listeners, - this.wrapper); - return; - } + try { + this.addon = loadManifestFromZipReader(zipreader); + } + catch (e) { + zipreader.close(); + throw e; + } - let addon = yield new Promise(resolve => { - XPIDatabase.getVisibleAddonForID(this.addon.id, resolve); + if (this.addon.type == "multipackage") { + this._loadMultipackageManifests(zipreader, function loadManifest_loadMultipackageManifests() { + addRepositoryData(self.addon); }); - - this.existingAddon = addon; - if (addon) - applyBlocklistChanges(addon, this.addon); - this.addon.updateDate = Date.now(); - this.addon.installDate = addon ? addon.installDate : this.addon.updateDate; - - if (!this.addon.isCompatible) { - this.state = AddonManager.STATE_CHECKING; - - yield new Promise(resolve => { - new UpdateChecker(this.addon, { - onUpdateFinished: aAddon => { - this.state = AddonManager.STATE_DOWNLOADED; - AddonManagerPrivate.callInstallListeners("onNewInstall", - this.listeners, - this.wrapper); - resolve(); - } - }, AddonManager.UPDATE_WHEN_ADDON_INSTALLED); - }); - } - else { - AddonManagerPrivate.callInstallListeners("onNewInstall", - this.listeners, - this.wrapper); - - } - }).bind(this)); - } - - install() { - if (this.state == AddonManager.STATE_DOWNLOAD_FAILED) { - // For a local install, this state means that verification of the - // file failed (e.g., the hash or signature or manifest contents - // were invalid). It doesn't make sense to retry anything in this - // case but we have callers who don't know if their AddonInstall - // object is a local file or a download so accomodate them here. - AddonManagerPrivate.callInstallListeners("onDownloadFailed", - this.listeners, this.wrapper); return; } - super.install(); - } -} -class DownloadAddonInstall extends AddonInstall { - /** - * Instantiates a DownloadAddonInstall - * - * @param installLocation - * The InstallLocation the add-on will be installed into - * @param url - * The nsIURL to get the add-on from - * @param name - * An optional name for the add-on - * @param hash - * An optional hash for the add-on - * @param existingAddon - * The add-on this install will update if known - * @param browser - * The browser performing the install, used to display - * authentication prompts. - * @param type - * An optional type for the add-on - * @param icons - * Optional icons for the add-on - * @param version - * An optional version for the add-on - */ - constructor(installLocation, url, hash, existingAddon, browser, - name, type, icons, version) { - super(installLocation, url, hash, existingAddon); + zipreader.close(); - this.browser = browser; + this.updateAddonURIs(); - this.state = AddonManager.STATE_AVAILABLE; - this.name = name; - this.type = type; - this.version = version; - this.icons = icons; - - this.stream = null; - this.crypto = null; - this.badCertHandler = null; - this.restartDownload = false; - - AddonManagerPrivate.callInstallListeners("onNewInstall", this.listeners, - this.wrapper); - } + this.addon._install = this; + this.name = this.addon.selectedLocale.name || this.addon.defaultLocale.name; + this.type = this.addon.type; + this.version = this.addon.version; - install() { - switch (this.state) { - case AddonManager.STATE_AVAILABLE: - this.startDownload(); - break; - case AddonManager.STATE_DOWNLOAD_FAILED: - case AddonManager.STATE_INSTALL_FAILED: - case AddonManager.STATE_CANCELLED: - this.removeTemporaryFile(); - this.state = AddonManager.STATE_AVAILABLE; - this.error = 0; - this.progress = 0; - this.maxProgress = -1; - this.hash = this.originalHash; - this.startDownload(); - break; - default: - super.install(); - } - } + // Setting the iconURL to something inside the XPI locks the XPI and + // makes it impossible to delete on Windows. + //let newIcon = createWrapper(this.addon).iconURL; + //if (newIcon) + // this.iconURL = newIcon; - cancel() { - if (this.state == AddonManager.STATE_DOWNLOADING) { - if (this.channel) { - logger.debug("Cancelling download of " + this.sourceURI.spec); - this.channel.cancel(Cr.NS_BINDING_ABORTED); - } - } else { - super.cancel(); - } - } + addRepositoryData(this.addon); + }, - observe(aSubject, aTopic, aData) { + observe: function AI_observe(aSubject, aTopic, aData) { // Network is going offline this.cancel(); - } + }, /** * Starts downloading the add-on's XPI file. */ - startDownload() { + startDownload: function AI_startDownload() { this.state = AddonManager.STATE_DOWNLOADING; if (!AddonManagerPrivate.callInstallListeners("onDownloadStarted", this.listeners, this.wrapper)) { @@ -6294,9 +5429,9 @@ class DownloadAddonInstall extends AddonInstall { } this.openChannel(); - } + }, - openChannel() { + openChannel: function AI_openChannel() { this.restartDownload = false; try { @@ -6321,8 +5456,9 @@ class DownloadAddonInstall extends AddonInstall { createInstance(Ci.nsIStreamListenerTee); listener.init(this, this.stream); try { + Components.utils.import("resource://gre/modules/CertUtils.jsm"); let requireBuiltIn = Preferences.get(PREF_INSTALL_REQUIREBUILTINCERTS, true); - this.badCertHandler = new CertUtils.BadCertHandler(!requireBuiltIn); + this.badCertHandler = new BadCertHandler(!requireBuiltIn); this.channel = NetUtil.newChannel({ uri: this.sourceURI, @@ -6346,21 +5482,22 @@ class DownloadAddonInstall extends AddonInstall { AddonManagerPrivate.callInstallListeners("onDownloadFailed", this.listeners, this.wrapper); } - } + }, /** * Update the crypto hasher with the new data and call the progress listeners. * * @see nsIStreamListener */ - onDataAvailable(aRequest, aContext, aInputstream, aOffset, aCount) { + onDataAvailable: function AI_onDataAvailable(aRequest, aContext, aInputstream, + aOffset, aCount) { this.crypto.updateFromStream(aInputstream, aCount); this.progress += aCount; if (!AddonManagerPrivate.callInstallListeners("onDownloadProgress", this.listeners, this.wrapper)) { // TODO cancel the download and make it available again (bug 553024) } - } + }, /** * Check the redirect response for a hash of the target XPI and verify that @@ -6368,7 +5505,7 @@ class DownloadAddonInstall extends AddonInstall { * * @see nsIChannelEventSink */ - asyncOnChannelRedirect(aOldChannel, aNewChannel, aFlags, aCallback) { + asyncOnChannelRedirect: function AI_asyncOnChannelRedirect(aOldChannel, aNewChannel, aFlags, aCallback) { if (!this.hash && aOldChannel.originalURI.schemeIs("https") && aOldChannel instanceof Ci.nsIHttpChannel) { try { @@ -6391,14 +5528,14 @@ class DownloadAddonInstall extends AddonInstall { aCallback.onRedirectVerifyCallback(Cr.NS_OK); this.channel = aNewChannel; - } + }, /** * This is the first chance to get at real headers on the channel. * * @see nsIStreamListener */ - onStartRequest(aRequest, aContext) { + onStartRequest: function AI_onStartRequest(aRequest, aContext) { this.crypto = Cc["@mozilla.org/security/hash;1"]. createInstance(Ci.nsICryptoHash); if (this.hash) { @@ -6432,14 +5569,14 @@ class DownloadAddonInstall extends AddonInstall { logger.debug("Download started for " + this.sourceURI.spec + " to file " + this.file.path); } - } + }, /** * The download is complete. * * @see nsIStreamListener */ - onStopRequest(aRequest, aContext, aStatus) { + onStopRequest: function AI_onStopRequest(aRequest, aContext, aStatus) { this.stream.close(); this.channel = null; this.badCerthandler = null; @@ -6471,8 +5608,8 @@ class DownloadAddonInstall extends AddonInstall { if (!(aRequest instanceof Ci.nsIHttpChannel) || aRequest.requestSucceeded) { if (!this.hash && (aRequest instanceof Ci.nsIChannel)) { try { - CertUtils.checkCert(aRequest, - !Preferences.get(PREF_INSTALL_REQUIREBUILTINCERTS, true)); + checkCert(aRequest, + !Preferences.get(PREF_INSTALL_REQUIREBUILTINCERTS, true)); } catch (e) { this.downloadFailed(AddonManager.ERROR_NETWORK_FAILURE, e); @@ -6489,36 +5626,44 @@ class DownloadAddonInstall extends AddonInstall { ") did not match provided hash (" + this.hash.data + ")"); return; } - - this.loadManifest(this.file).then(() => { - if (this.addon.isCompatible) { - this.downloadCompleted(); - } - else { - // TODO Should we send some event here (bug 557716)? - this.state = AddonManager.STATE_CHECKING; - new UpdateChecker(this.addon, { - onUpdateFinished: aAddon => this.downloadCompleted(), - }, AddonManager.UPDATE_WHEN_ADDON_INSTALLED); + try { + let self = this; + this.loadManifest(function onStopRequest_loadManifest() { + if (self.addon.isCompatible) { + self.downloadCompleted(); + } + else { + // TODO Should we send some event here (bug 557716)? + self.state = AddonManager.STATE_CHECKING; + new UpdateChecker(self.addon, { + onUpdateFinished: function onStopRequest_onUpdateFinished(aAddon) { + self.downloadCompleted(); + } + }, AddonManager.UPDATE_WHEN_ADDON_INSTALLED); + } + }); + } + catch (e) { + if (e.webext) { + this.downloadFailed(AddonManager.ERROR_WEBEXT_FILE, e); + } else { + this.downloadFailed(AddonManager.ERROR_CORRUPT_FILE, e); } - }, ([error, message]) => { - this.removeTemporaryFile(); - this.downloadFailed(error, message); - }); - } - else if (aRequest instanceof Ci.nsIHttpChannel) { - this.downloadFailed(AddonManager.ERROR_NETWORK_FAILURE, - aRequest.responseStatus + " " + - aRequest.responseStatusText); + } } else { - this.downloadFailed(AddonManager.ERROR_NETWORK_FAILURE, aStatus); + if (aRequest instanceof Ci.nsIHttpChannel) + this.downloadFailed(AddonManager.ERROR_NETWORK_FAILURE, + aRequest.responseStatus + " " + + aRequest.responseStatusText); + else + this.downloadFailed(AddonManager.ERROR_NETWORK_FAILURE, aStatus); } } else { this.downloadFailed(AddonManager.ERROR_NETWORK_FAILURE, aStatus); } - } + }, /** * Notify listeners that the download failed. @@ -6528,7 +5673,7 @@ class DownloadAddonInstall extends AddonInstall { * @param error * The error code to pass to the listeners */ - downloadFailed(aReason, aError) { + downloadFailed: function AI_downloadFailed(aReason, aError) { logger.warn("Download of " + this.sourceURI.spec + " failed", aError); this.state = AddonManager.STATE_DOWNLOAD_FAILED; this.error = aReason; @@ -6545,72 +5690,276 @@ class DownloadAddonInstall extends AddonInstall { else logger.debug("downloadFailed: listener changed AddonInstall state for " + this.sourceURI.spec + " to " + this.state); - } + }, /** * Notify listeners that the download completed. */ - downloadCompleted() { - XPIDatabase.getVisibleAddonForID(this.addon.id, aAddon => { + downloadCompleted: function AI_downloadCompleted() { + let self = this; + XPIDatabase.getVisibleAddonForID(this.addon.id, function downloadCompleted_getVisibleAddonForID(aAddon) { if (aAddon) - this.existingAddon = aAddon; + self.existingAddon = aAddon; - this.state = AddonManager.STATE_DOWNLOADED; - this.addon.updateDate = Date.now(); + self.state = AddonManager.STATE_DOWNLOADED; + self.addon.updateDate = Date.now(); - if (this.existingAddon) { - this.addon.existingAddonID = this.existingAddon.id; - this.addon.installDate = this.existingAddon.installDate; - applyBlocklistChanges(this.existingAddon, this.addon); + if (self.existingAddon) { + self.addon.existingAddonID = self.existingAddon.id; + self.addon.installDate = self.existingAddon.installDate; + applyBlocklistChanges(self.existingAddon, self.addon); } else { - this.addon.installDate = this.addon.updateDate; + self.addon.installDate = self.addon.updateDate; } if (AddonManagerPrivate.callInstallListeners("onDownloadEnded", - this.listeners, - this.wrapper)) { + self.listeners, + self.wrapper)) { // If a listener changed our state then do not proceed with the install - if (this.state != AddonManager.STATE_DOWNLOADED) + if (self.state != AddonManager.STATE_DOWNLOADED) return; - // If an upgrade listener is registered for this add-on, pass control - // over the upgrade to the add-on. - if (AddonManagerPrivate.hasUpgradeListener(this.addon.id)) { - logger.info(`add-on ${this.addon.id} has an upgrade listener, postponing upgrade until restart`); - let resumeFn = () => { - logger.info(`${this.addon.id} has resumed a previously postponed upgrade`); - this.state = AddonManager.STATE_DOWNLOADED; - this.install(); - } - this.postpone(resumeFn); - } else { - // no upgrade listener present, so proceed with normal install - this.install(); - if (this.linkedInstalls) { - for (let install of this.linkedInstalls) { - if (install.state == AddonManager.STATE_DOWNLOADED) - install.install(); + self.install(); + + if (self.linkedInstalls) { + self.linkedInstalls.forEach(function(aInstall) { + aInstall.install(); + }); + } + } + }); + }, + + // TODO This relies on the assumption that we are always installing into the + // highest priority install location so the resulting add-on will be visible + // overriding any existing copy in another install location (bug 557710). + /** + * Installs the add-on into the install location. + */ + startInstall: function AI_startInstall() { + this.state = AddonManager.STATE_INSTALLING; + if (!AddonManagerPrivate.callInstallListeners("onInstallStarted", + this.listeners, this.wrapper)) { + this.state = AddonManager.STATE_DOWNLOADED; + XPIProvider.removeActiveInstall(this); + AddonManagerPrivate.callInstallListeners("onInstallCancelled", + this.listeners, this.wrapper) + return; + } + + // Find and cancel any pending installs for the same add-on in the same + // install location + for (let aInstall of XPIProvider.installs) { + if (aInstall.state == AddonManager.STATE_INSTALLED && + aInstall.installLocation == this.installLocation && + aInstall.addon.id == this.addon.id) { + logger.debug("Cancelling previous pending install of " + aInstall.addon.id); + aInstall.cancel(); + } + } + + let isUpgrade = this.existingAddon && + this.existingAddon._installLocation == this.installLocation; + let requiresRestart = XPIProvider.installRequiresRestart(this.addon); + + logger.debug("Starting install of " + this.addon.id + " from " + this.sourceURI.spec); + AddonManagerPrivate.callAddonListeners("onInstalling", + createWrapper(this.addon), + requiresRestart); + + let stagingDir = this.installLocation.getStagingDir(); + let stagedAddon = stagingDir.clone(); + + Task.spawn((function() { + let installedUnpacked = 0; + yield this.installLocation.requestStagingDir(); + + // Remove any staged items for this add-on + stagedAddon.append(this.addon.id); + yield removeAsync(stagedAddon); + stagedAddon.leafName = this.addon.id + ".xpi"; + yield removeAsync(stagedAddon); + + // First stage the file regardless of whether restarting is necessary + if (this.addon.unpack || Preferences.get(PREF_XPI_UNPACK, false)) { + logger.debug("Addon " + this.addon.id + " will be installed as " + + "an unpacked directory"); + stagedAddon.leafName = this.addon.id; + yield OS.File.makeDir(stagedAddon.path); + yield ZipUtils.extractFilesAsync(this.file, stagedAddon); + installedUnpacked = 1; + } + else { + logger.debug("Addon " + this.addon.id + " will be installed as " + + "a packed xpi"); + stagedAddon.leafName = this.addon.id + ".xpi"; + yield OS.File.copy(this.file.path, stagedAddon.path); + } + + if (requiresRestart) { + // Point the add-on to its extracted files as the xpi may get deleted + this.addon._sourceBundle = stagedAddon; + + // Cache the AddonInternal as it may have updated compatibility info + let stagedJSON = stagedAddon.clone(); + stagedJSON.leafName = this.addon.id + ".json"; + if (stagedJSON.exists()) + stagedJSON.remove(true); + let stream = Cc["@mozilla.org/network/file-output-stream;1"]. + createInstance(Ci.nsIFileOutputStream); + let converter = Cc["@mozilla.org/intl/converter-output-stream;1"]. + createInstance(Ci.nsIConverterOutputStream); + + try { + stream.init(stagedJSON, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | + FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, + 0); + converter.init(stream, "UTF-8", 0, 0x0000); + converter.writeString(JSON.stringify(this.addon)); + } + finally { + converter.close(); + stream.close(); + } + + logger.debug("Staged install of " + this.addon.id + " from " + this.sourceURI.spec + " ready; waiting for restart."); + this.state = AddonManager.STATE_INSTALLED; + if (isUpgrade) { + delete this.existingAddon.pendingUpgrade; + this.existingAddon.pendingUpgrade = this.addon; + } + AddonManagerPrivate.callInstallListeners("onInstallEnded", + this.listeners, this.wrapper, + createWrapper(this.addon)); + } + else { + // The install is completed so it should be removed from the active list + XPIProvider.removeActiveInstall(this); + + // TODO We can probably reduce the number of DB operations going on here + // We probably also want to support rolling back failed upgrades etc. + // See bug 553015. + + // Deactivate and remove the old add-on as necessary + let reason = BOOTSTRAP_REASONS.ADDON_INSTALL; + if (this.existingAddon) { + if (Services.vc.compare(this.existingAddon.version, this.addon.version) < 0) + reason = BOOTSTRAP_REASONS.ADDON_UPGRADE; + else + reason = BOOTSTRAP_REASONS.ADDON_DOWNGRADE; + + if (this.existingAddon.bootstrap) { + let file = this.existingAddon._installLocation + .getLocationForID(this.existingAddon.id); + if (this.existingAddon.active) { + XPIProvider.callBootstrapMethod(this.existingAddon, file, + "shutdown", reason, + { newVersion: this.addon.version }); } + + XPIProvider.callBootstrapMethod(this.existingAddon, file, + "uninstall", reason, + { newVersion: this.addon.version }); + XPIProvider.unloadBootstrapScope(this.existingAddon.id); + flushStartupCache(); + } + + if (!isUpgrade && this.existingAddon.active) { + XPIDatabase.updateAddonActive(this.existingAddon, false); + } + } + + // Install the new add-on into its final location + let existingAddonID = this.existingAddon ? this.existingAddon.id : null; + let file = this.installLocation.installAddon(this.addon.id, stagedAddon, + existingAddonID); + + // Update the metadata in the database + this.addon._sourceBundle = file; + this.addon._installLocation = this.installLocation; + this.addon.visible = true; + + if (isUpgrade) { + this.addon = XPIDatabase.updateAddonMetadata(this.existingAddon, this.addon, + file.persistentDescriptor); + let state = XPIStates.getAddon(this.installLocation.name, this.addon.id); + if (state) { + state.syncWithDB(this.addon, true); + } else { + logger.warn("Unexpected missing XPI state for add-on ${id}", this.addon); + } + } + else { + this.addon.active = (this.addon.visible && !this.addon.disabled); + this.addon = XPIDatabase.addAddonMetadata(this.addon, file.persistentDescriptor); + XPIStates.addAddon(this.addon); + this.addon.installDate = this.addon.updateDate; + XPIDatabase.saveChanges(); + } + XPIStates.save(); + + let extraParams = {}; + if (this.existingAddon) { + extraParams.oldVersion = this.existingAddon.version; + } + + if (this.addon.bootstrap) { + XPIProvider.callBootstrapMethod(this.addon, file, "install", + reason, extraParams); + } + + AddonManagerPrivate.callAddonListeners("onInstalled", + createWrapper(this.addon)); + + logger.debug("Install of " + this.sourceURI.spec + " completed."); + this.state = AddonManager.STATE_INSTALLED; + AddonManagerPrivate.callInstallListeners("onInstallEnded", + this.listeners, this.wrapper, + createWrapper(this.addon)); + + if (this.addon.bootstrap) { + if (this.addon.active) { + XPIProvider.callBootstrapMethod(this.addon, file, "startup", + reason, extraParams); + } + else { + // XXX this makes it dangerous to do some things in onInstallEnded + // listeners because important cleanup hasn't been done yet + XPIProvider.unloadBootstrapScope(this.addon.id); } } } + }).bind(this)).then(null, (e) => { + logger.warn("Failed to install " + this.file.path + " from " + this.sourceURI.spec, e); + if (stagedAddon.exists()) + recursiveRemove(stagedAddon); + this.state = AddonManager.STATE_INSTALL_FAILED; + this.error = AddonManager.ERROR_FILE_ACCESS; + XPIProvider.removeActiveInstall(this); + AddonManagerPrivate.callAddonListeners("onOperationCancelled", + createWrapper(this.addon)); + AddonManagerPrivate.callInstallListeners("onInstallFailed", + this.listeners, + this.wrapper); + }).then(() => { + this.removeTemporaryFile(); + return this.installLocation.releaseStagingDir(); }); - } + }, - getInterface(iid) { + getInterface: function AI_getInterface(iid) { if (iid.equals(Ci.nsIAuthPrompt2)) { - let win = null; - if (this.browser) { - win = this.browser.contentWindow || this.browser.ownerDocument.defaultView; - } + let win = this.window; + if (!win && this.browser) + win = this.browser.ownerDocument.defaultView; let factory = Cc["@mozilla.org/prompter;1"]. getService(Ci.nsIPromptFactory); let prompt = factory.getPrompt(win, Ci.nsIAuthPrompt2); - if (this.browser && prompt instanceof Ci.nsILoginManagerPrompter) - prompt.browser = this.browser; + if (this.browser && this.browser.isRemoteBrowser && prompt instanceof Ci.nsILoginManagerPrompter) + prompt.setE10sData(this.browser, null); return prompt; } @@ -6620,113 +5969,46 @@ class DownloadAddonInstall extends AddonInstall { return this.badCertHandler.getInterface(iid); } - - /** - * Postone a pending update, until restart or until the add-on resumes. - * - * @param {Function} resumeFn - a function for the add-on to run - * when resuming. - */ - postpone(resumeFn) { - return Task.spawn((function*() { - this.state = AddonManager.STATE_POSTPONED; - - let stagingDir = this.installLocation.getStagingDir(); - let stagedAddon = stagingDir.clone(); - - yield this.installLocation.requestStagingDir(); - yield this.unstageInstall(stagedAddon); - - stagedAddon.append(this.addon.id); - stagedAddon.leafName = this.addon.id + ".xpi"; - - yield this.stageInstall(true, stagedAddon, true); - - AddonManagerPrivate.callInstallListeners("onInstallPostponed", - this.listeners, this.wrapper) - - // upgrade has been staged for restart, provide a way for it to call the - // resume function. - let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id); - if (callback) { - callback({ - version: this.version, - install: () => { - switch (this.state) { - case AddonManager.STATE_POSTPONED: - if (resumeFn) { - resumeFn(); - } - break; - default: - logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`); - break; - } - }, - }); - } - // Release the staging directory lock, but since the staging dir is populated - // it will not be removed until resumed or installed by restart. - // See also cleanStagingDir() - this.installLocation.releaseStagingDir(); - }).bind(this)); - } } /** - * This class exists just for the specific case of staged add-ons that - * fail to install at startup. When that happens, the add-on remains - * staged but we want to keep track of it like other installs so that we - * can clean it up if the same add-on is installed again (see the comment - * about "pending installs for the same add-on" in AddonInstall.startInstall) + * Creates a new AddonInstall for an already staged install. Used when + * installing the staged install failed for some reason. + * + * @param aDir + * The directory holding the staged install + * @param aManifest + * The cached manifest for the install */ -class StagedAddonInstall extends AddonInstall { - constructor(installLocation, dir, manifest) { - super(installLocation, dir); - - this.name = manifest.name; - this.type = manifest.type; - this.version = manifest.version; - this.icons = manifest.icons; - this.releaseNotesURI = manifest.releaseNotesURI ? - NetUtil.newURI(manifest.releaseNotesURI) : - null; - this.sourceURI = manifest.sourceURI ? - NetUtil.newURI(manifest.sourceURI) : - null; - this.file = null; - this.addon = manifest; +AddonInstall.createStagedInstall = function AI_createStagedInstall(aInstallLocation, aDir, aManifest) { + let url = Services.io.newFileURI(aDir); - this.state = AddonManager.STATE_INSTALLED; - } -} + let install = new AddonInstall(aInstallLocation, aDir); + install.initStagedInstall(aManifest); +}; /** - * Creates a new AddonInstall to install an add-on from a local file. + * Creates a new AddonInstall to install an add-on from a local file. Installs + * always go into the profile install location. * - * @param file + * @param aCallback + * The callback to pass the new AddonInstall to + * @param aFile * The file to install - * @param location - * The location to install to - * @returns Promise - * A Promise that resolves with the new install object. */ -function createLocalInstall(file, location) { - if (!location) { - location = XPIProvider.installLocationsByName[KEY_APP_PROFILE]; - } - let url = Services.io.newFileURI(file); +AddonInstall.createInstall = function AI_createInstall(aCallback, aFile) { + let location = XPIProvider.installLocationsByName[KEY_APP_PROFILE]; + let url = Services.io.newFileURI(aFile); try { - let install = new LocalAddonInstall(location, url); - return install.init().then(() => install); + let install = new AddonInstall(location, url); + install.initLocalInstall(aCallback); } - catch (e) { + catch(e) { logger.error("Error creating install", e); - XPIProvider.removeActiveInstall(this); - return Promise.resolve(null); + makeSafe(aCallback)(null); } -} +}; /** * Creates a new AddonInstall to download and install a URL. @@ -6746,21 +6028,17 @@ function createLocalInstall(file, location) { * @param aBrowser * The browser performing the install */ -function createDownloadInstall(aCallback, aUri, aHash, aName, aIcons, - aVersion, aBrowser) { +AddonInstall.createDownload = function AI_createDownload(aCallback, aUri, aHash, aName, aIcons, + aVersion, aBrowser) { let location = XPIProvider.installLocationsByName[KEY_APP_PROFILE]; let url = NetUtil.newURI(aUri); - if (url instanceof Ci.nsIFileURL) { - let install = new LocalAddonInstall(location, url, aHash); - install.init().then(() => { aCallback(install); }); - } else { - let install = new DownloadAddonInstall(location, url, aHash, null, - aBrowser, aName, null, aIcons, - aVersion); - aCallback(install); - } -} + let install = new AddonInstall(location, url, aHash, null, null, aBrowser); + if (url instanceof Ci.nsIFileURL) + install.initLocalInstall(aCallback); + else + install.initAvailableDownload(aName, null, aIcons, aVersion, aCallback); +}; /** * Creates a new AddonInstall for an update. @@ -6772,37 +6050,28 @@ function createDownloadInstall(aCallback, aUri, aHash, aName, aIcons, * @param aUpdate * The metadata about the new version from the update manifest */ -function createUpdate(aCallback, aAddon, aUpdate) { +AddonInstall.createUpdate = function AI_createUpdate(aCallback, aAddon, aUpdate) { let url = NetUtil.newURI(aUpdate.updateURL); + let releaseNotesURI = null; + try { + if (aUpdate.updateInfoURL) + releaseNotesURI = NetUtil.newURI(escapeAddonURI(aAddon, aUpdate.updateInfoURL)); + } + catch (e) { + // If the releaseNotesURI cannot be parsed then just ignore it. + } - Task.spawn(function*() { - let install; - if (url instanceof Ci.nsIFileURL) { - install = new LocalAddonInstall(aAddon._installLocation, url, - aUpdate.updateHash, aAddon); - yield install.init(); - } else { - install = new DownloadAddonInstall(aAddon._installLocation, url, - aUpdate.updateHash, aAddon, null, - aAddon.selectedLocale.name, aAddon.type, - aAddon.icons, aUpdate.version); - } - try { - if (aUpdate.updateInfoURL) - install.releaseNotesURI = NetUtil.newURI(escapeAddonURI(aAddon, aUpdate.updateInfoURL)); - } - catch (e) { - // If the releaseNotesURI cannot be parsed then just ignore it. - } - - aCallback(install); - }); -} - -// This map is shared between AddonInstallWrapper and AddonWrapper -const wrapperMap = new WeakMap(); -let installFor = wrapper => wrapperMap.get(wrapper); -let addonFor = installFor; + let install = new AddonInstall(aAddon._installLocation, url, + aUpdate.updateHash, releaseNotesURI, aAddon); + if (url instanceof Ci.nsIFileURL) { + install.initLocalInstall(aCallback); + } + else { + install.initAvailableDownload(aAddon.selectedLocale.name ? + aAddon.selectedLocale.name : aAddon.defaultLocale.name, + aAddon.type, aAddon.icons, aUpdate.version, aCallback); + } +}; /** * Creates a wrapper for an AddonInstall that only exposes the public API @@ -6811,69 +6080,55 @@ let addonFor = installFor; * The AddonInstall to create a wrapper for */ function AddonInstallWrapper(aInstall) { - wrapperMap.set(this, aInstall); -} - -AddonInstallWrapper.prototype = { - get __AddonInstallInternal__() { - return AppConstants.DEBUG ? installFor(this) : undefined; - }, - - get type() { - return getExternalType(installFor(this).type); - }, +#ifdef MOZ_EM_DEBUG + this.__defineGetter__("__AddonInstallInternal__", function AIW_debugGetter() { + return aInstall; + }); +#endif - get iconURL() { - return installFor(this).icons[32]; - }, + ["name", "type", "version", "icons", "releaseNotesURI", "file", "state", "error", + "progress", "maxProgress", "certificate", "certName"].forEach(function(aProp) { + this.__defineGetter__(aProp, function AIW_propertyGetter() aInstall[aProp]); + }, this); - get existingAddon() { - let install = installFor(this); - return install.existingAddon ? install.existingAddon.wrapper : null; - }, + this.__defineGetter__("iconURL", function AIW_iconURL() aInstall.icons[32]); - get addon() { - let install = installFor(this); - return install.addon ? install.addon.wrapper : null; - }, - - get sourceURI() { - return installFor(this).sourceURI; - }, + this.__defineGetter__("existingAddon", function AIW_existingAddonGetter() { + return createWrapper(aInstall.existingAddon); + }); + this.__defineGetter__("addon", function AIW_addonGetter() createWrapper(aInstall.addon)); + this.__defineGetter__("sourceURI", function AIW_sourceURIGetter() aInstall.sourceURI); - get linkedInstalls() { - let install = installFor(this); - if (!install.linkedInstalls) + this.__defineGetter__("linkedInstalls", function AIW_linkedInstallsGetter() { + if (!aInstall.linkedInstalls) return null; - return install.linkedInstalls.map(i => i.wrapper); - }, + // Tycho: return [i.wrapper for each (i in aInstall.linkedInstalls)]; + let result = []; + for each (let i in aInstall.linkedInstalls) { + result.push(i.wrapper); + } + + return result; + }); - install: function() { - installFor(this).install(); - }, + this.install = function AIW_install() { + aInstall.install(); + } - cancel: function() { - installFor(this).cancel(); - }, + this.cancel = function AIW_cancel() { + aInstall.cancel(); + } - addListener: function(listener) { - installFor(this).addListener(listener); - }, + this.addListener = function AIW_addListener(listener) { + aInstall.addListener(listener); + } - removeListener: function(listener) { - installFor(this).removeListener(listener); - }, -}; + this.removeListener = function AIW_removeListener(listener) { + aInstall.removeListener(listener); + } +} -["name", "version", "icons", "releaseNotesURI", "file", "state", "error", - "progress", "maxProgress", "certificate", "certName"].forEach(function(aProp) { - Object.defineProperty(AddonInstallWrapper.prototype, aProp, { - get: function() { - return installFor(this)[aProp]; - }, - enumerable: true, - }); -}); +AddonInstallWrapper.prototype = {}; /** * Creates a new update checker. @@ -6940,7 +6195,7 @@ UpdateChecker.prototype = { * @param aMethod * The method to call on the listener */ - callListener: function(aMethod, ...aArgs) { + callListener: function UC_callListener(aMethod, ...aArgs) { if (!(aMethod in this.listener)) return; @@ -6958,7 +6213,7 @@ UpdateChecker.prototype = { * @param updates * The list of update details for the add-on */ - onUpdateCheckComplete: function(aUpdates) { + onUpdateCheckComplete: function UC_onUpdateCheckComplete(aUpdates) { XPIProvider.done(this.addon._updateCheck); this.addon._updateCheck = null; let AUC = AddonUpdateChecker; @@ -7000,19 +6255,19 @@ UpdateChecker.prototype = { } if (compatUpdate) - this.callListener("onCompatibilityUpdateAvailable", this.addon.wrapper); + this.callListener("onCompatibilityUpdateAvailable", createWrapper(this.addon)); else - this.callListener("onNoCompatibilityUpdateAvailable", this.addon.wrapper); + this.callListener("onNoCompatibilityUpdateAvailable", createWrapper(this.addon)); function sendUpdateAvailableMessages(aSelf, aInstall) { if (aInstall) { - aSelf.callListener("onUpdateAvailable", aSelf.addon.wrapper, + aSelf.callListener("onUpdateAvailable", createWrapper(aSelf.addon), aInstall.wrapper); } else { - aSelf.callListener("onNoUpdateAvailable", aSelf.addon.wrapper); + aSelf.callListener("onNoUpdateAvailable", createWrapper(aSelf.addon)); } - aSelf.callListener("onUpdateFinished", aSelf.addon.wrapper, + aSelf.callListener("onUpdateFinished", createWrapper(aSelf.addon), AddonManager.UPDATE_STATUS_NO_ERROR); } @@ -7021,14 +6276,13 @@ UpdateChecker.prototype = { this.addon.compatibilityOverrides; let update = AUC.getNewestCompatibleUpdate(aUpdates, - this.appVersion, - this.platformVersion, - ignoreMaxVersion, - ignoreStrictCompat, - compatOverrides); - - if (update && Services.vc.compare(this.addon.version, update.version) < 0 - && !this.addon._installLocation.locked) { + this.appVersion, + this.platformVersion, + ignoreMaxVersion, + ignoreStrictCompat, + compatOverrides); + + if (update && Services.vc.compare(this.addon.version, update.version) < 0) { for (let currentInstall of XPIProvider.installs) { // Skip installs that don't match the available update if (currentInstall.existingAddon != this.addon || @@ -7047,8 +6301,9 @@ UpdateChecker.prototype = { return; } - createUpdate(aInstall => { - sendUpdateAvailableMessages(this, aInstall); + let self = this; + AddonInstall.createUpdate(function onUpdateCheckComplete_createUpdate(aInstall) { + sendUpdateAvailableMessages(self, aInstall); }, this.addon, update); } else { @@ -7062,18 +6317,18 @@ UpdateChecker.prototype = { * @param aError * An error status */ - onUpdateCheckError: function(aError) { + onUpdateCheckError: function UC_onUpdateCheckError(aError) { XPIProvider.done(this.addon._updateCheck); this.addon._updateCheck = null; - this.callListener("onNoCompatibilityUpdateAvailable", this.addon.wrapper); - this.callListener("onNoUpdateAvailable", this.addon.wrapper); - this.callListener("onUpdateFinished", this.addon.wrapper, aError); + this.callListener("onNoCompatibilityUpdateAvailable", createWrapper(this.addon)); + this.callListener("onNoUpdateAvailable", createWrapper(this.addon)); + this.callListener("onUpdateFinished", createWrapper(this.addon), aError); }, /** * Called to cancel an in-progress update check */ - cancel: function() { + cancel: function UC_cancel() { let parser = this._parser; if (parser) { this._parser = null; @@ -7089,16 +6344,10 @@ UpdateChecker.prototype = { * or an install manifest. */ function AddonInternal() { - this._hasResourceCache = new Map(); - - XPCOMUtils.defineLazyGetter(this, "wrapper", () => { - return new AddonWrapper(this); - }); } AddonInternal.prototype = { _selectedLocale: null, - _hasResourceCache: null, active: false, visible: false, userDisabled: false, @@ -7107,22 +6356,11 @@ AddonInternal.prototype = { sourceURI: null, releaseNotesURI: null, foreignInstall: false, - seen: true, - skinnable: false, - - /** - * @property {Array<string>} dependencies - * An array of bootstrapped add-on IDs on which this add-on depends. - * The add-on will remain appDisabled if any of the dependent - * add-ons is not installed and enabled. - */ - dependencies: Object.freeze([]), - hasEmbeddedWebExtension: false, get selectedLocale() { if (this._selectedLocale) return this._selectedLocale; - let locale = Locale.findClosestLocale(this.locales); + let locale = findClosestLocale(this.locales); this._selectedLocale = locale ? locale : this.defaultLocale; return this._selectedLocale; }, @@ -7132,32 +6370,6 @@ AddonInternal.prototype = { this.updateURL.substring(0, 6) == "https:"); }, - get isCorrectlySigned() { - switch (this._installLocation.name) { - case KEY_APP_SYSTEM_ADDONS: - // System add-ons must be signed by the system key. - return this.signedState == AddonManager.SIGNEDSTATE_SYSTEM - - case KEY_APP_SYSTEM_DEFAULTS: - case KEY_APP_TEMPORARY: - // Temporary and built-in system add-ons do not require signing. - return true; - - case KEY_APP_SYSTEM_SHARE: - case KEY_APP_SYSTEM_LOCAL: - // On UNIX platforms except OSX, an additional location for system - // add-ons exists in /usr/{lib,share}/mozilla/extensions. Add-ons - // installed there do not require signing. - if (Services.appinfo.OS != "Darwin") - return true; - break; - } - - if (this.signedState === AddonManager.SIGNEDSTATE_NOT_REQUIRED) - return true; - return this.signedState > AddonManager.SIGNEDSTATE_MISSING; - }, - get isCompatible() { return this.isCompatibleWith(); }, @@ -7209,23 +6421,42 @@ AddonInternal.prototype = { return matchedOS && !needsABI; }, - isCompatibleWith: function(aAppVersion, aPlatformVersion) { + isCompatibleWith: function AddonInternal_isCompatibleWith(aAppVersion, aPlatformVersion) { + // Experiments are installed through an external mechanism that + // limits target audience to compatible clients. We trust it knows what + // it's doing and skip compatibility checks. + // + // This decision does forfeit defense in depth. If the experiments system + // is ever wrong about targeting an add-on to a specific application + // or platform, the client will likely see errors. + if (this.type == "experiment") { + return true; + } + let app = this.matchingTargetApplication; if (!app) return false; - // set reasonable defaults for minVersion and maxVersion - let minVersion = app.minVersion || "0"; - let maxVersion = app.maxVersion || "*"; - if (!aAppVersion) aAppVersion = Services.appinfo.version; if (!aPlatformVersion) aPlatformVersion = Services.appinfo.platformVersion; + this.native = false; + let version; - if (app.id == Services.appinfo.ID) + if (app.id == Services.appinfo.ID) { version = aAppVersion; + this.native = true; + } +#ifdef MOZ_PHOENIX_EXTENSIONS + else if (app.id == FIREFOX_ID) { + version = FIREFOX_APPCOMPATVERSION; + if (this.type == "locale") + //Never allow language packs in Firefox compatibility mode + return false; + } +#endif else if (app.id == TOOLKIT_ID) version = aPlatformVersion @@ -7248,20 +6479,24 @@ AddonInternal.prototype = { // Extremely old extensions should not be compatible by default. let minCompatVersion; +#ifdef MOZ_PHOENIX_EXTENSIONS + if (app.id == Services.appinfo.ID || app.id == FIREFOX_ID) +#else if (app.id == Services.appinfo.ID) +#endif minCompatVersion = XPIProvider.minCompatibleAppVersion; else if (app.id == TOOLKIT_ID) minCompatVersion = XPIProvider.minCompatiblePlatformVersion; if (minCompatVersion && - Services.vc.compare(minCompatVersion, maxVersion) > 0) + Services.vc.compare(minCompatVersion, app.maxVersion) > 0) return false; - return Services.vc.compare(version, minVersion) >= 0; + return Services.vc.compare(version, app.minVersion) >= 0; } - return (Services.vc.compare(version, minVersion) >= 0) && - (Services.vc.compare(version, maxVersion) <= 0) + return (Services.vc.compare(version, app.minVersion) >= 0) && + (Services.vc.compare(version, app.maxVersion) <= 0) }, get matchingTargetApplication() { @@ -7272,6 +6507,16 @@ AddonInternal.prototype = { if (targetApp.id == TOOLKIT_ID) app = targetApp; } +#ifdef MOZ_PHOENIX_EXTENSIONS + //Special case: check for Firefox TargetApps. this has to be done AFTER + //the initial check to make sure appinfo.ID is preferred, even if + //Firefox is listed before it in the install manifest. + for (let targetApp of this.targetApplications) { + if (targetApp.id == FIREFOX_ID) //Firefox GUID + return targetApp; + } +#endif + // Return toolkit ID if toolkit. return app; }, @@ -7280,7 +6525,7 @@ AddonInternal.prototype = { if (staticItem) return staticItem.level; - return Blocklist.getAddonBlocklistState(this.wrapper); + return Blocklist.getAddonBlocklistState(createWrapper(this)); }, get blocklistURL() { @@ -7290,19 +6535,22 @@ AddonInternal.prototype = { return url.replace(/%blockID%/g, staticItem.blockID); } - return Blocklist.getAddonBlocklistURL(this.wrapper); + return Blocklist.getAddonBlocklistURL(createWrapper(this)); }, - applyCompatibilityUpdate: function(aUpdate, aSyncCompatibility) { - for (let targetApp of this.targetApplications) { - for (let updateTarget of aUpdate.targetApplications) { - if (targetApp.id == updateTarget.id && (aSyncCompatibility || - Services.vc.compare(targetApp.maxVersion, updateTarget.maxVersion) < 0)) { - targetApp.minVersion = updateTarget.minVersion; - targetApp.maxVersion = updateTarget.maxVersion; - } - } + applyCompatibilityUpdate: function AddonInternal_applyCompatibilityUpdate(aUpdate, aSyncCompatibility) { + if (this.strictCompatibility) { + return; } + this.targetApplications.forEach(function(aTargetApp) { + aUpdate.targetApplications.forEach(function(aUpdateTarget) { + if (aTargetApp.id == aUpdateTarget.id && (aSyncCompatibility || + Services.vc.compare(aTargetApp.maxVersion, aUpdateTarget.maxVersion) < 0)) { + aTargetApp.minVersion = aUpdateTarget.minVersion; + aTargetApp.maxVersion = aUpdateTarget.maxVersion; + } + }); + }); if (aUpdate.multiprocessCompatible !== undefined) this.multiprocessCompatible = aUpdate.multiprocessCompatible; this.appDisabled = !isUsableAddon(this); @@ -7337,13 +6585,9 @@ AddonInternal.prototype = { * @return an object containing copies of the properties of this object * ignoring private properties, functions, getters and setters */ - toJSON: function(aKey) { + toJSON: function AddonInternal_toJSON(aKey) { let obj = {}; for (let prop in this) { - // Ignore the wrapper property - if (prop == "wrapper") - continue; - // Ignore private properties if (prop.substring(0, 1) == "_") continue; @@ -7374,25 +6618,32 @@ AddonInternal.prototype = { * @param aObj * A JS object containing the cached metadata */ - importMetadata: function(aObj) { - for (let prop of PENDING_INSTALL_METADATA) { - if (!(prop in aObj)) - continue; + importMetadata: function AddonInternal_importMetaData(aObj) { + PENDING_INSTALL_METADATA.forEach(function(aProp) { + if (!(aProp in aObj)) + return; - this[prop] = aObj[prop]; - } + this[aProp] = aObj[aProp]; + }, this); // Compatibility info may have changed so update appDisabled this.appDisabled = !isUsableAddon(this); }, - permissions: function() { + permissions: function AddonInternal_permissions() { let permissions = 0; // Add-ons that aren't installed cannot be modified in any way if (!(this.inDatabase)) return permissions; + // Experiments can only be uninstalled. An uninstall reflects the user + // intent of "disable this experiment." This is partially managed by the + // experiments manager. + if (this.type == "experiment") { + return AddonManager.PERM_CAN_UNINSTALL; + } + if (!this.appDisabled) { if (this.userDisabled || this.softDisabled) { permissions |= AddonManager.PERM_CAN_ENABLE; @@ -7405,13 +6656,8 @@ AddonInternal.prototype = { // Add-ons that are in locked install locations, or are pending uninstall // cannot be upgraded or uninstalled if (!this._installLocation.locked && !this.pendingUninstall) { - // Experiments cannot be upgraded. - // System add-on upgrades are triggered through a different mechanism (see updateSystemAddons()) - let isSystem = (this._installLocation.name == KEY_APP_SYSTEM_DEFAULTS || - this._installLocation.name == KEY_APP_SYSTEM_ADDONS); - // Add-ons that are installed by a file link cannot be upgraded. - if (this.type != "experiment" && - !this._installLocation.isLinkedAddon(this.id) && !isSystem) { + // Add-ons that are installed by a file link cannot be upgraded + if (!this._installLocation.isLinkedAddon(this.id)) { permissions |= AddonManager.PERM_CAN_UPGRADE; } @@ -7423,91 +6669,109 @@ AddonInternal.prototype = { }; /** + * Creates an AddonWrapper for an AddonInternal. + * + * @param addon + * The AddonInternal to wrap + * @return an AddonWrapper or null if addon was null + */ +function createWrapper(aAddon) { + if (!aAddon) + return null; + if (!aAddon._wrapper) { + aAddon._hasResourceCache = new Map(); + aAddon._wrapper = new AddonWrapper(aAddon); + } + return aAddon._wrapper; +} + +/** * The AddonWrapper wraps an Addon to provide the data visible to consumers of * the public API. */ function AddonWrapper(aAddon) { - wrapperMap.set(this, aAddon); -} - -AddonWrapper.prototype = { - get __AddonInternal__() { - return AppConstants.DEBUG ? addonFor(this) : undefined; - }, +#ifdef MOZ_EM_DEBUG + this.__defineGetter__("__AddonInternal__", function AW_debugGetter() { + return aAddon; + }); +#endif - get seen() { - return addonFor(this).seen; - }, + function chooseValue(aObj, aProp) { + let repositoryAddon = aAddon._repositoryAddon; + let objValue = aObj[aProp]; - get hasEmbeddedWebExtension() { - return addonFor(this).hasEmbeddedWebExtension; - }, + if (repositoryAddon && (aProp in repositoryAddon) && + (objValue === undefined || objValue === null)) { + return [repositoryAddon[aProp], true]; + } - markAsSeen: function() { - addonFor(this).seen = true; - XPIDatabase.saveChanges(); - }, + return [objValue, false]; + } - get type() { - return getExternalType(addonFor(this).type); - }, + ["id", "syncGUID", "version", "type", "isCompatible", "isPlatformCompatible", + "providesUpdatesSecurely", "blocklistState", "blocklistURL", "appDisabled", + "softDisabled", "skinnable", "size", "foreignInstall", "hasBinaryComponents", + "strictCompatibility", "compatibilityOverrides", "updateURL", + "getDataDirectory", "multiprocessCompatible", "native"].forEach(function(aProp) { + this.__defineGetter__(aProp, function AddonWrapper_propertyGetter() aAddon[aProp]); + }, this); + + ["fullDescription", "developerComments", "eula", "supportURL", + "contributionURL", "contributionAmount", "averageRating", "reviewCount", + "reviewURL", "totalDownloads", "weeklyDownloads", "dailyUsers", + "repositoryStatus"].forEach(function(aProp) { + this.__defineGetter__(aProp, function AddonWrapper_repoPropertyGetter() { + if (aAddon._repositoryAddon) + return aAddon._repositoryAddon[aProp]; - get isWebExtension() { - return addonFor(this).type == "webextension"; - }, + return null; + }); + }, this); - get temporarilyInstalled() { - return addonFor(this)._installLocation == TemporaryInstallLocation; - }, + this.__defineGetter__("aboutURL", function AddonWrapper_aboutURLGetter() { + return this.isActive ? aAddon["aboutURL"] : null; + }); - get aboutURL() { - return this.isActive ? addonFor(this)["aboutURL"] : null; - }, + ["installDate", "updateDate"].forEach(function(aProp) { + this.__defineGetter__(aProp, function AddonWrapper_datePropertyGetter() new Date(aAddon[aProp])); + }, this); - get optionsURL() { - if (!this.isActive) { - return null; - } + ["sourceURI", "releaseNotesURI"].forEach(function(aProp) { + this.__defineGetter__(aProp, function AddonWrapper_URIPropertyGetter() { + let [target, fromRepo] = chooseValue(aAddon, aProp); + if (!target) + return null; + if (fromRepo) + return target; + return NetUtil.newURI(target); + }); + }, this); - let addon = addonFor(this); - if (addon.optionsURL) { - if (this.isWebExtension || this.hasEmbeddedWebExtension) { - // The internal object's optionsURL property comes from the addons - // DB and should be a relative URL. However, extensions with - // options pages installed before bug 1293721 was fixed got absolute - // URLs in the addons db. This code handles both cases. - let base = ExtensionManagement.getURLForExtension(addon.id); - if (!base) { - return null; - } - return new URL(addon.optionsURL, base).href; - } - return addon.optionsURL; - } + this.__defineGetter__("optionsURL", function AddonWrapper_optionsURLGetter() { + if (this.isActive && aAddon.optionsURL) + return aAddon.optionsURL; - if (this.hasResource("options.xul")) + if (this.isActive && this.hasResource("options.xul")) return this.getResourceURI("options.xul").spec; return null; - }, + }, this); - get optionsType() { + this.__defineGetter__("optionsType", function AddonWrapper_optionsTypeGetter() { if (!this.isActive) return null; - let addon = addonFor(this); let hasOptionsXUL = this.hasResource("options.xul"); let hasOptionsURL = !!this.optionsURL; - if (addon.optionsType) { - switch (parseInt(addon.optionsType, 10)) { + if (aAddon.optionsType) { + switch (parseInt(aAddon.optionsType, 10)) { case AddonManager.OPTIONS_TYPE_DIALOG: case AddonManager.OPTIONS_TYPE_TAB: - return hasOptionsURL ? addon.optionsType : null; + return hasOptionsURL ? aAddon.optionsType : null; case AddonManager.OPTIONS_TYPE_INLINE: case AddonManager.OPTIONS_TYPE_INLINE_INFO: - case AddonManager.OPTIONS_TYPE_INLINE_BROWSER: - return (hasOptionsXUL || hasOptionsURL) ? addon.optionsType : null; + return (hasOptionsXUL || hasOptionsURL) ? aAddon.optionsType : null; } return null; } @@ -7519,78 +6783,132 @@ AddonWrapper.prototype = { return AddonManager.OPTIONS_TYPE_DIALOG; return null; - }, + }, this); - get iconURL() { - return AddonManager.getPreferredIconURL(this, 48); - }, + this.__defineGetter__("iconURL", function AddonWrapper_iconURLGetter() { + return this.icons[32] || undefined; + }, this); - get icon64URL() { - return AddonManager.getPreferredIconURL(this, 64); - }, + this.__defineGetter__("icon64URL", function AddonWrapper_icon64URLGetter() { + return this.icons[64] || undefined; + }, this); - get icons() { - let addon = addonFor(this); + this.__defineGetter__("icons", function AddonWrapper_iconsGetter() { let icons = {}; - - if (addon._repositoryAddon) { - for (let size in addon._repositoryAddon.icons) { - icons[size] = addon._repositoryAddon.icons[size]; + if (aAddon._repositoryAddon) { + for (let size in aAddon._repositoryAddon.icons) { + icons[size] = aAddon._repositoryAddon.icons[size]; } } + if (this.isActive && aAddon.iconURL) { + icons[32] = aAddon.iconURL; + } else if (this.hasResource("icon.png")) { + icons[32] = this.getResourceURI("icon.png").spec; + } + if (this.isActive && aAddon.icon64URL) { + icons[64] = aAddon.icon64URL; + } else if (this.hasResource("icon64.png")) { + icons[64] = this.getResourceURI("icon64.png").spec; + } + Object.freeze(icons); + return icons; + }, this); - if (addon.icons) { - for (let size in addon.icons) { - icons[size] = this.getResourceURI(addon.icons[size]).spec; + PROP_LOCALE_SINGLE.forEach(function(aProp) { + this.__defineGetter__(aProp, function AddonWrapper_singleLocaleGetter() { + // Override XPI creator if repository creator is defined + if (aProp == "creator" && + aAddon._repositoryAddon && aAddon._repositoryAddon.creator) { + return aAddon._repositoryAddon.creator; } - } else { - // legacy add-on that did not update its icon data yet - if (this.hasResource("icon.png")) { - icons[32] = icons[48] = this.getResourceURI("icon.png").spec; + + let result = null; + + if (aAddon.active) { + try { + let pref = PREF_EM_EXTENSION_FORMAT + aAddon.id + "." + aProp; + let value = Preferences.get(pref, null, Ci.nsIPrefLocalizedString); + if (value) + result = value; + } + catch (e) { + } } - if (this.hasResource("icon64.png")) { - icons[64] = this.getResourceURI("icon64.png").spec; + + if (result == null) { + if (typeof aAddon.selectedLocale[aProp] == "string" && aAddon.selectedLocale[aProp].length) + [result, ] = chooseValue(aAddon.selectedLocale, aProp); + else + [result, ] = chooseValue(aAddon.defaultLocale, aProp); } - } - if (this.isActive && addon.iconURL) { - icons[32] = addon.iconURL; - icons[48] = addon.iconURL; - } + if (aProp == "creator") + return result ? new AddonManagerPrivate.AddonAuthor(result) : null; - if (this.isActive && addon.icon64URL) { - icons[64] = addon.icon64URL; - } + return result; + }); + }, this); + + PROP_LOCALE_MULTI.forEach(function(aProp) { + this.__defineGetter__(aProp, function AddonWrapper_multiLocaleGetter() { + let results = null; + let usedRepository = false; + + if (aAddon.active) { + let pref = PREF_EM_EXTENSION_FORMAT + aAddon.id + "." + + aProp.substring(0, aProp.length - 1); + let list = Services.prefs.getChildList(pref, {}); + if (list.length > 0) { + list.sort(); + results = []; + list.forEach(function(aPref) { + let value = Preferences.get(aPref, null, Ci.nsIPrefLocalizedString); + if (value) + results.push(value); + }); + } + } - Object.freeze(icons); - return icons; - }, + if (results == null) { + if (aAddon.selectedLocale[aProp] instanceof Array && aAddon.selectedLocale[aProp].length) + [results, usedRepository] = chooseValue(aAddon.selectedLocale, aProp); + else + [results, usedRepository] = chooseValue(aAddon.defaultLocale, aProp); + } + + if (results && !usedRepository) { + results = results.map(function mapResult(aResult) { + return new AddonManagerPrivate.AddonAuthor(aResult); + }); + } - get screenshots() { - let addon = addonFor(this); - let repositoryAddon = addon._repositoryAddon; + return results; + }); + }, this); + + this.__defineGetter__("screenshots", function AddonWrapper_screenshotsGetter() { + let repositoryAddon = aAddon._repositoryAddon; if (repositoryAddon && ("screenshots" in repositoryAddon)) { let repositoryScreenshots = repositoryAddon.screenshots; if (repositoryScreenshots && repositoryScreenshots.length > 0) return repositoryScreenshots; } - if (addon.type == "theme" && this.hasResource("preview.png")) { + if (aAddon.type == "theme" && this.hasResource("preview.png")) { let url = this.getResourceURI("preview.png").spec; return [new AddonManagerPrivate.AddonScreenshot(url)]; } return null; - }, + }); - get applyBackgroundUpdates() { - return addonFor(this).applyBackgroundUpdates; - }, - set applyBackgroundUpdates(val) { - let addon = addonFor(this); + this.__defineGetter__("applyBackgroundUpdates", function AddonWrapper_applyBackgroundUpdatesGetter() { + return aAddon.applyBackgroundUpdates; + }); + this.__defineSetter__("applyBackgroundUpdates", function AddonWrapper_applyBackgroundUpdatesSetter(val) { if (this.type == "experiment") { logger.warn("Setting applyBackgroundUpdates on an experiment is not supported."); - return addon.applyBackgroundUpdates; + return; } if (val != AddonManager.AUTOUPDATE_DEFAULT && @@ -7600,211 +6918,184 @@ AddonWrapper.prototype = { AddonManager.AUTOUPDATE_DISABLE; } - if (val == addon.applyBackgroundUpdates) + if (val == aAddon.applyBackgroundUpdates) return val; - XPIDatabase.setAddonProperties(addon, { + XPIDatabase.setAddonProperties(aAddon, { applyBackgroundUpdates: val }); AddonManagerPrivate.callAddonListeners("onPropertyChanged", this, ["applyBackgroundUpdates"]); return val; - }, + }); - set syncGUID(val) { - let addon = addonFor(this); - if (addon.syncGUID == val) + this.__defineSetter__("syncGUID", function AddonWrapper_syncGUIDGetter(val) { + if (aAddon.syncGUID == val) return val; - if (addon.inDatabase) - XPIDatabase.setAddonSyncGUID(addon, val); + if (aAddon.inDatabase) + XPIDatabase.setAddonSyncGUID(aAddon, val); - addon.syncGUID = val; + aAddon.syncGUID = val; return val; - }, + }); - get install() { - let addon = addonFor(this); - if (!("_install" in addon) || !addon._install) + this.__defineGetter__("install", function AddonWrapper_installGetter() { + if (!("_install" in aAddon) || !aAddon._install) return null; - return addon._install.wrapper; - }, + return aAddon._install.wrapper; + }); - get pendingUpgrade() { - let addon = addonFor(this); - return addon.pendingUpgrade ? addon.pendingUpgrade.wrapper : null; - }, + this.__defineGetter__("pendingUpgrade", function AddonWrapper_pendingUpgradeGetter() { + return createWrapper(aAddon.pendingUpgrade); + }); - get scope() { - let addon = addonFor(this); - if (addon._installLocation) - return addon._installLocation.scope; + this.__defineGetter__("scope", function AddonWrapper_scopeGetter() { + if (aAddon._installLocation) + return aAddon._installLocation.scope; return AddonManager.SCOPE_PROFILE; - }, + }); - get pendingOperations() { - let addon = addonFor(this); + this.__defineGetter__("pendingOperations", function AddonWrapper_pendingOperationsGetter() { let pending = 0; - if (!(addon.inDatabase)) { + if (!(aAddon.inDatabase)) { // Add-on is pending install if there is no associated install (shouldn't // happen here) or if the install is in the process of or has successfully // completed the install. If an add-on is pending install then we ignore // any other pending operations. - if (!addon._install || addon._install.state == AddonManager.STATE_INSTALLING || - addon._install.state == AddonManager.STATE_INSTALLED) + if (!aAddon._install || aAddon._install.state == AddonManager.STATE_INSTALLING || + aAddon._install.state == AddonManager.STATE_INSTALLED) return AddonManager.PENDING_INSTALL; } - else if (addon.pendingUninstall) { + else if (aAddon.pendingUninstall) { // If an add-on is pending uninstall then we ignore any other pending // operations return AddonManager.PENDING_UNINSTALL; } - if (addon.active && addon.disabled) - pending |= AddonManager.PENDING_DISABLE; - else if (!addon.active && !addon.disabled) - pending |= AddonManager.PENDING_ENABLE; + // Extensions have an intentional inconsistency between what the DB says is + // enabled and what we say to the ouside world. so we need to cover up that + // lie here as well. + if (aAddon.type != "experiment") { + if (aAddon.active && aAddon.disabled) + pending |= AddonManager.PENDING_DISABLE; + else if (!aAddon.active && !aAddon.disabled) + pending |= AddonManager.PENDING_ENABLE; + } - if (addon.pendingUpgrade) + if (aAddon.pendingUpgrade) pending |= AddonManager.PENDING_UPGRADE; return pending; - }, + }); - get operationsRequiringRestart() { - let addon = addonFor(this); + this.__defineGetter__("operationsRequiringRestart", function AddonWrapper_operationsRequiringRestartGetter() { let ops = 0; - if (XPIProvider.installRequiresRestart(addon)) + if (XPIProvider.installRequiresRestart(aAddon)) ops |= AddonManager.OP_NEEDS_RESTART_INSTALL; - if (XPIProvider.uninstallRequiresRestart(addon)) + if (XPIProvider.uninstallRequiresRestart(aAddon)) ops |= AddonManager.OP_NEEDS_RESTART_UNINSTALL; - if (XPIProvider.enableRequiresRestart(addon)) + if (XPIProvider.enableRequiresRestart(aAddon)) ops |= AddonManager.OP_NEEDS_RESTART_ENABLE; - if (XPIProvider.disableRequiresRestart(addon)) + if (XPIProvider.disableRequiresRestart(aAddon)) ops |= AddonManager.OP_NEEDS_RESTART_DISABLE; return ops; - }, + }); - get isDebuggable() { - return this.isActive && addonFor(this).bootstrap; - }, + this.__defineGetter__("isDebuggable", function AddonWrapper_isDebuggable() { + return this.isActive && aAddon.bootstrap; + }); - get permissions() { - return addonFor(this).permissions(); - }, + this.__defineGetter__("permissions", function AddonWrapper_permisionsGetter() { + return aAddon.permissions(); + }); - get isActive() { - let addon = addonFor(this); - if (!addon.active) + this.__defineGetter__("isActive", function AddonWrapper_isActiveGetter() { + if (Services.appinfo.inSafeMode) return false; - if (!Services.appinfo.inSafeMode) - return true; - return addon.bootstrap && canRunInSafeMode(addon); - }, + return aAddon.active; + }); - get userDisabled() { - let addon = addonFor(this); - return addon.softDisabled || addon.userDisabled; - }, - set userDisabled(val) { - let addon = addonFor(this); + this.__defineGetter__("userDisabled", function AddonWrapper_userDisabledGetter() { + if (XPIProvider._enabledExperiments.has(aAddon.id)) { + return false; + } + + return aAddon.softDisabled || aAddon.userDisabled; + }); + this.__defineSetter__("userDisabled", function AddonWrapper_userDisabledSetter(val) { if (val == this.userDisabled) { return val; } - if (addon.inDatabase) { - if (addon.type == "theme" && val) { - if (addon.internalName == XPIProvider.defaultSkin) + if (aAddon.type == "experiment") { + if (val) { + XPIProvider._enabledExperiments.delete(aAddon.id); + } else { + XPIProvider._enabledExperiments.add(aAddon.id); + } + } + + if (aAddon.inDatabase) { + if (aAddon.type == "theme" && val) { + if (aAddon.internalName == XPIProvider.defaultSkin) throw new Error("Cannot disable the default theme"); XPIProvider.enableDefaultTheme(); } else { - // hidden and system add-ons should not be user disasbled, - // as there is no UI to re-enable them. - if (this.hidden) { - throw new Error(`Cannot disable hidden add-on ${addon.id}`); - } - XPIProvider.updateAddonDisabledState(addon, val); + XPIProvider.updateAddonDisabledState(aAddon, val); } } else { - addon.userDisabled = val; + aAddon.userDisabled = val; // When enabling remove the softDisabled flag if (!val) - addon.softDisabled = false; + aAddon.softDisabled = false; } return val; - }, + }); - set softDisabled(val) { - let addon = addonFor(this); - if (val == addon.softDisabled) + this.__defineSetter__("softDisabled", function AddonWrapper_softDisabledSetter(val) { + if (val == aAddon.softDisabled) return val; - if (addon.inDatabase) { + if (aAddon.inDatabase) { // When softDisabling a theme just enable the active theme - if (addon.type == "theme" && val && !addon.userDisabled) { - if (addon.internalName == XPIProvider.defaultSkin) + if (aAddon.type == "theme" && val && !aAddon.userDisabled) { + if (aAddon.internalName == XPIProvider.defaultSkin) throw new Error("Cannot disable the default theme"); XPIProvider.enableDefaultTheme(); } else { - XPIProvider.updateAddonDisabledState(addon, undefined, val); + XPIProvider.updateAddonDisabledState(aAddon, undefined, val); } } - else if (!addon.userDisabled) { + else { // Only set softDisabled if not already disabled - addon.softDisabled = val; + if (!aAddon.userDisabled) + aAddon.softDisabled = val; } return val; - }, - - get hidden() { - let addon = addonFor(this); - if (addon._installLocation.name == KEY_APP_TEMPORARY) - return false; - - return (addon._installLocation.name == KEY_APP_SYSTEM_DEFAULTS || - addon._installLocation.name == KEY_APP_SYSTEM_ADDONS); - }, - - get isSystem() { - let addon = addonFor(this); - return (addon._installLocation.name == KEY_APP_SYSTEM_DEFAULTS || - addon._installLocation.name == KEY_APP_SYSTEM_ADDONS); - }, - - // Returns true if Firefox Sync should sync this addon. Only non-hotfixes - // directly in the profile are considered syncable. - get isSyncable() { - let addon = addonFor(this); - let hotfixID = Preferences.get(PREF_EM_HOTFIX_ID, undefined); - if (hotfixID && hotfixID == addon.id) { - return false; - } - return (addon._installLocation.name == KEY_APP_PROFILE); - }, + }); - isCompatibleWith: function(aAppVersion, aPlatformVersion) { - return addonFor(this).isCompatibleWith(aAppVersion, aPlatformVersion); - }, + this.isCompatibleWith = function AddonWrapper_isCompatiblewith(aAppVersion, aPlatformVersion) { + return aAddon.isCompatibleWith(aAppVersion, aPlatformVersion); + }; - uninstall: function(alwaysAllowUndo) { - let addon = addonFor(this); - XPIProvider.uninstallAddon(addon, alwaysAllowUndo); - }, + this.uninstall = function AddonWrapper_uninstall(alwaysAllowUndo) { + XPIProvider.uninstallAddon(aAddon, alwaysAllowUndo); + }; - cancelUninstall: function() { - let addon = addonFor(this); - XPIProvider.cancelUninstallAddon(addon); - }, + this.cancelUninstall = function AddonWrapper_cancelUninstall() { + XPIProvider.cancelUninstallAddon(aAddon); + }; - findUpdates: function(aListener, aReason, aAppVersion, aPlatformVersion) { + this.findUpdates = function AddonWrapper_findUpdates(aListener, aReason, aAppVersion, aPlatformVersion) { // Short-circuit updates for experiments because updates are handled // through the Experiments Manager. if (this.type == "experiment") { @@ -7813,40 +7104,41 @@ AddonWrapper.prototype = { return; } - new UpdateChecker(addonFor(this), aListener, aReason, aAppVersion, aPlatformVersion); - }, + new UpdateChecker(aAddon, aListener, aReason, aAppVersion, aPlatformVersion); + }; // Returns true if there was an update in progress, false if there was no update to cancel - cancelUpdate: function() { - let addon = addonFor(this); - if (addon._updateCheck) { - addon._updateCheck.cancel(); + this.cancelUpdate = function AddonWrapper_cancelUpdate() { + if (aAddon._updateCheck) { + aAddon._updateCheck.cancel(); return true; } return false; - }, + }; - hasResource: function(aPath) { - let addon = addonFor(this); - if (addon._hasResourceCache.has(aPath)) - return addon._hasResourceCache.get(aPath); + this.hasResource = function AddonWrapper_hasResource(aPath) { + if (aAddon._hasResourceCache.has(aPath)) + return aAddon._hasResourceCache.get(aPath); - let bundle = addon._sourceBundle.clone(); + let bundle = aAddon._sourceBundle.clone(); // Bundle may not exist any more if the addon has just been uninstalled, // but explicitly first checking .exists() results in unneeded file I/O. try { var isDir = bundle.isDirectory(); } catch (e) { - addon._hasResourceCache.set(aPath, false); + aAddon._hasResourceCache.set(aPath, false); return false; } if (isDir) { - if (aPath) - aPath.split("/").forEach(part => bundle.append(part)); + if (aPath) { + aPath.split("/").forEach(function(aPart) { + bundle.append(aPart); + }); + } let result = bundle.exists(); - addon._hasResourceCache.set(aPath, result); + aAddon._hasResourceCache.set(aPath, result); return result; } @@ -7855,11 +7147,11 @@ AddonWrapper.prototype = { try { zipReader.open(bundle); let result = zipReader.hasEntry(aPath); - addon._hasResourceCache.set(aPath, result); + aAddon._hasResourceCache.set(aPath, result); return result; } catch (e) { - addon._hasResourceCache.set(aPath, false); + aAddon._hasResourceCache.set(aPath, false); return false; } finally { @@ -7868,34 +7160,6 @@ AddonWrapper.prototype = { }, /** - * Reloads the add-on. - * - * For temporarily installed add-ons, this uninstalls and re-installs the - * add-on. Otherwise, the addon is disabled and then re-enabled, and the cache - * is flushed. - * - * @return Promise - */ - reload: function() { - return new Promise((resolve) => { - const addon = addonFor(this); - - logger.debug(`reloading add-on ${addon.id}`); - - if (!this.temporarilyInstalled) { - let addonFile = addon.getResourceURI; - XPIProvider.updateAddonDisabledState(addon, true); - Services.obs.notifyObservers(addonFile, "flush-cache-entry", null); - XPIProvider.updateAddonDisabledState(addon, false) - resolve(); - } else { - // This function supports re-installing an existing add-on. - resolve(AddonManager.installTemporaryAddon(addon._sourceBundle)); - } - }); - }, - - /** * Returns a URI to the selected resource or to the add-on bundle if aPath * is null. URIs to the bundle will always be file: URIs. URIs to resources * will be file: URIs if the add-on is unpacked or jar: URIs if the add-on is @@ -7906,216 +7170,14 @@ AddonWrapper.prototype = { * the file or directory the add-on is installed as. * @return an nsIURI */ - getResourceURI: function(aPath) { - let addon = addonFor(this); + this.getResourceURI = function AddonWrapper_getResourceURI(aPath) { if (!aPath) - return NetUtil.newURI(addon._sourceBundle); - - return getURIForResourceInFile(addon._sourceBundle, aPath); - } -}; - -/** - * The PrivateWrapper is used to expose certain functionality only when being - * called with the add-on instanceID, disallowing other add-ons to access it. - */ -function PrivateWrapper(aAddon) { - AddonWrapper.call(this, aAddon); -} - -PrivateWrapper.prototype = Object.create(AddonWrapper.prototype); -Object.assign(PrivateWrapper.prototype, { - addonId() { - return this.id; - }, + return NetUtil.newURI(aAddon._sourceBundle); - /** - * Retrieves the preferred global context to be used from the - * add-on debugging window. - * - * @returns global - * The object set as global context. Must be a window object. - */ - getDebugGlobal(global) { - let activeAddon = XPIProvider.activeAddons.get(this.id); - if (activeAddon) { - return activeAddon.debugGlobal; - } - - return null; - }, - - /** - * Defines a global context to be used in the console - * of the add-on debugging window. - * - * @param global - * The object to set as global context. Must be a window object. - */ - setDebugGlobal(global) { - if (!global) { - // If the new global is null, notify the listeners regardless - // from the current state of the addon. - // NOTE: this happen after the addon has been disabled and - // the global will never be set to null otherwise. - AddonManagerPrivate.callAddonListeners("onPropertyChanged", - addonFor(this), - ["debugGlobal"]); - } else { - let activeAddon = XPIProvider.activeAddons.get(this.id); - if (activeAddon) { - let globalChanged = activeAddon.debugGlobal != global; - activeAddon.debugGlobal = global; - - if (globalChanged) { - AddonManagerPrivate.callAddonListeners("onPropertyChanged", - addonFor(this), - ["debugGlobal"]); - } - } - } - } -}); - -function chooseValue(aAddon, aObj, aProp) { - let repositoryAddon = aAddon._repositoryAddon; - let objValue = aObj[aProp]; - - if (repositoryAddon && (aProp in repositoryAddon) && - (objValue === undefined || objValue === null)) { - return [repositoryAddon[aProp], true]; + return getURIForResourceInFile(aAddon._sourceBundle, aPath); } - - return [objValue, false]; -} - -function defineAddonWrapperProperty(name, getter) { - Object.defineProperty(AddonWrapper.prototype, name, { - get: getter, - enumerable: true, - }); } -["id", "syncGUID", "version", "isCompatible", "isPlatformCompatible", - "providesUpdatesSecurely", "blocklistState", "blocklistURL", "appDisabled", - "softDisabled", "skinnable", "size", "foreignInstall", "hasBinaryComponents", - "strictCompatibility", "compatibilityOverrides", "updateURL", "dependencies", - "getDataDirectory", "multiprocessCompatible", "signedState", "mpcOptedOut", - "isCorrectlySigned"].forEach(function(aProp) { - defineAddonWrapperProperty(aProp, function() { - let addon = addonFor(this); - return (aProp in addon) ? addon[aProp] : undefined; - }); -}); - -["fullDescription", "developerComments", "eula", "supportURL", - "contributionURL", "contributionAmount", "averageRating", "reviewCount", - "reviewURL", "totalDownloads", "weeklyDownloads", "dailyUsers", - "repositoryStatus"].forEach(function(aProp) { - defineAddonWrapperProperty(aProp, function() { - let addon = addonFor(this); - if (addon._repositoryAddon) - return addon._repositoryAddon[aProp]; - - return null; - }); -}); - -["installDate", "updateDate"].forEach(function(aProp) { - defineAddonWrapperProperty(aProp, function() { - return new Date(addonFor(this)[aProp]); - }); -}); - -["sourceURI", "releaseNotesURI"].forEach(function(aProp) { - defineAddonWrapperProperty(aProp, function() { - let addon = addonFor(this); - - // Temporary Installed Addons do not have a "sourceURI", - // But we can use the "_sourceBundle" as an alternative, - // which points to the path of the addon xpi installed - // or its source dir (if it has been installed from a - // directory). - if (aProp == "sourceURI" && this.temporarilyInstalled) { - return Services.io.newFileURI(addon._sourceBundle); - } - - let [target, fromRepo] = chooseValue(addon, addon, aProp); - if (!target) - return null; - if (fromRepo) - return target; - return NetUtil.newURI(target); - }); -}); - -PROP_LOCALE_SINGLE.forEach(function(aProp) { - defineAddonWrapperProperty(aProp, function() { - let addon = addonFor(this); - // Override XPI creator if repository creator is defined - if (aProp == "creator" && - addon._repositoryAddon && addon._repositoryAddon.creator) { - return addon._repositoryAddon.creator; - } - - let result = null; - - if (addon.active) { - try { - let pref = PREF_EM_EXTENSION_FORMAT + addon.id + "." + aProp; - let value = Preferences.get(pref, null, Ci.nsIPrefLocalizedString); - if (value) - result = value; - } - catch (e) { - } - } - - let rest; - if (result == null) - [result, ...rest] = chooseValue(addon, addon.selectedLocale, aProp); - - if (aProp == "creator") - return result ? new AddonManagerPrivate.AddonAuthor(result) : null; - - return result; - }); -}); - -PROP_LOCALE_MULTI.forEach(function(aProp) { - defineAddonWrapperProperty(aProp, function() { - let addon = addonFor(this); - let results = null; - let usedRepository = false; - - if (addon.active) { - let pref = PREF_EM_EXTENSION_FORMAT + addon.id + "." + - aProp.substring(0, aProp.length - 1); - let list = Services.prefs.getChildList(pref, {}); - if (list.length > 0) { - list.sort(); - results = []; - for (let childPref of list) { - let value = Preferences.get(childPref, null, Ci.nsIPrefLocalizedString); - if (value) - results.push(value); - } - } - } - - if (results == null) - [results, usedRepository] = chooseValue(addon, addon.selectedLocale, aProp); - - if (results && !usedRepository) { - results = results.map(function(aResult) { - return new AddonManagerPrivate.AddonAuthor(aResult); - }); - } - - return results; - }); -}); - /** * An object which identifies a directory install location for add-ons. The * location consists of a directory which contains the add-ons installed in the @@ -8126,22 +7188,33 @@ PROP_LOCALE_MULTI.forEach(function(aProp) { * containing the add-ons files. The directory or text file must have the same * name as the add-on's ID. * + * There may also a special directory named "staged" which can contain + * directories with the same name as an add-on ID. If the directory is empty + * then it means the add-on will be uninstalled from this location during the + * next startup. If the directory contains the add-on's files then they will be + * installed during the next startup. + * * @param aName * The string identifier for the install location * @param aDirectory * The nsIFile directory for the install location * @param aScope * The scope of add-ons installed in this location + * @param aLocked + * true if add-ons cannot be installed, uninstalled or upgraded in the + * install location */ -function DirectoryInstallLocation(aName, aDirectory, aScope) { +function DirectoryInstallLocation(aName, aDirectory, aScope, aLocked) { this._name = aName; - this.locked = true; + this.locked = aLocked; this._directory = aDirectory; this._scope = aScope this._IDToFileMap = {}; + this._FileToIDMap = {}; this._linkedAddons = []; + this._stagingDirLock = 0; - if (!aDirectory || !aDirectory.exists()) + if (!aDirectory.exists()) return; if (!aDirectory.isDirectory()) throw new Error("Location must be a directory."); @@ -8153,6 +7226,7 @@ DirectoryInstallLocation.prototype = { _name : "", _directory : null, _IDToFileMap : null, // mapping from add-on ID to nsIFile + _FileToIDMap : null, // mapping from add-on path to add-on ID /** * Reads a directory linked to in a file. @@ -8161,40 +7235,25 @@ DirectoryInstallLocation.prototype = { * The file containing the directory path * @return An nsIFile object representing the linked directory. */ - _readDirectoryFromFile: function(aFile) { - let linkedDirectory; - if (aFile.isSymlink()) { - linkedDirectory = aFile.clone(); + _readDirectoryFromFile: function DirInstallLocation__readDirectoryFromFile(aFile) { + let fis = Cc["@mozilla.org/network/file-input-stream;1"]. + createInstance(Ci.nsIFileInputStream); + fis.init(aFile, -1, -1, false); + let line = { value: "" }; + if (fis instanceof Ci.nsILineInputStream) + fis.readLine(line); + fis.close(); + if (line.value) { + let linkedDirectory = Cc["@mozilla.org/file/local;1"]. + createInstance(Ci.nsIFile); + try { - linkedDirectory.normalize(); - } catch (e) { - logger.warn("Symbolic link " + aFile.path + " points to a path" + - " which does not exist"); - return null; + linkedDirectory.initWithPath(line.value); } - } - else { - let fis = Cc["@mozilla.org/network/file-input-stream;1"]. - createInstance(Ci.nsIFileInputStream); - fis.init(aFile, -1, -1, false); - let line = { value: "" }; - if (fis instanceof Ci.nsILineInputStream) - fis.readLine(line); - fis.close(); - if (line.value) { - linkedDirectory = Cc["@mozilla.org/file/local;1"]. - createInstance(Ci.nsIFile); - - try { - linkedDirectory.initWithPath(line.value); - } - catch (e) { - linkedDirectory.setRelativeDescriptor(aFile.parent, line.value); - } + catch (e) { + linkedDirectory.setRelativeDescriptor(aFile.parent, line.value); } - } - if (linkedDirectory) { if (!linkedDirectory.exists()) { logger.warn("File pointer " + aFile.path + " points to " + linkedDirectory.path + " which does not exist"); @@ -8217,7 +7276,7 @@ DirectoryInstallLocation.prototype = { /** * Finds all the add-ons installed in this location. */ - _readAddons: function() { + _readAddons: function DirInstallLocation__readAddons() { // Use a snapshot of the directory contents to avoid possible issues with // iterating over a directory while removing files from it (the YAFFS2 // embedded filesystem has this issue, see bug 772238). @@ -8225,7 +7284,7 @@ DirectoryInstallLocation.prototype = { for (let entry of entries) { let id = entry.leafName; - if (id == DIR_STAGE || id == DIR_TRASH) + if (id == DIR_STAGE || id == DIR_XPI_STAGE || id == DIR_TRASH) continue; let directLoad = false; @@ -8241,7 +7300,7 @@ DirectoryInstallLocation.prototype = { continue; } - if (!directLoad && (entry.isFile() || entry.isSymlink())) { + if (entry.isFile() && !directLoad) { let newEntry = this._readDirectoryFromFile(entry); if (!newEntry) { logger.debug("Deleting stale pointer file " + entry.path); @@ -8260,6 +7319,7 @@ DirectoryInstallLocation.prototype = { } this._IDToFileMap[id] = entry; + this._FileToIDMap[entry.path] = id; XPIProvider._addURIMapping(id, entry); } }, @@ -8281,66 +7341,21 @@ DirectoryInstallLocation.prototype = { /** * Gets an array of nsIFiles for add-ons installed in this location. */ - getAddonLocations: function() { - let locations = new Map(); + get addonLocations() { + let locations = []; for (let id in this._IDToFileMap) { - locations.set(id, this._IDToFileMap[id].clone()); + locations.push(this._IDToFileMap[id].clone()); } return locations; }, /** - * Gets the directory that the add-on with the given ID is installed in. - * - * @param aId - * The ID of the add-on - * @return The nsIFile - * @throws if the ID does not match any of the add-ons installed - */ - getLocationForID: function(aId) { - if (aId in this._IDToFileMap) - return this._IDToFileMap[aId].clone(); - throw new Error("Unknown add-on ID " + aId); - }, - - /** - * Returns true if the given addon was installed in this location by a text - * file pointing to its real path. - * - * @param aId - * The ID of the addon - */ - isLinkedAddon: function(aId) { - return this._linkedAddons.indexOf(aId) != -1; - } -}; - -/** - * An extension of DirectoryInstallLocation which adds methods to installing - * and removing add-ons from the directory at runtime. - * - * @param aName - * The string identifier for the install location - * @param aDirectory - * The nsIFile directory for the install location - * @param aScope - * The scope of add-ons installed in this location - */ -function MutableDirectoryInstallLocation(aName, aDirectory, aScope) { - DirectoryInstallLocation.call(this, aName, aDirectory, aScope); - this.locked = false; - this._stagingDirLock = 0; -} - -MutableDirectoryInstallLocation.prototype = Object.create(DirectoryInstallLocation.prototype); -Object.assign(MutableDirectoryInstallLocation.prototype, { - /** * Gets the staging directory to put add-ons that are pending install and * uninstall into. * * @return an nsIFile */ - getStagingDir: function() { + getStagingDir: function DirInstallLocation_getStagingDir() { let dir = this._directory.clone(); dir.append(DIR_STAGE); return dir; @@ -8413,6 +7428,18 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { }, /** + * Gets the directory used by old versions for staging XPI and JAR files ready + * to be installed. + * + * @return an nsIFile + */ + getXPIStagingDir: function DirInstallLocation_getXPIStagingDir() { + let dir = this._directory.clone(); + dir.append(DIR_XPI_STAGE); + return dir; + }, + + /** * Returns a directory that is normally on the same filesystem as the rest of * the install location and can be used for temporarily storing files during * safe move operations. Calling this method will delete the existing trash @@ -8420,7 +7447,7 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { * * @return an nsIFile */ - getTrashDir: function() { + getTrashDir: function DirInstallLocation_getTrashDir() { let trashDir = this._directory.clone(); trashDir.append(DIR_TRASH); let trashDirExists = trashDir.exists(); @@ -8433,43 +7460,39 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { } if (!trashDirExists) trashDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - return trashDir; }, /** * Installs an add-on into the install location. * - * @param id + * @param aId * The ID of the add-on to install - * @param source + * @param aSource * The source nsIFile to install from - * @param existingAddonID + * @param aExistingAddonID * The ID of an existing add-on to uninstall at the same time - * @param action - * What to we do with the given source file: - * "move" - * Default action, the source files will be moved to the new - * location, - * "copy" - * The source files will be copied, - * "proxy" - * A "proxy file" is going to refer to the source file path + * @param aCopy + * If false the source files will be moved to the new location, + * otherwise they will only be copied * @return an nsIFile indicating where the add-on was installed to */ - installAddon: function({ id, source, existingAddonID, action = "move" }) { + installAddon: function DirInstallLocation_installAddon(aId, aSource, + aExistingAddonID, + aCopy) { let trashDir = this.getTrashDir(); let transaction = new SafeInstallOperation(); - let moveOldAddon = aId => { - let file = this._directory.clone(); + let self = this; + function moveOldAddon(aId) { + let file = self._directory.clone(); file.append(aId); if (file.exists()) transaction.moveUnder(file, trashDir); - file = this._directory.clone(); + file = self._directory.clone(); file.append(aId + ".xpi"); if (file.exists()) { flushJarCache(file); @@ -8480,9 +7503,9 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { // If any of these operations fails the finally block will clean up the // temporary directory try { - moveOldAddon(id); - if (existingAddonID && existingAddonID != id) { - moveOldAddon(existingAddonID); + moveOldAddon(aId); + if (aExistingAddonID && aExistingAddonID != aId) { + moveOldAddon(aExistingAddonID); { // Move the data directories. @@ -8491,12 +7514,12 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { * for porting to OS.File. */ let oldDataDir = FileUtils.getDir( - KEY_PROFILEDIR, ["extension-data", existingAddonID], false, true + KEY_PROFILEDIR, ["extension-data", aExistingAddonID], false, true ); if (oldDataDir.exists()) { let newDataDir = FileUtils.getDir( - KEY_PROFILEDIR, ["extension-data", id], false, true + KEY_PROFILEDIR, ["extension-data", aId], false, true ); if (newDataDir.exists()) { let trashData = trashDir.clone(); @@ -8509,16 +7532,15 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { } } - if (action == "copy") { - transaction.copy(source, this._directory); + if (aCopy) { + transaction.copy(aSource, this._directory); } - else if (action == "move") { - if (source.isFile()) - flushJarCache(source); + else { + if (aSource.isFile()) + flushJarCache(aSource); - transaction.moveUnder(source, this._directory); + transaction.moveUnder(aSource, this._directory); } - // Do nothing for the proxy file as we sideload an addon permanently } finally { // It isn't ideal if this cleanup fails but it isn't worth rolling back @@ -8527,33 +7549,25 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { recursiveRemove(trashDir); } catch (e) { - logger.warn("Failed to remove trash directory when installing " + id, e); + logger.warn("Failed to remove trash directory when installing " + aId, e); } } let newFile = this._directory.clone(); - - if (action == "proxy") { - // When permanently installing sideloaded addon, we just put a proxy file - // refering to the addon sources - newFile.append(id); - - writeStringToFile(newFile, source.path); - } else { - newFile.append(source.leafName); - } - + newFile.append(aSource.leafName); try { newFile.lastModifiedTime = Date.now(); } catch (e) { logger.warn("failed to set lastModifiedTime on " + newFile.path, e); } - this._IDToFileMap[id] = newFile; - XPIProvider._addURIMapping(id, newFile); + this._FileToIDMap[newFile.path] = aId; + this._IDToFileMap[aId] = newFile; + XPIProvider._addURIMapping(aId, newFile); - if (existingAddonID && existingAddonID != id && - existingAddonID in this._IDToFileMap) { - delete this._IDToFileMap[existingAddonID]; + if (aExistingAddonID && aExistingAddonID != aId && + aExistingAddonID in this._IDToFileMap) { + delete this._FileToIDMap[this._IDToFileMap[aExistingAddonID]]; + delete this._IDToFileMap[aExistingAddonID]; } return newFile; @@ -8566,7 +7580,7 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { * The ID of the add-on to uninstall * @throws if the ID does not match any of the add-ons installed */ - uninstallAddon: function(aId) { + uninstallAddon: function DirInstallLocation_uninstallAddon(aId) { let file = this._IDToFileMap[aId]; if (!file) { logger.warn("Attempted to remove " + aId + " from " + @@ -8583,6 +7597,7 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { logger.warn("Attempted to remove " + aId + " from " + this._name + " but it was already gone"); + delete this._FileToIDMap[file.path]; delete this._IDToFileMap[aId]; return; } @@ -8610,550 +7625,51 @@ Object.assign(MutableDirectoryInstallLocation.prototype, { } } + delete this._FileToIDMap[file.path]; delete this._IDToFileMap[aId]; }, -}); - -/** - * An object which identifies a directory install location for system add-ons - * upgrades. - * - * The location consists of a directory which contains the add-ons installed. - * - * @param aName - * The string identifier for the install location - * @param aDirectory - * The nsIFile directory for the install location - * @param aScope - * The scope of add-ons installed in this location - * @param aResetSet - * True to throw away the current add-on set - */ -function SystemAddonInstallLocation(aName, aDirectory, aScope, aResetSet) { - this._baseDir = aDirectory; - this._nextDir = null; - - this._stagingDirLock = 0; - - if (aResetSet) - this.resetAddonSet(); - - this._addonSet = this._loadAddonSet(); - - this._directory = null; - if (this._addonSet.directory) { - this._directory = aDirectory.clone(); - this._directory.append(this._addonSet.directory); - logger.info("SystemAddonInstallLocation scanning directory " + this._directory.path); - } - else { - logger.info("SystemAddonInstallLocation directory is missing"); - } - - DirectoryInstallLocation.call(this, aName, this._directory, aScope); - this.locked = false; -} - -SystemAddonInstallLocation.prototype = Object.create(DirectoryInstallLocation.prototype); -Object.assign(SystemAddonInstallLocation.prototype, { - /** - * Removes the specified files or directories in the staging directory and - * then if the staging directory is empty attempts to remove it. - * - * @param aLeafNames - * An array of file or directory to remove from the directory, the - * array may be empty - */ - cleanStagingDir: function(aLeafNames = []) { - let dir = this.getStagingDir(); - - for (let name of aLeafNames) { - let file = dir.clone(); - file.append(name); - recursiveRemove(file); - } - - if (this._stagingDirLock > 0) - return; - - let dirEntries = dir.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator); - try { - if (dirEntries.nextFile) - return; - } - finally { - dirEntries.close(); - } - - try { - setFilePermissions(dir, FileUtils.PERMS_DIRECTORY); - dir.remove(false); - } - catch (e) { - logger.warn("Failed to remove staging dir", e); - // Failing to remove the staging directory is ignorable - } - }, /** - * Gets the staging directory to put add-ons that are pending install and - * uninstall into. + * Gets the ID of the add-on installed in the given nsIFile. * - * @return {nsIFile} - staging directory for system add-on upgrades. - */ - getStagingDir: function() { - this._addonSet = this._loadAddonSet(); - let dir = null; - if (this._addonSet.directory) { - this._directory = this._baseDir.clone(); - this._directory.append(this._addonSet.directory); - dir = this._directory.clone(); - dir.append(DIR_STAGE); - } - else { - logger.info("SystemAddonInstallLocation directory is missing"); - } - - return dir; - }, - - requestStagingDir: function() { - this._stagingDirLock++; - if (this._stagingDirPromise) - return this._stagingDirPromise; - - this._addonSet = this._loadAddonSet(); - if (this._addonSet.directory) { - this._directory = this._baseDir.clone(); - this._directory.append(this._addonSet.directory); - } - - OS.File.makeDir(this._directory.path); - let stagepath = OS.Path.join(this._directory.path, DIR_STAGE); - return this._stagingDirPromise = OS.File.makeDir(stagepath).then(null, (e) => { - if (e instanceof OS.File.Error && e.becauseExists) - return; - logger.error("Failed to create staging directory", e); - throw e; - }); - }, - - releaseStagingDir: function() { - this._stagingDirLock--; - - if (this._stagingDirLock == 0) { - this._stagingDirPromise = null; - this.cleanStagingDir(); - } - - return Promise.resolve(); - }, - - /** - * Reads the current set of system add-ons - */ - _loadAddonSet: function() { - try { - let setStr = Preferences.get(PREF_SYSTEM_ADDON_SET, null); - if (setStr) { - let addonSet = JSON.parse(setStr); - if ((typeof addonSet == "object") && addonSet.schema == 1) - return addonSet; - } - } - catch (e) { - logger.error("Malformed system add-on set, resetting."); - } - - return { schema: 1, addons: {} }; - }, - - /** - * Saves the current set of system add-ons - * - * @param {Object} aAddonSet - object containing schema, directory and set - * of system add-on IDs and versions. - */ - _saveAddonSet: function(aAddonSet) { - Preferences.set(PREF_SYSTEM_ADDON_SET, JSON.stringify(aAddonSet)); - }, - - getAddonLocations: function() { - // Updated system add-ons are ignored in safe mode - if (Services.appinfo.inSafeMode) - return new Map(); - - let addons = DirectoryInstallLocation.prototype.getAddonLocations.call(this); - - // Strip out any unexpected add-ons from the list - for (let id of addons.keys()) { - if (!(id in this._addonSet.addons)) - addons.delete(id); - } - - return addons; - }, - - /** - * Tests whether updated system add-ons are expected. - */ - isActive: function() { - return this._directory != null; - }, - - isValidAddon: function(aAddon) { - if (aAddon.appDisabled) { - logger.warn(`System add-on ${aAddon.id} isn't compatible with the application.`); - return false; - } - - if (aAddon.unpack) { - logger.warn(`System add-on ${aAddon.id} isn't a packed add-on.`); - return false; - } - - if (!aAddon.bootstrap) { - logger.warn(`System add-on ${aAddon.id} isn't restartless.`); - return false; - } - - if (!aAddon.multiprocessCompatible) { - logger.warn(`System add-on ${aAddon.id} isn't multiprocess compatible.`); - return false; - } - - return true; - }, - - /** - * Tests whether the loaded add-on information matches what is expected. - */ - isValid: function(aAddons) { - for (let id of Object.keys(this._addonSet.addons)) { - if (!aAddons.has(id)) { - logger.warn(`Expected add-on ${id} is missing from the system add-on location.`); - return false; - } - - let addon = aAddons.get(id); - if (addon.version != this._addonSet.addons[id].version) { - logger.warn(`Expected system add-on ${id} to be version ${this._addonSet.addons[id].version} but was ${addon.version}.`); - return false; - } - - if (!this.isValidAddon(addon)) - return false; - } - - return true; - }, - - /** - * Resets the add-on set so on the next startup the default set will be used. + * @param aFile + * The nsIFile to look in + * @return the ID + * @throws if the file does not represent an installed add-on */ - resetAddonSet: function() { - - if (this._addonSet) { - logger.info("Removing all system add-on upgrades."); - - // remove everything from the pref first, if uninstall - // fails then at least they will not be re-activated on - // next restart. - this._saveAddonSet({ schema: 1, addons: {} }); - - for (let id of Object.keys(this._addonSet.addons)) { - AddonManager.getAddonByID(id, addon => { - if (addon) { - addon.uninstall(); - } - }); - } - } + getIDForLocation: function DirInstallLocation_getIDForLocation(aFile) { + if (aFile.path in this._FileToIDMap) + return this._FileToIDMap[aFile.path]; + throw new Error("Unknown add-on location " + aFile.path); }, /** - * Removes any directories not currently in use or pending use after a - * restart. Any errors that happen here don't really matter as we'll attempt - * to cleanup again next time. - */ - cleanDirectories: Task.async(function*() { - - // System add-ons directory does not exist - if (!(yield OS.File.exists(this._baseDir.path))) { - return; - } - - let iterator; - try { - iterator = new OS.File.DirectoryIterator(this._baseDir.path); - } - catch (e) { - logger.error("Failed to clean updated system add-ons directories.", e); - return; - } - - try { - let entries = []; - - yield iterator.forEach(entry => { - // Skip the directory currently in use - if (this._directory && this._directory.path == entry.path) - return; - - // Skip the next directory - if (this._nextDir && this._nextDir.path == entry.path) - return; - - entries.push(entry); - }); - - for (let entry of entries) { - if (entry.isDir) { - yield OS.File.removeDir(entry.path, { - ignoreAbsent: true, - ignorePermissions: true, - }); - } - else { - yield OS.File.remove(entry.path, { - ignoreAbsent: true, - }); - } - } - } - catch (e) { - logger.error("Failed to clean updated system add-ons directories.", e); - } - finally { - iterator.close(); - } - }), - - /** - * Installs a new set of system add-ons into the location and updates the - * add-on set in prefs. - * - * @param {Array} aAddons - An array of addons to install. - */ - installAddonSet: Task.async(function*(aAddons) { - // Make sure the base dir exists - yield OS.File.makeDir(this._baseDir.path, { ignoreExisting: true }); - - let addonSet = this._loadAddonSet(); - - // Remove any add-ons that are no longer part of the set. - for (let addonID of Object.keys(addonSet.addons)) { - if (!aAddons.includes(addonID)) { - AddonManager.getAddonByID(addonID, a => a.uninstall()); - } - } - - let newDir = this._baseDir.clone(); - - let uuidGen = Cc["@mozilla.org/uuid-generator;1"]. - getService(Ci.nsIUUIDGenerator); - newDir.append("blank"); - - while (true) { - newDir.leafName = uuidGen.generateUUID().toString(); - - try { - yield OS.File.makeDir(newDir.path, { ignoreExisting: false }); - break; - } - catch (e) { - logger.debug("Could not create new system add-on updates dir, retrying", e); - } - } - - // Record the new upgrade directory. - let state = { schema: 1, directory: newDir.leafName, addons: {} }; - this._saveAddonSet(state); - - this._nextDir = newDir; - let location = this; - - let installs = []; - for (let addon of aAddons) { - let install = yield createLocalInstall(addon._sourceBundle, location); - installs.push(install); - } - - let installAddon = Task.async(function*(install) { - // Make the new install own its temporary file. - install.ownsTempFile = true; - install.install(); - }); - - let postponeAddon = Task.async(function*(install) { - let resumeFn; - if (AddonManagerPrivate.hasUpgradeListener(install.addon.id)) { - logger.info(`system add-on ${install.addon.id} has an upgrade listener, postponing upgrade set until restart`); - resumeFn = () => { - logger.info(`${install.addon.id} has resumed a previously postponed addon set`); - install.installLocation.resumeAddonSet(installs); - } - } - yield install.postpone(resumeFn); - }); - - let previousState; - - try { - // All add-ons in position, create the new state and store it in prefs - state = { schema: 1, directory: newDir.leafName, addons: {} }; - for (let addon of aAddons) { - state.addons[addon.id] = { - version: addon.version - } - } - - previousState = this._loadAddonSet(); - this._saveAddonSet(state); - - let blockers = aAddons.filter( - addon => AddonManagerPrivate.hasUpgradeListener(addon.id) - ); - - if (blockers.length > 0) { - yield waitForAllPromises(installs.map(postponeAddon)); - } else { - yield waitForAllPromises(installs.map(installAddon)); - } - } - catch (e) { - // Roll back to previous upgrade set (if present) on restart. - if (previousState) { - this._saveAddonSet(previousState); - } - // Otherwise, roll back to built-in set on restart. - // TODO try to do these restartlessly - this.resetAddonSet(); - - try { - yield OS.File.removeDir(newDir.path, { ignorePermissions: true }); - } - catch (e) { - logger.warn(`Failed to remove failed system add-on directory ${newDir.path}.`, e); - } - throw e; - } - }), - - /** - * Resumes upgrade of a previously-delayed add-on set. - */ - resumeAddonSet: Task.async(function*(installs) { - let resumeAddon = Task.async(function*(install) { - install.state = AddonManager.STATE_DOWNLOADED; - install.installLocation.releaseStagingDir(); - install.install(); - }); - - let addonSet = this._loadAddonSet(); - let addonIDs = Object.keys(addonSet.addons); - - let blockers = installs.filter( - install => AddonManagerPrivate.hasUpgradeListener(install.addon.id) - ); - - if (blockers.length > 1) { - logger.warn("Attempted to resume system add-on install but upgrade blockers are still present"); - } else { - yield waitForAllPromises(installs.map(resumeAddon)); - } - }), - - /** - * Returns a directory that is normally on the same filesystem as the rest of - * the install location and can be used for temporarily storing files during - * safe move operations. Calling this method will delete the existing trash - * directory and its contents. + * Gets the directory that the add-on with the given ID is installed in. * - * @return an nsIFile + * @param aId + * The ID of the add-on + * @return The nsIFile + * @throws if the ID does not match any of the add-ons installed */ - getTrashDir: function() { - let trashDir = this._directory.clone(); - trashDir.append(DIR_TRASH); - let trashDirExists = trashDir.exists(); - try { - if (trashDirExists) - recursiveRemove(trashDir); - trashDirExists = false; - } catch (e) { - logger.warn("Failed to remove trash directory", e); - } - if (!trashDirExists) - trashDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - - return trashDir; + getLocationForID: function DirInstallLocation_getLocationForID(aId) { + if (aId in this._IDToFileMap) + return this._IDToFileMap[aId].clone(); + throw new Error("Unknown add-on ID " + aId); }, /** - * Installs an add-on into the install location. + * Returns true if the given addon was installed in this location by a text + * file pointing to its real path. * - * @param id - * The ID of the add-on to install - * @param source - * The source nsIFile to install from - * @return an nsIFile indicating where the add-on was installed to + * @param aId + * The ID of the addon */ - installAddon: function({id, source}) { - let trashDir = this.getTrashDir(); - let transaction = new SafeInstallOperation(); - - // If any of these operations fails the finally block will clean up the - // temporary directory - try { - if (source.isFile()) { - flushJarCache(source); - } - - transaction.moveUnder(source, this._directory); - } - finally { - // It isn't ideal if this cleanup fails but it isn't worth rolling back - // the install because of it. - try { - recursiveRemove(trashDir); - } - catch (e) { - logger.warn("Failed to remove trash directory when installing " + id, e); - } - } - - let newFile = this._directory.clone(); - newFile.append(source.leafName); - - try { - newFile.lastModifiedTime = Date.now(); - } catch (e) { - logger.warn("failed to set lastModifiedTime on " + newFile.path, e); - } - this._IDToFileMap[id] = newFile; - XPIProvider._addURIMapping(id, newFile); - - return newFile; - }, - - // old system add-on upgrade dirs get automatically removed - uninstallAddon: (aAddon) => {}, -}); - -/** - * An object which identifies an install location for temporary add-ons. - */ -const TemporaryInstallLocation = { - locked: false, - name: KEY_APP_TEMPORARY, - scope: AddonManager.SCOPE_TEMPORARY, - getAddonLocations: () => [], - isLinkedAddon: () => false, - installAddon: () => {}, - uninstallAddon: (aAddon) => {}, - getStagingDir: () => {}, -} + isLinkedAddon: function DirInstallLocation__isLinkedAddon(aId) { + return this._linkedAddons.indexOf(aId) != -1; + } +}; +#ifdef XP_WIN /** * An object that identifies a registry install location for add-ons. The location * consists of a registry key which contains string values mapping ID to the @@ -9172,6 +7688,7 @@ function WinRegInstallLocation(aName, aRootKey, aScope) { this._rootKey = aRootKey; this._scope = aScope; this._IDToFileMap = {}; + this._FileToIDMap = {}; let path = this._appKeyPath + "\\Extensions"; let key = Cc["@mozilla.org/windows-registry-key;1"]. @@ -9195,6 +7712,7 @@ WinRegInstallLocation.prototype = { _rootKey : null, _scope : null, _IDToFileMap : null, // mapping from ID to nsIFile + _FileToIDMap : null, // mapping from path to ID /** * Retrieves the path of this Application's data key in the registry. @@ -9203,9 +7721,11 @@ WinRegInstallLocation.prototype = { let appVendor = Services.appinfo.vendor; let appName = Services.appinfo.name; +#ifdef MOZ_THUNDERBIRD // XXX Thunderbird doesn't specify a vendor string - if (AppConstants.MOZ_APP_NAME == "thunderbird" && appVendor == "") + if (appVendor == "") appVendor = "Mozilla"; +#endif // XULRunner-based apps may intentionally not specify a vendor if (appVendor != "") @@ -9221,12 +7741,14 @@ WinRegInstallLocation.prototype = { * @param key * The key that contains the ID to path mapping */ - _readAddons: function(aKey) { + _readAddons: function RegInstallLocation__readAddons(aKey) { let count = aKey.valueCount; for (let i = 0; i < count; ++i) { let id = aKey.getValueName(i); - let file = new nsIFile(aKey.readStringValue(id)); + let file = Cc["@mozilla.org/file/local;1"]. + createInstance(Ci.nsIFile); + file.initWithPath(aKey.readStringValue(id)); if (!file.exists()) { logger.warn("Ignoring missing add-on in " + file.path); @@ -9234,6 +7756,7 @@ WinRegInstallLocation.prototype = { } this._IDToFileMap[id] = file; + this._FileToIDMap[file.path] = id; XPIProvider._addURIMapping(id, file); } }, @@ -9255,21 +7778,49 @@ WinRegInstallLocation.prototype = { /** * Gets an array of nsIFiles for add-ons installed in this location. */ - getAddonLocations: function() { - let locations = new Map(); + get addonLocations() { + let locations = []; for (let id in this._IDToFileMap) { - locations.set(id, this._IDToFileMap[id].clone()); + locations.push(this._IDToFileMap[id].clone()); } return locations; }, /** + * Gets the ID of the add-on installed in the given nsIFile. + * + * @param aFile + * The nsIFile to look in + * @return the ID + * @throws if the file does not represent an installed add-on + */ + getIDForLocation: function RegInstallLocation_getIDForLocation(aFile) { + if (aFile.path in this._FileToIDMap) + return this._FileToIDMap[aFile.path]; + throw new Error("Unknown add-on location"); + }, + + /** + * Gets the nsIFile that the add-on with the given ID is installed in. + * + * @param aId + * The ID of the add-on + * @return the nsIFile + */ + getLocationForID: function RegInstallLocation_getLocationForID(aId) { + if (aId in this._IDToFileMap) + return this._IDToFileMap[aId].clone(); + throw new Error("Unknown add-on ID"); + }, + + /** * @see DirectoryInstallLocation */ - isLinkedAddon: function(aId) { + isLinkedAddon: function RegInstallLocation_isLinkedAddon(aId) { return true; } }; +#endif var addonTypes = [ new AddonManagerPrivate.AddonType("extension", URI_EXTENSION_STRINGS, diff --git a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js index d04eb207c..d26029455 100644 --- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js +++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js @@ -4,22 +4,14 @@ "use strict"; -// These are injected from XPIProvider.jsm -/* globals ADDON_SIGNING, SIGNED_TYPES, BOOTSTRAP_REASONS, DB_SCHEMA, - AddonInternal, XPIProvider, XPIStates, syncLoadManifestFromFile, - isUsableAddon, recordAddonTelemetry, applyBlocklistChanges, - flushChromeCaches, canRunInSafeMode*/ - -var Cc = Components.classes; -var Ci = Components.interfaces; -var Cr = Components.results; -var Cu = Components.utils; +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cr = Components.results; +const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/AddonManager.jsm"); -/* globals AddonManagerPrivate*/ -Cu.import("resource://gre/modules/Preferences.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository", "resource://gre/modules/addons/AddonRepository.jsm"); @@ -31,15 +23,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise", "resource://gre/modules/Promise.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm"); -XPCOMUtils.defineLazyServiceGetter(this, "Blocklist", - "@mozilla.org/extensions/blocklist;1", - Ci.nsIBlocklistService); Cu.import("resource://gre/modules/Log.jsm"); const LOGGER_ID = "addons.xpi-utils"; -const nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile"); - // Create a new logger for use by the Addons XPI Provider Utils // (Requires AddonManager.jsm) var logger = Log.repository.getLogger(LOGGER_ID); @@ -50,20 +37,15 @@ const FILE_JSON_DB = "extensions.json"; const FILE_OLD_DATABASE = "extensions.rdf"; const FILE_XPI_ADDONS_LIST = "extensions.ini"; +// The value for this is in Makefile.in +#expand const DB_SCHEMA = __MOZ_EXTENSIONS_DB_SCHEMA__; + // The last version of DB_SCHEMA implemented in SQLITE const LAST_SQLITE_DB_SCHEMA = 14; const PREF_DB_SCHEMA = "extensions.databaseSchema"; const PREF_PENDING_OPERATIONS = "extensions.pendingOperations"; const PREF_EM_ENABLED_ADDONS = "extensions.enabledAddons"; const PREF_EM_DSS_ENABLED = "extensions.dss.enabled"; -const PREF_EM_AUTO_DISABLED_SCOPES = "extensions.autoDisableScopes"; -const PREF_E10S_BLOCKED_BY_ADDONS = "extensions.e10sBlockedByAddons"; -const PREF_E10S_HAS_NONEXEMPT_ADDON = "extensions.e10s.rollout.hasAddon"; - -const KEY_APP_PROFILE = "app-profile"; -const KEY_APP_SYSTEM_ADDONS = "app-system-addons"; -const KEY_APP_SYSTEM_DEFAULTS = "app-system-defaults"; -const KEY_APP_GLOBAL = "app-global"; // Properties that only exist in the database const DB_METADATA = ["syncGUID", @@ -81,22 +63,14 @@ const DB_BOOL_METADATA = ["visible", "active", "userDisabled", "appDisabled", // Properties to save in JSON file const PROP_JSON_FIELDS = ["id", "syncGUID", "location", "version", "type", "internalName", "updateURL", "updateKey", "optionsURL", - "optionsType", "aboutURL", "icons", "iconURL", "icon64URL", + "optionsType", "aboutURL", "iconURL", "icon64URL", "defaultLocale", "visible", "active", "userDisabled", "appDisabled", "pendingUninstall", "descriptor", "installDate", "updateDate", "applyBackgroundUpdates", "bootstrap", "skinnable", "size", "sourceURI", "releaseNotesURI", "softDisabled", "foreignInstall", "hasBinaryComponents", "strictCompatibility", "locales", "targetApplications", - "targetPlatforms", "multiprocessCompatible", "signedState", - "seen", "dependencies", "hasEmbeddedWebExtension", "mpcOptedOut"]; - -// Properties that should be migrated where possible from an old database. These -// shouldn't include properties that can be read directly from install.rdf files -// or calculated -const DB_MIGRATE_METADATA= ["installDate", "userDisabled", "softDisabled", - "sourceURI", "applyBackgroundUpdates", - "releaseNotesURI", "foreignInstall", "syncGUID"]; + "targetPlatforms", "multiprocessCompatible", "native"]; // Time to wait before async save of XPI JSON database, in milliseconds const ASYNC_SAVE_DELAY_MS = 20; @@ -170,7 +144,7 @@ function makeSafe(aCallback) { try { aCallback(...aArgs); } - catch (ex) { + catch(ex) { logger.warn("XPI Database callback failed", ex); } } @@ -187,7 +161,7 @@ function makeSafe(aCallback) { * @param aObjects * The array of objects to process asynchronously * @param aMethod - * Function with signature function(object, function(f_of_object)) + * Function with signature function(object, function aCallback(f_of_object)) * @param aCallback * Function with signature f([aMethod(object)]), called when all values * are available @@ -207,9 +181,9 @@ function asyncMap(aObjects, aMethod, aCallback) { } } - aObjects.map(function(aObject, aIndex, aArray) { + aObjects.map(function asyncMap_each(aObject, aIndex, aArray) { try { - aMethod(aObject, function(aResult) { + aMethod(aObject, function asyncMap_callback(aResult) { asyncMap_gotValue(aIndex, aResult); }); } @@ -226,7 +200,7 @@ function asyncMap(aObjects, aMethod, aCallback) { * @param aStatement * The statement to execute */ -function* resultRows(aStatement) { +function resultRows(aStatement) { try { while (stepStatement(aStatement)) yield aStatement.row; @@ -292,8 +266,7 @@ function copyProperties(aObject, aProperties, aTarget) { if (!aTarget) aTarget = {}; aProperties.forEach(function(aProp) { - if (aProp in aObject) - aTarget[aProp] = aObject[aProp]; + aTarget[aProp] = aObject[aProp]; }); return aTarget; } @@ -329,17 +302,11 @@ function copyRowProperties(aRow, aProperties, aTarget) { * Addon data fields loaded from JSON or the addon manifest. */ function DBAddonInternal(aLoaded) { - AddonInternal.call(this); - copyProperties(aLoaded, PROP_JSON_FIELDS, this); - if (!this.dependencies) - this.dependencies = []; - Object.freeze(this.dependencies); - if (aLoaded._installLocation) { this._installLocation = aLoaded._installLocation; - this.location = aLoaded._installLocation.name; + this.location = aLoaded._installLocation._name; } else if (aLoaded.location) { this._installLocation = XPIProvider.installLocationsByName[this.location]; @@ -347,13 +314,17 @@ function DBAddonInternal(aLoaded) { this._key = this.location + ":" + this.id; - if (!aLoaded._sourceBundle) { - throw new Error("Expected passed argument to contain a descriptor"); + try { + this._sourceBundle = this._installLocation.getLocationForID(this.id); + } + catch (e) { + // An exception will be thrown if the add-on appears in the database but + // not on disk. In general this should only happen during startup as + // this change is being detected. } - this._sourceBundle = aLoaded._sourceBundle; - - XPCOMUtils.defineLazyGetter(this, "pendingUpgrade", function() { + XPCOMUtils.defineLazyGetter(this, "pendingUpgrade", + function DBA_pendingUpgradeGetter() { for (let install of XPIProvider.installs) { if (install.state == AddonManager.STATE_INSTALLED && !(install.addon.inDatabase) && @@ -362,53 +333,46 @@ function DBAddonInternal(aLoaded) { delete this.pendingUpgrade; return this.pendingUpgrade = install.addon; } - } + }; return null; }); } -DBAddonInternal.prototype = Object.create(AddonInternal.prototype); -Object.assign(DBAddonInternal.prototype, { - applyCompatibilityUpdate: function(aUpdate, aSyncCompatibility) { - let wasCompatible = this.isCompatible; - - this.targetApplications.forEach(function(aTargetApp) { - aUpdate.targetApplications.forEach(function(aUpdateTarget) { - if (aTargetApp.id == aUpdateTarget.id && (aSyncCompatibility || - Services.vc.compare(aTargetApp.maxVersion, aUpdateTarget.maxVersion) < 0)) { - aTargetApp.minVersion = aUpdateTarget.minVersion; - aTargetApp.maxVersion = aUpdateTarget.maxVersion; - XPIDatabase.saveChanges(); - } +function DBAddonInternalPrototype() +{ + this.applyCompatibilityUpdate = + function(aUpdate, aSyncCompatibility) { + this.targetApplications.forEach(function(aTargetApp) { + aUpdate.targetApplications.forEach(function(aUpdateTarget) { + if (aTargetApp.id == aUpdateTarget.id && (aSyncCompatibility || + Services.vc.compare(aTargetApp.maxVersion, aUpdateTarget.maxVersion) < 0)) { + aTargetApp.minVersion = aUpdateTarget.minVersion; + aTargetApp.maxVersion = aUpdateTarget.maxVersion; + XPIDatabase.saveChanges(); + } + }); }); - }); - if (aUpdate.multiprocessCompatible !== undefined && - aUpdate.multiprocessCompatible != this.multiprocessCompatible) { - this.multiprocessCompatible = aUpdate.multiprocessCompatible; - XPIDatabase.saveChanges(); - } - - if (wasCompatible != this.isCompatible) + if (aUpdate.multiprocessCompatible !== undefined && + aUpdate.multiprocessCompatible != this.multiprocessCompatible) { + this.multiprocessCompatible = aUpdate.multiprocessCompatible; + XPIDatabase.saveChanges(); + } XPIProvider.updateAddonDisabledState(this); - }, - - toJSON: function() { - let jsonData = copyProperties(this, PROP_JSON_FIELDS); + }; - // Experiments are serialized as disabled so they aren't run on the next - // startup. - if (this.type == "experiment") { - jsonData.userDisabled = true; - jsonData.active = false; - } + this.toJSON = + function() { + return copyProperties(this, PROP_JSON_FIELDS); + }; - return jsonData; - }, + Object.defineProperty(this, "inDatabase", + { get: function() { return true; }, + enumerable: true, + configurable: true }); +} +DBAddonInternalPrototype.prototype = AddonInternal.prototype; - get inDatabase() { - return true; - } -}); +DBAddonInternal.prototype = new DBAddonInternalPrototype(); /** * Internal interface: find an addon from an already loaded addonDB @@ -426,7 +390,7 @@ function _findAddon(addonDB, aFilter) { * Internal interface to get a filtered list of addons from a loaded addonDB */ function _filterDB(addonDB, aFilter) { - return Array.from(addonDB.values()).filter(aFilter); + return [for (addon of addonDB.values()) if (aFilter(addon)) addon]; } this.XPIDatabase = { @@ -472,11 +436,10 @@ this.XPIDatabase = { ASYNC_SAVE_DELAY_MS); } - this.updateAddonsBlockingE10s(); let promise = this._deferredSave.saveChanges(); if (!this._schemaVersionSet) { this._schemaVersionSet = true; - promise = promise.then( + promise.then( count => { // Update the XPIDB schema version preference the first time we successfully // save the database. @@ -488,17 +451,12 @@ this.XPIDatabase = { error => { // Need to try setting the schema version again later this._schemaVersionSet = false; + logger.warn("Failed to save XPI database", error); // this._deferredSave.lastError has the most recent error so we don't // need this any more this._loadError = null; - - throw error; }); } - - promise.catch(error => { - logger.warn("Failed to save XPI database", error); - }); }, flush: function() { @@ -537,7 +495,7 @@ this.XPIDatabase = { * {location: {id1:{addon1}, id2:{addon2}}, location2:{...}, ...} * if there is useful information */ - getMigrateDataFromSQLITE: function() { + getMigrateDataFromSQLITE: function XPIDB_getMigrateDataFromSQLITE() { let connection = null; let dbfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_DATABASE], true); // Attempt to open the database @@ -572,7 +530,7 @@ this.XPIDatabase = { * from the install locations if the database needs to be rebuilt. * (if false, caller is XPIProvider.checkForChanges() which will rebuild) */ - syncLoadDB: function(aRebuildOnError) { + syncLoadDB: function XPIDB_syncLoadDB(aRebuildOnError) { this.migrateData = null; let fstream = null; let data = ""; @@ -598,7 +556,7 @@ this.XPIDatabase = { readTimer.done(); this.parseDB(data, aRebuildOnError); } - catch (e) { + catch(e) { logger.error("Failed to load XPI JSON data from profile", e); let rebuildTimer = AddonManagerPrivate.simpleTimer("XPIDB_rebuildReadFailed_MS"); this.rebuildDatabase(aRebuildOnError); @@ -668,25 +626,15 @@ this.XPIDatabase = { // Make AddonInternal instances from the loaded data and save them let addonDB = new Map(); for (let loadedAddon of inputAddons.addons) { - loadedAddon._sourceBundle = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - try { - loadedAddon._sourceBundle.persistentDescriptor = loadedAddon.descriptor; - } - catch (e) { - // We can fail here when the descriptor is invalid, usually from the - // wrong OS - logger.warn("Could not find source bundle for add-on " + loadedAddon.id, e); - } - let newAddon = new DBAddonInternal(loadedAddon); addonDB.set(newAddon._key, newAddon); - } + }; parseTimer.done(); this.addonDB = addonDB; logger.debug("Successfully read XPI database"); this.initialized = true; } - catch (e) { + catch(e) { // If we catch and log a SyntaxError from the JSON // parser, the xpcshell test harness fails the test for us: bug 870828 parseTimer.done(); @@ -722,7 +670,7 @@ this.XPIDatabase = { AddonManagerPrivate.recordSimpleMeasure("XPIDB_startupError", "dbMissing"); } } - catch (e) { + catch(e) { // No schema version pref means either a really old upgrade (RDF) or // a new profile this.migrateData = this.getMigrateDataFromRDF(); @@ -756,7 +704,7 @@ this.XPIDatabase = { * @return Promise<Map> resolves to the Map of loaded JSON data stored * in this.addonDB; never rejects. */ - asyncLoadDB: function() { + asyncLoadDB: function XPIDB_asyncLoadDB() { // Already started (and possibly finished) loading if (this._dbPromise) { return this._dbPromise; @@ -810,7 +758,7 @@ this.XPIDatabase = { * from the install locations if the database needs to be rebuilt. * (if false, caller is XPIProvider.checkForChanges() which will rebuild) */ - rebuildDatabase: function(aRebuildOnError) { + rebuildDatabase: function XIPDB_rebuildDatabase(aRebuildOnError) { this.addonDB = new Map(); this.initialized = true; @@ -828,7 +776,7 @@ this.XPIDatabase = { if (aRebuildOnError) { logger.warn("Rebuilding add-ons database from installed extensions."); try { - XPIDatabaseReconcile.processFileChanges({}, false); + XPIProvider.processFileChanges({}, false); } catch (e) { logger.error("Failed to rebuild XPI database from installed extensions", e); @@ -846,7 +794,7 @@ this.XPIDatabase = { * * @return an array of persistent descriptors for the directories */ - getActiveBundles: function() { + getActiveBundles: function XPIDB_getActiveBundles() { let bundles = []; // non-bootstrapped extensions @@ -885,7 +833,7 @@ this.XPIDatabase = { * @return an object holding information about what add-ons were previously * userDisabled and any updated compatibility information */ - getMigrateDataFromRDF: function(aDbWasMissing) { + getMigrateDataFromRDF: function XPIDB_getMigrateDataFromRDF(aDbWasMissing) { // Migrate data from extensions.rdf let rdffile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_OLD_DATABASE], true); @@ -957,7 +905,7 @@ this.XPIDatabase = { * @return an object holding information about what add-ons were previously * userDisabled and any updated compatibility information */ - getMigrateDataFromDatabase: function(aConnection) { + getMigrateDataFromDatabase: function XPIDB_getMigrateDataFromDatabase(aConnection) { let migrateData = {}; // Attempt to migrate data from a different (even future!) version of the @@ -970,7 +918,7 @@ this.XPIDatabase = { let reqCount = 0; let props = []; - for (let row of resultRows(stmt)) { + for (let row in resultRows(stmt)) { if (REQUIRED.indexOf(row.name) != -1) { reqCount++; props.push(row.name); @@ -990,7 +938,7 @@ this.XPIDatabase = { stmt.finalize(); stmt = aConnection.createStatement("SELECT " + props.join(",") + " FROM addon"); - for (let row of resultRows(stmt)) { + for (let row in resultRows(stmt)) { if (!(row.location in migrateData)) migrateData[row.location] = {}; let addonData = { @@ -1017,7 +965,7 @@ this.XPIDatabase = { for (let id in migrateData[location]) { taStmt.params.internal_id = migrateData[location][id].internal_id; delete migrateData[location][id].internal_id; - for (let row of resultRows(taStmt)) { + for (let row in resultRows(taStmt)) { migrateData[location][id].targetApplications.push({ id: row.id, minVersion: row.minVersion, @@ -1048,7 +996,7 @@ this.XPIDatabase = { * flush after the database is flushed and * all cleanup is done */ - shutdown: function() { + shutdown: function XPIDB_shutdown() { logger.debug("shutdown"); if (this.initialized) { // If our last database I/O had an error, try one last time to save. @@ -1127,7 +1075,7 @@ this.XPIDatabase = { }) .then(null, error => { - logger.error("getAddon failed", error); + logger.error("getAddon failed", e); makeSafe(aCallback)(null); }); }, @@ -1143,25 +1091,13 @@ this.XPIDatabase = { * @param aCallback * A callback to pass the DBAddonInternal to */ - getAddonInLocation: function(aId, aLocation, aCallback) { + getAddonInLocation: function XPIDB_getAddonInLocation(aId, aLocation, aCallback) { this.asyncLoadDB().then( addonDB => getRepositoryAddon(addonDB.get(aLocation + ":" + aId), makeSafe(aCallback))); }, /** - * Asynchronously get all the add-ons in a particular install location. - * - * @param aLocation - * The name of the install location - * @param aCallback - * A callback to pass the array of DBAddonInternals to - */ - getAddonsInLocation: function(aLocation, aCallback) { - this.getAddonList(aAddon => aAddon._installLocation.name == aLocation, aCallback); - }, - - /** * Asynchronously gets the add-on with the specified ID that is visible. * * @param aId @@ -1169,7 +1105,7 @@ this.XPIDatabase = { * @param aCallback * A callback to pass the DBAddonInternal to */ - getVisibleAddonForID: function(aId, aCallback) { + getVisibleAddonForID: function XPIDB_getVisibleAddonForID(aId, aCallback) { this.getAddon(aAddon => ((aAddon.id == aId) && aAddon.visible), aCallback); }, @@ -1182,7 +1118,7 @@ this.XPIDatabase = { * @param aCallback * A callback to pass the array of DBAddonInternals to */ - getVisibleAddons: function(aTypes, aCallback) { + getVisibleAddons: function XPIDB_getVisibleAddons(aTypes, aCallback) { this.getAddonList(aAddon => (aAddon.visible && (!aTypes || (aTypes.length == 0) || (aTypes.indexOf(aAddon.type) > -1))), @@ -1196,7 +1132,7 @@ this.XPIDatabase = { * The type of add-on to retrieve * @return an array of DBAddonInternals */ - getAddonsByType: function(aType) { + getAddonsByType: function XPIDB_getAddonsByType(aType) { if (!this.addonDB) { // jank-tastic! Must synchronously load DB if the theme switches from // an XPI theme to a lightweight theme before the DB has loaded, @@ -1215,7 +1151,7 @@ this.XPIDatabase = { * The internalName of the add-on to retrieve * @return a DBAddonInternal */ - getVisibleAddonForInternalName: function(aInternalName) { + getVisibleAddonForInternalName: function XPIDB_getVisibleAddonForInternalName(aInternalName) { if (!this.addonDB) { // This may be called when the DB hasn't otherwise been loaded logger.warn("Synchronous load of XPI database due to getVisibleAddonForInternalName"); @@ -1223,7 +1159,7 @@ this.XPIDatabase = { XPIProvider.runPhase); this.syncLoadDB(true); } - + return _findAddon(this.addonDB, aAddon => aAddon.visible && (aAddon.internalName == aInternalName)); @@ -1237,7 +1173,9 @@ this.XPIDatabase = { * @param aCallback * A callback to pass the array of DBAddonInternal to */ - getVisibleAddonsWithPendingOperations: function(aTypes, aCallback) { + getVisibleAddonsWithPendingOperations: + function XPIDB_getVisibleAddonsWithPendingOperations(aTypes, aCallback) { + this.getAddonList( aAddon => (aAddon.visible && (aAddon.pendingUninstall || @@ -1258,7 +1196,7 @@ this.XPIDatabase = { * if no add-on with that GUID is found. * */ - getAddonBySyncGUID: function(aGUID, aCallback) { + getAddonBySyncGUID: function XPIDB_getAddonBySyncGUID(aGUID, aCallback) { this.getAddon(aAddon => aAddon.syncGUID == aGUID, aCallback); }, @@ -1271,7 +1209,7 @@ this.XPIDatabase = { * * @return an array of DBAddonInternals */ - getAddons: function() { + getAddons: function XPIDB_getAddons() { if (!this.addonDB) { return []; } @@ -1287,7 +1225,7 @@ this.XPIDatabase = { * The file descriptor of the add-on * @return The DBAddonInternal that was added to the database */ - addAddonMetadata: function(aAddon, aDescriptor) { + addAddonMetadata: function XPIDB_addAddonMetadata(aAddon, aDescriptor) { if (!this.addonDB) { AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_addMetadata", XPIProvider.runPhase); @@ -1317,13 +1255,13 @@ this.XPIDatabase = { * The file descriptor of the add-on * @return The DBAddonInternal that was added to the database */ - updateAddonMetadata: function(aOldAddon, aNewAddon, aDescriptor) { + updateAddonMetadata: function XPIDB_updateAddonMetadata(aOldAddon, aNewAddon, + aDescriptor) { this.removeAddonMetadata(aOldAddon); aNewAddon.syncGUID = aOldAddon.syncGUID; aNewAddon.installDate = aOldAddon.installDate; aNewAddon.applyBackgroundUpdates = aOldAddon.applyBackgroundUpdates; aNewAddon.foreignInstall = aOldAddon.foreignInstall; - aNewAddon.seen = aOldAddon.seen; aNewAddon.active = (aNewAddon.visible && !aNewAddon.disabled && !aNewAddon.pendingUninstall); // addAddonMetadata does a saveChanges() @@ -1336,7 +1274,7 @@ this.XPIDatabase = { * @param aAddon * The DBAddonInternal being removed */ - removeAddonMetadata: function(aAddon) { + removeAddonMetadata: function XPIDB_removeAddonMetadata(aAddon) { this.addonDB.delete(aAddon._key); this.saveChanges(); }, @@ -1348,13 +1286,12 @@ this.XPIDatabase = { * @param aAddon * The DBAddonInternal to make visible */ - makeAddonVisible: function(aAddon) { + makeAddonVisible: function XPIDB_makeAddonVisible(aAddon) { logger.debug("Make addon " + aAddon._key + " visible"); for (let [, otherAddon] of this.addonDB) { if ((otherAddon.id == aAddon.id) && (otherAddon._key != aAddon._key)) { logger.debug("Hide addon " + otherAddon._key); otherAddon.visible = false; - otherAddon.active = false; } } aAddon.visible = true; @@ -1369,7 +1306,7 @@ this.XPIDatabase = { * @param aProperties * A dictionary of properties to set */ - setAddonProperties: function(aAddon, aProperties) { + setAddonProperties: function XPIDB_setAddonProperties(aAddon, aProperties) { for (let key in aProperties) { aAddon[key] = aProperties[key]; } @@ -1386,7 +1323,7 @@ this.XPIDatabase = { * GUID string to set the value to * @throws if another addon already has the specified GUID */ - setAddonSyncGUID: function(aAddon, aGUID) { + setAddonSyncGUID: function XPIDB_setAddonSyncGUID(aAddon, aGUID) { // Need to make sure no other addon has this GUID function excludeSyncGUID(otherAddon) { return (otherAddon._key != aAddon._key) && (otherAddon.syncGUID == aGUID); @@ -1406,32 +1343,17 @@ this.XPIDatabase = { * @param aAddon * The DBAddonInternal to update */ - updateAddonActive: function(aAddon, aActive) { + updateAddonActive: function XPIDB_updateAddonActive(aAddon, aActive) { logger.debug("Updating active state for add-on " + aAddon.id + " to " + aActive); aAddon.active = aActive; this.saveChanges(); }, - updateAddonsBlockingE10s: function() { - let blockE10s = false; - - Preferences.set(PREF_E10S_HAS_NONEXEMPT_ADDON, false); - for (let [, addon] of this.addonDB) { - let active = (addon.visible && !addon.disabled && !addon.pendingUninstall); - - if (active && XPIProvider.isBlockingE10s(addon)) { - blockE10s = true; - break; - } - } - Preferences.set(PREF_E10S_BLOCKED_BY_ADDONS, blockE10s); - }, - /** * Synchronously calculates and updates all the active flags in the database. */ - updateActiveAddons: function() { + updateActiveAddons: function XPIDB_updateActiveAddons() { if (!this.addonDB) { logger.warn("updateActiveAddons called when DB isn't loaded"); // force the DB to load @@ -1453,7 +1375,7 @@ this.XPIDatabase = { * Writes out the XPI add-ons list for the platform to read. * @return true if the file was successfully updated, false otherwise */ - writeAddonsList: function() { + writeAddonsList: function XPIDB_writeAddonsList() { if (!this.addonDB) { // force the DB to load AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_writeList", @@ -1557,699 +1479,3 @@ this.XPIDatabase = { return true; } }; - -this.XPIDatabaseReconcile = { - /** - * Returns a map of ID -> add-on. When the same add-on ID exists in multiple - * install locations the highest priority location is chosen. - */ - flattenByID(addonMap, hideLocation) { - let map = new Map(); - - for (let installLocation of XPIProvider.installLocations) { - if (installLocation.name == hideLocation) - continue; - - let locationMap = addonMap.get(installLocation.name); - if (!locationMap) - continue; - - for (let [id, addon] of locationMap) { - if (!map.has(id)) - map.set(id, addon); - } - } - - return map; - }, - - /** - * Finds the visible add-ons from the map. - */ - getVisibleAddons(addonMap) { - let map = new Map(); - - for (let [location, addons] of addonMap) { - for (let [id, addon] of addons) { - if (!addon.visible) - continue; - - if (map.has(id)) { - logger.warn("Previous database listed more than one visible add-on with id " + id); - continue; - } - - map.set(id, addon); - } - } - - return map; - }, - - /** - * Called to add the metadata for an add-on in one of the install locations - * to the database. This can be called in three different cases. Either an - * add-on has been dropped into the location from outside of Firefox, or - * an add-on has been installed through the application, or the database - * has been upgraded or become corrupt and add-on data has to be reloaded - * into it. - * - * @param aInstallLocation - * The install location containing the add-on - * @param aId - * The ID of the add-on - * @param aAddonState - * The new state of the add-on - * @param aNewAddon - * The manifest for the new add-on if it has already been loaded - * @param aOldAppVersion - * The version of the application last run with this profile or null - * if it is a new profile or the version is unknown - * @param aOldPlatformVersion - * The version of the platform last run with this profile or null - * if it is a new profile or the version is unknown - * @param aMigrateData - * If during startup the database had to be upgraded this will - * contain data that used to be held about this add-on - * @return a boolean indicating if flushing caches is required to complete - * changing this add-on - */ - addMetadata(aInstallLocation, aId, aAddonState, aNewAddon, aOldAppVersion, - aOldPlatformVersion, aMigrateData) { - logger.debug("New add-on " + aId + " installed in " + aInstallLocation.name); - - // If we had staged data for this add-on or we aren't recovering from a - // corrupt database and we don't have migration data for this add-on then - // this must be a new install. - let isNewInstall = (!!aNewAddon) || (!XPIDatabase.activeBundles && !aMigrateData); - - // If it's a new install and we haven't yet loaded the manifest then it - // must be something dropped directly into the install location - let isDetectedInstall = isNewInstall && !aNewAddon; - - // Load the manifest if necessary and sanity check the add-on ID - try { - if (!aNewAddon) { - // Load the manifest from the add-on. - let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file.persistentDescriptor = aAddonState.descriptor; - aNewAddon = syncLoadManifestFromFile(file, aInstallLocation); - } - // The add-on in the manifest should match the add-on ID. - if (aNewAddon.id != aId) { - throw new Error("Invalid addon ID: expected addon ID " + aId + - ", found " + aNewAddon.id + " in manifest"); - } - } - catch (e) { - logger.warn("addMetadata: Add-on " + aId + " is invalid", e); - - // Remove the invalid add-on from the install location if the install - // location isn't locked, no restart will be necessary - if (aInstallLocation.isLinkedAddon(aId)) - logger.warn("Not uninstalling invalid item because it is a proxy file"); - else if (aInstallLocation.locked) - logger.warn("Could not uninstall invalid item from locked install location"); - else - aInstallLocation.uninstallAddon(aId); - return null; - } - - // Update the AddonInternal properties. - aNewAddon.installDate = aAddonState.mtime; - aNewAddon.updateDate = aAddonState.mtime; - - // Assume that add-ons in the system add-ons install location aren't - // foreign and should default to enabled. - aNewAddon.foreignInstall = isDetectedInstall && - aInstallLocation.name != KEY_APP_SYSTEM_ADDONS && - aInstallLocation.name != KEY_APP_SYSTEM_DEFAULTS; - - // appDisabled depends on whether the add-on is a foreignInstall so update - aNewAddon.appDisabled = !isUsableAddon(aNewAddon); - - if (aMigrateData) { - // If there is migration data then apply it. - logger.debug("Migrating data from old database"); - - DB_MIGRATE_METADATA.forEach(function(aProp) { - // A theme's disabled state is determined by the selected theme - // preference which is read in loadManifestFromRDF - if (aProp == "userDisabled" && aNewAddon.type == "theme") - return; - - if (aProp in aMigrateData) - aNewAddon[aProp] = aMigrateData[aProp]; - }); - - // Force all non-profile add-ons to be foreignInstalls since they can't - // have been installed through the API - aNewAddon.foreignInstall |= aInstallLocation.name != KEY_APP_PROFILE; - - // Some properties should only be migrated if the add-on hasn't changed. - // The version property isn't a perfect check for this but covers the - // vast majority of cases. - if (aMigrateData.version == aNewAddon.version) { - logger.debug("Migrating compatibility info"); - if ("targetApplications" in aMigrateData) - aNewAddon.applyCompatibilityUpdate(aMigrateData, true); - } - - // Since the DB schema has changed make sure softDisabled is correct - applyBlocklistChanges(aNewAddon, aNewAddon, aOldAppVersion, - aOldPlatformVersion); - } - - // The default theme is never a foreign install - if (aNewAddon.type == "theme" && aNewAddon.internalName == XPIProvider.defaultSkin) - aNewAddon.foreignInstall = false; - - if (isDetectedInstall && aNewAddon.foreignInstall) { - // If the add-on is a foreign install and is in a scope where add-ons - // that were dropped in should default to disabled then disable it - let disablingScopes = Preferences.get(PREF_EM_AUTO_DISABLED_SCOPES, 0); - if (aInstallLocation.scope & disablingScopes) { - logger.warn("Disabling foreign installed add-on " + aNewAddon.id + " in " - + aInstallLocation.name); - aNewAddon.userDisabled = true; - - // If we don't have an old app version then this is a new profile in - // which case just mark any sideloaded add-ons as already seen. - aNewAddon.seen = !aOldAppVersion; - } - } - - return XPIDatabase.addAddonMetadata(aNewAddon, aAddonState.descriptor); - }, - - /** - * Called when an add-on has been removed. - * - * @param aOldAddon - * The AddonInternal as it appeared the last time the application - * ran - * @return a boolean indicating if flushing caches is required to complete - * changing this add-on - */ - removeMetadata(aOldAddon) { - // This add-on has disappeared - logger.debug("Add-on " + aOldAddon.id + " removed from " + aOldAddon.location); - XPIDatabase.removeAddonMetadata(aOldAddon); - }, - - /** - * Updates an add-on's metadata and determines if a restart of the - * application is necessary. This is called when either the add-on's - * install directory path or last modified time has changed. - * - * @param aInstallLocation - * The install location containing the add-on - * @param aOldAddon - * The AddonInternal as it appeared the last time the application - * ran - * @param aAddonState - * The new state of the add-on - * @param aNewAddon - * The manifest for the new add-on if it has already been loaded - * @return a boolean indicating if flushing caches is required to complete - * changing this add-on - */ - updateMetadata(aInstallLocation, aOldAddon, aAddonState, aNewAddon) { - logger.debug("Add-on " + aOldAddon.id + " modified in " + aInstallLocation.name); - - try { - // If there isn't an updated install manifest for this add-on then load it. - if (!aNewAddon) { - let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file.persistentDescriptor = aAddonState.descriptor; - aNewAddon = syncLoadManifestFromFile(file, aInstallLocation); - applyBlocklistChanges(aOldAddon, aNewAddon); - - // Carry over any pendingUninstall state to add-ons modified directly - // in the profile. This is important when the attempt to remove the - // add-on in processPendingFileChanges failed and caused an mtime - // change to the add-ons files. - aNewAddon.pendingUninstall = aOldAddon.pendingUninstall; - } - - // The ID in the manifest that was loaded must match the ID of the old - // add-on. - if (aNewAddon.id != aOldAddon.id) - throw new Error("Incorrect id in install manifest for existing add-on " + aOldAddon.id); - } - catch (e) { - logger.warn("updateMetadata: Add-on " + aOldAddon.id + " is invalid", e); - XPIDatabase.removeAddonMetadata(aOldAddon); - XPIStates.removeAddon(aOldAddon.location, aOldAddon.id); - if (!aInstallLocation.locked) - aInstallLocation.uninstallAddon(aOldAddon.id); - else - logger.warn("Could not uninstall invalid item from locked install location"); - - return null; - } - - // Set the additional properties on the new AddonInternal - aNewAddon.updateDate = aAddonState.mtime; - - // Update the database - return XPIDatabase.updateAddonMetadata(aOldAddon, aNewAddon, aAddonState.descriptor); - }, - - /** - * Updates an add-on's descriptor for when the add-on has moved in the - * filesystem but hasn't changed in any other way. - * - * @param aInstallLocation - * The install location containing the add-on - * @param aOldAddon - * The AddonInternal as it appeared the last time the application - * ran - * @param aAddonState - * The new state of the add-on - * @return a boolean indicating if flushing caches is required to complete - * changing this add-on - */ - updateDescriptor(aInstallLocation, aOldAddon, aAddonState) { - logger.debug("Add-on " + aOldAddon.id + " moved to " + aAddonState.descriptor); - aOldAddon.descriptor = aAddonState.descriptor; - aOldAddon._sourceBundle.persistentDescriptor = aAddonState.descriptor; - - return aOldAddon; - }, - - /** - * Called when no change has been detected for an add-on's metadata but the - * application has changed so compatibility may have changed. - * - * @param aInstallLocation - * The install location containing the add-on - * @param aOldAddon - * The AddonInternal as it appeared the last time the application - * ran - * @param aAddonState - * The new state of the add-on - * @param aOldAppVersion - * The version of the application last run with this profile or null - * if it is a new profile or the version is unknown - * @param aOldPlatformVersion - * The version of the platform last run with this profile or null - * if it is a new profile or the version is unknown - * @param aReloadMetadata - * A boolean which indicates whether metadata should be reloaded from - * the addon manifests. Default to false. - * @return the new addon. - */ - updateCompatibility(aInstallLocation, aOldAddon, aAddonState, aOldAppVersion, - aOldPlatformVersion, aReloadMetadata) { - logger.debug("Updating compatibility for add-on " + aOldAddon.id + " in " + aInstallLocation.name); - - // If updating from a version of the app that didn't support signedState - // then fetch that property now - if (aOldAddon.signedState === undefined && ADDON_SIGNING && - SIGNED_TYPES.has(aOldAddon.type)) { - let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file.persistentDescriptor = aAddonState.descriptor; - let manifest = syncLoadManifestFromFile(file, aInstallLocation); - aOldAddon.signedState = manifest.signedState; - } - - // May be updating from a version of the app that didn't support all the - // properties of the currently-installed add-ons. - if (aReloadMetadata) { - let file = new nsIFile() - file.persistentDescriptor = aAddonState.descriptor; - let manifest = syncLoadManifestFromFile(file, aInstallLocation); - - // Avoid re-reading these properties from manifest, - // use existing addon instead. - // TODO - consider re-scanning for targetApplications. - let remove = ["syncGUID", "foreignInstall", "visible", "active", - "userDisabled", "applyBackgroundUpdates", "sourceURI", - "releaseNotesURI", "targetApplications"]; - - let props = PROP_JSON_FIELDS.filter(a => !remove.includes(a)); - copyProperties(manifest, props, aOldAddon); - } - - // This updates the addon's JSON cached data in place - applyBlocklistChanges(aOldAddon, aOldAddon, aOldAppVersion, - aOldPlatformVersion); - aOldAddon.appDisabled = !isUsableAddon(aOldAddon); - - return aOldAddon; - }, - - /** - * Compares the add-ons that are currently installed to those that were - * known to be installed when the application last ran and applies any - * changes found to the database. Also sends "startupcache-invalidate" signal to - * observerservice if it detects that data may have changed. - * Always called after XPIProviderUtils.js and extensions.json have been loaded. - * - * @param aManifests - * A dictionary of cached AddonInstalls for add-ons that have been - * installed - * @param aUpdateCompatibility - * true to update add-ons appDisabled property when the application - * version has changed - * @param aOldAppVersion - * The version of the application last run with this profile or null - * if it is a new profile or the version is unknown - * @param aOldPlatformVersion - * The version of the platform last run with this profile or null - * if it is a new profile or the version is unknown - * @param aSchemaChange - * The schema has changed and all add-on manifests should be re-read. - * @return a boolean indicating if a change requiring flushing the caches was - * detected - */ - processFileChanges(aManifests, aUpdateCompatibility, aOldAppVersion, aOldPlatformVersion, - aSchemaChange) { - let loadedManifest = (aInstallLocation, aId) => { - if (!(aInstallLocation.name in aManifests)) - return null; - if (!(aId in aManifests[aInstallLocation.name])) - return null; - return aManifests[aInstallLocation.name][aId]; - }; - - // Add-ons loaded from the database can have an uninitialized _sourceBundle - // if the descriptor was invalid. Swallow that error and say they don't exist. - let exists = (aAddon) => { - try { - return aAddon._sourceBundle.exists(); - } - catch (e) { - if (e.result == Cr.NS_ERROR_NOT_INITIALIZED) - return false; - throw e; - } - }; - - // Get the previous add-ons from the database and put them into maps by location - let previousAddons = new Map(); - for (let a of XPIDatabase.getAddons()) { - let locationAddonMap = previousAddons.get(a.location); - if (!locationAddonMap) { - locationAddonMap = new Map(); - previousAddons.set(a.location, locationAddonMap); - } - locationAddonMap.set(a.id, a); - } - - // Build the list of current add-ons into similar maps. When add-ons are still - // present we re-use the add-on objects from the database and update their - // details directly - let currentAddons = new Map(); - for (let installLocation of XPIProvider.installLocations) { - let locationAddonMap = new Map(); - currentAddons.set(installLocation.name, locationAddonMap); - - // Get all the on-disk XPI states for this location, and keep track of which - // ones we see in the database. - let states = XPIStates.getLocation(installLocation.name); - - // Iterate through the add-ons installed the last time the application - // ran - let dbAddons = previousAddons.get(installLocation.name); - if (dbAddons) { - for (let [id, oldAddon] of dbAddons) { - // Check if the add-on is still installed - let xpiState = states && states.get(id); - if (xpiState) { - // Here the add-on was present in the database and on disk - recordAddonTelemetry(oldAddon); - - // Check if the add-on has been changed outside the XPI provider - if (oldAddon.updateDate != xpiState.mtime) { - // Did time change in the wrong direction? - if (xpiState.mtime < oldAddon.updateDate) { - XPIProvider.setTelemetry(oldAddon.id, "olderFile", { - name: XPIProvider._mostRecentlyModifiedFile[id], - mtime: xpiState.mtime, - oldtime: oldAddon.updateDate - }); - } else { - XPIProvider.setTelemetry(oldAddon.id, "modifiedFile", - XPIProvider._mostRecentlyModifiedFile[id]); - } - } - - // The add-on has changed if the modification time has changed, if - // we have an updated manifest for it, or if the schema version has - // changed. - // - // Also reload the metadata for add-ons in the application directory - // when the application version has changed. - let newAddon = loadedManifest(installLocation, id); - if (newAddon || oldAddon.updateDate != xpiState.mtime || - (aUpdateCompatibility && (installLocation.name == KEY_APP_GLOBAL || - installLocation.name == KEY_APP_SYSTEM_DEFAULTS))) { - newAddon = this.updateMetadata(installLocation, oldAddon, xpiState, newAddon); - } - else if (oldAddon.descriptor != xpiState.descriptor) { - newAddon = this.updateDescriptor(installLocation, oldAddon, xpiState); - } - // Check compatility when the application version and/or schema - // version has changed. A schema change also reloads metadata from - // the manifests. - else if (aUpdateCompatibility || aSchemaChange) { - newAddon = this.updateCompatibility(installLocation, oldAddon, xpiState, - aOldAppVersion, aOldPlatformVersion, - aSchemaChange); - } - else { - // No change - newAddon = oldAddon; - } - - if (newAddon) - locationAddonMap.set(newAddon.id, newAddon); - } - else { - // The add-on is in the DB, but not in xpiState (and thus not on disk). - this.removeMetadata(oldAddon); - } - } - } - - // Any add-on in our current location that we haven't seen needs to - // be added to the database. - // Get the migration data for this install location so we can include that as - // we add, in case this is a database upgrade or rebuild. - let locMigrateData = {}; - if (XPIDatabase.migrateData && installLocation.name in XPIDatabase.migrateData) - locMigrateData = XPIDatabase.migrateData[installLocation.name]; - - if (states) { - for (let [id, xpiState] of states) { - if (locationAddonMap.has(id)) - continue; - let migrateData = id in locMigrateData ? locMigrateData[id] : null; - let newAddon = loadedManifest(installLocation, id); - let addon = this.addMetadata(installLocation, id, xpiState, newAddon, - aOldAppVersion, aOldPlatformVersion, migrateData); - if (addon) - locationAddonMap.set(addon.id, addon); - } - } - } - - // previousAddons may contain locations where the database contains add-ons - // but the browser is no longer configured to use that location. The metadata - // for those add-ons must be removed from the database. - for (let [locationName, addons] of previousAddons) { - if (!currentAddons.has(locationName)) { - for (let [id, oldAddon] of addons) - this.removeMetadata(oldAddon); - } - } - - // Validate the updated system add-ons - let systemAddonLocation = XPIProvider.installLocationsByName[KEY_APP_SYSTEM_ADDONS]; - let addons = currentAddons.get(KEY_APP_SYSTEM_ADDONS) || new Map(); - - let hideLocation; - - if (!systemAddonLocation.isValid(addons)) { - // Hide the system add-on updates if any are invalid. - logger.info("One or more updated system add-ons invalid, falling back to defaults."); - hideLocation = KEY_APP_SYSTEM_ADDONS; - } - - let previousVisible = this.getVisibleAddons(previousAddons); - let currentVisible = this.flattenByID(currentAddons, hideLocation); - let sawActiveTheme = false; - XPIProvider.bootstrappedAddons = {}; - - // Pass over the new set of visible add-ons, record any changes that occured - // during startup and call bootstrap install/uninstall scripts as necessary - for (let [id, currentAddon] of currentVisible) { - let previousAddon = previousVisible.get(id); - - // Note if any visible add-on is not in the application install location - if (currentAddon._installLocation.name != KEY_APP_GLOBAL) - XPIProvider.allAppGlobal = false; - - let isActive = !currentAddon.disabled; - let wasActive = previousAddon ? previousAddon.active : currentAddon.active - - if (!previousAddon) { - // If we had a manifest for this add-on it was a staged install and - // so wasn't something recovered from a corrupt database - let wasStaged = !!loadedManifest(currentAddon._installLocation, id); - - // We might be recovering from a corrupt database, if so use the - // list of known active add-ons to update the new add-on - if (!wasStaged && XPIDatabase.activeBundles) { - // For themes we know which is active by the current skin setting - if (currentAddon.type == "theme") - isActive = currentAddon.internalName == XPIProvider.currentSkin; - else - isActive = XPIDatabase.activeBundles.indexOf(currentAddon.descriptor) != -1; - - // If the add-on wasn't active and it isn't already disabled in some way - // then it was probably either softDisabled or userDisabled - if (!isActive && !currentAddon.disabled) { - // If the add-on is softblocked then assume it is softDisabled - if (currentAddon.blocklistState == Blocklist.STATE_SOFTBLOCKED) - currentAddon.softDisabled = true; - else - currentAddon.userDisabled = true; - } - } - else { - // This is a new install - if (currentAddon.foreignInstall) - AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_INSTALLED, id); - - if (currentAddon.bootstrap) { - AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_INSTALLED, id); - // Visible bootstrapped add-ons need to have their install method called - XPIProvider.callBootstrapMethod(currentAddon, currentAddon._sourceBundle, - "install", BOOTSTRAP_REASONS.ADDON_INSTALL); - if (!isActive) - XPIProvider.unloadBootstrapScope(currentAddon.id); - } - } - } - else { - if (previousAddon !== currentAddon) { - // This is an add-on that has changed, either the metadata was reloaded - // or the version in a different location has become visible - AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED, id); - - let installReason = Services.vc.compare(previousAddon.version, currentAddon.version) < 0 ? - BOOTSTRAP_REASONS.ADDON_UPGRADE : - BOOTSTRAP_REASONS.ADDON_DOWNGRADE; - - // If the previous add-on was in a different path, bootstrapped - // and still exists then call its uninstall method. - if (previousAddon.bootstrap && previousAddon._installLocation && - exists(previousAddon) && - currentAddon._sourceBundle.path != previousAddon._sourceBundle.path) { - - XPIProvider.callBootstrapMethod(previousAddon, previousAddon._sourceBundle, - "uninstall", installReason, - { newVersion: currentAddon.version }); - XPIProvider.unloadBootstrapScope(previousAddon.id); - } - - // Make sure to flush the cache when an old add-on has gone away - flushChromeCaches(); - - if (currentAddon.bootstrap) { - // Visible bootstrapped add-ons need to have their install method called - let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file.persistentDescriptor = currentAddon._sourceBundle.persistentDescriptor; - XPIProvider.callBootstrapMethod(currentAddon, file, - "install", installReason, - { oldVersion: previousAddon.version }); - if (currentAddon.disabled) - XPIProvider.unloadBootstrapScope(currentAddon.id); - } - } - - if (isActive != wasActive) { - let change = isActive ? AddonManager.STARTUP_CHANGE_ENABLED - : AddonManager.STARTUP_CHANGE_DISABLED; - AddonManagerPrivate.addStartupChange(change, id); - } - } - - XPIDatabase.makeAddonVisible(currentAddon); - currentAddon.active = isActive; - - // Make sure the bootstrap information is up to date for this ID - if (currentAddon.bootstrap && currentAddon.active) { - XPIProvider.bootstrappedAddons[id] = { - version: currentAddon.version, - type: currentAddon.type, - descriptor: currentAddon._sourceBundle.persistentDescriptor, - multiprocessCompatible: currentAddon.multiprocessCompatible, - runInSafeMode: canRunInSafeMode(currentAddon), - dependencies: currentAddon.dependencies, - hasEmbeddedWebExtension: currentAddon.hasEmbeddedWebExtension, - }; - } - - if (currentAddon.active && currentAddon.internalName == XPIProvider.selectedSkin) - sawActiveTheme = true; - } - - // Pass over the set of previously visible add-ons that have now gone away - // and record the change. - for (let [id, previousAddon] of previousVisible) { - if (currentVisible.has(id)) - continue; - - // This add-on vanished - - // If the previous add-on was bootstrapped and still exists then call its - // uninstall method. - if (previousAddon.bootstrap && exists(previousAddon)) { - XPIProvider.callBootstrapMethod(previousAddon, previousAddon._sourceBundle, - "uninstall", BOOTSTRAP_REASONS.ADDON_UNINSTALL); - XPIProvider.unloadBootstrapScope(previousAddon.id); - } - AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_UNINSTALLED, id); - - // Make sure to flush the cache when an old add-on has gone away - flushChromeCaches(); - } - - // Make sure add-ons from hidden locations are marked invisible and inactive - let locationAddonMap = currentAddons.get(hideLocation); - if (locationAddonMap) { - for (let addon of locationAddonMap.values()) { - addon.visible = false; - addon.active = false; - } - } - - // If a custom theme is selected and it wasn't seen in the new list of - // active add-ons then enable the default theme - if (XPIProvider.selectedSkin != XPIProvider.defaultSkin && !sawActiveTheme) { - logger.info("Didn't see selected skin " + XPIProvider.selectedSkin); - XPIProvider.enableDefaultTheme(); - } - - // Finally update XPIStates to match everything - for (let [locationName, locationAddonMap] of currentAddons) { - for (let [id, addon] of locationAddonMap) { - let xpiState = XPIStates.getAddon(locationName, id); - xpiState.syncWithDB(addon); - } - } - XPIStates.save(); - - XPIProvider.persistBootstrappedAddons(); - - // Clear out any cached migration data. - XPIDatabase.migrateData = null; - XPIDatabase.saveChanges(); - - return true; - }, -} diff --git a/toolkit/mozapps/extensions/internal/moz.build b/toolkit/mozapps/extensions/internal/moz.build index 28c34f8c9..efcd2af21 100644 --- a/toolkit/mozapps/extensions/internal/moz.build +++ b/toolkit/mozapps/extensions/internal/moz.build @@ -1,28 +1,17 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- # vim: set filetype=python: # 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/. EXTRA_JS_MODULES.addons += [ + '../../webextensions/internal/ProductAddonChecker.jsm', 'AddonLogging.jsm', - 'AddonRepository.jsm', 'AddonRepository_SQLiteMigrator.jsm', - 'AddonUpdateChecker.jsm', - 'APIExtensionBootstrap.js', 'Content.js', - 'E10SAddonsRollout.jsm', 'GMPProvider.jsm', 'LightweightThemeImageOptimizer.jsm', - 'ProductAddonChecker.jsm', 'SpellCheckDictionaryBootstrap.js', - 'WebExtensionBootstrap.js', - 'XPIProvider.jsm', - 'XPIProviderUtils.js', -] - -TESTING_JS_MODULES += [ - 'AddonTestUtils.jsm', ] # Don't ship unused providers on Android @@ -32,5 +21,20 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android': ] EXTRA_PP_JS_MODULES.addons += [ - 'AddonConstants.jsm', + 'AddonRepository.jsm', + 'AddonUpdateChecker.jsm', + 'XPIProvider.jsm', + 'XPIProviderUtils.js', ] + +# This is used in multiple places, so is defined here to avoid it getting +# out of sync. +DEFINES['MOZ_EXTENSIONS_DB_SCHEMA'] = 16 + +# Additional debugging info is exposed in debug builds +if CONFIG['MOZ_EM_DEBUG']: + DEFINES['MOZ_EM_DEBUG'] = 1 + +# Apperently this needs to be defined because it isn't picked up automagically any more +if CONFIG['MOZ_PHOENIX_EXTENSIONS']: + DEFINES['MOZ_PHOENIX_EXTENSIONS'] = 1
\ No newline at end of file |