From 643b881db42891a3b37e5e261d9ff086055262c4 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 1 May 2007 19:11:28 +0000 Subject: [PATCH] Switch order around a bit to be safer. Followup to bug 379093, r+sr=roc git-svn-id: svn://10.0.0.236/trunk@225397 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsDocumentViewer.cpp | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index a1607c092a0..e43fb33bc68 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -1012,6 +1012,22 @@ DocumentViewerImpl::DumpContentToPPM(const char* aFileName) NS_IMETHODIMP DocumentViewerImpl::LoadComplete(nsresult aStatus) { + /* We need to protect ourself against auto-destruction in case the + window is closed while processing the OnLoad event. See bug + http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more + explanation. + */ + nsCOMPtr kungFuDeathGrip(this); + + // Flush out layout so it's up-to-date by the time onload is called. + // Note that this could destroy the window, so do this before + // checking for our mDocument and its window. + if (mPresShell && !mStopped) { + // Hold strong ref because this could conceivably run script + nsCOMPtr shell = mPresShell; + shell->FlushPendingNotifications(Flush_Layout); + } + nsresult rv = NS_OK; NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); @@ -1023,20 +1039,6 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) mLoaded = PR_TRUE; - /* We need to protect ourself against auto-destruction in case the - window is closed while processing the OnLoad event. See bug - http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more - explanation. - */ - nsCOMPtr kungFuDeathGrip(this); - - // Flush out layout so it's up-to-date by the time onload is called - if (mPresShell && !mStopped) { - // Hold strong ref because this could conceivably run script - nsCOMPtr shell = mPresShell; - shell->FlushPendingNotifications(Flush_Layout); - } - // Now, fire either an OnLoad or OnError event to the document... PRBool restoring = PR_FALSE; if(NS_SUCCEEDED(aStatus)) {