Bug 1005098 - don't update titlebar attributes before the window has been activated, r?MattN draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 12 Jan 2016 16:57:20 +0000
changeset 320876 42c7244b6dd6fa3c6dd79cfa1c4fd3fe6a2edb56
parent 320820 eae9f44f7444407a28ab3b876032eceebe19310c
child 512840 d86fd977d0f7d9af40e90603f9b5401b0deffe5e
push id9313
push usergijskruitbosch@gmail.com
push dateTue, 12 Jan 2016 18:32:34 +0000
reviewersMattN
bugs1005098
milestone46.0a1
Bug 1005098 - don't update titlebar attributes before the window has been activated, r?MattN
browser/base/content/browser-tabsintitlebar.js
--- a/browser/base/content/browser-tabsintitlebar.js
+++ b/browser/base/content/browser-tabsintitlebar.js
@@ -74,16 +74,17 @@ var TabsInTitlebar = {
       }
     }
   },
 
   _initialized: false,
   _disallowed: {},
   _prefName: "browser.tabs.drawInTitlebar",
   _lastSizeMode: null,
+  haveUpdatedTitlebarDisplay: false,
 
   _readPref: function () {
     this.allowedBy("pref",
                    Services.prefs.getBoolPref(this._prefName));
   },
 
   _update: function (aForce=false) {
     let $ = id => document.getElementById(id);
@@ -258,16 +259,32 @@ var TabsInTitlebar = {
     this._initialized = false;
     Services.prefs.removeObserver(this._prefName, this);
     this._menuObserver.disconnect();
     CustomizableUI.removeListener(this);
   }
 };
 
 function updateTitlebarDisplay() {
+  // On Windows, trying to run this before the window has been activated
+  // results in Bad Things Happening. Prevent us from doing that:
+  if (!TabsInTitlebar.haveUpdatedTitlebarDisplay) {
+    if (AppConstants.platform == "win" && Services.focus.activeWindow != window) {
+      if (!TabsInTitlebar._titlebarUpdateListener) {
+        TabsInTitlebar._titlebarUpdateListener = e => {
+          window.removeEventListener("activate", TabsInTitlebar._titlebarUpdateListener);
+          updateTitlebarDisplay();
+        };
+        window.addEventListener("activate", TabsInTitlebar._titlebarUpdateListener);
+      }
+      return;
+    }
+    TabsInTitlebar.haveUpdatedTitlebarDisplay = true;
+  }
+
   if (AppConstants.platform == "macosx") {
     // OS X and the other platforms differ enough to necessitate this kind of
     // special-casing. Like the other platforms where we CAN_DRAW_IN_TITLEBAR,
     // we draw in the OS X titlebar when putting the tabs up there. However, OS X
     // also draws in the titlebar when a lightweight theme is applied, regardless
     // of whether or not the tabs are drawn in the titlebar.
     if (TabsInTitlebar.enabled) {
       document.documentElement.setAttribute("chromemargin-nonlwtheme", "0,-1,-1,-1");