diff --git a/mozilla/modules/plugin/samples/4x-scriptable/doc.html b/mozilla/modules/plugin/samples/4x-scriptable/doc.html new file mode 100644 index 00000000000..820d8e37fc7 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/doc.html @@ -0,0 +1,220 @@ + + +
+ + +Introduction
+
New in Mozilla code
+
New in plugin code
+
JavaScript code
+
Building and installing the plugin
+
What else to read
+
Examples
+
Plugins that used to take advantage of being scriptable via LiveConnect +in 4.x Netscape browsers lost this possibility in the new world. The main +reason for this is that there is no guarantee of Java compatibility on +a binary level due to the jri/jni switch. The newly introduced Mozilla +Plugin API allows plugins be scriptable via a different mechanism called +XPConnect. +Basically, this means that in order to use and take full advantage of this +new API, which is interface-based, and to be scriptable, plugins +must be rewritten to become XPCOM +components. Switching to the new world may not be immediately desirable +by some plugin makers, since the task involves a fair amount of effort, +and if the plugin mostly works fine lacking only scriptability, developers +will probably just give up on this feature, which may result in unpleasant +experience for the end user. +
In order to make the transtion smoother, some changes have been made +to the Mozilla code. The changes allow to make existing 4.x plugins scriptable +with only minor modifications in their code. The present document describes +the steps of what should be done to the plugin code to turn it scriptable +again. +
A couple of lines have been added to the DOM code asking a plugin to +return a scriptable iid and a pointer to a scriptable instance object. +The old Plugin API call NPP_GetValue is used to retrieve this +information from the plugin. So the plugin project should be aware of two +new additions to NPPVariable enumeration type which are now defined +in npapi.h as +
NPPVpluginScriptableInstance = 10,
+
NPPVpluginScriptableIID =
+11
+
and two analogous additions to nsPluginInstanceVariable type in nsplugindefs.h +as +
nsPluginInstanceVariable_ScriptableInstance = 10,
+
nsPluginInstanceVariable_ScriptableIID
+= 11
+
1. A unique interface id should be obtained. Windows command uuidgen +should be sufficient. +
2. An Interface Definition (.idl) file describing the plugin +scriptable interface should be added to the project (see +example 1). +
3. A Scriptable instance object should be implemented in the plugin. +This class will contain native methods callable from JavaScript. This class +should also inherit from nsISecurityCheckedComponent and implement its +methods to be able to request all necessary privileges from the Mozilla +security manager (see example 2). +
4. Two new cases for the above mentioned new variables should be added +to the plugin implementation of NPP_GetValue (see +example 3). +
How to call plugin native methods +
The following HTML code will do the job: +
<embed type="application/plugin-mimetype">
+
<script>
+
var embed = document.embeds[0];
+
embed.nativeMethod();
+
</script>
+
Having the built Mozilla tree is probably not necessary, but building +the plugin with a scriptable instance interface will require Mozilla headers +and the XPCOM compatible idl compiler -- xpidl.exe. MS DevStudio MIDL +should not be used. (Let's assume 'TestPlugin' as a plugin name-place +holder.) +
1. Compile nsITestPlugin.idl with the idl compiler. This will generate +nsITestPlugin.h and nsITestPlugin.xpt files. +
2. Put nsITestPlugin.xpt to the Components folder. +
3. Build nptestplugin.dll with nsITestPlugin.h included for compiling +scriptable instance class implementaion. +
4. Put nptestplugin.dll to the Plugins folder. +
#include "nsISupports.idl" +
[scriptable, uuid(bedb0778-2ee0-11d5-9cf8-0060b0fbd8ac)]
+
interface nsITestPlugin : nsISupports {
+
void nativeMethod();
+
};
+
Example 2. Scriptable instance class +
#include "nsITestPlugin.h"
+
#include "nsISecurityCheckedComponent.h"
+
class nsScriptablePeer : public nsITestPlugin,
+
+public nsISecurityCheckedComponent
+
{
+
public:
+
nsScriptablePeer();
+
~nsScriptablePeer();
+
NS_DECL_ISUPPORTS
+
NS_DECL_NSITESTPLUGIN
+
NS_DECL_NSISECURITYCHECKEDCOMPONENT
+
};
+
nsScriptablePeer::nsScriptablePeer()
+
{
+
NS_INIT_ISUPPORTS();
+
}
+
nsScriptablePeer::~nsScriptablePeer()
+
{
+
}
+
NS_IMPL_ISUPPORTS2(nsScriptablePeer, nsITestPlugin, nsISecurityCheckedComponent) +
// the following method will be callable from JavaScript
+
NS_IMETHODIMP nsScriptablePeer::NativeMethod()
+
{
+
return NS_OK;
+
}
+
// the purpose of the rest of the code is to get succesfully
+
// through the Mozilla Security Manager
+
static const char gAllAccess[] = "AllAccess";
+
NS_IMETHODIMP nsScriptablePeer::CanCreateWrapper(const nsIID *
+iid, char **_retval)
+
{
+
if (!_retval)
+
return NS_ERROR_NULL_POINTER;
+
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
+
if (!*_retval)
+
return NS_ERROR_OUT_OF_MEMORY;
+
strcpy(*_retval, gAllAccess);
+
return NS_OK;
+
}
+
NS_IMETHODIMP nsScriptablePeer::CanCallMethod(const nsIID * iid,
+const PRUnichar *methodName, char **_retval)
+
{
+
if (!_retval)
+
return NS_ERROR_NULL_POINTER;
+
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
+
if (!*_retval)
+
return NS_ERROR_OUT_OF_MEMORY;
+
strcpy(*_retval, gAllAccess);
+
return NS_OK;
+
}
+
NS_IMETHODIMP nsScriptablePeer::CanGetProperty(const nsIID * iid,
+const PRUnichar *propertyName, char **_retval)
+
{
+
if (!_retval)
+
return NS_ERROR_NULL_POINTER;
+
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
+
if (!*_retval)
+
return NS_ERROR_OUT_OF_MEMORY;
+
strcpy(*_retval, gAllAccess);
+
return NS_OK;
+
}
+
NS_IMETHODIMP nsScriptablePeer::CanSetProperty(const nsIID * iid,
+const PRUnichar *propertyName, char **_retval)
+
{
+
if (!_retval)
+
return NS_ERROR_NULL_POINTER;
+
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
+
if (!*_retval)
+
return NS_ERROR_OUT_OF_MEMORY;
+
strcpy(*_retval, gAllAccess);
+
return NS_OK;
+
}
+
Example 3. NPP_GetValue implementation +
#include "nsITestPlugin.h" +
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
+
{
+
if(instance == NULL)
+
return NPERR_INVALID_INSTANCE_ERROR;
+
NPError rv = NPERR_NO_ERROR;
+
static nsIID scriptableIID = NS_ITESTPLUGIN_IID;
+
if (variable == NPPVpluginScriptableInstance)
+
{
+
if (this is first time and we haven't created
+it yet)
+
{
+
nsITestPlugin * scriptablePeer =
+new nsScriptablePeer();
+
if(scriptablePeer)
+
// addref for ourself,
+don't forget to release on shutdown to trigger its destruction
+
NS_ADDREF(scriptablePeer);
+
}
+
// add reference for the caller requesting the
+object
+
NS_ADDREF(scriptablePeer);
+
*(nsISupports **)value = scriptablePeer;
+
}
+
else if (variable == NPPVpluginScriptableIID)
+
{
+
nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
+
*ptr = scriptableIID;
+
*(nsIID **)value = ptr;
+
}
+
return rv;
+
}
+
+
+
diff --git a/mozilla/modules/plugin/samples/4x-scriptable/makefile.win b/mozilla/modules/plugin/samples/4x-scriptable/makefile.win
new file mode 100644
index 00000000000..c76de7dc09d
--- /dev/null
+++ b/mozilla/modules/plugin/samples/4x-scriptable/makefile.win
@@ -0,0 +1,51 @@
+#!gmake
+#
+# 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.
+
+DEPTH = ..\..\..\..
+include <$(DEPTH)/config/config.mak>
+
+MODULE = np4xscr
+
+XPIDLSRCS = \
+ .\nsI4xScrPlugin.idl \
+ $(NULL)
+
+MAKE_OBJ_TYPE = DLL
+DLLNAME = np4xscr
+RESFILE = np4xscr.res
+DEFFILE = np4xscr.def
+DLL=.\$(OBJDIR)\$(DLLNAME).dll
+
+OBJS = \
+ .\$(OBJDIR)\np_entry.obj \
+ .\$(OBJDIR)\npn_gate.obj \
+ .\$(OBJDIR)\npp_gate.obj \
+ .\$(OBJDIR)\plugin.obj \
+ .\$(OBJDIR)\nsScriptablePeer.obj \
+ $(NULL)
+
+WIN_LIBS = version.lib
+
+include <$(DEPTH)/config/rules.mak>
+
+#MAKE_INSTALL=echo $(MAKE_INSTALL)
+
+install:: $(DLL)
+# $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\plugins
+
+clobber::
+ rm -f *.sbr $(DIST)\bin\plugins\$(DLLNAME).dll $(DIST)\bin\components\$(DLLNAME).xpt
diff --git a/mozilla/modules/plugin/samples/4x-scriptable/np4xscr.def b/mozilla/modules/plugin/samples/4x-scriptable/np4xscr.def
new file mode 100644
index 00000000000..6c69b0002f4
--- /dev/null
+++ b/mozilla/modules/plugin/samples/4x-scriptable/np4xscr.def
@@ -0,0 +1,6 @@
+LIBRARY NP4XSCR
+
+EXPORTS
+ NP_GetEntryPoints @1
+ NP_Initialize @2
+ NP_Shutdown @3
diff --git a/mozilla/modules/plugin/samples/4x-scriptable/np_entry.cpp b/mozilla/modules/plugin/samples/4x-scriptable/np_entry.cpp
new file mode 100644
index 00000000000..97200664950
--- /dev/null
+++ b/mozilla/modules/plugin/samples/4x-scriptable/np_entry.cpp
@@ -0,0 +1,100 @@
+/* -*- 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 mozilla.org code.
+ *
+ * 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.
+ *
+ * Contributor(s):
+ */
+
+//////////////////////////////////////////////////////////////
+//
+// Main plugin entry point implementation
+//
+#include "npapi.h"
+#include "npupp.h"
+
+NPNetscapeFuncs NPNFuncs;
+
+NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)
+{
+ if(pFuncs == NULL)
+ return NPERR_INVALID_FUNCTABLE_ERROR;
+
+ if(pFuncs->size < sizeof(NPPluginFuncs))
+ return NPERR_INVALID_FUNCTABLE_ERROR;
+
+ pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
+ pFuncs->newp = NPP_New;
+ pFuncs->destroy = NPP_Destroy;
+ pFuncs->setwindow = NPP_SetWindow;
+ pFuncs->newstream = NPP_NewStream;
+ pFuncs->destroystream = NPP_DestroyStream;
+ pFuncs->asfile = NPP_StreamAsFile;
+ pFuncs->writeready = NPP_WriteReady;
+ pFuncs->write = NPP_Write;
+ pFuncs->print = NPP_Print;
+ pFuncs->event = NPP_HandleEvent;
+ pFuncs->urlnotify = NPP_URLNotify;
+ pFuncs->getvalue = NPP_GetValue;
+ pFuncs->setvalue = NPP_SetValue;
+ pFuncs->javaClass = NULL;
+
+ return NPERR_NO_ERROR;
+}
+
+NPError OSCALL NP_Initialize(NPNetscapeFuncs* pFuncs)
+{
+ if(pFuncs == NULL)
+ return NPERR_INVALID_FUNCTABLE_ERROR;
+
+ if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+ if(pFuncs->size < sizeof NPNetscapeFuncs)
+ return NPERR_INVALID_FUNCTABLE_ERROR;
+
+ NPNFuncs.size = pFuncs->size;
+ NPNFuncs.version = pFuncs->version;
+ NPNFuncs.geturlnotify = pFuncs->geturlnotify;
+ NPNFuncs.geturl = pFuncs->geturl;
+ NPNFuncs.posturlnotify = pFuncs->posturlnotify;
+ NPNFuncs.posturl = pFuncs->posturl;
+ NPNFuncs.requestread = pFuncs->requestread;
+ NPNFuncs.newstream = pFuncs->newstream;
+ NPNFuncs.write = pFuncs->write;
+ NPNFuncs.destroystream = pFuncs->destroystream;
+ NPNFuncs.status = pFuncs->status;
+ NPNFuncs.uagent = pFuncs->uagent;
+ NPNFuncs.memalloc = pFuncs->memalloc;
+ NPNFuncs.memfree = pFuncs->memfree;
+ NPNFuncs.memflush = pFuncs->memflush;
+ NPNFuncs.reloadplugins = pFuncs->reloadplugins;
+ NPNFuncs.getJavaEnv = pFuncs->getJavaEnv;
+ NPNFuncs.getJavaPeer = pFuncs->getJavaPeer;
+ NPNFuncs.getvalue = pFuncs->getvalue;
+ NPNFuncs.setvalue = pFuncs->setvalue;
+ NPNFuncs.invalidaterect = pFuncs->invalidaterect;
+ NPNFuncs.invalidateregion = pFuncs->invalidateregion;
+ NPNFuncs.forceredraw = pFuncs->forceredraw;
+
+ return NPERR_NO_ERROR;
+}
+
+NPError OSCALL NP_Shutdown()
+{
+ return NPERR_NO_ERROR;
+}
diff --git a/mozilla/modules/plugin/samples/4x-scriptable/npn_gate.cpp b/mozilla/modules/plugin/samples/4x-scriptable/npn_gate.cpp
new file mode 100644
index 00000000000..58735cae81d
--- /dev/null
+++ b/mozilla/modules/plugin/samples/4x-scriptable/npn_gate.cpp
@@ -0,0 +1,198 @@
+/* -*- 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 mozilla.org code.
+ *
+ * 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.
+ *
+ * Contributor(s):
+ */
+
+////////////////////////////////////////////////////////////
+//
+// Implementation of Netscape entry points (NPN_*)
+//
+#include "npapi.h"
+#include "npupp.h"
+
+extern NPNetscapeFuncs NPNFuncs;
+
+void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
+{
+ *plugin_major = NP_VERSION_MAJOR;
+ *plugin_minor = NP_VERSION_MINOR;
+ *netscape_major = HIBYTE(NPNFuncs.version);
+ *netscape_minor = LOBYTE(NPNFuncs.version);
+}
+
+NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
+{
+ int navMinorVers = NPNFuncs.version & 0xFF;
+ NPError rv = NPERR_NO_ERROR;
+
+ if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
+ rv = NPNFuncs.geturlnotify(instance, url, target, notifyData);
+ else
+ rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+ return rv;
+}
+
+NPError NPN_GetURL(NPP instance, const char *url, const char *target)
+{
+ NPError rv = NPNFuncs.geturl(instance, url, target);
+ return rv;
+}
+
+NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
+{
+ int navMinorVers = NPNFuncs.version & 0xFF;
+ NPError rv = NPERR_NO_ERROR;
+
+ if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
+ rv = NPNFuncs.posturlnotify(instance, url, window, len, buf, file, notifyData);
+ else
+ rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+ return rv;
+}
+
+NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
+{
+ NPError rv = NPNFuncs.posturl(instance, url, window, len, buf, file);
+ return rv;
+}
+
+NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
+{
+ NPError rv = NPNFuncs.requestread(stream, rangeList);
+ return rv;
+}
+
+NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
+{
+ int navMinorVersion = NPNFuncs.version & 0xFF;
+
+ NPError rv = NPERR_NO_ERROR;
+
+ if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT )
+ rv = NPNFuncs.newstream(instance, type, target, stream);
+ else
+ rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+ return rv;
+}
+
+int32 NPN_Write(NPP instance, NPStream *stream, int32 len, void *buffer)
+{
+ int navMinorVersion = NPNFuncs.version & 0xFF;
+ int32 rv = 0;
+
+ if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT )
+ rv = NPNFuncs.write(instance, stream, len, buffer);
+ else
+ rv = -1;
+
+ return rv;
+}
+
+NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
+{
+ int navMinorVersion = NPNFuncs.version & 0xFF;
+ NPError rv = NPERR_NO_ERROR;
+
+ if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT )
+ rv = NPNFuncs.destroystream(instance, stream, reason);
+ else
+ rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+ return rv;
+}
+
+void NPN_Status(NPP instance, const char *message)
+{
+ NPNFuncs.status(instance, message);
+}
+
+const char* NPN_UserAgent(NPP instance)
+{
+ const char * rv = NULL;
+ rv = NPNFuncs.uagent(instance);
+ return rv;
+}
+
+void* NPN_MemAlloc(uint32 size)
+{
+ void * rv = NULL;
+ rv = NPNFuncs.memalloc(size);
+ return rv;
+}
+
+void NPN_MemFree(void* ptr)
+{
+ NPNFuncs.memfree(ptr);
+}
+
+uint32 NPN_MemFlush(uint32 size)
+{
+ uint32 rv = NPNFuncs.memflush(size);
+ return rv;
+}
+
+void NPN_ReloadPlugins(NPBool reloadPages)
+{
+ NPNFuncs.reloadplugins(reloadPages);
+}
+
+JRIEnv* NPN_GetJavaEnv(void)
+{
+ JRIEnv * rv = NULL;
+ rv = NPNFuncs.getJavaEnv();
+ return rv;
+}
+
+jref NPN_GetJavaPeer(NPP instance)
+{
+ jref rv;
+ rv = NPNFuncs.getJavaPeer(instance);
+ return rv;
+}
+
+NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
+{
+ NPError rv = NPNFuncs.getvalue(instance, variable, value);
+ return rv;
+}
+
+NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
+{
+ NPError rv = NPNFuncs.setvalue(instance, variable, value);
+ return rv;
+}
+
+void NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
+{
+ NPNFuncs.invalidaterect(instance, invalidRect);
+}
+
+void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
+{
+ NPNFuncs.invalidateregion(instance, invalidRegion);
+}
+
+void NPN_ForceRedraw(NPP instance)
+{
+ NPNFuncs.forceredraw(instance);
+}
diff --git a/mozilla/modules/plugin/samples/4x-scriptable/npp_gate.cpp b/mozilla/modules/plugin/samples/4x-scriptable/npp_gate.cpp
new file mode 100644
index 00000000000..401aae10902
--- /dev/null
+++ b/mozilla/modules/plugin/samples/4x-scriptable/npp_gate.cpp
@@ -0,0 +1,230 @@
+/* -*- 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 mozilla.org code.
+ *
+ * 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.
+ *
+ * Contributor(s):
+ */
+
+////////////////////////////////////////////////////////////
+//
+// Implementation of plugin entry points (NPP_*)
+// most are just empty stubs for this particular plugin
+//
+#include "plugin.h"
+
+// here the plugin creates an instance of our CPlugin object which
+// will be associated with this newly created plugin instance and
+// will do all the neccessary job
+NPError NPP_New(NPMIMEType pluginType,
+ NPP instance,
+ uint16 mode,
+ int16 argc,
+ char* argn[],
+ char* argv[],
+ NPSavedData* saved)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+
+ CPlugin * pPlugin = new CPlugin(instance);
+ if(pPlugin == NULL)
+ return NPERR_OUT_OF_MEMORY_ERROR;
+
+ instance->pdata = (void *)pPlugin;
+ return rv;
+}
+
+// here is the place to clean up and destroy the CPlugin object
+NPError NPP_Destroy (NPP instance, NPSavedData** save)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+
+ CPlugin * pPlugin = (CPlugin *)instance->pdata;
+ if(pPlugin != NULL) {
+ pPlugin->shut();
+ delete pPlugin;
+ }
+ return rv;
+}
+
+// during this call we know when the plugin window is ready or
+// is about to be destroyed so we can do some gui specific
+// initialization and shutdown
+NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+
+ if(pNPWindow == NULL)
+ return NPERR_GENERIC_ERROR;
+
+ CPlugin * pPlugin = (CPlugin *)instance->pdata;
+
+ if(pPlugin == NULL)
+ return NPERR_GENERIC_ERROR;
+
+ // window just created
+ if(!pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
+ if(!pPlugin->init(pNPWindow)) {
+ delete pPlugin;
+ pPlugin = NULL;
+ return NPERR_MODULE_LOAD_FAILED_ERROR;
+ }
+ }
+
+ // window goes away
+ if((pNPWindow->window == NULL) && pPlugin->isInitialized())
+ return NPERR_NO_ERROR;
+
+ // window resized
+ if(pPlugin->isInitialized() && (pNPWindow->window != NULL))
+ return NPERR_NO_ERROR;
+
+ // this should not happen, nothing to do
+ if((pNPWindow->window == NULL) && !pPlugin->isInitialized())
+ return NPERR_NO_ERROR;
+
+ return rv;
+}
+
+// ==============================
+// ! 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 NPP_GetValue(NPP instance, NPPVariable variable, void *value)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+
+ if(instance == NULL)
+ return NPERR_GENERIC_ERROR;
+
+ CPlugin * pPlugin = (CPlugin *)instance->pdata;
+ if(pPlugin == NULL)
+ return NPERR_GENERIC_ERROR;
+
+ static nsIID scriptableIID = NS_I4XSCRPLUGIN_IID;
+
+ if (variable == NPPVpluginScriptableInstance) {
+ // addref happens in getter, so we don't addref here
+ nsI4xScrPlugin * scriptablePeer = pPlugin->getScriptablePeer();
+ *(nsISupports **)value = scriptablePeer;
+ }
+ else if (variable == NPPVpluginScriptableIID) {
+ nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
+ *ptr = scriptableIID;
+ *(nsIID **)value = ptr;
+ }
+
+ return rv;
+}
+
+NPError NPP_NewStream(NPP instance,
+ NPMIMEType type,
+ NPStream* stream,
+ NPBool seekable,
+ uint16* stype)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+ return rv;
+}
+
+int32 NPP_WriteReady (NPP instance, NPStream *stream)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ int32 rv = 0x0fffffff;
+ return rv;
+}
+
+int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ int32 rv = len;
+ return rv;
+}
+
+NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+ return rv;
+}
+
+void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
+{
+ if(instance == NULL)
+ return;
+}
+
+void NPP_Print (NPP instance, NPPrint* printInfo)
+{
+ if(instance == NULL)
+ return;
+}
+
+void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
+{
+ if(instance == NULL)
+ return;
+}
+
+NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
+{
+ if(instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ NPError rv = NPERR_NO_ERROR;
+ return rv;
+}
+
+int16 NPP_HandleEvent(NPP instance, void* event)
+{
+ if(instance == NULL)
+ return 0;
+
+ int16 rv = 0;
+ return rv;
+}
+
+jref NPP_GetJavaClass (void)
+{
+ return NULL;
+}
diff --git a/mozilla/modules/plugin/samples/4x-scriptable/nsI4xScrPlugin.idl b/mozilla/modules/plugin/samples/4x-scriptable/nsI4xScrPlugin.idl
new file mode 100644
index 00000000000..f30f37f6945
--- /dev/null
+++ b/mozilla/modules/plugin/samples/4x-scriptable/nsI4xScrPlugin.idl
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * 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 Netscape are
+ * Copyright (C) 2001 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Stuart Parmenter XPConnect Scriptable Old Style Sample Plug-in
+
+
+