Bug 1181475 - Refactor duplicateTabIn to avoid a race between swapping frameloaders and SessionStore. r=Mossop
authorMike Conley <mconley@mozilla.com>
Thu, 30 Jul 2015 15:06:13 -0400
changeset 287796 65a711af2c0bc55d434783fee16e6061556506dd
parent 287795 e0c790a2af42f5b06643c0faa74db81d12664f47
child 287797 09d779eb4be2c328c5d2b9c42e4b25a0d8f954ad
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1181475
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1181475 - Refactor duplicateTabIn to avoid a race between swapping frameloaders and SessionStore. r=Mossop A race between SessionStore tab duplication and swapBrowsersAndCloseOther was causing us to usually display a duplicated tab before it was actually ready to be shown. We were also being pretty inefficient, since SessionStore supports being able to duplicate a tab into a new window.
browser/base/content/browser.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7554,27 +7554,40 @@ function safeModeRestart() {
  *  "tab"         new tab
  *  "tabshifted"  same as "tab" but in background if default is to select new
  *                tabs, and vice versa
  *  "window"      new window
  *
  * delta is the offset to the history entry that you want to load.
  */
 function duplicateTabIn(aTab, where, delta) {
-  let newTab = SessionStore.duplicateTab(window, aTab, delta);
-
   switch (where) {
     case "window":
-      gBrowser.hideTab(newTab);
-      gBrowser.replaceTabWithWindow(newTab);
+      let otherWin = OpenBrowserWindow();
+      let delayedStartupFinished = (subject, topic) => {
+        if (topic == "browser-delayed-startup-finished" &&
+            subject == otherWin) {
+          Services.obs.removeObserver(delayedStartupFinished, topic);
+          let otherGBrowser = otherWin.gBrowser;
+          let otherTab = otherGBrowser.selectedTab;
+          SessionStore.duplicateTab(otherWin, aTab, delta);
+          otherGBrowser.removeTab(otherTab, { animate: false });
+        }
+      };
+
+      Services.obs.addObserver(delayedStartupFinished,
+                               "browser-delayed-startup-finished",
+                               false);
       break;
     case "tabshifted":
+      SessionStore.duplicateTab(window, aTab, delta);
       // A background tab has been opened, nothing else to do here.
       break;
     case "tab":
+      let newTab = SessionStore.duplicateTab(window, aTab, delta);
       gBrowser.selectedTab = newTab;
       break;
   }
 }
 
 var Scratchpad = {
   openScratchpad: function SP_openScratchpad() {
     return this.ScratchpadManager.openScratchpad();