This commit is contained in:
rogerl%netscape.com 2003-06-18 20:02:09 +00:00
Родитель 5d9ec77910
Коммит 717316bfb0
5 изменённых файлов: 428 добавлений и 0 удалений

41
js2/src/epimetheus.h Normal file
Просмотреть файл

@ -0,0 +1,41 @@
// -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
//
// The contents of this file are subject to the Netscape Public
// License Version 1.1 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of
// the License at http://www.mozilla.org/NPL/
//
// Software distributed under the License is distributed on an "AS
// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
// implied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Original Code is the JavaScript 2 Prototype.
//
// The Initial Developer of the Original Code is Netscape
// Communications Corporation. Portions created by Netscape are
// Copyright (C) 1998 Netscape Communications Corporation. All
// Rights Reserved.
#ifdef _WIN32
#include "msvc_pragma.h"
#endif
#include <algorithm>
#include <assert.h>
#include "world.h"
#include "utilities.h"
#include "js2value.h"
#include <map>
#include <algorithm>
#include <list>
#include <stack>
#include "reader.h"
#include "parser.h"
#include "regexp.h"
#include "js2engine.h"
#include "bytecodecontainer.h"
#include "js2metadata.h"

6
js2/src/npscriptable.def Normal file
Просмотреть файл

@ -0,0 +1,6 @@
LIBRARY NPANDORA
EXPORTS
NP_GetEntryPoints @1
NP_Initialize @2
NP_Shutdown @3

Просмотреть файл

@ -0,0 +1,144 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// ==============================
// ! Scriptability related code !
// ==============================
/////////////////////////////////////////////////////
//
// This file implements the nsScriptablePeer object
// The native methods of this class are supposed to
// be callable from JavaScript
//
#include "epimetheus.h"
#include "mozilla-config.h"
#include <nsIXPConnect.h>
#include "plugin.h"
static NS_DEFINE_IID(kIScriptableIID, NS_IPANDORA_IID);
static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsScriptablePeer::nsScriptablePeer(nsPluginInstance* aPlugin)
{
mPlugin = aPlugin;
mRefCnt = 0;
}
nsScriptablePeer::~nsScriptablePeer()
{
}
// AddRef, Release and QueryInterface are common methods and must
// be implemented for any interface
NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::AddRef()
{
++mRefCnt;
return mRefCnt;
}
NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::Release()
{
--mRefCnt;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// here nsScriptablePeer should return three interfaces it can be asked for by their iid's
// static casts are necessary to ensure that correct pointer is returned
NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if(!aInstancePtr)
return NS_ERROR_NULL_POINTER;
if(aIID.Equals(kIScriptableIID)) {
*aInstancePtr = static_cast<nsIPandora*>(this);
AddRef();
return NS_OK;
}
if(aIID.Equals(kIClassInfoIID)) {
*aInstancePtr = static_cast<nsIClassInfo*>(this);
AddRef();
return NS_OK;
}
if(aIID.Equals(kISupportsIID)) {
*aInstancePtr = static_cast<nsISupports*>(static_cast<nsIPandora*>(this));
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
void nsScriptablePeer::SetInstance(nsPluginInstance* plugin)
{
mPlugin = plugin;
}
//
// the following methods will be callable from JavaScript
//
NS_IMETHODIMP nsScriptablePeer::Invoke(const char *target, char **_retval)
{
if (mPlugin)
mPlugin->invoke(target, _retval);
return NS_OK;
}
/* attribute acmeJSObject document; */
NS_IMETHODIMP nsScriptablePeer::GetDocument(nsISupports * *aDocument)
{
if (mPlugin)
mPlugin->GetDocument(aDocument);
return NS_OK;
}
NS_IMETHODIMP nsScriptablePeer::SetDocument(nsISupports * aDocument)
{
if (mPlugin)
mPlugin->SetDocument(aDocument);
return NS_OK;
}

107
js2/src/nsScriptablePeer.h Normal file
Просмотреть файл

@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// ==============================
// ! Scriptability related code !
// ==============================
//
// nsScriptablePeer - xpconnect scriptable peer
//
#ifndef __nsScriptablePeer_h__
#define __nsScriptablePeer_h__
#include "npandora.h"
#include "nsIClassInfo.h"
class nsPluginInstance;
// We must implement nsIClassInfo because it signals the
// Mozilla Security Manager to allow calls from JavaScript.
class nsClassInfoMixin : public nsIClassInfo
{
// These flags are used by the DOM and security systems to signal that
// JavaScript callers are allowed to call this object's scritable methods.
NS_IMETHOD GetFlags(PRUint32 *aFlags)
{*aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
return NS_OK;}
NS_IMETHOD GetImplementationLanguage(PRUint32 *aImplementationLanguage)
{*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
return NS_OK;}
// The rest of the methods can safely return error codes...
NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetContractID(char * *aContractID)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetClassDescription(char * *aClassDescription)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetClassID(nsCID * *aClassID)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
{return NS_ERROR_NOT_IMPLEMENTED;}
};
class nsScriptablePeer : public nsIPandora,
public nsClassInfoMixin
{
public:
nsScriptablePeer(nsPluginInstance* plugin);
~nsScriptablePeer();
public:
// methods from nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
protected:
nsrefcnt mRefCnt;
public:
// native methods callable from JavaScript
NS_DECL_NSIPANDORA
void SetInstance(nsPluginInstance* plugin);
protected:
nsPluginInstance* mPlugin;
};
#endif

130
js2/src/plugin.h Normal file
Просмотреть файл

@ -0,0 +1,130 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __PLUGIN_H__
#define __PLUGIN_H__
#include "pluginbase.h"
#include "nsScriptablePeer.h"
class nsPluginInstance : public nsPluginInstanceBase
{
public:
nsPluginInstance(NPP aInstance);
~nsPluginInstance();
NPBool init(NPWindow* aWindow);
void shut();
NPBool isInitialized();
// we need to provide implementation of this method as it will be
// used by Mozilla to retrive the scriptable peer
NPError GetValue(NPPVariable variable, void *value);
JavaScript::World *world;
JavaScript::MetaData::JS2Metadata *metadata;
JavaScript::MetaData::JS2Class *spiderMonkeyClass;
// locals
void invoke(const char *target, char **_retval);
void GetDocument(nsISupports * *aDocument);
void SetDocument(nsISupports *aDocument);
bool convertJSValueToJS2Value(JSContext *cx, jsval v, js2val *rval);
bool convertJS2ValueToJSValue(JSContext *cx, js2val v, jsval *rval);
nsScriptablePeer* getScriptablePeer();
virtual NPError NewStream(NPMIMEType type, NPStream* stream,
NPBool seekable, uint16* stype);
virtual void StreamAsFile(NPStream* stream, const char* fname);
private:
NPP mInstance;
NPBool mInitialized;
HWND mhWnd;
nsScriptablePeer * mScriptablePeer;
nsISupports *doc;
public:
char mString[128];
};
class JS2SpiderMonkeyClass : public JavaScript::MetaData::JS2Class {
public:
JS2SpiderMonkeyClass(const StringAtom &name)
: JS2Class(NULL, JS2VAL_VOID, NULL, false, true, name) { }
virtual bool Read(JS2Metadata *meta, js2val *base, Multiname *multiname, Environment *env, Phase phase, js2val *rval);
virtual bool BracketRead(JS2Metadata *meta, js2val *base, js2val indexVal, Phase phase, js2val *rval);
virtual bool Write(JS2Metadata *meta, js2val base, Multiname *multiname, Environment *env, bool createIfMissing, js2val newValue, bool initFlag);
virtual bool BracketWrite(JS2Metadata *meta, js2val base, js2val indexVal, js2val newValue);
virtual bool Delete(JS2Metadata *meta, js2val base, Multiname *multiname, Environment *env, bool *result);
virtual bool BracketDelete(JS2Metadata *meta, js2val base, js2val indexVal, bool *result);
};
class SpiderMonkeyInstance : public JavaScript::MetaData::SimpleInstance {
public:
SpiderMonkeyInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type) { }
JSObject *jsObject;
nsPluginInstance *pluginInstance;
virtual ~SpiderMonkeyInstance() { }
};
class SpiderMonkeyFunction : public JavaScript::MetaData::FunctionInstance {
public:
SpiderMonkeyFunction(JS2Metadata *meta) : FunctionInstance(meta, meta->functionClass->prototype, meta->functionClass) { }
JSObject *jsObject;
nsPluginInstance *pluginInstance;
virtual ~SpiderMonkeyFunction() { }
};
#endif // __PLUGIN_H__