commit e6a1a7448dfb70352cf1200027fc3d70b2ad6543
parent 8293a2ae485dd25a16a4987a2cd92986dee19992
Author: Jared Hirsch <ohai@6a68.net>
Date: Wed, 5 Nov 2025 18:52:49 +0000
Bug 1997455 - Add a pref so forced-colors theme override can optionally be disabled r=emilio,rpl
Differential Revision: https://phabricator.services.mozilla.com/D271323
Diffstat:
5 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js
@@ -905,6 +905,10 @@ pref("browser.dataFeatureRecommendations.enabled", false);
// sets darkTheme data.
pref("browser.theme.dark-private-windows", true);
+// Whether to override themes in forced-colors mode and just use the
+// system theme and forced-colors palette to style the chrome.
+pref("browser.theme.forced-colors-override.enabled", true);
+
// Pref to control whether or not Private Browsing windows show up
// as separate icons in the Windows taskbar.
pref("browser.privateWindowSeparation.enabled", true);
diff --git a/toolkit/modules/LightweightThemeConsumer.sys.mjs b/toolkit/modules/LightweightThemeConsumer.sys.mjs
@@ -222,6 +222,14 @@ export function LightweightThemeConsumer(aDocument) {
this._win = aDocument.defaultView;
this._winId = this._win.docShell.outerWindowID;
+ XPCOMUtils.defineLazyPreferenceGetter(
+ this,
+ "FORCED_COLORS_OVERRIDE_ENABLED",
+ "browser.theme.forced-colors-override.enabled",
+ true,
+ () => this._update(this._lastData)
+ );
+
Services.obs.addObserver(this, "lightweight-theme-styling-update");
this.darkThemeMediaQuery = this._win.matchMedia("(-moz-system-dark-theme)");
@@ -309,7 +317,10 @@ LightweightThemeConsumer.prototype = {
})();
let theme = useDarkTheme ? themeData.darkTheme : themeData.theme;
- if (!theme || this.forcedColorsMediaQuery?.matches) {
+ let forcedColorsThemeOverride =
+ this.FORCED_COLORS_OVERRIDE_ENABLED &&
+ this.forcedColorsMediaQuery?.matches;
+ if (!theme || forcedColorsThemeOverride) {
theme = { id: DEFAULT_THEME_ID };
}
let builtinThemeConfig = lazy.BuiltInThemeConfig.get(theme.id);
diff --git a/toolkit/mozapps/extensions/content/aboutaddons.js b/toolkit/mozapps/extensions/content/aboutaddons.js
@@ -57,6 +57,12 @@ XPCOMUtils.defineLazyPreferenceGetter(
"extensions.dataCollectionPermissions.enabled",
false
);
+XPCOMUtils.defineLazyPreferenceGetter(
+ this,
+ "FORCED_COLORS_OVERRIDE_ENABLED",
+ "browser.theme.forced-colors-override.enabled",
+ true
+);
const PLUGIN_ICON_URL = "chrome://global/skin/icons/plugin.svg";
const EXTENSION_ICON_URL =
@@ -4172,8 +4178,10 @@ class ForcedColorsNotice extends HTMLElement {
}
render() {
- this.hidden = !this.forcedColorsMediaQuery.matches;
- if (!this.hidden && this.childElementCount == 0) {
+ let shouldShowNotice =
+ FORCED_COLORS_OVERRIDE_ENABLED && this.forcedColorsMediaQuery.matches;
+ this.hidden = !shouldShowNotice;
+ if (shouldShowNotice && this.childElementCount == 0) {
this.appendChild(importTemplate("forced-colors-notice"));
}
}
diff --git a/toolkit/mozapps/extensions/test/browser/browser_html_forced_colors_notice.js b/toolkit/mozapps/extensions/test/browser/browser_html_forced_colors_notice.js
@@ -63,5 +63,17 @@ add_task(async function test_aboutaddons_forced_colors_notice() {
});
await assertForcedColorsNotice(win, { expectVisible: false });
+ info("Test that forced-colors override is disabled when the pref is false");
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["browser.theme.forced-colors-override.enabled", false],
+ ["ui.useAccessibilityTheme", 1],
+ ],
+ });
+ await closeView(win);
+ win = await loadInitialView("theme");
+ await assertForcedColorsNotice(win, { expectVisible: false });
+ await SpecialPowers.popPrefEnv();
+
await closeView(win);
});
diff --git a/toolkit/mozapps/extensions/test/browser/browser_theme_forced_colors.js b/toolkit/mozapps/extensions/test/browser/browser_theme_forced_colors.js
@@ -46,5 +46,18 @@ add_task(async function test_forced_colors_themes() {
"should be in forced-colors mode"
);
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.theme.forced-colors-override.enabled", false]],
+ });
+
+ Assert.ok(
+ docEl.hasAttribute("lwtheme"),
+ "when forced-colors override is disabled, LWT attribute should be set"
+ );
+ Assert.ok(
+ window.matchMedia("(forced-colors)").matches,
+ "when forced-colors override is disabled, window should still be in forced-colors mode"
+ );
+
await theme.unload();
});