]> git.sesse.net Git - vlc/blob - projects/mozilla/support/npunix.c
Mozilla plugin event listeners.
[vlc] / projects / mozilla / support / npunix.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * Mozilla/Firefox plugin for VLC
4  * Copyright (C) 2009, Jean-Paul Saman <jpsaman@videolan.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * The Original Code is mozilla.org code.
21  *
22  * The Initial Developer of the Original Code is
23  * Netscape Communications Corporation.
24  * Portions created by the Initial Developer are Copyright (C) 1998
25  * the Initial Developer. All Rights Reserved.
26  *
27  * Contributor(s):
28  *   Stephen Mak <smak@sun.com>
29  *
30  */
31
32 /*
33  * npunix.c
34  *
35  * Netscape Client Plugin API
36  * - Wrapper function to interface with the Netscape Navigator
37  *
38  * dp Suresh <dp@netscape.com>
39  *
40  *----------------------------------------------------------------------
41  * PLUGIN DEVELOPERS:
42  *  YOU WILL NOT NEED TO EDIT THIS FILE.
43  *----------------------------------------------------------------------
44  */
45
46 #include "config.h"
47
48 #define XP_UNIX 1
49 #define OJI 1
50
51 #include <npapi.h>
52 #ifdef HAVE_NPFUNCTIONS_H
53 #include <npfunctions.h>
54 #else
55 #include <npupp.h>
56 #endif
57
58 #include "../vlcshell.h"
59
60 /*
61  * Define PLUGIN_TRACE to have the wrapper functions print
62  * messages to stderr whenever they are called.
63  */
64
65 #ifdef PLUGIN_TRACE
66 #include <stdio.h>
67 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
68 #else
69 #define PLUGINDEBUGSTR(msg)
70 #endif
71
72 /***********************************************************************
73  *
74  * Globals
75  *
76  ***********************************************************************/
77
78 static NPNetscapeFuncs   gNetscapeFuncs;    /* Netscape Function table */
79
80 /***********************************************************************
81  *
82  * Wrapper functions : plugin calling Netscape Navigator
83  *
84  * These functions let the plugin developer just call the APIs
85  * as documented and defined in npapi.h, without needing to know
86  * about the function table and call macros in npupp.h.
87  *
88  ***********************************************************************/
89
90 void
91 NPN_Version(int* plugin_major, int* plugin_minor,
92          int* netscape_major, int* netscape_minor)
93 {
94     *plugin_major = NP_VERSION_MAJOR;
95     *plugin_minor = NP_VERSION_MINOR;
96
97     /* Major version is in high byte */
98     *netscape_major = gNetscapeFuncs.version >> 8;
99     /* Minor version is in low byte */
100     *netscape_minor = gNetscapeFuncs.version & 0xFF;
101 }
102
103 void
104 NPN_PluginThreadAsyncCall(NPP plugin,
105                           void (*func)(void *),
106                           void *userData)
107 {
108 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
109     return (*gNetscapeFuncs.pluginthreadasynccall)(plugin, func, userData);
110 #endif
111 }
112
113 NPError
114 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
115 {
116 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
117     return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
118                     instance, variable, r_value);
119 #else
120     return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
121 #endif
122 }
123
124 NPError
125 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
126 {
127 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
128     return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
129                     instance, variable, value);
130 #else
131     return (*gNetscapeFuncs.setvalue)(instance, variable, value);
132 #endif
133 }
134
135 NPError
136 NPN_GetURL(NPP instance, const char* url, const char* window)
137 {
138 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
139     return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
140 #else
141     return (*gNetscapeFuncs.geturl)(instance, url, window);
142 #endif
143 }
144
145 NPError
146 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
147 {
148 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
149     return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
150 #else
151     return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
152 #endif
153 }
154
155 NPError
156 NPN_PostURL(NPP instance, const char* url, const char* window,
157          uint32_t len, const char* buf, NPBool file)
158 {
159 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
160     return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
161                     url, window, len, buf, file);
162 #else
163     return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
164 #endif
165 }
166
167 NPError
168 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
169                   const char* buf, NPBool file, void* notifyData)
170 {
171 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
172     return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
173             instance, url, window, len, buf, file, notifyData);
174 #else
175     return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);
176
177 #endif
178 }
179
180 NPError
181 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
182 {
183 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
184     return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
185                     stream, rangeList);
186 #else
187     return (*gNetscapeFuncs.requestread)(stream, rangeList);
188 #endif
189 }
190
191 NPError
192 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
193           NPStream** stream_ptr)
194 {
195 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
196     return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
197                     type, window, stream_ptr);
198 #else
199     return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
200 #endif
201 }
202
203 int32_t
204 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
205 {
206 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
207     return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
208                     stream, len, buffer);
209 #else
210     return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
211 #endif
212 }
213
214 NPError
215 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
216 {
217 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
218     return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
219                         instance, stream, reason);
220 #else
221     return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
222 #endif
223 }
224
225 void
226 NPN_Status(NPP instance, const char* message)
227 {
228 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
229     CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
230 #else
231     (*gNetscapeFuncs.status)(instance, message);
232 #endif
233 }
234
235 const char*
236 NPN_UserAgent(NPP instance)
237 {
238 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
239     return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
240 #else
241     return (*gNetscapeFuncs.uagent)(instance);
242 #endif
243 }
244
245 void *NPN_MemAlloc(uint32_t size)
246 {
247 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
248     return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
249 #else
250     return (*gNetscapeFuncs.memalloc)(size);
251 #endif
252 }
253
254 void NPN_MemFree(void* ptr)
255 {
256 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
257     CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
258 #else
259     (*gNetscapeFuncs.memfree)(ptr);
260 #endif
261 }
262
263 uint32_t NPN_MemFlush(uint32_t size)
264 {
265 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
266     return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
267 #else
268     return (*gNetscapeFuncs.memflush)(size);
269 #endif
270 }
271
272 void NPN_ReloadPlugins(NPBool reloadPages)
273 {
274 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
275     CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
276 #else
277     (*gNetscapeFuncs.reloadplugins)(reloadPages);
278 #endif
279 }
280
281 #ifdef OJI
282 JRIEnv* NPN_GetJavaEnv()
283 {
284 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
285     return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
286 #else
287     return (*gNetscapeFuncs.getJavaEnv);
288 #endif
289 }
290
291 jref NPN_GetJavaPeer(NPP instance)
292 {
293 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
294     return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
295                        instance);
296 #else
297     return (*gNetscapeFuncs.getJavaPeer)(instance);
298 #endif
299 }
300 #endif
301
302 void
303 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
304 {
305 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
306     CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
307         invalidRect);
308 #else
309     (*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
310 #endif
311 }
312
313 void
314 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
315 {
316 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
317     CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
318         invalidRegion);
319 #else
320     (*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
321 #endif
322 }
323
324 void
325 NPN_ForceRedraw(NPP instance)
326 {
327 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
328     CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
329 #else
330     (*gNetscapeFuncs.forceredraw)(instance);
331 #endif
332 }
333
334 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
335 {
336 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
337     CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
338         instance, enabled);
339 #else
340     (*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
341 #endif
342 }
343
344 void NPN_PopPopupsEnabledState(NPP instance)
345 {
346 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
347     CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
348         instance);
349 #else
350     (*gNetscapeFuncs.poppopupsenabledstate)(instance);
351 #endif
352 }
353
354 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
355 {
356     int minor = gNetscapeFuncs.version & 0xFF;
357     if( minor >= 14 )
358     {
359 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
360         return CallNPN_GetStringIdentifierProc(
361                         gNetscapeFuncs.getstringidentifier, name);
362 #else
363         return (*gNetscapeFuncs.getstringidentifier)(name);
364 #endif
365     }
366     return NULL;
367 }
368
369 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
370                               NPIdentifier *identifiers)
371 {
372     int minor = gNetscapeFuncs.version & 0xFF;
373     if( minor >= 14 )
374     {
375 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
376         CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
377                                          names, nameCount, identifiers);
378 #else
379         (*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
380 #endif
381     }
382 }
383
384 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
385 {
386     int minor = gNetscapeFuncs.version & 0xFF;
387     if( minor >= 14 )
388     {
389 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
390         return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
391 #else
392         return (*gNetscapeFuncs.getintidentifier)(intid);
393 #endif
394     }
395     return NULL;
396 }
397
398 bool NPN_IdentifierIsString(NPIdentifier identifier)
399 {
400     int minor = gNetscapeFuncs.version & 0xFF;
401     if( minor >= 14 )
402     {
403 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
404         return CallNPN_IdentifierIsStringProc(
405                         gNetscapeFuncs.identifierisstring,
406                         identifier);
407 #else
408         return (*gNetscapeFuncs.identifierisstring)(identifier);
409 #endif
410     }
411     return false;
412 }
413
414 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
415 {
416     int minor = gNetscapeFuncs.version & 0xFF;
417     if( minor >= 14 )
418     {
419 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
420         return CallNPN_UTF8FromIdentifierProc(
421                             gNetscapeFuncs.utf8fromidentifier,
422                             identifier);
423 #else
424         return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
425 #endif
426     }
427     return NULL;
428 }
429
430 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
431 {
432     int minor = gNetscapeFuncs.version & 0xFF;
433     if( minor >= 14 )
434     {
435 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
436         return CallNPN_IntFromIdentifierProc(
437                         gNetscapeFuncs.intfromidentifier,
438                         identifier);
439 #else
440         return (*gNetscapeFuncs.intfromidentifier)(identifier);
441 #endif
442     }
443     return 0;
444 }
445
446 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
447 {
448     int minor = gNetscapeFuncs.version & 0xFF;
449     if( minor >= 14 )
450 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
451         return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
452 #else
453         return (*gNetscapeFuncs.createobject)(npp, aClass);
454 #endif
455     return NULL;
456 }
457
458 NPObject *NPN_RetainObject(NPObject *obj)
459 {
460     int minor = gNetscapeFuncs.version & 0xFF;
461     if( minor >= 14 )
462 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
463         return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
464 #else
465         return (*gNetscapeFuncs.retainobject)(obj);
466 #endif
467     return NULL;
468 }
469
470 void NPN_ReleaseObject(NPObject *obj)
471 {
472     int minor = gNetscapeFuncs.version & 0xFF;
473     if( minor >= 14 )
474 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
475         CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
476 #else
477         (*gNetscapeFuncs.releaseobject)(obj);
478 #endif
479 }
480
481 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
482                 const NPVariant *args, uint32_t argCount, NPVariant *result)
483 {
484     int minor = gNetscapeFuncs.version & 0xFF;
485     if( minor >= 14 )
486 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
487         return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
488                                   args, argCount, result);
489 #else
490         return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
491 #endif
492     return false;
493 }
494
495 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
496                        uint32_t argCount, NPVariant *result)
497 {
498     int minor = gNetscapeFuncs.version & 0xFF;
499     if( minor >= 14 )
500 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
501         return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
502                                          args, argCount, result);
503 #else
504         return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
505 #endif
506     return false;
507 }
508
509 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
510                   NPVariant *result)
511 {
512     int minor = gNetscapeFuncs.version & 0xFF;
513     if( minor >= 14 )
514 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
515         return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
516                                     script, result);
517 #else
518         return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
519 #endif
520     return false;
521 }
522
523 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
524                      NPVariant *result)
525 {
526     int minor = gNetscapeFuncs.version & 0xFF;
527     if( minor >= 14 )
528 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
529         return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
530                                        propertyName, result);
531 #else
532         return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
533 #endif
534     return false;
535 }
536
537 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
538                      const NPVariant *value)
539 {
540     int minor = gNetscapeFuncs.version & 0xFF;
541     if( minor >= 14 )
542 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
543         return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
544                                        propertyName, value);
545 #else
546         return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
547 #endif
548     return false;
549 }
550
551 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
552 {
553     int minor = gNetscapeFuncs.version & 0xFF;
554     if( minor >= 14 )
555 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
556         return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
557                                           propertyName);
558 #else
559         return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
560 #endif
561     return false;
562 }
563
564 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
565 {
566     int minor = gNetscapeFuncs.version & 0xFF;
567     if( minor >= 14 )
568 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
569         return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
570                                        propertyName);
571 #else
572         return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
573 #endif
574     return false;
575 }
576
577 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
578 {
579     int minor = gNetscapeFuncs.version & 0xFF;
580     if( minor >= 14 )
581 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
582         return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
583                                      obj, methodName);
584 #else
585         return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
586 #endif
587     return false;
588 }
589
590 void NPN_ReleaseVariantValue(NPVariant *variant)
591 {
592     int minor = gNetscapeFuncs.version & 0xFF;
593     if( minor >= 14 )
594 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
595         CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
596 #else
597         (*gNetscapeFuncs.releasevariantvalue)(variant);
598 #endif
599 }
600
601 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
602 {
603     int minor = gNetscapeFuncs.version & 0xFF;
604     if( minor >= 14 )
605 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
606         CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
607 #else
608         (*gNetscapeFuncs.setexception)(obj, message);
609 #endif
610 }
611
612 /***********************************************************************
613  *
614  * Wrapper functions : Netscape Navigator -> plugin
615  *
616  * These functions let the plugin developer just create the APIs
617  * as documented and defined in npapi.h, without needing to 
618  * install those functions in the function table or worry about
619  * setting up globals for 68K plugins.
620  *
621  ***********************************************************************/
622
623 /* Function prototypes */
624 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
625         int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
626 NPError Private_Destroy(NPP instance, NPSavedData** save);
627 NPError Private_SetWindow(NPP instance, NPWindow* window);
628 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
629                           NPBool seekable, uint16_t* stype);
630 int32_t Private_WriteReady(NPP instance, NPStream* stream);
631 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
632                     int32_t len, void* buffer);
633 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
634 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
635 void Private_URLNotify(NPP instance, const char* url,
636                        NPReason reason, void* notifyData);
637 void Private_Print(NPP instance, NPPrint* platformPrint);
638 NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
639 NPError Private_SetValue(NPP instance, NPPVariable variable, void *r_value);
640 #ifdef OJI
641 JRIGlobalRef Private_GetJavaClass(void);
642 #endif
643
644 /* function implementations */
645 NPError
646 Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
647         int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
648 {
649     NPError ret;
650     PLUGINDEBUGSTR("New");
651     ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
652     return ret; 
653 }
654
655 NPError
656 Private_Destroy(NPP instance, NPSavedData** save)
657 {
658     PLUGINDEBUGSTR("Destroy");
659     return NPP_Destroy(instance, save);
660 }
661
662 NPError
663 Private_SetWindow(NPP instance, NPWindow* window)
664 {
665     NPError err;
666     PLUGINDEBUGSTR("SetWindow");
667     err = NPP_SetWindow(instance, window);
668     return err;
669 }
670
671 NPError
672 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
673             NPBool seekable, uint16_t* stype)
674 {
675     NPError err;
676     PLUGINDEBUGSTR("NewStream");
677     err = NPP_NewStream(instance, type, stream, seekable, stype);
678     return err;
679 }
680
681 int32_t
682 Private_WriteReady(NPP instance, NPStream* stream)
683 {
684     unsigned int result;
685     PLUGINDEBUGSTR("WriteReady");
686     result = NPP_WriteReady(instance, stream);
687     return result;
688 }
689
690 int32_t
691 Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
692         void* buffer)
693 {
694     unsigned int result;
695     PLUGINDEBUGSTR("Write");
696     result = NPP_Write(instance, stream, offset, len, buffer);
697     return result;
698 }
699
700 void
701 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
702 {
703     PLUGINDEBUGSTR("StreamAsFile");
704     NPP_StreamAsFile(instance, stream, fname);
705 }
706
707
708 NPError
709 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
710 {
711     NPError err;
712     PLUGINDEBUGSTR("DestroyStream");
713     err = NPP_DestroyStream(instance, stream, reason);
714     return err;
715 }
716
717 void
718 Private_URLNotify(NPP instance, const char* url,
719                 NPReason reason, void* notifyData)
720 {
721     PLUGINDEBUGSTR("URLNotify");
722     NPP_URLNotify(instance, url, reason, notifyData);
723 }
724
725 void
726 Private_Print(NPP instance, NPPrint* platformPrint)
727 {
728     PLUGINDEBUGSTR("Print");
729     NPP_Print(instance, platformPrint);
730 }
731
732 NPError
733 Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
734 {
735     PLUGINDEBUGSTR("GetValue");
736     return NPP_GetValue(instance, variable, r_value);
737 }
738
739 NPError
740 Private_SetValue(NPP instance, NPPVariable variable, void *r_value)
741 {
742     PLUGINDEBUGSTR("SetValue");
743     return NPP_SetValue(instance, variable, r_value);
744 }
745
746 #ifdef OJI
747 JRIGlobalRef
748 Private_GetJavaClass(void)
749 {
750     jref clazz = NPP_GetJavaClass();
751     if (clazz) {
752     JRIEnv* env = NPN_GetJavaEnv();
753     return JRI_NewGlobalRef(env, clazz);
754     }
755     return NULL;
756 }
757 #endif
758
759 /*********************************************************************** 
760  *
761  * These functions are located automagically by netscape.
762  *
763  ***********************************************************************/
764
765 /*
766  * NP_GetMIMEDescription
767  *  - Netscape needs to know about this symbol
768  *  - Netscape uses the return value to identify when an object instance
769  *    of this plugin should be created.
770  */
771 char *
772 NP_GetMIMEDescription(void)
773 {
774     return NPP_GetMIMEDescription();
775 }
776
777 /*
778  * NP_GetValue [optional]
779  *  - Netscape needs to know about this symbol.
780  *  - Interfaces with plugin to get values for predefined variables
781  *    that the navigator needs.
782  */
783 NPError
784 NP_GetValue(void* future, NPPVariable variable, void *value)
785 {
786     return NPP_GetValue(future, variable, value);
787 }
788
789 /*
790  * NP_Initialize
791  *  - Netscape needs to know about this symbol.
792  *  - It calls this function after looking up its symbol before it
793  *    is about to create the first ever object of this kind.
794  *
795  * PARAMETERS
796  *    nsTable   - The netscape function table. If developers just use these
797  *        wrappers, they don't need to worry about all these function
798  *        tables.
799  * RETURN
800  *    pluginFuncs
801  *      - This functions needs to fill the plugin function table
802  *        pluginFuncs and return it. Netscape Navigator plugin
803  *        library will use this function table to call the plugin.
804  *
805  */
806 NPError
807 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
808 {
809     NPError err = NPERR_NO_ERROR;
810
811     PLUGINDEBUGSTR("NP_Initialize");
812
813     /* validate input parameters */
814     if ((nsTable == NULL) || (pluginFuncs == NULL))
815         err = NPERR_INVALID_FUNCTABLE_ERROR;
816
817     /*
818      * Check the major version passed in Netscape's function table.
819      * We won't load if the major version is newer than what we expect.
820      * Also check that the function tables passed in are big enough for
821      * all the functions we need (they could be bigger, if Netscape added
822      * new APIs, but that's OK with us -- we'll just ignore them).
823      *
824      */
825     if (err == NPERR_NO_ERROR) {
826         if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
827             err = NPERR_INCOMPATIBLE_VERSION_ERROR;
828         if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
829             err = NPERR_INVALID_FUNCTABLE_ERROR;
830         if (pluginFuncs->size < sizeof(NPPluginFuncs))
831             err = NPERR_INVALID_FUNCTABLE_ERROR;
832     }
833
834     if (err == NPERR_NO_ERROR)
835     {
836         /*
837          * Copy all the fields of Netscape function table into our
838          * copy so we can call back into Netscape later.  Note that
839          * we need to copy the fields one by one, rather than assigning
840          * the whole structure, because the Netscape function table
841          * could actually be bigger than what we expect.
842          */
843         int minor = nsTable->version & 0xFF;
844
845         gNetscapeFuncs.version       = nsTable->version;
846         gNetscapeFuncs.size          = nsTable->size;
847         gNetscapeFuncs.posturl       = nsTable->posturl;
848         gNetscapeFuncs.geturl        = nsTable->geturl;
849         gNetscapeFuncs.requestread   = nsTable->requestread;
850         gNetscapeFuncs.newstream     = nsTable->newstream;
851         gNetscapeFuncs.write         = nsTable->write;
852         gNetscapeFuncs.destroystream = nsTable->destroystream;
853         gNetscapeFuncs.status        = nsTable->status;
854         gNetscapeFuncs.uagent        = nsTable->uagent;
855         gNetscapeFuncs.memalloc      = nsTable->memalloc;
856         gNetscapeFuncs.memfree       = nsTable->memfree;
857         gNetscapeFuncs.memflush      = nsTable->memflush;
858         gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
859 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
860         gNetscapeFuncs.pluginthreadasynccall =
861             nsTable->pluginthreadasynccall;
862 #endif
863 #ifdef OJI
864         if( minor >= NPVERS_HAS_LIVECONNECT )
865         {
866             gNetscapeFuncs.getJavaEnv    = nsTable->getJavaEnv;
867             gNetscapeFuncs.getJavaPeer   = nsTable->getJavaPeer;
868         }
869 #endif
870         gNetscapeFuncs.getvalue      = nsTable->getvalue;
871         gNetscapeFuncs.setvalue      = nsTable->setvalue;
872
873         if( minor >= NPVERS_HAS_NOTIFICATION )
874         {
875             gNetscapeFuncs.geturlnotify  = nsTable->geturlnotify;
876             gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
877         }
878
879         if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
880         {
881             gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
882             gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
883             gNetscapeFuncs.forceredraw = nsTable->forceredraw;
884             /* npruntime support */
885             if (minor >= 14)
886             {
887                 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
888                 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
889                 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
890                 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
891                 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
892                 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
893                 gNetscapeFuncs.createobject = nsTable->createobject;
894                 gNetscapeFuncs.retainobject = nsTable->retainobject;
895                 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
896                 gNetscapeFuncs.invoke = nsTable->invoke;
897                 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
898                 gNetscapeFuncs.evaluate = nsTable->evaluate;
899                 gNetscapeFuncs.getproperty = nsTable->getproperty;
900                 gNetscapeFuncs.setproperty = nsTable->setproperty;
901                 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
902                 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
903                 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
904                 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
905                 gNetscapeFuncs.setexception = nsTable->setexception;
906             }
907         }
908         else
909         {
910             gNetscapeFuncs.invalidaterect = NULL;
911             gNetscapeFuncs.invalidateregion = NULL;
912             gNetscapeFuncs.forceredraw = NULL;
913             gNetscapeFuncs.getstringidentifier = NULL;
914             gNetscapeFuncs.getstringidentifiers = NULL;
915             gNetscapeFuncs.getintidentifier = NULL;
916             gNetscapeFuncs.identifierisstring = NULL;
917             gNetscapeFuncs.utf8fromidentifier = NULL;
918             gNetscapeFuncs.intfromidentifier = NULL;
919             gNetscapeFuncs.createobject = NULL;
920             gNetscapeFuncs.retainobject = NULL;
921             gNetscapeFuncs.releaseobject = NULL;
922             gNetscapeFuncs.invoke = NULL;
923             gNetscapeFuncs.invokeDefault = NULL;
924             gNetscapeFuncs.evaluate = NULL;
925             gNetscapeFuncs.getproperty = NULL;
926             gNetscapeFuncs.setproperty = NULL;
927             gNetscapeFuncs.removeproperty = NULL;
928             gNetscapeFuncs.hasproperty = NULL;
929             gNetscapeFuncs.releasevariantvalue = NULL;
930             gNetscapeFuncs.setexception = NULL;
931         }
932         if (nsTable->size >=
933             ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
934         {
935             gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
936             gNetscapeFuncs.poppopupsenabledstate  = nsTable->poppopupsenabledstate;
937         }
938         else
939         {
940             gNetscapeFuncs.pushpopupsenabledstate = NULL;
941             gNetscapeFuncs.poppopupsenabledstate  = NULL;
942         }
943
944         /*
945          * Set up the plugin function table that Netscape will use to
946          * call us.  Netscape needs to know about our version and size
947          * and have a UniversalProcPointer for every function we
948          * implement.
949          */
950         pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
951         pluginFuncs->size       = sizeof(NPPluginFuncs);
952 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
953         pluginFuncs->newp       = NewNPP_NewProc(Private_New);
954         pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
955         pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
956         pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
957         pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
958         pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
959         pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
960         pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
961         pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
962         pluginFuncs->getvalue   = NewNPP_GetValueProc(Private_GetValue);
963         pluginFuncs->setvalue   = NewNPP_SetValueProc(Private_SetValue);
964 #else
965         pluginFuncs->newp       = (NPP_NewProcPtr)(Private_New);
966         pluginFuncs->destroy    = (NPP_DestroyProcPtr)(Private_Destroy);
967         pluginFuncs->setwindow  = (NPP_SetWindowProcPtr)(Private_SetWindow);
968         pluginFuncs->newstream  = (NPP_NewStreamProcPtr)(Private_NewStream);
969         pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
970         pluginFuncs->asfile     = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
971         pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
972         pluginFuncs->write      = (NPP_WriteProcPtr)(Private_Write);
973         pluginFuncs->print      = (NPP_PrintProcPtr)(Private_Print);
974         pluginFuncs->getvalue   = (NPP_GetValueProcPtr)(Private_GetValue);
975         pluginFuncs->setvalue   = (NPP_SetValueProcPtr)(Private_SetValue);
976 #endif
977         pluginFuncs->event      = NULL;
978         if( minor >= NPVERS_HAS_NOTIFICATION )
979         {
980 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
981             pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
982 #else
983             pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
984 #endif
985         }
986 #ifdef OJI
987         if( minor >= NPVERS_HAS_LIVECONNECT )
988             pluginFuncs->javaClass  = Private_GetJavaClass();
989         else
990             pluginFuncs->javaClass = NULL;
991 #else
992         pluginFuncs->javaClass = NULL;
993 #endif
994
995         err = NPP_Initialize();
996     }
997
998     return err;
999 }
1000
1001 /*
1002  * NP_Shutdown [optional]
1003  *  - Netscape needs to know about this symbol.
1004  *  - It calls this function after looking up its symbol after
1005  *    the last object of this kind has been destroyed.
1006  *
1007  */
1008 NPError
1009 NP_Shutdown(void)
1010 {
1011     PLUGINDEBUGSTR("NP_Shutdown");
1012     NPP_Shutdown();
1013     return NPERR_NO_ERROR;
1014 }