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