From d85e65a92d0cb0e91fcb153c0c8f112106cb8ca3 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Sat, 7 Oct 2006 23:31:52 +0000 Subject: [PATCH] src git-svn-id: svn://10.0.0.236/trunk@213300 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/plugins/mozilla/Makefile.in | 92 +++++++ mozilla/java/plugins/mozilla/nppluglet.cpp | 237 ++++++++++++++++++ mozilla/java/plugins/mozilla/nppluglet.def | 6 + mozilla/java/plugins/mozilla/nppluglet.h | 72 ++++++ .../java/plugins/mozilla/nsISimplePlugin.idl | 43 ++++ .../java/plugins/mozilla/nsScriptablePeer.cpp | 123 +++++++++ .../java/plugins/mozilla/nsScriptablePeer.h | 108 ++++++++ 7 files changed, 681 insertions(+) create mode 100644 mozilla/java/plugins/mozilla/Makefile.in create mode 100644 mozilla/java/plugins/mozilla/nppluglet.cpp create mode 100644 mozilla/java/plugins/mozilla/nppluglet.def create mode 100644 mozilla/java/plugins/mozilla/nppluglet.h create mode 100644 mozilla/java/plugins/mozilla/nsISimplePlugin.idl create mode 100644 mozilla/java/plugins/mozilla/nsScriptablePeer.cpp create mode 100644 mozilla/java/plugins/mozilla/nsScriptablePeer.h diff --git a/mozilla/java/plugins/mozilla/Makefile.in b/mozilla/java/plugins/mozilla/Makefile.in new file mode 100644 index 00000000000..a04c68c9a1b --- /dev/null +++ b/mozilla/java/plugins/mozilla/Makefile.in @@ -0,0 +1,92 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla 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/MPL/ +# +# 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 MPL, 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 MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +PLUGIN_SDK=$(DEPTH)/modules/plugin/tools/sdk + +XPIDL_MODULE = nppluglet +LIBRARY_NAME = nppluglet +REQUIRES = xpcom \ + plugin \ + java \ + $(NULL) + +NO_DIST_INSTALL = 1 + +CPPSRCS = nsScriptablePeer.cpp \ + nppluglet.cpp \ + $(NULL) + +XPIDLSRCS = nsISimplePlugin.idl + +SHARED_LIBRARY_LIBS = $(PLUGIN_SDK)/samples/common/$(LIB_PREFIX)plugingate_s.$(LIB_SUFFIX) ../src/$(LIB_PREFIX)pluglet_s.$(LIB_SUFFIX) + +ifeq ($(OS_ARCH),WINNT) +DEFFILE = $(win_srcdir)/nppluglet.def +RESFILE = nppluglet.res +endif + +include $(topsrcdir)/config/rules.mk + +ifeq ($(OS_ARCH),WINNT) +MS_SDK_HOME=/cygdrive/d/Files_2k/MICROS~1 +INCLUDES += \ + -I$(MS_SDK_HOME)/VC98/Include \ + -I$(MS_SDK_HOME)/VC98/ATL/SRC \ + -I../src \ + -I../src/_xpidlgen \ + -I$(MOZILLA_FIVE_HOME)/../include/string \ + -I$(MOZILLA_FIVE_HOME)/../include/xpcom_obsolete \ + $(NULL) +CXXFLAGS += /Zi /Yd +endif + +DEFINES += -DMOZILLA_STRICT_API + +ifeq ($(OS_ARCH),Linux) +EXTRA_DSO_LDOPTS += $(XLDFLAGS) -rdynamic -lXi -lXext -lX11 -lm -lXt +endif + +LOCAL_INCLUDES = -I./$(XPIDL_GEN_DIR) \ + -I$(PLUGIN_SDK)/samples/include \ + $(NULL) diff --git a/mozilla/java/plugins/mozilla/nppluglet.cpp b/mozilla/java/plugins/mozilla/nppluglet.cpp new file mode 100644 index 00000000000..0bdc209ecae --- /dev/null +++ b/mozilla/java/plugins/mozilla/nppluglet.cpp @@ -0,0 +1,237 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 MPL, 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 MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nppluglet.h" + +#include "PlugletLoader.h" + +#include "nsIServiceManager.h" +#include "nsIMemory.h" +#include "nsISupportsUtils.h" // this is where some useful macros defined + +// service manager which will give the access to all public browser services +// we will use memory service as an illustration +nsIServiceManager * gServiceManager = NULL; + +// Unix needs this +#ifdef XP_UNIX +#define MIME_TYPES_HANDLED "*" +#define PLUGIN_NAME "Java Plugins for Mozilla" +#define MIME_TYPES_DESCRIPTION MIME_TYPES_HANDLED"::"PLUGIN_NAME +#define PLUGIN_DESCRIPTION PLUGIN_NAME " Pluglets" + +char* NPP_GetMIMEDescription(void) +{ + return(MIME_TYPES_DESCRIPTION); +} + +// get values per plugin +NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue) +{ + NPError err = NPERR_NO_ERROR; + switch (aVariable) { + case NPPVpluginNameString: + *((char **)aValue) = PLUGIN_NAME; + break; + case NPPVpluginDescriptionString: + *((char **)aValue) = PLUGIN_DESCRIPTION; + break; + default: + err = NPERR_INVALID_PARAM; + break; + } + return err; +} +#endif //XP_UNIX + +////////////////////////////////////// +// +// general initialization and shutdown +// +NPError NS_PluginInitialize() +{ + // this is probably a good place to get the service manager + // note that Mozilla will add reference, so do not forget to release + nsISupports * sm = NULL; + + NPN_GetValue(NULL, NPNVserviceManager, &sm); + + // Mozilla returns nsIServiceManager so we can use it directly; doing QI on + // nsISupports here can still be more appropriate in case something is changed + // in the future so we don't need to do casting of any sort. + if(sm) { + sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void**)&gServiceManager); + NS_RELEASE(sm); + } + + PlugletLoader::Initialize(); + + return NPERR_NO_ERROR; +} + +void NS_PluginShutdown() +{ + + PlugletLoader::Destroy(); + + // we should release the service manager + NS_IF_RELEASE(gServiceManager); + gServiceManager = NULL; +} + +///////////////////////////////////////////////////////////// +// +// construction and destruction of our plugin instance object +// +nsPluginInstanceBase * NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct) +{ + if(!aCreateDataStruct) + return NULL; + + nsPluginInstance * plugin = new nsPluginInstance(aCreateDataStruct->instance); + return plugin; +} + +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin) +{ + if(aPlugin) + delete (nsPluginInstance *)aPlugin; +} + +//////////////////////////////////////// +// +// nsPluginInstance class implementation +// +nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(), + mInstance(aInstance), + mInitialized(FALSE), + mScriptablePeer(NULL) +{ + mString[0] = '\0'; +} + +nsPluginInstance::~nsPluginInstance() +{ + // mScriptablePeer may be also held by the browser + // so releasing it here does not guarantee that it is over + // we should take precaution in case it will be called later + // and zero its mPlugin member + mScriptablePeer->SetInstance(NULL); + NS_IF_RELEASE(mScriptablePeer); +} + +NPBool nsPluginInstance::init(NPWindow* aWindow) +{ + if(aWindow == NULL) + return FALSE; + + mInitialized = TRUE; + return TRUE; +} + +void nsPluginInstance::shut() +{ + mInitialized = FALSE; +} + +NPBool nsPluginInstance::isInitialized() +{ + return mInitialized; +} + + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// here the plugin is asked by Mozilla to tell if it is scriptable +// we should return a valid interface id and a pointer to +// nsScriptablePeer interface which we should have implemented +// and which should be defined in the corressponding *.xpt file +// in the bin/components folder +NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) +{ + NPError rv = NPERR_NO_ERROR; + + switch (aVariable) { + case NPPVpluginScriptableInstance: { + // addref happens in getter, so we don't addref here + nsISimplePlugin * scriptablePeer = getScriptablePeer(); + if (scriptablePeer) { + *(nsISupports **)aValue = scriptablePeer; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + break; + + case NPPVpluginScriptableIID: { + static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID; + nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID)); + if (ptr) { + *ptr = scriptableIID; + *(nsIID **)aValue = ptr; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + break; + + default: + break; + } + + return rv; +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// this method will return the scriptable object (and create it if necessary) +nsScriptablePeer* nsPluginInstance::getScriptablePeer() +{ + if (!mScriptablePeer) { + mScriptablePeer = new nsScriptablePeer(this); + if(!mScriptablePeer) + return NULL; + + NS_ADDREF(mScriptablePeer); + } + + // add reference for the caller requesting the object + NS_ADDREF(mScriptablePeer); + return mScriptablePeer; +} diff --git a/mozilla/java/plugins/mozilla/nppluglet.def b/mozilla/java/plugins/mozilla/nppluglet.def new file mode 100644 index 00000000000..975435b4be4 --- /dev/null +++ b/mozilla/java/plugins/mozilla/nppluglet.def @@ -0,0 +1,6 @@ +LIBRARY NPPLUGLET + +EXPORTS + NP_GetEntryPoints @1 + NP_Initialize @2 + NP_Shutdown @3 diff --git a/mozilla/java/plugins/mozilla/nppluglet.h b/mozilla/java/plugins/mozilla/nppluglet.h new file mode 100644 index 00000000000..8b185181c2b --- /dev/null +++ b/mozilla/java/plugins/mozilla/nppluglet.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 MPL, 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 MPL, 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 + // and couple of other things on Unix + NPError GetValue(NPPVariable variable, void *value); + + // locals + + nsScriptablePeer* getScriptablePeer(); + +private: + NPP mInstance; + NPBool mInitialized; + nsScriptablePeer * mScriptablePeer; + +public: + char mString[128]; +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/java/plugins/mozilla/nsISimplePlugin.idl b/mozilla/java/plugins/mozilla/nsISimplePlugin.idl new file mode 100644 index 00000000000..ed8351606cf --- /dev/null +++ b/mozilla/java/plugins/mozilla/nsISimplePlugin.idl @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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) 2001 + * 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 MPL, 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 MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +[scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)] +interface nsISimplePlugin : nsISupports { +}; diff --git a/mozilla/java/plugins/mozilla/nsScriptablePeer.cpp b/mozilla/java/plugins/mozilla/nsScriptablePeer.cpp new file mode 100644 index 00000000000..08ae8e9d805 --- /dev/null +++ b/mozilla/java/plugins/mozilla/nsScriptablePeer.cpp @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 MPL, 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 MPL, 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 "nppluglet.h" + +static NS_DEFINE_IID(kISimplePluginIID, NS_ISIMPLEPLUGIN_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(kISimplePluginIID)) { + *aInstancePtr = NS_STATIC_CAST(nsISimplePlugin*, this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kIClassInfoIID)) { + *aInstancePtr = NS_STATIC_CAST(nsIClassInfo*, this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kISupportsIID)) { + *aInstancePtr = NS_STATIC_CAST(nsISupports*,(NS_STATIC_CAST(nsISimplePlugin*, this))); + AddRef(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +void nsScriptablePeer::SetInstance(nsPluginInstance* plugin) +{ + mPlugin = plugin; +} + +// +// the following method will be callable from JavaScript +// +//NS_IMETHODIMP nsScriptablePeer::GetVersion(char * *aVersion) +//{ +// if (mPlugin) +// mPlugin->getVersion(aVersion); +// return NS_OK; +//} diff --git a/mozilla/java/plugins/mozilla/nsScriptablePeer.h b/mozilla/java/plugins/mozilla/nsScriptablePeer.h new file mode 100644 index 00000000000..61100d8cf7f --- /dev/null +++ b/mozilla/java/plugins/mozilla/nsScriptablePeer.h @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 MPL, 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 MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// nsScriptablePeer - xpconnect scriptable peer +// + +#ifndef __nsScriptablePeer_h__ +#define __nsScriptablePeer_h__ + +#include "nsISimplePlugin.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 nsISimplePlugin, + 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_NSISIMPLEPLUGIN + + void SetInstance(nsPluginInstance* plugin); + +protected: + nsPluginInstance* mPlugin; +}; + +#endif +