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>
52 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
53 JRIGlobalRef Private_GetJavaClass(void);
55 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
56 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
57 // Private_GetJavaClass (global function)
59 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
60 // of this class existence
63 Private_GetJavaClass(void)
65 jref clazz = NPP_GetJavaClass();
67 JRIEnv* env = NPN_GetJavaEnv();
68 return JRI_NewGlobalRef(env, clazz);
73 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
74 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
75 // PLUGIN DLL entry points
77 // These are the Windows specific DLL entry points. They must be exoprted
80 // we need these to be global since we have to fill one of its field
81 // with a data (class) which requires knowlwdge of the navigator
82 // jump-table. This jump table is known at Initialize time (NP_Initialize)
83 // which is called after NP_GetEntryPoint
84 static NPPluginFuncs* g_pluginFuncs;
86 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
87 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
90 // fills in the func table used by Navigator to call entry points in
91 // plugin DLL. Note that these entry points ensure that DS is loaded
92 // by using the NP_LOADDS macro, when compiling for Win16
95 extern "C" __declspec(dllexport) NPError WINAPI
97 NPError WINAPI NP_EXPORT
99 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
103 return NPERR_INVALID_FUNCTABLE_ERROR;
105 // if the plugin's function table is smaller than the plugin expects,
106 // then they are incompatible, and should return an error
108 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
109 pFuncs->newp = NPP_New;
110 pFuncs->destroy = NPP_Destroy;
111 pFuncs->setwindow = NPP_SetWindow;
112 pFuncs->newstream = NPP_NewStream;
113 pFuncs->destroystream = NPP_DestroyStream;
114 pFuncs->asfile = NPP_StreamAsFile;
115 pFuncs->writeready = NPP_WriteReady;
116 pFuncs->write = NPP_Write;
117 pFuncs->print = NPP_Print;
118 pFuncs->event = 0; /// reserved
119 pFuncs->getvalue = NPP_GetValue;
120 //pFuncs->setvalue = NPP_SetValue;
122 g_pluginFuncs = pFuncs;
124 return NPERR_NO_ERROR;
127 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
128 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
131 // called immediately after the plugin DLL is loaded
134 extern "C" __declspec(dllexport) NPError WINAPI
136 NPError WINAPI NP_EXPORT
138 NP_Initialize(NPNetscapeFuncs* pFuncs)
142 return NPERR_INVALID_FUNCTABLE_ERROR;
144 g_pNavigatorFuncs = pFuncs; // save it for future reference
146 // if the plugin's major ver level is lower than the Navigator's,
147 // then they are incompatible, and should return an error
148 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
149 return NPERR_INCOMPATIBLE_VERSION_ERROR;
151 // We have to defer these assignments until g_pNavigatorFuncs is set
152 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
154 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
155 g_pluginFuncs->urlnotify = NPP_URLNotify;
158 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
159 g_pluginFuncs->javaClass = Private_GetJavaClass();
162 // NPP_Initialize is a standard (cross-platform) initialize function.
163 return NPP_Initialize();
166 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
167 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
170 // called immediately before the plugin DLL is unloaded.
171 // This functio shuold check for some ref count on the dll to see if it is
172 // unloadable or it needs to stay in memory.
175 extern "C" __declspec(dllexport) NPError WINAPI
177 NPError WINAPI NP_EXPORT
182 g_pNavigatorFuncs = NULL;
183 return NPERR_NO_ERROR;
186 // END - PLUGIN DLL entry points
187 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
188 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
190 /* NAVIGATOR Entry points */
192 /* These entry points expect to be called from within the plugin. The
193 noteworthy assumption is that DS has already been set to point to the
194 plugin's DLL data segment. Don't call these functions from outside
195 the plugin without ensuring DS is set to the DLLs data segment first,
196 typically using the NP_LOADDS macro
199 /* returns the major/minor version numbers of the Plugin API for the plugin
202 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
204 *plugin_major = NP_VERSION_MAJOR;
205 *plugin_minor = NP_VERSION_MINOR;
206 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
207 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
210 /* causes the specified URL to be fetched and streamed in
212 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
215 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
217 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
218 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
221 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
227 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
229 return g_pNavigatorFuncs->geturl(instance, url, target);
232 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
234 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
236 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
237 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
240 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
246 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
248 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
251 /* Requests that a number of bytes be provided on a stream. Typically
252 this would be used if a stream was in "pull" mode. An optional
253 position can be provided for streams which are seekable.
255 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
257 return g_pNavigatorFuncs->requestread(stream, rangeList);
260 /* Creates a new stream of data from the plug-in to be interpreted
261 by Netscape in the current window.
263 NPError NPN_NewStream(NPP instance, NPMIMEType type,
264 const char* target, NPStream** stream)
266 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
269 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
270 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
273 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
278 /* Provides len bytes of data.
280 int32 NPN_Write(NPP instance, NPStream *stream,
281 int32 len, void *buffer)
283 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
286 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
287 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
295 /* Closes a stream object.
296 reason indicates why the stream was closed.
298 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
300 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
303 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
304 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
307 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
312 /* Provides a text status message in the Netscape client user interface
314 void NPN_Status(NPP instance, const char *message)
316 g_pNavigatorFuncs->status(instance, message);
319 /* returns the user agent string of Navigator, which contains version info
321 const char* NPN_UserAgent(NPP instance)
323 return g_pNavigatorFuncs->uagent(instance);
326 /* allocates memory from the Navigator's memory space. Necessary so that
327 saved instance data may be freed by Navigator when exiting.
331 void* NPN_MemAlloc(uint32 size)
333 return g_pNavigatorFuncs->memalloc(size);
336 /* reciprocal of MemAlloc() above
338 void NPN_MemFree(void* ptr)
340 g_pNavigatorFuncs->memfree(ptr);
343 /* private function to Netscape. do not use!
345 void NPN_ReloadPlugins(NPBool reloadPages)
347 g_pNavigatorFuncs->reloadplugins(reloadPages);
350 JRIEnv* NPN_GetJavaEnv(void)
352 return g_pNavigatorFuncs->getJavaEnv();
355 jref NPN_GetJavaPeer(NPP instance)
357 return g_pNavigatorFuncs->getJavaPeer(instance);
360 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
362 return g_pNavigatorFuncs->getvalue(instance, variable, result);
365 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
367 return g_pNavigatorFuncs->setvalue(instance, variable, value);
370 void NPN_InvalidateRect(NPP instance, NPRect *rect)
372 g_pNavigatorFuncs->invalidaterect(instance, rect);
375 void NPN_InvalidateRegion(NPP instance, NPRegion region)
377 g_pNavigatorFuncs->invalidateregion(instance, region);
380 void NPN_ForceRedraw(NPP instance)
382 g_pNavigatorFuncs->forceredraw(instance);
385 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
387 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
388 if( navMinorVers >= 14 )
390 return g_pNavigatorFuncs->getstringidentifier(name);
395 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
397 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
398 if( navMinorVers >= 14 )
400 g_pNavigatorFuncs->getstringidentifiers(names, nameCount, identifiers);
404 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
406 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
407 if( navMinorVers >= 14 )
409 return g_pNavigatorFuncs->getintidentifier(intid);
414 bool NPN_IdentifierIsString(NPIdentifier identifier)
416 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
417 if( navMinorVers >= 14 )
419 return g_pNavigatorFuncs->identifierisstring(identifier);
424 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
426 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
427 if( navMinorVers >= 14 )
429 return g_pNavigatorFuncs->utf8fromidentifier(identifier);
434 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
436 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
437 if( navMinorVers >= 14 )
439 return g_pNavigatorFuncs->intfromidentifier(identifier);
444 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
446 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
447 if( navMinorVers >= 14 )
449 return g_pNavigatorFuncs->createobject(instance, aClass);
454 NPObject *NPN_RetainObject(NPObject *npobj)
456 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
457 if( navMinorVers >= 14 )
459 return g_pNavigatorFuncs->retainobject(npobj);
464 void NPN_ReleaseObject(NPObject *npobj)
466 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
467 if( navMinorVers >= 14 )
469 g_pNavigatorFuncs->releaseobject(npobj);
473 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
475 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
476 if( navMinorVers >= 14 )
478 return g_pNavigatorFuncs->invoke(instance, npobj, methodName, args, argCount, result);
483 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
485 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
486 if( navMinorVers >= 14 )
488 return g_pNavigatorFuncs->invokeDefault(instance, npobj, args, argCount, result);
493 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
495 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
496 if( navMinorVers >= 14 )
498 return g_pNavigatorFuncs->evaluate(instance, npobj, script, result);
503 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
505 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
506 if( navMinorVers >= 14 )
508 return g_pNavigatorFuncs->getproperty(instance, npobj, propertyName, result);
513 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
515 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
516 if( navMinorVers >= 14 )
518 return g_pNavigatorFuncs->setproperty(instance, npobj, propertyName, value);
523 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
525 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
526 if( navMinorVers >= 14 )
528 return g_pNavigatorFuncs->removeproperty(instance, npobj, propertyName);
533 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
535 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
536 if( navMinorVers >= 14 )
538 return g_pNavigatorFuncs->hasproperty(instance, npobj, propertyName);
543 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
545 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
546 if( navMinorVers >= 14 )
548 return g_pNavigatorFuncs->hasmethod(instance, npobj, methodName);
553 void NPN_ReleaseVariantValue(NPVariant *variant)
555 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
556 if( navMinorVers >= 14 )
558 g_pNavigatorFuncs->releasevariantvalue(variant);
562 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
564 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
565 if( navMinorVers >= 14 )
567 g_pNavigatorFuncs->setexception(npobj, message);