Bug 1502096 - Make peviewing and selecting the default theme work consistently in Dark mode. r=spohl, a=RyanVM
authorDão Gottwald <dao@mozilla.com>
Thu, 25 Oct 2018 21:43:35 +0000
changeset 500900 869a690e1c28c9baf1700cbe0100d58b282b008e
parent 500899 52d060761f0c9edacbcc7476b7d6ec919d9ce986
child 500901 442e20f46b5d670b0dafb158072dadde45d58e23
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, RyanVM
bugs1502096
milestone64.0
Bug 1502096 - Make peviewing and selecting the default theme work consistently in Dark mode. r=spohl, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D9861
toolkit/mozapps/extensions/LightweightThemeManager.jsm
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -120,26 +120,17 @@ var LightweightThemeManager = {
     let data = null;
     if (selectedThemeID) {
       data = this.getUsedTheme(selectedThemeID);
     }
     return data;
   },
 
   get currentThemeForDisplay() {
-    var data = this.currentTheme;
-
-    if (!data || data.id == DEFAULT_THEME_ID) {
-      if (_fallbackThemeData) {
-        return _fallbackThemeData;
-      }
-      if (_defaultThemeIsInDarkMode && _defaultDarkThemeID) {
-        return this.getUsedTheme(_defaultDarkThemeID);
-      }
-    }
+    var data = _substituteDefaulThemeIfNeeded(this.currentTheme);
 
     if (data && PERSIST_ENABLED) {
       for (let key in PERSIST_FILES) {
         try {
           if (data[key] && _prefs.getBoolPref("persisted." + key))
             data[key] = _getLocalImageURI(PERSIST_FILES[key]).spec
                         + "?" + data.id + ";" + _version(data);
         } catch (e) {}
@@ -216,16 +207,18 @@ var LightweightThemeManager = {
 
   clearBuiltInThemes() {
     for (let id of this._builtInThemes.keys()) {
       this.forgetBuiltInTheme(id);
     }
   },
 
   previewTheme(aData) {
+    aData = _substituteDefaulThemeIfNeeded(aData);
+
     let cancel = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
     cancel.data = false;
     Services.obs.notifyObservers(cancel, "lightweight-theme-preview-requested",
                                  JSON.stringify(aData));
     if (cancel.data)
       return;
 
     if (_previewTimer)
@@ -895,16 +888,29 @@ function _updateUsedThemes(aList) {
   Services.obs.notifyObservers(null, "lightweight-theme-list-changed");
 }
 
 function _notifyWindows(aThemeData) {
   Services.obs.notifyObservers(null, "lightweight-theme-styling-update",
                                JSON.stringify({theme: aThemeData}));
 }
 
+function _substituteDefaulThemeIfNeeded(aThemeData) {
+  if (!aThemeData || aThemeData.id == DEFAULT_THEME_ID) {
+    if (_fallbackThemeData) {
+      return _fallbackThemeData;
+    }
+    if (_defaultThemeIsInDarkMode && _defaultDarkThemeID) {
+      return LightweightThemeManager.getUsedTheme(_defaultDarkThemeID);
+    }
+  }
+
+  return aThemeData;
+}
+
 var _previewTimer;
 var _previewTimerCallback = {
   notify() {
     LightweightThemeManager.resetPreview();
   },
 };
 
 /**