Bug 1476970 - Port desktop LightweightConsumer.jsm changes to Android. r=nalexander draft
authorTim Nguyen <ntim.bugs@gmail.com>
Thu, 26 Jul 2018 10:39:40 +0100
changeset 822931 18392e1823d536020e5615033bdbbea83c71b224
parent 821963 1e5fa52a612e8985e12212d1950a732954e00e45
push id117534
push userbmo:ntim.bugs@gmail.com
push dateThu, 26 Jul 2018 12:29:07 +0000
reviewersnalexander
bugs1476970
milestone63.0a1
Bug 1476970 - Port desktop LightweightConsumer.jsm changes to Android. r=nalexander MozReview-Commit-ID: 6zeneRwPeI4
mobile/android/modules/LightweightThemeConsumer.jsm
toolkit/modules/LightweightThemeConsumer.jsm
--- 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) {