Bug 459567 - reuse the Session Restore page's window for restoring the session; r=dietrich
--- 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)) {