Added the nsIScriptContextOwner.h to aid in SCRIPT tag evaluation

git-svn-id: svn://10.0.0.236/trunk@4536 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
vidur
1998-06-25 22:25:39 +00:00
parent a6474a3611
commit e3e4d2ffbb
7 changed files with 100 additions and 29 deletions

View File

@@ -17,7 +17,9 @@
#
nsIScriptContext.h
nsIJSScriptObject.h
nsIScriptObject.h
nsIScriptObjectOwner.h
nsIScriptContextOwner.h
nsIJSScriptObject.h
nsIScriptGlobalObject.h
nsIDOMWindow.h
nsIDOMWindow.h

View File

@@ -23,6 +23,7 @@ DEFINES = -D_IMPL_NS_DOM
EXPORTS = \
nsIScriptContext.h \
nsIScriptContextOwner.h \
nsIJSScriptObject.h \
nsIScriptObjectOwner.h \
nsIScriptGlobalObject.h \

View File

@@ -21,7 +21,7 @@ IGNORE_MANIFEST=1
DIRS=coreDom coreEvents events
DEFINES=-D_IMPL_NS_DOM
EXPORTS=nsIScriptContext.h nsIJSScriptObject.h nsIScriptObjectOwner.h \
nsIScriptGlobalObject.h nsIDOMWindow.h
nsIScriptGlobalObject.h nsIDOMWindow.h nsIScriptContextOwner.h
MODULE=dom

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIScriptContextOwner_h__
#define nsIScriptContextOwner_h__
#include "nscore.h"
#include "nsISupports.h"
#include "nsIScriptContext.h"
class nsIScriptContext;
#define NS_ISCRIPTCONTEXTOWNER_IID \
{ /* a94ec640-0bba-11d2-b326-00805f8a3859 */ \
0xa94ec640, 0x0bba, 0x11d2, \
{0xb3, 0x26, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59} }
/**
* Implemented by any object capable of supplying a nsIScriptContext.
* The implentor may create the script context on demand and is
* allowed (though not expected) to throw it away on release.
*/
class nsIScriptContextOwner : public nsISupports {
public:
/**
* Returns a script context. The assumption is that the
* script context has an associated script global object and
* is ready for script evaluation.
*/
NS_IMETHOD GetScriptContext(nsIScriptContext **aContext) = 0;
/**
* Called to indicate that the script context is no longer needed.
* The caller should <B>not</B> also call the context's Release()
* method.
*/
NS_IMETHOD ReleaseScriptContext(nsIScriptContext *aContext) = 0;
};
#endif // nsIScriptContextOwner_h__

View File

@@ -25,7 +25,6 @@ class nsIDOMDocument;
class nsILinkHandler;
class nsIPresContext;
class nsIStyleSet;
class nsIScriptContext;
// IID for the nsWebWidget interface
#define NS_IWEBWIDGET_IID \
@@ -96,12 +95,8 @@ public:
virtual PRBool GetShowFrameBorders() = 0;
NS_IMETHOD GetScriptContext(nsIScriptContext **aContext) = 0;
NS_IMETHOD GetDOMDocument(nsIDOMDocument** aDocument) = 0;
NS_IMETHOD ReleaseScriptContext() = 0;
virtual nsIPresContext* GetPresContext() = 0;
};

View File

@@ -36,6 +36,7 @@
#include "nsWidgetsCID.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsICSSParser.h"
@@ -55,7 +56,7 @@
((nsWebWidget*) ((char*)this - nsWebWidget::GetOuterOffset()))
// Machine independent implementation portion of the web widget
class WebWidgetImpl : public nsIWebWidget {
class WebWidgetImpl : public nsIWebWidget, public nsIScriptContextOwner {
public:
WebWidgetImpl();
~WebWidgetImpl();
@@ -115,8 +116,8 @@ public:
virtual PRBool GetShowFrameBorders();
virtual nsIWidget* GetWWWindow();
NS_IMETHOD GetScriptContext(nsIScriptContext **aContext);
NS_IMETHOD ReleaseScriptContext(nsIScriptContext *aContext);
NS_IMETHOD GetDOMDocument(nsIDOMDocument** aDocument);
NS_IMETHOD ReleaseScriptContext();
private:
nsresult ProvideDefaultHandlers();
@@ -149,6 +150,7 @@ private:
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIWebWidgetIID, NS_IWEBWIDGET_IID);
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
//nsIWebWidget* WebWidgetImpl::gRootWebWidget = nsnull;
@@ -169,6 +171,11 @@ nsresult WebWidgetImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
AddRef();
return NS_OK;
}
if (aIID.Equals(kIScriptContextOwnerIID)) {
*aInstancePtr = (void*)(nsIScriptContextOwner*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIWebWidget*)this;
AddRef();
@@ -681,6 +688,9 @@ WebWidgetImpl::LoadURL(const nsString& aURLSpec,
}
}
// Set the script object owner to ourselves
doc->SetScriptContextOwner(this);
// Now load the document
mPresShell->EnterReflowLock();
doc->LoadURL(url, aListener, this, aPostData);
@@ -1022,11 +1032,19 @@ nsresult WebWidgetImpl::GetScriptContext(nsIScriptContext **aContext)
if (NS_OK == res) {
*aContext = mScriptContext;
NS_ADDREF(mScriptContext);
}
return res;
}
nsresult WebWidgetImpl::ReleaseScriptContext(nsIScriptContext *aContext)
{
NS_IF_RELEASE(aContext);
return NS_OK;
}
nsresult WebWidgetImpl::GetDOMDocument(nsIDOMDocument** aDocument)
{
nsresult res = NS_OK;
@@ -1043,14 +1061,6 @@ nsresult WebWidgetImpl::GetDOMDocument(nsIDOMDocument** aDocument)
return res;
}
nsresult WebWidgetImpl::ReleaseScriptContext()
{
NS_IF_RELEASE(mScriptContext);
mScriptContext = nsnull;
return NS_OK;
}
/*******************************************
/* nsWebWidgetFactory
/*******************************************/

View File

@@ -31,12 +31,15 @@
#include "nsCRT.h"
#include "prenv.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
// Debug Robot options
static int gDebugRobotLoads = 5000;
static char gVerifyDir[_MAX_PATH];
static BOOL gVisualDebug = TRUE;
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
// DebugRobot call
extern "C" NS_EXPORT int DebugRobot(
nsVoidArray * workList, nsIWebWidget * ww, int imax, char * verify_dir, void (*yieldProc)(const char *));
@@ -197,22 +200,26 @@ void nsWin32Viewer::ShowConsole(WindowData* aWinData)
JSConsole::sAccelTable = LoadAccelerators(gInstance,
MAKEINTRESOURCE(ACCELERATOR_TABLE));
}
nsIScriptContextOwner *owner = nsnull;
nsIScriptContext *context = nsnull;
if (NS_OK == aWinData->ww->GetScriptContext(&context)) {
if (NS_OK == aWinData->ww->QueryInterface(kIScriptContextOwnerIID, (void **)&owner)) {
if (NS_OK == owner->GetScriptContext(&context)) {
// create the console
gConsole = JSConsole::CreateConsole();
gConsole->SetContext(context);
// lifetime of the context is still unclear at this point.
// Anyway, as long as the web widget is alive the context is alive.
// Maybe the context shouldn't even be RefCounted
context->Release();
gConsole->SetNotification(DestroyConsole);
// create the console
gConsole = JSConsole::CreateConsole();
gConsole->SetContext(context);
// lifetime of the context is still unclear at this point.
// Anyway, as long as the web widget is alive the context is alive.
// Maybe the context shouldn't even be RefCounted
context->Release();
gConsole->SetNotification(DestroyConsole);
}
NS_RELEASE(owner);
}
else {
MessageBox(hWnd, "Unable to load JavaScript", "Viewer Error", MB_ICONSTOP);
}
}
}