Kanika
Bug 1465950 - Parsed policies stored by EnterprisePolicies.js to display on about:policies page r?felipe
MozReview-Commit-ID: Ller1U0PY3r
--- 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,15 @@ 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 configured
+ * @return an object that contains policy names and their coressponding parameters
+ */
+ jsval getActivePolicies();
};