Bug 1350642 - part 2 - Use tab events to keep tabCountResizable property in sync; r?dao
Keep each tab's nsITabChild::hasSiblings property in sync with the
number of tabs in the window.
MozReview-Commit-ID: GTrtOSQPCiD
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1406,16 +1406,25 @@ var gBrowserInit = {
_delayedStartup() {
let tmp = {};
Cu.import("resource://gre/modules/TelemetryTimestamps.jsm", tmp);
let TelemetryTimestamps = tmp.TelemetryTimestamps;
TelemetryTimestamps.add("delayedStartupStarted");
this._cancelDelayedStartup();
+ let initialBrowser =
+ document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser");
+ let initialTab = gBrowser.getTabForBrowser(initialBrowser);
+ if (initialTab) {
+ initialTab.linkedBrowser
+ .messageManager
+ .sendAsyncMessage("Browser:HasSiblings", false);
+ }
+
// We need to set the OfflineApps message listeners up before we
// load homepages, which might need them.
OfflineApps.init();
// This pageshow listener needs to be registered before we may call
// swapBrowsersAndCloseOther() to receive pageshow events fired by that.
window.messageManager.addMessageListener("PageVisibility:Show", function(message) {
if (message.target == gBrowser.selectedBrowser) {
--- a/browser/base/content/tab-content.js
+++ b/browser/base/content/tab-content.js
@@ -60,16 +60,24 @@ addMessageListener("Browser:HideSessionR
let doc = content.document;
let container;
if (doc.documentURI.toLowerCase() == "about:home" &&
(container = doc.getElementById("sessionRestoreContainer"))) {
container.hidden = true;
}
});
+if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
+ addMessageListener("Browser:HasSiblings", function(message) {
+ let tabChild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsITabChild);
+ let hasSiblings = message.data;
+ tabChild.hasSiblings = hasSiblings;
+ });
+}
addMessageListener("Browser:Reload", function(message) {
/* First, we'll try to use the session history object to reload so
* that framesets are handled properly. If we're in a special
* window (such as view-source) that has no session history, fall
* back on using the web navigation's reload method.
*/
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -5928,16 +5928,53 @@
"browser.tabs.remote.warmup.unloadDelayMs", 2000);
XPCOMUtils.defineLazyPreferenceGetter(this, "tabMinWidthPref",
"browser.tabs.tabMinWidth", this._tabMinWidthLimit,
(pref, prevValue, newValue) => this.tabMinWidth = newValue,
newValue => Math.max(newValue, this._tabMinWidthLimit),
);
this.tabMinWidth = this.tabMinWidthPref;
+
+ // Add listeners for keeping HasSiblings in sync
+ this.tabContainer.addEventListener("TabOpen", (function(aEvent) {
+ // The new tab is already in the tabs array
+ if (this.tabs.length == 2) {
+ // Tell the original tab it now has siblings
+ for (let tab of this.tabs) {
+ if (tab !== aEvent.originalTarget) {
+ tab.linkedBrowser
+ .messageManager
+ .sendAsyncMessage("Browser:HasSiblings", true);
+ return;
+ }
+ }
+ }
+ }).bind(this));
+
+ this.tabContainer.addEventListener("TabClose", (function() {
+ // Tell the lone tab it now has no siblings
+ let newCount = this.tabs.length - 1;
+ if (newCount == 1) {
+ window.messageManager
+ .broadcastAsyncMessage("Browser:HasSiblings", false);
+ }
+ }).bind(this));
+
+ this.tabContainer.addEventListener("TabRemotenessChange", (function(aEvent) {
+ // A new TabChild defaults to HasSiblings=true, so we only
+ // need to send an update if we have no siblings.
+ if (this.tabs.length == 1) {
+ let tab = aEvent.originalTarget;
+ tab.linkedBrowser
+ .messageManager
+ .sendAsyncMessage("Browser:HasSiblings", false);
+ }
+ }).bind(this));
+
]]>
</constructor>
<method name="_generateUniquePanelID">
<body><![CDATA[
if (!this._uniquePanelIDCounter) {
this._uniquePanelIDCounter = 0;
}