Bug 1344926 - make sure that WebExtension theme data is persisted across windows when they open and image data is persisted to disk as well. r=mossop

MozReview-Commit-ID: 5UUjajCa8nK

--HG--
extra : rebase_source : 0fe682294bb98aa233e58099c4402fef44c08cde
This commit is contained in:
Mike de Boer 2017-03-14 18:36:18 +01:00
Родитель fed2f97579
Коммит 66407b6bab
3 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -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));

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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");