Bug 1261225 - Part 1 - Refactor text data restoring. r=margaret draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 31 Mar 2016 20:54:03 +0200
changeset 348165 706c30212c8c07598e5dd5f877612a34db55b59f
parent 348040 68c0b7d6f16ce5bb023e08050102b5f2fe4aacd8
child 348166 3b8be583ceebfc25b77971d319108f850a8d6fb7
push id14761
push usermozilla@buttercookie.de
push dateWed, 06 Apr 2016 19:41:12 +0000
reviewersmargaret
bugs1261225, 852267
milestone48.0a1
Bug 1261225 - Part 1 - Refactor text data restoring. r=margaret Previously, when restoring a tab, we made a copy of the whole session data from which we would then extract and restore the form data - if present - after page loading had completed. With the changes from bug 852267, the original session data - containing any eventual form data - is now always reattached to the restored tab object, therefore we no longer need to make a copy of it. Instead, OnTabLoad() has been adapted to preserve the formdata if it is needed for restoring later on. MozReview-Commit-ID: D9fQxtVnuZe
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -243,18 +243,18 @@ SessionStore.prototype = {
         this.onTabLoad(window, browser);
         break;
       }
       case "load": {
         // Handle restoring the text data into the content and frames. We wait
         // until the main content and all frames are loaded before trying to
         // restore the text data.
         let browser = aEvent.currentTarget;
-        if (browser.__SS_restore_data) {
-          this._restoreTextData(browser.__SS_restore_data, browser);
+        if (browser.__SS_restore_text_data) {
+          this._restoreTextData(browser.__SS_data.formdata, browser);
         }
         break;
       }
       case "change":
       case "input":
       case "DOMAutoComplete": {
         let browser = aEvent.currentTarget;
         this.onTabInput(window, browser);
@@ -407,18 +407,30 @@ SessionStore.prototype = {
           index--;
         continue;
       }
       let entry = this._serializeHistoryEntry(historyEntry);
       entries.push(entry);
     }
     let data = { entries: entries, index: index };
 
+    let formdata;
+    if (aBrowser.__SS_data) {
+      formdata = aBrowser.__SS_data.formdata;
+    }
     delete aBrowser.__SS_data;
+
     this._collectTabData(aWindow, aBrowser, data);
+    if (aBrowser.__SS_restore_text_data) {
+      // If the tab has been freshly restored and the "load" event
+      // hasn't yet fired, we need to restore any form data that
+      // might have been present.
+      aBrowser.__SS_data.formdata = formdata;
+    }
+
     this.saveStateDelayed();
 
     this._updateCrashReportURL(aWindow);
   },
 
   onTabSelect: function ss_onTabSelect(aWindow, aBrowser) {
     if (this._loadState != STATE_RUNNING)
       return;
@@ -1012,18 +1024,17 @@ SessionStore.prototype = {
     if (!aTabData || aTabData.entries.length == 0) {
       Cu.reportError("SessionStore.js: Error trying to restore tab with empty tabdata");
       return;
     }
     this._restoreHistory(aTabData, aBrowser.sessionHistory);
 
     // Restoring the text data requires waiting for the content to load. So
     // we set a flag and delay this until the "load" event.
-    //this._restoreTextData(aTabData, aBrowser);
-    aBrowser.__SS_restore_data = aTabData;
+    aBrowser.__SS_restore_text_data = true;
   },
 
   /**
   * Takes serialized history data and create news entries into the given
   * nsISessionHistory object.
   */
   _restoreHistory: function ss_restoreHistory(aTabData, aHistory) {
     if (aHistory.count > 0) {
@@ -1053,22 +1064,21 @@ SessionStore.prototype = {
     } catch (e) {
       // This will throw if the current entry is an error page.
     }
   },
 
   /**
   * Takes serialized form text data and restores it into the given browser.
   */
-  _restoreTextData: function ss_restoreTextData(aTabData, aBrowser) {
-    let formdata = aTabData.formdata;
-    if (formdata) {
-      FormData.restoreTree(aBrowser.contentWindow, formdata);
+  _restoreTextData: function ss_restoreTextData(aFormData, aBrowser) {
+    if (aFormData) {
+      FormData.restoreTree(aBrowser.contentWindow, aFormData);
     }
-    delete aBrowser.__SS_restore_data;
+    delete aBrowser.__SS_restore_text_data;
   },
 
   getBrowserState: function ss_getBrowserState() {
     return this._getCurrentState();
   },
 
   _restoreWindow: function ss_restoreWindow(aData) {
     let state;