]> git.sesse.net Git - vlc/blob - projects/mozilla/support/npmac.cpp
mozilla: rewrite and license npunix.c/npwin.cpp under LGPLv2.1 (or later)
[vlc] / projects / mozilla / support / npmac.cpp
1 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 //
3 // npmac.cpp
4 //
5 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
6
7 #include "config.h"
8
9 #include <string.h>
10
11 #include <Processes.h>
12 #include <Gestalt.h>
13 #include <CodeFragments.h>
14 #include <Timer.h>
15 #include <Resources.h>
16 #include <ToolUtils.h>
17
18 #define XP_MACOSX 1
19 #undef TARGET_RT_MAC_CFM
20
21 //
22 // A4Stuff.h contains the definition of EnterCodeResource and
23 // EnterCodeResource, used for setting up the code resource’s
24 // globals for 68K (analagous to the function SetCurrentA5
25 // defined by the toolbox).
26 //
27 // A4Stuff does not exist as of CW 7. Define them to nothing.
28 //
29
30 #if (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) || defined(__GNUC__)
31     #define EnterCodeResource()
32     #define ExitCodeResource()
33 #else
34     #include <A4Stuff.h>
35 #endif
36
37 #include "npapi.h"
38
39 //
40 // The Mixed Mode procInfos defined in npupp.h assume Think C-
41 // style calling conventions.  These conventions are used by
42 // Metrowerks with the exception of pointer return types, which
43 // in Metrowerks 68K are returned in A0, instead of the standard
44 // D0. Thus, since NPN_MemAlloc and NPN_UserAgent return pointers,
45 // Mixed Mode will return the values to a 68K plugin in D0, but
46 // a 68K plugin compiled by Metrowerks will expect the result in
47 // A0.  The following pragma forces Metrowerks to use D0 instead.
48 //
49 #ifdef __MWERKS__
50 #ifndef powerc
51 #pragma pointers_in_D0
52 #endif
53 #endif
54
55 #ifdef XP_UNIX
56 #undef XP_UNIX
57 #endif
58
59 #ifdef HAVE_NPFUNCTIONS_H
60 #include "npfunctions.h"
61 #else
62 #include "npupp.h"
63 #endif
64
65 #include "../vlcshell.h"
66
67 #ifdef __MWERKS__
68 #ifndef powerc
69 #pragma pointers_in_A0
70 #endif
71 #endif
72
73 // The following fix for static initializers (which fixes a previous
74 // incompatibility with some parts of PowerPlant, was submitted by
75 // Jan Ulbrich.
76 #ifdef __MWERKS__
77     #ifdef __cplusplus
78     extern "C" {
79     #endif
80         #ifndef powerc
81             extern void __InitCode__(void);
82         #else
83             extern void __sinit(void);
84             #define __InitCode__ __sinit
85         #endif
86         extern void __destroy_global_chain(void);
87     #ifdef __cplusplus
88     }
89     #endif // __cplusplus
90 #endif // __MWERKS__
91
92 //
93 // Define PLUGIN_TRACE to 1 to have the wrapper functions emit
94 // DebugStr messages whenever they are called.
95 //
96 #define PLUGIN_TRACE 0
97
98 #if PLUGIN_TRACE
99 #define PLUGINDEBUGSTR(msg)     ::DebugStr(msg)
100 #else
101 #define PLUGINDEBUGSTR(msg) {}
102 #endif
103
104 #if defined(XP_MACOSX) && defined(__POWERPC__) && (!defined(TARGET_RT_MAC_CFM))
105
106 // glue for mapping outgoing Macho function pointers to TVectors
107 struct TFPtoTVGlue {
108     void* glue[2];
109 };
110
111 static struct {
112     TFPtoTVGlue     newp;
113     TFPtoTVGlue     destroy;
114     TFPtoTVGlue     setwindow;
115     TFPtoTVGlue     newstream;
116     TFPtoTVGlue     destroystream;
117     TFPtoTVGlue     asfile;
118     TFPtoTVGlue     writeready;
119     TFPtoTVGlue     write;
120     TFPtoTVGlue     print;
121     TFPtoTVGlue     event;
122     TFPtoTVGlue     urlnotify;
123     TFPtoTVGlue     getvalue;
124     TFPtoTVGlue     setvalue;
125
126     TFPtoTVGlue     shutdown;
127 } gPluginFuncsGlueTable;
128
129 static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
130 {
131     functionGlue->glue[0] = fp;
132     functionGlue->glue[1] = 0;
133     return functionGlue;
134 }
135
136 #define PLUGIN_TO_HOST_GLUE(name, fp) (SetupFPtoTVGlue(&gPluginFuncsGlueTable.name, (void*)fp))
137
138 // glue for mapping netscape TVectors to Macho function pointers
139 struct TTVtoFPGlue {
140     uint32 glue[6];
141 };
142
143 static struct {
144     TTVtoFPGlue             geturl;
145     TTVtoFPGlue             posturl;
146     TTVtoFPGlue             requestread;
147     TTVtoFPGlue             newstream;
148     TTVtoFPGlue             write;
149     TTVtoFPGlue             destroystream;
150     TTVtoFPGlue             status;
151     TTVtoFPGlue             uagent;
152     TTVtoFPGlue             memalloc;
153     TTVtoFPGlue             memfree;
154     TTVtoFPGlue             memflush;
155     TTVtoFPGlue             reloadplugins;
156     TTVtoFPGlue             getJavaEnv;
157     TTVtoFPGlue             getJavaPeer;
158     TTVtoFPGlue             geturlnotify;
159     TTVtoFPGlue             posturlnotify;
160     TTVtoFPGlue             getvalue;
161     TTVtoFPGlue             setvalue;
162     TTVtoFPGlue             invalidaterect;
163     TTVtoFPGlue             invalidateregion;
164     TTVtoFPGlue             forceredraw;
165     // NPRuntime support
166     TTVtoFPGlue             getstringidentifier;
167     TTVtoFPGlue             getstringidentifiers;
168     TTVtoFPGlue             getintidentifier;
169     TTVtoFPGlue             identifierisstring;
170     TTVtoFPGlue             utf8fromidentifier;
171     TTVtoFPGlue             intfromidentifier;
172     TTVtoFPGlue             createobject;
173     TTVtoFPGlue             retainobject;
174     TTVtoFPGlue             releaseobject;
175     TTVtoFPGlue             invoke;
176     TTVtoFPGlue             invokeDefault;
177     TTVtoFPGlue             evaluate;
178     TTVtoFPGlue             getproperty;
179     TTVtoFPGlue             setproperty;
180     TTVtoFPGlue             removeproperty;
181     TTVtoFPGlue             hasproperty;
182     TTVtoFPGlue             hasmethod;
183     TTVtoFPGlue             releasevariantvalue;
184     TTVtoFPGlue             setexception;
185 } gNetscapeFuncsGlueTable;
186
187 static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
188 {
189     static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
190
191     memcpy(functionGlue, &glueTemplate, sizeof(TTVtoFPGlue));
192     functionGlue->glue[0] |= ((UInt32)tvp >> 16);
193     functionGlue->glue[1] |= ((UInt32)tvp & 0xFFFF);
194     ::MakeDataExecutable(functionGlue, sizeof(TTVtoFPGlue));
195     return functionGlue;
196 }
197
198 #define HOST_TO_PLUGIN_GLUE(name, fp) (SetupTVtoFPGlue(&gNetscapeFuncsGlueTable.name, (void*)fp))
199
200 #else
201
202 #define PLUGIN_TO_HOST_GLUE(name, fp) (fp)
203 #define HOST_TO_PLUGIN_GLUE(name, fp) (fp)
204
205 #endif /* XP_MACOSX */
206
207
208 #pragma mark -
209
210
211 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
212 //
213 // Globals
214 //
215 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
216
217 #if !TARGET_API_MAC_CARBON
218 QDGlobals*      gQDPtr;             // Pointer to Netscape’s QuickDraw globals
219 #endif
220 short           gResFile;           // Refnum of the plugin’s resource file
221 NPNetscapeFuncs    gNetscapeFuncs;      // Function table for procs in Netscape called by plugin
222
223 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
224 //
225 // Wrapper functions for all calls from the plugin to Netscape.
226 // These functions let the plugin developer just call the APIs
227 // as documented and defined in npapi.h, without needing to know
228 // about the function table and call macros in npupp.h.
229 //
230 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
231
232
233 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
234 {
235     *plugin_major = NP_VERSION_MAJOR;
236     *plugin_minor = NP_VERSION_MINOR;
237     *netscape_major = gNetscapeFuncs.version >> 8;      // Major version is in high byte
238     *netscape_minor = gNetscapeFuncs.version & 0xFF;    // Minor version is in low byte
239 }
240
241 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
242 {
243     int navMinorVers = gNetscapeFuncs.version & 0xFF;
244     NPError err;
245
246     if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
247     {
248         err = CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
249     }
250     else
251     {
252         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
253     }
254     return err;
255 }
256
257 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
258 {
259     return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
260 }
261
262 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
263 {
264     int navMinorVers = gNetscapeFuncs.version & 0xFF;
265     NPError err;
266
267     if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
268     {
269         err = CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify, instance, url,
270                                                         window, len, buf, file, notifyData);
271     }
272     else
273     {
274         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
275     }
276     return err;
277 }
278
279 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
280 {
281     return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, url, window, len, buf, file);
282 }
283
284 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
285 {
286     return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, stream, rangeList);
287 }
288
289 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream)
290 {
291     int navMinorVers = gNetscapeFuncs.version & 0xFF;
292     NPError err;
293
294     if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
295     {
296         err = CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, type, window, stream);
297     }
298     else
299     {
300         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
301     }
302     return err;
303 }
304
305 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
306 {
307     int navMinorVers = gNetscapeFuncs.version & 0xFF;
308     NPError err;
309
310     if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
311     {
312         err = CallNPN_WriteProc(gNetscapeFuncs.write, instance, stream, len, buffer);
313     }
314     else
315     {
316         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
317     }
318     return err;
319 }
320
321 NPError    NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
322 {
323     int navMinorVers = gNetscapeFuncs.version & 0xFF;
324     NPError err;
325
326     if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
327     {
328         err = CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, instance, stream, reason);
329     }
330     else
331     {
332         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
333     }
334     return err;
335 }
336
337 void NPN_Status(NPP instance, const char* message)
338 {
339     CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
340 }
341
342 const char* NPN_UserAgent(NPP instance)
343 {
344     return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
345 }
346
347 void* NPN_MemAlloc(uint32 size)
348 {
349     return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
350 }
351
352 void NPN_MemFree(void* ptr)
353 {
354     CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
355 }
356
357 uint32 NPN_MemFlush(uint32 size)
358 {
359     return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
360 }
361
362 void NPN_ReloadPlugins(NPBool reloadPages)
363 {
364     CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
365 }
366
367 #ifdef OJI
368 JRIEnv* NPN_GetJavaEnv(void)
369 {
370     return CallNPN_GetJavaEnvProc( gNetscapeFuncs.getJavaEnv );
371 }
372
373 jobject  NPN_GetJavaPeer(NPP instance)
374 {
375     return CallNPN_GetJavaPeerProc( gNetscapeFuncs.getJavaPeer, instance );
376 }
377 #endif
378
379 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
380 {
381     return CallNPN_GetValueProc( gNetscapeFuncs.getvalue, instance, variable, value);
382 }
383
384 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
385 {
386     return CallNPN_SetValueProc( gNetscapeFuncs.setvalue, instance, variable, value);
387 }
388
389 void NPN_InvalidateRect(NPP instance, NPRect *rect)
390 {
391     CallNPN_InvalidateRectProc( gNetscapeFuncs.invalidaterect, instance, rect);
392 }
393
394 void NPN_InvalidateRegion(NPP instance, NPRegion region)
395 {
396     CallNPN_InvalidateRegionProc( gNetscapeFuncs.invalidateregion, instance, region);
397 }
398
399 void NPN_ForceRedraw(NPP instance)
400 {
401     CallNPN_ForceRedrawProc( gNetscapeFuncs.forceredraw, instance);
402 }
403
404 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
405 {
406     int navMinorVers = gNetscapeFuncs.version & 0xFF;
407     if( navMinorVers >= 14 )
408     {
409         return CallNPN_GetStringIdentifierProc( gNetscapeFuncs.getstringidentifier, name);
410     }
411     return NULL;
412 }
413
414 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
415 {
416     int navMinorVers = gNetscapeFuncs.version & 0xFF;
417     if( navMinorVers >= 14 )
418     {
419         CallNPN_GetStringIdentifiersProc( gNetscapeFuncs.getstringidentifiers, names, nameCount, identifiers);
420     }
421 }
422
423 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
424 {
425     int navMinorVers = gNetscapeFuncs.version & 0xFF;
426     if( navMinorVers >= 14 )
427     {
428         return CallNPN_GetIntIdentifierProc( gNetscapeFuncs.getintidentifier, intid);
429     }
430     return NULL;
431 }
432
433 bool NPN_IdentifierIsString(NPIdentifier identifier)
434 {
435     int navMinorVers = gNetscapeFuncs.version & 0xFF;
436     if( navMinorVers >= 14 )
437     {
438         return CallNPN_IdentifierIsStringProc( gNetscapeFuncs.identifierisstring, identifier);
439     }
440     return false;
441 }
442
443 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
444 {
445     int navMinorVers = gNetscapeFuncs.version & 0xFF;
446     if( navMinorVers >= 14 )
447     {
448         return CallNPN_UTF8FromIdentifierProc( gNetscapeFuncs.utf8fromidentifier, identifier);
449     }
450     return NULL;
451 }
452
453 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
454 {
455     int navMinorVers = gNetscapeFuncs.version & 0xFF;
456     if( navMinorVers >= 14 )
457     {
458         return CallNPN_IntFromIdentifierProc( gNetscapeFuncs.intfromidentifier, identifier);
459     }
460     return 0;
461 }
462
463 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
464 {
465     int navMinorVers = gNetscapeFuncs.version & 0xFF;
466     if( navMinorVers >= 14 )
467     {
468         return CallNPN_CreateObjectProc( gNetscapeFuncs.createobject, instance, aClass);
469     }
470     return NULL;
471 }
472
473 NPObject *NPN_RetainObject(NPObject *npobj)
474 {
475     int navMinorVers = gNetscapeFuncs.version & 0xFF;
476     if( navMinorVers >= 14 )
477     {
478         return CallNPN_RetainObjectProc( gNetscapeFuncs.retainobject, npobj);
479     }
480     return NULL;
481 }
482
483 void NPN_ReleaseObject(NPObject *npobj)
484 {
485     int navMinorVers = gNetscapeFuncs.version & 0xFF;
486     if( navMinorVers >= 14 )
487     {
488         CallNPN_ReleaseObjectProc( gNetscapeFuncs.releaseobject, npobj);
489     }
490 }
491
492 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
493 {
494     int navMinorVers = gNetscapeFuncs.version & 0xFF;
495     if( navMinorVers >= 14 )
496     {
497         return CallNPN_InvokeProc( gNetscapeFuncs.invoke, instance, npobj, methodName, args, argCount, result);
498     }
499     return false;
500 }
501
502 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
503 {
504     int navMinorVers = gNetscapeFuncs.version & 0xFF;
505     if( navMinorVers >= 14 )
506     {
507         return CallNPN_InvokeDefaultProc( gNetscapeFuncs.invokeDefault, instance, npobj, args, argCount, result);
508     }
509     return false;
510 }
511
512 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
513 {
514     int navMinorVers = gNetscapeFuncs.version & 0xFF;
515     if( navMinorVers >= 14 )
516     {
517         return CallNPN_EvaluateProc( gNetscapeFuncs.evaluate, instance, npobj, script, result);
518     }
519     return false;
520 }
521
522 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
523 {
524     int navMinorVers = gNetscapeFuncs.version & 0xFF;
525     if( navMinorVers >= 14 )
526     {
527         return CallNPN_GetPropertyProc( gNetscapeFuncs.getproperty, instance, npobj, propertyName, result);
528     }
529     return false;
530 }
531
532 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
533 {
534     int navMinorVers = gNetscapeFuncs.version & 0xFF;
535     if( navMinorVers >= 14 )
536     {
537         return CallNPN_SetPropertyProc( gNetscapeFuncs.setproperty, instance, npobj, propertyName, value);
538     }
539     return false;
540 }
541
542 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
543 {
544     int navMinorVers = gNetscapeFuncs.version & 0xFF;
545     if( navMinorVers >= 14 )
546     {
547         return CallNPN_RemovePropertyProc( gNetscapeFuncs.removeproperty, instance, npobj, propertyName);
548     }
549     return false;
550 }
551
552 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
553 {
554     int navMinorVers = gNetscapeFuncs.version & 0xFF;
555     if( navMinorVers >= 14 )
556     {
557         return CallNPN_HasPropertyProc( gNetscapeFuncs.hasproperty, instance, npobj, propertyName);
558     }
559     return false;
560 }
561
562 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
563 {
564     int navMinorVers = gNetscapeFuncs.version & 0xFF;
565     if( navMinorVers >= 14 )
566     {
567         return CallNPN_HasMethodProc( gNetscapeFuncs.hasmethod, instance, npobj, methodName);
568     }
569     return false;
570 }
571
572 void NPN_ReleaseVariantValue(NPVariant *variant)
573 {
574     int navMinorVers = gNetscapeFuncs.version & 0xFF;
575     if( navMinorVers >= 14 )
576     {
577         CallNPN_ReleaseVariantValueProc( gNetscapeFuncs.releasevariantvalue, variant);
578     }
579 }
580
581 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
582 {
583     int navMinorVers = gNetscapeFuncs.version & 0xFF;
584     if( navMinorVers >= 14 )
585     {
586         CallNPN_SetExceptionProc( gNetscapeFuncs.setexception, npobj, message);
587     }
588 }
589
590 #pragma mark -
591
592 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
593 //
594 // Wrapper functions for all calls from Netscape to the plugin.
595 // These functions let the plugin developer just create the APIs
596 // as documented and defined in npapi.h, without needing to
597 // install those functions in the function table or worry about
598 // setting up globals for 68K plugins.
599 //
600 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
601
602 NPError     Private_Initialize(void);
603 void        Private_Shutdown(void);
604 NPError     Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
605 NPError     Private_Destroy(NPP instance, NPSavedData** save);
606 NPError     Private_SetWindow(NPP instance, NPWindow* window);
607 NPError     Private_GetValue( NPP instance, NPPVariable variable, void *value );
608 NPError     Private_SetValue( NPP instance, NPPVariable variable, void *value );
609 NPError     Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
610 NPError     Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
611 int32       Private_WriteReady(NPP instance, NPStream* stream);
612 int32       Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer);
613 void        Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
614 void        Private_Print(NPP instance, NPPrint* platformPrint);
615 int16       Private_HandleEvent(NPP instance, void* event);
616 void        Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData);
617 jobject     Private_GetJavaClass(void);
618
619
620 NPError Private_Initialize(void)
621 {
622     NPError err;
623     EnterCodeResource();
624     PLUGINDEBUGSTR("\pInitialize;g;");
625     err = NPP_Initialize();
626     ExitCodeResource();
627     return err;
628 }
629
630 void Private_Shutdown(void)
631 {
632     EnterCodeResource();
633     PLUGINDEBUGSTR("\pShutdown;g;");
634     NPP_Shutdown();
635
636 #ifdef __MWERKS__
637     __destroy_global_chain();
638 #endif
639
640     ExitCodeResource();
641 }
642
643 NPError    Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
644 {
645     EnterCodeResource();
646     NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
647     PLUGINDEBUGSTR("\pNew;g;");
648     ExitCodeResource();
649     return ret;
650 }
651
652 NPError Private_Destroy(NPP instance, NPSavedData** save)
653 {
654     NPError err;
655     EnterCodeResource();
656     PLUGINDEBUGSTR("\pDestroy;g;");
657     err = NPP_Destroy(instance, save);
658     ExitCodeResource();
659     return err;
660 }
661
662 NPError Private_SetWindow(NPP instance, NPWindow* window)
663 {
664     NPError err;
665     EnterCodeResource();
666     PLUGINDEBUGSTR("\pSetWindow;g;");
667     err = NPP_SetWindow(instance, window);
668     ExitCodeResource();
669     return err;
670 }
671
672 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
673 {
674     NPError err;
675     EnterCodeResource();
676     PLUGINDEBUGSTR("\pGetValue;g;");
677     err = NPP_GetValue(instance, variable, value);
678     ExitCodeResource();
679     return err;
680 }
681
682 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
683 {
684     NPError err;
685     EnterCodeResource();
686     PLUGINDEBUGSTR("\pSetValue;g;");
687     err = NPP_SetValue(instance, variable, value);
688     ExitCodeResource();
689     return err;
690 }
691
692 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
693 {
694     NPError err;
695     EnterCodeResource();
696     PLUGINDEBUGSTR("\pNewStream;g;");
697     err = NPP_NewStream(instance, type, stream, seekable, stype);
698     ExitCodeResource();
699     return err;
700 }
701
702 int32 Private_WriteReady(NPP instance, NPStream* stream)
703 {
704     int32 result;
705     EnterCodeResource();
706     PLUGINDEBUGSTR("\pWriteReady;g;");
707     result = NPP_WriteReady(instance, stream);
708     ExitCodeResource();
709     return result;
710 }
711
712 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
713 {
714     int32 result;
715     EnterCodeResource();
716     PLUGINDEBUGSTR("\pWrite;g;");
717     result = NPP_Write(instance, stream, offset, len, buffer);
718     ExitCodeResource();
719     return result;
720 }
721
722 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
723 {
724     EnterCodeResource();
725     PLUGINDEBUGSTR("\pStreamAsFile;g;");
726     NPP_StreamAsFile(instance, stream, fname);
727     ExitCodeResource();
728 }
729
730 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
731 {
732     NPError err;
733     EnterCodeResource();
734     PLUGINDEBUGSTR("\pDestroyStream;g;");
735     err = NPP_DestroyStream(instance, stream, reason);
736     ExitCodeResource();
737     return err;
738 }
739
740 int16 Private_HandleEvent(NPP instance, void* event)
741 {
742     int16 result;
743     EnterCodeResource();
744     PLUGINDEBUGSTR("\pHandleEvent;g;");
745     result = NPP_HandleEvent(instance, event);
746     ExitCodeResource();
747     return result;
748 }
749
750 void Private_Print(NPP instance, NPPrint* platformPrint)
751 {
752     EnterCodeResource();
753     PLUGINDEBUGSTR("\pPrint;g;");
754     NPP_Print(instance, platformPrint);
755     ExitCodeResource();
756 }
757
758 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
759 {
760     EnterCodeResource();
761     PLUGINDEBUGSTR("\pURLNotify;g;");
762     NPP_URLNotify(instance, url, reason, notifyData);
763     ExitCodeResource();
764 }
765
766 #ifdef OJI
767 jobject Private_GetJavaClass(void)
768 {
769     EnterCodeResource();
770     PLUGINDEBUGSTR("\pGetJavaClass;g;");
771
772     jobject clazz = NPP_GetJavaClass();
773     ExitCodeResource();
774     if (clazz)
775     {
776         JRIEnv* env = NPN_GetJavaEnv();
777         return (jobject)JRI_NewGlobalRef(env, clazz);
778     }
779     return NULL;
780 }
781 #endif
782
783 void SetUpQD(void);
784 void SetUpQD(void)
785 {
786 #if !TARGET_API_MAC_CARBON
787     ProcessSerialNumber PSN;
788     FSSpec              myFSSpec;
789     Str63               name;
790     ProcessInfoRec      infoRec;
791     OSErr               result = noErr;
792     CFragConnectionID   connID;
793     Str255              errName;
794 #endif
795
796     //
797     // Memorize the plugin’s resource file
798     // refnum for later use.
799     //
800     gResFile = CurResFile();
801
802 #if !TARGET_API_MAC_CARBON
803     //
804     // Ask the system if CFM is available.
805     //
806     long response;
807     OSErr err = Gestalt(gestaltCFMAttr, &response);
808     Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
809
810     ProcessInfoRec infoRec;
811     if (hasCFM)
812     {
813         //
814         // GetProcessInformation takes a process serial number and
815         // will give us back the name and FSSpec of the application.
816         // See the Process Manager in IM.
817         //
818         Str63 name;
819         FSSpec myFSSpec;
820         infoRec.processInfoLength = sizeof(ProcessInfoRec);
821         infoRec.processName = name;
822         infoRec.processAppSpec = &myFSSpec;
823
824         ProcessSerialNumber PSN;
825         PSN.highLongOfPSN = 0;
826         PSN.lowLongOfPSN = kCurrentProcess;
827
828         result = GetProcessInformation(&PSN, &infoRec);
829         if (result != noErr)
830             PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
831     }
832     else
833         //
834         // If no CFM installed, assume it must be a 68K app.
835         //
836         result = -1;
837
838     CFragConnectionID connID;
839     if (result == noErr)
840     {
841         //
842         // Now that we know the app name and FSSpec, we can call GetDiskFragment
843         // to get a connID to use in a subsequent call to FindSymbol (it will also
844         // return the address of “main” in app, which we ignore).  If GetDiskFragment
845         // returns an error, we assume the app must be 68K.
846         //
847         Ptr mainAddr;
848         Str255 errName;
849         result =  GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
850                                   kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
851     }
852
853     if (result == noErr)
854     {
855         //
856         // The app is a PPC code fragment, so call FindSymbol
857         // to get the exported “qd” symbol so we can access its
858         // QuickDraw globals.
859         //
860         CFragSymbolClass symClass;
861         result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
862         if (result != noErr) {  // this fails if we are in NS 6
863             gQDPtr = &qd;       // so we default to the standard QD globals
864         }
865     }
866     else
867     {
868         //
869         // The app is 68K, so use its A5 to compute the address
870         // of its QuickDraw globals.
871         //
872         gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
873     }
874 #endif
875 }
876
877
878 #ifdef __GNUC__
879 // gcc requires that main have an 'int' return type
880 int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
881 #else
882 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
883 #endif
884
885 #if !TARGET_API_MAC_CARBON
886 #pragma export on
887
888 #if TARGET_RT_MAC_CFM
889
890 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
891
892 #endif
893
894 #pragma export off
895 #endif /* !TARGET_API_MAC_CARBON */
896
897 #ifdef __GNUC__
898 DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
899 #else
900 DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
901 #endif
902 {
903     EnterCodeResource();
904     PLUGINDEBUGSTR("\pmain");
905
906 #ifdef __MWERKS__
907     __InitCode__();
908 #endif
909
910     NPError err = NPERR_NO_ERROR;
911
912     //
913     // Ensure that everything Netscape passed us is valid!
914     //
915     if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
916         err = NPERR_INVALID_FUNCTABLE_ERROR;
917
918     //
919     // Check the “major” version passed in Netscape’s function table.
920     // We won’t load if the major version is newer than what we expect.
921     // Also check that the function tables passed in are big enough for
922     // all the functions we need (they could be bigger, if Netscape added
923     // new APIs, but that’s OK with us -- we’ll just ignore them).
924     //
925     if (err == NPERR_NO_ERROR)
926     {
927         if ((nsTable->version >> 8) > NP_VERSION_MAJOR)     // Major version is in high byte
928             err = NPERR_INCOMPATIBLE_VERSION_ERROR;
929     }
930
931     if (err == NPERR_NO_ERROR)
932     {
933         //
934         // Copy all the fields of Netscape’s function table into our
935         // copy so we can call back into Netscape later.  Note that
936         // we need to copy the fields one by one, rather than assigning
937         // the whole structure, because the Netscape function table
938         // could actually be bigger than what we expect.
939         //
940
941         int navMinorVers = nsTable->version & 0xFF;
942
943         gNetscapeFuncs.version          = nsTable->version;
944         gNetscapeFuncs.size             = nsTable->size;
945         gNetscapeFuncs.posturl          = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
946         gNetscapeFuncs.geturl           = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
947         gNetscapeFuncs.requestread      = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
948         gNetscapeFuncs.newstream        = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
949         gNetscapeFuncs.write            = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
950         gNetscapeFuncs.destroystream    = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
951         gNetscapeFuncs.status           = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
952         gNetscapeFuncs.uagent           = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
953         gNetscapeFuncs.memalloc         = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
954         gNetscapeFuncs.memfree          = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
955         gNetscapeFuncs.memflush         = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
956         gNetscapeFuncs.reloadplugins    = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
957         if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
958         {
959             gNetscapeFuncs.getJavaEnv   = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
960             gNetscapeFuncs.getJavaPeer  = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
961         }
962         if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
963         {
964             gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
965             gNetscapeFuncs.posturlnotify    = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
966         }
967         gNetscapeFuncs.getvalue         = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
968         gNetscapeFuncs.setvalue         = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
969         gNetscapeFuncs.invalidaterect   = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
970         gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
971         gNetscapeFuncs.forceredraw      = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
972         if( navMinorVers >= 14 )
973         {
974             // NPRuntime support
975             gNetscapeFuncs.getstringidentifier  = (NPN_GetStringIdentifierUPP)HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
976             gNetscapeFuncs.getstringidentifiers = (NPN_GetStringIdentifiersUPP)HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
977             gNetscapeFuncs.getintidentifier     = (NPN_GetIntIdentifierUPP)HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
978             gNetscapeFuncs.identifierisstring   = (NPN_IdentifierIsStringUPP)HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
979             gNetscapeFuncs.utf8fromidentifier   = (NPN_UTF8FromIdentifierUPP)HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
980             gNetscapeFuncs.intfromidentifier    = (NPN_IntFromIdentifierUPP)HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
981             gNetscapeFuncs.createobject         = (NPN_CreateObjectUPP)HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
982             gNetscapeFuncs.retainobject         = (NPN_RetainObjectUPP)HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
983             gNetscapeFuncs.releaseobject        = (NPN_ReleaseObjectUPP)HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
984             gNetscapeFuncs.invoke               = (NPN_InvokeUPP)HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
985             gNetscapeFuncs.invokeDefault        = (NPN_InvokeDefaultUPP)HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
986             gNetscapeFuncs.evaluate             = (NPN_EvaluateUPP)HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
987             gNetscapeFuncs.getproperty          = (NPN_GetPropertyUPP)HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
988             gNetscapeFuncs.setproperty          = (NPN_SetPropertyUPP)HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
989             gNetscapeFuncs.removeproperty       = (NPN_RemovePropertyUPP)HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
990             gNetscapeFuncs.hasproperty          = (NPN_HasPropertyUPP)HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
991             gNetscapeFuncs.hasmethod            = (NPN_HasMethodUPP)HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
992             gNetscapeFuncs.releasevariantvalue  = (NPN_ReleaseVariantValueUPP)HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
993             gNetscapeFuncs.setexception         = (NPN_SetExceptionUPP)HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
994         }
995
996         //
997         // Set up the plugin function table that Netscape will use to
998         // call us.  Netscape needs to know about our version and size
999         // and have a UniversalProcPointer for every function we implement.
1000         //
1001         pluginFuncs->version        = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1002         pluginFuncs->size           = sizeof(NPPluginFuncs);
1003         pluginFuncs->newp           = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1004         pluginFuncs->destroy        = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1005         pluginFuncs->setwindow      = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1006         pluginFuncs->newstream      = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1007         pluginFuncs->destroystream  = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1008         pluginFuncs->asfile         = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1009         pluginFuncs->writeready     = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1010         pluginFuncs->write          = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1011         pluginFuncs->print          = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1012         pluginFuncs->event          = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1013         pluginFuncs->getvalue       = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1014         if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1015         {
1016             pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1017         }
1018 #ifdef OJI
1019         if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1020         {
1021             pluginFuncs->javaClass  = (JRIGlobalRef) Private_GetJavaClass();
1022         }
1023 #else
1024         pluginFuncs->javaClass = NULL;
1025 #endif
1026         *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1027
1028         SetUpQD();
1029         err = Private_Initialize();
1030     }
1031
1032     ExitCodeResource();
1033     return err;
1034 }
1035
1036 #ifdef __MACH__
1037
1038 /*
1039 ** netscape plugins functions when building Mach-O binary
1040 */
1041
1042 extern "C" {
1043     NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1044     NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1045     NPError NP_Shutdown(void);
1046 }
1047
1048 /*
1049 ** netscape plugins functions when using Mach-O binary
1050 */
1051
1052 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1053 {
1054     PLUGINDEBUGSTR("\pNP_Initialize");
1055
1056     /* validate input parameters */
1057
1058     if( NULL == nsTable  )
1059         return NPERR_INVALID_FUNCTABLE_ERROR;
1060
1061     /*
1062      * Check the major version passed in Netscape's function table.
1063      * We won't load if the major version is newer than what we expect.
1064      * Also check that the function tables passed in are big enough for
1065      * all the functions we need (they could be bigger, if Netscape added
1066      * new APIs, but that's OK with us -- we'll just ignore them).
1067      *
1068      */
1069
1070     if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1071         return NPERR_INCOMPATIBLE_VERSION_ERROR;
1072
1073     if (nsTable->size < sizeof(NPNetscapeFuncs))
1074         return NPERR_INVALID_FUNCTABLE_ERROR;
1075
1076     int navMinorVers = nsTable->version & 0xFF;
1077
1078     /*
1079      * Copy all the fields of Netscape function table into our
1080      * copy so we can call back into Netscape later.  Note that
1081      * we need to copy the fields one by one, rather than assigning
1082      * the whole structure, because the Netscape function table
1083      * could actually be bigger than what we expect.
1084      */
1085     gNetscapeFuncs.version       = nsTable->version;
1086     gNetscapeFuncs.size          = nsTable->size;
1087     gNetscapeFuncs.posturl       = nsTable->posturl;
1088     gNetscapeFuncs.geturl        = nsTable->geturl;
1089     gNetscapeFuncs.requestread   = nsTable->requestread;
1090     gNetscapeFuncs.newstream     = nsTable->newstream;
1091     gNetscapeFuncs.write         = nsTable->write;
1092     gNetscapeFuncs.destroystream = nsTable->destroystream;
1093     gNetscapeFuncs.status        = nsTable->status;
1094     gNetscapeFuncs.uagent        = nsTable->uagent;
1095     gNetscapeFuncs.memalloc      = nsTable->memalloc;
1096     gNetscapeFuncs.memfree       = nsTable->memfree;
1097     gNetscapeFuncs.memflush      = nsTable->memflush;
1098     gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1099     if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1100     {
1101         gNetscapeFuncs.getJavaEnv   = nsTable->getJavaEnv;
1102         gNetscapeFuncs.getJavaPeer  = nsTable->getJavaPeer;
1103     }
1104     if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1105     {
1106         gNetscapeFuncs.geturlnotify     = nsTable->geturlnotify;
1107         gNetscapeFuncs.posturlnotify    = nsTable->posturlnotify;
1108     }
1109
1110     gNetscapeFuncs.getvalue         = nsTable->getvalue;
1111     gNetscapeFuncs.setvalue         = nsTable->setvalue;
1112     gNetscapeFuncs.invalidaterect   = nsTable->invalidaterect;
1113     gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1114     gNetscapeFuncs.forceredraw      = nsTable->forceredraw;
1115     if( navMinorVers >= 14 )
1116     {
1117         // NPRuntime support
1118         gNetscapeFuncs.getstringidentifier  = nsTable->getstringidentifier;
1119         gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1120         gNetscapeFuncs.getintidentifier     = nsTable->getintidentifier;
1121         gNetscapeFuncs.identifierisstring   = nsTable->identifierisstring;
1122         gNetscapeFuncs.utf8fromidentifier   = nsTable->utf8fromidentifier;
1123         gNetscapeFuncs.intfromidentifier    = nsTable->intfromidentifier;
1124         gNetscapeFuncs.createobject         = nsTable->createobject;
1125         gNetscapeFuncs.retainobject         = nsTable->retainobject;
1126         gNetscapeFuncs.releaseobject        = nsTable->releaseobject;
1127         gNetscapeFuncs.invoke               = nsTable->invoke;
1128         gNetscapeFuncs.invokeDefault        = nsTable->invokeDefault;
1129         gNetscapeFuncs.evaluate             = nsTable->evaluate;
1130         gNetscapeFuncs.getproperty          = nsTable->getproperty;
1131         gNetscapeFuncs.setproperty          = nsTable->setproperty;
1132         gNetscapeFuncs.removeproperty       = nsTable->removeproperty;
1133         gNetscapeFuncs.hasproperty          = nsTable->hasproperty;
1134         gNetscapeFuncs.hasmethod            = nsTable->hasmethod;
1135         gNetscapeFuncs.releasevariantvalue  = nsTable->releasevariantvalue;
1136         gNetscapeFuncs.setexception         = nsTable->setexception;
1137     }
1138     return NPP_Initialize();
1139 }
1140
1141 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1142 {
1143     int navMinorVers = gNetscapeFuncs.version & 0xFF;
1144
1145     PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1146
1147     if( pluginFuncs == NULL )
1148         return NPERR_INVALID_FUNCTABLE_ERROR;
1149
1150     /*if (pluginFuncs->size < sizeof(NPPluginFuncs))
1151     return NPERR_INVALID_FUNCTABLE_ERROR;*/
1152
1153     /*
1154      * Set up the plugin function table that Netscape will use to
1155      * call us.  Netscape needs to know about our version and size
1156      * and have a UniversalProcPointer for every function we
1157      * implement.
1158      */
1159
1160     pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1161     pluginFuncs->size       = sizeof(NPPluginFuncs);
1162     pluginFuncs->newp       = NewNPP_NewProc(Private_New);
1163     pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
1164     pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
1165     pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
1166     pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1167     pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1168     pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1169     pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
1170     pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
1171     pluginFuncs->event      = NewNPP_HandleEventProc(Private_HandleEvent);
1172     pluginFuncs->getvalue   = NewNPP_GetValueProc(Private_GetValue);
1173     pluginFuncs->setvalue   = NewNPP_SetValueProc(Private_SetValue);
1174     if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1175     {
1176         pluginFuncs->urlnotify = Private_URLNotify;
1177     }
1178 #ifdef OJI
1179     if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1180     {
1181         pluginFuncs->javaClass  = (JRIGlobalRef) Private_GetJavaClass();
1182     }
1183 #else
1184     pluginFuncs->javaClass = NULL;
1185 #endif
1186
1187     return NPERR_NO_ERROR;
1188 }
1189
1190 NPError NP_Shutdown(void)
1191 {
1192     PLUGINDEBUGSTR("\pNP_Shutdown");
1193     NPP_Shutdown();
1194     return NPERR_NO_ERROR;
1195 }
1196
1197 #endif