From eb96099e6dafa92e3a4c2e8c2fe79bae6d5b2066 Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Fri, 3 Dec 1999 09:24:22 +0000 Subject: [PATCH] 1.) WebShell no longer implements nsIScriptContextOwner. 2.) WebShell now implements the new nsIScriptGlobalObjectOwner. 3.) WebShell supports GetInterface to nsIScriptGlobalObject. 4.) Documents no longer carry around a reference to nsIScriptContextOwner. Instead they hold on to a nsIScriptGlobalObject. nsIDocument::GetScriptContextOwner has now become nsIDocument::GetScriptGlobalObject(). Same change to the set methods. --- content/base/public/nsIDocument.h | 6 +- content/base/src/nsDocument.cpp | 93 +++------ content/base/src/nsDocument.h | 8 +- content/base/src/nsDocumentViewer.cpp | 27 +-- content/base/src/nsGenericDOMDataNode.cpp | 24 +-- content/base/src/nsGenericElement.cpp | 34 ++-- content/base/src/nsRange.cpp | 4 +- content/events/src/nsEventStateManager.cpp | 37 +--- .../html/content/src/nsAttributeContent.cpp | 1 - .../html/content/src/nsGenericHTMLElement.cpp | 1 - .../html/content/src/nsHTMLFormElement.cpp | 11 +- .../html/document/src/nsHTMLContentSink.cpp | 138 +++++-------- content/html/document/src/nsHTMLDocument.cpp | 13 +- content/xml/document/src/nsXMLContentSink.cpp | 20 +- content/xul/content/src/nsXULElement.cpp | 41 ++-- .../xul/content/src/nsXULPopupListener.cpp | 11 +- .../document/src/nsXULCommandDispatcher.cpp | 6 +- content/xul/document/src/nsXULContentSink.cpp | 2 - content/xul/document/src/nsXULControllers.cpp | 1 - content/xul/document/src/nsXULDocument.cpp | 87 +++----- content/xul/document/src/nsXULDocument.h | 7 +- .../templates/src/nsXULTemplateBuilder.cpp | 17 +- docshell/base/MANIFEST_IDL | 1 + docshell/base/Makefile.in | 1 + docshell/base/makefile.win | 1 + docshell/base/nsCDocShell.idl | 2 +- docshell/base/nsDocShell.cpp | 38 ++-- docshell/base/nsDocShell.h | 10 +- docshell/base/nsWebShell.cpp | 189 ++++++++---------- dom/public/nsIScriptGlobalObject.h | 30 ++- dom/src/base/nsGlobalWindow.cpp | 123 ++++++------ dom/src/base/nsGlobalWindow.h | 15 +- dom/src/base/nsJSEnvironment.cpp | 37 ++-- layout/base/nsDocumentViewer.cpp | 27 +-- layout/base/public/nsIDocument.h | 6 +- layout/base/src/nsDocument.cpp | 93 +++------ layout/base/src/nsDocument.h | 8 +- layout/base/src/nsDocumentViewer.cpp | 27 +-- layout/base/src/nsGenericDOMDataNode.cpp | 24 +-- layout/base/src/nsGenericElement.cpp | 34 ++-- layout/base/src/nsRange.cpp | 4 +- layout/base/src/nsRangeList.cpp | 6 +- layout/events/src/nsEventStateManager.cpp | 37 +--- layout/generic/nsFrameFrame.cpp | 4 +- .../html/content/src/nsAttributeContent.cpp | 1 - .../html/content/src/nsGenericHTMLElement.cpp | 1 - layout/html/content/src/nsHTMLFormElement.cpp | 11 +- layout/html/document/src/nsFrameFrame.cpp | 4 +- .../html/document/src/nsHTMLContentSink.cpp | 138 +++++-------- layout/html/document/src/nsHTMLDocument.cpp | 13 +- .../forms/src/nsGfxAutoTextControlFrame.cpp | 19 +- .../xml/content/src/nsGenericXMLElement.cpp | 1 - layout/xml/document/src/nsXMLContentSink.cpp | 20 +- layout/xul/base/src/nsMenuPopupFrame.cpp | 4 +- rdf/content/src/nsDlgDefaultKeys.cpp | 1 - rdf/content/src/nsRDFGenericBuilder.cpp | 17 +- rdf/content/src/nsXULCommandDispatcher.cpp | 6 +- rdf/content/src/nsXULContentSink.cpp | 2 - rdf/content/src/nsXULControllers.cpp | 1 - rdf/content/src/nsXULDocument.cpp | 87 +++----- rdf/content/src/nsXULDocument.h | 7 +- rdf/content/src/nsXULElement.cpp | 41 ++-- rdf/content/src/nsXULKeyListener.cpp | 1 - rdf/content/src/nsXULPopupListener.cpp | 11 +- rdf/content/src/nsXULTemplateBuilder.cpp | 17 +- webshell/src/nsWebShell.cpp | 189 ++++++++---------- xpfe/AppCores/src/nsBaseAppCore.cpp | 19 +- xpfe/appshell/src/nsWebShellWindow.cpp | 39 ++-- xpfe/browser/src/nsBrowserInstance.cpp | 18 +- .../directory/nsDirectoryViewer.cpp | 85 ++++---- .../prefwindow/src/nsPrefWindow.cpp | 1 - 71 files changed, 824 insertions(+), 1236 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 5b4852af6d7d0..823cf62de3d01 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -44,7 +44,7 @@ class nsIURI; class nsILoadGroup; class nsIViewManager; class nsString; -class nsIScriptContextOwner; +class nsIScriptGlobalObject; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; @@ -213,8 +213,8 @@ class nsIDocument : public nsISupports { * This is the context within which all scripts (during document * creation and during event handling) will run. */ - virtual nsIScriptContextOwner *GetScriptContextOwner() = 0; - virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) = 0; + NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject) = 0; + NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0; /** * Get the name space manager for this document diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index fd6e19ea0019a..23e506eebd77c 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -22,6 +22,7 @@ #include "plstr.h" #include "nsCOMPtr.h" +#include "nsIInterfaceRequestor.h" #include "nsDocument.h" #include "nsIArena.h" #include "nsIURL.h" @@ -36,7 +37,6 @@ #include "nsIDocumentObserver.h" #include "nsEventListenerManager.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptEventListener.h" #include "nsDOMEvent.h" #include "nsDOMEventsIIDs.h" @@ -575,7 +575,6 @@ nsDocument::nsDocument() mParentDocument = nsnull; mRootContent = nsnull; mScriptObject = nsnull; - mScriptContextOwner = nsnull; mListenerManager = nsnull; mDisplaySelection = PR_FALSE; mInDestructor = PR_FALSE; @@ -661,7 +660,6 @@ nsDocument::~nsDocument() } NS_IF_RELEASE(mArena); - NS_IF_RELEASE(mScriptContextOwner); NS_IF_RELEASE(mListenerManager); NS_IF_RELEASE(mDOMStyleSheets); NS_IF_RELEASE(mNameSpaceManager); @@ -1399,35 +1397,30 @@ void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet, } } -nsIScriptContextOwner *nsDocument::GetScriptContextOwner() +NS_IMETHODIMP +nsDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject) { - if (nsnull != mScriptContextOwner) { - NS_ADDREF(mScriptContextOwner); - } - - return mScriptContextOwner; + NS_ENSURE_ARG_POINTER(aScriptGlobalObject); + + *aScriptGlobalObject = mScriptGlobalObject; + NS_IF_ADDREF(*aScriptGlobalObject); + return NS_OK; } -void nsDocument::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) +NS_IMETHODIMP +nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) { // XXX HACK ALERT! If the script context owner is null, the document // will soon be going away. So tell our content that to lose its // reference to the document. This has to be done before we // actually set the script context owner to null so that the // content elements can remove references to their script objects. - if ((nsnull == aScriptContextOwner) && (nsnull != mRootContent)) { + if ((nsnull == aScriptGlobalObject) && (nsnull != mRootContent)) { mRootContent->SetDocument(nsnull, PR_TRUE); } - if (nsnull != mScriptContextOwner) { - NS_RELEASE(mScriptContextOwner); - } - - mScriptContextOwner = aScriptContextOwner; - - if (nsnull != mScriptContextOwner) { - NS_ADDREF(mScriptContextOwner); - } + mScriptGlobalObject = aScriptGlobalObject; + return NS_OK; } NS_IMETHODIMP @@ -1715,10 +1708,7 @@ nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptO res = cx->GetContainer(getter_AddRefs(container)); if (NS_SUCCEEDED(res) && container) { - nsCOMPtr sco = do_QueryInterface(container); - if (sco) { - res = sco->GetScriptGlobalObject(getter_AddRefs(global)); - } + global = do_GetInterface(container); } } // XXX If we can't find a view, parent to the calling context's @@ -2399,12 +2389,8 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Capturing stage - if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptContextOwner) { - nsIScriptGlobalObject* mGlobal; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&mGlobal)) { - mGlobal->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - NS_RELEASE(mGlobal); - } + if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); } //Local handling stage @@ -2414,11 +2400,8 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptContextOwner) { - nsCOMPtr global; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global))) { - global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); - } + if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } if (NS_EVENT_FLAG_INIT == aFlags) { @@ -2506,19 +2489,13 @@ PRBool nsDocument::GetProperty(JSContext *aContext, jsval aID, jsval *aVp) if (JSVAL_IS_STRING(aID) && PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) { - if (nsnull != mScriptContextOwner) { - nsIScriptGlobalObject *global; - mScriptContextOwner->GetScriptGlobalObject(&global); - if (nsnull != global) { - nsIJSScriptObject *window; - if (NS_OK == global->QueryInterface(kIJSScriptObjectIID, (void **)&window)) { - result = window->GetProperty(aContext, aID, aVp); - NS_RELEASE(window); - } - else { - result = PR_FALSE; - } - NS_RELEASE(global); + if (mScriptGlobalObject) { + nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); + if(window) { + result = window->GetProperty(aContext, aID, aVp); + } + else { + result = PR_FALSE; } } } @@ -2611,19 +2588,13 @@ PRBool nsDocument::SetProperty(JSContext *aContext, jsval aID, jsval *aVp) } else if (JSVAL_IS_STRING(aID) && PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) { - if (nsnull != mScriptContextOwner) { - nsIScriptGlobalObject *global; - mScriptContextOwner->GetScriptGlobalObject(&global); - if (nsnull != global) { - nsIJSScriptObject *window; - if (NS_OK == global->QueryInterface(kIJSScriptObjectIID, (void **)&window)) { - result = window->SetProperty(aContext, aID, aVp); - NS_RELEASE(window); - } - else { - result = PR_FALSE; - } - NS_RELEASE(global); + if (mScriptGlobalObject) { + nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); + if(window) { + result = window->SetProperty(aContext, aID, aVp); + } + else { + result = PR_FALSE; } } } diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 221772699b04f..8a21064f109fe 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -31,7 +31,7 @@ #include "nsIDOMEventReceiver.h" #include "nsIDiskDocument.h" #include "nsIScriptObjectOwner.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIDOMEventTarget.h" #include "nsXIFConverter.h" #include "nsIJSScriptObject.h" @@ -244,8 +244,8 @@ class nsDocument : public nsIDocument, * This is the context within which all scripts (during document * creation and during event handling) will run. */ - virtual nsIScriptContextOwner *GetScriptContextOwner(); - virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner); + NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject); + NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject); /** * Get the name space manager for this document @@ -466,7 +466,7 @@ class nsDocument : public nsIDocument, nsVoidArray mStyleSheets; nsVoidArray mObservers; void* mScriptObject; - nsIScriptContextOwner *mScriptContextOwner; + nsCOMPtr mScriptGlobalObject; nsIEventListenerManager* mListenerManager; PRBool mDisplaySelection; PRBool mInDestructor; diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 2d4931665635c..c7154eab2661b 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -38,7 +38,7 @@ #include "nsIStyleSheet.h" #include "nsIFrame.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsILinkHandler.h" #include "nsIDOMDocument.h" @@ -201,7 +201,6 @@ static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); // Interface IDs -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); @@ -304,19 +303,13 @@ DocumentViewerImpl::~DocumentViewerImpl() if (mDocument) { // Break global object circular reference on the document created // in the DocViewer Init - nsIScriptContextOwner *mOwner = mDocument->GetScriptContextOwner(); - if (nsnull != mOwner) { - nsIScriptGlobalObject *mGlobal; - mOwner->GetScriptGlobalObject(&mGlobal); - if (nsnull != mGlobal) { - mGlobal->SetNewDocument(nsnull); - NS_RELEASE(mGlobal); - } - NS_RELEASE(mOwner); - - // out of band cleanup of webshell - mDocument->SetScriptContextOwner(nsnull); + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + global->SetNewDocument(nsnull); } + // out of band cleanup of webshell + mDocument->SetScriptGlobalObject(nsnull); } if (mDeviceContext) @@ -404,14 +397,14 @@ DocumentViewerImpl::Init(nsNativeWidget aNativeParent, mPresContext->SetLinkHandler(linkHandler); // Set script-context-owner in the document - nsCOMPtr owner; - requestor->GetInterface(NS_GET_IID(nsIScriptContextOwner), + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), getter_AddRefs(owner)); if (nsnull != owner) { - mDocument->SetScriptContextOwner(owner); nsCOMPtr global; rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); if (NS_SUCCEEDED(rv) && (nsnull != global)) { + mDocument->SetScriptGlobalObject(global); nsCOMPtr domdoc(do_QueryInterface(mDocument)); if (nsnull != domdoc) { global->SetNewDocument(domdoc); diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index c755f6b5886c7..60711479e61c5 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -41,7 +41,7 @@ #include "nsDOMEvent.h" #include "nsIDOMText.h" #include "nsIDOMScriptObjectFactory.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" #include "prprf.h" #include "nsCOMPtr.h" @@ -714,15 +714,14 @@ nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep) // script context reference to our script object so that our // script object can be freed (or collected). if ((nsnull != mDocument) && (nsnull != mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { context->RemoveReference((void *)&mScriptObject, mScriptObject); - NS_RELEASE(context); } - NS_RELEASE(owner); } } @@ -733,16 +732,15 @@ nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep) // reference to our script object. This will ensure that it // won't be freed (or collected) out from under us. if ((nsnull != mDocument) && (nsnull != mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { context->AddNamedReference((void *)&mScriptObject, mScriptObject, "Text"); - NS_RELEASE(context); } - NS_RELEASE(owner); } } diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index d3f83af1ce787..8823a8052387b 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -34,7 +34,6 @@ #include "nsRange.h" #include "nsIEventListenerManager.h" #include "nsILinkHandler.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" #include "nsISizeOfHandler.h" @@ -672,15 +671,14 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) // script object can be freed (or collected). if ((nsnull != mDocument) && (nsnull != mDOMSlots) && (nsnull != mDOMSlots->mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { context->RemoveReference((void *)&mDOMSlots->mScriptObject, mDOMSlots->mScriptObject); - NS_RELEASE(context); } - NS_RELEASE(owner); } } @@ -692,10 +690,11 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) // won't be freed (or collected) out from under us. if ((nsnull != mDocument) && (nsnull != mDOMSlots) && (nsnull != mDOMSlots->mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { nsAutoString tag; char tagBuf[50]; @@ -704,9 +703,7 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) context->AddNamedReference((void *)&mDOMSlots->mScriptObject, mDOMSlots->mScriptObject, tagBuf); - NS_RELEASE(context); } - NS_RELEASE(owner); } } @@ -1292,15 +1289,14 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, { nsresult ret = NS_OK; nsIScriptContext* context; - nsIScriptContextOwner* owner; if (nsnull != mDocument) { - owner = mDocument->GetScriptContextOwner(); - if (owner) { - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + if (NS_OK == global->GetContext(&context)) { if (nsHTMLAtoms::body == mTag || nsHTMLAtoms::frameset == mTag) { nsIDOMEventReceiver *receiver; - nsIScriptGlobalObject *global = context->GetGlobalObject(); if (nsnull != global && NS_OK == global->QueryInterface(kIDOMEventReceiverIID, (void**)&receiver)) { nsIEventListenerManager *manager; @@ -1314,7 +1310,6 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, } NS_RELEASE(receiver); } - NS_IF_RELEASE(global); } else { nsIEventListenerManager *manager; @@ -1331,7 +1326,6 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, } NS_RELEASE(context); } - NS_RELEASE(owner); } } return ret; diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index b0e951c0cc3f6..ad3a6fd2d326e 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -1952,7 +1952,7 @@ nsRange::IsValidFragment(const nsString& aFragment, PRBool* aReturn) return result; } -// BEGIN nsIScriptContextOwner interface implementations +// BEGIN nsIScriptObjectOwner interface implementations NS_IMETHODIMP nsRange::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { @@ -1975,7 +1975,7 @@ nsRange::SetScriptObject(void *aScriptObject) return NS_OK; } -// END nsIScriptContextOwner interface implementations +// END nsIScriptObjectOwner interface implementations nsresult nsRange::Lock() diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 51370ff138f0c..ab35f3faa237c 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -45,7 +45,6 @@ #include "nsIDOMSelection.h" #include "nsIFrameSelection.h" #include "nsIDeviceContext.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsISelfScrollingFrame.h" @@ -249,11 +248,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, if (gLastFocusedDocument) { mCurrentTarget = nsnull; - nsCOMPtr contextOwner = dont_QueryInterface(gLastFocusedDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -289,11 +285,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentTarget = nsnull; // fire focus on window, not document - nsCOMPtr contextOwner = dont_QueryInterface(mDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -354,11 +347,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentTarget = nsnull; // fire focus on window, not document - nsCOMPtr contextOwner = dont_QueryInterface(mDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -400,11 +390,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentTarget = nsnull; // fire focus on window, not document - nsCOMPtr contextOwner = dont_QueryInterface(mDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -1973,16 +1960,12 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo } if (gLastFocusedDocument) { - nsCOMPtr contextOwner = dont_QueryInterface(gLastFocusedDocument->GetScriptContextOwner()); - if(contextOwner){ - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if(globalObject) - globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - gLastFocusedDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - + nsCOMPtr globalObject; + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if(globalObject) + globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + gLastFocusedDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } NS_IF_RELEASE(mCurrentTargetContent); } } diff --git a/content/html/content/src/nsAttributeContent.cpp b/content/html/content/src/nsAttributeContent.cpp index 2309e7a9405f8..eb8bd5983cee3 100644 --- a/content/html/content/src/nsAttributeContent.cpp +++ b/content/html/content/src/nsAttributeContent.cpp @@ -41,7 +41,6 @@ #include "nsDOMEvent.h" #include "nsIDOMText.h" #include "nsIDOMScriptObjectFactory.h" -#include "nsIScriptContextOwner.h" #include "prprf.h" #include "nsCOMPtr.h" diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 6fd0928bda479..53e49cbdc1ae1 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -38,7 +38,6 @@ #include "nsIHTMLDocument.h" #include "nsIHTMLContent.h" #include "nsILinkHandler.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" #include "nsISizeOfHandler.h" diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp index 0780dea7e684b..04151453fc310 100644 --- a/content/html/content/src/nsHTMLFormElement.cpp +++ b/content/html/content/src/nsHTMLFormElement.cpp @@ -27,7 +27,6 @@ #include "nsIDOMNSHTMLFormElement.h" #include "nsIDOMHTMLCollection.h" #include "nsIScriptObjectOwner.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -41,6 +40,7 @@ #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsISizeOfHandler.h" +#include "nsIScriptGlobalObject.h" static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); @@ -566,11 +566,10 @@ nsHTMLFormElement::Resolve(JSContext *aContext, jsval aID) nsCOMPtr scriptContext; if (nsnull != mInner.mDocument) { - nsCOMPtr contextOwner; - - contextOwner = getter_AddRefs(mInner.mDocument->GetScriptContextOwner()); - if (contextOwner) { - result = contextOwner->GetScriptContext(getter_AddRefs(scriptContext)); + nsCOMPtr globalObject; + mInner.mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + result = globalObject->GetContext(getter_AddRefs(scriptContext)); } } else { diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index a80eaccb9c679..5efe20bfc23fa 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -68,11 +68,11 @@ #include "nsIDOMHTMLMapElement.h" #include "nsIRefreshURI.h" #include "nsVoidArray.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" #include "nsHTMLIIDs.h" #include "nsTextFragment.h" +#include "nsIScriptGlobalObject.h" #include "nsIParserService.h" #include "nsParserCIID.h" @@ -189,11 +189,9 @@ class HTMLContentSink : public nsIHTMLContentSink, void ReduceEntities(nsString& aString); void GetAttributeValueAt(const nsIParserNode& aNode, PRInt32 aIndex, - nsString& aResult, - nsIScriptContextOwner* aScriptContextOwner); + nsString& aResult); nsresult AddAttributes(const nsIParserNode& aNode, nsIHTMLContent* aContent, - nsIScriptContextOwner* aScriptContextOwner, PRBool aNotify = PR_FALSE); nsresult CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType, @@ -509,8 +507,7 @@ HTMLContentSink::ReduceEntities(nsString& aString) void HTMLContentSink::GetAttributeValueAt(const nsIParserNode& aNode, PRInt32 aIndex, - nsString& aResult, - nsIScriptContextOwner* aScriptContextOwner) + nsString& aResult) { // Copy value const nsString& value = aNode.GetValueAt(aIndex); @@ -536,7 +533,6 @@ HTMLContentSink::GetAttributeValueAt(const nsIParserNode& aNode, nsresult HTMLContentSink::AddAttributes(const nsIParserNode& aNode, nsIHTMLContent* aContent, - nsIScriptContextOwner* aScriptContextOwner, PRBool aNotify) { // Add tag attributes to the content attributes @@ -555,7 +551,7 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode, if (NS_CONTENT_ATTR_NOT_THERE == aContent->GetHTMLAttribute(keyAtom, value)) { // Get value and remove mandatory quotes - GetAttributeValueAt(aNode, i, v, aScriptContextOwner); + GetAttributeValueAt(aNode, i, v); // Add attribute to content aContent->SetAttribute(kNameSpaceID_HTML, keyAtom, v,aNotify); @@ -1151,9 +1147,9 @@ SinkContext::OpenContainer(const nsIParserNode& aNode) mStack[mStackPos].mInsertionPoint = -1; content->SetDocument(mSink->mDocument, PR_FALSE); - nsIScriptContextOwner* sco = mSink->mDocument->GetScriptContextOwner(); - rv = mSink->AddAttributes(aNode, content, sco); - NS_IF_RELEASE(sco); + nsCOMPtr scriptGlobalObject; + mSink->mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); + rv = mSink->AddAttributes(aNode, content); if (mPreAppend) { NS_ASSERTION(mStackPos > 0, "container w/o parent"); @@ -1456,9 +1452,7 @@ SinkContext::AddLeaf(const nsIParserNode& aNode) // Set the content's document content->SetDocument(mSink->mDocument, PR_FALSE); - nsIScriptContextOwner* sco = mSink->mDocument->GetScriptContextOwner(); - rv = mSink->AddAttributes(aNode, content, sco); - NS_IF_RELEASE(sco); + rv = mSink->AddAttributes(aNode, content); if (NS_OK != rv) { NS_RELEASE(content); return rv; @@ -2293,9 +2287,7 @@ HTMLContentSink::OpenHead(const nsIParserNode& aNode) mCurrentContext = mHeadContext; if (nsnull != mHead) { - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); - rv = AddAttributes(aNode, mHead, sco); - NS_IF_RELEASE(sco); + rv = AddAttributes(aNode, mHead); } MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n")); @@ -2331,9 +2323,7 @@ HTMLContentSink::OpenBody(const nsIParserNode& aNode) mCurrentContext->mStackPos, this); // Add attributes, if any, to the current BODY node if(mBody != nsnull){ - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); - AddAttributes(aNode,mBody,sco,PR_TRUE); - NS_IF_RELEASE(sco); + AddAttributes(aNode,mBody,PR_TRUE); MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n")); MOZ_TIMER_STOP(mWatch); return NS_OK; @@ -2887,10 +2877,8 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) area->SetContentID(mContentIDCounter++); // Set the content's document and attributes - area->SetDocument(mDocument, PR_FALSE); - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); - rv = AddAttributes(aNode, area, sco); - NS_IF_RELEASE(sco); + area->SetDocument(mDocument, PR_FALSE); + rv = AddAttributes(aNode, area); if (NS_FAILED(rv)) { NS_RELEASE(area); return rv; @@ -2949,7 +2937,6 @@ nsresult HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) { nsresult result = NS_OK; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); // Create content object nsAutoString tag("BASE"); @@ -2961,7 +2948,7 @@ HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - result = AddAttributes(aNode, element, sco); + result = AddAttributes(aNode, element); if (NS_SUCCEEDED(result)) { mHead->AppendChildTo(element, PR_FALSE); @@ -2975,7 +2962,6 @@ HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) } } - NS_IF_RELEASE(sco); return result; } @@ -3250,27 +3236,26 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) nsAutoString type; nsAutoString media; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); for (i = 0; i < count; i++) { const nsString& key = aNode.GetKeyAt(i); if (key.EqualsIgnoreCase("href")) { - GetAttributeValueAt(aNode, i, href, sco); + GetAttributeValueAt(aNode, i, href); href.StripWhitespace(); } else if (key.EqualsIgnoreCase("rel")) { - GetAttributeValueAt(aNode, i, rel, sco); + GetAttributeValueAt(aNode, i, rel); rel.CompressWhitespace(); } else if (key.EqualsIgnoreCase("title")) { - GetAttributeValueAt(aNode, i, title, sco); + GetAttributeValueAt(aNode, i, title); title.CompressWhitespace(); } else if (key.EqualsIgnoreCase("type")) { - GetAttributeValueAt(aNode, i, type, sco); + GetAttributeValueAt(aNode, i, type); type.StripWhitespace(); } else if (key.EqualsIgnoreCase("media")) { - GetAttributeValueAt(aNode, i, media, sco); + GetAttributeValueAt(aNode, i, media); media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE } } @@ -3285,7 +3270,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - result = AddAttributes(aNode, element, sco); + result = AddAttributes(aNode, element); if (NS_FAILED(result)) { NS_RELEASE(element); return result; @@ -3293,10 +3278,8 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) mHead->AppendChildTo(element, PR_FALSE); } else { - NS_IF_RELEASE(sco); return result; } - NS_IF_RELEASE(sco); result = ProcessStyleLink(element, href, rel, title, type, media); @@ -3357,10 +3340,8 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) if (NS_OK == rv) { // Add in the attributes and add the meta content object to the // head container. - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); it->SetDocument(mDocument, PR_FALSE); - rv = AddAttributes(aNode, it, sco); - NS_IF_RELEASE(sco); + rv = AddAttributes(aNode, it); if (NS_OK != rv) { NS_RELEASE(it); return rv; @@ -3594,40 +3575,33 @@ HTMLContentSink::EvaluateScript(nsString& aScript, nsresult rv = NS_OK; if (aScript.Length() > 0) { - nsIScriptContextOwner *owner; - nsIScriptContext *context; - owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - - rv = owner->GetScriptContext(&context); - if (rv != NS_OK) { - NS_RELEASE(owner); - return rv; - } + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); - nsCOMPtr principal; - principal = getter_AddRefs(mDocument->GetDocumentPrincipal()); - NS_ASSERTION(principal, "principal expected for document"); - - nsAutoString ret; - nsIURI* docURL = mDocument->GetDocumentURL(); - char* url = nsnull; + nsCOMPtr context; + NS_ENSURE_SUCCESS(globalObject->GetContext(getter_AddRefs(context)), + NS_ERROR_FAILURE); - if (docURL) { - (void)docURL->GetSpec(&url); - } + nsCOMPtr principal; + principal = getter_AddRefs(mDocument->GetDocumentPrincipal()); + NS_ASSERTION(principal, "principal expected for document"); + + nsAutoString ret; + nsIURI* docURL = mDocument->GetDocumentURL(); + char* url = nsnull; + + if (docURL) { + (void)docURL->GetSpec(&url); + } - PRBool isUndefined; - context->EvaluateString(aScript, nsnull, principal, url, - aLineNo, aVersion, ret, &isUndefined); - - if (docURL) { - NS_RELEASE(docURL); - nsCRT::free(url); - } - - NS_RELEASE(context); - NS_RELEASE(owner); + PRBool isUndefined; + context->EvaluateString(aScript, nsnull, principal, url, + aLineNo, aVersion, ret, &isUndefined); + + if (docURL) { + NS_RELEASE(docURL); + nsCRT::free(url); } } @@ -3675,12 +3649,12 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) for (i = 0; i < ac; i++) { const nsString& key = aNode.GetKeyAt(i); if (key.EqualsIgnoreCase("src")) { - GetAttributeValueAt(aNode, i, src, nsnull); + GetAttributeValueAt(aNode, i, src); } else if (key.EqualsIgnoreCase("type")) { nsAutoString type; - GetAttributeValueAt(aNode, i, type, nsnull); + GetAttributeValueAt(aNode, i, type); nsAutoString mimeType; nsAutoString params; @@ -3709,7 +3683,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) else if (key.EqualsIgnoreCase("language")) { nsAutoString lang; - GetAttributeValueAt(aNode, i, lang, nsnull); + GetAttributeValueAt(aNode, i, lang); isJavaScript = IsJavaScriptLanguage(lang, &jsVersionString); } } @@ -3717,7 +3691,6 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) // Create content object NS_ASSERTION(mCurrentContext->mStackPos > 0, "leaf w/o container"); nsIHTMLContent* parent = mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); nsAutoString tag("SCRIPT"); nsIHTMLContent* element = nsnull; rv = NS_CreateHTMLElement(&element, tag); @@ -3727,7 +3700,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - rv = AddAttributes(aNode, element, sco); + rv = AddAttributes(aNode, element); if (NS_FAILED(rv)) { NS_RELEASE(element); return rv; @@ -3742,10 +3715,8 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) } } else { - NS_IF_RELEASE(sco); return rv; } - NS_IF_RELEASE(sco); // Create a text node holding the content // First, get the text content of the script tag @@ -3845,23 +3816,22 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) nsAutoString type; nsAutoString media; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); for (i = 0; i < count; i++) { const nsString& key = aNode.GetKeyAt(i); if (key.EqualsIgnoreCase("src")) { - GetAttributeValueAt(aNode, i, src, sco); + GetAttributeValueAt(aNode, i, src); src.StripWhitespace(); } else if (key.EqualsIgnoreCase("title")) { - GetAttributeValueAt(aNode, i, title, sco); + GetAttributeValueAt(aNode, i, title); title.CompressWhitespace(); } else if (key.EqualsIgnoreCase("type")) { - GetAttributeValueAt(aNode, i, type, sco); + GetAttributeValueAt(aNode, i, type); type.StripWhitespace(); } else if (key.EqualsIgnoreCase("media")) { - GetAttributeValueAt(aNode, i, media, sco); + GetAttributeValueAt(aNode, i, media); media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE } } @@ -3876,7 +3846,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - rv = AddAttributes(aNode, element, sco); + rv = AddAttributes(aNode, element); if (NS_FAILED(rv)) { NS_RELEASE(element); return rv; @@ -3884,10 +3854,8 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) mHead->AppendChildTo(element, PR_FALSE); } else { - NS_IF_RELEASE(sco); return rv; } - NS_IF_RELEASE(sco); nsAutoString mimeType; nsAutoString params; diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 0b11620648fcf..3243bd93f46e6 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -2469,10 +2469,7 @@ nsHTMLDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject res = cx->GetContainer(getter_AddRefs(container)); if (NS_SUCCEEDED(res) && container) { - nsCOMPtr sco = do_QueryInterface(container); - if (sco) { - res = sco->GetScriptGlobalObject(getter_AddRefs(global)); - } + global = do_GetInterface(container); } } // XXX If we can't find a view, parent to the calling context's @@ -2510,11 +2507,11 @@ nsHTMLDocument::Resolve(JSContext *aContext, jsval aID) if (owner) { nsCOMPtr scriptContext; - nsCOMPtr contextOwner; + nsCOMPtr scriptGlobal; + GetScriptGlobalObject(getter_AddRefs(scriptGlobal)); - contextOwner = getter_AddRefs(GetScriptContextOwner()); - if (contextOwner) { - result = contextOwner->GetScriptContext(getter_AddRefs(scriptContext)); + if (scriptGlobal) { + result = scriptGlobal->GetContext(getter_AddRefs(scriptContext)); } if (!scriptContext) { diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index 82e03c9c111cb..2896f9778ce4a 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -28,6 +28,7 @@ #include "nsIXMLDocument.h" #include "nsIXMLContent.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIURL.h" #include "nsIURL.h" #include "nsNetUtil.h" @@ -50,7 +51,6 @@ #include "nsHTMLAtoms.h" #include "nsLayoutAtoms.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" @@ -1623,16 +1623,12 @@ nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo, const char nsresult rv = NS_OK; if (0 < aScript.Length()) { - nsIScriptContextOwner *owner; - nsIScriptContext *context; - owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - - rv = owner->GetScriptContext(&context); - if (rv != NS_OK) { - NS_RELEASE(owner); - return rv; - } + nsCOMPtr scriptGlobal; + mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobal)); + if (scriptGlobal) { + nsCOMPtr context; + NS_ENSURE_SUCCESS(scriptGlobal->GetContext(getter_AddRefs(context)), + NS_ERROR_FAILURE); nsIURI* docURL = mDocument->GetDocumentURL(); char* url; @@ -1649,8 +1645,6 @@ nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo, const char NS_IF_RELEASE(docURL); - NS_RELEASE(context); - NS_RELEASE(owner); nsCRT::free(url); } } diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 327f4d5da4a7f..9977add07b043 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -74,7 +74,6 @@ #include "nsIStyleSheet.h" #include "nsIHTMLStyleSheet.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIStyledContent.h" #include "nsIStyleContext.h" #include "nsIMutableStyleContext.h" @@ -1304,24 +1303,19 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REF nsresult rv; nsCOMPtr context; - + nsCOMPtr global; { - nsCOMPtr owner = - dont_AddRef( mDocument->GetScriptContextOwner() ); + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); // This can happen normally as part of teardown code. - if (! owner) + if (! global) return NS_OK; - rv = owner->GetScriptContext(getter_AddRefs(context)); + rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; } if (Tag() == kWindowAtom) { - nsCOMPtr global = context->GetGlobalObject(); - if (! global) - return NS_ERROR_UNEXPECTED; - nsCOMPtr receiver = do_QueryInterface(global); if (! receiver) return NS_ERROR_UNEXPECTED; @@ -1631,11 +1625,11 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) // Release the named reference to the script object so it can // be garbage collected. if (mScriptObject) { - nsCOMPtr owner = - dont_AddRef( mDocument->GetScriptContextOwner() ); - if (owner) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { nsCOMPtr context; - if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) { + if (NS_OK == global->GetContext(getter_AddRefs(context))) { context->RemoveReference((void*) &mScriptObject, mScriptObject); } @@ -1648,11 +1642,11 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) if (mDocument) { // Add a named reference to the script object. if (mScriptObject) { - nsCOMPtr owner = - dont_AddRef( mDocument->GetScriptContextOwner() ); - if (owner) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { nsCOMPtr context; - if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) { + if (NS_OK == global->GetContext(getter_AddRefs(context))) { nsAutoString tag; Tag()->ToString(tag); context->AddNamedReference((void*) &mScriptObject, mScriptObject, nsCAutoString(tag)); @@ -3674,16 +3668,13 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, PRInt32 aTextLength, { nsresult rv; - nsCOMPtr owner = - dont_AddRef( aDocument->GetScriptContextOwner() ); + nsCOMPtr global; + aDocument->GetScriptGlobalObject(getter_AddRefs(global)); - NS_ASSERTION(owner != nsnull, "document has no script context owner"); - if (!owner) { - return NS_ERROR_UNEXPECTED; - } + NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = owner->GetScriptContext(getter_AddRefs(context)); + rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; if (!mScriptRuntime) { diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index 5eab272a84ba9..38e2f63776886 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -34,7 +34,6 @@ #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIContent.h" @@ -459,11 +458,11 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) return NS_OK; // We have some popup content. Obtain our window. - nsIScriptContextOwner* owner = document->GetScriptContextOwner(); nsCOMPtr context; - if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) { - nsIScriptGlobalObject* global = context->GetGlobalObject(); - if (global) { + nsCOMPtr global; + document->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + if (NS_OK == global->GetContext(getter_AddRefs(context))) { // Get the DOM window nsCOMPtr domWindow = do_QueryInterface(global); if (domWindow != nsnull) { @@ -484,10 +483,8 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) type, anchorAlignment, popupAlignment, getter_AddRefs(uselessPopup)); } - NS_RELEASE(global); } } - NS_IF_RELEASE(owner); return NS_OK; } diff --git a/content/xul/document/src/nsXULCommandDispatcher.cpp b/content/xul/document/src/nsXULCommandDispatcher.cpp index 987967f76a699..fa9d7435d85e8 100644 --- a/content/xul/document/src/nsXULCommandDispatcher.cpp +++ b/content/xul/document/src/nsXULCommandDispatcher.cpp @@ -37,7 +37,6 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIContent.h" @@ -485,11 +484,8 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen nsCOMPtr objectOwner = do_QueryInterface(document); if(!objectOwner) return NS_OK; - nsCOMPtr contextOwner = dont_QueryInterface(objectOwner->GetScriptContextOwner()); - if(!contextOwner) return NS_OK; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + objectOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) return NS_OK; nsCOMPtr privateDOMWindow = do_QueryInterface(globalObject); diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index 7adda7c51b6aa..ed402c5d612df 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -59,12 +59,10 @@ #include "nsIRDFContentModelBuilder.h" #include "nsIRDFService.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIServiceManager.h" #include "nsITextContent.h" #include "nsIURL.h" #include "nsIViewManager.h" -#include "nsIWebShell.h" #include "nsIXMLContent.h" #include "nsIXMLElementFactory.h" #include "nsIXULContentSink.h" diff --git a/content/xul/document/src/nsXULControllers.cpp b/content/xul/document/src/nsXULControllers.cpp index 3a059c949d106..5e2c6b130be9d 100644 --- a/content/xul/document/src/nsXULControllers.cpp +++ b/content/xul/document/src/nsXULControllers.cpp @@ -37,7 +37,6 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIContent.h" diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 37f5f5aa6786d..ce86ce5ca30a2 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -83,7 +83,6 @@ #include "nsIRDFNode.h" #include "nsIRDFRemoteDataSource.h" #include "nsIRDFService.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsIStreamListener.h" @@ -307,7 +306,6 @@ PlaceholderChannel::~PlaceholderChannel() nsXULDocument::nsXULDocument(void) : mParentDocument(nsnull), - mScriptContextOwner(nsnull), mScriptObject(nsnull), mNextSrcLoadWaiter(nsnull), mCharSetID("UTF-8"), @@ -1146,25 +1144,27 @@ nsXULDocument::GetCSSLoader(nsICSSLoader*& aLoader) return result; } -nsIScriptContextOwner * -nsXULDocument::GetScriptContextOwner() +NS_IMETHODIMP +nsXULDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject) { - NS_IF_ADDREF(mScriptContextOwner); - return mScriptContextOwner; + *aScriptGlobalObject = mScriptGlobalObject; + NS_IF_ADDREF(*aScriptGlobalObject); + return NS_OK; } -void -nsXULDocument::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) +NS_IMETHODIMP +nsXULDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) { // XXX HACK ALERT! If the script context owner is null, the document // will soon be going away. So tell our content that to lose its // reference to the document. This has to be done before we // actually set the script context owner to null so that the // content elements can remove references to their script objects. - if (!aScriptContextOwner && mRootContent) + if (!aScriptGlobalObject && mRootContent) mRootContent->SetDocument(nsnull, PR_TRUE); - mScriptContextOwner = aScriptContextOwner; + mScriptGlobalObject = aScriptGlobalObject; + return NS_OK; } NS_IMETHODIMP @@ -1757,12 +1757,8 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Capturing stage - if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptContextOwner) { - nsIScriptGlobalObject* global; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&global)) { - global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - NS_RELEASE(global); - } + if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); } //Local handling stage @@ -1772,12 +1768,8 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptContextOwner) { - nsIScriptGlobalObject* global; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&global)) { - global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); - NS_RELEASE(global); - } + if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } if (NS_EVENT_FLAG_INIT == aFlags) { @@ -3001,16 +2993,10 @@ nsXULDocument::GetProperty(JSContext *aContext, jsval aID, jsval *aVp) return PR_FALSE; if (PL_strcmp("location", JS_GetStringBytes(jsString)) == 0) { - if (nsnull != mScriptContextOwner) { - nsCOMPtr global; - mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global)); - if (nsnull != global) { - nsCOMPtr window = do_QueryInterface(global); - if (nsnull != window) { - return window->GetProperty(aContext, aID, aVp); - } - } - } + nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + if (nsnull != window) { + return window->GetProperty(aContext, aID, aVp); + } } } @@ -3104,9 +3090,7 @@ nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) // Make sure that we've got our script context owner; this // assertion will fire if we've tried to get the script object // before our scope has been set up. - NS_ASSERTION(mScriptContextOwner != nsnull, "no script context owner"); - if (! mScriptContextOwner) - return NS_ERROR_NOT_INITIALIZED; + NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_NOT_INITIALIZED); nsresult rv; @@ -3115,17 +3099,10 @@ nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) // global object from aContext would make our script object // dynamically scoped in the first context that ever tried to // use us!) - nsCOMPtr global; - rv = mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global)); - if (NS_FAILED(rv)) return rv; - - NS_ASSERTION(global != nsnull, "script context owner has no global object"); - if (! global) - return NS_ERROR_UNEXPECTED; rv = NS_NewScriptXULDocument(aContext, NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMXULDocument*, this)), - global, &mScriptObject); + mScriptGlobalObject, &mScriptObject); if (NS_FAILED(rv)) return rv; } @@ -3468,9 +3445,9 @@ nsXULDocument::StartLayout(void) // Perform the resize PRInt32 chromeX,chromeY,chromeWidth,chromeHeight; - nsCOMPtr webShellWin(do_QueryInterface(webShell)); - NS_ABORT_IF_FALSE(webShellWin, "QI Failed!!!!"); - webShellWin->GetPositionAndSize(&chromeX, &chromeY, &chromeWidth, + nsCOMPtr docShellWin(do_QueryInterface(webShell)); + NS_ABORT_IF_FALSE(docShellWin, "QI Failed!!!!"); + docShellWin->GetPositionAndSize(&chromeX, &chromeY, &chromeWidth, &chromeHeight); float t2p; @@ -4917,13 +4894,10 @@ nsXULDocument::ExecuteScript(JSObject* aScriptObject) // Execute the precompiled script with the given version nsresult rv; - nsCOMPtr owner = dont_AddRef(GetScriptContextOwner()); - NS_ASSERTION(owner != nsnull, "document has no script context owner"); - if (! owner) - return NS_ERROR_UNEXPECTED; + NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = owner->GetScriptContext(getter_AddRefs(context)); + rv = mScriptGlobalObject->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull); @@ -5720,15 +5694,8 @@ nsXULDocument::CachedChromeLoader::OnStopRequest(nsIChannel* aChannel, if (! container) continue; - // the container should be a script context owner... - nsCOMPtr owner = do_QueryInterface(container); - NS_ASSERTION(owner != nsnull, "container is not a script context owner"); - if (! owner) - continue; - - // and the script context owner has a script global object... - nsCOMPtr global; - rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); + // the container should support GI to globalObject... + nsCOMPtr global(do_GetInterface(container, &rv)); if (NS_FAILED(rv)) continue; diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 2e9c2be92dccc..cdbd26de66987 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -65,7 +65,6 @@ class nsIHTMLElementFactory; class nsILoadGroup; class nsIRDFResource; class nsIRDFService; -class nsIScriptContextOwner; class nsITimer; class nsIUnicharStreamLoader; class nsIXMLElementFactory; @@ -182,9 +181,9 @@ class nsXULDocument : public nsIDocument, NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader); - virtual nsIScriptContextOwner *GetScriptContextOwner(); + NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject); - virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner); + NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject); NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager); @@ -502,7 +501,7 @@ class nsXULDocument : public nsIDocument, nsCOMPtr mDocumentPrincipal; // [OWNER] nsCOMPtr mRootContent; // [OWNER] nsIDocument* mParentDocument; // [WEAK] - nsIScriptContextOwner* mScriptContextOwner; // [WEAK] it owns me! (indirectly) + nsCOMPtr mScriptGlobalObject; void* mScriptObject; // ???? nsXULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr nsString mCharSetID; diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index fb8c01fafef23..7307bd6450ef0 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -58,8 +58,8 @@ #include "nsIRDFObserver.h" #include "nsIRDFRemoteDataSource.h" #include "nsIRDFService.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsITextContent.h" @@ -2956,18 +2956,13 @@ RDFGenericBuilderImpl::AddDatabasePropertyToHTMLElement(nsIContent* aElement, ns if (! doc) return NS_ERROR_UNEXPECTED; - nsCOMPtr contextowner = dont_QueryInterface(doc->GetScriptContextOwner()); - NS_ASSERTION(contextowner != nsnull, "no script context owner"); - if (! contextowner) - return NS_ERROR_UNEXPECTED; + nsCOMPtr global; + doc->GetScriptGlobalObject(getter_AddRefs(global)); + NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = contextowner->GetScriptContext(getter_AddRefs(context)); - NS_ASSERTION(NS_SUCCEEDED(rv), "no script context"); - if (NS_FAILED(rv)) return rv; - - if (! context) - return NS_ERROR_UNEXPECTED; + global->GetContext(getter_AddRefs(context)); + NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); JSContext* jscontext = NS_STATIC_CAST(JSContext*, context->GetNativeContext()); NS_ASSERTION(context != nsnull, "no jscontext"); diff --git a/docshell/base/MANIFEST_IDL b/docshell/base/MANIFEST_IDL index 2003cba1cf352..bbc5598926eed 100644 --- a/docshell/base/MANIFEST_IDL +++ b/docshell/base/MANIFEST_IDL @@ -23,6 +23,7 @@ nsCDocShell.idl nsIDocShell.idl nsIDocShellContainer.idl +nsIDocShellTreeNode.idl nsIMarkupDocumentViewer.idl nsIScrollable.idl nsITextScroll.idl \ No newline at end of file diff --git a/docshell/base/Makefile.in b/docshell/base/Makefile.in index 39bcf58d1fd03..44cabff700b62 100644 --- a/docshell/base/Makefile.in +++ b/docshell/base/Makefile.in @@ -32,6 +32,7 @@ XPIDLSRCS = \ nsCDocShell.idl \ nsIDocShell.idl \ nsIDocShellContainer.idl \ + nsIDocShellTreeNode.idl \ nsIMarkupDocumentViewer.idl \ nsIScrollable.idl \ nsITextScroll.idl \ diff --git a/docshell/base/makefile.win b/docshell/base/makefile.win index 0f852eab4ff05..a9ed91edb4214 100644 --- a/docshell/base/makefile.win +++ b/docshell/base/makefile.win @@ -26,6 +26,7 @@ XPIDLSRCS= \ .\nsCDocShell.idl \ .\nsIDocShell.idl \ .\nsIDocShellContainer.idl \ + .\nsIDocShellTreeNode.idl \ # .\nsIContentViewerEdit.idl \ # .\nsIContentViewerFile.idl \ .\nsIMarkupDocumentViewer.idl \ diff --git a/docshell/base/nsCDocShell.idl b/docshell/base/nsCDocShell.idl index 9b7749915499d..b2a02b9f491dc 100644 --- a/docshell/base/nsCDocShell.idl +++ b/docshell/base/nsCDocShell.idl @@ -21,7 +21,7 @@ */ #include "nsIDocShell.idl" -#include "nsIDocShellContainer.idl" +#include "nsIDocShellTreeNode.idl" #include "nsIBaseWindow.idl" #include "nsIScrollable.idl" #include "nsITextScroll.idl" diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 75eb215f7019a..119079f2b4e42 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -104,11 +104,12 @@ NS_IMPL_RELEASE(nsDocShell) NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShell) NS_INTERFACE_MAP_ENTRY(nsIDocShell) + NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode) NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) NS_INTERFACE_MAP_ENTRY(nsIScrollable) NS_INTERFACE_MAP_ENTRY(nsITextScroll) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) - NS_INTERFACE_MAP_ENTRY(nsIScriptContextOwner) + NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) NS_INTERFACE_MAP_END //***************************************************************************** @@ -521,7 +522,7 @@ nsDocShell::SetMarginHeight(PRInt32 aHeight) } //***************************************************************************** -// nsDocShell::nsIDocShellContainer +// nsDocShell::nsIDocShellTreeNode //***************************************************************************** NS_IMETHODIMP nsDocShell::GetChildCount(PRInt32 *aChildCount) @@ -597,7 +598,7 @@ NS_IMETHODIMP nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShell** aDocShell) /* depth-first search for a child shell with aName */ NS_IMETHODIMP nsDocShell::FindChildWithName(const PRUnichar *aName, nsIDocShell **_retval) { - NS_ENSURE_ARG_POINTER(aName); + NS_ENSURE_ARG(aName); NS_ENSURE_ARG_POINTER(_retval); *_retval = nsnull; // if we don't find one, we return NS_OK and a null result @@ -616,12 +617,12 @@ NS_IMETHODIMP nsDocShell::FindChildWithName(const PRUnichar *aName, nsIDocShell } // See if child contains the shell with the given name - nsCOMPtr childAsContainer = do_QueryInterface(child); + nsCOMPtr childAsContainer = do_QueryInterface(child); if (child) { NS_ENSURE_SUCCESS(childAsContainer->FindChildWithName(name.GetUnicode(), _retval), NS_ERROR_FAILURE); } - if (_retval) { // found it + if (*_retval) { // found it break; } } @@ -1256,6 +1257,9 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink) if(aIID.Equals(NS_GET_IID(nsIURIContentListener)) && NS_SUCCEEDED(EnsureContentListener())) *aSink = mContentListener; + if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) && + NS_SUCCEEDED(EnsureScriptEnvironment())) + *aSink = mScriptGlobal; else return QueryInterface(aIID, aSink); @@ -1264,20 +1268,9 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink) } //***************************************************************************** -// nsDocShell::nsIScriptContextOwner +// nsDocShell::nsIScriptGlobalObjectOwner //***************************************************************************** -NS_IMETHODIMP nsDocShell::GetScriptContext(nsIScriptContext** aContext) -{ - NS_ENSURE_ARG_POINTER(aContext); - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - - *aContext = mScriptContext; - NS_IF_ADDREF(*aContext); - - return NS_OK; -} - NS_IMETHODIMP nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal) { NS_ENSURE_ARG_POINTER(aGlobal); @@ -1288,13 +1281,6 @@ NS_IMETHODIMP nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal) return NS_OK; } -NS_IMETHODIMP nsDocShell::ReleaseScriptContext(nsIScriptContext *aContext) -{ - NS_IF_RELEASE(aContext); - mScriptContext = nsnull; - return NS_OK; -} - NS_IMETHODIMP nsDocShell::ReportScriptError(const char* aErrorString, const char* aFileName, PRInt32 aLineNo, const char* aLineBuf) { @@ -1509,12 +1495,12 @@ nsresult nsDocShell::EnsureScriptEnvironment() //XXXWEBSHELL //mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell*, this)); + mScriptGlobal->SetGlobalObjectOwner( + NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this)); NS_ENSURE_SUCCESS(NS_CreateScriptContext(scriptGlobalObject, getter_AddRefs(mScriptContext)), NS_ERROR_FAILURE); - mScriptContext->SetOwner(NS_STATIC_CAST(nsIScriptContextOwner*, this)); - return NS_OK; } diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 111f9da8da8d4..50ab1e77abbdf 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -41,7 +41,7 @@ #include "nsIDocumentLoaderObserver.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIInterfaceRequestor.h" #include "nsDSURIContentListener.h" @@ -60,13 +60,13 @@ class nsDocShellInitInfo }; class nsDocShell : public nsIDocShell, - public nsIDocShellContainer, + public nsIDocShellTreeNode, public nsIBaseWindow, public nsIScrollable, public nsITextScroll, public nsIContentViewerContainer, public nsIInterfaceRequestor, - public nsIScriptContextOwner + public nsIScriptGlobalObjectOwner { friend class nsDSURIContentListener; @@ -74,12 +74,12 @@ friend class nsDSURIContentListener; NS_DECL_ISUPPORTS NS_DECL_NSIDOCSHELL - NS_DECL_NSIDOCSHELLCONTAINER + NS_DECL_NSIDOCSHELLTREENODE NS_DECL_NSIBASEWINDOW NS_DECL_NSISCROLLABLE NS_DECL_NSITEXTSCROLL NS_DECL_NSIINTERFACEREQUESTOR - NS_DECL_NSISCRIPTCONTEXTOWNER + NS_DECL_NSISCRIPTGLOBALOBJECTOWNER // XXX: move to a macro // nsIContentViewerContainer diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index aded601146f47..74d6141c66f96 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -35,7 +35,7 @@ #include "nsIDNSService.h" #include "nsIRefreshURI.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIDocumentLoaderObserver.h" #include "nsIProgressEventSink.h" #include "nsDOMEvent.h" @@ -160,7 +160,6 @@ class nsWebShell : public nsIWebShell, public nsIWebShellContainer, public nsIWebShellServices, public nsILinkHandler, - public nsIScriptContextOwner, public nsIDocumentLoaderObserver, public nsIProgressEventSink, // should go away (nsIDocLoaderObs) public nsIPrompt, @@ -170,7 +169,8 @@ class nsWebShell : public nsIWebShell, public nsIInterfaceRequestor, public nsIBaseWindow, public nsIDocShell, - public nsIDocShellContainer + public nsIDocShellContainer, + public nsIScriptGlobalObjectOwner { public: nsWebShell(); @@ -313,8 +313,8 @@ class nsWebShell : public nsIWebShell, const PRUnichar* aTargetSpec); NS_IMETHOD GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState); - // nsIScriptContextOwner - NS_DECL_NSISCRIPTCONTEXTOWNER + // nsIScriptGlobalObjectOwner + NS_DECL_NSISCRIPTGLOBALOBJECTOWNER // nsIDocumentLoaderObserver NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, @@ -536,7 +536,6 @@ static NS_DEFINE_IID(kIProgressEventSinkIID, NS_IPROGRESSEVENTSINK_IID); static NS_DEFINE_IID(kIDeviceContextIID, NS_IDEVICE_CONTEXT_IID); static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kRefreshURIIID, NS_IREFRESHURI_IID); @@ -763,7 +762,7 @@ NS_INTERFACE_MAP_BEGIN(nsWebShell) NS_INTERFACE_MAP_ENTRY(nsIWebShell) NS_INTERFACE_MAP_ENTRY(nsIWebShellServices) NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer) - NS_INTERFACE_MAP_ENTRY(nsIScriptContextOwner) + NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) NS_INTERFACE_MAP_ENTRY(nsIDocumentLoaderObserver) NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink) NS_INTERFACE_MAP_ENTRY(nsIWebShellContainer) @@ -786,21 +785,28 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr) if(aIID.Equals(NS_GET_IID(nsILinkHandler))) { *aInstancePtr = NS_STATIC_CAST(nsILinkHandler*, this); - NS_ADDREF_THIS(); + NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } - else if(aIID.Equals(NS_GET_IID(nsIScriptContextOwner))) + else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectOwner))) { - *aInstancePtr = NS_STATIC_CAST(nsIScriptContextOwner*, this); - NS_ADDREF_THIS(); + *aInstancePtr = NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this); + NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } else if (aIID.Equals(NS_GET_IID(nsIURIContentListener))) { *aInstancePtr = NS_STATIC_CAST(nsIURIContentListener*, this); - NS_ADDREF_THIS(); + NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } + else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject))) + { + NS_ENSURE_SUCCESS(CreateScriptEnvironment(), NS_ERROR_FAILURE); + *aInstancePtr = mScriptGlobal; + NS_ADDREF((nsISupports*)*aInstancePtr); + return NS_OK; + } else if(mPluginManager) //XXX this seems a little wrong. MMP return mPluginManager->QueryInterface(aIID, aInstancePtr); @@ -2888,103 +2894,17 @@ nsWebShell::CreateScriptEnvironment() return res; } mScriptGlobal->SetWebShell(this); + mScriptGlobal->SetGlobalObjectOwner( + NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this)); } if (nsnull == mScriptContext) { res = NS_CreateScriptContext(mScriptGlobal, &mScriptContext); - if (NS_SUCCEEDED(res)) { - mScriptContext->SetOwner(this); - } } return res; } -nsresult -nsWebShell::GetScriptContext(nsIScriptContext** aContext) -{ - NS_PRECONDITION(nsnull != aContext, "null arg"); - nsresult res = NS_OK; - - res = CreateScriptEnvironment(); - - if (NS_SUCCEEDED(res)) { - *aContext = mScriptContext; - NS_ADDREF(mScriptContext); - } - - return res; -} - -nsresult -nsWebShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal) -{ - NS_PRECONDITION(nsnull != aGlobal, "null arg"); - nsresult res = NS_OK; - - res = CreateScriptEnvironment(); - - if (NS_SUCCEEDED(res)) { - *aGlobal = mScriptGlobal; - NS_IF_ADDREF(mScriptGlobal); - } - - return res; -} - -nsresult -nsWebShell::ReleaseScriptContext(nsIScriptContext *aContext) -{ - // XXX Is this right? Why are we passing in a context? - NS_IF_RELEASE(aContext); - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::ReportScriptError(const char* aErrorString, - const char* aFileName, - PRInt32 aLineNo, - const char* aLineBuf) -{ - // XXX To be implemented by scc. The following implementation - // is temporary. - - nsAutoString error; - error.SetString("JavaScript Error: "); - error.Append(aErrorString); - error += "\n"; - - if (aFileName) { - error += "URL: "; - error += aFileName; - error += "\n"; - } - - if(aLineNo) { - error += "LineNo: "; - error.Append(aLineNo, 10); - error += "\n"; - } - - if(aLineBuf) { - error += "Line text: '"; - error += aLineBuf; - error += "'\n"; - } - - // XXX Ughhh...allocation - char* errorStr = error.ToNewCString(); - if (errorStr) { - printf("%s\n", errorStr); - Recycle(errorStr); - } - - // XXX Turn it off for now...there should be an Error method too - //Alert(error.GetUnicode()); - - return NS_OK; -} - NS_IMETHODIMP nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, @@ -4600,7 +4520,7 @@ NS_IMETHODIMP nsWebShell::GetChildAt(PRInt32 aIndex, nsIDocShell** aDocShell) /* depth-first search for a child shell with aName */ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShell **_retval) { - NS_ENSURE_ARG_POINTER(aName); + NS_ENSURE_ARG(aName); NS_ENSURE_ARG_POINTER(_retval); *_retval = nsnull; // if we don't find one, we return NS_OK and a null result @@ -4624,7 +4544,7 @@ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShell { NS_ENSURE_SUCCESS(childAsContainer->FindChildWithName(name.GetUnicode(), _retval), NS_ERROR_FAILURE); } - if (_retval) { // found it + if (*_retval) { // found it break; } } @@ -4632,6 +4552,71 @@ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShell return NS_OK; } +//***************************************************************************** +// nsWebShell::nsIScriptGlobalObjectOwner +//***************************************************************************** + +NS_IMETHODIMP +nsWebShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal) +{ + NS_PRECONDITION(nsnull != aGlobal, "null arg"); + nsresult res = NS_OK; + + res = CreateScriptEnvironment(); + + if (NS_SUCCEEDED(res)) { + *aGlobal = mScriptGlobal; + NS_IF_ADDREF(mScriptGlobal); + } + + return res; +} + +NS_IMETHODIMP +nsWebShell::ReportScriptError(const char* aErrorString, + const char* aFileName, + PRInt32 aLineNo, + const char* aLineBuf) +{ + // XXX To be implemented by scc. The following implementation + // is temporary. + + nsAutoString error; + error.SetString("JavaScript Error: "); + error.Append(aErrorString); + error += "\n"; + + if (aFileName) { + error += "URL: "; + error += aFileName; + error += "\n"; + } + + if(aLineNo) { + error += "LineNo: "; + error.Append(aLineNo, 10); + error += "\n"; + } + + if(aLineBuf) { + error += "Line text: '"; + error += aLineBuf; + error += "'\n"; + } + + // XXX Ughhh...allocation + char* errorStr = error.ToNewCString(); + if (errorStr) { + printf("%s\n", errorStr); + Recycle(errorStr); + } + + // XXX Turn it off for now...there should be an Error method too + //Alert(error.GetUnicode()); + + return NS_OK; +} + //---------------------------------------------------------------------- // Factory code for creating nsWebShell's diff --git a/dom/public/nsIScriptGlobalObject.h b/dom/public/nsIScriptGlobalObject.h index 87aebfc333b54..9305cc8620323 100644 --- a/dom/public/nsIScriptGlobalObject.h +++ b/dom/public/nsIScriptGlobalObject.h @@ -33,6 +33,7 @@ class nsIDOMEvent; class nsIPresContext; class nsIWebShell; class nsIDOMWindow; +class nsIScriptGlobalObjectOwner; #define NS_ISCRIPTGLOBALOBJECT_IID \ { 0x2b16fc80, 0xfa41, 0x11d1, \ @@ -47,12 +48,29 @@ class nsIScriptGlobalObject : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID) - NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext)=0; - NS_IMETHOD_(void) GetContext(nsIScriptContext **aContext)=0; - NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument)=0; - NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell)=0; - NS_IMETHOD_(void) GetWebShell(nsIWebShell **aWebShell)=0; - NS_IMETHOD_(void) SetOpenerWindow(nsIDOMWindow *aOpener)=0; + NS_IMETHOD SetContext(nsIScriptContext *aContext)=0; + NS_IMETHOD GetContext(nsIScriptContext **aContext)=0; + NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument)=0; + NS_IMETHOD SetWebShell(nsIWebShell *aWebShell)=0; + NS_IMETHOD GetWebShell(nsIWebShell **aWebShell)=0; + NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener)=0; + + /** + * Let the script global object know who its owner is. + * The script global object should not addref the owner. It + * will be told when the owner goes away. + * @return NS_OK if the method is successful + */ + NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) = 0; + + /** + * Get the owner of the script global object. The method + * addrefs the returned reference according to regular + * XPCOM rules, even though the internal reference itself + * is a "weak" reference. + */ + NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) = 0; + NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 454df763ff26e..dbea2aab66006 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -54,8 +54,9 @@ #include "nsIPrivateDOMEvent.h" #include "nsIBrowserWindow.h" #include "nsIWebShell.h" +#include "nsIDocShell.h" #include "nsIBaseWindow.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIDocument.h" #include "nsIURL.h" #include "nsIPref.h" @@ -134,6 +135,7 @@ GlobalWindowImpl::GlobalWindowImpl() mLocation = nsnull; mFrames = nsnull; mOpener = nsnull; + mGlobalObjectOwner = nsnull; mTimeouts = nsnull; mTimeoutInsertionPoint = nsnull; @@ -252,7 +254,7 @@ GlobalWindowImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObje return res; } -NS_IMETHODIMP_(void) +NS_IMETHODIMP GlobalWindowImpl::SetContext(nsIScriptContext *aContext) { if (mContext) { @@ -261,23 +263,25 @@ GlobalWindowImpl::SetContext(nsIScriptContext *aContext) mContext = aContext; NS_ADDREF(mContext); + return NS_OK; } -NS_IMETHODIMP_(void) +NS_IMETHODIMP GlobalWindowImpl::GetContext(nsIScriptContext **aContext) { *aContext = mContext; NS_IF_ADDREF(*aContext); + return NS_OK; } -NS_IMETHODIMP_(void) +NS_IMETHODIMP GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument) { if (mFirstDocumentLoad) { mFirstDocumentLoad = PR_FALSE; mDocument = aDocument; NS_IF_ADDREF(mDocument); - return; + return NS_OK; } if (mDocument) { @@ -332,9 +336,10 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument) mContext->InitContext(this); } } + return NS_OK; } -NS_IMETHODIMP_(void) +NS_IMETHODIMP GlobalWindowImpl::SetWebShell(nsIWebShell *aWebShell) { //mWebShell isn't refcnt'd here. WebShell calls SetWebShell(nsnull) when deleted. @@ -384,26 +389,41 @@ GlobalWindowImpl::SetWebShell(nsIWebShell *aWebShell) if(chromeEventHandler) mChromeEventHandler = chromeEventHandler.get(); // Weak ref } + return NS_OK; } -NS_IMETHODIMP_(void) // XXX This may be temporary - rods +NS_IMETHODIMP GlobalWindowImpl::GetWebShell(nsIWebShell **aWebShell) { - if (nsnull != mWebShell) { - *aWebShell = mWebShell; - NS_ADDREF(mWebShell); - } else { - //*mWebShell = nsnull; - } - + *aWebShell = mWebShell; + NS_IF_ADDREF(*aWebShell); + return NS_OK; } -NS_IMETHODIMP_(void) +NS_IMETHODIMP GlobalWindowImpl::SetOpenerWindow(nsIDOMWindow *aOpener) { NS_IF_RELEASE(mOpener); mOpener = aOpener; NS_IF_ADDREF(mOpener); + return NS_OK; +} + +NS_IMETHODIMP +GlobalWindowImpl::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) +{ + mGlobalObjectOwner = aOwner; // Note this is supposed to be a weak ref. + return NS_OK; +} + +NS_IMETHODIMP +GlobalWindowImpl::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) +{ + NS_ENSURE_ARG_POINTER(aOwner); + + *aOwner = mGlobalObjectOwner; + NS_IF_ADDREF(*aOwner); + return NS_OK; } NS_IMETHODIMP @@ -1310,13 +1330,12 @@ GlobalWindowImpl::Close(JSContext* cx, jsval* argv, PRUint32 argc) nsresult result = NS_OK; nsIScriptContext* callingContext = (nsIScriptContext*)JS_GetContextPrivate(cx); nsIScriptContext* winContext; - nsCOMPtr owner; + nsCOMPtr globalObject(do_GetInterface(mWebShell)); - if (mWebShell) { - owner = do_QueryInterface(mWebShell, &result); + if (globalObject) { if (NS_SUCCEEDED(result)) { - result = owner->GetScriptContext(&winContext); + result = globalObject->GetContext(&winContext); if (NS_SUCCEEDED(result)) { if (winContext == callingContext) { result = callingContext->SetTerminationFunction(CloseWindow, (nsISupports*)(nsIScriptGlobalObject*)this); @@ -2515,21 +2534,13 @@ GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, nsresult GlobalWindowImpl::ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow) { - nsIScriptContextOwner *newContextOwner = nsnull; - nsIScriptGlobalObject *newGlobalObject = nsnull; nsresult res; *aDOMWindow = nsnull; - res = aWebShell->QueryInterface(NS_GET_IID(nsIScriptContextOwner), (void**)&newContextOwner); - if (NS_SUCCEEDED(res)) { - res = newContextOwner->GetScriptGlobalObject(&newGlobalObject); - if (NS_SUCCEEDED(res)) { - res = newGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aDOMWindow); - newGlobalObject->SetOpenerWindow(this); // damnit - NS_RELEASE(newGlobalObject); - } - NS_RELEASE(newContextOwner); - } + nsCOMPtr globalObject(do_GetInterface(mWebShell)); + NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); + res = CallQueryInterface(globalObject.get(), aDOMWindow); + globalObject->SetOpenerWindow(this); // damnit return res; } @@ -2537,21 +2548,11 @@ GlobalWindowImpl::ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDO nsresult GlobalWindowImpl::WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow) { - nsresult rv; - - NS_ASSERTION(aWebShell, "null in param to WebShellToDOMWindow"); - NS_ASSERTION(aDOMWindow, "null out param to WebShellToDOMWindow"); - - *aDOMWindow = nsnull; + NS_ENSURE_ARG_POINTER(aDOMWindow); + NS_ENSURE_TRUE(aWebShell, NS_ERROR_FAILURE); - nsCOMPtr owner = do_QueryInterface(aWebShell, &rv); - if (owner) { - nsCOMPtr scriptobj; - rv = owner->GetScriptGlobalObject(getter_AddRefs(scriptobj)); - if (NS_SUCCEEDED(rv) && scriptobj) - rv = scriptobj->QueryInterface(nsIDOMWindow::GetIID(), (void **) aDOMWindow); - } - return rv; + nsCOMPtr globalObject(do_GetInterface(aWebShell)); + return CallQueryInterface(globalObject.get(), aDOMWindow); } NS_IMETHODIMP @@ -2876,23 +2877,17 @@ GlobalWindowImpl::Resolve(JSContext *aContext, jsval aID) if (child) { JSObject *childObj; //We found a subframe of the right name. The rest of this is to get its script object. - nsIScriptContextOwner *contextOwner; - if (NS_SUCCEEDED(child->QueryInterface(NS_GET_IID(nsIScriptContextOwner), (void**)&contextOwner))) { - nsIScriptGlobalObject *childGlobalObj; - if (NS_SUCCEEDED(contextOwner->GetScriptGlobalObject(&childGlobalObj))) { - nsIScriptObjectOwner *objOwner; - if (NS_SUCCEEDED(childGlobalObj->QueryInterface(NS_GET_IID(nsIScriptObjectOwner), (void**)&objOwner))) { - nsIScriptContext *scriptContext; - childGlobalObj->GetContext(&scriptContext); - if (scriptContext) { - objOwner->GetScriptObject(scriptContext, (void**)&childObj); - NS_RELEASE(scriptContext); - } - NS_RELEASE(objOwner); + nsCOMPtr childGlobalObject(do_GetInterface(child)); + if(childGlobalObject) { + nsCOMPtr objOwner(do_QueryInterface(childGlobalObject)); + if(objOwner) { + nsCOMPtr scriptContext; + + childGlobalObject->GetContext(getter_AddRefs(scriptContext)); + if(scriptContext) { + objOwner->GetScriptObject(scriptContext, (void**)&childObj); } - NS_RELEASE(childGlobalObj); - } - NS_RELEASE(contextOwner); + } } //Okay, if we now have a childObj, we can define it and proceed. if (childObj) { @@ -3487,12 +3482,8 @@ GlobalWindowImpl::GetPrivateParent(nsPIDOMWindow** aParent) NS_ENSURE_SUCCESS(chromeElement->GetDocument(*getter_AddRefs(doc)), NS_ERROR_FAILURE); - nsCOMPtr contextOwner = - dont_QueryInterface(doc->GetScriptContextOwner()); - NS_ENSURE_TRUE(contextOwner, NS_ERROR_FAILURE); - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + doc->GetScriptGlobalObject(getter_AddRefs(globalObject)); NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); parent = do_QueryInterface(globalObject); diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 72d409c79f5dd..9f22e773361a6 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -85,12 +85,14 @@ class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObje NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD SetScriptObject(void *aScriptObject); - NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext); - NS_IMETHOD_(void) GetContext(nsIScriptContext **aContext); - NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument); - NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell); - NS_IMETHOD_(void) GetWebShell(nsIWebShell **aWebShell);// XXX This may be temporary - rods - NS_IMETHOD_(void) SetOpenerWindow(nsIDOMWindow *aOpener); + NS_IMETHOD SetContext(nsIScriptContext *aContext); + NS_IMETHOD GetContext(nsIScriptContext **aContext); + NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument); + NS_IMETHOD SetWebShell(nsIWebShell *aWebShell); + NS_IMETHOD GetWebShell(nsIWebShell **aWebShell);// XXX This may be temporary - rods + NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener); + NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); + NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); NS_IMETHOD GetWindow(nsIDOMWindow** aWindow); NS_IMETHOD GetSelf(nsIDOMWindow** aSelf); @@ -274,6 +276,7 @@ class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObje HistoryImpl *mHistory; nsIWebShell *mWebShell; nsIDOMWindow *mOpener; + nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // [Weak Ref] BarPropImpl *mMenubar; BarPropImpl *mToolbar; diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index f03cba03940cc..a1011f8aad5e7 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -24,6 +24,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptGlobalObjectData.h" #include "nsIDOMWindow.h" #include "nsIDOMNode.h" @@ -70,28 +71,32 @@ NS_ScriptErrorReporter(JSContext *cx, JSErrorReport *report) { nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx); + nsCOMPtr globalObject(context->GetGlobalObject()); + + if (globalObject) { + nsCOMPtr owner; + if(NS_FAILED(globalObject->GetGlobalObjectOwner(getter_AddRefs(owner))) || + !owner) { + NS_WARN_IF_FALSE(PR_FALSE, "Failed to get a global Object Owner"); + return; + } + + const char* error; + if (message) { + error = message; + } + else { + error = ""; + } - if (context) { - nsCOMPtr owner; - nsresult rv = context->GetOwner(getter_AddRefs(owner)); - if (NS_SUCCEEDED(rv) && owner) { - const char* error; - if (message) { - error = message; - } - else { - error = ""; - } - - if (report) { + if(report) { owner->ReportScriptError(error, report->filename, report->lineno, report->linebuf); - } - else { + } + else { owner->ReportScriptError(error, nsnull, 0, nsnull); - } } } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 2d4931665635c..c7154eab2661b 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -38,7 +38,7 @@ #include "nsIStyleSheet.h" #include "nsIFrame.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsILinkHandler.h" #include "nsIDOMDocument.h" @@ -201,7 +201,6 @@ static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); // Interface IDs -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); @@ -304,19 +303,13 @@ DocumentViewerImpl::~DocumentViewerImpl() if (mDocument) { // Break global object circular reference on the document created // in the DocViewer Init - nsIScriptContextOwner *mOwner = mDocument->GetScriptContextOwner(); - if (nsnull != mOwner) { - nsIScriptGlobalObject *mGlobal; - mOwner->GetScriptGlobalObject(&mGlobal); - if (nsnull != mGlobal) { - mGlobal->SetNewDocument(nsnull); - NS_RELEASE(mGlobal); - } - NS_RELEASE(mOwner); - - // out of band cleanup of webshell - mDocument->SetScriptContextOwner(nsnull); + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + global->SetNewDocument(nsnull); } + // out of band cleanup of webshell + mDocument->SetScriptGlobalObject(nsnull); } if (mDeviceContext) @@ -404,14 +397,14 @@ DocumentViewerImpl::Init(nsNativeWidget aNativeParent, mPresContext->SetLinkHandler(linkHandler); // Set script-context-owner in the document - nsCOMPtr owner; - requestor->GetInterface(NS_GET_IID(nsIScriptContextOwner), + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), getter_AddRefs(owner)); if (nsnull != owner) { - mDocument->SetScriptContextOwner(owner); nsCOMPtr global; rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); if (NS_SUCCEEDED(rv) && (nsnull != global)) { + mDocument->SetScriptGlobalObject(global); nsCOMPtr domdoc(do_QueryInterface(mDocument)); if (nsnull != domdoc) { global->SetNewDocument(domdoc); diff --git a/layout/base/public/nsIDocument.h b/layout/base/public/nsIDocument.h index 5b4852af6d7d0..823cf62de3d01 100644 --- a/layout/base/public/nsIDocument.h +++ b/layout/base/public/nsIDocument.h @@ -44,7 +44,7 @@ class nsIURI; class nsILoadGroup; class nsIViewManager; class nsString; -class nsIScriptContextOwner; +class nsIScriptGlobalObject; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; @@ -213,8 +213,8 @@ class nsIDocument : public nsISupports { * This is the context within which all scripts (during document * creation and during event handling) will run. */ - virtual nsIScriptContextOwner *GetScriptContextOwner() = 0; - virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) = 0; + NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject) = 0; + NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0; /** * Get the name space manager for this document diff --git a/layout/base/src/nsDocument.cpp b/layout/base/src/nsDocument.cpp index fd6e19ea0019a..23e506eebd77c 100644 --- a/layout/base/src/nsDocument.cpp +++ b/layout/base/src/nsDocument.cpp @@ -22,6 +22,7 @@ #include "plstr.h" #include "nsCOMPtr.h" +#include "nsIInterfaceRequestor.h" #include "nsDocument.h" #include "nsIArena.h" #include "nsIURL.h" @@ -36,7 +37,6 @@ #include "nsIDocumentObserver.h" #include "nsEventListenerManager.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptEventListener.h" #include "nsDOMEvent.h" #include "nsDOMEventsIIDs.h" @@ -575,7 +575,6 @@ nsDocument::nsDocument() mParentDocument = nsnull; mRootContent = nsnull; mScriptObject = nsnull; - mScriptContextOwner = nsnull; mListenerManager = nsnull; mDisplaySelection = PR_FALSE; mInDestructor = PR_FALSE; @@ -661,7 +660,6 @@ nsDocument::~nsDocument() } NS_IF_RELEASE(mArena); - NS_IF_RELEASE(mScriptContextOwner); NS_IF_RELEASE(mListenerManager); NS_IF_RELEASE(mDOMStyleSheets); NS_IF_RELEASE(mNameSpaceManager); @@ -1399,35 +1397,30 @@ void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet, } } -nsIScriptContextOwner *nsDocument::GetScriptContextOwner() +NS_IMETHODIMP +nsDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject) { - if (nsnull != mScriptContextOwner) { - NS_ADDREF(mScriptContextOwner); - } - - return mScriptContextOwner; + NS_ENSURE_ARG_POINTER(aScriptGlobalObject); + + *aScriptGlobalObject = mScriptGlobalObject; + NS_IF_ADDREF(*aScriptGlobalObject); + return NS_OK; } -void nsDocument::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) +NS_IMETHODIMP +nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) { // XXX HACK ALERT! If the script context owner is null, the document // will soon be going away. So tell our content that to lose its // reference to the document. This has to be done before we // actually set the script context owner to null so that the // content elements can remove references to their script objects. - if ((nsnull == aScriptContextOwner) && (nsnull != mRootContent)) { + if ((nsnull == aScriptGlobalObject) && (nsnull != mRootContent)) { mRootContent->SetDocument(nsnull, PR_TRUE); } - if (nsnull != mScriptContextOwner) { - NS_RELEASE(mScriptContextOwner); - } - - mScriptContextOwner = aScriptContextOwner; - - if (nsnull != mScriptContextOwner) { - NS_ADDREF(mScriptContextOwner); - } + mScriptGlobalObject = aScriptGlobalObject; + return NS_OK; } NS_IMETHODIMP @@ -1715,10 +1708,7 @@ nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptO res = cx->GetContainer(getter_AddRefs(container)); if (NS_SUCCEEDED(res) && container) { - nsCOMPtr sco = do_QueryInterface(container); - if (sco) { - res = sco->GetScriptGlobalObject(getter_AddRefs(global)); - } + global = do_GetInterface(container); } } // XXX If we can't find a view, parent to the calling context's @@ -2399,12 +2389,8 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Capturing stage - if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptContextOwner) { - nsIScriptGlobalObject* mGlobal; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&mGlobal)) { - mGlobal->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - NS_RELEASE(mGlobal); - } + if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); } //Local handling stage @@ -2414,11 +2400,8 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptContextOwner) { - nsCOMPtr global; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global))) { - global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); - } + if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } if (NS_EVENT_FLAG_INIT == aFlags) { @@ -2506,19 +2489,13 @@ PRBool nsDocument::GetProperty(JSContext *aContext, jsval aID, jsval *aVp) if (JSVAL_IS_STRING(aID) && PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) { - if (nsnull != mScriptContextOwner) { - nsIScriptGlobalObject *global; - mScriptContextOwner->GetScriptGlobalObject(&global); - if (nsnull != global) { - nsIJSScriptObject *window; - if (NS_OK == global->QueryInterface(kIJSScriptObjectIID, (void **)&window)) { - result = window->GetProperty(aContext, aID, aVp); - NS_RELEASE(window); - } - else { - result = PR_FALSE; - } - NS_RELEASE(global); + if (mScriptGlobalObject) { + nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); + if(window) { + result = window->GetProperty(aContext, aID, aVp); + } + else { + result = PR_FALSE; } } } @@ -2611,19 +2588,13 @@ PRBool nsDocument::SetProperty(JSContext *aContext, jsval aID, jsval *aVp) } else if (JSVAL_IS_STRING(aID) && PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) { - if (nsnull != mScriptContextOwner) { - nsIScriptGlobalObject *global; - mScriptContextOwner->GetScriptGlobalObject(&global); - if (nsnull != global) { - nsIJSScriptObject *window; - if (NS_OK == global->QueryInterface(kIJSScriptObjectIID, (void **)&window)) { - result = window->SetProperty(aContext, aID, aVp); - NS_RELEASE(window); - } - else { - result = PR_FALSE; - } - NS_RELEASE(global); + if (mScriptGlobalObject) { + nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); + if(window) { + result = window->SetProperty(aContext, aID, aVp); + } + else { + result = PR_FALSE; } } } diff --git a/layout/base/src/nsDocument.h b/layout/base/src/nsDocument.h index 221772699b04f..8a21064f109fe 100644 --- a/layout/base/src/nsDocument.h +++ b/layout/base/src/nsDocument.h @@ -31,7 +31,7 @@ #include "nsIDOMEventReceiver.h" #include "nsIDiskDocument.h" #include "nsIScriptObjectOwner.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIDOMEventTarget.h" #include "nsXIFConverter.h" #include "nsIJSScriptObject.h" @@ -244,8 +244,8 @@ class nsDocument : public nsIDocument, * This is the context within which all scripts (during document * creation and during event handling) will run. */ - virtual nsIScriptContextOwner *GetScriptContextOwner(); - virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner); + NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject); + NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject); /** * Get the name space manager for this document @@ -466,7 +466,7 @@ class nsDocument : public nsIDocument, nsVoidArray mStyleSheets; nsVoidArray mObservers; void* mScriptObject; - nsIScriptContextOwner *mScriptContextOwner; + nsCOMPtr mScriptGlobalObject; nsIEventListenerManager* mListenerManager; PRBool mDisplaySelection; PRBool mInDestructor; diff --git a/layout/base/src/nsDocumentViewer.cpp b/layout/base/src/nsDocumentViewer.cpp index 2d4931665635c..c7154eab2661b 100644 --- a/layout/base/src/nsDocumentViewer.cpp +++ b/layout/base/src/nsDocumentViewer.cpp @@ -38,7 +38,7 @@ #include "nsIStyleSheet.h" #include "nsIFrame.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsILinkHandler.h" #include "nsIDOMDocument.h" @@ -201,7 +201,6 @@ static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); // Interface IDs -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); @@ -304,19 +303,13 @@ DocumentViewerImpl::~DocumentViewerImpl() if (mDocument) { // Break global object circular reference on the document created // in the DocViewer Init - nsIScriptContextOwner *mOwner = mDocument->GetScriptContextOwner(); - if (nsnull != mOwner) { - nsIScriptGlobalObject *mGlobal; - mOwner->GetScriptGlobalObject(&mGlobal); - if (nsnull != mGlobal) { - mGlobal->SetNewDocument(nsnull); - NS_RELEASE(mGlobal); - } - NS_RELEASE(mOwner); - - // out of band cleanup of webshell - mDocument->SetScriptContextOwner(nsnull); + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + global->SetNewDocument(nsnull); } + // out of band cleanup of webshell + mDocument->SetScriptGlobalObject(nsnull); } if (mDeviceContext) @@ -404,14 +397,14 @@ DocumentViewerImpl::Init(nsNativeWidget aNativeParent, mPresContext->SetLinkHandler(linkHandler); // Set script-context-owner in the document - nsCOMPtr owner; - requestor->GetInterface(NS_GET_IID(nsIScriptContextOwner), + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), getter_AddRefs(owner)); if (nsnull != owner) { - mDocument->SetScriptContextOwner(owner); nsCOMPtr global; rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); if (NS_SUCCEEDED(rv) && (nsnull != global)) { + mDocument->SetScriptGlobalObject(global); nsCOMPtr domdoc(do_QueryInterface(mDocument)); if (nsnull != domdoc) { global->SetNewDocument(domdoc); diff --git a/layout/base/src/nsGenericDOMDataNode.cpp b/layout/base/src/nsGenericDOMDataNode.cpp index c755f6b5886c7..60711479e61c5 100644 --- a/layout/base/src/nsGenericDOMDataNode.cpp +++ b/layout/base/src/nsGenericDOMDataNode.cpp @@ -41,7 +41,7 @@ #include "nsDOMEvent.h" #include "nsIDOMText.h" #include "nsIDOMScriptObjectFactory.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" #include "prprf.h" #include "nsCOMPtr.h" @@ -714,15 +714,14 @@ nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep) // script context reference to our script object so that our // script object can be freed (or collected). if ((nsnull != mDocument) && (nsnull != mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { context->RemoveReference((void *)&mScriptObject, mScriptObject); - NS_RELEASE(context); } - NS_RELEASE(owner); } } @@ -733,16 +732,15 @@ nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep) // reference to our script object. This will ensure that it // won't be freed (or collected) out from under us. if ((nsnull != mDocument) && (nsnull != mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { context->AddNamedReference((void *)&mScriptObject, mScriptObject, "Text"); - NS_RELEASE(context); } - NS_RELEASE(owner); } } diff --git a/layout/base/src/nsGenericElement.cpp b/layout/base/src/nsGenericElement.cpp index d3f83af1ce787..8823a8052387b 100644 --- a/layout/base/src/nsGenericElement.cpp +++ b/layout/base/src/nsGenericElement.cpp @@ -34,7 +34,6 @@ #include "nsRange.h" #include "nsIEventListenerManager.h" #include "nsILinkHandler.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" #include "nsISizeOfHandler.h" @@ -672,15 +671,14 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) // script object can be freed (or collected). if ((nsnull != mDocument) && (nsnull != mDOMSlots) && (nsnull != mDOMSlots->mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { context->RemoveReference((void *)&mDOMSlots->mScriptObject, mDOMSlots->mScriptObject); - NS_RELEASE(context); } - NS_RELEASE(owner); } } @@ -692,10 +690,11 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) // won't be freed (or collected) out from under us. if ((nsnull != mDocument) && (nsnull != mDOMSlots) && (nsnull != mDOMSlots->mScriptObject)) { - nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - nsIScriptContext *context; - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + nsCOMPtr context; + if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) { nsAutoString tag; char tagBuf[50]; @@ -704,9 +703,7 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) context->AddNamedReference((void *)&mDOMSlots->mScriptObject, mDOMSlots->mScriptObject, tagBuf); - NS_RELEASE(context); } - NS_RELEASE(owner); } } @@ -1292,15 +1289,14 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, { nsresult ret = NS_OK; nsIScriptContext* context; - nsIScriptContextOwner* owner; if (nsnull != mDocument) { - owner = mDocument->GetScriptContextOwner(); - if (owner) { - if (NS_OK == owner->GetScriptContext(&context)) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + if (NS_OK == global->GetContext(&context)) { if (nsHTMLAtoms::body == mTag || nsHTMLAtoms::frameset == mTag) { nsIDOMEventReceiver *receiver; - nsIScriptGlobalObject *global = context->GetGlobalObject(); if (nsnull != global && NS_OK == global->QueryInterface(kIDOMEventReceiverIID, (void**)&receiver)) { nsIEventListenerManager *manager; @@ -1314,7 +1310,6 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, } NS_RELEASE(receiver); } - NS_IF_RELEASE(global); } else { nsIEventListenerManager *manager; @@ -1331,7 +1326,6 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, } NS_RELEASE(context); } - NS_RELEASE(owner); } } return ret; diff --git a/layout/base/src/nsRange.cpp b/layout/base/src/nsRange.cpp index b0e951c0cc3f6..ad3a6fd2d326e 100644 --- a/layout/base/src/nsRange.cpp +++ b/layout/base/src/nsRange.cpp @@ -1952,7 +1952,7 @@ nsRange::IsValidFragment(const nsString& aFragment, PRBool* aReturn) return result; } -// BEGIN nsIScriptContextOwner interface implementations +// BEGIN nsIScriptObjectOwner interface implementations NS_IMETHODIMP nsRange::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { @@ -1975,7 +1975,7 @@ nsRange::SetScriptObject(void *aScriptObject) return NS_OK; } -// END nsIScriptContextOwner interface implementations +// END nsIScriptObjectOwner interface implementations nsresult nsRange::Lock() diff --git a/layout/base/src/nsRangeList.cpp b/layout/base/src/nsRangeList.cpp index 8c6bac5a8e07b..7ed935558a10d 100644 --- a/layout/base/src/nsRangeList.cpp +++ b/layout/base/src/nsRangeList.cpp @@ -192,7 +192,7 @@ class nsDOMSelection : public nsIDOMSelection , public nsIScriptObjectOwner nsRangeList *mRangeList; - // for nsIScriptContextOwner + // for nsIScriptObjectOwner void* mScriptObject; nsAutoScrollTimer *mAutoScrollTimer; // timer for autoscrolling. @@ -4156,7 +4156,7 @@ nsDOMSelection::DeleteFromDocument() return mRangeList->DeleteFromDocument(); } -// BEGIN nsIScriptContextOwner interface implementations +// BEGIN nsIScriptObjectOwner interface implementations NS_IMETHODIMP nsDOMSelection::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { @@ -4179,4 +4179,4 @@ nsDOMSelection::SetScriptObject(void *aScriptObject) return NS_OK; } -// END nsIScriptContextOwner interface implementations +// END nsIScriptObjectOwner interface implementations diff --git a/layout/events/src/nsEventStateManager.cpp b/layout/events/src/nsEventStateManager.cpp index 51370ff138f0c..ab35f3faa237c 100644 --- a/layout/events/src/nsEventStateManager.cpp +++ b/layout/events/src/nsEventStateManager.cpp @@ -45,7 +45,6 @@ #include "nsIDOMSelection.h" #include "nsIFrameSelection.h" #include "nsIDeviceContext.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsISelfScrollingFrame.h" @@ -249,11 +248,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, if (gLastFocusedDocument) { mCurrentTarget = nsnull; - nsCOMPtr contextOwner = dont_QueryInterface(gLastFocusedDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -289,11 +285,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentTarget = nsnull; // fire focus on window, not document - nsCOMPtr contextOwner = dont_QueryInterface(mDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -354,11 +347,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentTarget = nsnull; // fire focus on window, not document - nsCOMPtr contextOwner = dont_QueryInterface(mDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -400,11 +390,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentTarget = nsnull; // fire focus on window, not document - nsCOMPtr contextOwner = dont_QueryInterface(mDocument->GetScriptContextOwner()); - if(!contextOwner) break; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) break; globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -1973,16 +1960,12 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo } if (gLastFocusedDocument) { - nsCOMPtr contextOwner = dont_QueryInterface(gLastFocusedDocument->GetScriptContextOwner()); - if(contextOwner){ - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if(globalObject) - globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - gLastFocusedDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - + nsCOMPtr globalObject; + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if(globalObject) + globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + gLastFocusedDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } NS_IF_RELEASE(mCurrentTargetContent); } } diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index d7d7bdcf7d120..e7cf075ede1f2 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -753,9 +753,7 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext, // nearest enclosing chrome shell. nsCOMPtr chromeEventHandler; - nsWebShellType chromeShellType; - outerShell->GetWebShellType(chromeShellType); - if (chromeShellType == nsWebShellChrome) { + if (parentType == nsWebShellChrome) { // Our parent shell is a chrome shell. It is therefore our nearest // enclosing chrome shell. chromeEventHandler = do_QueryInterface(mContent); diff --git a/layout/html/content/src/nsAttributeContent.cpp b/layout/html/content/src/nsAttributeContent.cpp index 2309e7a9405f8..eb8bd5983cee3 100644 --- a/layout/html/content/src/nsAttributeContent.cpp +++ b/layout/html/content/src/nsAttributeContent.cpp @@ -41,7 +41,6 @@ #include "nsDOMEvent.h" #include "nsIDOMText.h" #include "nsIDOMScriptObjectFactory.h" -#include "nsIScriptContextOwner.h" #include "prprf.h" #include "nsCOMPtr.h" diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp index 6fd0928bda479..53e49cbdc1ae1 100644 --- a/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/layout/html/content/src/nsGenericHTMLElement.cpp @@ -38,7 +38,6 @@ #include "nsIHTMLDocument.h" #include "nsIHTMLContent.h" #include "nsILinkHandler.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" #include "nsISizeOfHandler.h" diff --git a/layout/html/content/src/nsHTMLFormElement.cpp b/layout/html/content/src/nsHTMLFormElement.cpp index 0780dea7e684b..04151453fc310 100644 --- a/layout/html/content/src/nsHTMLFormElement.cpp +++ b/layout/html/content/src/nsHTMLFormElement.cpp @@ -27,7 +27,6 @@ #include "nsIDOMNSHTMLFormElement.h" #include "nsIDOMHTMLCollection.h" #include "nsIScriptObjectOwner.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -41,6 +40,7 @@ #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsISizeOfHandler.h" +#include "nsIScriptGlobalObject.h" static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); @@ -566,11 +566,10 @@ nsHTMLFormElement::Resolve(JSContext *aContext, jsval aID) nsCOMPtr scriptContext; if (nsnull != mInner.mDocument) { - nsCOMPtr contextOwner; - - contextOwner = getter_AddRefs(mInner.mDocument->GetScriptContextOwner()); - if (contextOwner) { - result = contextOwner->GetScriptContext(getter_AddRefs(scriptContext)); + nsCOMPtr globalObject; + mInner.mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (globalObject) { + result = globalObject->GetContext(getter_AddRefs(scriptContext)); } } else { diff --git a/layout/html/document/src/nsFrameFrame.cpp b/layout/html/document/src/nsFrameFrame.cpp index d7d7bdcf7d120..e7cf075ede1f2 100644 --- a/layout/html/document/src/nsFrameFrame.cpp +++ b/layout/html/document/src/nsFrameFrame.cpp @@ -753,9 +753,7 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext, // nearest enclosing chrome shell. nsCOMPtr chromeEventHandler; - nsWebShellType chromeShellType; - outerShell->GetWebShellType(chromeShellType); - if (chromeShellType == nsWebShellChrome) { + if (parentType == nsWebShellChrome) { // Our parent shell is a chrome shell. It is therefore our nearest // enclosing chrome shell. chromeEventHandler = do_QueryInterface(mContent); diff --git a/layout/html/document/src/nsHTMLContentSink.cpp b/layout/html/document/src/nsHTMLContentSink.cpp index a80eaccb9c679..5efe20bfc23fa 100644 --- a/layout/html/document/src/nsHTMLContentSink.cpp +++ b/layout/html/document/src/nsHTMLContentSink.cpp @@ -68,11 +68,11 @@ #include "nsIDOMHTMLMapElement.h" #include "nsIRefreshURI.h" #include "nsVoidArray.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" #include "nsHTMLIIDs.h" #include "nsTextFragment.h" +#include "nsIScriptGlobalObject.h" #include "nsIParserService.h" #include "nsParserCIID.h" @@ -189,11 +189,9 @@ class HTMLContentSink : public nsIHTMLContentSink, void ReduceEntities(nsString& aString); void GetAttributeValueAt(const nsIParserNode& aNode, PRInt32 aIndex, - nsString& aResult, - nsIScriptContextOwner* aScriptContextOwner); + nsString& aResult); nsresult AddAttributes(const nsIParserNode& aNode, nsIHTMLContent* aContent, - nsIScriptContextOwner* aScriptContextOwner, PRBool aNotify = PR_FALSE); nsresult CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType, @@ -509,8 +507,7 @@ HTMLContentSink::ReduceEntities(nsString& aString) void HTMLContentSink::GetAttributeValueAt(const nsIParserNode& aNode, PRInt32 aIndex, - nsString& aResult, - nsIScriptContextOwner* aScriptContextOwner) + nsString& aResult) { // Copy value const nsString& value = aNode.GetValueAt(aIndex); @@ -536,7 +533,6 @@ HTMLContentSink::GetAttributeValueAt(const nsIParserNode& aNode, nsresult HTMLContentSink::AddAttributes(const nsIParserNode& aNode, nsIHTMLContent* aContent, - nsIScriptContextOwner* aScriptContextOwner, PRBool aNotify) { // Add tag attributes to the content attributes @@ -555,7 +551,7 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode, if (NS_CONTENT_ATTR_NOT_THERE == aContent->GetHTMLAttribute(keyAtom, value)) { // Get value and remove mandatory quotes - GetAttributeValueAt(aNode, i, v, aScriptContextOwner); + GetAttributeValueAt(aNode, i, v); // Add attribute to content aContent->SetAttribute(kNameSpaceID_HTML, keyAtom, v,aNotify); @@ -1151,9 +1147,9 @@ SinkContext::OpenContainer(const nsIParserNode& aNode) mStack[mStackPos].mInsertionPoint = -1; content->SetDocument(mSink->mDocument, PR_FALSE); - nsIScriptContextOwner* sco = mSink->mDocument->GetScriptContextOwner(); - rv = mSink->AddAttributes(aNode, content, sco); - NS_IF_RELEASE(sco); + nsCOMPtr scriptGlobalObject; + mSink->mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); + rv = mSink->AddAttributes(aNode, content); if (mPreAppend) { NS_ASSERTION(mStackPos > 0, "container w/o parent"); @@ -1456,9 +1452,7 @@ SinkContext::AddLeaf(const nsIParserNode& aNode) // Set the content's document content->SetDocument(mSink->mDocument, PR_FALSE); - nsIScriptContextOwner* sco = mSink->mDocument->GetScriptContextOwner(); - rv = mSink->AddAttributes(aNode, content, sco); - NS_IF_RELEASE(sco); + rv = mSink->AddAttributes(aNode, content); if (NS_OK != rv) { NS_RELEASE(content); return rv; @@ -2293,9 +2287,7 @@ HTMLContentSink::OpenHead(const nsIParserNode& aNode) mCurrentContext = mHeadContext; if (nsnull != mHead) { - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); - rv = AddAttributes(aNode, mHead, sco); - NS_IF_RELEASE(sco); + rv = AddAttributes(aNode, mHead); } MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n")); @@ -2331,9 +2323,7 @@ HTMLContentSink::OpenBody(const nsIParserNode& aNode) mCurrentContext->mStackPos, this); // Add attributes, if any, to the current BODY node if(mBody != nsnull){ - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); - AddAttributes(aNode,mBody,sco,PR_TRUE); - NS_IF_RELEASE(sco); + AddAttributes(aNode,mBody,PR_TRUE); MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n")); MOZ_TIMER_STOP(mWatch); return NS_OK; @@ -2887,10 +2877,8 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) area->SetContentID(mContentIDCounter++); // Set the content's document and attributes - area->SetDocument(mDocument, PR_FALSE); - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); - rv = AddAttributes(aNode, area, sco); - NS_IF_RELEASE(sco); + area->SetDocument(mDocument, PR_FALSE); + rv = AddAttributes(aNode, area); if (NS_FAILED(rv)) { NS_RELEASE(area); return rv; @@ -2949,7 +2937,6 @@ nsresult HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) { nsresult result = NS_OK; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); // Create content object nsAutoString tag("BASE"); @@ -2961,7 +2948,7 @@ HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - result = AddAttributes(aNode, element, sco); + result = AddAttributes(aNode, element); if (NS_SUCCEEDED(result)) { mHead->AppendChildTo(element, PR_FALSE); @@ -2975,7 +2962,6 @@ HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) } } - NS_IF_RELEASE(sco); return result; } @@ -3250,27 +3236,26 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) nsAutoString type; nsAutoString media; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); for (i = 0; i < count; i++) { const nsString& key = aNode.GetKeyAt(i); if (key.EqualsIgnoreCase("href")) { - GetAttributeValueAt(aNode, i, href, sco); + GetAttributeValueAt(aNode, i, href); href.StripWhitespace(); } else if (key.EqualsIgnoreCase("rel")) { - GetAttributeValueAt(aNode, i, rel, sco); + GetAttributeValueAt(aNode, i, rel); rel.CompressWhitespace(); } else if (key.EqualsIgnoreCase("title")) { - GetAttributeValueAt(aNode, i, title, sco); + GetAttributeValueAt(aNode, i, title); title.CompressWhitespace(); } else if (key.EqualsIgnoreCase("type")) { - GetAttributeValueAt(aNode, i, type, sco); + GetAttributeValueAt(aNode, i, type); type.StripWhitespace(); } else if (key.EqualsIgnoreCase("media")) { - GetAttributeValueAt(aNode, i, media, sco); + GetAttributeValueAt(aNode, i, media); media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE } } @@ -3285,7 +3270,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - result = AddAttributes(aNode, element, sco); + result = AddAttributes(aNode, element); if (NS_FAILED(result)) { NS_RELEASE(element); return result; @@ -3293,10 +3278,8 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) mHead->AppendChildTo(element, PR_FALSE); } else { - NS_IF_RELEASE(sco); return result; } - NS_IF_RELEASE(sco); result = ProcessStyleLink(element, href, rel, title, type, media); @@ -3357,10 +3340,8 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) if (NS_OK == rv) { // Add in the attributes and add the meta content object to the // head container. - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); it->SetDocument(mDocument, PR_FALSE); - rv = AddAttributes(aNode, it, sco); - NS_IF_RELEASE(sco); + rv = AddAttributes(aNode, it); if (NS_OK != rv) { NS_RELEASE(it); return rv; @@ -3594,40 +3575,33 @@ HTMLContentSink::EvaluateScript(nsString& aScript, nsresult rv = NS_OK; if (aScript.Length() > 0) { - nsIScriptContextOwner *owner; - nsIScriptContext *context; - owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - - rv = owner->GetScriptContext(&context); - if (rv != NS_OK) { - NS_RELEASE(owner); - return rv; - } + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); - nsCOMPtr principal; - principal = getter_AddRefs(mDocument->GetDocumentPrincipal()); - NS_ASSERTION(principal, "principal expected for document"); - - nsAutoString ret; - nsIURI* docURL = mDocument->GetDocumentURL(); - char* url = nsnull; + nsCOMPtr context; + NS_ENSURE_SUCCESS(globalObject->GetContext(getter_AddRefs(context)), + NS_ERROR_FAILURE); - if (docURL) { - (void)docURL->GetSpec(&url); - } + nsCOMPtr principal; + principal = getter_AddRefs(mDocument->GetDocumentPrincipal()); + NS_ASSERTION(principal, "principal expected for document"); + + nsAutoString ret; + nsIURI* docURL = mDocument->GetDocumentURL(); + char* url = nsnull; + + if (docURL) { + (void)docURL->GetSpec(&url); + } - PRBool isUndefined; - context->EvaluateString(aScript, nsnull, principal, url, - aLineNo, aVersion, ret, &isUndefined); - - if (docURL) { - NS_RELEASE(docURL); - nsCRT::free(url); - } - - NS_RELEASE(context); - NS_RELEASE(owner); + PRBool isUndefined; + context->EvaluateString(aScript, nsnull, principal, url, + aLineNo, aVersion, ret, &isUndefined); + + if (docURL) { + NS_RELEASE(docURL); + nsCRT::free(url); } } @@ -3675,12 +3649,12 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) for (i = 0; i < ac; i++) { const nsString& key = aNode.GetKeyAt(i); if (key.EqualsIgnoreCase("src")) { - GetAttributeValueAt(aNode, i, src, nsnull); + GetAttributeValueAt(aNode, i, src); } else if (key.EqualsIgnoreCase("type")) { nsAutoString type; - GetAttributeValueAt(aNode, i, type, nsnull); + GetAttributeValueAt(aNode, i, type); nsAutoString mimeType; nsAutoString params; @@ -3709,7 +3683,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) else if (key.EqualsIgnoreCase("language")) { nsAutoString lang; - GetAttributeValueAt(aNode, i, lang, nsnull); + GetAttributeValueAt(aNode, i, lang); isJavaScript = IsJavaScriptLanguage(lang, &jsVersionString); } } @@ -3717,7 +3691,6 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) // Create content object NS_ASSERTION(mCurrentContext->mStackPos > 0, "leaf w/o container"); nsIHTMLContent* parent = mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); nsAutoString tag("SCRIPT"); nsIHTMLContent* element = nsnull; rv = NS_CreateHTMLElement(&element, tag); @@ -3727,7 +3700,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - rv = AddAttributes(aNode, element, sco); + rv = AddAttributes(aNode, element); if (NS_FAILED(rv)) { NS_RELEASE(element); return rv; @@ -3742,10 +3715,8 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) } } else { - NS_IF_RELEASE(sco); return rv; } - NS_IF_RELEASE(sco); // Create a text node holding the content // First, get the text content of the script tag @@ -3845,23 +3816,22 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) nsAutoString type; nsAutoString media; - nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner(); for (i = 0; i < count; i++) { const nsString& key = aNode.GetKeyAt(i); if (key.EqualsIgnoreCase("src")) { - GetAttributeValueAt(aNode, i, src, sco); + GetAttributeValueAt(aNode, i, src); src.StripWhitespace(); } else if (key.EqualsIgnoreCase("title")) { - GetAttributeValueAt(aNode, i, title, sco); + GetAttributeValueAt(aNode, i, title); title.CompressWhitespace(); } else if (key.EqualsIgnoreCase("type")) { - GetAttributeValueAt(aNode, i, type, sco); + GetAttributeValueAt(aNode, i, type); type.StripWhitespace(); } else if (key.EqualsIgnoreCase("media")) { - GetAttributeValueAt(aNode, i, media, sco); + GetAttributeValueAt(aNode, i, media); media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE } } @@ -3876,7 +3846,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) // Add in the attributes and add the style content object to the // head container. element->SetDocument(mDocument, PR_FALSE); - rv = AddAttributes(aNode, element, sco); + rv = AddAttributes(aNode, element); if (NS_FAILED(rv)) { NS_RELEASE(element); return rv; @@ -3884,10 +3854,8 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) mHead->AppendChildTo(element, PR_FALSE); } else { - NS_IF_RELEASE(sco); return rv; } - NS_IF_RELEASE(sco); nsAutoString mimeType; nsAutoString params; diff --git a/layout/html/document/src/nsHTMLDocument.cpp b/layout/html/document/src/nsHTMLDocument.cpp index 0b11620648fcf..3243bd93f46e6 100644 --- a/layout/html/document/src/nsHTMLDocument.cpp +++ b/layout/html/document/src/nsHTMLDocument.cpp @@ -2469,10 +2469,7 @@ nsHTMLDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject res = cx->GetContainer(getter_AddRefs(container)); if (NS_SUCCEEDED(res) && container) { - nsCOMPtr sco = do_QueryInterface(container); - if (sco) { - res = sco->GetScriptGlobalObject(getter_AddRefs(global)); - } + global = do_GetInterface(container); } } // XXX If we can't find a view, parent to the calling context's @@ -2510,11 +2507,11 @@ nsHTMLDocument::Resolve(JSContext *aContext, jsval aID) if (owner) { nsCOMPtr scriptContext; - nsCOMPtr contextOwner; + nsCOMPtr scriptGlobal; + GetScriptGlobalObject(getter_AddRefs(scriptGlobal)); - contextOwner = getter_AddRefs(GetScriptContextOwner()); - if (contextOwner) { - result = contextOwner->GetScriptContext(getter_AddRefs(scriptContext)); + if (scriptGlobal) { + result = scriptGlobal->GetContext(getter_AddRefs(scriptContext)); } if (!scriptContext) { diff --git a/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp b/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp index 7b489d5017130..44ef0862ab562 100644 --- a/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp +++ b/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp @@ -26,7 +26,6 @@ #include "nsITimer.h" #include "nsITimerCallback.h" #include "nsIDOMHTMLInputElement.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObjectData.h" #include "nsIScriptObjectOwner.h" @@ -269,19 +268,18 @@ nsresult nsGfxAutoTextControlFrame::SetEventHandlers(PRInt32 handlerID) nsresult nsGfxAutoTextControlFrame::AddScriptEventHandler(PRInt32 handlerID, const char* handlerName, const nsString& aFunc, nsIDocument* aDocument) { nsresult ret = NS_OK; - nsIScriptContext* context; - nsIScriptContextOwner* owner; + nsCOMPtr scriptGlobal; if (nsnull != aDocument) { - owner = aDocument->GetScriptContextOwner(); - if (owner) + aDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobal)); + if (scriptGlobal) { - if (NS_OK == owner->GetScriptContext(&context)) + nsCOMPtr context; + if (NS_OK == scriptGlobal->GetContext(getter_AddRefs(context))) { - nsIScriptObjectOwner* cowner; - if (NS_OK == mContent->QueryInterface(kIScriptObjectOwnerIID, - (void**) &cowner)) + nsCOMPtr cowner(do_QueryInterface(mContent)); + if (cowner) { JSObject *mScriptObject; ret = BuildScriptEventHandler(context, cowner, handlerName, aFunc, &mScriptObject); @@ -290,11 +288,8 @@ nsresult nsGfxAutoTextControlFrame::AddScriptEventHandler(PRInt32 handlerID, con mEvtHdlrContext[handlerID] = context; mEvtHdlrScript[handlerID] = mScriptObject; } - NS_RELEASE(cowner); } - NS_RELEASE(context); } - NS_RELEASE(owner); } } return ret; diff --git a/layout/xml/content/src/nsGenericXMLElement.cpp b/layout/xml/content/src/nsGenericXMLElement.cpp index faf803c8eb170..18777d128aa75 100644 --- a/layout/xml/content/src/nsGenericXMLElement.cpp +++ b/layout/xml/content/src/nsGenericXMLElement.cpp @@ -30,7 +30,6 @@ #include "nsIDOMDocumentFragment.h" #include "nsIDOMRange.h" #include "nsRange.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" #include "nsISizeOfHandler.h" diff --git a/layout/xml/document/src/nsXMLContentSink.cpp b/layout/xml/document/src/nsXMLContentSink.cpp index 82e03c9c111cb..2896f9778ce4a 100644 --- a/layout/xml/document/src/nsXMLContentSink.cpp +++ b/layout/xml/document/src/nsXMLContentSink.cpp @@ -28,6 +28,7 @@ #include "nsIXMLDocument.h" #include "nsIXMLContent.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIURL.h" #include "nsIURL.h" #include "nsNetUtil.h" @@ -50,7 +51,6 @@ #include "nsHTMLAtoms.h" #include "nsLayoutAtoms.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" @@ -1623,16 +1623,12 @@ nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo, const char nsresult rv = NS_OK; if (0 < aScript.Length()) { - nsIScriptContextOwner *owner; - nsIScriptContext *context; - owner = mDocument->GetScriptContextOwner(); - if (nsnull != owner) { - - rv = owner->GetScriptContext(&context); - if (rv != NS_OK) { - NS_RELEASE(owner); - return rv; - } + nsCOMPtr scriptGlobal; + mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobal)); + if (scriptGlobal) { + nsCOMPtr context; + NS_ENSURE_SUCCESS(scriptGlobal->GetContext(getter_AddRefs(context)), + NS_ERROR_FAILURE); nsIURI* docURL = mDocument->GetDocumentURL(); char* url; @@ -1649,8 +1645,6 @@ nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo, const char NS_IF_RELEASE(docURL); - NS_RELEASE(context); - NS_RELEASE(owner); nsCRT::free(url); } } diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index 5d12c358efb87..e5e98e4f04955 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -36,7 +36,6 @@ #include "nsMenuFrame.h" #include "nsIPopupSetFrame.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMScreen.h" #include "nsIScriptGlobalObject.h" #include "nsIPresShell.h" @@ -283,9 +282,8 @@ nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext* aPresContext, nsCOMPtr document; presShell->GetDocument(getter_AddRefs(document)); - nsCOMPtr scriptContextOwner = getter_AddRefs(document->GetScriptContextOwner()); nsCOMPtr scriptGlobalObject; - scriptContextOwner->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); + document->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); nsCOMPtr window(do_QueryInterface(scriptGlobalObject)); nsCOMPtr screen; diff --git a/rdf/content/src/nsDlgDefaultKeys.cpp b/rdf/content/src/nsDlgDefaultKeys.cpp index f8bcea4b7ae88..d3bf835d67e5c 100644 --- a/rdf/content/src/nsDlgDefaultKeys.cpp +++ b/rdf/content/src/nsDlgDefaultKeys.cpp @@ -33,7 +33,6 @@ #include "nsINSEvent.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDlgDefaultKeys.h" #include "nsRDFCID.h" diff --git a/rdf/content/src/nsRDFGenericBuilder.cpp b/rdf/content/src/nsRDFGenericBuilder.cpp index fb8c01fafef23..7307bd6450ef0 100644 --- a/rdf/content/src/nsRDFGenericBuilder.cpp +++ b/rdf/content/src/nsRDFGenericBuilder.cpp @@ -58,8 +58,8 @@ #include "nsIRDFObserver.h" #include "nsIRDFRemoteDataSource.h" #include "nsIRDFService.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsITextContent.h" @@ -2956,18 +2956,13 @@ RDFGenericBuilderImpl::AddDatabasePropertyToHTMLElement(nsIContent* aElement, ns if (! doc) return NS_ERROR_UNEXPECTED; - nsCOMPtr contextowner = dont_QueryInterface(doc->GetScriptContextOwner()); - NS_ASSERTION(contextowner != nsnull, "no script context owner"); - if (! contextowner) - return NS_ERROR_UNEXPECTED; + nsCOMPtr global; + doc->GetScriptGlobalObject(getter_AddRefs(global)); + NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = contextowner->GetScriptContext(getter_AddRefs(context)); - NS_ASSERTION(NS_SUCCEEDED(rv), "no script context"); - if (NS_FAILED(rv)) return rv; - - if (! context) - return NS_ERROR_UNEXPECTED; + global->GetContext(getter_AddRefs(context)); + NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); JSContext* jscontext = NS_STATIC_CAST(JSContext*, context->GetNativeContext()); NS_ASSERTION(context != nsnull, "no jscontext"); diff --git a/rdf/content/src/nsXULCommandDispatcher.cpp b/rdf/content/src/nsXULCommandDispatcher.cpp index 987967f76a699..fa9d7435d85e8 100644 --- a/rdf/content/src/nsXULCommandDispatcher.cpp +++ b/rdf/content/src/nsXULCommandDispatcher.cpp @@ -37,7 +37,6 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIContent.h" @@ -485,11 +484,8 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen nsCOMPtr objectOwner = do_QueryInterface(document); if(!objectOwner) return NS_OK; - nsCOMPtr contextOwner = dont_QueryInterface(objectOwner->GetScriptContextOwner()); - if(!contextOwner) return NS_OK; - nsCOMPtr globalObject; - contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + objectOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); if(!globalObject) return NS_OK; nsCOMPtr privateDOMWindow = do_QueryInterface(globalObject); diff --git a/rdf/content/src/nsXULContentSink.cpp b/rdf/content/src/nsXULContentSink.cpp index 7adda7c51b6aa..ed402c5d612df 100644 --- a/rdf/content/src/nsXULContentSink.cpp +++ b/rdf/content/src/nsXULContentSink.cpp @@ -59,12 +59,10 @@ #include "nsIRDFContentModelBuilder.h" #include "nsIRDFService.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIServiceManager.h" #include "nsITextContent.h" #include "nsIURL.h" #include "nsIViewManager.h" -#include "nsIWebShell.h" #include "nsIXMLContent.h" #include "nsIXMLElementFactory.h" #include "nsIXULContentSink.h" diff --git a/rdf/content/src/nsXULControllers.cpp b/rdf/content/src/nsXULControllers.cpp index 3a059c949d106..5e2c6b130be9d 100644 --- a/rdf/content/src/nsXULControllers.cpp +++ b/rdf/content/src/nsXULControllers.cpp @@ -37,7 +37,6 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIContent.h" diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index 37f5f5aa6786d..ce86ce5ca30a2 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -83,7 +83,6 @@ #include "nsIRDFNode.h" #include "nsIRDFRemoteDataSource.h" #include "nsIRDFService.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsIStreamListener.h" @@ -307,7 +306,6 @@ PlaceholderChannel::~PlaceholderChannel() nsXULDocument::nsXULDocument(void) : mParentDocument(nsnull), - mScriptContextOwner(nsnull), mScriptObject(nsnull), mNextSrcLoadWaiter(nsnull), mCharSetID("UTF-8"), @@ -1146,25 +1144,27 @@ nsXULDocument::GetCSSLoader(nsICSSLoader*& aLoader) return result; } -nsIScriptContextOwner * -nsXULDocument::GetScriptContextOwner() +NS_IMETHODIMP +nsXULDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject) { - NS_IF_ADDREF(mScriptContextOwner); - return mScriptContextOwner; + *aScriptGlobalObject = mScriptGlobalObject; + NS_IF_ADDREF(*aScriptGlobalObject); + return NS_OK; } -void -nsXULDocument::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) +NS_IMETHODIMP +nsXULDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) { // XXX HACK ALERT! If the script context owner is null, the document // will soon be going away. So tell our content that to lose its // reference to the document. This has to be done before we // actually set the script context owner to null so that the // content elements can remove references to their script objects. - if (!aScriptContextOwner && mRootContent) + if (!aScriptGlobalObject && mRootContent) mRootContent->SetDocument(nsnull, PR_TRUE); - mScriptContextOwner = aScriptContextOwner; + mScriptGlobalObject = aScriptGlobalObject; + return NS_OK; } NS_IMETHODIMP @@ -1757,12 +1757,8 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Capturing stage - if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptContextOwner) { - nsIScriptGlobalObject* global; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&global)) { - global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - NS_RELEASE(global); - } + if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); } //Local handling stage @@ -1772,12 +1768,8 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptContextOwner) { - nsIScriptGlobalObject* global; - if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&global)) { - global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); - NS_RELEASE(global); - } + if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptGlobalObject) { + mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } if (NS_EVENT_FLAG_INIT == aFlags) { @@ -3001,16 +2993,10 @@ nsXULDocument::GetProperty(JSContext *aContext, jsval aID, jsval *aVp) return PR_FALSE; if (PL_strcmp("location", JS_GetStringBytes(jsString)) == 0) { - if (nsnull != mScriptContextOwner) { - nsCOMPtr global; - mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global)); - if (nsnull != global) { - nsCOMPtr window = do_QueryInterface(global); - if (nsnull != window) { - return window->GetProperty(aContext, aID, aVp); - } - } - } + nsCOMPtr window = do_QueryInterface(mScriptGlobalObject); + if (nsnull != window) { + return window->GetProperty(aContext, aID, aVp); + } } } @@ -3104,9 +3090,7 @@ nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) // Make sure that we've got our script context owner; this // assertion will fire if we've tried to get the script object // before our scope has been set up. - NS_ASSERTION(mScriptContextOwner != nsnull, "no script context owner"); - if (! mScriptContextOwner) - return NS_ERROR_NOT_INITIALIZED; + NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_NOT_INITIALIZED); nsresult rv; @@ -3115,17 +3099,10 @@ nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) // global object from aContext would make our script object // dynamically scoped in the first context that ever tried to // use us!) - nsCOMPtr global; - rv = mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global)); - if (NS_FAILED(rv)) return rv; - - NS_ASSERTION(global != nsnull, "script context owner has no global object"); - if (! global) - return NS_ERROR_UNEXPECTED; rv = NS_NewScriptXULDocument(aContext, NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMXULDocument*, this)), - global, &mScriptObject); + mScriptGlobalObject, &mScriptObject); if (NS_FAILED(rv)) return rv; } @@ -3468,9 +3445,9 @@ nsXULDocument::StartLayout(void) // Perform the resize PRInt32 chromeX,chromeY,chromeWidth,chromeHeight; - nsCOMPtr webShellWin(do_QueryInterface(webShell)); - NS_ABORT_IF_FALSE(webShellWin, "QI Failed!!!!"); - webShellWin->GetPositionAndSize(&chromeX, &chromeY, &chromeWidth, + nsCOMPtr docShellWin(do_QueryInterface(webShell)); + NS_ABORT_IF_FALSE(docShellWin, "QI Failed!!!!"); + docShellWin->GetPositionAndSize(&chromeX, &chromeY, &chromeWidth, &chromeHeight); float t2p; @@ -4917,13 +4894,10 @@ nsXULDocument::ExecuteScript(JSObject* aScriptObject) // Execute the precompiled script with the given version nsresult rv; - nsCOMPtr owner = dont_AddRef(GetScriptContextOwner()); - NS_ASSERTION(owner != nsnull, "document has no script context owner"); - if (! owner) - return NS_ERROR_UNEXPECTED; + NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = owner->GetScriptContext(getter_AddRefs(context)); + rv = mScriptGlobalObject->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull); @@ -5720,15 +5694,8 @@ nsXULDocument::CachedChromeLoader::OnStopRequest(nsIChannel* aChannel, if (! container) continue; - // the container should be a script context owner... - nsCOMPtr owner = do_QueryInterface(container); - NS_ASSERTION(owner != nsnull, "container is not a script context owner"); - if (! owner) - continue; - - // and the script context owner has a script global object... - nsCOMPtr global; - rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); + // the container should support GI to globalObject... + nsCOMPtr global(do_GetInterface(container, &rv)); if (NS_FAILED(rv)) continue; diff --git a/rdf/content/src/nsXULDocument.h b/rdf/content/src/nsXULDocument.h index 2e9c2be92dccc..cdbd26de66987 100644 --- a/rdf/content/src/nsXULDocument.h +++ b/rdf/content/src/nsXULDocument.h @@ -65,7 +65,6 @@ class nsIHTMLElementFactory; class nsILoadGroup; class nsIRDFResource; class nsIRDFService; -class nsIScriptContextOwner; class nsITimer; class nsIUnicharStreamLoader; class nsIXMLElementFactory; @@ -182,9 +181,9 @@ class nsXULDocument : public nsIDocument, NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader); - virtual nsIScriptContextOwner *GetScriptContextOwner(); + NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject); - virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner); + NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject); NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager); @@ -502,7 +501,7 @@ class nsXULDocument : public nsIDocument, nsCOMPtr mDocumentPrincipal; // [OWNER] nsCOMPtr mRootContent; // [OWNER] nsIDocument* mParentDocument; // [WEAK] - nsIScriptContextOwner* mScriptContextOwner; // [WEAK] it owns me! (indirectly) + nsCOMPtr mScriptGlobalObject; void* mScriptObject; // ???? nsXULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr nsString mCharSetID; diff --git a/rdf/content/src/nsXULElement.cpp b/rdf/content/src/nsXULElement.cpp index 327f4d5da4a7f..9977add07b043 100644 --- a/rdf/content/src/nsXULElement.cpp +++ b/rdf/content/src/nsXULElement.cpp @@ -74,7 +74,6 @@ #include "nsIStyleSheet.h" #include "nsIHTMLStyleSheet.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIStyledContent.h" #include "nsIStyleContext.h" #include "nsIMutableStyleContext.h" @@ -1304,24 +1303,19 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REF nsresult rv; nsCOMPtr context; - + nsCOMPtr global; { - nsCOMPtr owner = - dont_AddRef( mDocument->GetScriptContextOwner() ); + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); // This can happen normally as part of teardown code. - if (! owner) + if (! global) return NS_OK; - rv = owner->GetScriptContext(getter_AddRefs(context)); + rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; } if (Tag() == kWindowAtom) { - nsCOMPtr global = context->GetGlobalObject(); - if (! global) - return NS_ERROR_UNEXPECTED; - nsCOMPtr receiver = do_QueryInterface(global); if (! receiver) return NS_ERROR_UNEXPECTED; @@ -1631,11 +1625,11 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) // Release the named reference to the script object so it can // be garbage collected. if (mScriptObject) { - nsCOMPtr owner = - dont_AddRef( mDocument->GetScriptContextOwner() ); - if (owner) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { nsCOMPtr context; - if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) { + if (NS_OK == global->GetContext(getter_AddRefs(context))) { context->RemoveReference((void*) &mScriptObject, mScriptObject); } @@ -1648,11 +1642,11 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) if (mDocument) { // Add a named reference to the script object. if (mScriptObject) { - nsCOMPtr owner = - dont_AddRef( mDocument->GetScriptContextOwner() ); - if (owner) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { nsCOMPtr context; - if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) { + if (NS_OK == global->GetContext(getter_AddRefs(context))) { nsAutoString tag; Tag()->ToString(tag); context->AddNamedReference((void*) &mScriptObject, mScriptObject, nsCAutoString(tag)); @@ -3674,16 +3668,13 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, PRInt32 aTextLength, { nsresult rv; - nsCOMPtr owner = - dont_AddRef( aDocument->GetScriptContextOwner() ); + nsCOMPtr global; + aDocument->GetScriptGlobalObject(getter_AddRefs(global)); - NS_ASSERTION(owner != nsnull, "document has no script context owner"); - if (!owner) { - return NS_ERROR_UNEXPECTED; - } + NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = owner->GetScriptContext(getter_AddRefs(context)); + rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; if (!mScriptRuntime) { diff --git a/rdf/content/src/nsXULKeyListener.cpp b/rdf/content/src/nsXULKeyListener.cpp index bf6e6aae5712d..6a5776090446b 100644 --- a/rdf/content/src/nsXULKeyListener.cpp +++ b/rdf/content/src/nsXULKeyListener.cpp @@ -33,7 +33,6 @@ #include "nsINSEvent.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIXULKeyListener.h" #include "nsRDFCID.h" diff --git a/rdf/content/src/nsXULPopupListener.cpp b/rdf/content/src/nsXULPopupListener.cpp index 5eab272a84ba9..38e2f63776886 100644 --- a/rdf/content/src/nsXULPopupListener.cpp +++ b/rdf/content/src/nsXULPopupListener.cpp @@ -34,7 +34,6 @@ #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIContent.h" @@ -459,11 +458,11 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) return NS_OK; // We have some popup content. Obtain our window. - nsIScriptContextOwner* owner = document->GetScriptContextOwner(); nsCOMPtr context; - if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) { - nsIScriptGlobalObject* global = context->GetGlobalObject(); - if (global) { + nsCOMPtr global; + document->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + if (NS_OK == global->GetContext(getter_AddRefs(context))) { // Get the DOM window nsCOMPtr domWindow = do_QueryInterface(global); if (domWindow != nsnull) { @@ -484,10 +483,8 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) type, anchorAlignment, popupAlignment, getter_AddRefs(uselessPopup)); } - NS_RELEASE(global); } } - NS_IF_RELEASE(owner); return NS_OK; } diff --git a/rdf/content/src/nsXULTemplateBuilder.cpp b/rdf/content/src/nsXULTemplateBuilder.cpp index fb8c01fafef23..7307bd6450ef0 100644 --- a/rdf/content/src/nsXULTemplateBuilder.cpp +++ b/rdf/content/src/nsXULTemplateBuilder.cpp @@ -58,8 +58,8 @@ #include "nsIRDFObserver.h" #include "nsIRDFRemoteDataSource.h" #include "nsIRDFService.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsITextContent.h" @@ -2956,18 +2956,13 @@ RDFGenericBuilderImpl::AddDatabasePropertyToHTMLElement(nsIContent* aElement, ns if (! doc) return NS_ERROR_UNEXPECTED; - nsCOMPtr contextowner = dont_QueryInterface(doc->GetScriptContextOwner()); - NS_ASSERTION(contextowner != nsnull, "no script context owner"); - if (! contextowner) - return NS_ERROR_UNEXPECTED; + nsCOMPtr global; + doc->GetScriptGlobalObject(getter_AddRefs(global)); + NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); nsCOMPtr context; - rv = contextowner->GetScriptContext(getter_AddRefs(context)); - NS_ASSERTION(NS_SUCCEEDED(rv), "no script context"); - if (NS_FAILED(rv)) return rv; - - if (! context) - return NS_ERROR_UNEXPECTED; + global->GetContext(getter_AddRefs(context)); + NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); JSContext* jscontext = NS_STATIC_CAST(JSContext*, context->GetNativeContext()); NS_ASSERTION(context != nsnull, "no jscontext"); diff --git a/webshell/src/nsWebShell.cpp b/webshell/src/nsWebShell.cpp index aded601146f47..74d6141c66f96 100644 --- a/webshell/src/nsWebShell.cpp +++ b/webshell/src/nsWebShell.cpp @@ -35,7 +35,7 @@ #include "nsIDNSService.h" #include "nsIRefreshURI.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIDocumentLoaderObserver.h" #include "nsIProgressEventSink.h" #include "nsDOMEvent.h" @@ -160,7 +160,6 @@ class nsWebShell : public nsIWebShell, public nsIWebShellContainer, public nsIWebShellServices, public nsILinkHandler, - public nsIScriptContextOwner, public nsIDocumentLoaderObserver, public nsIProgressEventSink, // should go away (nsIDocLoaderObs) public nsIPrompt, @@ -170,7 +169,8 @@ class nsWebShell : public nsIWebShell, public nsIInterfaceRequestor, public nsIBaseWindow, public nsIDocShell, - public nsIDocShellContainer + public nsIDocShellContainer, + public nsIScriptGlobalObjectOwner { public: nsWebShell(); @@ -313,8 +313,8 @@ class nsWebShell : public nsIWebShell, const PRUnichar* aTargetSpec); NS_IMETHOD GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState); - // nsIScriptContextOwner - NS_DECL_NSISCRIPTCONTEXTOWNER + // nsIScriptGlobalObjectOwner + NS_DECL_NSISCRIPTGLOBALOBJECTOWNER // nsIDocumentLoaderObserver NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, @@ -536,7 +536,6 @@ static NS_DEFINE_IID(kIProgressEventSinkIID, NS_IPROGRESSEVENTSINK_IID); static NS_DEFINE_IID(kIDeviceContextIID, NS_IDEVICE_CONTEXT_IID); static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kRefreshURIIID, NS_IREFRESHURI_IID); @@ -763,7 +762,7 @@ NS_INTERFACE_MAP_BEGIN(nsWebShell) NS_INTERFACE_MAP_ENTRY(nsIWebShell) NS_INTERFACE_MAP_ENTRY(nsIWebShellServices) NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer) - NS_INTERFACE_MAP_ENTRY(nsIScriptContextOwner) + NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) NS_INTERFACE_MAP_ENTRY(nsIDocumentLoaderObserver) NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink) NS_INTERFACE_MAP_ENTRY(nsIWebShellContainer) @@ -786,21 +785,28 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr) if(aIID.Equals(NS_GET_IID(nsILinkHandler))) { *aInstancePtr = NS_STATIC_CAST(nsILinkHandler*, this); - NS_ADDREF_THIS(); + NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } - else if(aIID.Equals(NS_GET_IID(nsIScriptContextOwner))) + else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectOwner))) { - *aInstancePtr = NS_STATIC_CAST(nsIScriptContextOwner*, this); - NS_ADDREF_THIS(); + *aInstancePtr = NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this); + NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } else if (aIID.Equals(NS_GET_IID(nsIURIContentListener))) { *aInstancePtr = NS_STATIC_CAST(nsIURIContentListener*, this); - NS_ADDREF_THIS(); + NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } + else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject))) + { + NS_ENSURE_SUCCESS(CreateScriptEnvironment(), NS_ERROR_FAILURE); + *aInstancePtr = mScriptGlobal; + NS_ADDREF((nsISupports*)*aInstancePtr); + return NS_OK; + } else if(mPluginManager) //XXX this seems a little wrong. MMP return mPluginManager->QueryInterface(aIID, aInstancePtr); @@ -2888,103 +2894,17 @@ nsWebShell::CreateScriptEnvironment() return res; } mScriptGlobal->SetWebShell(this); + mScriptGlobal->SetGlobalObjectOwner( + NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this)); } if (nsnull == mScriptContext) { res = NS_CreateScriptContext(mScriptGlobal, &mScriptContext); - if (NS_SUCCEEDED(res)) { - mScriptContext->SetOwner(this); - } } return res; } -nsresult -nsWebShell::GetScriptContext(nsIScriptContext** aContext) -{ - NS_PRECONDITION(nsnull != aContext, "null arg"); - nsresult res = NS_OK; - - res = CreateScriptEnvironment(); - - if (NS_SUCCEEDED(res)) { - *aContext = mScriptContext; - NS_ADDREF(mScriptContext); - } - - return res; -} - -nsresult -nsWebShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal) -{ - NS_PRECONDITION(nsnull != aGlobal, "null arg"); - nsresult res = NS_OK; - - res = CreateScriptEnvironment(); - - if (NS_SUCCEEDED(res)) { - *aGlobal = mScriptGlobal; - NS_IF_ADDREF(mScriptGlobal); - } - - return res; -} - -nsresult -nsWebShell::ReleaseScriptContext(nsIScriptContext *aContext) -{ - // XXX Is this right? Why are we passing in a context? - NS_IF_RELEASE(aContext); - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::ReportScriptError(const char* aErrorString, - const char* aFileName, - PRInt32 aLineNo, - const char* aLineBuf) -{ - // XXX To be implemented by scc. The following implementation - // is temporary. - - nsAutoString error; - error.SetString("JavaScript Error: "); - error.Append(aErrorString); - error += "\n"; - - if (aFileName) { - error += "URL: "; - error += aFileName; - error += "\n"; - } - - if(aLineNo) { - error += "LineNo: "; - error.Append(aLineNo, 10); - error += "\n"; - } - - if(aLineBuf) { - error += "Line text: '"; - error += aLineBuf; - error += "'\n"; - } - - // XXX Ughhh...allocation - char* errorStr = error.ToNewCString(); - if (errorStr) { - printf("%s\n", errorStr); - Recycle(errorStr); - } - - // XXX Turn it off for now...there should be an Error method too - //Alert(error.GetUnicode()); - - return NS_OK; -} - NS_IMETHODIMP nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, @@ -4600,7 +4520,7 @@ NS_IMETHODIMP nsWebShell::GetChildAt(PRInt32 aIndex, nsIDocShell** aDocShell) /* depth-first search for a child shell with aName */ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShell **_retval) { - NS_ENSURE_ARG_POINTER(aName); + NS_ENSURE_ARG(aName); NS_ENSURE_ARG_POINTER(_retval); *_retval = nsnull; // if we don't find one, we return NS_OK and a null result @@ -4624,7 +4544,7 @@ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShell { NS_ENSURE_SUCCESS(childAsContainer->FindChildWithName(name.GetUnicode(), _retval), NS_ERROR_FAILURE); } - if (_retval) { // found it + if (*_retval) { // found it break; } } @@ -4632,6 +4552,71 @@ NS_IMETHODIMP nsWebShell::FindChildWithName(const PRUnichar *aName, nsIDocShell return NS_OK; } +//***************************************************************************** +// nsWebShell::nsIScriptGlobalObjectOwner +//***************************************************************************** + +NS_IMETHODIMP +nsWebShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal) +{ + NS_PRECONDITION(nsnull != aGlobal, "null arg"); + nsresult res = NS_OK; + + res = CreateScriptEnvironment(); + + if (NS_SUCCEEDED(res)) { + *aGlobal = mScriptGlobal; + NS_IF_ADDREF(mScriptGlobal); + } + + return res; +} + +NS_IMETHODIMP +nsWebShell::ReportScriptError(const char* aErrorString, + const char* aFileName, + PRInt32 aLineNo, + const char* aLineBuf) +{ + // XXX To be implemented by scc. The following implementation + // is temporary. + + nsAutoString error; + error.SetString("JavaScript Error: "); + error.Append(aErrorString); + error += "\n"; + + if (aFileName) { + error += "URL: "; + error += aFileName; + error += "\n"; + } + + if(aLineNo) { + error += "LineNo: "; + error.Append(aLineNo, 10); + error += "\n"; + } + + if(aLineBuf) { + error += "Line text: '"; + error += aLineBuf; + error += "'\n"; + } + + // XXX Ughhh...allocation + char* errorStr = error.ToNewCString(); + if (errorStr) { + printf("%s\n", errorStr); + Recycle(errorStr); + } + + // XXX Turn it off for now...there should be an Error method too + //Alert(error.GetUnicode()); + + return NS_OK; +} + //---------------------------------------------------------------------- // Factory code for creating nsWebShell's diff --git a/xpfe/AppCores/src/nsBaseAppCore.cpp b/xpfe/AppCores/src/nsBaseAppCore.cpp index 82440f180a0b1..77af8936f3d92 100644 --- a/xpfe/AppCores/src/nsBaseAppCore.cpp +++ b/xpfe/AppCores/src/nsBaseAppCore.cpp @@ -22,12 +22,12 @@ */ #include "nsBaseAppCore.h" -#include "nsIScriptContextOwner.h" #include "nsAppCoresManager.h" #include "nsIDOMDocument.h" #include "nsIDOMNode.h" #include "nsIDOMElement.h" #include "nsIScriptContext.h" +#include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" #include "nsIDocument.h" #include "nsAppCoresCIDs.h" @@ -160,21 +160,12 @@ nsBaseAppCore::GetScriptContext(nsIDOMWindow * aWin) { nsIScriptContext * scriptContext = nsnull; if (nsnull != aWin) { - nsIDOMDocument * domDoc; - aWin->GetDocument(&domDoc); - if (nsnull != domDoc) { - nsIDocument * doc; - if (NS_OK == domDoc->QueryInterface(kIDocumentIID,(void**)&doc)) { - nsIScriptContextOwner * owner = doc->GetScriptContextOwner(); - if (nsnull != owner) { - owner->GetScriptContext(&scriptContext); - NS_RELEASE(owner); - } - NS_RELEASE(doc); - } - NS_RELEASE(domDoc); + nsCOMPtr global(do_QueryInterface(aWin)); + if (!NS_WARN_IF_FALSE(global, "This should succeed")) { + global->GetContext(&scriptContext); } } + return scriptContext; } diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 3a7f5f2b0663c..828b336efd73a 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -67,7 +67,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsIContextMenu.h" // For JS Execution -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIJSContextStack.h" #include "nsIEventQueueService.h" @@ -1126,26 +1126,18 @@ nsWebShellWindow::AddWebShellInfo(const nsString& aID, NS_IMETHODIMP nsWebShellWindow::ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindow** aDOMWindow) { - nsresult rv; - nsCOMPtr newContextOwner; - nsCOMPtr newGlobalObject; - nsCOMPtr newDOMWindow; - - newContextOwner = do_QueryInterface(aShell); - if (newContextOwner) { - if (NS_FAILED(rv = newContextOwner->GetScriptGlobalObject(getter_AddRefs(newGlobalObject)))) { - NS_ERROR("Unable to retrieve global object."); - return rv; - } - - if (newGlobalObject) { - newDOMWindow = do_QueryInterface(newGlobalObject); - *aDOMWindow = newDOMWindow.get(); - NS_ADDREF(*aDOMWindow); - } - else return NS_ERROR_FAILURE; - } + nsCOMPtr globalObjectOwner(do_QueryInterface(aShell)); + NS_ENSURE_TRUE(globalObjectOwner, NS_ERROR_FAILURE); + + nsCOMPtr globalObject; + globalObjectOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); + NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); + + nsCOMPtr newDOMWindow(do_QueryInterface(globalObject)); + NS_ENSURE_TRUE(newDOMWindow, NS_ERROR_FAILURE); + *aDOMWindow = newDOMWindow.get(); + NS_ADDREF(*aDOMWindow); return NS_OK; } @@ -2420,12 +2412,11 @@ PRBool nsWebShellWindow::ExecuteCloseHandler() nsCOMPtr kungFuDeathGrip(this); nsresult rv; - nsCOMPtr contextOwner; + nsCOMPtr globalObjectOwner(do_QueryInterface(mWebShell)); nsCOMPtr globalObject; - contextOwner = do_QueryInterface(mWebShell); - if (contextOwner) { - if (NS_SUCCEEDED(contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject))) && globalObject) { + if (globalObjectOwner) { + if (NS_SUCCEEDED(globalObjectOwner->GetScriptGlobalObject(getter_AddRefs(globalObject))) && globalObject) { nsCOMPtr contentViewer; if (NS_SUCCEEDED(mWebShell->GetContentViewer(getter_AddRefs(contentViewer)))) { nsCOMPtr docViewer; diff --git a/xpfe/browser/src/nsBrowserInstance.cpp b/xpfe/browser/src/nsBrowserInstance.cpp index 8ad8bdceb7c53..0d6b0548656bf 100644 --- a/xpfe/browser/src/nsBrowserInstance.cpp +++ b/xpfe/browser/src/nsBrowserInstance.cpp @@ -35,7 +35,6 @@ #include "nsIFileSpecWithUI.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMDocument.h" #include "nsIDOMXULDocument.h" @@ -1177,21 +1176,12 @@ nsIScriptContext * GetScriptContext(nsIDOMWindow * aWin) { nsIScriptContext * scriptContext = nsnull; if (nsnull != aWin) { - nsIDOMDocument * domDoc; - aWin->GetDocument(&domDoc); - if (nsnull != domDoc) { - nsIDocument * doc; - if (NS_OK == domDoc->QueryInterface(kIDocumentIID,(void**)&doc)) { - nsIScriptContextOwner * owner = doc->GetScriptContextOwner(); - if (nsnull != owner) { - owner->GetScriptContext(&scriptContext); - NS_RELEASE(owner); - } - NS_RELEASE(doc); - } - NS_RELEASE(domDoc); + nsCOMPtr global(do_QueryInterface(aWin)); + if (!NS_WARN_IF_FALSE(global, "This should succeed")) { + global->GetContext(&scriptContext); } } + return scriptContext; } diff --git a/xpfe/components/directory/nsDirectoryViewer.cpp b/xpfe/components/directory/nsDirectoryViewer.cpp index 0cbf6a66a49f0..edb105a6b1bdf 100644 --- a/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/xpfe/components/directory/nsDirectoryViewer.cpp @@ -45,7 +45,7 @@ #include "nsIRDFDataSource.h" #include "nsIRDFService.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsIXPConnect.h" @@ -321,62 +321,55 @@ nsHTTPIndexParser::OnStartRequest(nsIChannel* aChannel, nsISupports* aContext) { nsresult rv; - nsCOMPtr requestor(do_QueryInterface(mContainer)); - if (requestor) { - // We need to undo the AddRef() on the nsHTTPIndex object that - // happened in nsDirectoryViewerFactory::CreateInstance(). We'll - // stuff it into an nsCOMPtr (because we _know_ it'll get release - // if any errors occur)... - nsCOMPtr httpindex = do_QueryInterface(mHTTPIndex); + // We need to undo the AddRef() on the nsHTTPIndex object that + // happened in nsDirectoryViewerFactory::CreateInstance(). We'll + // stuff it into an nsCOMPtr (because we _know_ it'll get release + // if any errors occur)... + nsCOMPtr httpindex = do_QueryInterface(mHTTPIndex); - // ...and then _force_ a release here - mHTTPIndex->Release(); + // ...and then _force_ a release here + mHTTPIndex->Release(); - // Now get the content viewer container's script object. - nsCOMPtr contextowner; - rv = requestor->GetInterface(NS_GET_IID(nsIScriptContextOwner), - getter_AddRefs(contextowner)); + // Now get the content viewer container's script object. + nsCOMPtr scriptGlobal(do_GetInterface(mContainer)); + NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_FAILURE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get script context owner from document"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr context; - rv = contextowner->GetScriptContext(getter_AddRefs(context)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get script context"); - if (NS_FAILED(rv)) return rv; + nsCOMPtr context; + rv = scriptGlobal->GetContext(getter_AddRefs(context)); + NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - JSContext* jscontext = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext()); + JSContext* jscontext = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext()); - // Using XPConnect, wrap the HTTP index object... - static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID); - NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv); - if (NS_FAILED(rv)) return rv; + // Using XPConnect, wrap the HTTP index object... + static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID); + NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr wrapper; - rv = xpc->WrapNative(jscontext, - httpindex, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(wrapper)); + nsCOMPtr wrapper; + rv = xpc->WrapNative(jscontext, + httpindex, + nsCOMTypeInfo::GetIID(), + getter_AddRefs(wrapper)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to xpconnect-wrap http-index"); - if (NS_FAILED(rv)) return rv; + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to xpconnect-wrap http-index"); + if (NS_FAILED(rv)) return rv; - JSObject* jsobj; - rv = wrapper->GetJSObject(&jsobj); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get jsobj from xpconnect wrapper"); - if (NS_FAILED(rv)) return rv; + JSObject* jsobj; + rv = wrapper->GetJSObject(&jsobj); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get jsobj from xpconnect wrapper"); + if (NS_FAILED(rv)) return rv; - jsval jslistener = OBJECT_TO_JSVAL(jsobj); + jsval jslistener = OBJECT_TO_JSVAL(jsobj); - // ...and stuff it into the global context - PRBool ok; - JSObject* global = JS_GetGlobalObject(jscontext); - ok = JS_SetProperty(jscontext, global, "HTTPIndex", &jslistener); + // ...and stuff it into the global context + PRBool ok; + JSObject* global = JS_GetGlobalObject(jscontext); + ok = JS_SetProperty(jscontext, global, "HTTPIndex", &jslistener); - NS_ASSERTION(ok, "unable to set Listener property"); - if (! ok) - return NS_ERROR_FAILURE; - } + NS_ASSERTION(ok, "unable to set Listener property"); + if (! ok) + return NS_ERROR_FAILURE; + // Save off some information about the stream we're about to parse. rv = aChannel->GetURI(getter_AddRefs(mDirectoryURI)); diff --git a/xpfe/components/prefwindow/src/nsPrefWindow.cpp b/xpfe/components/prefwindow/src/nsPrefWindow.cpp index ebaf7668b009c..68255dd131f0e 100644 --- a/xpfe/components/prefwindow/src/nsPrefWindow.cpp +++ b/xpfe/components/prefwindow/src/nsPrefWindow.cpp @@ -43,7 +43,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" #include "nsIDOMDocument.h" #include "nsIDocument.h" #include "nsIDOMWindow.h"