Bug 1158855 - Don't collect children of SHEntries if one or more of those were dynamically added. r=Yoric, a=sledru
authorTim Taubert <ttaubert@mozilla.com>
Mon, 25 May 2015 19:03:33 +0200
changeset 266130 2d83b8a022a6
parent 266129 4f5b9c0de6ce
child 266131 a74ce2833a96
push id4762
push userryanvm@gmail.com
push date2015-05-28 18:54 +0000
treeherdermozilla-beta@dc9c305024f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric, sledru
bugs1158855
milestone39.0
Bug 1158855 - Don't collect children of SHEntries if one or more of those were dynamically added. r=Yoric, a=sledru
browser/components/sessionstore/SessionHistory.jsm
browser/components/sessionstore/test/browser_dynamic_frames.js
--- a/browser/components/sessionstore/SessionHistory.jsm
+++ b/browser/components/sessionstore/SessionHistory.jsm
@@ -135,31 +135,16 @@ let SessionHistoryInternal = {
         data.index = 1;
       }
     }
 
     return data;
   },
 
   /**
-   * Determines whether a given session history entry has been added dynamically.
-   *
-   * @param shEntry
-   *        The session history entry.
-   * @return bool
-   */
-  isDynamic: function (shEntry) {
-    // shEntry.isDynamicallyAdded() is true for dynamically added
-    // <iframe> and <frameset>, but also for <html> (the root of the
-    // document) so we use shEntry.parent to ensure that we're not looking
-    // at the root of the document
-    return shEntry.parent && shEntry.isDynamicallyAdded();
-  },
-
-  /**
    * Get an object that is a serialized representation of a History entry.
    *
    * @param shEntry
    *        nsISHEntry instance
    * @param isPinned
    *        The tab is pinned and should be treated differently for privacy.
    * @return object
    */
@@ -227,22 +212,22 @@ let SessionHistoryInternal = {
       entry.structuredCloneState = shEntry.stateData.getDataAsBase64();
       entry.structuredCloneVersion = shEntry.stateData.formatVersion;
     }
 
     if (!(shEntry instanceof Ci.nsISHContainer)) {
       return entry;
     }
 
-    if (shEntry.childCount > 0) {
+    if (shEntry.childCount > 0 && !shEntry.hasDynamicallyAddedChild()) {
       let children = [];
       for (let i = 0; i < shEntry.childCount; i++) {
         let child = shEntry.GetChildAt(i);
 
-        if (child && !this.isDynamic(child)) {
+        if (child) {
           // Don't try to restore framesets containing wyciwyg URLs.
           // (cf. bug 424689 and bug 450595)
           if (child.URI.schemeIs("wyciwyg")) {
             children.length = 0;
             break;
           }
 
           children.push(this.serializeEntry(child, isPinned));
--- a/browser/components/sessionstore/test/browser_dynamic_frames.js
+++ b/browser/components/sessionstore/test/browser_dynamic_frames.js
@@ -61,35 +61,27 @@ add_task(function () {
   let browser = tab.linkedBrowser;
   yield promiseBrowserLoaded(browser);
 
   TabState.flush(browser);
   let {entries} = JSON.parse(ss.getTabState(tab));
 
   // Check URLs.
   ok(entries[0].url.startsWith("data:text/html"), "correct root url");
-  is(entries[0].children[0].url, "about:mozilla", "correct url for static frame");
-
-  // Check the number of children.
-  is(entries.length, 1, "there is one root entry ...");
-  is(entries[0].children.length, 1, "... with a single child entry");
+  ok(!entries[0].children, "no children collected");
 
   // Navigate the subframe.
   browser.messageManager.sendAsyncMessage("ss-test:click", {id: "lnk"});
   yield promiseBrowserLoaded(browser, false /* don't ignore subframes */);
 
   TabState.flush(browser);
   ({entries} = JSON.parse(ss.getTabState(tab)));
 
   // Check URLs.
   ok(entries[0].url.startsWith("data:text/html"), "correct 1st root url");
   ok(entries[1].url.startsWith("data:text/html"), "correct 2nd root url");
-  is(entries[0].children[0].url, "about:mozilla", "correct url for 1st static frame");
-  is(entries[1].children[0].url, "about:robots", "correct url for 2ns static frame");
-
-  // Check the number of children.
-  is(entries.length, 2, "there are two root entries ...");
-  is(entries[0].children.length, 1, "... with a single child entry ...");
-  is(entries[1].children.length, 1, "... each");
+  ok(!entries.children, "no children collected");
+  ok(!entries[0].children, "no children collected");
+  ok(!entries[1].children, "no children collected");
 
   // Cleanup.
   gBrowser.removeTab(tab);
 });