Bug 1419102 - Support passing down the information to the content process. r=Mossop
MozReview-Commit-ID: FFrf59qmYfr
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -36,18 +36,16 @@ const PREF_ALTERNATE_PATH = "browser
// testing this feature without rolling it out officially. When the
// policy engine is released, this pref should be removed.
const PREF_ENABLED = "browser.policies.enabled";
// File mode constants
const MODE_RDONLY = 0x01;
const PERMS_FILE = 0o644;
-
-
// ==== Start XPCOM Boilerplate ==== \\
// Factory object
const EnterprisePoliciesFactory = {
_instance: null,
createInstance: function BGSF_createInstance(outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
@@ -168,28 +166,50 @@ EnterprisePoliciesManager.prototype = {
break;
case "sessionstore-windows-restored":
this._runPoliciesCallbacks("AllWindowsRestored");
break;
}
},
- disallowFeature(feature) {
+ disallowFeature(feature, neededOnContentProcess = false) {
DisallowedFeatures[feature] = true;
+
+ // NOTE: For optimization purposes, only features marked as needed
+ // on content process will be passed onto the child processes.
+ if (neededOnContentProcess) {
+ Services.ppmm.initialProcessData.policies
+ .disallowedFeatures.push(feature);
+
+ if (Services.ppmm.childCount > 1) {
+ LOG("sending disallow feature for " + feature);
+ // If there has been a content process already initialized, let's
+ // broadcast the newly disallowed feature.
+ Services.ppmm.broadcastAsyncMessage(
+ "EnterprisePolicies:DisallowFeature", {feature}
+ );
+ }
+ }
},
// ------------------------------
// public nsIEnterprisePolicies members
// ------------------------------
_status: Ci.nsIEnterprisePolicies.UNINITIALIZED,
set status(val) {
this._status = val;
+ if (val != Ci.nsIEnterprisePolicies.INACTIVE) {
+ Services.ppmm.initialProcessData.policies = {
+ status: val,
+ disallowedFeatures: [],
+ };
+ }
return val;
},
get status() {
return this._status;
},
isAllowed: function BG_sanitize(feature) {
--- a/browser/components/enterprisepolicies/EnterprisePolicies.manifest
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.manifest
@@ -1,3 +1,6 @@
component {ea4e1414-779b-458b-9d1f-d18e8efbc145} EnterprisePolicies.js process=main
contract @mozilla.org/browser/enterprisepolicies;1 {ea4e1414-779b-458b-9d1f-d18e8efbc145} process=main
category app-startup EnterprisePoliciesManager service,@mozilla.org/browser/enterprisepolicies;1 process=main
+
+component {dc6358f8-d167-4566-bf5b-4350b5e6a7a2} EnterprisePoliciesContent.js process=content
+contract @mozilla.org/browser/enterprisepolicies;1 {dc6358f8-d167-4566-bf5b-4350b5e6a7a2} process=content
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
@@ -0,0 +1,77 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cr = Components.results;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+function LOG(s) {
+ Services.console.logStringMessage("$ POLICIES CHILD $: " + s + "\n");
+ dump("% POLICIES CHILD %: " + s + "\n");
+}
+
+// ==== Start XPCOM Boilerplate ==== \\
+
+// Factory object
+const EnterprisePoliciesFactory = {
+ _instance: null,
+ createInstance: function BGSF_createInstance(outer, iid) {
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ return this._instance == null ?
+ this._instance = new EnterprisePoliciesManagerContent() : this._instance;
+ }
+};
+
+// ==== End XPCOM Boilerplate ==== //
+
+
+function EnterprisePoliciesManagerContent() {
+ LOG("STARTING CONSTRUCTOR");
+ let policies = Services.cpmm.initialProcessData.policies;
+ if (policies) {
+ this._status = policies.status;
+ // make a copy of the array so that we can keep adding to it
+ // in a way that is not confusing.
+ this._disallowedFeatures = policies.disallowedFeatures.slice();
+ }
+
+ Services.cpmm.addMessageListener("EnterprisePolicies:DisallowFeature", this);
+}
+
+EnterprisePoliciesManagerContent.prototype = {
+ // for XPCOM
+ classID: Components.ID("{dc6358f8-d167-4566-bf5b-4350b5e6a7a2}"),
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener,
+ Ci.nsIEnterprisePolicies]),
+
+ // redefine the default factory for XPCOMUtils
+ _xpcom_factory: EnterprisePoliciesFactory,
+
+ _status: Ci.nsIEnterprisePolicies.INACTIVE,
+
+ _disallowedFeatures: [],
+
+ receiveMessage({name, data}) {
+ LOG(`received message: {name}, with data.feature: ${data.feature}`);
+ if (name == "EnterprisePolicies:DisallowFeature") {
+ this._disallowedFeatures.push(data.feature);
+ }
+ },
+
+ get status() {
+ return this._status;
+ },
+
+ isAllowed(feature) {
+ return !this._disallowedFeatures.includes(feature);
+ }
+};
+
+var components = [EnterprisePoliciesManagerContent];
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -17,19 +17,19 @@ this.EXPORTED_SYMBOLS = ["Policies", "Po
this.PoliciesValidator = {
validateAndParseParameters() {
return true;
}
}
this.Policies = {
"block_about_config": {
- onProfileAfterChange(manager, param) {
+ onBeforeUIStartup(manager, param) {
if (param == true) {
- manager.disallowFeature("about:config");
+ manager.disallowFeature("about:config", true);
}
}
},
"block_devtools": {
onProfileAfterChange(manager, param) {
if (param == true) {
manager.disallowFeature("devtools");
--- a/browser/components/enterprisepolicies/moz.build
+++ b/browser/components/enterprisepolicies/moz.build
@@ -16,16 +16,17 @@ XPIDL_SOURCES += [
'nsIEnterprisePolicies.idl',
]
XPIDL_MODULE = 'enterprisepolicies'
EXTRA_COMPONENTS += [
'EnterprisePolicies.js',
'EnterprisePolicies.manifest',
+ 'EnterprisePoliciesContent.js',
]
EXTRA_JS_MODULES.policies += [
'Policies.jsm',
]
#BROWSER_CHROME_MANIFESTS += [
# 'tests/browser/browser.ini'