fune/browser/base/content/browser-compacttheme.js
Jan Henning 4aeb4f5c39 Bug 1429488 - Part 5: Support persisting moz-extension resources. r=Gijs
Bug 1344926 integrated static themes more closely into the existing infra-
structure for lightweight themes and also intended the static theme's image data
to be persisted to disk as well.

While the headerURL image file is in fact successfully copied out of the
extension archive into the profile, the persist progress listener being used
isn't equipped to properly handle this case and therefore the success callback
is never executed.

As a result
- the callback passed to _persistImages in the LWTManager isn't executed,
  either, although because setting the fallbackThemeData passes in an empty
  callback anyway, no one noticed.
- the persist operation never actually completes, so subsequent calls to
  currentThemeForDisplay() always return the original moz-extension:// image URI
  and never the persisted file from the profile folder.

For Android we definitively require a working callback in order to be able to
forward the fixed-up theme data once the image data has been persisted, so the
persistProgressListener's logic is modified accordingly.
Additionally, because as far as the LWTManager is concerned, WE static themes
are only fallback themes and a call to LWTManager.currentTheme will therefore
never return a WE static theme, the LWTPersister's logic to check whether the
theme, whose files have just been successfully persisted, is still the current
theme, needs to be modified.

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

--HG--
extra : source : 91b2a9224846ef9cc81f1afc9fcfcd1db278644b
extra : histedit_source : d8a47bba3563cb8eb0faf94a7c1f28ba2925d80c
2018-10-22 22:08:01 +02:00

68 lines
1.9 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Enables compacttheme.css when needed.
*/
var CompactTheme = {
get styleSheet() {
delete this.styleSheet;
for (let styleSheet of document.styleSheets) {
if (styleSheet.href == "chrome://browser/skin/compacttheme.css") {
this.styleSheet = styleSheet;
break;
}
}
return this.styleSheet;
},
get isStyleSheetEnabled() {
return this.styleSheet && !this.styleSheet.disabled;
},
get isThemeCurrentlyApplied() {
let theme = LightweightThemeManager.currentThemeWithPersistedData;
return theme && (
theme.id == "firefox-compact-dark@mozilla.org" ||
theme.id == "firefox-compact-light@mozilla.org");
},
init() {
Services.obs.addObserver(this, "lightweight-theme-styling-update");
if (this.isThemeCurrentlyApplied) {
this._toggleStyleSheet(true);
}
},
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")) {
// We are using the theme ID on this object instead of always referencing
// LightweightThemeManager.currentTheme in case this is a preview
this._toggleStyleSheet(true);
} else {
this._toggleStyleSheet(false);
}
}
},
_toggleStyleSheet(enabled) {
let wasEnabled = this.isStyleSheetEnabled;
if (enabled) {
this.styleSheet.disabled = false;
} else if (!enabled && wasEnabled) {
this.styleSheet.disabled = true;
}
},
uninit() {
Services.obs.removeObserver(this, "lightweight-theme-styling-update");
this.styleSheet = null;
},
};