From 5d315b1ba6723e31e1ab813a03cbaf9679014935 Mon Sep 17 00:00:00 2001 From: "ashuk%eng.sun.com" Date: Wed, 23 Aug 2000 00:03:49 +0000 Subject: [PATCH] Bug = 48356 author = ashuk r = a = edburns Added checks to make sure that DocShell is valid and that calls to getInterface(nsIDOMWindow) return a valid object. --- java/webclient/src_moz/CurrentPageImpl.cpp | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/java/webclient/src_moz/CurrentPageImpl.cpp b/java/webclient/src_moz/CurrentPageImpl.cpp index efd2d72e833..7086ff08f46 100644 --- a/java/webclient/src_moz/CurrentPageImpl.cpp +++ b/java/webclient/src_moz/CurrentPageImpl.cpp @@ -97,20 +97,37 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp nsresult rv; NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_PROGID, &rv); - if (NS_FAILED(rv)) { + if (NS_FAILED(rv) || nsnull == findComponent) { initContext->initFailCode = kFindComponentError; ::util_ThrowExceptionToJava(env, "Exception: can't access FindComponent Service"); return; } - nsCOMPtr interfaceRequestor(do_QueryInterface(initContext->docShell)); nsCOMPtr domWindow; - rv = interfaceRequestor->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow)); - if (NS_FAILED(rv)) { - initContext->initFailCode = kGetDOMWindowError; - ::util_ThrowExceptionToJava(env, "Exception: cant get DOMWindow from DocShell"); - return; + if (initContext->docShell != nsnull) { + nsCOMPtr interfaceRequestor(do_QueryInterface(initContext->docShell)); + + if (interfaceRequestor != nsnull) { + rv = interfaceRequestor->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow)); + if (NS_FAILED(rv) || nsnull == domWindow) { + initContext->initFailCode = kGetDOMWindowError; + ::util_ThrowExceptionToJava(env, "Exception: cant get DOMWindow from DocShell"); + return; + } + } + else + { + initContext->initFailCode = kFindComponentError; + ::util_ThrowExceptionToJava(env, "Exception: cant get InterfaceRequestor from DocShell"); + return; + } } + else + { + initContext->initFailCode = kFindComponentError; + ::util_ThrowExceptionToJava(env, "Exception: DocShell is not initialized"); + return; + } nsCOMPtr searchContext; rv = findComponent->CreateContext(domWindow, nsnull, getter_AddRefs(searchContext));