Bug 597637 Can't undo close tab if it is only in bfundo cache r=misak
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Sat, 09 Oct 2010 23:55:04 +0100
changeset 6533 bfd1320b39acbd8c1aaab876abbd13196f2dfda3
parent 6532 317093217f1022b16c4a92a7c7680beb0d79fade
child 6534 426abd4c74c79be95df16f8891c8ba0219fa6936
push idunknown
push userunknown
push dateunknown
reviewersmisak
bugs597637
Bug 597637 Can't undo close tab if it is only in bfundo cache r=misak
suite/common/src/nsSessionStore.js
--- a/suite/common/src/nsSessionStore.js
+++ b/suite/common/src/nsSessionStore.js
@@ -845,65 +845,62 @@ SessionStoreService.prototype = {
       return newTab;
     }
 
     var state = { windows: [{ tabs: [tabState] }] };
     this.windowToFocus = this._openWindowWithState(state);
     return null;
   },
 
-  getClosedTabCount: function sss_getClosedTabCount(aWindow) {
-    if (!aWindow.__SSi && aWindow.__SS_dyingCache)
-      return aWindow.__SS_dyingCache._closedTabs.length;
-
-    if (!aWindow.__SSi)
-      // XXXzeniko shouldn't we throw here?
-      return 0; // not a browser window, or not otherwise tracked by SS.
-
-    var closedTabs = this._windows[aWindow.__SSi]._closedTabs;
-    closedTabs = closedTabs.concat(aWindow.getBrowser().savedBrowsers);
-    closedTabs = closedTabs.filter(function(aTabData, aIndex, aArray) {
-      return aArray.indexOf(aTabData) == aIndex;
-    });
-    return closedTabs.length;
-  },
-
-  getClosedTabData: function sss_getClosedTabData(aWindow) {
-    if (!aWindow.__SSi && !aWindow.__SS_dyingCache)
-      throw (Components.returnCode = Components.results.NS_ERROR_INVALID_ARG);
-
+  _getClosedTabs: function sss_getClosedTabs(aWindow) {
     if (!aWindow.__SSi)
       return this._toJSONString(aWindow.__SS_dyingCache._closedTabs);
 
     var closedTabs = this._windows[aWindow.__SSi]._closedTabs;
     closedTabs = closedTabs.concat(aWindow.getBrowser().savedBrowsers);
     closedTabs = closedTabs.filter(function(aTabData, aIndex, aArray) {
       return aArray.indexOf(aTabData) == aIndex;
     });
-    return this._toJSONString(closedTabs);
+    return closedTabs;
+  },
+
+  getClosedTabCount: function sss_getClosedTabCount(aWindow) {
+    if (!aWindow.__SSi && !aWindow.__SS_dyingCache)
+      // XXXzeniko shouldn't we throw here?
+      return 0; // not a browser window, or not otherwise tracked by SS.
+
+    return this._getClosedTabs(aWindow).length;
+  },
+
+  getClosedTabData: function sss_getClosedTabData(aWindow) {
+    if (!aWindow.__SSi && !aWindow.__SS_dyingCache)
+      throw (Components.returnCode = Components.results.NS_ERROR_INVALID_ARG);
+
+    return this._toJSONString(this._getClosedTabs(aWindow));
   },
 
   undoCloseTab: function sss_undoCloseTab(aWindow, aIndex) {
     if (!aWindow.__SSi)
       throw (Components.returnCode = Components.results.NS_ERROR_INVALID_ARG);
 
-    var closedTabs = this._windows[aWindow.__SSi]._closedTabs;
+    var closedTabs = this._getClosedTabs(aWindow);
     if (!(aIndex in closedTabs))
       throw (Components.returnCode = Components.results.NS_ERROR_INVALID_ARG);
 
     // fetch the data of closed tab, while removing it from the array
-    let closedTab = closedTabs.splice(aIndex, 1)[0];
+    let closedTab = closedTabs[aIndex];
+    if (aIndex in this._windows[aWindow.__SSi]._closedTabs)
+      this._windows[aWindow.__SSi]._closedTabs.splice(aIndex, 1);
     var browser = aWindow.getBrowser();
     var index = browser.savedBrowsers.indexOf(closedTab);
     if (index != -1)
       // SeaMonkey has its own undoclosetab functionality
       return browser.restoreTab(index);
 
     // create a new tab
-    var browser = aWindow.getBrowser();
     var tab = browser.addTab();
 
     // restore the tab's position
     browser.moveTabTo(tab, closedTab.pos);
 
     // restore tab content
     this.restoreHistoryPrecursor(aWindow, [tab], [closedTab.state], 1, 0, 0);
 
@@ -913,22 +910,24 @@ SessionStoreService.prototype = {
 
     return tab;
   },
 
   forgetClosedTab: function sss_forgetClosedTab(aWindow, aIndex) {
     if (!aWindow.__SSi)
       throw (Components.returnCode = Components.results.NS_ERROR_INVALID_ARG);
 
-    var closedTabs = this._windows[aWindow.__SSi]._closedTabs;
+    var closedTabs = this._getClosedTabs(aWindow);
     if (!(aIndex in closedTabs))
       throw (Components.returnCode = Components.results.NS_ERROR_INVALID_ARG);
 
     // remove closed tab from the array
-    var closedTab = closedTabs.splice(aIndex, 1)[0];
+    var closedTab = closedTabs[aIndex];
+    if (aIndex in this._windows[aWindow.__SSi]._closedTabs)
+      this._windows[aWindow.__SSi]._closedTabs.splice(aIndex, 1);
     var browser = aWindow.getBrowser();
     var index = browser.savedBrowsers.indexOf(closedTab);
     if (index != -1)
       browser.forgetSavedBrowser(aIndex);
   },
 
   getClosedWindowCount: function sss_getClosedWindowCount() {
     return this._closedWindows.length;