Bug 1542371 - Add basic support for ExtensionSettings policy. r=Felipe

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Michael Kaply 2019-04-11 19:10:49 +00:00
Родитель fdb93637f9
Коммит 2ff9f81d03
6 изменённых файлов: 70 добавлений и 0 удалений

Просмотреть файл

@ -298,11 +298,26 @@ EnterprisePoliciesManager.prototype = {
}
return null;
},
setExtensionSettings(extensionSettings) {
ExtensionSettings = extensionSettings;
},
getExtensionSettings(extensionID) {
let settings = null;
if (extensionID in ExtensionSettings) {
settings = ExtensionSettings[extensionID];
} else if ("*" in ExtensionSettings) {
settings = ExtensionSettings["*"];
}
return settings;
},
};
let DisallowedFeatures = {};
let SupportMenu = null;
let ExtensionPolicies = null;
let ExtensionSettings = null;
/**
* areEnterpriseOnlyPoliciesAllowed

Просмотреть файл

@ -577,6 +577,12 @@ var Policies = {
},
},
"ExtensionSettings": {
onBeforeAddons(manager, param) {
manager.setExtensionSettings(param);
},
},
"ExtensionUpdate": {
onBeforeAddons(manager, param) {
if (!param) {

Просмотреть файл

@ -313,6 +313,20 @@
}
},
"ExtensionSettings": {
"type": "object",
"patternProperties": {
"^.*$": {
"type": "object",
"properties": {
"blocked_install_message": {
"type": "string"
}
}
}
}
},
"ExtensionUpdate": {
"type": "boolean"
},

Просмотреть файл

@ -54,6 +54,7 @@ skip-if = (verify && debug && (os == 'mac'))
[browser_policy_display_bookmarks.js]
[browser_policy_display_menu.js]
[browser_policy_extensions.js]
[browser_policy_extensionsettings.js]
[browser_policy_locale.js]
[browser_policy_override_postupdatepage.js]
[browser_policy_permissions.js]

Просмотреть файл

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_extensionsettings() {
await setupPolicyEngineWithJson({
"policies": {
"ExtensionSettings": {
"extension1@mozilla.com": {
"blocked_install_message": "Extension1 error message.",
},
"*": {
"blocked_install_message": "Generic error message.",
},
},
},
});
let extensionSettings = Services.policies.getExtensionSettings("extension1@mozilla.com");
is(extensionSettings.blocked_install_message, "Extension1 error message.", "Should have extension specific message.");
extensionSettings = Services.policies.getExtensionSettings("extension2@mozilla.com");
is(extensionSettings.blocked_install_message, "Generic error message.", "Should have generic message.");
});

Просмотреть файл

@ -37,4 +37,15 @@ interface nsIEnterprisePolicies : nsISupports
* @returns A JS object that contains the storage or null if unavailable.
*/
jsval getExtensionPolicy(in ACString extensionID);
/**
* Retrieves the ExtensionSettings policy for the given extensionID.
*
* If there is no policy for the extension, it returns the global policy.
*
* If there is no global policy, it returns null.
*
* @returns A JS object that settings or null if unavailable.
*/
jsval getExtensionSettings(in ACString extensionID);
};