From d11d5d871b0eeffa4aa7cab9f49acee3d82b1e2f Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 1 Aug 2002 23:44:40 +0000 Subject: [PATCH] Add a nullcheck for the parentDocshell, since the parent window might get closed out from under us. Bug 160590, r=sicking, sr=jst, a=asa --- .../windowwatcher/src/nsWindowWatcher.cpp | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index fe3a2328834..c98ec0cc537 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -628,22 +628,24 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, if (parentSGO) { nsCOMPtr parentDocshell; parentSGO->GetDocShell(getter_AddRefs(parentDocshell)); - - nsCOMPtr parentContentViewer; - parentDocshell->GetContentViewer(getter_AddRefs(parentContentViewer)); - nsCOMPtr parentDocViewer(do_QueryInterface(parentContentViewer)); - if (parentDocViewer) { - nsCOMPtr doc; - parentDocViewer->GetDocument(*getter_AddRefs(doc)); - - nsCOMPtr newContentViewer; - newDocShell->GetContentViewer(getter_AddRefs(newContentViewer)); - nsCOMPtr newMarkupDocViewer(do_QueryInterface(newContentViewer)); - if (doc && newMarkupDocViewer) { - nsXPIDLString charset; - rv = doc->GetDocumentCharacterSet(charset); - if (NS_SUCCEEDED(rv)) - newMarkupDocViewer->SetDefaultCharacterSet(charset); + // parentDocshell may be null if the parent got closed in the meantime + if (parentDocshell) { + nsCOMPtr parentContentViewer; + parentDocshell->GetContentViewer(getter_AddRefs(parentContentViewer)); + nsCOMPtr parentDocViewer(do_QueryInterface(parentContentViewer)); + if (parentDocViewer) { + nsCOMPtr doc; + parentDocViewer->GetDocument(*getter_AddRefs(doc)); + + nsCOMPtr newContentViewer; + newDocShell->GetContentViewer(getter_AddRefs(newContentViewer)); + nsCOMPtr newMarkupDocViewer(do_QueryInterface(newContentViewer)); + if (doc && newMarkupDocViewer) { + nsXPIDLString charset; + rv = doc->GetDocumentCharacterSet(charset); + if (NS_SUCCEEDED(rv)) + newMarkupDocViewer->SetDefaultCharacterSet(charset); + } } } }