Skip to content

Commit

Permalink
1.) WebShell no longer implements nsIScriptContextOwner.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbogard%aol.net committed Dec 3, 1999
1 parent 9e84349 commit eb96099
Show file tree
Hide file tree
Showing 71 changed files with 824 additions and 1,236 deletions.
6 changes: 3 additions & 3 deletions content/base/public/nsIDocument.h
Expand Up @@ -44,7 +44,7 @@ class nsIURI;
class nsILoadGroup;
class nsIViewManager;
class nsString;
class nsIScriptContextOwner;
class nsIScriptGlobalObject;
class nsIDOMEvent;
class nsIDeviceContext;
class nsIParser;
Expand Down Expand Up @@ -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
Expand Down
93 changes: 32 additions & 61 deletions content/base/src/nsDocument.cpp
Expand Up @@ -22,6 +22,7 @@
#include "plstr.h"

#include "nsCOMPtr.h"
#include "nsIInterfaceRequestor.h"
#include "nsDocument.h"
#include "nsIArena.h"
#include "nsIURL.h"
Expand All @@ -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"
Expand Down Expand Up @@ -575,7 +575,6 @@ nsDocument::nsDocument()
mParentDocument = nsnull;
mRootContent = nsnull;
mScriptObject = nsnull;
mScriptContextOwner = nsnull;
mListenerManager = nsnull;
mDisplaySelection = PR_FALSE;
mInDestructor = PR_FALSE;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1715,10 +1708,7 @@ nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptO

res = cx->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(res) && container) {
nsCOMPtr<nsIScriptContextOwner> 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
Expand Down Expand Up @@ -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
Expand All @@ -2414,11 +2400,8 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
}

//Bubbling stage
if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptContextOwner) {
nsCOMPtr<nsIScriptGlobalObject> 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) {
Expand Down Expand Up @@ -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<nsIJSScriptObject> window(do_QueryInterface(mScriptGlobalObject));
if(window) {
result = window->GetProperty(aContext, aID, aVp);
}
else {
result = PR_FALSE;
}
}
}
Expand Down Expand Up @@ -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<nsIJSScriptObject> window(do_QueryInterface(mScriptGlobalObject));
if(window) {
result = window->SetProperty(aContext, aID, aVp);
}
else {
result = PR_FALSE;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions content/base/src/nsDocument.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -466,7 +466,7 @@ class nsDocument : public nsIDocument,
nsVoidArray mStyleSheets;
nsVoidArray mObservers;
void* mScriptObject;
nsIScriptContextOwner *mScriptContextOwner;
nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
nsIEventListenerManager* mListenerManager;
PRBool mDisplaySelection;
PRBool mInDestructor;
Expand Down
27 changes: 10 additions & 17 deletions content/base/src/nsDocumentViewer.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<nsIScriptGlobalObject> global;
mDocument->GetScriptGlobalObject(getter_AddRefs(global));
if (global) {
global->SetNewDocument(nsnull);
}
// out of band cleanup of webshell
mDocument->SetScriptGlobalObject(nsnull);
}

if (mDeviceContext)
Expand Down Expand Up @@ -404,14 +397,14 @@ DocumentViewerImpl::Init(nsNativeWidget aNativeParent,
mPresContext->SetLinkHandler(linkHandler);

// Set script-context-owner in the document
nsCOMPtr<nsIScriptContextOwner> owner;
requestor->GetInterface(NS_GET_IID(nsIScriptContextOwner),
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner),
getter_AddRefs(owner));
if (nsnull != owner) {
mDocument->SetScriptContextOwner(owner);
nsCOMPtr<nsIScriptGlobalObject> global;
rv = owner->GetScriptGlobalObject(getter_AddRefs(global));
if (NS_SUCCEEDED(rv) && (nsnull != global)) {
mDocument->SetScriptGlobalObject(global);
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));
if (nsnull != domdoc) {
global->SetNewDocument(domdoc);
Expand Down
24 changes: 11 additions & 13 deletions content/base/src/nsGenericDOMDataNode.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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<nsIScriptGlobalObject> globalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
if (globalObject) {
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) {
context->RemoveReference((void *)&mScriptObject,
mScriptObject);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}

Expand All @@ -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<nsIScriptGlobalObject> globalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
if (globalObject) {
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == globalObject->GetContext(getter_AddRefs(context))) {
context->AddNamedReference((void *)&mScriptObject,
mScriptObject,
"Text");
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}

Expand Down

0 comments on commit eb96099

Please sign in to comment.