Bug 1542371 - Add basic support for ExtensionSettings policy. r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Thu, 11 Apr 2019 19:10:49 +0000
changeset 469092 b813d19ab2d1b27a46446f576f1f4294007300b2
parent 469091 7befb6bf6b3b2441d1659579e0edf7226aff8781
child 469093 acb04833e713061274e2f2221aa0b84cf2c2a8ab
push id82964
push usermozilla@kaply.com
push dateThu, 11 Apr 2019 19:27:22 +0000
treeherderautoland@b813d19ab2d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1542371
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 1542371 - Add basic support for ExtensionSettings policy. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D26376
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings.js
toolkit/components/enterprisepolicies/nsIEnterprisePolicies.idl
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -293,21 +293,36 @@ EnterprisePoliciesManager.prototype = {
 
   getExtensionPolicy(extensionID) {
     if (ExtensionPolicies &&
         extensionID in ExtensionPolicies) {
       return ExtensionPolicies[extensionID];
     }
     return null;
   },
+
+  setExtensionSettings(extensionSettings) {
+    ExtensionSettings = extensionSettings;
+  },
+
+  getExtensionSettings(extensionID) {
+    let settings = null;
+    if (extensionID in ExtensionSettings) {
+      settings = ExtensionSettings[extensionID];
+    } else if ("*" in ExtensionSettings) {
+      settings = ExtensionSettings["*"];
+    }
+    return settings;
+  },
 };
 
 let DisallowedFeatures = {};
 let SupportMenu = null;
 let ExtensionPolicies = null;
+let ExtensionSettings = null;
 
 /**
  * areEnterpriseOnlyPoliciesAllowed
  *
  * Checks whether the policies marked as enterprise_only in the
  * schema are allowed to run on this browser.
  *
  * This is meant to only allow policies to run on ESR, but in practice
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -572,16 +572,22 @@ var Policies = {
       if ("Locked" in param) {
         for (let ID of param.Locked) {
           manager.disallowFeature(`modify-extension:${ID}`);
         }
       }
     },
   },
 
+  "ExtensionSettings": {
+    onBeforeAddons(manager, param) {
+      manager.setExtensionSettings(param);
+    },
+  },
+
   "ExtensionUpdate": {
     onBeforeAddons(manager, param) {
       if (!param) {
         setAndLockPref("extensions.update.enabled", param);
       }
     },
   },
 
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -308,16 +308,30 @@
           "type": "array",
           "items": {
             "type": "string"
           }
         }
       }
     },
 
+    "ExtensionSettings": {
+      "type": "object",
+      "patternProperties": {
+        "^.*$": {
+          "type": "object",
+          "properties": {
+            "blocked_install_message": {
+              "type": "string"
+            }
+          }
+        }
+      }
+    },
+
     "ExtensionUpdate": {
       "type": "boolean"
     },
 
     "FlashPlugin": {
       "type": "object",
       "properties": {
         "Allow": {
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -49,16 +49,17 @@ skip-if = (verify && debug && (os == 'ma
 [browser_policy_disable_profile_reset.js]
 [browser_policy_disable_profile_import.js]
 [browser_policy_disable_safemode.js]
 [browser_policy_disable_shield.js]
 [browser_policy_disable_telemetry.js]
 [browser_policy_display_bookmarks.js]
 [browser_policy_display_menu.js]
 [browser_policy_extensions.js]
+[browser_policy_extensionsettings.js]
 [browser_policy_locale.js]
 [browser_policy_override_postupdatepage.js]
 [browser_policy_permissions.js]
 [browser_policy_proxy.js]
 [browser_policy_preferences.js]
 [browser_policy_search_engine.js]
 [browser_policy_searchbar.js]
 [browser_policy_set_homepage.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings.js
@@ -0,0 +1,23 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+add_task(async function test_extensionsettings() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "ExtensionSettings": {
+        "extension1@mozilla.com": {
+          "blocked_install_message": "Extension1 error message.",
+        },
+        "*": {
+          "blocked_install_message": "Generic error message.",
+        },
+      },
+    },
+  });
+
+  let extensionSettings =  Services.policies.getExtensionSettings("extension1@mozilla.com");
+  is(extensionSettings.blocked_install_message, "Extension1 error message.", "Should have extension specific message.");
+  extensionSettings =  Services.policies.getExtensionSettings("extension2@mozilla.com");
+  is(extensionSettings.blocked_install_message, "Generic error message.", "Should have generic message.");
+});
--- a/toolkit/components/enterprisepolicies/nsIEnterprisePolicies.idl
+++ b/toolkit/components/enterprisepolicies/nsIEnterprisePolicies.idl
@@ -32,9 +32,20 @@ interface nsIEnterprisePolicies : nsISup
   jsval getSupportMenu();
 
   /**
    * Get the policy for a given extensionID (if available)
    *
    * @returns A JS object that contains the storage or null if unavailable.
    */
   jsval getExtensionPolicy(in ACString extensionID);
+
+  /**
+   * Retrieves the ExtensionSettings policy for the given extensionID.
+   *
+   * If there is no policy for the extension, it returns the global policy.
+   *
+   * If there is no global policy, it returns null.
+   *
+   * @returns A JS object that settings or null if unavailable.
+   */
+  jsval getExtensionSettings(in ACString extensionID);
 };