зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1525762: Part 3f - Get rid of LWTPersister. r=aswan
Differential Revision: https://phabricator.services.mozilla.com/D24633 --HG-- extra : rebase_source : fda3a73f7fae19bc63ec6df91a82f43c1932a230 extra : histedit_source : 8859fcaef84fca2e7cdf03cefdb322e212c7065d
This commit is contained in:
Родитель
6d78820c90
Коммит
5b06eaa613
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}`;
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
]
|
||||
|
|
Загрузка…
Ссылка в новой задаче