From c381b18ecd36edc7f90cc6b7c3e66b74145c8758 Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Fri, 3 Dec 1999 19:02:31 +0000 Subject: [PATCH] Fixes to get rid of relying on webShell implementing nsIScriptContextOwner. It now implements nsIScriptGlobalObjectOwner or can do a GetInterface to nsIScriptGlobalObject. --- dom/src/base/nsDOMWindowList.cpp | 50 ++++++++------------------- dom/src/base/nsFrameList.cpp | 47 +++++++------------------ dom/src/base/nsLocation.cpp | 21 +++++------ dom/src/jsurl/nsJSProtocolHandler.cpp | 23 ++++++------ 4 files changed, 48 insertions(+), 93 deletions(-) diff --git a/dom/src/base/nsDOMWindowList.cpp b/dom/src/base/nsDOMWindowList.cpp index 8f38ac79c62..d44f69e5e88 100644 --- a/dom/src/base/nsDOMWindowList.cpp +++ b/dom/src/base/nsDOMWindowList.cpp @@ -20,16 +20,16 @@ * Contributor(s): */ +#include "nsCOMPtr.h" #include "nsDOMWindowList.h" #include "nsIWebShell.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" +#include "nsIInterfaceRequestor.h" static NS_DEFINE_IID(kIDOMWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kIDOMWindowIID, NS_IDOMWINDOW_IID); nsDOMWindowList::nsDOMWindowList(nsIWebShell *aWebShell) @@ -94,54 +94,34 @@ nsDOMWindowList::GetLength(PRUint32* aLength) NS_IMETHODIMP nsDOMWindowList::Item(PRUint32 aIndex, nsIDOMWindow** aReturn) { - nsIWebShell *mItem; - nsresult ret; + nsCOMPtr item; - mWebShell->ChildAt(aIndex, mItem); + mWebShell->ChildAt(aIndex, *getter_AddRefs(item)); - if (nsnull != mItem) { - nsIScriptContextOwner *mItemContextOwner; - if (NS_OK == mItem->QueryInterface(kIScriptContextOwnerIID, (void**)&mItemContextOwner)) { - nsIScriptGlobalObject *mItemGlobalObject; - if (NS_OK == mItemContextOwner->GetScriptGlobalObject(&mItemGlobalObject)) { - ret = mItemGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aReturn); - NS_RELEASE(mItemGlobalObject); - } - NS_RELEASE(mItemContextOwner); - } - NS_RELEASE(mItem); - } - else { + nsCOMPtr globalObject(do_GetInterface(item)); + if (NS_WARN_IF_FALSE(globalObject, "Couldn't get to the globalObject")) { *aReturn = nsnull; } - + else { + CallQueryInterface(globalObject.get(), aReturn); + } return NS_OK; } NS_IMETHODIMP nsDOMWindowList::NamedItem(const nsString& aName, nsIDOMWindow** aReturn) { - nsIWebShell *mItem; - nsresult ret; - - mWebShell->FindChildWithName(aName.GetUnicode(), mItem); + nsCOMPtr item; - if (nsnull != mItem) { - nsIScriptContextOwner *mItemContextOwner; - if (NS_OK == mItem->QueryInterface(kIScriptContextOwnerIID, (void**)&mItemContextOwner)) { - nsIScriptGlobalObject *mItemGlobalObject; - if (NS_OK == mItemContextOwner->GetScriptGlobalObject(&mItemGlobalObject)) { - ret = mItemGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aReturn); - NS_RELEASE(mItemGlobalObject); - } - NS_RELEASE(mItemContextOwner); - } - NS_RELEASE(mItem); + mWebShell->FindChildWithName(aName.GetUnicode(), *getter_AddRefs(item)); + + nsCOMPtr globalObject(do_GetInterface(item)); + if (NS_WARN_IF_FALSE(globalObject, "Couldn't get to the globalObject")) { + CallQueryInterface(globalObject.get(), aReturn); } else { *aReturn = nsnull; } - return NS_OK; } diff --git a/dom/src/base/nsFrameList.cpp b/dom/src/base/nsFrameList.cpp index e551c6b6a25..eabc94fce2a 100644 --- a/dom/src/base/nsFrameList.cpp +++ b/dom/src/base/nsFrameList.cpp @@ -22,7 +22,6 @@ #include "nsFrameList.h" #include "nsIWebShell.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" @@ -94,54 +93,34 @@ nsFrameList::GetLength(PRUint32* aLength) NS_IMETHODIMP nsFrameList::Item(PRUint32 aIndex, nsIDOMWindow** aReturn) { - nsIWebShell *mItem; - nsresult ret; + nsCOMPtr item; - mWebShell->ChildAt(aIndex, mItem); + mWebShell->ChildAt(aIndex, *getter_AddRefs(item)); - if (nsnull != mItem) { - nsIScriptContextOwner *mItemContextOwner; - if (NS_OK == mItem->QueryInterface(kIScriptContextOwnerIID, (void**)&mItemContextOwner)) { - nsIScriptGlobalObject *mItemGlobalObject; - if (NS_OK == mItemContextOwner->GetScriptGlobalObject(&mItemGlobalObject)) { - ret = mItemGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aReturn); - NS_RELEASE(mItemGlobalObject); - } - NS_RELEASE(mItemContextOwner); - } - NS_RELEASE(mItem); - } - else { + nsCOMPtr globalObject(do_GetInterface(item)); + if (NS_WARN_IF_FALSE(globalObject, "Couldn't get to the globalObject")) { *aReturn = nsnull; } - + else { + CallQueryInterface(globalObject.get(), aReturn); + } return NS_OK; } NS_IMETHODIMP nsFrameList::NamedItem(const nsString& aName, nsIDOMWindow** aReturn) { - nsIWebShell *mItem; - nsresult ret; - - mWebShell->FindChildWithName(aName.GetUnicode(), mItem); + nsCOMPtr item; - if (nsnull != mItem) { - nsIScriptContextOwner *mItemContextOwner; - if (NS_OK == mItem->QueryInterface(kIScriptContextOwnerIID, (void**)&mItemContextOwner)) { - nsIScriptGlobalObject *mItemGlobalObject; - if (NS_OK == mItemContextOwner->GetScriptGlobalObject(&mItemGlobalObject)) { - ret = mItemGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aReturn); - NS_RELEASE(mItemGlobalObject); - } - NS_RELEASE(mItemContextOwner); - } - NS_RELEASE(mItem); + mWebShell->FindChildWithName(aName.GetUnicode(), *getter_AddRefs(item)); + + nsCOMPtr globalObject(do_GetInterface(item)); + if (NS_WARN_IF_FALSE(globalObject, "Couldn't get to the globalObject")) { + CallQueryInterface(globalObject.get(), aReturn); } else { *aReturn = nsnull; } - return NS_OK; } diff --git a/dom/src/base/nsLocation.cpp b/dom/src/base/nsLocation.cpp index c947e1e5f2e..710587d0eac 100644 --- a/dom/src/base/nsLocation.cpp +++ b/dom/src/base/nsLocation.cpp @@ -33,7 +33,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsCOMPtr.h" #include "nsJSUtils.h" #include "nsIScriptSecurityManager.h" -#include "nsIScriptContextOwner.h" #include "nsIJSContextStack.h" static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); @@ -102,20 +101,16 @@ LocationImpl::SetScriptObject(void *aScriptObject) nsresult LocationImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { - NS_PRECONDITION(nsnull != aScriptObject, "null arg"); - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsCOMPtr owner = do_QueryInterface(mWebShell); - if (!owner) - return NS_ERROR_NO_INTERFACE; - nsCOMPtr global; - if (NS_FAILED(res = owner->GetScriptGlobalObject(getter_AddRefs(global)))) - return res; - res = NS_NewScriptLocation(aContext, (nsISupports *)(nsIDOMLocation *)this, global, &mScriptObject); + NS_ENSURE_ARG_POINTER(aScriptObject); + + if (!mScriptObject) { + nsCOMPtr global(do_GetInterface(mWebShell)); + NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); + return NS_NewScriptLocation(aContext, NS_STATIC_CAST(nsIDOMLocation*, this), + global, &mScriptObject); } - *aScriptObject = mScriptObject; - return res; + return NS_OK; } NS_IMETHODIMP_(void) diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index 2c1eeebb3a8..0ba9d0bac9d 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -31,8 +31,8 @@ #include "nsIStringStream.h" #include "nsIURI.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptGlobalObjectData.h" #include "nsJSProtocolHandler.h" #include "nsIPrincipal.h" @@ -202,18 +202,19 @@ nsJSProtocolHandler::NewChannel(const char* verb, nsresult rv; - // The event sink must be a script context owner or we fail. - nsCOMPtr owner; - rv = notificationCallbacks->GetInterface(NS_GET_IID(nsIScriptContextOwner), - getter_AddRefs(owner)); - if (NS_FAILED(rv)) - return rv; - if (!owner) - return NS_ERROR_FAILURE; + // The event sink must be a script global Object Owner or we fail. + nsCOMPtr globalOwner; + notificationCallbacks->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), + getter_AddRefs(globalOwner)); + NS_ENSURE_TRUE(globalOwner, NS_ERROR_FAILURE); // So far so good: get the script context from its owner. + nsCOMPtr global; + globalOwner->GetScriptGlobalObject(getter_AddRefs(global)); + NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); + nsCOMPtr scriptContext; - rv = owner->GetScriptContext(getter_AddRefs(scriptContext)); + rv = global->GetContext(getter_AddRefs(scriptContext)); if (NS_FAILED(rv)) return rv; @@ -230,7 +231,7 @@ nsJSProtocolHandler::NewChannel(const char* verb, if (!principal) { // No scripts currently executing; get principal from referrer of link nsCOMPtr webShell; - webShell = do_QueryInterface(owner); + webShell = do_QueryInterface(globalOwner); if (!webShell) return NS_ERROR_FAILURE; const PRUnichar* url;