Bug 459567 - reuse the Session Restore page's window for restoring the session; r=dietrich
authorSimon Bünzli <zeniko@gmail.com>
Thu, 30 Oct 2008 12:46:43 +0330
changeset 21090 90ddcaa921e4834b88962031c74cdc07c0e55544
parent 21089 0e702acc89d97b11a3d7a7f199f7aa77515cc2f6
child 21091 7e85c5796676b613e07538cd6ee55df201a4c8ae
push id3302
push userehsan.akhgari@gmail.com
push dateThu, 30 Oct 2008 09:17:30 +0000
treeherdermozilla-central@90ddcaa921e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs459567
milestone1.9.1b2pre
Bug 459567 - reuse the Session Restore page's window for restoring the session; r=dietrich
browser/components/sessionstore/content/aboutSessionRestore.js
--- a/browser/components/sessionstore/content/aboutSessionRestore.js
+++ b/browser/components/sessionstore/content/aboutSessionRestore.js
@@ -110,31 +110,34 @@ function restoreSession() {
       else if (!gTreeData[t].checked)
         // this window won't be restored at all
         gStateObject.windows.splice(ix, 1);
       ix--;
     }
   }
   var stateString = gStateObject.toSource();
   
-  // restore the session into a new window and close the current tab
+  var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
   var top = getBrowserWindow();
-  var selfBrowser = top.gBrowser.getBrowserForDocument(document);
+  
+  // if there's only this page open, reuse the window for restoring the session
+  if (top.gBrowser.tabContainer.childNodes.length == 1) {
+    ss.setWindowState(top, stateString, true);
+    return;
+  }
+  
+  // restore the session into a new window and close the current tab
   var newWindow = top.openDialog(top.location, "_blank", "chrome,dialog=no,all");
   newWindow.addEventListener("load", function() {
     newWindow.removeEventListener("load", arguments.callee, true);
-    
-    var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
     ss.setWindowState(newWindow, stateString, true);
     
     var tabbrowser = top.gBrowser;
-    if (tabbrowser.tabContainer.childNodes.length == 1)
-      top.close();
-    else
-      tabbrowser.removeTab(getTabForBrowser(selfBrowser));
+    var tabIndex = tabbrowser.getBrowserIndexForDocument(document);
+    tabbrowser.removeTab(tabbrowser.tabContainer.childNodes[tabIndex]);
   }, true);
 }
 
 function startNewSession() {
   getBrowserWindow().BrowserHome();
 }
 
 function onListClick(aEvent) {
@@ -180,21 +183,16 @@ function onListKeyDown(aEvent) {
 // Helper functions
 
 function getBrowserWindow() {
   return window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
                .QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem
                .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
 }
 
-function getTabForBrowser(aBrowser) {
-  return Array.filter(getBrowserWindow().gBrowser.tabContainer.childNodes,
-                      function(aTab) aTab.linkedBrowser == aBrowser)[0];
-}
-
 function toggleRowChecked(aIx) {
   var item = gTreeData[aIx];
   item.checked = !item.checked;
   treeView.treeBox.invalidateRow(aIx);
   
   function isChecked(aItem) aItem.checked;
   
   if (treeView.isContainer(aIx)) {