зеркало из https://github.com/mozilla/gecko-dev.git
Bug 73874 -- sample plugin (4.x scriptability), not part of the build, r=peterl
This commit is contained in:
Родитель
ec95c41e90
Коммит
148209b714
|
@ -0,0 +1,220 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.76 [en]C-AOLNSCP (Win98; U) [Netscape]">
|
||||
<title>Scripting Old Style Plugins with Mozilla</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><b><font size=+2>Scripting Old Style Plugins in Mozilla</font></b>
|
||||
<br><i>April 11, 2001</i>
|
||||
<br>(see online version for the latest updates:
|
||||
<a href="http://mozilla.org/docs/scripting-plugins.html">http://mozilla.org/docs/scripting-plugins.html</a>)
|
||||
</center>
|
||||
|
||||
<p><a href="readme.html#introduction">Introduction</a>
|
||||
<br><a href="readme.html#mozilla">New in Mozilla code</a>
|
||||
<br><a href="readme.html#plugin">New in plugin code</a>
|
||||
<br><a href="readme.html#script">JavaScript code</a>
|
||||
<br><a href="readme.html#build">Building and installing the plugin</a>
|
||||
<br><a href="readme.html#more">What else to read</a>
|
||||
<br><a href="readme.html#example1">Examples</a>
|
||||
<p><a NAME="introduction"></a><b>Introduction</b>
|
||||
<p>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 <a href="http://www.mozilla.org/docs/plugin.html">Mozilla
|
||||
Plugin API</a> allows plugins be scriptable via a different mechanism called
|
||||
<a href="http://www.mozilla.org/scriptable/index.html">XPConnect.</a>
|
||||
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 <a href="http://www.mozilla.org/projects/xpcom/">XPCOM</a>
|
||||
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.
|
||||
<p>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.
|
||||
<p><a NAME="mozilla"></a><b>What's in the Mozilla code?</b>
|
||||
<p>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 <tt>NPP_GetValue</tt> is used to retrieve this
|
||||
information from the plugin. So the plugin project should be aware of two
|
||||
new additions to <tt>NPPVariable</tt> enumeration type which are now defined
|
||||
in npapi.h as
|
||||
<p><tt> NPPVpluginScriptableInstance = 10,</tt>
|
||||
<br><tt> NPPVpluginScriptableIID =
|
||||
11</tt>
|
||||
<p>and two analogous additions to nsPluginInstanceVariable type in nsplugindefs.h
|
||||
as
|
||||
<p><tt> nsPluginInstanceVariable_ScriptableInstance = 10,</tt>
|
||||
<br><tt> nsPluginInstanceVariable_ScriptableIID
|
||||
= 11</tt>
|
||||
<p><a NAME="plugin"></a><b>What's in the plugin code?</b>
|
||||
<p>1. A unique interface id should be obtained. Windows command <tt>uuidgen</tt>
|
||||
should be sufficient.
|
||||
<p>2. An Interface Definition (<tt>.idl</tt>) file describing the plugin
|
||||
scriptable interface should be added to the project (<a href="#example1">see
|
||||
example 1</a>).
|
||||
<p>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 (<a href="#example2">see example 2</a>).
|
||||
<p>4. Two new cases for the above mentioned new variables should be added
|
||||
to the plugin implementation of <tt>NPP_GetValue</tt> (<a href="#example3">see
|
||||
example 3</a>).
|
||||
<p><a NAME="script"></a><b>How to call plugin native methods</b>
|
||||
<p>The following HTML code will do the job:
|
||||
<p><tt><embed type="application/plugin-mimetype"></tt>
|
||||
<br><tt><script></tt>
|
||||
<br><tt>var embed = document.embeds[0];</tt>
|
||||
<br><tt>embed.nativeMethod();</tt>
|
||||
<br><tt></script></tt>
|
||||
<p><a NAME="build"></a><b>How to build and install</b>
|
||||
<p>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. <i>MS DevStudio MIDL
|
||||
should not be used</i>. (Let's assume 'TestPlugin' as a plugin name-place
|
||||
holder.)
|
||||
<p>1. Compile nsITestPlugin.idl with the idl compiler. This will generate
|
||||
nsITestPlugin.h and nsITestPlugin.xpt files.
|
||||
<p>2. Put nsITestPlugin.xpt to the Components folder.
|
||||
<p>3. Build nptestplugin.dll with nsITestPlugin.h included for compiling
|
||||
scriptable instance class implementaion.
|
||||
<p>4. Put nptestplugin.dll to the Plugins folder.
|
||||
<p><a NAME="more"></a><b>Related sources</b>
|
||||
<br>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="http://bugzilla.mozilla.org/">http://bugzilla.mozilla.org</a>
|
||||
has two bugs in its database which are related to this topic: <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=73856">73856
|
||||
</a>and <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=73874">73874</a>.
|
||||
The latter contains the full sample plugin code.</li>
|
||||
|
||||
<li>
|
||||
IBM Developer Works has published <a href="http://www-106.ibm.com/developerworks/components/library/co-xpcom.html">a
|
||||
good article on XPCOM.</a></li>
|
||||
</ul>
|
||||
|
||||
<p><a NAME="example1"></a><b>Example 1. Sample .idl file</b>
|
||||
<p><tt>#include "nsISupports.idl"</tt>
|
||||
<p><tt>[scriptable, uuid(bedb0778-2ee0-11d5-9cf8-0060b0fbd8ac)]</tt>
|
||||
<br><tt>interface nsITestPlugin : nsISupports {</tt>
|
||||
<br><tt> void nativeMethod();</tt>
|
||||
<br><tt>};</tt>
|
||||
<p><a NAME="example2"></a><b>Example 2. Scriptable instance class</b>
|
||||
<p><tt>#include "nsITestPlugin.h"</tt>
|
||||
<br><tt>#include "nsISecurityCheckedComponent.h"</tt>
|
||||
<p><tt>class nsScriptablePeer : public nsITestPlugin,</tt>
|
||||
<br><tt>
|
||||
public nsISecurityCheckedComponent</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt>public:</tt>
|
||||
<br><tt> nsScriptablePeer();</tt>
|
||||
<br><tt> ~nsScriptablePeer();</tt>
|
||||
<p><tt> NS_DECL_ISUPPORTS</tt>
|
||||
<br><tt> NS_DECL_NSITESTPLUGIN</tt>
|
||||
<br><tt> NS_DECL_NSISECURITYCHECKEDCOMPONENT</tt>
|
||||
<br><tt>};</tt>
|
||||
<p><tt>nsScriptablePeer::nsScriptablePeer()</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> NS_INIT_ISUPPORTS();</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><tt>nsScriptablePeer::~nsScriptablePeer()</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><tt>NS_IMPL_ISUPPORTS2(nsScriptablePeer, nsITestPlugin, nsISecurityCheckedComponent)</tt>
|
||||
<p><tt>// the following method will be callable from JavaScript</tt>
|
||||
<br><tt>NS_IMETHODIMP nsScriptablePeer::NativeMethod()</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> return NS_OK;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><tt>// the purpose of the rest of the code is to get succesfully</tt>
|
||||
<br><tt>// through the Mozilla Security Manager</tt>
|
||||
<br><tt>static const char gAllAccess[] = "AllAccess";</tt>
|
||||
<br><tt>NS_IMETHODIMP nsScriptablePeer::CanCreateWrapper(const nsIID *
|
||||
iid, char **_retval)</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> if (!_retval)</tt>
|
||||
<br><tt> return NS_ERROR_NULL_POINTER;</tt>
|
||||
<br><tt> *_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);</tt>
|
||||
<br><tt> if (!*_retval)</tt>
|
||||
<br><tt> return NS_ERROR_OUT_OF_MEMORY;</tt>
|
||||
<br><tt> strcpy(*_retval, gAllAccess);</tt>
|
||||
<br><tt> return NS_OK;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><tt>NS_IMETHODIMP nsScriptablePeer::CanCallMethod(const nsIID * iid,
|
||||
const PRUnichar *methodName, char **_retval)</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> if (!_retval)</tt>
|
||||
<br><tt> return NS_ERROR_NULL_POINTER;</tt>
|
||||
<br><tt> *_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);</tt>
|
||||
<br><tt> if (!*_retval)</tt>
|
||||
<br><tt> return NS_ERROR_OUT_OF_MEMORY;</tt>
|
||||
<br><tt> strcpy(*_retval, gAllAccess);</tt>
|
||||
<br><tt> return NS_OK;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><tt>NS_IMETHODIMP nsScriptablePeer::CanGetProperty(const nsIID * iid,
|
||||
const PRUnichar *propertyName, char **_retval)</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> if (!_retval)</tt>
|
||||
<br><tt> return NS_ERROR_NULL_POINTER;</tt>
|
||||
<br><tt> *_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);</tt>
|
||||
<br><tt> if (!*_retval)</tt>
|
||||
<br><tt> return NS_ERROR_OUT_OF_MEMORY;</tt>
|
||||
<br><tt> strcpy(*_retval, gAllAccess);</tt>
|
||||
<br><tt> return NS_OK;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><tt>NS_IMETHODIMP nsScriptablePeer::CanSetProperty(const nsIID * iid,
|
||||
const PRUnichar *propertyName, char **_retval)</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> if (!_retval)</tt>
|
||||
<br><tt> return NS_ERROR_NULL_POINTER;</tt>
|
||||
<br><tt> *_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);</tt>
|
||||
<br><tt> if (!*_retval)</tt>
|
||||
<br><tt> return NS_ERROR_OUT_OF_MEMORY;</tt>
|
||||
<br><tt> strcpy(*_retval, gAllAccess);</tt>
|
||||
<br><tt> return NS_OK;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p><a NAME="example3"></a><b>Example 3. NPP_GetValue implementation</b>
|
||||
<p><tt>#include "nsITestPlugin.h"</tt>
|
||||
<p><tt>NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)</tt>
|
||||
<br><tt>{</tt>
|
||||
<br><tt> if(instance == NULL)</tt>
|
||||
<br><tt> return NPERR_INVALID_INSTANCE_ERROR;</tt>
|
||||
<p><tt> NPError rv = NPERR_NO_ERROR;</tt>
|
||||
<br><tt> static nsIID scriptableIID = NS_ITESTPLUGIN_IID;</tt>
|
||||
<p><tt> if (variable == NPPVpluginScriptableInstance)</tt>
|
||||
<br><tt> {</tt>
|
||||
<br><tt> if (this is first time and we haven't created
|
||||
it yet)</tt>
|
||||
<br><tt> {</tt>
|
||||
<br><tt> nsITestPlugin * scriptablePeer =
|
||||
new nsScriptablePeer();</tt>
|
||||
<br><tt> if(scriptablePeer)</tt>
|
||||
<br><tt> // addref for ourself,
|
||||
don't forget to release on shutdown to trigger its destruction</tt>
|
||||
<br><tt> NS_ADDREF(scriptablePeer);</tt>
|
||||
<br><tt> }</tt>
|
||||
<br><tt> // add reference for the caller requesting the
|
||||
object</tt>
|
||||
<br><tt> NS_ADDREF(scriptablePeer);</tt>
|
||||
<br><tt> *(nsISupports **)value = scriptablePeer;</tt>
|
||||
<br><tt> }</tt>
|
||||
<br><tt> else if (variable == NPPVpluginScriptableIID)</tt>
|
||||
<br><tt> {</tt>
|
||||
<br><tt> nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));</tt>
|
||||
<br><tt> *ptr = scriptableIID;</tt>
|
||||
<br><tt> *(nsIID **)value = ptr;</tt>
|
||||
<br><tt> }</tt>
|
||||
<br><tt> return rv;</tt>
|
||||
<br><tt>}</tt>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
LIBRARY NP4XSCR
|
||||
|
||||
EXPORTS
|
||||
NP_GetEntryPoints @1
|
||||
NP_Initialize @2
|
||||
NP_Shutdown @3
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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 <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)]
|
||||
interface nsI4xScrPlugin : nsISupports {
|
||||
void showVersion();
|
||||
void clear();
|
||||
};
|
|
@ -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<nsI4xScrPlugin*>(this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if(aIID.Equals(kISecurityCheckedComponentIID)) {
|
||||
*aInstancePtr = static_cast<nsISecurityCheckedComponent*>(this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if(aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = static_cast<nsISupports*>(static_cast<nsI4xScrPlugin*>(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;
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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 <windows.h>
|
||||
#include <windowsx.h>
|
||||
#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
|
|
@ -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__
|
|
@ -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
|
|
@ -0,0 +1,48 @@
|
|||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>4x Scriptable Plug-in Test</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<center>
|
||||
<h1> XPConnect Scriptable Old Style Sample Plug-in </h1>
|
||||
</center>
|
||||
|
||||
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.
|
||||
|
||||
<br><br>
|
||||
|
||||
<center>
|
||||
|
||||
<embed type="application/mozilla-4x-scriptable-plugin" width=600 height=40><br>
|
||||
|
||||
<script>
|
||||
var embed = document.embeds[0];
|
||||
|
||||
function ShowVersion()
|
||||
{
|
||||
embed.showVersion();
|
||||
}
|
||||
|
||||
function Clear()
|
||||
{
|
||||
embed.clear();
|
||||
}
|
||||
</script>
|
||||
|
||||
<br>
|
||||
<form name="formname">
|
||||
<input type=button value="Show Version" onclick='ShowVersion()'>
|
||||
<input type=button value="Clear" onclick='Clear()'>
|
||||
</form>
|
||||
|
||||
</center>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
Загрузка…
Ссылка в новой задаче