Bug 1465950 - Keep parsed policies stored by EnterprisePolicies.js to display them on about:policies page. r=felipe
authorKanika Saini <ksaini@mozilla.com>
Wed, 20 Jun 2018 22:48:12 +0530
changeset 424026 6039fa792e1b8043b4df8167e2f7f3c92bbbbd99
parent 424025 d45a45dd4b5b6dc659000fa0f45df5972bef0f7c
child 424027 7758cd890fa8d73a275331a7e3babf58e9404e09
push id34198
push usercsabou@mozilla.com
push dateThu, 28 Jun 2018 10:05:18 +0000
treeherdermozilla-central@b429b9fb68f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1465950
milestone63.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 1465950 - Keep parsed policies stored by EnterprisePolicies.js to display them on about:policies page. r=felipe
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/EnterprisePoliciesContent.js
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js
toolkit/components/enterprisepolicies/nsIEnterprisePolicies.idl
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -85,16 +85,17 @@ EnterprisePoliciesManager.prototype = {
     }
 
     if (provider.failed) {
       this.status = Ci.nsIEnterprisePolicies.FAILED;
       return;
     }
 
     this.status = Ci.nsIEnterprisePolicies.ACTIVE;
+    this._parsedPolicies = {};
     this._activatePolicies(provider.policies);
   },
 
   _chooseProvider() {
     if (AppConstants.platform == "win") {
       let gpoProvider = new GPOPoliciesProvider();
       if (gpoProvider.hasPolicies) {
         return gpoProvider;
@@ -129,16 +130,17 @@ EnterprisePoliciesManager.prototype = {
       let [parametersAreValid, parsedParameters] =
         JsonSchemaValidator.validateAndParseParameters(policyParameters, policySchema);
 
       if (!parametersAreValid) {
         log.error(`Invalid parameters specified for ${policyName}.`);
         continue;
       }
 
+      this._parsedPolicies[policyName] = parsedParameters;
       let policyImpl = Policies[policyName];
 
       for (let timing of Object.keys(this._callbacks)) {
         let policyCallback = policyImpl[timing];
         if (policyCallback) {
           this._schedulePolicyCallback(
             timing,
             policyCallback.bind(policyImpl,
@@ -294,16 +296,20 @@ EnterprisePoliciesManager.prototype = {
 
   get status() {
     return this._status;
   },
 
   isAllowed: function BG_sanitize(feature) {
     return !(feature in DisallowedFeatures);
   },
+
+  getActivePolicies() {
+    return this._parsedPolicies;
+  },
 };
 
 let DisallowedFeatures = {};
 
 /**
  * areEnterpriseOnlyPoliciesAllowed
  *
  * Checks whether the policies marked as enterprise_only in the
--- a/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
+++ b/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
@@ -73,13 +73,17 @@ EnterprisePoliciesManagerContent.prototy
   },
 
   get status() {
     return this._status;
   },
 
   isAllowed(feature) {
     return !this._disallowedFeatures.includes(feature);
+  },
+
+  getActivePolicies() {
+    throw Cr.NS_ERROR_NOT_AVAILABLE;
   }
 };
 
 var components = [EnterprisePoliciesManagerContent];
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -7,16 +7,17 @@ support-files =
   opensearchEngine.xml
   policytest.xpi
   policy_websitefilter_block.html
   policy_websitefilter_exception.html
 
 [browser_policies_basic_tests.js]
 [browser_policies_broken_json.js]
 [browser_policies_enterprise_only.js]
+[browser_policies_getActivePolicies.js]
 [browser_policies_notice_in_aboutpreferences.js]
 [browser_policies_popups_cookies_addons_flash.js]
 [browser_policies_runOnce_helper.js]
 [browser_policies_setAndLockPref_API.js]
 [browser_policies_simple_pref_policies.js]
 [browser_policies_sorted_alphabetically.js]
 [browser_policy_app_update.js]
 [browser_policy_block_about_addons.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_active_policies() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "DisablePrivateBrowsing": true
+    }
+  });
+
+  let expected = {
+    "DisablePrivateBrowsing": true
+  };
+
+  Assert.deepEqual(await Services.policies.getActivePolicies(), expected, "Active policies parsed correctly");
+});
+
+add_task(async function test_wrong_policies() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "BlockAboutSupport": [true]
+    }
+  });
+
+  let expected = {};
+
+  Assert.deepEqual(await Services.policies.getActivePolicies(), expected, "Wrong policies ignored");
+});
+
+add_task(async function test_content_process() {
+  await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+    try {
+      Services.policies.getActivePolicies();
+    } catch (ex) {
+      is(ex.result, Cr.NS_ERROR_NOT_AVAILABLE, "Function getActivePolicies() doesn't have a valid definition in the content process");
+    }
+  });
+});
--- a/toolkit/components/enterprisepolicies/nsIEnterprisePolicies.idl
+++ b/toolkit/components/enterprisepolicies/nsIEnterprisePolicies.idl
@@ -10,9 +10,17 @@ interface nsIEnterprisePolicies : nsISup
   const short UNINITIALIZED = -1;
   const short INACTIVE      = 0;
   const short ACTIVE        = 1;
   const short FAILED        = 2;
 
   readonly attribute short status;
 
   bool isAllowed(in ACString feature);
+
+  /**
+   * Get the active policies that have been successfully parsed.
+   *
+   * @returns A JS object that contains the policies names and
+   *          their corresponding parameters.
+   */
+  jsval getActivePolicies();
 };