Bug 495123 - Save an empty window state if it's the last window closed and there were no others closed in series before r=smacleod a=lsblakk
authorTim Taubert <ttaubert@mozilla.com>
Thu, 27 Mar 2014 17:51:59 +0100
changeset 192272 f29ab60028d4
parent 192271 9bd4a69ee2e0
child 192273 dcd4cf44e61b
push id3556
push userttaubert@mozilla.com
push date2014-05-14 14:56 +0000
Treeherderresults
reviewerssmacleod, lsblakk
bugs495123
milestone30.0
Bug 495123 - Save an empty window state if it's the last window closed and there were no others closed in series before r=smacleod a=lsblakk
browser/components/sessionstore/src/SessionStore.jsm
browser/components/tabview/test/browser_tabview_bug628061.js
browser/components/tabview/test/browser_tabview_bug697390.js
browser/components/tabview/test/browser_tabview_bug707466.js
--- a/browser/components/sessionstore/src/SessionStore.jsm
+++ b/browser/components/sessionstore/src/SessionStore.jsm
@@ -1051,26 +1051,36 @@ let SessionStoreInternal = {
       winData._shouldRestore = true;
 #endif
 
       // Store the window's close date to figure out when each individual tab
       // was closed. This timestamp should allow re-arranging data based on how
       // recently something was closed.
       winData.closedAt = Date.now();
 
-      // Save the window if it has multiple tabs or a single saveable tab and
-      // it's not private.
+      // Save non-private windows if they have at
+      // least one saveable tab or are the last window.
       if (!winData.isPrivate) {
         // Remove any open private tabs the window may contain.
         PrivacyFilter.filterPrivateTabs(winData);
 
-        let hasSingleTabToSave =
-          winData.tabs.length == 1 && this._shouldSaveTabState(winData.tabs[0]);
-
-        if (hasSingleTabToSave || winData.tabs.length > 1) {
+        // Determine whether the window has any tabs worth saving.
+        let hasSaveableTabs = winData.tabs.some(this._shouldSaveTabState);
+
+        // When closing windows one after the other until Firefox quits, we
+        // will move those closed in series back to the "open windows" bucket
+        // before writing to disk. If however there is only a single window
+        // with tabs we deem not worth saving then we might end up with a
+        // random closed or even a pop-up window re-opened. To prevent that
+        // we explicitly allow saving an "empty" window state.
+        let isLastWindow =
+          Object.keys(this._windows).length == 1 &&
+          !this._closedWindows.some(win => win._shouldRestore || false);
+
+        if (hasSaveableTabs || isLastWindow) {
           // we don't want to save the busy state
           delete winData.busy;
 
           this._closedWindows.unshift(winData);
           this._capClosedWindows();
         }
       }
 
--- a/browser/components/tabview/test/browser_tabview_bug628061.js
+++ b/browser/components/tabview/test/browser_tabview_bug628061.js
@@ -1,23 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
 
 let state = {
   windows: [{
     tabs: [{
-      entries: [{ url: "about:blank" }],
+      entries: [{ url: "about:robots" }],
       hidden: true,
-      extData: {"tabview-tab": '{"url":"about:blank","groupID":1,"bounds":{"left":20,"top":20,"width":20,"height":20}}'}
+      extData: {"tabview-tab": '{"url":"about:robots","groupID":1,"bounds":{"left":20,"top":20,"width":20,"height":20}}'}
     },{
-      entries: [{ url: "about:blank" }],
+      entries: [{ url: "about:robots" }],
       hidden: false,
-      extData: {"tabview-tab": '{"url":"about:blank","groupID":2,"bounds":{"left":20,"top":20,"width":20,"height":20}}'},
+      extData: {"tabview-tab": '{"url":"about:robots","groupID":2,"bounds":{"left":20,"top":20,"width":20,"height":20}}'},
     }],
     selected: 2,
     extData: {
       "tabview-groups": '{"nextID":3,"activeGroupId":2, "totalNumber":2}',
       "tabview-group":
         '{"1":{"bounds":{"left":15,"top":5,"width":280,"height":232},"id":1},' +
         '"2":{"bounds":{"left":309,"top":5,"width":267,"height":226},"id":2}}'
     }
--- a/browser/components/tabview/test/browser_tabview_bug697390.js
+++ b/browser/components/tabview/test/browser_tabview_bug697390.js
@@ -1,21 +1,21 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 let state = {
   windows: [{
     tabs: [{
-      entries: [{ url: "about:blank" }],
+      entries: [{ url: "about:robots" }],
       hidden: true,
-      extData: {"tabview-tab": '{"url":"about:blank","groupID":1,"bounds":{"left":120,"top":20,"width":20,"height":20}}'}
+      extData: {"tabview-tab": '{"url":"about:robots","groupID":1,"bounds":{"left":120,"top":20,"width":20,"height":20}}'}
     },{
-      entries: [{ url: "about:blank" }],
+      entries: [{ url: "about:robots" }],
       hidden: false,
-      extData: {"tabview-tab": '{"url":"about:blank","groupID":2,"bounds":{"left":20,"top":20,"width":20,"height":20}}'},
+      extData: {"tabview-tab": '{"url":"about:robots","groupID":2,"bounds":{"left":20,"top":20,"width":20,"height":20}}'},
     }],
     selected: 2,
     extData: {
       "tabview-groups": '{"nextID":3,"activeGroupId":2, "totalNumber":2}',
       "tabview-group":
         '{"1":{"bounds":{"left":15,"top":5,"width":280,"height":232},"id":1},' +
         '"2":{"bounds":{"left":309,"top":5,"width":267,"height":226},"id":2}}'
     }
--- a/browser/components/tabview/test/browser_tabview_bug707466.js
+++ b/browser/components/tabview/test/browser_tabview_bug707466.js
@@ -3,33 +3,33 @@
 
 function test() {
   waitForExplicitFinish();
 
   // create two groups and each group has one tab item
   let newState = {
     windows: [{
       tabs: [{
-        entries: [{ url: "about:blank" }],
+        entries: [{ url: "about:robots" }],
         hidden: true,
         attributes: {},
         extData: {
           "tabview-tab":
             '{"bounds":{"left":21,"top":29,"width":204,"height":153},' +
-            '"userSize":null,"url":"about:blank","groupID":1,' +
+            '"userSize":null,"url":"about:robots","groupID":1,' +
             '"imageData":null,"title":null}'
         }
       },{
-        entries: [{ url: "about:blank" }],
+        entries: [{ url: "about:robots" }],
         hidden: false,
         attributes: {},
         extData: {
           "tabview-tab":
             '{"bounds":{"left":315,"top":29,"width":111,"height":84},' +
-            '"userSize":null,"url":"about:blank","groupID":2,' +
+            '"userSize":null,"url":"about:robots","groupID":2,' +
             '"imageData":null,"title":null}'
         },
       }],
       selected:2,
       _closedTabs: [],
       extData: {
         "tabview-groups": '{"nextID":3,"activeGroupId":2}',
         "tabview-group":