Bug 551505 - Fix context of RestoreDocument_proxy [r=zeniko]

This commit is contained in:
Paul O’Shannessy 2010-03-15 10:51:10 -07:00
Родитель 2f37954183
Коммит 4b8f322fb5
1 изменённых файлов: 28 добавлений и 27 удалений

Просмотреть файл

@ -551,6 +551,12 @@ SessionStoreService.prototype = {
var win = aEvent.currentTarget.ownerDocument.defaultView; var win = aEvent.currentTarget.ownerDocument.defaultView;
switch (aEvent.type) { switch (aEvent.type) {
case "load": case "load":
// If __SS_restore_data is set, then we need to restore the document
// (form data, scrolling, etc.). This will only happen when a tab is
// first restored.
if (aEvent.currentTarget.__SS_restore_data)
this.restoreDocument(win, aEvent.currentTarget, aEvent);
// We still need to call onTabLoad, so fall through to "pageshow" case.
case "pageshow": case "pageshow":
this.onTabLoad(win, aEvent.currentTarget, aEvent); this.onTabLoad(win, aEvent.currentTarget, aEvent);
break; break;
@ -2143,8 +2149,6 @@ SessionStoreService.prototype = {
browser.__SS_restore_data = tabData.entries[activeIndex] || {}; browser.__SS_restore_data = tabData.entries[activeIndex] || {};
browser.__SS_restore_pageStyle = tabData.pageStyle || ""; browser.__SS_restore_pageStyle = tabData.pageStyle || "";
browser.__SS_restore_tab = tab; browser.__SS_restore_tab = tab;
browser.__SS_restore = this.restoreDocument_proxy;
browser.addEventListener("load", browser.__SS_restore, true);
} }
// Handle userTypedValue. Setting userTypedValue seems to update gURLbar // Handle userTypedValue. Setting userTypedValue seems to update gURLbar
@ -2292,7 +2296,7 @@ SessionStoreService.prototype = {
/** /**
* Restore properties to a loaded document * Restore properties to a loaded document
*/ */
restoreDocument_proxy: function sss_restoreDocument_proxy(aEvent) { restoreDocument: function sss_restoreDocument(aWindow, aBrowser, aEvent) {
// wait for the top frame to be loaded completely // wait for the top frame to be loaded completely
if (!aEvent || !aEvent.originalTarget || !aEvent.originalTarget.defaultView || aEvent.originalTarget.defaultView != aEvent.originalTarget.defaultView.top) { if (!aEvent || !aEvent.originalTarget || !aEvent.originalTarget.defaultView || aEvent.originalTarget.defaultView != aEvent.originalTarget.defaultView.top) {
return; return;
@ -2340,13 +2344,12 @@ SessionStoreService.prototype = {
} }
} }
let selectedPageStyle = this.__SS_restore_pageStyle; let selectedPageStyle = aBrowser.__SS_restore_pageStyle;
let window = this.ownerDocument.defaultView;
function restoreTextDataAndScrolling(aContent, aData, aPrefix) { function restoreTextDataAndScrolling(aContent, aData, aPrefix) {
if (aData.formdata) if (aData.formdata)
restoreFormData(aContent.document, aData.formdata, aData.url); restoreFormData(aContent.document, aData.formdata, aData.url);
if (aData.innerHTML) { if (aData.innerHTML) {
window.setTimeout(function() { aWindow.setTimeout(function() {
if (aContent.document.designMode == "on" && if (aContent.document.designMode == "on" &&
hasExpectedURL(aContent.document, aData.url)) { hasExpectedURL(aContent.document, aData.url)) {
aContent.document.body.innerHTML = aData.innerHTML; aContent.document.body.innerHTML = aData.innerHTML;
@ -2369,27 +2372,25 @@ SessionStoreService.prototype = {
// don't restore text data and scrolling state if the user has navigated // don't restore text data and scrolling state if the user has navigated
// away before the loading completed (except for in-page navigation) // away before the loading completed (except for in-page navigation)
if (hasExpectedURL(aEvent.originalTarget, this.__SS_restore_data.url)) { if (hasExpectedURL(aEvent.originalTarget, aBrowser.__SS_restore_data.url)) {
var content = aEvent.originalTarget.defaultView; var content = aEvent.originalTarget.defaultView;
if (this.currentURI.spec == "about:config") { if (aBrowser.currentURI.spec == "about:config") {
// unwrap the document for about:config because otherwise the properties // unwrap the document for about:config because otherwise the properties
// of the XBL bindings - as the textbox - aren't accessible (see bug 350718) // of the XBL bindings - as the textbox - aren't accessible (see bug 350718)
content = content.wrappedJSObject; content = content.wrappedJSObject;
} }
restoreTextDataAndScrolling(content, this.__SS_restore_data, ""); restoreTextDataAndScrolling(content, aBrowser.__SS_restore_data, "");
this.markupDocumentViewer.authorStyleDisabled = selectedPageStyle == "_nostyle"; aBrowser.markupDocumentViewer.authorStyleDisabled = selectedPageStyle == "_nostyle";
// notify the tabbrowser that this document has been completely restored // notify the tabbrowser that this document has been completely restored
var event = this.ownerDocument.createEvent("Events"); var event = aBrowser.ownerDocument.createEvent("Events");
event.initEvent("SSTabRestored", true, false); event.initEvent("SSTabRestored", true, false);
this.__SS_restore_tab.dispatchEvent(event); aBrowser.__SS_restore_tab.dispatchEvent(event);
} }
this.removeEventListener("load", this.__SS_restore, true); delete aBrowser.__SS_restore_data;
delete this.__SS_restore_data; delete aBrowser.__SS_restore_pageStyle;
delete this.__SS_restore_pageStyle; delete aBrowser.__SS_restore_tab;
delete this.__SS_restore_tab;
delete this.__SS_restore;
}, },
/** /**