Bug 1436851 - Implement mechanism to disable system addon updates via enterprise policy draft
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 12 Feb 2018 10:44:43 -0800
changeset 763269 8d77889b6712e1dc9739fab17c6d2013acf60e29
parent 763109 51200c0fdaddb2749549a82596da5323a4cbd499
child 763270 36b90814f04c1bab00e02e63f7675a6bf9d08ae6
push id101390
push userksteuber@mozilla.com
push dateMon, 05 Mar 2018 18:18:23 +0000
bugs1436851
milestone60.0a1
Bug 1436851 - Implement mechanism to disable system addon updates via enterprise policy This patch additionally removes the check where if AddonManagerPrivate.backgroundUpdateTimerHandler does not call AddonManagerInternal.backgroundUpdateCheck if updates to all addons are disabled. The check is redundant as AddonManagerInternal.backgroundUpdateCheck makes those same checks. MozReview-Commit-ID: FxS8127JYkn
toolkit/mozapps/extensions/AddonManager.jsm
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -1320,31 +1320,40 @@ var AddonManagerInternal = {
         addon: info.addon,
         permissions: difference,
         resolve, reject
       }};
       Services.obs.notifyObservers(subject, "webextension-update-permissions");
     });
   },
 
+  // Returns true if System Addons should be updated
+  systemUpdateEnabled() {
+    if (!Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED) ||
+        !Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO)) {
+      return false;
+    }
+    if (Services.policies && !Services.policies.isAllowed("SysAddonUpdate")) {
+      return false;
+    }
+    return true;
+  },
+
   /**
    * Performs a background update check by starting an update for all add-ons
    * that can be updated.
    * @return Promise{null} Resolves when the background update check is complete
    *                       (the resulting addon installations may still be in progress).
    */
   backgroundUpdateCheck() {
     if (!gStarted)
       throw Components.Exception("AddonManager is not initialized",
                                  Cr.NS_ERROR_NOT_INITIALIZED);
 
     let buPromise = (async () => {
-      let appUpdateEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED) &&
-                             Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO);
-
       logger.debug("Background update check beginning");
 
       Services.obs.notifyObservers(null, "addons-background-update-start");
 
       if (this.updateEnabled) {
         let scope = {};
         ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm", scope);
         scope.LightweightThemeManager.updateCurrentTheme();
@@ -1381,17 +1390,17 @@ var AddonManagerInternal = {
 
               onUpdateFinished: aAddon => { logger.debug("onUpdateFinished for ${id}", aAddon); resolve(); }
             }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
           }));
         }
         await Promise.all(updates);
       }
 
-      if (appUpdateEnabled) {
+      if (AddonManagerInternal.systemUpdateEnabled()) {
         try {
           await AddonManagerInternal._getProviderByName("XPIProvider").updateSystemAddons();
         } catch (e) {
           logger.warn("Failed to update system addons", e);
         }
       }
 
       logger.debug("Background update check complete");
@@ -2999,24 +3008,16 @@ var AddonManagerPrivate = {
     AddonManagerInternal.markProviderSafe(aProvider);
   },
 
   backgroundUpdateCheck() {
     return AddonManagerInternal.backgroundUpdateCheck();
   },
 
   backgroundUpdateTimerHandler() {
-    // Don't call through to the real update check if no checks are enabled.
-    let appUpdateEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED) &&
-                           Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO);
-
-    if (!AddonManagerInternal.updateEnabled && !appUpdateEnabled) {
-      logger.info("Skipping background update check");
-      return;
-    }
     // Don't return the promise here, since the caller doesn't care.
     AddonManagerInternal.backgroundUpdateCheck();
   },
 
   addStartupChange(aType, aID) {
     AddonManagerInternal.addStartupChange(aType, aID);
   },