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