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
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
--- 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");