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
--- 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;