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=MattN,mconley, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 13 May 2016 18:52:53 +0100
changeset 333127 b2f0425218851914b703b902ed56c6148b37b537
parent 333126 70f114d27c05ff5e994c8996cc24f7dd8720425e
child 333128 9f9dc77cc9e9708921171f750729a5b8ede5e250
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, mconley, sylvestre
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=MattN,mconley, a=sylvestre 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");