1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the NPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the NPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 #ifdef HAVE_MOZILLA_CONFIG_H
41 # include <mozilla-config.h>
45 #ifdef HAVE_NPFUNCTIONS_H
46 #include "npfunctions.h"
55 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
56 JRIGlobalRef Private_GetJavaClass(void);
58 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
59 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
60 // Private_GetJavaClass (global function)
62 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
63 // of this class existence
66 Private_GetJavaClass(void)
68 jref clazz = NPP_GetJavaClass();
70 JRIEnv* env = NPN_GetJavaEnv();
71 return JRI_NewGlobalRef(env, clazz);
76 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
77 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
78 // PLUGIN DLL entry points
80 // These are the Windows specific DLL entry points. They must be exoprted
83 // we need these to be global since we have to fill one of its field
84 // with a data (class) which requires knowlwdge of the navigator
85 // jump-table. This jump table is known at Initialize time (NP_Initialize)
86 // which is called after NP_GetEntryPoint
87 static NPPluginFuncs* g_pluginFuncs;
89 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
90 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
93 // fills in the func table used by Navigator to call entry points in
94 // plugin DLL. Note that these entry points ensure that DS is loaded
95 // by using the NP_LOADDS macro, when compiling for Win16
98 extern "C" __declspec(dllexport) NPError WINAPI
100 NPError WINAPI NP_EXPORT
102 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
106 return NPERR_INVALID_FUNCTABLE_ERROR;
108 // if the plugin's function table is smaller than the plugin expects,
109 // then they are incompatible, and should return an error
111 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
112 pFuncs->newp = NPP_New;
113 pFuncs->destroy = NPP_Destroy;
114 pFuncs->setwindow = NPP_SetWindow;
115 pFuncs->newstream = NPP_NewStream;
116 pFuncs->destroystream = NPP_DestroyStream;
117 pFuncs->asfile = NPP_StreamAsFile;
118 pFuncs->writeready = NPP_WriteReady;
119 pFuncs->write = NPP_Write;
120 pFuncs->print = NPP_Print;
121 pFuncs->event = 0; /// reserved
122 pFuncs->getvalue = NPP_GetValue;
123 pFuncs->setvalue = NPP_SetValue;
125 g_pluginFuncs = pFuncs;
127 return NPERR_NO_ERROR;
130 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
131 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
134 // called immediately after the plugin DLL is loaded
137 extern "C" __declspec(dllexport) NPError WINAPI
139 NPError WINAPI NP_EXPORT
141 NP_Initialize(NPNetscapeFuncs* pFuncs)
145 return NPERR_INVALID_FUNCTABLE_ERROR;
147 g_pNavigatorFuncs = pFuncs; // save it for future reference
149 // if the plugin's major ver level is lower than the Navigator's,
150 // then they are incompatible, and should return an error
151 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
152 return NPERR_INCOMPATIBLE_VERSION_ERROR;
154 // We have to defer these assignments until g_pNavigatorFuncs is set
155 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
157 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
158 g_pluginFuncs->urlnotify = NPP_URLNotify;
161 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
162 g_pluginFuncs->javaClass = Private_GetJavaClass();
165 // NPP_Initialize is a standard (cross-platform) initialize function.
166 return NPP_Initialize();
169 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
170 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
173 // called immediately before the plugin DLL is unloaded.
174 // This functio shuold check for some ref count on the dll to see if it is
175 // unloadable or it needs to stay in memory.
178 extern "C" __declspec(dllexport) NPError WINAPI
180 NPError WINAPI NP_EXPORT
185 g_pNavigatorFuncs = NULL;
186 return NPERR_NO_ERROR;
189 // END - PLUGIN DLL entry points
190 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
191 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
193 /* NAVIGATOR Entry points */
195 /* These entry points expect to be called from within the plugin. The
196 noteworthy assumption is that DS has already been set to point to the
197 plugin's DLL data segment. Don't call these functions from outside
198 the plugin without ensuring DS is set to the DLLs data segment first,
199 typically using the NP_LOADDS macro
202 /* returns the major/minor version numbers of the Plugin API for the plugin
205 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
207 *plugin_major = NP_VERSION_MAJOR;
208 *plugin_minor = NP_VERSION_MINOR;
209 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
210 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
213 /* causes the specified URL to be fetched and streamed in
215 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
218 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
220 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
221 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
224 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
230 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
232 return g_pNavigatorFuncs->geturl(instance, url, target);
235 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
237 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
239 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
240 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
243 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
249 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
251 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
254 /* Requests that a number of bytes be provided on a stream. Typically
255 this would be used if a stream was in "pull" mode. An optional
256 position can be provided for streams which are seekable.
258 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
260 return g_pNavigatorFuncs->requestread(stream, rangeList);
263 /* Creates a new stream of data from the plug-in to be interpreted
264 by Netscape in the current window.
266 NPError NPN_NewStream(NPP instance, NPMIMEType type,
267 const char* target, NPStream** stream)
269 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
272 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
273 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
276 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
281 /* Provides len bytes of data.
283 int32 NPN_Write(NPP instance, NPStream *stream,
284 int32 len, void *buffer)
286 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
289 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
290 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
298 /* Closes a stream object.
299 reason indicates why the stream was closed.
301 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
303 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
306 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
307 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
310 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
315 /* Provides a text status message in the Netscape client user interface
317 void NPN_Status(NPP instance, const char *message)
319 g_pNavigatorFuncs->status(instance, message);
322 /* returns the user agent string of Navigator, which contains version info
324 const char* NPN_UserAgent(NPP instance)
326 return g_pNavigatorFuncs->uagent(instance);
329 /* allocates memory from the Navigator's memory space. Necessary so that
330 saved instance data may be freed by Navigator when exiting.
334 void* NPN_MemAlloc(uint32 size)
336 return g_pNavigatorFuncs->memalloc(size);
339 /* reciprocal of MemAlloc() above
341 void NPN_MemFree(void* ptr)
343 g_pNavigatorFuncs->memfree(ptr);
346 /* private function to Netscape. do not use!
348 void NPN_ReloadPlugins(NPBool reloadPages)
350 g_pNavigatorFuncs->reloadplugins(reloadPages);
353 JRIEnv* NPN_GetJavaEnv(void)
355 return g_pNavigatorFuncs->getJavaEnv();
358 jref NPN_GetJavaPeer(NPP instance)
360 return g_pNavigatorFuncs->getJavaPeer(instance);
363 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
365 return g_pNavigatorFuncs->getvalue(instance, variable, result);
368 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
370 return g_pNavigatorFuncs->setvalue(instance, variable, value);
373 void NPN_InvalidateRect(NPP instance, NPRect *rect)
375 g_pNavigatorFuncs->invalidaterect(instance, rect);
378 void NPN_InvalidateRegion(NPP instance, NPRegion region)
380 g_pNavigatorFuncs->invalidateregion(instance, region);
383 void NPN_ForceRedraw(NPP instance)
385 g_pNavigatorFuncs->forceredraw(instance);
388 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
390 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
391 if( navMinorVers >= 14 )
393 return g_pNavigatorFuncs->getstringidentifier(name);
398 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
400 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
401 if( navMinorVers >= 14 )
403 g_pNavigatorFuncs->getstringidentifiers(names, nameCount, identifiers);
407 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
409 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
410 if( navMinorVers >= 14 )
412 return g_pNavigatorFuncs->getintidentifier(intid);
417 bool NPN_IdentifierIsString(NPIdentifier identifier)
419 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
420 if( navMinorVers >= 14 )
422 return g_pNavigatorFuncs->identifierisstring(identifier);
427 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
429 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
430 if( navMinorVers >= 14 )
432 return g_pNavigatorFuncs->utf8fromidentifier(identifier);
437 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
439 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
440 if( navMinorVers >= 14 )
442 return g_pNavigatorFuncs->intfromidentifier(identifier);
447 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
449 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
450 if( navMinorVers >= 14 )
452 return g_pNavigatorFuncs->createobject(instance, aClass);
457 NPObject *NPN_RetainObject(NPObject *npobj)
459 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
460 if( navMinorVers >= 14 )
462 return g_pNavigatorFuncs->retainobject(npobj);
467 void NPN_ReleaseObject(NPObject *npobj)
469 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
470 if( navMinorVers >= 14 )
472 g_pNavigatorFuncs->releaseobject(npobj);
476 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
478 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
479 if( navMinorVers >= 14 )
481 return g_pNavigatorFuncs->invoke(instance, npobj, methodName, args, argCount, result);
486 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
488 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
489 if( navMinorVers >= 14 )
491 return g_pNavigatorFuncs->invokeDefault(instance, npobj, args, argCount, result);
496 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
498 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
499 if( navMinorVers >= 14 )
501 return g_pNavigatorFuncs->evaluate(instance, npobj, script, result);
506 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
508 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
509 if( navMinorVers >= 14 )
511 return g_pNavigatorFuncs->getproperty(instance, npobj, propertyName, result);
516 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
518 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
519 if( navMinorVers >= 14 )
521 return g_pNavigatorFuncs->setproperty(instance, npobj, propertyName, value);
526 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
528 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
529 if( navMinorVers >= 14 )
531 return g_pNavigatorFuncs->removeproperty(instance, npobj, propertyName);
536 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
538 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
539 if( navMinorVers >= 14 )
541 return g_pNavigatorFuncs->hasproperty(instance, npobj, propertyName);
546 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
548 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
549 if( navMinorVers >= 14 )
551 return g_pNavigatorFuncs->hasmethod(instance, npobj, methodName);
556 void NPN_ReleaseVariantValue(NPVariant *variant)
558 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
559 if( navMinorVers >= 14 )
561 g_pNavigatorFuncs->releasevariantvalue(variant);
565 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
567 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
568 if( navMinorVers >= 14 )
570 g_pNavigatorFuncs->setexception(npobj, message);