Bug 1428922 - Implement helper function to support various permissions-type policies, and use it to implement the Flash Plugin policy. r=mystor
MozReview-Commit-ID: xFefBXBwo2
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -20,16 +20,20 @@ XPCOMUtils.defineLazyGetter(this, "log",
prefix: "Policies.jsm",
// tip: set maxLogLevel to "debug" and use log.debug() to create detailed
// messages during development. See LOG_LEVELS in Console.jsm for details.
maxLogLevel: "error",
maxLogLevelPref: PREF_LOGLEVEL,
});
});
+XPCOMUtils.defineLazyModuleGetters(this, {
+ PermissionPolicies: "resource:///modules/policies/PermissionPolicies.jsm",
+});
+
this.EXPORTED_SYMBOLS = ["Policies", "PoliciesValidator"];
this.PoliciesValidator = {
validateAndParseParameters(param, properties) {
return validateAndParseParamRecursive(param, properties);
}
};
@@ -54,16 +58,22 @@ this.Policies = {
"bookmarks_on_menu": {
onProfileAfterChange(manager, param) {
log.debug("Bookmarks to add: ");
for (let bookmark of param) {
log.debug(" -> " + bookmark.spec);
}
}
},
+
+ "flash_plugin": {
+ onBeforeUIStartup(manager, param) {
+ PermissionPolicies.addAllowDenyPermissions("plugin:flash", param.allow, param.block);
+ }
+ },
};
function validateAndParseParamRecursive(param, properties) {
if (properties.enum) {
if (properties.enum.includes(param)) {
return [true, param];
}
return [false, null];
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/helpers/PermissionPolicies.jsm
@@ -0,0 +1,39 @@
+/* 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/. */
+
+"use strict";
+
+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");
+
+this.EXPORTED_SYMBOLS = ["PermissionPolicies"];
+
+this.PermissionPolicies = {
+ addAllowDenyPermissions(permissionName, allowList, blockList) {
+ allowList = allowList || [];
+ blockList = blockList || [];
+
+ for (let origin of allowList) {
+ this._setPermission(origin,
+ permissionName,
+ Ci.nsIPermissionManager.ALLOW_ACTION);
+ }
+
+ for (let origin of blockList) {
+ this._setPermission(origin,
+ permissionName,
+ Ci.nsIPermissionManager.DENY_ACTION);
+ }
+ },
+
+ _setPermission(uri, name, value) {
+ Services.perms.add(uri, name, value,
+ Ci.nsIPermissionManager.EXPIRE_POLICY);
+ },
+};
--- a/browser/components/enterprisepolicies/helpers/moz.build
+++ b/browser/components/enterprisepolicies/helpers/moz.build
@@ -1,8 +1,12 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
with Files("**"):
BUG_COMPONENT = ("Firefox", "Enterprise Policies")
+
+EXTRA_JS_MODULES.policies += [
+ 'PermissionPolicies.jsm',
+]
--- a/browser/components/enterprisepolicies/schemas/policies.json
+++ b/browser/components/enterprisepolicies/schemas/policies.json
@@ -22,11 +22,33 @@
"description": "Adds a set of bookmarks to the Bookmarks Menu.",
"first_available": "59.0",
"run_on_modified": true,
"type": "array",
"items": {
"type": "URL"
}
+ },
+
+ "flash_plugin": {
+ "description": "Allow or deny flash plugin usage.",
+ "first_available": "60.0",
+
+ "type": "object",
+ "properties": {
+ "allow": {
+ "type": "array",
+ "items": {
+ "type": "origin"
+ }
+ },
+
+ "block": {
+ "type": "array",
+ "items": {
+ "type": "origin"
+ }
+ }
+ }
}
}
}