Bug 1269462 - fix race condition in TabsInTitlebar code where it was possible we'd only be called before init(), resulting in never updating the titlebar maths, r=mconley,MattN draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 13 May 2016 18:52:53 +0100
changeset 367084 99a0432db43c05b2f4abe4799c0c78d21d551927
parent 366958 544bc272bfe13911e43f21b7fe52eb01f0435de4
child 520912 e627f5c999d8131bbdd0c0ab4e755d37e92a2b28
push id18136
push usergijskruitbosch@gmail.com
push dateSat, 14 May 2016 08:33:42 +0000
reviewersmconley, MattN
bugs1269462
milestone48.0a2
Bug 1269462 - fix race condition in TabsInTitlebar code where it was possible we'd only be called before init(), resulting in never updating the titlebar maths, r=mconley,MattN MozReview-Commit-ID: KM274gGpiuR
browser/base/content/browser-tabsintitlebar.js
--- a/browser/base/content/browser-tabsintitlebar.js
+++ b/browser/base/content/browser-tabsintitlebar.js
@@ -33,16 +33,22 @@ var TabsInTitlebar = {
       if (aArea == CustomizableUI.AREA_TABSTRIP || aArea == CustomizableUI.AREA_MENUBAR)
         this._update(true);
     };
     CustomizableUI.addListener(this);
 
     addEventListener("resolutionchange", this, false);
 
     this._initialized = true;
+    if (this._updateOnInit) {
+      // We don't need to call this with 'true', even if original calls
+      // (before init()) did, because this will be the first call and so
+      // we will update anyway.
+      this._update();
+    }
   },
 
   allowedBy: function (condition, allow) {
     if (allow) {
       if (condition in this._disallowed) {
         delete this._disallowed[condition];
         this._update(true);
       }
@@ -79,33 +85,41 @@ var TabsInTitlebar = {
           mutation.attributeName == "autohide") {
         TabsInTitlebar._update(true);
         return;
       }
     }
   },
 
   _initialized: false,
+  _updateOnInit: false,
   _disallowed: {},
   _prefName: "browser.tabs.drawInTitlebar",
   _lastSizeMode: null,
 
   _readPref: function () {
     this.allowedBy("pref",
                    Services.prefs.getBoolPref(this._prefName));
   },
 
   _update: function (aForce=false) {
     let $ = id => document.getElementById(id);
     let rect = ele => ele.getBoundingClientRect();
     let verticalMargins = cstyle => parseFloat(cstyle.marginBottom) + parseFloat(cstyle.marginTop);
 
-    if (!this._initialized || window.fullScreen)
+    if (window.fullScreen)
       return;
 
+    // In some edgecases it is possible for this to fire before we've initialized.
+    // Don't run now, but don't forget to run it when we do initialize.
+    if (!this._initialized) {
+      this._updateOnInit = true;
+      return;
+    }
+
     let allowed = true;
 
     if (!aForce) {
       // _update is called on resize events, because the window is not ready
       // after sizemode events. However, we only care about the event when the
       // sizemode is different from the last time we updated the appearance of
       // the tabs in the titlebar.
       let sizemode = document.documentElement.getAttribute("sizemode");