commit 67b246b15740768e6cd6aed8f4178cde4f151de9
parent d82d44bd3e25f60640c289715430b773c15e176f
Author: Vincent Hilla <vhilla@mozilla.com>
Date: Tue, 6 Jan 2026 08:54:31 +0000
Bug 2003244 - Don't crash when failing to initialize docshell. r=dom-core,mccr8,smaug
Bug 543435 changed nsDocShell::Initialize from always returning true to
returning whether CreateInitialDocumentViewer succeeded. If this fails,
it is propagated up to ContentChild::RecvConstructBrowser where we crash.
The call to CreateDocumentViewerForActor that existed before bug 543435 in
nsWebBrowser::Create would've failed silently.
This commit restores avoids a crash by restoring the silent failure.
Differential Revision: https://phabricator.services.mozilla.com/D277765
Diffstat:
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
@@ -443,7 +443,11 @@ nsresult nsDocShell::InitWindow(nsIWidget* aParentWidget, int32_t aX,
mozilla::dom::WindowGlobalChild* aWindowActor) {
SetParentWidget(aParentWidget);
SetPositionAndSize(aX, aY, aWidth, aHeight, 0);
- NS_ENSURE_TRUE(Initialize(aOpenWindowInfo, aWindowActor), NS_ERROR_FAILURE);
+ if (!Initialize(aOpenWindowInfo, aWindowActor)) {
+ // Since bug 543435, Initialize can fail and propagating this would
+ // cause callers to crash when they didn't previously (bug 2003244).
+ NS_WARNING("Failed to initialize docshell");
+ }
return NS_OK;
}
diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp
@@ -1170,6 +1170,8 @@ nsresult ContentChild::ProvideWindowCommon(
// Now change the principal to what it should be according to aOpenWindowInfo.
// This creates a new document and the timing is quite fragile.
NS_ENSURE_TRUE(browsingContext->GetDOMWindow(), NS_ERROR_ABORT);
+ NS_ENSURE_TRUE(browsingContext->GetDOMWindow()->GetExtantDoc(),
+ NS_ERROR_ABORT);
browsingContext->GetDOMWindow()->SetInitialPrincipal(
aOpenWindowInfo->PrincipalToInheritForAboutBlank());
diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp
@@ -242,6 +242,7 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
NS_ENSURE_SUCCESS(mDocShell->InitWindow(mWindow, r.X(), r.Y(), r.Width(),
r.Height(), aOpenWindowInfo, nullptr),
NS_ERROR_FAILURE);
+ NS_ENSURE_TRUE(mDocShell->GetDocument(), NS_ERROR_FAILURE);
// Attach a WebProgress listener.during initialization...
mDocShell->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);