Bug 488930 - SessionStore can lose track of a window. r=zpao/dietrich
authorSimon Bünzli <zeniko@gmail.com>
Thu, 30 Apr 2009 18:44:07 +0200
changeset 27917 8b953baa1edee9a6a34d376901ffa0fba6b3d680
parent 27916 28a71363089737c4edf93fd0699a774a322ce585
child 27918 87799243c9e60bc6e3664e03033f465144027ef1
push id6775
push userdgottwald@mozilla.com
push dateThu, 30 Apr 2009 16:44:40 +0000
treeherdermozilla-central@8b953baa1ede [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszpao, dietrich
bugs488930
milestone1.9.2a1pre
Bug 488930 - SessionStore can lose track of a window. r=zpao/dietrich
browser/components/sessionstore/src/nsSessionStore.js
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -1860,41 +1860,43 @@ SessionStoreService.prototype = {
       let activePageData = aTabData[t].entries[activeIndex] || null;
       browser.userTypedValue = activePageData ? activePageData.url || null : null;
       
       // keep the data around to prevent dataloss in case
       // a tab gets closed before it's been properly restored
       browser.parentNode.__SS_data = aTabData[t];
     }
     
-    // Determine if we can optimize & load visible tabs first
-    let tabScrollBoxObject = tabbrowser.tabContainer.mTabstrip.scrollBoxObject;
-    let tabBoxObject = aTabs[0].boxObject;
-    let maxVisibleTabs = Math.ceil(tabScrollBoxObject.width / tabBoxObject.width);
+    if (aTabs.length > 0) {
+      // Determine if we can optimize & load visible tabs first
+      let tabScrollBoxObject = tabbrowser.tabContainer.mTabstrip.scrollBoxObject;
+      let tabBoxObject = aTabs[0].boxObject;
+      let maxVisibleTabs = Math.ceil(tabScrollBoxObject.width / tabBoxObject.width);
 
-    // make sure we restore visible tabs first, if there are enough
-    if (maxVisibleTabs < aTabs.length && aSelectTab > 1) {
-      let firstVisibleTab = 0;
-      if (aTabs.length - maxVisibleTabs > aSelectTab) {
-        // aSelectTab is leftmost since we scroll to it when possible
-        firstVisibleTab = aSelectTab - 1;
-      } else {
-        // aSelectTab is rightmost or no more room to scroll right
-        firstVisibleTab = aTabs.length - maxVisibleTabs;
+      // make sure we restore visible tabs first, if there are enough
+      if (maxVisibleTabs < aTabs.length && aSelectTab > 1) {
+        let firstVisibleTab = 0;
+        if (aTabs.length - maxVisibleTabs > aSelectTab) {
+          // aSelectTab is leftmost since we scroll to it when possible
+          firstVisibleTab = aSelectTab - 1;
+        } else {
+          // aSelectTab is rightmost or no more room to scroll right
+          firstVisibleTab = aTabs.length - maxVisibleTabs;
+        }
+        aTabs = aTabs.splice(firstVisibleTab, maxVisibleTabs).concat(aTabs);
+        aTabData = aTabData.splice(firstVisibleTab, maxVisibleTabs).concat(aTabData);
+        aSelectTab -= firstVisibleTab;
       }
-      aTabs = aTabs.splice(firstVisibleTab, maxVisibleTabs).concat(aTabs);
-      aTabData = aTabData.splice(firstVisibleTab, maxVisibleTabs).concat(aTabData);
-      aSelectTab -= firstVisibleTab;
-    }
 
-    // make sure to restore the selected tab first (if any)
-    if (aSelectTab-- && aTabs[aSelectTab]) {
+      // make sure to restore the selected tab first (if any)
+      if (aSelectTab-- && aTabs[aSelectTab]) {
         aTabs.unshift(aTabs.splice(aSelectTab, 1)[0]);
         aTabData.unshift(aTabData.splice(aSelectTab, 1)[0]);
         tabbrowser.selectedTab = aTabs[0];
+      }
     }
 
     if (!this._isWindowLoaded(aWindow)) {
       // from now on, the data will come from the actual window
       delete this._statesToRestore[aWindow.__SS_restoreID];
       delete aWindow.__SS_restoreID;
     }