Bug 1429129 - Add enterprise policy to remove "Set As Desktop Background" context menu option r=Felipe,Gijs

MozReview-Commit-ID: EdVKcujYUh4

--HG--
extra : rebase_source : 747a24e0181b6c9cfbfeda1ad247d118439ef766
This commit is contained in:
Kirk Steuber 2018-01-29 13:24:26 -08:00
Родитель 9d063bfac8
Коммит fac065190c
6 изменённых файлов: 62 добавлений и 2 удалений

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

@ -451,7 +451,8 @@ nsContextMenu.prototype = {
// and only works if we have a shell service.
var haveSetDesktopBackground = false;
if (AppConstants.HAVE_SHELL_SERVICE) {
if (AppConstants.HAVE_SHELL_SERVICE &&
Services.policies.isAllowed("set_desktop_background")) {
// Only enable Set as Desktop Background if we can get the shell service.
var shell = getShellService();
if (shell)
@ -1017,8 +1018,10 @@ nsContextMenu.prototype = {
mm.removeMessageListener("ContextMenu:SetAsDesktopBackground:Result",
onMessage);
if (message.data.disable)
if (message.data.disable ||
!Services.policies.isAllowed("set_desktop_background")) {
return;
}
let image = document.createElementNS("http://www.w3.org/1999/xhtml", "img");
image.src = message.data.dataUrl;

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

@ -76,6 +76,14 @@ this.Policies = {
}
},
"block_set_desktop_background": {
onBeforeUIStartup(manager, param) {
if (param == true) {
manager.disallowFeature("set_desktop_background", true);
}
}
},
"dont_check_default_browser": {
onBeforeUIStartup(manager, param) {
setAndLockPref("browser.shell.checkDefaultBrowser", false);

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

@ -26,6 +26,14 @@
"enum": [true]
},
"block_set_desktop_background": {
"description": "Prevents usage of the \"Set Image as Desktop Background\" feature.",
"first_available": "60.0",
"type": "boolean",
"enum": [true]
},
"dont_check_default_browser": {
"description": "Don't check for the default browser on startup.",
"first_available": "60.0",

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

@ -10,6 +10,7 @@ support-files =
config_broken_json.json
config_display_menu.json
config_display_bookmarks.json
config_block_set_desktop_background.json
[browser_policies_broken_json.js]
[browser_policies_popups_cookies_addons_flash.js]
@ -19,3 +20,4 @@ support-files =
[browser_policy_default_browser_check.js]
[browser_policy_display_menu.js]
[browser_policy_display_bookmarks.js]
[browser_policy_block_set_desktop_background.js]

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

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function setup() {
await setupPolicyEngineWithJson("config_block_set_desktop_background.json");
});
add_task(async function test_check_set_desktop_background() {
const imageUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gwMDAsTBZbkNwAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAABNElEQVQ4y8WSsU0DURBE3yyWIaAJaqAAN4DPSL6AlIACKIEOyJEgRsIgOOkiInJqgAKowNg7BHdn7MOksNl+zZ//dvbDf5cAiklp22BdVtXdeTEpDYDB9m1VzU6OJuVp2NdEQCaI96fH2YHG4+mDduKYNMYINTcjcGbXzQVDEAphG0k48zUsajIbnAiMIXThpW8EICE0RAK4dvoKg9NIcTiQ589otyHOZLnwqK5nLwBFUZ4igc3iM0d1ff8CMC6mZ6Ihiaqq3gi1aUAnArD00SW1fq5OLBg0ymYmSZsR2/t4e/rGyCLW0sbp3oq+yTYqVgytQWui2FS7XYF7GFprY921T4CNQt8zr47dNzCkIX7y/jBtH+v+RGMQrc828W8pApnZbmEVQp/Ae7BlOy2ttib81/UFc+WRWEbjckIAAAAASUVORK5CYII=";
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, imageUrl, true);
// Right click on the image and wait for the context menu to open
let contextMenu = document.getElementById("contentAreaContextMenu");
let promiseContextMenuOpen = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
await BrowserTestUtils.synthesizeMouse("img", 0, 0,
{
type: "contextmenu",
button: 2,
centered: true
},
gBrowser.selectedBrowser);
await promiseContextMenuOpen;
info("Context Menu Shown");
let buttonElement = document.getElementById("context-setDesktopBackground");
is(buttonElement.hidden, true,
"The \"Set Desktop Background\" context menu element should be hidden");
let promiseContextMenuHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
contextMenu.hidePopup();
await promiseContextMenuHidden;
await BrowserTestUtils.removeTab(tab);
});

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

@ -0,0 +1,5 @@
{
"policies": {
"block_set_desktop_background": true
}
}