Bug 1436851 - Create an enterprise policy to disable system addon updates draft
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 12 Feb 2018 10:48:18 -0800
changeset 763859 49a49423b2f0e168b280ace047877768030574da
parent 763270 36b90814f04c1bab00e02e63f7675a6bf9d08ae6
child 763860 e962f9118262c1b1d93f13817415e264c5cf08ab
push id101569
push userksteuber@mozilla.com
push dateTue, 06 Mar 2018 19:27:32 +0000
bugs1436851
milestone60.0a1
Bug 1436851 - Create an enterprise policy to disable system addon updates MozReview-Commit-ID: AzxFGpFvxtm
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -329,22 +329,28 @@ class JSONPoliciesProvider {
     return this._policies;
   }
 
   get failed() {
     return this._failed;
   }
 
   _getConfigurationFile() {
-    let configFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile);
-    configFile.append(POLICIES_FILENAME);
+    let configFile = null;
+    try {
+      configFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile);
+      configFile.append(POLICIES_FILENAME);
+    } catch (ex) {
+      // Getting the correct directory will fail in xpcshell tests. This should
+      // be handled the same way as if the configFile simply does not exist.
+    }
 
     let alternatePath = Services.prefs.getStringPref(PREF_ALTERNATE_PATH, "");
 
-    if (alternatePath && !configFile.exists()) {
+    if (alternatePath && (!configFile || !configFile.exists())) {
       // We only want to use the alternate file path if the file on the install
       // folder doesn't exist. Otherwise it'd be possible for a user to override
       // the admin-provided policies by changing the user-controlled prefs.
       // This pref is only meant for tests, so it's fine to use this extra
       // synchronous configFile.exists() above.
       if (alternatePath.startsWith(MAGIC_TEST_ROOT_PREFIX)) {
         // Intentionally not using a default value on this pref lookup. If no
         // test root is set, we are not currently testing and this function
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -185,16 +185,24 @@ var Policies = {
       if (param) {
         manager.disallowFeature("privatebrowsing");
         manager.disallowFeature("about:privatebrowsing", true);
         setAndLockPref("browser.privatebrowsing.autostart", false);
       }
     }
   },
 
+  "DisableSysAddonUpdate": {
+    onBeforeAddons(manager, param) {
+      if (param) {
+        manager.disallowFeature("SysAddonUpdate");
+      }
+    }
+  },
+
   "DisplayBookmarksToolbar": {
     onBeforeUIStartup(manager, param) {
       if (param) {
         // This policy is meant to change the default behavior, not to force it.
         // If this policy was alreay applied and the user chose to re-hide the
         // bookmarks toolbar, do not show it again.
         runOnce("displayBookmarksToolbar", () => {
           gXulStore.setValue(BROWSER_DOCUMENT_URL, "PersonalToolbar", "collapsed", "false");
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -153,16 +153,25 @@
     "DisablePrivateBrowsing": {
       "description": "Disables private browsing.",
       "first_available": "60.0",
 
       "type": "boolean",
       "enum": [true]
     },
 
+    "DisableSysAddonUpdate": {
+      "description": "Prevent the browser from installing and updating system addons.",
+      "first_available": "60.0",
+      "enterprise_only": true,
+
+      "type": "boolean",
+      "enum": [true]
+    },
+
     "DisplayBookmarksToolbar": {
       "description": "Causes the bookmarks toolbar to be displayed by default.",
       "first_available": "60.0",
 
       "type": "boolean"
     },
 
     "DisplayMenuBar": {