]> git.sesse.net Git - vlc/blob - mozilla/support/npmac.cpp
fee124f2f1fa85e28d3007bd74d6295ccb0090c1
[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 #ifdef XP_MACOSX && !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
637 NPError    Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
638 {
639     EnterCodeResource();
640     NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
641     PLUGINDEBUGSTR("\pNew;g;");
642     ExitCodeResource();
643     return ret; 
644 }
645
646 NPError Private_Destroy(NPP instance, NPSavedData** save)
647 {
648     NPError err;
649     EnterCodeResource();
650     PLUGINDEBUGSTR("\pDestroy;g;");
651     err = NPP_Destroy(instance, save);
652     ExitCodeResource();
653     return err;
654 }
655
656 NPError Private_SetWindow(NPP instance, NPWindow* window)
657 {
658     NPError err;
659     EnterCodeResource();
660     PLUGINDEBUGSTR("\pSetWindow;g;");
661     err = NPP_SetWindow(instance, window);
662     ExitCodeResource();
663     return err;
664 }
665
666 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
667 {
668     NPError err;
669     EnterCodeResource();
670     PLUGINDEBUGSTR("\pGetValue;g;");
671     err = NPP_GetValue( instance, variable, value);
672     ExitCodeResource();
673     return err;
674 }
675
676 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
677 {
678     NPError err;
679     EnterCodeResource();
680     PLUGINDEBUGSTR("\pSetValue;g;");
681     err = NPERR_NO_ERROR; //NPP_SetValue( instance, variable, value);
682     ExitCodeResource();
683     return err;
684 }
685
686 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
687 {
688     NPError err;
689     EnterCodeResource();
690     PLUGINDEBUGSTR("\pNewStream;g;");
691     err = NPP_NewStream(instance, type, stream, seekable, stype);
692     ExitCodeResource();
693     return err;
694 }
695
696 int32 Private_WriteReady(NPP instance, NPStream* stream)
697 {
698     int32 result;
699     EnterCodeResource();
700     PLUGINDEBUGSTR("\pWriteReady;g;");
701     result = NPP_WriteReady(instance, stream);
702     ExitCodeResource();
703     return result;
704 }
705
706 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
707 {
708     int32 result;
709     EnterCodeResource();
710     PLUGINDEBUGSTR("\pWrite;g;");
711     result = NPP_Write(instance, stream, offset, len, buffer);
712     ExitCodeResource();
713     return result;
714 }
715
716 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
717 {
718     EnterCodeResource();
719     PLUGINDEBUGSTR("\pStreamAsFile;g;");
720     NPP_StreamAsFile(instance, stream, fname);
721     ExitCodeResource();
722 }
723
724
725 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
726 {
727     NPError err;
728     EnterCodeResource();
729     PLUGINDEBUGSTR("\pDestroyStream;g;");
730     err = NPP_DestroyStream(instance, stream, reason);
731     ExitCodeResource();
732     return err;
733 }
734
735 int16 Private_HandleEvent(NPP instance, void* event)
736 {
737     int16 result;
738     EnterCodeResource();
739     PLUGINDEBUGSTR("\pHandleEvent;g;");
740     result = NPP_HandleEvent(instance, event);
741     ExitCodeResource();
742     return result;
743 }
744
745 void Private_Print(NPP instance, NPPrint* platformPrint)
746 {
747     EnterCodeResource();
748     PLUGINDEBUGSTR("\pPrint;g;");
749     NPP_Print(instance, platformPrint);
750     ExitCodeResource();
751 }
752
753 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
754 {
755     EnterCodeResource();
756     PLUGINDEBUGSTR("\pURLNotify;g;");
757     NPP_URLNotify(instance, url, reason, notifyData);
758     ExitCodeResource();
759 }
760
761 #ifdef OJI
762 jobject Private_GetJavaClass(void)
763 {
764     EnterCodeResource();
765     PLUGINDEBUGSTR("\pGetJavaClass;g;");
766
767     jobject clazz = NPP_GetJavaClass();
768     ExitCodeResource();
769     if (clazz)
770     {
771         JRIEnv* env = NPN_GetJavaEnv();
772         return (jobject)JRI_NewGlobalRef(env, clazz);
773     }
774     return NULL;
775 }
776 #endif
777
778 void SetUpQD(void);
779 void SetUpQD(void)
780 {
781 #if !TARGET_API_MAC_CARBON
782     ProcessSerialNumber PSN;
783     FSSpec              myFSSpec;
784     Str63               name;
785     ProcessInfoRec      infoRec;
786     OSErr               result = noErr;
787     CFragConnectionID   connID;
788     Str255              errName;
789 #endif    
790
791     //
792     // Memorize the plugin’s resource file 
793     // refnum for later use.
794     //
795     gResFile = CurResFile();
796     
797 #if !TARGET_API_MAC_CARBON
798     //
799     // Ask the system if CFM is available.
800     //
801     long response;
802     OSErr err = Gestalt(gestaltCFMAttr, &response);
803     Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
804
805     ProcessInfoRec infoRec;
806     if (hasCFM)
807     {
808         //
809         // GetProcessInformation takes a process serial number and 
810         // will give us back the name and FSSpec of the application.
811         // See the Process Manager in IM.
812         //
813         Str63 name;
814         FSSpec myFSSpec;
815         infoRec.processInfoLength = sizeof(ProcessInfoRec);
816         infoRec.processName = name;
817         infoRec.processAppSpec = &myFSSpec;
818         
819         ProcessSerialNumber PSN;
820         PSN.highLongOfPSN = 0;
821         PSN.lowLongOfPSN = kCurrentProcess;
822         
823         result = GetProcessInformation(&PSN, &infoRec);
824         if (result != noErr)
825             PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
826     }
827     else
828         //
829         // If no CFM installed, assume it must be a 68K app.
830         //
831         result = -1;        
832         
833     CFragConnectionID connID;
834     if (result == noErr)
835     {
836         //
837         // Now that we know the app name and FSSpec, we can call GetDiskFragment
838         // to get a connID to use in a subsequent call to FindSymbol (it will also
839         // return the address of “main” in app, which we ignore).  If GetDiskFragment 
840         // returns an error, we assume the app must be 68K.
841         //
842         Ptr mainAddr;   
843         Str255 errName;
844         result =  GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
845                                   kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
846     }
847
848     if (result == noErr) 
849     {
850         //
851         // The app is a PPC code fragment, so call FindSymbol
852         // to get the exported “qd” symbol so we can access its
853         // QuickDraw globals.
854         //
855         CFragSymbolClass symClass;
856         result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
857         if (result != noErr) {  // this fails if we are in NS 6
858             gQDPtr = &qd;       // so we default to the standard QD globals
859         }
860     }
861     else
862     {
863         //
864         // The app is 68K, so use its A5 to compute the address
865         // of its QuickDraw globals.
866         //
867         gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
868     }
869 #endif
870 }
871
872
873 #ifdef __GNUC__
874 // gcc requires that main have an 'int' return type
875 int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
876 #else
877 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
878 #endif
879
880 #if !TARGET_API_MAC_CARBON
881 #pragma export on
882
883 #if TARGET_RT_MAC_CFM
884
885 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
886
887 #endif
888
889 #pragma export off
890 #endif /* !TARGET_API_MAC_CARBON */
891
892 #ifdef __GNUC__
893 DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
894 #else
895 DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
896 #endif
897 {
898     EnterCodeResource();
899     PLUGINDEBUGSTR("\pmain");
900
901 #ifdef __MWERKS__
902     __InitCode__();
903 #endif
904
905     NPError err = NPERR_NO_ERROR;
906     
907     //
908     // Ensure that everything Netscape passed us is valid!
909     //
910     if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
911         err = NPERR_INVALID_FUNCTABLE_ERROR;
912     
913     //
914     // Check the “major” version passed in Netscape’s function table.
915     // We won’t load if the major version is newer than what we expect.
916     // Also check that the function tables passed in are big enough for
917     // all the functions we need (they could be bigger, if Netscape added
918     // new APIs, but that’s OK with us -- we’ll just ignore them).
919     //
920     if (err == NPERR_NO_ERROR)
921     {
922         if ((nsTable->version >> 8) > NP_VERSION_MAJOR)     // Major version is in high byte
923             err = NPERR_INCOMPATIBLE_VERSION_ERROR;
924     }
925         
926     
927     if (err == NPERR_NO_ERROR)
928     {
929         //
930         // Copy all the fields of Netscape’s function table into our
931         // copy so we can call back into Netscape later.  Note that
932         // we need to copy the fields one by one, rather than assigning
933         // the whole structure, because the Netscape function table
934         // could actually be bigger than what we expect.
935         //
936         
937         int navMinorVers = nsTable->version & 0xFF;
938
939         gNetscapeFuncs.version          = nsTable->version;
940         gNetscapeFuncs.size             = nsTable->size;
941         gNetscapeFuncs.posturl          = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
942         gNetscapeFuncs.geturl           = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
943         gNetscapeFuncs.requestread      = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
944         gNetscapeFuncs.newstream        = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
945         gNetscapeFuncs.write            = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
946         gNetscapeFuncs.destroystream    = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
947         gNetscapeFuncs.status           = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
948         gNetscapeFuncs.uagent           = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
949         gNetscapeFuncs.memalloc         = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
950         gNetscapeFuncs.memfree          = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
951         gNetscapeFuncs.memflush         = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
952         gNetscapeFuncs.reloadplugins    = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
953         if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
954         {
955             gNetscapeFuncs.getJavaEnv   = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
956             gNetscapeFuncs.getJavaPeer  = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
957         }
958         if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
959         {   
960             gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
961             gNetscapeFuncs.posturlnotify    = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
962         }
963         gNetscapeFuncs.getvalue         = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
964         gNetscapeFuncs.setvalue         = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
965         gNetscapeFuncs.invalidaterect   = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
966         gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
967         gNetscapeFuncs.forceredraw      = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
968         if( navMinorVers >= 14 )
969         {   
970             // NPRuntime support 
971             gNetscapeFuncs.getstringidentifier  = (NPN_GetStringIdentifierUPP)HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
972             gNetscapeFuncs.getstringidentifiers = (NPN_GetStringIdentifiersUPP)HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
973             gNetscapeFuncs.getintidentifier     = (NPN_GetIntIdentifierUPP)HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
974             gNetscapeFuncs.identifierisstring   = (NPN_IdentifierIsStringUPP)HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
975             gNetscapeFuncs.utf8fromidentifier   = (NPN_UTF8FromIdentifierUPP)HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
976             gNetscapeFuncs.intfromidentifier    = (NPN_IntFromIdentifierUPP)HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
977             gNetscapeFuncs.createobject         = (NPN_CreateObjectUPP)HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
978             gNetscapeFuncs.retainobject         = (NPN_RetainObjectUPP)HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
979             gNetscapeFuncs.releaseobject        = (NPN_ReleaseObjectUPP)HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
980             gNetscapeFuncs.invoke               = (NPN_InvokeUPP)HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
981             gNetscapeFuncs.invokeDefault        = (NPN_InvokeDefaultUPP)HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
982             gNetscapeFuncs.evaluate             = (NPN_EvaluateUPP)HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
983             gNetscapeFuncs.getproperty          = (NPN_GetPropertyUPP)HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
984             gNetscapeFuncs.setproperty          = (NPN_SetPropertyUPP)HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
985             gNetscapeFuncs.removeproperty       = (NPN_RemovePropertyUPP)HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
986             gNetscapeFuncs.hasproperty          = (NPN_HasPropertyUPP)HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
987             gNetscapeFuncs.hasmethod            = (NPN_HasMethodUPP)HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
988             gNetscapeFuncs.releasevariantvalue  = (NPN_ReleaseVariantValueUPP)HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
989             gNetscapeFuncs.setexception         = (NPN_SetExceptionUPP)HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
990         }
991
992         //
993         // Set up the plugin function table that Netscape will use to
994         // call us.  Netscape needs to know about our version and size
995         // and have a UniversalProcPointer for every function we implement.
996         //
997         pluginFuncs->version        = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
998         pluginFuncs->size           = sizeof(NPPluginFuncs);
999         pluginFuncs->newp           = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1000         pluginFuncs->destroy        = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1001         pluginFuncs->setwindow      = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1002         pluginFuncs->newstream      = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1003         pluginFuncs->destroystream  = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1004         pluginFuncs->asfile         = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1005         pluginFuncs->writeready     = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1006         pluginFuncs->write          = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1007         pluginFuncs->print          = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1008         pluginFuncs->event          = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));  
1009         pluginFuncs->getvalue       = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue)); 
1010         if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1011         {   
1012             pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));           
1013         }
1014 #ifdef OJI
1015         if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1016         {
1017             pluginFuncs->javaClass  = (JRIGlobalRef) Private_GetJavaClass();
1018         }
1019 #else
1020         pluginFuncs->javaClass = NULL;
1021 #endif
1022         *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1023
1024         SetUpQD();
1025         err = Private_Initialize();
1026     }
1027     
1028     ExitCodeResource();
1029     return err;
1030 }
1031
1032 #ifdef __MACH__
1033
1034 /*
1035 ** netscape plugins functions when building Mach-O binary
1036 */
1037
1038 extern "C" {
1039     NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1040     NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1041     NPError NP_Shutdown(void);
1042 }
1043
1044 /*
1045 ** netscape plugins functions when using Mach-O binary
1046 */
1047
1048 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1049 {
1050     PLUGINDEBUGSTR("\pNP_Initialize");
1051     
1052     /* validate input parameters */
1053
1054     if( NULL == nsTable  )
1055         return NPERR_INVALID_FUNCTABLE_ERROR;
1056     
1057     /*
1058      * Check the major version passed in Netscape's function table.
1059      * We won't load if the major version is newer than what we expect.
1060      * Also check that the function tables passed in are big enough for
1061      * all the functions we need (they could be bigger, if Netscape added
1062      * new APIs, but that's OK with us -- we'll just ignore them).
1063      *
1064      */
1065
1066     if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1067         return NPERR_INCOMPATIBLE_VERSION_ERROR;
1068
1069     if (nsTable->size < sizeof(NPNetscapeFuncs))
1070         return NPERR_INVALID_FUNCTABLE_ERROR;
1071         
1072     
1073     int navMinorVers = nsTable->version & 0xFF;
1074
1075     /*
1076      * Copy all the fields of Netscape function table into our
1077      * copy so we can call back into Netscape later.  Note that
1078      * we need to copy the fields one by one, rather than assigning
1079      * the whole structure, because the Netscape function table
1080      * could actually be bigger than what we expect.
1081      */
1082     gNetscapeFuncs.version       = nsTable->version;
1083     gNetscapeFuncs.size          = nsTable->size;
1084     gNetscapeFuncs.posturl       = nsTable->posturl;
1085     gNetscapeFuncs.geturl        = nsTable->geturl;
1086     gNetscapeFuncs.requestread   = nsTable->requestread;
1087     gNetscapeFuncs.newstream     = nsTable->newstream;
1088     gNetscapeFuncs.write         = nsTable->write;
1089     gNetscapeFuncs.destroystream = nsTable->destroystream;
1090     gNetscapeFuncs.status        = nsTable->status;
1091     gNetscapeFuncs.uagent        = nsTable->uagent;
1092     gNetscapeFuncs.memalloc      = nsTable->memalloc;
1093     gNetscapeFuncs.memfree       = nsTable->memfree;
1094     gNetscapeFuncs.memflush      = nsTable->memflush;
1095     gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1096     if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1097     {
1098         gNetscapeFuncs.getJavaEnv   = nsTable->getJavaEnv;
1099         gNetscapeFuncs.getJavaPeer  = nsTable->getJavaPeer;
1100     }
1101     if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1102     {    
1103         gNetscapeFuncs.geturlnotify     = nsTable->geturlnotify;
1104         gNetscapeFuncs.posturlnotify    = nsTable->posturlnotify;
1105     }
1106
1107     gNetscapeFuncs.getvalue         = nsTable->getvalue;
1108     gNetscapeFuncs.setvalue         = nsTable->setvalue;
1109     gNetscapeFuncs.invalidaterect   = nsTable->invalidaterect;
1110     gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1111     gNetscapeFuncs.forceredraw      = nsTable->forceredraw;
1112     if( navMinorVers >= 14 )
1113     {   
1114         // NPRuntime support 
1115         gNetscapeFuncs.getstringidentifier  = nsTable->getstringidentifier;
1116         gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1117         gNetscapeFuncs.getintidentifier     = nsTable->getintidentifier;
1118         gNetscapeFuncs.identifierisstring   = nsTable->identifierisstring;
1119         gNetscapeFuncs.utf8fromidentifier   = nsTable->utf8fromidentifier;
1120         gNetscapeFuncs.intfromidentifier    = nsTable->intfromidentifier;
1121         gNetscapeFuncs.createobject         = nsTable->createobject;
1122         gNetscapeFuncs.retainobject         = nsTable->retainobject;
1123         gNetscapeFuncs.releaseobject        = nsTable->releaseobject;
1124         gNetscapeFuncs.invoke               = nsTable->invoke;
1125         gNetscapeFuncs.invokeDefault        = nsTable->invokeDefault;
1126         gNetscapeFuncs.evaluate             = nsTable->evaluate;
1127         gNetscapeFuncs.getproperty          = nsTable->getproperty;
1128         gNetscapeFuncs.setproperty          = nsTable->setproperty;
1129         gNetscapeFuncs.removeproperty       = nsTable->removeproperty;
1130         gNetscapeFuncs.hasproperty          = nsTable->hasproperty;
1131         gNetscapeFuncs.hasmethod            = nsTable->hasmethod;
1132         gNetscapeFuncs.releasevariantvalue  = nsTable->releasevariantvalue;
1133         gNetscapeFuncs.setexception         = nsTable->setexception;
1134     }
1135     return NPP_Initialize();
1136 }
1137
1138 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1139 {
1140     int navMinorVers = gNetscapeFuncs.version & 0xFF;
1141
1142     PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1143
1144     if( pluginFuncs == NULL )
1145         return NPERR_INVALID_FUNCTABLE_ERROR;
1146
1147     /*if (pluginFuncs->size < sizeof(NPPluginFuncs)) 
1148     return NPERR_INVALID_FUNCTABLE_ERROR;*/
1149
1150     /*
1151      * Set up the plugin function table that Netscape will use to
1152      * call us.  Netscape needs to know about our version and size
1153      * and have a UniversalProcPointer for every function we
1154      * implement.
1155      */
1156
1157     pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1158     pluginFuncs->size       = sizeof(NPPluginFuncs);
1159     pluginFuncs->newp       = Private_New;
1160     pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
1161     pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
1162     pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
1163     pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1164     pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1165     pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1166     pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
1167     pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
1168     pluginFuncs->event      = NewNPP_HandleEventProc(Private_HandleEvent);
1169     pluginFuncs->getvalue   = NewNPP_GetValueProc(Private_GetValue);
1170     pluginFuncs->setvalue   = NewNPP_SetValueProc(Private_SetValue);
1171     if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1172     {    
1173         pluginFuncs->urlnotify = Private_URLNotify;         
1174     }
1175 #ifdef OJI
1176     if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1177     {
1178         pluginFuncs->javaClass  = (JRIGlobalRef) Private_GetJavaClass();
1179     }
1180 #else
1181     pluginFuncs->javaClass = NULL;
1182 #endif
1183
1184     return NPERR_NO_ERROR;
1185 }
1186
1187 NPError NP_Shutdown(void)
1188 {
1189     PLUGINDEBUGSTR("\pNP_Shutdown");
1190     NPP_Shutdown();
1191     return NPERR_NO_ERROR;
1192 }
1193
1194 #endif