diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 71bd1c99d90..c6b802ffbf5 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -4838,6 +4838,9 @@ nsDocument::Destroy() { // The ContentViewer wants to release the document now. So, tell our content // to drop any references to the document so that it can be destroyed. + if (mIsGoingAway) + return; + PRInt32 count = mChildren.Count(); mIsGoingAway = PR_TRUE; diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index b242a895dda..5e6c3a7d08b 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -3392,7 +3392,7 @@ nsDocShell::Destroy() docShellParentAsNode->RemoveChild(this); if (mContentViewer) { - mContentViewer->Close(); + mContentViewer->Close(nsnull); mContentViewer->Destroy(); mContentViewer = nsnull; } @@ -5053,11 +5053,7 @@ nsDocShell::RestorePresentation(nsISHEntry *aSHEntry, PRBool aSavePresentation, mFiredUnloadEvent = PR_FALSE; if (mContentViewer) { - mContentViewer->Close(); - - if (aSavePresentation) - mContentViewer->SetHistoryEntry(mOSHE); - + mContentViewer->Close(aSavePresentation ? mOSHE : nsnull); mContentViewer->Destroy(); } @@ -5572,15 +5568,11 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) } } - mContentViewer->Close(); + // Tell the old content viewer to hibernate in session history when + // it is destroyed. + mContentViewer->Close(mSavingOldViewer ? mOSHE : nsnull); aNewViewer->SetPreviousViewer(mContentViewer); - if (mSavingOldViewer) { - // Tell the old content viewer to hibernate in session history when - // it is destroyed. - mContentViewer->SetHistoryEntry(mOSHE); - } - mContentViewer = nsnull; } diff --git a/mozilla/docshell/base/nsIContentViewer.idl b/mozilla/docshell/base/nsIContentViewer.idl index b9355d8aef0..5359b8dedd8 100644 --- a/mozilla/docshell/base/nsIContentViewer.idl +++ b/mozilla/docshell/base/nsIContentViewer.idl @@ -14,7 +14,7 @@ struct nsRect; [ptr] native nsIDeviceContextPtr(nsIDeviceContext); [ref] native nsRectRef(nsRect); -[scriptable, uuid(e2c68a4d-b396-11d9-a3d1-00112478d626)] +[scriptable, uuid(456651af-14ca-4f8d-91a3-c7cdd7e7eef6)] interface nsIContentViewer : nsISupports { @@ -36,8 +36,21 @@ interface nsIContentViewer : nsISupports * close() should be called when the load of a new page for the next * content viewer begins, and destroy() should be called when the next * content viewer replaces this one. + * + * |historyEntry| sets the session history entry for the content viewer. If + * this is null, then Destroy() will be called on the document by close(). + * If it is non-null, the document will not be destroyed, and the following + * actions will happen when destroy() is called (*): + * - Sanitize() will be called on the viewer's document + * - The content viewer will set the contentViewer property on the + * history entry, and release its reference (ownership reversal). + * - hide() will be called, and no further destruction will happen. + * + * (*) unless the document is currently being printed, in which case + * it will never be saved in session history. + * */ - void close(); + void close(in nsISHEntry historyEntry); void destroy(); void stop(); @@ -76,15 +89,8 @@ interface nsIContentViewer : nsISupports void open(); /** - * Set the session history entry for the content viewer. If this is set, - * then the following actions will happen when destroy() is called (*): - * - Sanitize() will be called on the viewer's document - * - The content viewer will set the contentViewer property on the - * history entry, and release its reference (ownership reversal). - * - hide() will be called, and no further destruction will happen. - * - * (*) unless the document is currently being printed, in which case - * it will never be saved in session history. + * Clears the current history entry. This is used if we need to clear out + * the saved presentation state. */ - void setHistoryEntry(in nsISHEntry entry); + void clearHistoryEntry(); }; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 13b0f7593e8..b88a1219350 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -518,7 +518,7 @@ NS_IMPL_ISUPPORTS7(DocumentViewerImpl, DocumentViewerImpl::~DocumentViewerImpl() { if (mDocument) { - Close(); + Close(nsnull); mDocument->Destroy(); } @@ -1206,13 +1206,15 @@ DocumentViewerImpl::Open() } NS_IMETHODIMP -DocumentViewerImpl::Close() +DocumentViewerImpl::Close(nsISHEntry *aSHEntry) { // All callers are supposed to call close to break circular // references. If we do this stuff in the destructor, the // destructor might never be called (especially if we're being // used from JS. + mSHEntry = aSHEntry; + // Close is also needed to disable scripts during paint suppression, // since we transfer the existing global object to the new document // that is loaded. In the future, the global object may become a proxy @@ -1251,6 +1253,9 @@ DocumentViewerImpl::Close() { // out of band cleanup of webshell mDocument->SetScriptGlobalObject(nsnull); + + if (!mSHEntry) + mDocument->Destroy(); } if (mFocusListener) { @@ -1893,13 +1898,6 @@ DocumentViewerImpl::SetSticky(PRBool aSticky) return NS_OK; } -NS_IMETHODIMP -DocumentViewerImpl::SetHistoryEntry(nsISHEntry *aEntry) -{ - mSHEntry = aEntry; - return NS_OK; -} - NS_IMETHODIMP DocumentViewerImpl::GetEnableRendering(PRBool* aResult) { @@ -2046,6 +2044,12 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, return NS_OK; } +NS_IMETHODIMP +DocumentViewerImpl::ClearHistoryEntry() +{ + mSHEntry = nsnull; + return NS_OK; +} //------------------------------------------------------- @@ -4041,6 +4045,7 @@ DocumentViewerImpl::OnDonePrinting() } else if (mClosingWhilePrinting) { if (mDocument) { mDocument->SetScriptGlobalObject(nsnull); + mDocument->Destroy(); mDocument = nsnull; } mClosingWhilePrinting = PR_FALSE; diff --git a/mozilla/layout/base/nsIDocumentViewer.h b/mozilla/layout/base/nsIDocumentViewer.h index c7d8309f67d..a8e3f0fbb99 100644 --- a/mozilla/layout/base/nsIDocumentViewer.h +++ b/mozilla/layout/base/nsIDocumentViewer.h @@ -45,7 +45,7 @@ class nsIPresShell; class nsIStyleSheet; #define NS_IDOCUMENT_VIEWER_IID \ - { 0x09ad1126, 0xb397, 0x11d9,{0xa5, 0x2c, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26}} + { 0x7e7a579e, 0xfa46, 0x4daf,{0xb7, 0xc6, 0x45, 0x69, 0xd3, 0xb5, 0x30, 0x05}} /** * A document viewer is a kind of content viewer that uses NGLayout