From b852ebcc9cb7a0abad726479a8cbe3fe85370144 Mon Sep 17 00:00:00 2001 From: "akhil.arora%sun.com" Date: Mon, 22 Nov 1999 22:05:31 +0000 Subject: [PATCH] 19305 r=akhil.arora fix=Denis Sharypov Use QI to check for nsIWebShell before casting. Safer. --- java/dom/nsJavaDOMImpl.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/java/dom/nsJavaDOMImpl.cpp b/java/dom/nsJavaDOMImpl.cpp index 94a01731bc4..0f720b121a8 100755 --- a/java/dom/nsJavaDOMImpl.cpp +++ b/java/dom/nsJavaDOMImpl.cpp @@ -43,6 +43,7 @@ static char* strip_whitespace(const PRUnichar* input, int length); static const char* describe_type(int type); #endif +static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID); static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); @@ -238,15 +239,18 @@ PRBool nsJavaDOMImpl::Cleanup() nsIDOMDocument* nsJavaDOMImpl::GetDocument(nsIDocumentLoader* loader) { - nsIWebShell* container = nsnull; + nsIWebShell* webshell = nsnull; + nsISupports* container = nsnull; nsIContentViewer* contentv = nsnull; nsIDocumentViewer* docv = nsnull; nsIDocument* document = nsnull; nsIDOMDocument* domDoc = nsnull; - nsresult rv = loader->GetContainer((nsISupports**)&container); + nsresult rv = loader->GetContainer(&container); if (NS_SUCCEEDED(rv) && container) - rv = container->GetContentViewer(&contentv); + rv = container->QueryInterface(kIWebShellIID, (void**) &webshell); + if (NS_SUCCEEDED(rv) && webshell) + rv = webshell->GetContentViewer(&contentv); if (NS_SUCCEEDED(rv) && contentv) { rv = contentv->QueryInterface(kIDocumentViewerIID, @@ -263,11 +267,16 @@ nsIDOMDocument* nsJavaDOMImpl::GetDocument(nsIDocumentLoader* loader) fprintf(stderr, "nsJavaDOMImpl::GetDocument: failed: " - "container=%x, contentViewer=%x, documentViewer=%x, document=%x, " + "container=%x, webshell=%x, contentViewer=%x, " + "documentViewer=%x, document=%x, " "domDocument=%x, error=%x\n", - (unsigned) (void*) container, (unsigned) (void*) contentv, - (unsigned) (void*) docv, (unsigned) (void*) document, - (unsigned) (void*) domDoc, rv); + (unsigned) (void*) container, + (unsigned) (void*) webshell, + (unsigned) (void*) contentv, + (unsigned) (void*) docv, + (unsigned) (void*) document, + (unsigned) (void*) domDoc, + rv); return NULL; }