Bug 1350642 - part 2 - Use tab events to keep tabCountResizable property in sync; r?dao draft
authorHaik Aftandilian <haftandilian@mozilla.com>
Tue, 29 Aug 2017 23:23:34 -0700
changeset 763807 b7a7ecf2b653caef1272cfe806404d3f68feaa3a
parent 763806 46214285d545a3a3de0970fcffdc3bbd014261c9
child 763808 1cd09b68535e4c2a7666ed21d567a466a83e224c
push id101566
push userhaftandilian@mozilla.com
push dateTue, 06 Mar 2018 19:11:38 +0000
reviewersdao
bugs1350642
milestone58.0a1
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
browser/base/content/browser.js
browser/base/content/tab-content.js
browser/base/content/tabbrowser.xml
--- 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;
           }