diff --git a/toolkit/components/extensions/ext-theme.js b/toolkit/components/extensions/ext-theme.js index 28380e73d6e3..3c1262efb0b9 100644 --- a/toolkit/components/extensions/ext-theme.js +++ b/toolkit/components/extensions/ext-theme.js @@ -4,6 +4,8 @@ Cu.import("resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Preferences", "resource://gre/modules/Preferences.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager", + "resource://gre/modules/LightweightThemeManager.jsm"); // WeakMap[Extension -> Theme] let themeMap = new WeakMap(); @@ -50,6 +52,7 @@ class Theme { if (this.lwtStyles.headerURL && this.lwtStyles.accentcolor && this.lwtStyles.textcolor) { + LightweightThemeManager.fallbackThemeData = this.lwtStyles; Services.obs.notifyObservers(null, "lightweight-theme-styling-update", JSON.stringify(this.lwtStyles)); @@ -142,6 +145,7 @@ class Theme { for (let icon of ICONS) { lwtStyles.icons[`--${icon}--icon`] = ""; } + LightweightThemeManager.fallbackThemeData = null; Services.obs.notifyObservers(null, "lightweight-theme-styling-update", JSON.stringify(lwtStyles)); diff --git a/toolkit/mozapps/extensions/LightweightThemeManager.jsm b/toolkit/mozapps/extensions/LightweightThemeManager.jsm index 265f2bc195f5..e3e856616c2e 100644 --- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm +++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm @@ -71,6 +71,10 @@ Object.defineProperty(this, "_maxUsedThemes", { var _themeIDBeingEnabled = null; var _themeIDBeingDisabled = null; +// Holds optional fallback theme data that will be returned when no data for an +// active theme can be found. This the case for WebExtension Themes, for example. +var _fallbackThemeData = null; + // Convert from the old storage format (in which the order of usedThemes // was combined with isThemeSelected to determine which theme was selected) // to the new one (where a selectedThemeID determines which theme is selected). @@ -96,6 +100,19 @@ this.LightweightThemeManager = { return "LightweightThemeManager"; }, + set fallbackThemeData(data) { + if (data && Object.getOwnPropertyNames(data).length) { + _fallbackThemeData = Object.assign({}, data); + if (PERSIST_ENABLED) { + LightweightThemeImageOptimizer.purge(); + _persistImages(_fallbackThemeData, () => {}); + } + } else { + _fallbackThemeData = null; + } + return _fallbackThemeData; + }, + // Themes that can be added for an application. They can't be removed, and // will always show up at the top of the list. _builtInThemes: new Map(), @@ -123,6 +140,8 @@ this.LightweightThemeManager = { get currentThemeForDisplay() { var data = this.currentTheme; + if (!data && _fallbackThemeData) + data = _fallbackThemeData; if (data && PERSIST_ENABLED) { for (let key in PERSIST_FILES) { diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index fcee1f3dce6b..aedd6c0293a4 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -7543,7 +7543,7 @@ AddonWrapper.prototype = { } if (addon.inDatabase) { - let theme = isTheme(addon.type) + let theme = isTheme(addon.type); if (theme && val) { if (addon.internalName == XPIProvider.defaultSkin) throw new Error("Cannot disable the default theme");