Bug 1525762: Part 1h - Use SCOPE_APPLICATION consistently for built-in add-ons. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Thu, 21 Mar 2019 19:33:26 -0700
changeset 466968 f9e0f5aa1c6df624ed2ad10d09fc5bb9aadee493
parent 466967 d7e4177fca6f63b1703687ad809048904e2415c2
child 466969 7c7df3ee8aaa9367dfc9715edd95586acfb2627a
push id35789
push userbtara@mozilla.com
push dateSun, 31 Mar 2019 09:00:52 +0000
treeherdermozilla-central@c06dfc552c64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1525762
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525762: Part 1h - Use SCOPE_APPLICATION consistently for built-in add-ons. r=aswan Most of our tests disable SCOPE_SYSTEM add-ons, which are meant to have been registered externally, but still rely on SCOPE_APPLICATION addons (i.e., the default theme), which are meant to be part of the application. We currently flag the built-in location as SCOPE_SYSTEM in some places and SCOPE_APPLICATION in others, which leads to those add-ons not being available to some tests that need them.
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_builtin_location.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -103,16 +103,28 @@ const STARTUP_MTIME_SCOPES = [KEY_APP_GL
 
 const NOTIFICATION_FLUSH_PERMISSIONS  = "flush-pending-permissions";
 const XPI_PERMISSION                  = "install";
 
 const XPI_SIGNATURE_CHECK_PERIOD      = 24 * 60 * 60;
 
 const DB_SCHEMA = 29;
 
+XPCOMUtils.defineLazyPreferenceGetter(this, "enabledScopesPref",
+                                      PREF_EM_ENABLED_SCOPES,
+                                      AddonManager.SCOPE_ALL);
+
+Object.defineProperty(this, "enabledScopes", {
+  get() {
+    // The profile location is always enabled
+    return enabledScopesPref | AddonManager.SCOPE_PROFILE;
+  },
+});
+
+
 function encoded(strings, ...values) {
   let result = [];
 
   for (let [i, string] of strings.entries()) {
     result.push(string);
     if (i < values.length)
       result.push(encodeURIComponent(values[i]));
   }
@@ -2110,36 +2122,31 @@ var XPIProvider = {
     }
 
     function RegistryLoc(aName, aScope, aKey) {
       if ("nsIWindowsRegKey" in Ci) {
         return new WinRegLocation(aName, Ci.nsIWindowsRegKey[aKey], aScope);
       }
     }
 
-    let enabledScopes = Services.prefs.getIntPref(PREF_EM_ENABLED_SCOPES,
-                                                  AddonManager.SCOPE_ALL);
-    // The profile location is always enabled
-    enabledScopes |= AddonManager.SCOPE_PROFILE;
-
     // These must be in order of priority, highest to lowest,
     // for processFileChanges etc. to work
     let locations = [
       [() => TemporaryInstallLocation, TemporaryInstallLocation.name, null],
 
       [DirectoryLoc, KEY_APP_PROFILE, AddonManager.SCOPE_PROFILE,
        KEY_PROFILEDIR, [DIR_EXTENSIONS], false],
 
       [SystemLoc, KEY_APP_SYSTEM_ADDONS, AddonManager.SCOPE_PROFILE,
        KEY_PROFILEDIR, [DIR_SYSTEM_ADDONS]],
 
       [SystemDefaultsLoc, KEY_APP_SYSTEM_DEFAULTS, AddonManager.SCOPE_PROFILE,
        KEY_APP_FEATURES, []],
 
-      [() => BuiltInLocation, KEY_APP_BUILTINS, AddonManager.SCOPE_SYSTEM],
+      [() => BuiltInLocation, KEY_APP_BUILTINS, AddonManager.SCOPE_APPLICATION],
 
       [DirectoryLoc, KEY_APP_SYSTEM_USER, AddonManager.SCOPE_USER,
        "XREUSysExt", [Services.appinfo.ID], true],
 
       [RegistryLoc, "winreg-app-user", AddonManager.SCOPE_USER,
        "ROOT_KEY_CURRENT_USER"],
 
       [DirectoryLoc, KEY_APP_GLOBAL, AddonManager.SCOPE_APPLICATION,
@@ -2607,16 +2614,20 @@ var XPIProvider = {
         logger.error(`Failed to install distribution add-on ${file.path}`, e);
       }
     }
 
     return changed;
   },
 
   maybeInstallBuiltinAddon(aID, aVersion, aBase) {
+    if (!(enabledScopes & BuiltInLocation.scope)) {
+      return;
+    }
+
     let existing = BuiltInLocation.get(aID);
     if (!existing || existing.version != aVersion) {
       this.startupPromises.push(this.installBuiltinAddon(aBase));
     }
   },
 
   getDependentAddons(aAddon) {
     return Array.from(XPIDatabase.getAddons())
--- a/toolkit/mozapps/extensions/test/xpcshell/test_builtin_location.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_builtin_location.js
@@ -1,15 +1,15 @@
 "use strict";
 
 /* globals browser */
 
 // Tests installing an extension from the built-in location.
 add_task(async function test_builtin_location() {
-  let scopes = AddonManager.SCOPE_PROFILE | AddonManager.SCOPE_SYSTEM;
+  let scopes = AddonManager.SCOPE_PROFILE | AddonManager.SCOPE_APPLICATION;
   Services.prefs.setIntPref("extensions.enabledScopes", scopes);
   Services.prefs.setBoolPref("extensions.webextensions.background-delayed-startup", false);
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
   await promiseStartupManager();
 
   const ID = "builtin@tests.mozilla.org";
   let xpi = await AddonTestUtils.createTempWebExtensionFile({