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