Backed out changeset f468ae1633d4 (bug 367052)
authorDave Camp <dcamp@mozilla.com>
Wed, 20 Aug 2008 03:25:06 -0700
changeset 17158 cafe838a9b87c8a80a674a2aa3acb890d2d4d37c
parent 17137 f468ae1633d421c84960427ce3550176449b7832
child 17159 21c24bbd01c029ebee70f4017e88d46ed0aa9edf
push idunknown
push userunknown
push dateunknown
bugs367052
milestone1.9.1a2pre
backs outf468ae1633d421c84960427ce3550176449b7832
Backed out changeset f468ae1633d4 (bug 367052)
browser/components/sessionstore/src/nsSessionStore.js
browser/components/sessionstore/test/Makefile.in
browser/components/sessionstore/test/browser/Makefile.in
browser/components/sessionstore/test/browser/browser_367052.js
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -567,17 +567,17 @@ SessionStoreService.prototype = {
     var tabState = this._collectTabData(aTab);
     this._updateTextAndScrollDataForTab(aWindow, aTab.linkedBrowser, tabState);
 
     // reset the _tab property to avoid keeping the tab's XUL element alive
     // longer than we need it
     delete tabState._tab;
     
     // store closed-tab data for undo
-    if (tabState.entries.length > 0) {
+    if (tabState.entries.length > 1 || tabState.entries[0].url != "about:blank") {
       this._windows[aWindow.__SSi]._closedTabs.unshift({
         state: tabState,
         title: aTab.getAttribute("label"),
         image: aTab.getAttribute("image"),
         pos: aTab._tPos
       });
       var length = this._windows[aWindow.__SSi]._closedTabs.length;
       if (length > maxTabsUndo)
@@ -683,17 +683,17 @@ SessionStoreService.prototype = {
     var window = aTab.ownerDocument.defaultView;
     this._updateTextAndScrollDataForTab(window, aTab.linkedBrowser, tabState);
     
     return this._toJSONString(tabState);
   },
 
   setTabState: function sss_setTabState(aTab, aState) {
     var tabState = this._safeEval("(" + aState + ")");
-    if (!tabState.entries) {
+    if (!tabState.entries || !tabState.entries.length) {
       Components.returnCode = Cr.NS_ERROR_INVALID_ARG;
       return;
     }
     tabState._tab = aTab;
     
     var window = aTab.ownerDocument.defaultView;
     this.restoreHistoryPrecursor(window, [tabState], 0, 0, 0);
   },
@@ -852,17 +852,17 @@ SessionStoreService.prototype = {
    * Collect data related to a single tab
    * @param aTab
    *        tabbrowser tab
    * @param aFullData
    *        always return privacy sensitive data (use with care)
    * @returns object
    */
   _collectTabData: function sss_collectTabData(aTab, aFullData) {
-    var tabData = { entries: [] };
+    var tabData = { entries: [], index: 0 };
     var browser = aTab.linkedBrowser;
     
     if (!browser || !browser.currentURI)
       // can happen when calling this function right after .addTab()
       return tabData;
     else if (browser.parentNode.__SS_data && browser.parentNode.__SS_data._tab)
       // use the data to be restored when the tab hasn't been completely loaded
       return browser.parentNode.__SS_data;
@@ -883,18 +883,17 @@ SessionStoreService.prototype = {
         tabData.entries.push(this._serializeHistoryEntry(history.getEntryAtIndex(j, false),
                                                          aFullData));
       tabData.index = history.index + 1;
 
       // make sure not to cache privacy sensitive data which shouldn't get out
       if (!aFullData)
         browser.parentNode.__SS_data = tabData;
     }
-    else if (browser.currentURI.spec != "about:blank" ||
-             browser.contentDocument.body.hasChildNodes()) {
+    else {
       tabData.entries[0] = { url: browser.currentURI.spec };
       tabData.index = 1;
     }
     
     var disallow = [];
     for (var i = 0; i < CAPABILITIES.length; i++)
       if (!browser.docShell["allow" + CAPABILITIES[i]])
         disallow.push(CAPABILITIES[i]);
@@ -1088,17 +1087,18 @@ SessionStoreService.prototype = {
    * @param aWindow
    *        Window reference
    */
   _updateTextAndScrollData: function sss_updateTextAndScrollData(aWindow) {
     var browsers = aWindow.getBrowser().browsers;
     for (var i = 0; i < browsers.length; i++) {
       try {
         var tabData = this._windows[aWindow.__SSi].tabs[i];
-        if (browsers[i].parentNode.__SS_data && browsers[i].parentNode.__SS_data._tab)
+        if (tabData.entries.length == 0 ||
+            browsers[i].parentNode.__SS_data && browsers[i].parentNode.__SS_data._tab)
           continue; // ignore incompletely initialized tabs
         this._updateTextAndScrollDataForTab(aWindow, browsers[i], tabData);
       }
       catch (ex) { debug(ex); } // get as much data as possible, ignore failures (might succeed the next time)
     }
   },
 
   /**
@@ -1402,19 +1402,21 @@ SessionStoreService.prototype = {
       }
     }
     winData = root.windows[0];
     if (!winData.tabs) {
       winData.tabs = [];
     }
     // don't restore a single blank tab when we've had an external
     // URL passed in for loading at startup (cf. bug 357419)
-    else if (root._firstTabs && !aOverwriteTabs && winData.tabs.length == 1 &&
-             (!winData.tabs[0].entries || winData.tabs[0].entries.length == 0)) {
-      winData.tabs = [];
+    else if (root._firstTabs && !aOverwriteTabs && winData.tabs.length == 1) {
+      let tabEntries = winData.tabs[0].entries || [];
+      if (tabEntries.length == 0 ||
+          tabEntries.length == 1 && tabEntries[0].url == "about:blank")
+        winData.tabs = [];
     }
     
     var tabbrowser = aWindow.getBrowser();
     var openTabCount = aOverwriteTabs ? tabbrowser.browsers.length : -1;
     var newTabCount = winData.tabs.length;
     
     for (var t = 0; t < newTabCount; t++) {
       winData.tabs[t]._tab = t < openTabCount ? tabbrowser.mTabs[t] : tabbrowser.addTab();
@@ -1483,26 +1485,21 @@ SessionStoreService.prototype = {
           aWindow.setTimeout(restoreHistoryFunc, 100, this);
           return;
         }
       }
     }
     
     // mark the tabs as loading
     for (t = 0; t < aTabs.length; t++) {
+      if (!aTabs[t].entries || !aTabs[t].entries[0])
+        continue; // there won't be anything to load
+      
       var tab = aTabs[t]._tab;
       var browser = tabbrowser.getBrowserForTab(tab);
-      
-      if (!aTabs[t].entries || aTabs[t].entries.length == 0) {
-        // make sure to blank out this tab's content
-        // (just purging the tab's history won't be enough)
-        browser.contentDocument.location = "about:blank";
-        continue;
-      }
-      
       browser.stop(); // in case about:blank isn't done yet
       
       tab.setAttribute("busy", "true");
       tabbrowser.updateIcon(tab);
       tabbrowser.setTabTitleLoading(tab);
       
       // keep the data around to prevent dataloss in case
       // a tab gets closed before it's been properly restored
@@ -1580,31 +1577,29 @@ SessionStoreService.prototype = {
       tab.setAttribute(name, tabData.attributes[name]);
     
     // notify the tabbrowser that the tab chrome has been restored
     var event = aWindow.document.createEvent("Events");
     event.initEvent("SSTabRestoring", true, false);
     tab.dispatchEvent(event);
     
     var activeIndex = (tabData.index || tabData.entries.length) - 1;
-    if (activeIndex >= tabData.entries.length)
-      activeIndex = tabData.entries.length - 1;
-    if (activeIndex >= 0)
+    try {
       browser.webNavigation.gotoIndex(activeIndex);
+    }
+    catch (ex) { } // ignore an invalid tabData.index
     
-    if (tabData.entries.length > 0) {
-      // restore those aspects of the currently active documents
-      // which are not preserved in the plain history entries
-      // (mainly scroll state and text data)
-      browser.__SS_restore_data = tabData.entries[activeIndex] || {};
-      browser.__SS_restore_text = tabData.text || "";
-      browser.__SS_restore_tab = tab;
-      browser.__SS_restore = this.restoreDocument_proxy;
-      browser.addEventListener("load", browser.__SS_restore, true);
-    }
+    // restore those aspects of the currently active documents
+    // which are not preserved in the plain history entries
+    // (mainly scroll state and text data)
+    browser.__SS_restore_data = tabData.entries[activeIndex] || {};
+    browser.__SS_restore_text = tabData.text || "";
+    browser.__SS_restore_tab = tab;
+    browser.__SS_restore = this.restoreDocument_proxy;
+    browser.addEventListener("load", browser.__SS_restore, true);
     
     aWindow.setTimeout(function(){ _this.restoreHistory(aWindow, aTabs, aIdMap); }, 0);
   },
 
   /**
    * expands serialized history data into a session-history-entry instance
    * @param aEntry
    *        Object containing serialized history data for a URL
--- a/browser/components/sessionstore/test/Makefile.in
+++ b/browser/components/sessionstore/test/Makefile.in
@@ -38,13 +38,12 @@ DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 
 DIRS +=	chrome \
-		browser \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
deleted file mode 100644
--- a/browser/components/sessionstore/test/browser/Makefile.in
+++ /dev/null
@@ -1,52 +0,0 @@
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is sessionstore test code.
-#
-# The Initial Developer of the Original Code is
-# Mozilla Foundation.
-# Portions created by the Initial Developer are Copyright (C) 2008
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#   Simon Bünzli <zeniko@gmail.com>
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-relativesrcdir  = browser/components/sessionstore/test/browser 
-
-include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-
-_BROWSER_TEST_FILES = \
-	browser_367052.js \
-	$(NULL)
-
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
deleted file mode 100644
--- a/browser/components/sessionstore/test/browser/browser_367052.js
+++ /dev/null
@@ -1,72 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is sessionstore test code.
- *
- * The Initial Developer of the Original Code is
- * Simon Bünzli <zeniko@gmail.com>.
- * Portions created by the Initial Developer are Copyright (C) 2008
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-function test() {
-  /** Test for Bug 367052 **/
-  
-  // test setup
-  let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
-  let tabbrowser = getBrowser();
-  waitForExplicitFinish();
-  
-  // make sure that the next closed tab will increase getClosedTabCount
-  let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
-  gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
-  let closedTabCount = ss.getClosedTabCount(window);
-  
-  // restore a blank tab
-  let tab = tabbrowser.addTab("about:");
-  tab.linkedBrowser.addEventListener("load", function(aEvent) {
-    this.removeEventListener("load", arguments.callee, true);
-    
-    let browser = tabbrowser.getBrowserForTab(tab);
-    let history = browser.webNavigation.sessionHistory;
-    ok(history.count >= 1, "the new tab does have at least one history entry");
-    
-    ss.setTabState(tab, "{ entries: [] }");
-    tab.linkedBrowser.addEventListener("load", function(aEvent) {
-      ok(history.count == 0, "the tab was restored without any history whatsoever");
-      
-      tabbrowser.removeTab(tab);
-      ok(ss.getClosedTabCount(window) == closedTabCount,
-         "The closed blank tab wasn't added to Recently Closed Tabs");
-      
-      // clean up
-      gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo);
-      finish();
-    }, true);
-  }, true);
-}