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 @@ + + + + + + Scripting Old Style Plugins with Mozilla + + + +
Scripting Old Style Plugins in Mozilla +
April 11, 2001 +
(see online version for the latest updates: +http://mozilla.org/docs/scripting-plugins.html) +
+ +

Introduction +
New in Mozilla code +
New in plugin code +
JavaScript code +
Building and installing the plugin +
What else to read +
Examples +

Introduction +

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. +

What's in the Mozilla code? +

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 +

What's in the plugin code? +

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> +

How to build and install +

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. +

Related sources +
  +

+ +

Example 1. Sample .idl file +

#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 + */ + +#include "nsISupports.idl" + +[scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)] +interface nsI4xScrPlugin : nsISupports { + void showVersion(); + void clear(); +}; \ No newline at end of file diff --git a/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer.cpp b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer.cpp new file mode 100644 index 00000000000..22672dfee02 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer.cpp @@ -0,0 +1,175 @@ +/* -*- 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): + */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// + +///////////////////////////////////////////////////// +// +// This file implements the nsScriptablePeer object +// The native methods of this class are supposed to +// be callable from JavaScript +// +#include "plugin.h" + +static NS_DEFINE_IID(kI4xScrPluginIID, NS_I4XSCRPLUGIN_IID); +static NS_DEFINE_IID(kISecurityCheckedComponentIID, NS_ISECURITYCHECKEDCOMPONENT_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsScriptablePeer::nsScriptablePeer(CPlugin* 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(kI4xScrPluginIID)) { + *aInstancePtr = static_cast(this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kISecurityCheckedComponentIID)) { + *aInstancePtr = static_cast(this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kISupportsIID)) { + *aInstancePtr = static_cast(static_cast(this)); + AddRef(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +// +// the following two methods will be callable from JavaScript +// +NS_IMETHODIMP nsScriptablePeer::ShowVersion() +{ + if (mPlugin) + mPlugin->showVersion(); + + return NS_OK; +} + +NS_IMETHODIMP nsScriptablePeer::Clear() +{ + if (mPlugin) + mPlugin->clear(); + + 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; +} diff --git a/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer.h b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer.h new file mode 100644 index 00000000000..6d26264aea7 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer.h @@ -0,0 +1,73 @@ +/* -*- 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): + */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// nsScriptablePeer - xpconnect scriptable peer +// + +#ifndef __nsScriptablePeer_h__ +#define __nsScriptablePeer_h__ + +#include "nsI4xScrPlugin.h" +#include "nsISecurityCheckedComponent.h" + +class CPlugin; + +// we should add nsISecurityCheckedComponent because the +// Mozilla Security Manager will ask scriptable object about +// priveleges the plugin requests in order to allow calls +// from JavaScript +class nsScriptablePeer : public nsI4xScrPlugin, + public nsISecurityCheckedComponent +{ +public: + nsScriptablePeer(CPlugin* 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_IMETHOD ShowVersion(); + NS_IMETHOD Clear(); + + // methods from nsISecurityCheckedComponent + NS_IMETHOD CanCreateWrapper(const nsIID * iid, char **_retval); + NS_IMETHOD CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval); + NS_IMETHOD CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval); + NS_IMETHOD CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval); + +protected: + CPlugin* mPlugin; +}; + +#endif \ No newline at end of file diff --git a/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer1.cpp b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer1.cpp new file mode 100644 index 00000000000..9c03ecc101a --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer1.cpp @@ -0,0 +1,128 @@ +/* -*- 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): + */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// + +///////////////////////////////////////////////////// +// +// This file implements the nsScriptablePeer object +// The native methods of this class are supposed to +// be callable from JavaScript +// +#include "plugin.h" + +nsScriptablePeer::nsScriptablePeer(CPlugin* aPlugin) +{ + + NS_INIT_ISUPPORTS(); + mPlugin = aPlugin; +} + +nsScriptablePeer::~nsScriptablePeer() +{ +} + +NS_IMPL_ISUPPORTS2(nsScriptablePeer, nsI4xScrPlugin, nsISecurityCheckedComponent) + +// +// the following two methods will be callable from JavaScript +// +NS_IMETHODIMP nsScriptablePeer::ShowVersion() +{ + if (mPlugin) + mPlugin->showVersion(); + + return NS_OK; +} + +NS_IMETHODIMP nsScriptablePeer::Clear() +{ + if (mPlugin) + mPlugin->clear(); + + 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; +} diff --git a/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer1.h b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer1.h new file mode 100644 index 00000000000..8c666e47e92 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/nsScriptablePeer1.h @@ -0,0 +1,57 @@ +/* -*- 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): + */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// nsScriptablePeer - xpconnect scriptable peer +// + +#ifndef __nsScriptablePeer_h__ +#define __nsScriptablePeer_h__ + +#include "nsI4xScrPlugin.h" +#include "nsISecurityCheckedComponent.h" + +class CPlugin; + +// we should add nsISecurityCheckedComponent because the +// Mozilla Security Manager will ask scriptable object about +// priveleges the plugin requests in order to allow calls +// from JavaScript +class nsScriptablePeer : public nsI4xScrPlugin, + public nsISecurityCheckedComponent +{ +public: + nsScriptablePeer(CPlugin* plugin); + ~nsScriptablePeer(); + + NS_DECL_ISUPPORTS + NS_DECL_NSI4XSCRPLUGIN + NS_DECL_NSISECURITYCHECKEDCOMPONENT + +protected: + CPlugin* mPlugin; +}; + +#endif \ No newline at end of file diff --git a/mozilla/modules/plugin/samples/4x-scriptable/plugin.cpp b/mozilla/modules/plugin/samples/4x-scriptable/plugin.cpp new file mode 100644 index 00000000000..cb391a7a710 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/plugin.cpp @@ -0,0 +1,163 @@ +/* -*- 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): + */ + +////////////////////////////////////////////////// +// +// CPlugin class implementation +// +#ifdef XP_WIN +#include +#include +#endif + +#include "plugin.h" + +CPlugin::CPlugin(NPP pNPInstance) : + m_pNPInstance(pNPInstance), + m_pNPStream(NULL), + m_bInitialized(FALSE), + m_pScriptablePeer(NULL) +{ +#ifdef XP_WIN + m_hWnd = NULL; +#endif + + m_String[0] = '\0'; +} + +CPlugin::~CPlugin() +{ + NS_IF_RELEASE(m_pScriptablePeer); +} + +#ifdef XP_WIN +static LRESULT CALLBACK PluginWinProc(HWND, UINT, WPARAM, LPARAM); +static WNDPROC lpOldProc = NULL; +#endif + +BOOL CPlugin::init(NPWindow* pNPWindow) +{ + if(pNPWindow == NULL) + return FALSE; + +#ifdef XP_WIN + m_hWnd = (HWND)pNPWindow->window; + if(m_hWnd == NULL) + return FALSE; + + // subclass window so we can intercept window messages and + // do our drawing to it + lpOldProc = SubclassWindow(m_hWnd, (WNDPROC)PluginWinProc); + + // associate window with our CPlugin object so we can access + // it in the window procedure + SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this); +#endif + + m_bInitialized = TRUE; + return TRUE; +} + +void CPlugin::shut() +{ +#ifdef XP_WIN + // subclass it back + SubclassWindow(m_hWnd, lpOldProc); + m_hWnd = NULL; +#endif + + m_bInitialized = FALSE; +} + +BOOL CPlugin::isInitialized() +{ + return m_bInitialized; +} + +// this will force to draw a version string in the plugin window +void CPlugin::showVersion() +{ + const char *ua = NPN_UserAgent(m_pNPInstance); + strcpy(m_String, ua); + +#ifdef XP_WIN + InvalidateRect(m_hWnd, NULL, TRUE); + UpdateWindow(m_hWnd); +#endif +} + +// this will clean the plugin window +void CPlugin::clear() +{ + strcpy(m_String, ""); + +#ifdef XP_WIN + InvalidateRect(m_hWnd, NULL, TRUE); + UpdateWindow(m_hWnd); +#endif +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// this method will return the scriptable object (and create it if necessary) +nsI4xScrPlugin* CPlugin::getScriptablePeer() +{ + if (!m_pScriptablePeer) { + m_pScriptablePeer = new nsScriptablePeer(this); + if(!m_pScriptablePeer) + return NULL; + + NS_ADDREF(m_pScriptablePeer); + } + + // add reference for the caller requesting the object + NS_ADDREF(m_pScriptablePeer); + return m_pScriptablePeer; +} + +#ifdef XP_WIN +static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_PAINT: + { + // draw a frame and display the string + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + RECT rc; + GetClientRect(hWnd, &rc); + FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH)); + CPlugin * p = (CPlugin *)GetWindowLong(hWnd, GWL_USERDATA); + if(p) + DrawText(hdc, p->m_String, strlen(p->m_String), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + EndPaint(hWnd, &ps); + } + break; + default: + break; + } + + return DefWindowProc(hWnd, msg, wParam, lParam); +} +#endif diff --git a/mozilla/modules/plugin/samples/4x-scriptable/plugin.h b/mozilla/modules/plugin/samples/4x-scriptable/plugin.h new file mode 100644 index 00000000000..a9e45aa13e1 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/plugin.h @@ -0,0 +1,59 @@ +/* -*- 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): + */ + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +#include "npapi.h" +#include "nsScriptablePeer.h" + +class CPlugin +{ +private: + NPP m_pNPInstance; + +#ifdef XP_WIN + HWND m_hWnd; +#endif + + NPStream * m_pNPStream; + BOOL m_bInitialized; + nsI4xScrPlugin * m_pScriptablePeer; + +public: + char m_String[128]; + +public: + CPlugin(NPP pNPInstance); + ~CPlugin(); + + BOOL init(NPWindow* pNPWindow); + void shut(); + BOOL isInitialized(); + + void showVersion(); + void clear(); + + nsI4xScrPlugin* getScriptablePeer(); +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/samples/4x-scriptable/resource.h b/mozilla/modules/plugin/samples/4x-scriptable/resource.h new file mode 100644 index 00000000000..43f7ebf6241 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by np4xscr.rc +// +#define IDD_MAIN 101 +#define IDC_BUTTON_GO 1002 +#define IDC_STATIC_UA 1003 +#define IDC_BUTTON1 1005 +#define IDC_BUTTON_DONT 1005 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1006 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/mozilla/modules/plugin/samples/4x-scriptable/test.html b/mozilla/modules/plugin/samples/4x-scriptable/test.html new file mode 100644 index 00000000000..ecca2920037 --- /dev/null +++ b/mozilla/modules/plugin/samples/4x-scriptable/test.html @@ -0,0 +1,48 @@ + + +4x Scriptable Plug-in Test + + + +

+

XPConnect Scriptable Old Style Sample Plug-in

+
+ +This page contains a testcase which demonstrates the work of scriptable 4.x style +Navigator plug-in with Mozilla. The example plug-in occupies the area right below this text, +and you should see a frame the plug-in draws around its window. Below the plug-in window +there are two buttons. Clicking on the buttons will result in calling native plugin +methods from JavaScript. Show Version will instruct the plug-in to retrieve the +Mozilla user agent string and display it in the plug-in window, Clear button will +call plug-in method to erase the window. + +

+ +
+ +
+ + + +
+
+ + +
+ +
+ + +