From 81afabd3d2f6ee18347a1ff069b0137a12b40c12 Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Wed, 9 Jul 2008 15:48:02 +0200 Subject: [PATCH] Deal with a dead docshell during document.open. bug 435128, r+sr=jst --- content/html/document/src/nsHTMLDocument.cpp | 56 +++++++++++++++------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index f3349acfc0..9ba307ce26 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1785,12 +1785,15 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) // check whether we're in the middle of unload. If so, ignore this call. nsCOMPtr shell = do_QueryReferent(mDocumentContainer); - if (shell) { - PRBool inUnload; - shell->GetIsInUnload(&inUnload); - if (inUnload) { - return NS_OK; - } + if (!shell) { + // We won't be able to create a parser anyway. + return NS_OK; + } + + PRBool inUnload; + shell->GetIsInUnload(&inUnload); + if (inUnload) { + return NS_OK; } // Note: We want to use GetDocumentFromContext here because this document @@ -1846,12 +1849,10 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) NS_ENSURE_SUCCESS(rv, rv); } - nsCOMPtr docshell = do_QueryReferent(mDocumentContainer); - // Stop current loads targeted at the window this document is in. - if (mScriptGlobalObject && docshell) { + if (mScriptGlobalObject) { nsCOMPtr cv; - docshell->GetContentViewer(getter_AddRefs(cv)); + shell->GetContentViewer(getter_AddRefs(cv)); if (cv) { PRBool okToUnload; @@ -1864,7 +1865,7 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) } } - nsCOMPtr webnav(do_QueryInterface(docshell)); + nsCOMPtr webnav(do_QueryInterface(shell)); webnav->Stop(nsIWebNavigation::STOP_NETWORK); } @@ -1997,30 +1998,33 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) if (NS_SUCCEEDED(rv)) { nsCOMPtr sink; - rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, uri, docshell, + rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, uri, shell, channel); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + // Don't use a parser without a content sink. + mParser = nsnull; + mWriteState = eNotWriting; + return rv; + } mParser->SetContentSink(sink); } // Prepare the docshell and the document viewer for the impending // out of band document.write() - if (docshell) { - docshell->PrepareForNewContentModel(); + shell->PrepareForNewContentModel(); - // Now check whether we were opened with a "replace" argument. If - // so, we need to tell the docshell to not create a new history - // entry for this load. Otherwise, make sure that we're doing a normal load, - // not whatever type of load was previously done on this docshell. - docshell->SetLoadType(aReplace ? LOAD_NORMAL_REPLACE : LOAD_NORMAL); + // Now check whether we were opened with a "replace" argument. If + // so, we need to tell the docshell to not create a new history + // entry for this load. Otherwise, make sure that we're doing a normal load, + // not whatever type of load was previously done on this docshell. + shell->SetLoadType(aReplace ? LOAD_NORMAL_REPLACE : LOAD_NORMAL); - nsCOMPtr cv; - docshell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr docViewer = do_QueryInterface(cv); - if (docViewer) { - docViewer->LoadStart(static_cast(this)); - } + nsCOMPtr cv; + shell->GetContentViewer(getter_AddRefs(cv)); + nsCOMPtr docViewer = do_QueryInterface(cv); + if (docViewer) { + docViewer->LoadStart(static_cast(this)); } // Add a wyciwyg channel request into the document load group -- 2.11.4.GIT