Bug 1359203 Part 3 Add extensions.legacy.enabled preference draft
authorAndrew Swan <aswan@mozilla.com>
Mon, 15 May 2017 22:04:55 -0700
changeset 581373 6351a33dae65975748ddc62dbfbc6cd22218bfca
parent 581372 510bb3d21711c04700b250e484b616a2a1d552ec
child 629559 328341f57f6301b899bb97064f1bea01d27c7e39
push id59850
push useraswan@mozilla.com
push dateFri, 19 May 2017 19:08:41 +0000
bugs1359203
milestone55.0a1
Bug 1359203 Part 3 Add extensions.legacy.enabled preference MozReview-Commit-ID: 3CaWhlcOgql
modules/libpref/init/all.js
toolkit/mozapps/extensions/internal/AddonSettings.jsm
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4792,16 +4792,17 @@ pref("browser.meta_refresh_when_inactive
 
 // XPInstall prefs
 pref("xpinstall.whitelist.required", true);
 // Only Firefox requires add-on signatures
 pref("xpinstall.signatures.required", false);
 pref("extensions.alwaysUnpack", false);
 pref("extensions.minCompatiblePlatformVersion", "2.0");
 pref("extensions.webExtensionsMinPlatformVersion", "42.0a1");
+pref("extensions.legacy.enabled", true);
 pref("extensions.allow-non-mpc-extensions", true);
 
 // Other webextensions prefs
 pref("extensions.webextensions.keepStorageOnUninstall", false);
 pref("extensions.webextensions.keepUuidOnUninstall", false);
 // Redirect basedomain used by identity api
 pref("extensions.webextensions.identity.redirectDomain", "extensions.allizom.org");
 // Whether or not webextension themes are supported.
--- a/toolkit/mozapps/extensions/internal/AddonSettings.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonSettings.jsm
@@ -7,16 +7,17 @@
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 this.EXPORTED_SYMBOLS = [ "AddonSettings" ];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/AppConstants.jsm");
 
 const PREF_SIGNATURES_REQUIRED = "xpinstall.signatures.required";
+const PREF_ALLOW_LEGACY = "extensions.legacy.enabled";
 
 this.AddonSettings = {};
 
 // Make a non-changable property that can't be manipulated from other
 // code in the app.
 function makeConstant(name, value) {
   Object.defineProperty(AddonSettings, name, {
     configurable: false,
@@ -29,8 +30,15 @@ function makeConstant(name, value) {
 makeConstant("ADDON_SIGNING", AppConstants.MOZ_ADDON_SIGNING);
 
 if (AppConstants.MOZ_REQUIRE_SIGNING && !Cu.isInAutomation) {
   makeConstant("REQUIRE_SIGNING", true);
 } else {
   XPCOMUtils.defineLazyPreferenceGetter(AddonSettings, "REQUIRE_SIGNING",
                                         PREF_SIGNATURES_REQUIRED, false);
 }
+
+if (AppConstants.MOZ_ALLOW_LEGACY_EXTENSIONS || Cu.isInAutomation) {
+  XPCOMUtils.defineLazyPreferenceGetter(AddonSettings, "ALLOW_LEGACY_EXTENSIONS",
+                                        PREF_ALLOW_LEGACY, true);
+} else {
+  makeConstant("ALLOW_LEGACY_EXTENSIONS", false);
+}
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -212,16 +212,17 @@ const PREF_INSTALL_DISTRO_ADDONS      = 
 const PREF_BRANCH_INSTALLED_ADDON     = "extensions.installedDistroAddon.";
 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_ALLOW_LEGACY               = "extensions.legacy.enabled";
 const PREF_ALLOW_NON_MPC              = "extensions.allow-non-mpc-extensions";
 
 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";
@@ -909,16 +910,23 @@ function isUsableAddon(aAddon) {
       let active = XPIProvider.activeAddons.get(id);
       return active && !active.disable;
     };
 
     if (aAddon.dependencies.some(id => !isActive(id)))
       return false;
   }
 
+  if (!AddonSettings.ALLOW_LEGACY_EXTENSIONS &&
+      aAddon.type == "extension" && !aAddon.isSystem &&
+      aAddon.signedState !== AddonManager.SIGNEDSTATE_PRIVILEGED) {
+    logger.warn(`disabling legacy extension ${aAddon.id}`);
+    return false;
+  }
+
   if (!ALLOW_NON_MPC && aAddon.type == "extension" &&
       aAddon.multiprocessCompatible !== true) {
     logger.warn(`disabling ${aAddon.id} since it is not multiprocess compatible`);
     return false;
   }
 
   if (AddonManager.checkCompatibility) {
     if (!aAddon.isCompatible) {
@@ -3218,16 +3226,17 @@ this.XPIProvider = {
                                                           null);
 
       Services.prefs.addObserver(PREF_EM_MIN_COMPAT_APP_VERSION, this);
       Services.prefs.addObserver(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, this);
       Services.prefs.addObserver(PREF_E10S_ADDON_BLOCKLIST, this);
       Services.prefs.addObserver(PREF_E10S_ADDON_POLICY, this);
       if (!AppConstants.MOZ_REQUIRE_SIGNING || Cu.isInAutomation)
         Services.prefs.addObserver(PREF_XPI_SIGNATURES_REQUIRED, this);
+      Services.prefs.addObserver(PREF_ALLOW_LEGACY, this);
       Services.prefs.addObserver(PREF_ALLOW_NON_MPC, this);
       Services.obs.addObserver(this, NOTIFICATION_FLUSH_PERMISSIONS);
 
       // 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
@@ -4864,16 +4873,17 @@ this.XPIProvider = {
         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:
+      case PREF_ALLOW_LEGACY:
       case PREF_ALLOW_NON_MPC:
         this.updateAddonAppDisabledStates();
         break;
 
       case PREF_E10S_ADDON_BLOCKLIST:
       case PREF_E10S_ADDON_POLICY:
         XPIDatabase.updateAddonsBlockingE10s();
         break;