Backed out changeset 905f054bd2c9 (bug 1550090) for Browser-chrome failure on toolkit/mozapps/extensions/test/browser/browser_webapi_theme.js. CLOSED TREE
authorDorel Luca <dluca@mozilla.com>
Fri, 10 May 2019 20:43:11 +0300
changeset 532245 140d74ec32c931407a18f9dc9128fcc6c2698a51
parent 532244 cacd53838ee6aa12cf3ef1f974704e51a2782150
child 532246 06e683412cfbd40b38c9838f0cdd5fe76019744d
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1550090
milestone68.0a1
backs out905f054bd2c9acc944a626d08e1f4071d45aa2ec
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 905f054bd2c9 (bug 1550090) for Browser-chrome failure on toolkit/mozapps/extensions/test/browser/browser_webapi_theme.js. CLOSED TREE
toolkit/components/extensions/parent/ext-theme.js
toolkit/modules/LightweightThemeConsumer.jsm
--- a/toolkit/components/extensions/parent/ext-theme.js
+++ b/toolkit/components/extensions/parent/ext-theme.js
@@ -40,21 +40,30 @@ class Theme {
     this.extension = extension;
     this.details = details;
     this.darkDetails = darkDetails;
     this.windowId = windowId;
 
     if (startupData && startupData.lwtData) {
       Object.assign(this, startupData);
     } else {
+      // TODO(ntim): clean this in bug 1550090
       this.lwtStyles = {};
-      this.lwtDarkStyles = {};
+      this.lwtDarkStyles = null;
+      if (darkDetails) {
+        this.lwtDarkStyles = {};
+      }
 
       if (experiment) {
         if (extension.experimentsAllowed) {
+          this.lwtStyles.experimental = {
+            colors: {},
+            images: {},
+            properties: {},
+          };
           const {baseURI} = this.extension;
           if (experiment.stylesheet) {
             experiment.stylesheet = baseURI.resolve(experiment.stylesheet);
           }
           this.experiment = experiment;
         } else {
           const {logger} = this.extension;
           logger.warn("This extension is not allowed to run theme experiments");
@@ -77,18 +86,16 @@ class Theme {
       this.loadDetails(this.details, this.lwtStyles);
       if (this.darkDetails) {
         this.loadDetails(this.darkDetails, this.lwtDarkStyles);
       }
 
       this.lwtData = {
         theme: this.lwtStyles,
         darkTheme: this.lwtDarkStyles,
-        id: this.extension.id,
-        version: this.extension.version,
       };
 
       if (this.experiment) {
         this.lwtData.experiment = this.experiment;
       }
 
       this.extension.startupData = {
         lwtData: this.lwtData,
@@ -114,35 +121,29 @@ class Theme {
                                  "lightweight-theme-styling-update");
   }
 
   /**
    * @param {Object} details Details
    * @param {Object} styles Styles object in which to store the colors.
    */
   loadDetails(details, styles) {
-    if (this.experiment) {
-      styles.experimental = {
-        colors: {},
-        images: {},
-        properties: {},
-      };
-    }
-
     if (details.colors) {
       this.loadColors(details.colors, styles);
     }
 
     if (details.images) {
       this.loadImages(details.images, styles);
     }
 
     if (details.properties) {
       this.loadProperties(details.properties, styles);
     }
+
+    this.loadMetadata(this.extension, styles);
   }
 
   /**
    * Helper method for loading colors found in the extension's manifest.
    *
    * @param {Object} colors Dictionary mapping color properties to values.
    * @param {Object} styles Styles object in which to store the colors.
    */
@@ -331,20 +332,31 @@ class Theme {
             logger.warn(`Unrecognized theme property found: properties.${property}`);
           }
           break;
         }
       }
     }
   }
 
+  /**
+   * Helper method for loading extension metadata required by downstream
+   * consumers.
+   *
+   * @param {Object} extension Extension object.
+   * @param {Object} styles Styles object in which to store the colors.
+   */
+  loadMetadata(extension, styles) {
+    styles.id = extension.id;
+    styles.version = extension.version;
+  }
+
   static unload(windowId) {
     let lwtData = {
-      theme: {},
-      darkTheme: {},
+      theme: null,
     };
 
     if (windowId) {
       lwtData.window = getWinUtils(windowTracker.getWindow(windowId)).outerWindowID;
       windowOverrides.set(windowId, emptyTheme);
     } else {
       windowOverrides.clear();
       defaultTheme = emptyTheme;
--- a/toolkit/modules/LightweightThemeConsumer.jsm
+++ b/toolkit/modules/LightweightThemeConsumer.jsm
@@ -184,49 +184,53 @@ LightweightThemeConsumer.prototype = {
   get darkMode() {
     return this.darkThemeMediaQuery && this.darkThemeMediaQuery.matches;
   },
 
   _update(themeData) {
     this._lastData = themeData;
 
     let theme = themeData.theme;
-    if (Object.keys(themeData.darkTheme).length && this.darkMode) {
+    if (themeData.darkTheme && this.darkMode) {
       theme = themeData.darkTheme;
     }
+    if (!theme) {
+      theme = { id: DEFAULT_THEME_ID };
+    }
 
     let active = this._active = Object.keys(theme).length;
 
     let root = this._doc.documentElement;
 
     if (active && theme.headerURL) {
       root.setAttribute("lwtheme-image", "true");
     } else {
       root.removeAttribute("lwtheme-image");
     }
 
+    this._setExperiment(active, themeData.experiment, theme.experimental);
+
     if (theme.headerImage) {
       this._doc.mozSetImageElement("lwt-header-image", theme.headerImage);
       root.style.setProperty("--lwt-header-image", "-moz-element(#lwt-header-image)");
     } else {
       this._doc.mozSetImageElement("lwt-header-image", null);
       root.style.removeProperty("--lwt-header-image");
     }
 
     _setImage(root, active, "--lwt-additional-images", theme.additionalBackgrounds);
     _setProperties(root, active, theme);
-    this._setExperiment(active, themeData.experiment, theme.experimental);
 
-    if (active) {
+    if (theme.id != DEFAULT_THEME_ID || this.darkMode) {
       root.setAttribute("lwtheme", "true");
     } else {
       root.removeAttribute("lwtheme");
       root.removeAttribute("lwthemetextcolor");
     }
-    if (themeData.id == DEFAULT_THEME_ID && this.darkMode) {
+    if (theme.id == DEFAULT_THEME_ID && this.darkMode) {
       root.setAttribute("lwt-default-theme-in-dark-mode", "true");
     } else {
       root.removeAttribute("lwt-default-theme-in-dark-mode");
     }
 
     let contentThemeData = _getContentProperties(this._doc, active, theme);
     Services.ppmm.sharedData.set(`theme/${this._winId}`, contentThemeData);
   },