Bug 1476970 - Port desktop LightweightConsumer.jsm changes to Android. r=nalexander
MozReview-Commit-ID: 6zeneRwPeI4
--- a/mobile/android/modules/LightweightThemeConsumer.jsm
+++ b/mobile/android/modules/LightweightThemeConsumer.jsm
@@ -6,41 +6,48 @@ var EXPORTED_SYMBOLS = ["LightweightThem
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.defineModuleGetter(this, "EventDispatcher",
"resource://gre/modules/Messaging.jsm");
+const DEFAULT_THEME_ID = "default-theme@mozilla.org";
+
function LightweightThemeConsumer(aDocument) {
this._doc = aDocument;
Services.obs.addObserver(this, "lightweight-theme-styling-update");
Services.obs.addObserver(this, "lightweight-theme-apply");
this._update(LightweightThemeManager.currentThemeForDisplay);
}
LightweightThemeConsumer.prototype = {
observe: function(aSubject, aTopic, aData) {
- if (aTopic == "lightweight-theme-styling-update")
- this._update(JSON.parse(aData));
- else if (aTopic == "lightweight-theme-apply")
+ if (aTopic == "lightweight-theme-styling-update") {
+ let parsedData = JSON.parse(aData);
+ if (!parsedData) {
+ parsedData = { theme: null };
+ }
+ this._update(parsedData.theme);
+ } else if (aTopic == "lightweight-theme-apply") {
this._update(LightweightThemeManager.currentThemeForDisplay);
+ }
},
destroy: function() {
Services.obs.removeObserver(this, "lightweight-theme-styling-update");
Services.obs.removeObserver(this, "lightweight-theme-apply");
this._doc = null;
},
_update: function(aData) {
- if (!aData)
- aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" };
-
- let active = !!aData.headerURL;
+ let active = aData && aData.id !== DEFAULT_THEME_ID;
+ if (!aData) {
+ aData = {};
+ }
let msg = active ? { type: "LightweightTheme:Update", data: aData } :
{ type: "LightweightTheme:Disable" };
EventDispatcher.instance.sendRequest(msg);
}
};
--- a/toolkit/modules/LightweightThemeConsumer.jsm
+++ b/toolkit/modules/LightweightThemeConsumer.jsm
@@ -182,17 +182,17 @@ LightweightThemeConsumer.prototype = {
},
_update(aData) {
this._lastData = aData;
if (aData) {
aData = LightweightThemeImageOptimizer.optimize(aData, this._win.screen);
}
- let active = this._active = !!aData && aData.id !== DEFAULT_THEME_ID;
+ let active = this._active = aData && aData.id !== DEFAULT_THEME_ID;
if (!aData) {
aData = {};
}
let root = this._doc.documentElement;
if (active && aData.headerURL) {