зеркало из https://github.com/mozilla/pjs.git
Fixes to get rid of relying on webShell implementing nsIScriptContextOwner. It now implements nsIScriptGlobalObjectOwner or can do a GetInterface to nsIScriptGlobalObject.
This commit is contained in:
Родитель
aa18e4d52b
Коммит
c381b18ecd
|
@ -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<nsIWebShell> 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<nsIScriptGlobalObject> 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<nsIWebShell> 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<nsIScriptGlobalObject> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<nsIWebShell> 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<nsIScriptGlobalObject> 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<nsIWebShell> 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<nsIScriptGlobalObject> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<nsIScriptContextOwner> owner = do_QueryInterface(mWebShell);
|
||||
if (!owner)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIScriptGlobalObject> 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)
|
||||
|
|
|
@ -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<nsIScriptContextOwner> 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<nsIScriptGlobalObjectOwner> 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<nsIScriptGlobalObject> global;
|
||||
globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIWebShell> webShell;
|
||||
webShell = do_QueryInterface(owner);
|
||||
webShell = do_QueryInterface(globalOwner);
|
||||
if (!webShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
const PRUnichar* url;
|
||||
|
|
Загрузка…
Ссылка в новой задаче