tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6273b2348e5132cd5f3847819107d0acbac51fec
parent f98572c5fa769d3a8d4e6948803f2e78fdb5b2e6
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Wed,  8 Oct 2025 19:13:32 +0000

Bug 1993056 - Move light/dark theme config to BuiltInThemeConfig. r=desktop-theme-reviewers,dao

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

Diffstat:
Mbrowser/themes/BuiltInThemeConfig.sys.mjs | 18++++++++++++------
Mbrowser/themes/addons/dark/manifest.json | 6+++++-
Mbrowser/themes/addons/light/manifest.json | 6+++++-
Mtoolkit/modules/LightweightThemeConsumer.sys.mjs | 26++++++++++----------------
4 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/browser/themes/BuiltInThemeConfig.sys.mjs b/browser/themes/BuiltInThemeConfig.sys.mjs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * A Map of themes built in to the browser, alongwith a Map of collections those themes belong to. Params for the objects contained + * A Map of themes built in to the browser. Params for the objects contained * within the map: * * @param {string} id @@ -12,11 +12,13 @@ * The theme add-on's semantic version, as defined in its manifest. * @param {string} path * Path to the add-on files. - * @param {string} [expiry] - * Date in YYYY-MM-DD format. Optional. If defined, the themes in the collection can no longer be - * used after this date, unless the user has permission to retain it. - * @param {string} [collection] - * The collection id that the theme is a part of. Optional. + * @param {boolean} inApp + * Optional, whether the theme uses the app's CSS, just forcing it to a + * particular color scheme or variant. + * @param {boolean} nonNative + * Whether this inApp theme should force the native theme, but with + * non-native appearance. See Document.forceNonNativeTheme and the + * (-moz-native-theme) media query. */ export const BuiltInThemeConfig = new Map([ [ @@ -24,6 +26,8 @@ export const BuiltInThemeConfig = new Map([ { version: "1.3.4", path: "resource://builtin-themes/light/", + inApp: true, + nonNative: true, }, ], [ @@ -31,6 +35,8 @@ export const BuiltInThemeConfig = new Map([ { version: "1.3.4", path: "resource://builtin-themes/dark/", + inApp: true, + nonNative: true, }, ], [ diff --git a/browser/themes/addons/dark/manifest.json b/browser/themes/addons/dark/manifest.json @@ -13,5 +13,9 @@ "version": "1.3.4", "icons": { "32": "icon.svg" }, - "theme": {} + "theme": { + "properties": { + "color_scheme": "dark" + } + } } diff --git a/browser/themes/addons/light/manifest.json b/browser/themes/addons/light/manifest.json @@ -13,5 +13,9 @@ "version": "1.3.4", "icons": { "32": "icon.svg" }, - "theme": {} + "theme": { + "properties": { + "color_scheme": "light" + } + } } diff --git a/toolkit/modules/LightweightThemeConsumer.sys.mjs b/toolkit/modules/LightweightThemeConsumer.sys.mjs @@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, { PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", ThemeContentPropertyList: "resource:///modules/ThemeVariableMap.sys.mjs", ThemeVariableMap: "resource:///modules/ThemeVariableMap.sys.mjs", + BuiltInThemeConfig: "resource:///modules/BuiltInThemeConfig.sys.mjs", }); // Whether the content and chrome areas should always use the same color @@ -23,17 +24,6 @@ XPCOMUtils.defineLazyPreferenceGetter( ); const DEFAULT_THEME_ID = "default-theme@mozilla.org"; -const kDefaultThemes = { - [DEFAULT_THEME_ID]: {}, - "firefox-compact-light@mozilla.org": { - colorScheme: "light", - forceNonNative: true, - }, - "firefox-compact-dark@mozilla.org": { - colorScheme: "dark", - forceNonNative: true, - }, -}; const toolkitVariableMap = [ [ @@ -317,14 +307,18 @@ LightweightThemeConsumer.prototype = { if (!theme) { theme = { id: DEFAULT_THEME_ID }; } - let builtinThemeConfig = kDefaultThemes[theme.id]; - let hasTheme = !builtinThemeConfig; + let builtinThemeConfig = lazy.BuiltInThemeConfig.get(theme.id); + let hasTheme = theme.id != DEFAULT_THEME_ID && !builtinThemeConfig?.inApp; let colorSchemeOverride = (() => { if (useDarkTheme || themeData.darkTheme) { return useDarkTheme ? "dark" : "light"; } - if (builtinThemeConfig?.colorScheme) { - return builtinThemeConfig.colorScheme; + if (builtinThemeConfig && theme.color_scheme) { + // TODO(emilio): Seems we could do this for all themes, (not just + // built-ins, and taking care of the auto/system values) and it'd + // be the right thing to do for per-window themes (but then we'd need + // to fix up the content theme selection too). + return theme.color_scheme; } // If not, reset the color scheme override field. This is required to reset // the color scheme on theme switch. @@ -338,7 +332,7 @@ LightweightThemeConsumer.prototype = { this._win.browsingContext.prefersColorSchemeOverride = colorSchemeOverride; } - this._doc.forceNonNativeTheme = !!builtinThemeConfig?.forceNonNative; + this._doc.forceNonNativeTheme = !!builtinThemeConfig?.nonNative; let root = this._doc.documentElement; root.toggleAttribute("lwtheme-image", !!(hasTheme && theme.headerURL)); this._setExperiment(hasTheme, themeData.experiment, theme.experimental);