From 198804c3dbdcc362453b32f25b145570c908ecbb Mon Sep 17 00:00:00 2001 From: Mike Kaply Date: Tue, 22 Jun 2021 16:32:52 +0000 Subject: [PATCH] Bug 1714428 - Add support for accessing color management prefs via WebExtensions. r=mixedpuppy,jaws Differential Revision: https://phabricator.services.mozilla.com/D116769 --- .../extensions/parent/ext-browserSettings.js | 50 +++++++++++++++++++ .../extensions/schemas/browser_settings.json | 21 ++++++++ .../test/xpcshell/test_ext_browserSettings.js | 23 ++++++++- 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/toolkit/components/extensions/parent/ext-browserSettings.js b/toolkit/components/extensions/parent/ext-browserSettings.js index 429bb33fb2a7..30a2c35b687e 100644 --- a/toolkit/components/extensions/parent/ext-browserSettings.js +++ b/toolkit/components/extensions/parent/ext-browserSettings.js @@ -61,6 +61,31 @@ ExtensionPreferencesManager.addSetting("closeTabsByDoubleClick", { }, }); +ExtensionPreferencesManager.addSetting("colorManagement.mode", { + permission: "browserSettings", + prefNames: ["gfx.color_management.mode"], + + setCallback(value) { + switch (value) { + case "off": + return { [this.prefNames[0]]: 0 }; + case "full": + return { [this.prefNames[0]]: 1 }; + case "tagged_only": + return { [this.prefNames[0]]: 2 }; + } + }, +}); + +ExtensionPreferencesManager.addSetting("colorManagement.useNativeSRGB", { + permission: "browserSettings", + prefNames: ["gfx.color_management.native_srgb"], + + setCallback(value) { + return { [this.prefNames[0]]: value }; + }, +}); + ExtensionPreferencesManager.addSetting("contextMenuShowEvent", { permission: "browserSettings", prefNames: ["ui.context_menus.after_mouseup"], @@ -439,6 +464,31 @@ this.browserSettings = class extends ExtensionAPI { return Services.prefs.getBoolPref("browser.zoom.siteSpecific"); }, }), + colorManagement: { + mode: getSettingsAPI({ + context, + name: "colorManagement.mode", + callback() { + switch (Services.prefs.getIntPref("gfx.color_management.mode")) { + case 0: + return "off"; + case 1: + return "full"; + case 2: + return "tagged_only"; + } + }, + }), + useNativeSRGB: getSettingsAPI({ + context, + name: "colorManagement.useNativeSRGB", + callback() { + return Services.prefs.getBoolPref( + "gfx.color_management.native_srgb" + ); + }, + }), + }, }, }; } diff --git a/toolkit/components/extensions/schemas/browser_settings.json b/toolkit/components/extensions/schemas/browser_settings.json index 5efb1c41b2bd..a773826b50f8 100644 --- a/toolkit/components/extensions/schemas/browser_settings.json +++ b/toolkit/components/extensions/schemas/browser_settings.json @@ -35,6 +35,12 @@ "type": "string", "enum": ["mouseup", "mousedown"], "description": "After which mouse event context menus should popup." + }, + { + "id": "ColorManagementMode", + "type": "string", + "enum": ["off", "full", "tagged_only"], + "description": "Color management mode." } ], "properties": { @@ -108,5 +114,20 @@ "description": "This boolean setting controls whether zoom is applied on a per-site basis or to the current tab only. If privacy.resistFingerprinting is true, this setting has no effect and zoom is applied to the current tab only." } } + }, + { + "namespace": "browserSettings.colorManagement", + "description": "Use the browserSettings.colorManagement API to query and set items related to color management.", + "permissions": ["browserSettings"], + "properties": { + "mode": { + "$ref": "types.Setting", + "description": "This setting controls the mode used for color management and must be a string from $(ref:browserSettings.ColorManagementMode)" + }, + "useNativeSRGB": { + "$ref": "types.Setting", + "description": "This boolean setting controls whether or not native sRGB color management is used." + } + } } ] diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js b/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js index 7e162961ba3f..e951e92d9ba8 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js @@ -56,7 +56,11 @@ add_task(async function test_browser_settings() { async function background() { let listeners = new Set([]); browser.test.onMessage.addListener(async (msg, apiName, value) => { - let apiObj = browser.browserSettings[apiName]; + let apiObj = browser.browserSettings; + let apiNameSplit = apiName.split("."); + for (let apiPart of apiNameSplit) { + apiObj = apiObj[apiPart]; + } if (msg == "get") { browser.test.sendMessage("settingData", await apiObj.get({})); return; @@ -288,6 +292,23 @@ add_task(async function test_browser_settings() { "browser.zoom.siteSpecific": false, }); + await testSetting("colorManagement.mode", "off", { + "gfx.color_management.mode": 0, + }); + await testSetting("colorManagement.mode", "full", { + "gfx.color_management.mode": 1, + }); + await testSetting("colorManagement.mode", "tagged_only", { + "gfx.color_management.mode": 2, + }); + + await testSetting("colorManagement.useNativeSRGB", false, { + "gfx.color_management.native_srgb": false, + }); + await testSetting("colorManagement.useNativeSRGB", true, { + "gfx.color_management.native_srgb": true, + }); + await extension.unload(); await promiseShutdownManager(); });