Bug 1031303 - mContext can be null when nsGlobalWindow::SetNewDocument is called, r=jst

This commit is contained in:
Olli Pettay 2014-07-31 23:15:57 +03:00
parent d7c06606cf
commit 53cb1f1d85
3 changed files with 35 additions and 16 deletions

View File

@ -6630,6 +6630,7 @@ nsDocShell::Embed(nsIContentViewer * aContentViewer,
PersistLayoutHistoryState();
nsresult rv = SetupNewViewer(aContentViewer);
NS_ENSURE_SUCCESS(rv, rv);
// If we are loading a wyciwyg url from history, change the base URI for
// the document to the original http url that created the document.write().
@ -7327,6 +7328,8 @@ nsDocShell::EnsureContentViewer()
nsresult rv = CreateAboutBlankContentViewer(principal, baseURI);
NS_ENSURE_STATE(mContentViewer);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIDocument> doc(GetDocument());
NS_ASSERTION(doc,
@ -7355,6 +7358,7 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
if (mCreatingDocument)
return NS_ERROR_FAILURE;
AutoRestore<bool> creatingDocument(mCreatingDocument);
mCreatingDocument = true;
// mContentViewer->PermitUnload may release |this| docshell.
@ -7441,14 +7445,14 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
// hook 'em up
if (viewer) {
viewer->SetContainer(this);
Embed(viewer, "", 0);
rv = Embed(viewer, "", 0);
NS_ENSURE_SUCCESS(rv, rv);
SetCurrentURI(blankDoc->GetDocumentURI(), nullptr, true, 0);
rv = mIsBeingDestroyed ? NS_ERROR_NOT_AVAILABLE : NS_OK;
}
}
}
mCreatingDocument = false;
// The transient about:blank viewer doesn't have a session history entry.
SetHistoryEntry(&mOSHE, nullptr);
@ -8658,7 +8662,7 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
if (NS_FAILED(mContentViewer->Init(widget, bounds))) {
mContentViewer = nullptr;
NS_ERROR("ContentViewer Initialization failed");
NS_WARNING("ContentViewer Initialization failed");
return NS_ERROR_FAILURE;
}
@ -8704,6 +8708,7 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
nsresult
nsDocShell::SetDocCurrentStateObj(nsISHEntry *shEntry)
{
NS_ENSURE_STATE(mContentViewer);
nsCOMPtr<nsIDocument> document = GetDocument();
NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);

View File

@ -2338,6 +2338,9 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
NS_PRECONDITION(IsOuterWindow(), "Must only be called on outer windows");
// Bail out early if we're in process of closing down the window.
NS_ENSURE_STATE(!mCleanedUp);
if (IsFrozen()) {
// This outer is now getting its first inner, thaw the outer now
// that it's ready and is getting an inner window.

View File

@ -893,7 +893,11 @@ nsDocumentViewer::InitInternal(nsIWidget* aParentWidget,
if (window) {
nsCOMPtr<nsIDocument> curDoc = window->GetExtantDoc();
if (aForceSetNewDocument || curDoc != mDocument) {
window->SetNewDocument(mDocument, aState, false);
rv = window->SetNewDocument(mDocument, aState, false);
if (NS_FAILED(rv)) {
Destroy();
return rv;
}
nsJSContext::LoadStart();
}
}
@ -1795,16 +1799,6 @@ nsDocumentViewer::SetDocumentInternal(nsIDocument* aDocument,
mDocument->SetScriptGlobalObject(nullptr);
mDocument->Destroy();
}
// Replace the old document with the new one. Do this only when
// the new document really is a new document.
mDocument = aDocument;
// Set the script global object on the new document
nsCOMPtr<nsPIDOMWindow> window =
mContainer ? mContainer->GetWindow() : nullptr;
if (window) {
window->SetNewDocument(aDocument, nullptr, aForceReuseInnerWindow);
}
// Clear the list of old child docshells. Child docshells for the new
// document will be constructed as frames are created.
@ -1820,6 +1814,22 @@ nsDocumentViewer::SetDocumentInternal(nsIDocument* aDocument,
}
}
}
// Replace the old document with the new one. Do this only when
// the new document really is a new document.
mDocument = aDocument;
// Set the script global object on the new document
nsCOMPtr<nsPIDOMWindow> window =
mContainer ? mContainer->GetWindow() : nullptr;
if (window) {
nsresult rv = window->SetNewDocument(aDocument, nullptr,
aForceReuseInnerWindow);
if (NS_FAILED(rv)) {
Destroy();
return rv;
}
}
}
nsresult rv = SyncParentSubDocMap();
@ -1835,7 +1845,7 @@ nsDocumentViewer::SetDocumentInternal(nsIDocument* aDocument,
DestroyPresContext();
mWindow = nullptr;
InitInternal(mParentWidget, nullptr, mBounds, true, true, false);
rv = InitInternal(mParentWidget, nullptr, mBounds, true, true, false);
}
return rv;
@ -4377,7 +4387,8 @@ NS_IMETHODIMP nsDocumentViewer::SetPageMode(bool aPageMode, nsIPrintSettings* aP
nsresult rv = mPresContext->Init(mDeviceContext);
NS_ENSURE_SUCCESS(rv, rv);
}
InitInternal(mParentWidget, nullptr, mBounds, true, false);
NS_ENSURE_SUCCESS(InitInternal(mParentWidget, nullptr, mBounds, true, false),
NS_ERROR_FAILURE);
Show();
return NS_OK;