Bug 1429129 - Add enterprise policy to remove "Set As Desktop Background" context menu option
MozReview-Commit-ID: EdVKcujYUh4
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -446,17 +446,18 @@ nsContextMenu.prototype = {
this.showItem("context-inspect", showInspect);
this.showItem("context-sep-viewsource", shouldShow);
// Set as Desktop background depends on whether an image was clicked on,
// 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)
haveSetDesktopBackground = shell.canSetDesktopBackground;
}
this.showItem("context-setDesktopBackground",
haveSetDesktopBackground && this.onLoadedImage);
@@ -1012,18 +1013,20 @@ nsContextMenu.prototype = {
mm.sendAsyncMessage("ContextMenu:SetAsDesktopBackground", null,
{ target: this.target });
let onMessage = (message) => {
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;
let imageName = message.data.imageName;
// Confirm since it's annoying if you hit this accidentally.
const kDesktopBackgroundURL =
"chrome://browser/content/setDesktopBackground.xul";
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -71,16 +71,24 @@ this.Policies = {
Services.prefs.setBoolPref(PREF_BOOKMARKS_ALREADY_DISPLAYED, true);
} else {
log.debug("Not showing the bookmarks toolbar because it has already been shown.");
}
}
}
},
+ "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);
}
},
"flash_plugin": {
onBeforeUIStartup(manager, param) {
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -21,16 +21,24 @@
"display_bookmarks_toolbar": {
"description": "Causes the bookmarks toolbar to be displayed by default.",
"first_available": "60.0",
"type": "boolean",
"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",
"type": "boolean",
"enum": [true]
},
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -5,17 +5,19 @@ support-files =
head.js
config_dont_check_default_browser.json
config_popups_cookies_addons_flash.json
config_setAndLockPref.json
config_simple_policies.json
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]
[browser_policies_setAndLockPref_API.js]
[browser_policies_simple_policies.js]
[browser_policies_validate_and_parse_API.js]
[browser_policy_default_browser_check.js]
[browser_policy_display_menu.js]
[browser_policy_display_bookmarks.js]
+[browser_policy_block_set_desktop_background.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/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);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/config_block_set_desktop_background.json
@@ -0,0 +1,5 @@
+{
+ "policies": {
+ "block_set_desktop_background": true
+ }
+}