diff --git a/browser/base/content/browser-compacttheme.js b/browser/base/content/browser-compacttheme.js index ba4169e987ab..38c05b85755b 100644 --- a/browser/base/content/browser-compacttheme.js +++ b/browser/base/content/browser-compacttheme.js @@ -25,11 +25,13 @@ var CompactTheme = { return this.styleSheet && !this.styleSheet.disabled; }, + isCompactTheme(theme) { + return theme && (theme.id == "firefox-compact-dark@mozilla.org" || + theme.id == "firefox-compact-light@mozilla.org"); + }, + get isThemeCurrentlyApplied() { - let theme = LightweightThemeManager.currentThemeWithPersistedData; - return theme && ( - theme.id == "firefox-compact-dark@mozilla.org" || - theme.id == "firefox-compact-light@mozilla.org"); + return this.isCompactTheme(LightweightThemeManager.currentThemeWithFallback); }, init() { @@ -43,9 +45,7 @@ var CompactTheme = { observe(subject, topic, data) { if (topic == "lightweight-theme-styling-update") { let { theme } = JSON.parse(data) || {}; - if (theme && ( - theme.id == "firefox-compact-light@mozilla.org" || - theme.id == "firefox-compact-dark@mozilla.org")) { + if (this.isCompactTheme(theme)) { // We are using the theme ID on this object instead of always referencing // LightweightThemeManager.currentTheme in case this is a preview this._toggleStyleSheet(true); diff --git a/toolkit/mozapps/extensions/LightweightThemeManager.jsm b/toolkit/mozapps/extensions/LightweightThemeManager.jsm index 4af8cda7ee6c..884f2fec4c47 100644 --- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm +++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm @@ -6,13 +6,8 @@ var EXPORTED_SYMBOLS = ["LightweightThemeManager"]; -ChromeUtils.defineModuleGetter(this, "LightweightThemePersister", - "resource://gre/modules/addons/LightweightThemePersister.jsm"); ChromeUtils.defineModuleGetter(this, "LightweightThemeImageOptimizer", "resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm"); -ChromeUtils.defineModuleGetter(this, "AppConstants", - "resource://gre/modules/AppConstants.jsm"); - // 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. @@ -22,10 +17,7 @@ var LightweightThemeManager = { set fallbackThemeData(data) { if (data && Object.getOwnPropertyNames(data).length) { _fallbackThemeData = Object.assign({}, data); - if (LightweightThemePersister.persistEnabled) { - LightweightThemeImageOptimizer.purge(); - _persistImages(_fallbackThemeData, () => {}); - } + LightweightThemeImageOptimizer.purge(); } else { _fallbackThemeData = null; } @@ -43,24 +35,6 @@ var LightweightThemeManager = { return _fallbackThemeData; }, - /* - * Returns the currently active theme, taking the fallback theme into account - * if we'd be using the default theme otherwise. - * - * This will rewrite the theme data to use locally persisted resources if - * available. - * - * Unless you have any special requirements, this is what you normally want - * to use in order to retrieve the currently active theme for use in the UI. - */ - get currentThemeWithPersistedData() { - let data = this.currentThemeWithFallback; - if (data && LightweightThemePersister.persistEnabled) { - data = LightweightThemePersister.getPersistedData(data); - } - return data; - }, - systemThemeChanged() { }, @@ -76,10 +50,3 @@ var LightweightThemeManager = { } }, }; - -function _persistImages(aData, aCallback) { - if (AppConstants.platform != "android") { - // On Android, the LightweightThemeConsumer is responsible for doing this. - LightweightThemePersister.persistImages(aData, aCallback); - } -} diff --git a/toolkit/mozapps/extensions/internal/LightweightThemePersister.jsm b/toolkit/mozapps/extensions/internal/LightweightThemePersister.jsm index 009b6a83c120..1023a513b32b 100644 --- a/toolkit/mozapps/extensions/internal/LightweightThemePersister.jsm +++ b/toolkit/mozapps/extensions/internal/LightweightThemePersister.jsm @@ -6,35 +6,24 @@ var EXPORTED_SYMBOLS = ["LightweightThemePersister"]; -const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); +const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); -ChromeUtils.defineModuleGetter(this, "Services", - "resource://gre/modules/Services.jsm"); - -const PERSIST_ENABLED = true; -const PERSIST_BYPASS_CACHE = false; -const PERSIST_FILES = { - headerURL: "lightweighttheme-header", -}; +let _prefs = Services.prefs.getBranch("lightweightThemes."); ChromeUtils.defineModuleGetter(this, "LightweightThemeManager", "resource://gre/modules/LightweightThemeManager.jsm"); -XPCOMUtils.defineLazyGetter(this, "_prefs", () => { - return Services.prefs.getBranch("lightweightThemes."); -}); +const PERSIST_FILES = { + headerURL: "lightweighttheme-header", +}; var LightweightThemePersister = { - get persistEnabled() { - return PERSIST_ENABLED; - }, - getPersistedData(aData) { for (let key in PERSIST_FILES) { try { if (aData[key] && _prefs.getBoolPref("persisted." + key)) aData[key] = _getLocalImageURI(PERSIST_FILES[key]).spec - + "?" + aData.id + ";" + _version(aData); + + `?${aData.id};${aData.version}`; } catch (e) {} } return aData; @@ -94,10 +83,7 @@ function _persistImage(sourceURL, localFileName, successCallback) { persist.persistFlags = Ci.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES | - Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION | - (PERSIST_BYPASS_CACHE ? - Ci.nsIWebBrowserPersist.PERSIST_FLAGS_BYPASS_CACHE : - Ci.nsIWebBrowserPersist.PERSIST_FLAGS_FROM_CACHE); + Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION; persist.progressListener = new _persistProgressListener(successCallback); @@ -139,10 +125,6 @@ function _getLocalImageURI(localFileName) { return Services.io.newFileURI(localFile); } -function _version(aThemeData) { - return aThemeData.version || ""; -} - function _versionCode(aThemeData) { - return aThemeData.id + "-" + _version(aThemeData); + return `${aThemeData.id}-${aThemeData.version}`; } diff --git a/toolkit/mozapps/extensions/internal/moz.build b/toolkit/mozapps/extensions/internal/moz.build index 6db01bc47dfb..e6adce0800c5 100644 --- a/toolkit/mozapps/extensions/internal/moz.build +++ b/toolkit/mozapps/extensions/internal/moz.build @@ -11,19 +11,21 @@ EXTRA_JS_MODULES.addons += [ 'Content.js', 'GMPProvider.jsm', 'LightweightThemeImageOptimizer.jsm', - 'LightweightThemePersister.jsm', 'ProductAddonChecker.jsm', 'XPIDatabase.jsm', 'XPIInstall.jsm', 'XPIProvider.jsm', ] -TESTING_JS_MODULES += [ - 'AddonTestUtils.jsm', -] - -# Don't ship unused providers on Android -if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android': +if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': + EXTRA_JS_MODULES.addons += [ + 'LightweightThemePersister.jsm', + ] +else: EXTRA_JS_MODULES.addons += [ 'PluginProvider.jsm', ] + +TESTING_JS_MODULES += [ + 'AddonTestUtils.jsm', +]