From c872ff3d333b1fdf8dc84373f2e82bd6e5fdf874 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Thu, 19 Nov 2015 15:30:47 -0800 Subject: [PATCH] Bug 1226386: Remove most of the preprocessing from the add-ons manager. r=gps For build speed, for correct line numbers in errors, for faster development, for so many reasons. Still a couple of cases left mostly in XUL files for different strings on Windows. Bonus: The new lexical scope means ADDON_SIGNING and REQUIRE_SIGNING can just be declared as regular constants and outside code can't get to them easily. --HG-- extra : commitid : Kj8khjuCwG2 extra : rebase_source : 2e0a3143900c0c414cda43254306f0c070f8e621 --- configure.in | 5 -- toolkit/mozapps/extensions/AddonManager.jsm | 23 ++++---- .../mozapps/extensions/content/extensions.js | 12 ++-- .../extensions/internal/AddonConstants.jsm | 31 ++++++++++ .../extensions/internal/XPIProvider.jsm | 58 +++++-------------- .../extensions/internal/XPIProviderUtils.js | 3 - toolkit/mozapps/extensions/internal/moz.build | 13 +---- toolkit/mozapps/extensions/jar.mn | 2 +- toolkit/mozapps/extensions/moz.build | 12 +--- 9 files changed, 69 insertions(+), 90 deletions(-) create mode 100644 toolkit/mozapps/extensions/internal/AddonConstants.jsm diff --git a/configure.in b/configure.in index 255926dc2aae..fcbe2e30e791 100644 --- a/configure.in +++ b/configure.in @@ -8988,11 +8988,6 @@ AC_SUBST(DMG_TOOL) dnl Host JavaScript runtime, if any, to use during cross compiles. AC_SUBST(JS_BINARY) -if test "$MOZ_DEBUG"; then - MOZ_EM_DEBUG=1 -fi -AC_SUBST(MOZ_EM_DEBUG) - AC_SUBST(NSS_EXTRA_SYMBOLS_FILE) if test -n "$COMPILE_ENVIRONMENT"; then diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 3def44b06ecd..63949aa7f921 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -21,6 +21,9 @@ if ("@mozilla.org/xre/app-info;1" in Cc) { } } +Cu.import("resource://gre/modules/AppConstants.jsm"); + +const MOZ_COMPATIBILITY_NIGHTLY = !['aurora', 'beta', 'release', 'esr'].includes(AppConstants.MOZ_UPDATE_CHANNEL); const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion"; const PREF_DEFAULT_PROVIDERS_ENABLED = "extensions.defaultProviders.enabled"; @@ -55,11 +58,9 @@ const FILE_BLOCKLIST = "blocklist.xml"; const BRANCH_REGEXP = /^([^\.]+\.[0-9]+[a-z]*).*/gi; const PREF_EM_CHECK_COMPATIBILITY_BASE = "extensions.checkCompatibility"; -#ifdef MOZ_COMPATIBILITY_NIGHTLY -var PREF_EM_CHECK_COMPATIBILITY = PREF_EM_CHECK_COMPATIBILITY_BASE + ".nightly"; -#else -var PREF_EM_CHECK_COMPATIBILITY; -#endif +var PREF_EM_CHECK_COMPATIBILITY = MOZ_COMPATIBILITY_NIGHTLY ? + PREF_EM_CHECK_COMPATIBILITY_BASE + ".nightly" : + undefined; const TOOLKIT_ID = "toolkit@mozilla.org"; @@ -911,10 +912,10 @@ var AddonManagerInternal = { this.validateBlocklist(); } -#ifndef MOZ_COMPATIBILITY_NIGHTLY - PREF_EM_CHECK_COMPATIBILITY = PREF_EM_CHECK_COMPATIBILITY_BASE + "." + - Services.appinfo.version.replace(BRANCH_REGEXP, "$1"); -#endif + if (!MOZ_COMPATIBILITY_NIGHTLY) { + PREF_EM_CHECK_COMPATIBILITY = PREF_EM_CHECK_COMPATIBILITY_BASE + "." + + Services.appinfo.version.replace(BRANCH_REGEXP, "$1"); + } try { gCheckCompatibility = Services.prefs.getBoolPref(PREF_EM_CHECK_COMPATIBILITY); @@ -3138,11 +3139,9 @@ this.AddonManager = { // case-by-case basis. STATE_ASK_TO_ACTIVATE: "askToActivate", -#ifdef MOZ_EM_DEBUG get __AddonManagerInternal__() { - return AddonManagerInternal; + return AppConstants.DEBUG ? AddonManagerInternal : undefined; }, -#endif get isReady() { return gStartupComplete && !gShutdownInProgress; diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 6289e2516607..c5ea3a7197c6 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -15,6 +15,12 @@ Cu.import("resource://gre/modules/DownloadUtils.jsm"); Cu.import("resource://gre/modules/AddonManager.jsm"); Cu.import("resource://gre/modules/addons/AddonRepository.jsm"); +const CONSTANTS = {}; +Cu.import("resource://gre/modules/addons/AddonConstants.jsm", CONSTANTS); +const SIGNING_REQUIRED = CONSTANTS.REQUIRE_SIGNING ? + true : + Services.prefs.getBoolPref("xpinstall.signatures.required"); + XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm"); @@ -3796,9 +3802,3 @@ var gDragDrop = { aEvent.preventDefault(); } }; - -#ifdef MOZ_REQUIRE_SIGNING -const SIGNING_REQUIRED = true; -#else -const SIGNING_REQUIRED = Services.prefs.getBoolPref("xpinstall.signatures.required"); -#endif diff --git a/toolkit/mozapps/extensions/internal/AddonConstants.jsm b/toolkit/mozapps/extensions/internal/AddonConstants.jsm new file mode 100644 index 000000000000..22d91fdf5b7d --- /dev/null +++ b/toolkit/mozapps/extensions/internal/AddonConstants.jsm @@ -0,0 +1,31 @@ +/* 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/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index 36d9b2557bbf..988ad23f9f0e 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -11,10 +11,14 @@ const Cu = Components.utils; this.EXPORTED_SYMBOLS = ["XPIProvider"]; -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"); +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"); XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository", "resource://gre/modules/addons/AddonRepository.jsm"); @@ -48,6 +52,8 @@ 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.defineLazyServiceGetter(this, "Blocklist", "@mozilla.org/extensions/blocklist;1", @@ -158,9 +164,8 @@ const TOOLKIT_ID = "toolkit@mozilla.org"; const XPI_SIGNATURE_CHECK_PERIOD = 24 * 60 * 60; -// The value for this is in Makefile.in -#expand const DB_SCHEMA = __MOZ_EXTENSIONS_DB_SCHEMA__; -XPCOMUtils.defineConstant(this, "DB_SCHEMA", DB_SCHEMA); +XPCOMUtils.defineConstant(this, "DB_SCHEMA", 17); + const NOTIFICATION_TOOLBOXPROCESS_LOADED = "ToolboxProcessLoaded"; // Properties that exist in the install manifest @@ -288,6 +293,7 @@ function loadLazyObjects() { ADDON_SIGNING, SIGNED_TYPES, BOOTSTRAP_REASONS, + DB_SCHEMA, AddonInternal, XPIProvider, XPIStates, @@ -6154,11 +6160,9 @@ AddonInstall.createUpdate = function AI_createUpdate(aCallback, aAddon, aUpdate) * The AddonInstall to create a wrapper for */ function AddonInstallWrapper(aInstall) { -#ifdef MOZ_EM_DEBUG this.__defineGetter__("__AddonInstallInternal__", function AIW_debugGetter() { - return aInstall; + return AppConstants.DEBUG ? aInstall : undefined; }); -#endif ["name", "version", "icons", "releaseNotesURI", "file", "state", "error", "progress", "maxProgress", "certificate", "certName"].forEach(function(aProp) { @@ -6722,11 +6726,9 @@ function createWrapper(aAddon) { * the public API. */ function AddonWrapper(aAddon) { -#ifdef MOZ_EM_DEBUG this.__defineGetter__("__AddonInternal__", function AW_debugGetter() { - return aAddon; + return AppConstants.DEBUG ? aAddon : undefined; }); -#endif function chooseValue(aObj, aProp) { let repositoryAddon = aAddon._repositoryAddon; @@ -7962,7 +7964,6 @@ const TemporaryInstallLocation = { getStagingDir: () => {}, } -#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 @@ -8012,11 +8013,9 @@ WinRegInstallLocation.prototype = { let appVendor = Services.appinfo.vendor; let appName = Services.appinfo.name; -#ifdef MOZ_THUNDERBIRD // XXX Thunderbird doesn't specify a vendor string - if (appVendor == "") + if (AppConstants.MOZ_APP_NAME == "thunderbird" && appVendor == "") appVendor = "Mozilla"; -#endif // XULRunner-based apps may intentionally not specify a vendor if (appVendor != "") @@ -8083,31 +8082,6 @@ WinRegInstallLocation.prototype = { return true; } }; -#endif - -// 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 -}); 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 4d06bf890d2c..256ca84e9dbc 100644 --- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js +++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js @@ -41,9 +41,6 @@ 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"; diff --git a/toolkit/mozapps/extensions/internal/moz.build b/toolkit/mozapps/extensions/internal/moz.build index a12a18360130..ec586b968d7a 100644 --- a/toolkit/mozapps/extensions/internal/moz.build +++ b/toolkit/mozapps/extensions/internal/moz.build @@ -15,6 +15,8 @@ EXTRA_JS_MODULES.addons += [ 'ProductAddonChecker.jsm', 'SpellCheckDictionaryBootstrap.js', 'WebExtensionBootstrap.js', + 'XPIProvider.jsm', + 'XPIProviderUtils.js', ] # Don't ship unused providers on Android @@ -24,18 +26,9 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android': ] EXTRA_PP_JS_MODULES.addons += [ - 'XPIProvider.jsm', - 'XPIProviderUtils.js', + 'AddonConstants.jsm', ] -# This is used in multiple places, so is defined here to avoid it getting -# out of sync. -DEFINES['MOZ_EXTENSIONS_DB_SCHEMA'] = 17 - -# Additional debugging info is exposed in debug builds -if CONFIG['MOZ_EM_DEBUG']: - DEFINES['MOZ_EM_DEBUG'] = 1 - if CONFIG['MOZ_ADDON_SIGNING']: DEFINES['MOZ_ADDON_SIGNING'] = 1 diff --git a/toolkit/mozapps/extensions/jar.mn b/toolkit/mozapps/extensions/jar.mn index e95d93ca0292..02430591c09a 100644 --- a/toolkit/mozapps/extensions/jar.mn +++ b/toolkit/mozapps/extensions/jar.mn @@ -6,7 +6,7 @@ toolkit.jar: % content mozapps %content/mozapps/ * content/mozapps/extensions/extensions.xul (content/extensions.xul) content/mozapps/extensions/extensions.css (content/extensions.css) -* content/mozapps/extensions/extensions.js (content/extensions.js) + content/mozapps/extensions/extensions.js (content/extensions.js) * content/mozapps/extensions/extensions.xml (content/extensions.xml) content/mozapps/extensions/updateinfo.xsl (content/updateinfo.xsl) content/mozapps/extensions/about.xul (content/about.xul) diff --git a/toolkit/mozapps/extensions/moz.build b/toolkit/mozapps/extensions/moz.build index faa4f749098c..8fbd96da8b46 100644 --- a/toolkit/mozapps/extensions/moz.build +++ b/toolkit/mozapps/extensions/moz.build @@ -30,22 +30,12 @@ EXTRA_PP_COMPONENTS += [ ] EXTRA_JS_MODULES += [ + 'AddonManager.jsm', 'ChromeManifestParser.jsm', 'DeferredSave.jsm', 'LightweightThemeManager.jsm', ] -EXTRA_PP_JS_MODULES += [ - 'AddonManager.jsm' -] - -if CONFIG['MOZ_UPDATE_CHANNEL'] not in ('aurora', 'beta', 'release', 'esr'): - DEFINES['MOZ_COMPATIBILITY_NIGHTLY'] = 1 - -# Additional debugging info is exposed in debug builds -if CONFIG['MOZ_EM_DEBUG']: - DEFINES['MOZ_EM_DEBUG'] = 1 - JAR_MANIFESTS += ['jar.mn'] EXPORTS.mozilla += [