Commit 8002a5b1 authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1230802 - Add support for setting chrome.storage.managed via enterprise...

Bug 1230802 - Add support for setting chrome.storage.managed via enterprise policy. r=Felipe,zombie,flod

Differential Revision: https://phabricator.services.mozilla.com/D21470

--HG--
extra : moz-landing-system : lando
parent 3061bc35
......@@ -286,10 +286,23 @@ EnterprisePoliciesManager.prototype = {
getSupportMenu() {
return SupportMenu;
},
setExtensionPolicies(extensionPolicies) {
ExtensionPolicies = extensionPolicies;
},
getExtensionPolicy(extensionID) {
if (ExtensionPolicies &&
extensionID in ExtensionPolicies) {
return ExtensionPolicies[extensionID];
}
return null;
},
};
let DisallowedFeatures = {};
let SupportMenu = null;
let ExtensionPolicies = null;
/**
* areEnterpriseOnlyPoliciesAllowed
......
......@@ -66,6 +66,12 @@ var EXPORTED_SYMBOLS = ["Policies"];
* The callbacks will be bound to their parent policy object.
*/
var Policies = {
"3rdparty": {
onBeforeAddons(manager, param) {
manager.setExtensionPolicies(param.Extensions);
},
},
"AppUpdateURL": {
onBeforeAddons(manager, param) {
setDefaultPref("app.update.url", param.href);
......
......@@ -2,6 +2,21 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"3rdparty": {
"type": "object",
"properties": {
"Extensions" : {
"type": "object",
"patternProperties": {
"^.*$": {
"type": "JSON"
}
}
}
}
},
"AppUpdateURL": {
"type": "URL"
},
......
......@@ -25,6 +25,7 @@ skip-if = os != 'mac'
[browser_policies_setAndLockPref_API.js]
[browser_policies_simple_pref_policies.js]
[browser_policies_sorted_alphabetically.js]
[browser_policy_3rdparty.js]
[browser_policy_app_update.js]
[browser_policy_app_update_URL.js]
[browser_policy_block_about_addons.js]
......
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function setup() {
await setupPolicyEngineWithJson({
"policies": {
"3rdparty": {
"Extensions": {
"3rdparty-policy@mozilla.com": {
"string": "value",
},
},
},
},
});
let extensionPolicy = Services.policies.getExtensionPolicy("3rdparty-policy@mozilla.com");
Assert.deepEqual(extensionPolicy, {"string": "value"});
});
......@@ -9,6 +9,8 @@
## These are short descriptions for individual policies, to be displayed
## in the documentation section in about:policies.
policy-3rdparty = Set policies that WebExtensions can access via chrome.storage.managed.
policy-AppUpdateURL = Set custom app update URL.
policy-Authentication = Configure integrated authentication for websites that support it.
......
......@@ -30,4 +30,11 @@ interface nsIEnterprisePolicies : nsISupports
* @returns A JS object that contains the url and label or null.
*/
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);
};
......@@ -26,6 +26,10 @@ const enforceNoTemporaryAddon = extensionId => {
const managedStorage = new WeakMap();
const lookupManagedStorage = async (extensionId, context) => {
let extensionPolicy = Services.policies.getExtensionPolicy(extensionId);
if (extensionPolicy) {
return ExtensionStorage._serializableMap(extensionPolicy);
}
let info = await NativeManifests.lookupManifest("storage", extensionId, context);
if (info) {
return ExtensionStorage._serializableMap(info.manifest.data);
......
"use strict";
const PREF_DISABLE_SECURITY = ("security.turn_off_all_security_so_that_" +
"viruses_can_take_over_this_computer");
const {EnterprisePolicyTesting} = ChromeUtils.import("resource://testing-common/EnterprisePolicyTesting.jsm");
// Setting PREF_DISABLE_SECURITY tells the policy engine that we are in testing
// mode and enables restarting the policy engine without restarting the browser.
Services.prefs.setBoolPref(PREF_DISABLE_SECURITY, true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref(PREF_DISABLE_SECURITY);
});
// Load policy engine
Services.policies; // eslint-disable-line no-unused-expressions
add_task(async function test_storage_managed_policy() {
await ExtensionTestUtils.startAddonManager();
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
"policies": {
"3rdparty": {
"Extensions": {
"test-storage-managed-policy@mozilla.com": {
"string": "value",
},
},
},
},
});
let extension = ExtensionTestUtils.loadExtension({
manifest: {
applications: {gecko: {id: "test-storage-managed-policy@mozilla.com"}},
permissions: ["storage"],
},
async background() {
let str = await browser.storage.managed.get("string");
browser.test.sendMessage("results", str);
},
});
await extension.startup();
deepEqual(await extension.awaitMessage("results"), {"string": "value"});
await extension.unload();
});
......@@ -116,6 +116,8 @@ skip-if = os == "android" && debug
skip-if = os == "android" && debug
[test_ext_storage_managed.js]
skip-if = os == "android"
[test_ext_storage_managed_policy.js]
skip-if = os == "android"
[test_ext_storage_sync.js]
head = head.js head_sync.js
skip-if = appname == "thunderbird" || os == "android"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment