Remove obsolete feisty script
[vlc/asuraparaju-public.git] / projects / mozilla / support / npmac.cpp
blobb8e2d0e63b473897087ffde65593aea22f848124
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * Safari/Mozilla/Firefox plugin for VLC
4 * Copyright (C) 2009, Jean-Paul Saman <jpsaman@videolan.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
23 // npmac.cpp
25 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
27 #include "config.h"
29 #include <string.h>
31 #include <Processes.h>
32 #include <Gestalt.h>
33 #include <CodeFragments.h>
34 #include <Timer.h>
35 #include <Resources.h>
36 #include <ToolUtils.h>
38 #define XP_MACOSX 1
39 #undef TARGET_RT_MAC_CFM
42 // A4Stuff.h contains the definition of EnterCodeResource and
43 // EnterCodeResource, used for setting up the code resource’s
44 // globals for 68K (analagous to the function SetCurrentA5
45 // defined by the toolbox).
47 // A4Stuff does not exist as of CW 7. Define them to nothing.
50 #if (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) || defined(__GNUC__)
51 #define EnterCodeResource()
52 #define ExitCodeResource()
53 #else
54 #include <A4Stuff.h>
55 #endif
57 #include "npapi.h"
60 // The Mixed Mode procInfos defined in npupp.h assume Think C-
61 // style calling conventions. These conventions are used by
62 // Metrowerks with the exception of pointer return types, which
63 // in Metrowerks 68K are returned in A0, instead of the standard
64 // D0. Thus, since NPN_MemAlloc and NPN_UserAgent return pointers,
65 // Mixed Mode will return the values to a 68K plugin in D0, but
66 // a 68K plugin compiled by Metrowerks will expect the result in
67 // A0. The following pragma forces Metrowerks to use D0 instead.
69 #ifdef __MWERKS__
70 #ifndef powerc
71 #pragma pointers_in_D0
72 #endif
73 #endif
75 #ifdef XP_UNIX
76 #undef XP_UNIX
77 #endif
79 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
80 #include "npupp.h"
81 // e.g. CALL_NPN(CallNPN_GetURLNotify, x, y, z) -> CallNPN_GetURLNotify(x, y, z);
82 #define CALL_NPN(__CallNPNFunc__, ...) (__CallNPNFunc__(__VA_ARGS__))
83 #else
84 #include "npfunctions.h"
85 #define CALL_NPN(unused, FN, ...) ((*FN)(__VA_ARGS__))
86 #endif
88 #include "../vlcshell.h"
90 #ifdef __MWERKS__
91 #ifndef powerc
92 #pragma pointers_in_A0
93 #endif
94 #endif
96 // The following fix for static initializers (which fixes a previous
97 // incompatibility with some parts of PowerPlant, was submitted by
98 // Jan Ulbrich.
99 #ifdef __MWERKS__
100 #ifdef __cplusplus
101 extern "C" {
102 #endif
103 #ifndef powerc
104 extern void __InitCode__(void);
105 #else
106 extern void __sinit(void);
107 #define __InitCode__ __sinit
108 #endif
109 extern void __destroy_global_chain(void);
110 #ifdef __cplusplus
112 #endif // __cplusplus
113 #endif // __MWERKS__
116 // Define PLUGIN_TRACE to 1 to have the wrapper functions emit
117 // DebugStr messages whenever they are called.
119 #define PLUGIN_TRACE 0
121 #if PLUGIN_TRACE
122 #define PLUGINDEBUGSTR(msg) ::DebugStr(msg)
123 #else
124 #define PLUGINDEBUGSTR(msg) {}
125 #endif
127 #if defined(XP_MACOSX) && defined(__POWERPC__) && (!defined(TARGET_RT_MAC_CFM))
129 // glue for mapping outgoing Macho function pointers to TVectors
130 struct TFPtoTVGlue {
131 void* glue[2];
134 static struct {
135 TFPtoTVGlue newp;
136 TFPtoTVGlue destroy;
137 TFPtoTVGlue setwindow;
138 TFPtoTVGlue newstream;
139 TFPtoTVGlue destroystream;
140 TFPtoTVGlue asfile;
141 TFPtoTVGlue writeready;
142 TFPtoTVGlue write;
143 TFPtoTVGlue print;
144 TFPtoTVGlue event;
145 TFPtoTVGlue urlnotify;
146 TFPtoTVGlue getvalue;
147 TFPtoTVGlue setvalue;
149 TFPtoTVGlue shutdown;
150 } gPluginFuncsGlueTable;
152 static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
154 functionGlue->glue[0] = fp;
155 functionGlue->glue[1] = 0;
156 return functionGlue;
159 #define PLUGIN_TO_HOST_GLUE(name, fp) (SetupFPtoTVGlue(&gPluginFuncsGlueTable.name, (void*)fp))
161 // glue for mapping netscape TVectors to Macho function pointers
162 struct TTVtoFPGlue {
163 uint32_t glue[6];
166 static struct {
167 TTVtoFPGlue geturl;
168 TTVtoFPGlue posturl;
169 TTVtoFPGlue requestread;
170 TTVtoFPGlue newstream;
171 TTVtoFPGlue write;
172 TTVtoFPGlue destroystream;
173 TTVtoFPGlue status;
174 TTVtoFPGlue uagent;
175 TTVtoFPGlue memalloc;
176 TTVtoFPGlue memfree;
177 TTVtoFPGlue memflush;
178 TTVtoFPGlue reloadplugins;
179 TTVtoFPGlue getJavaEnv;
180 TTVtoFPGlue getJavaPeer;
181 TTVtoFPGlue geturlnotify;
182 TTVtoFPGlue posturlnotify;
183 TTVtoFPGlue getvalue;
184 TTVtoFPGlue setvalue;
185 TTVtoFPGlue invalidaterect;
186 TTVtoFPGlue invalidateregion;
187 TTVtoFPGlue forceredraw;
188 // NPRuntime support
189 TTVtoFPGlue getstringidentifier;
190 TTVtoFPGlue getstringidentifiers;
191 TTVtoFPGlue getintidentifier;
192 TTVtoFPGlue identifierisstring;
193 TTVtoFPGlue utf8fromidentifier;
194 TTVtoFPGlue intfromidentifier;
195 TTVtoFPGlue createobject;
196 TTVtoFPGlue retainobject;
197 TTVtoFPGlue releaseobject;
198 TTVtoFPGlue invoke;
199 TTVtoFPGlue invokeDefault;
200 TTVtoFPGlue evaluate;
201 TTVtoFPGlue getproperty;
202 TTVtoFPGlue setproperty;
203 TTVtoFPGlue removeproperty;
204 TTVtoFPGlue hasproperty;
205 TTVtoFPGlue hasmethod;
206 TTVtoFPGlue releasevariantvalue;
207 TTVtoFPGlue setexception;
208 } gNetscapeFuncsGlueTable;
210 static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
212 static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
214 memcpy(functionGlue, &glueTemplate, sizeof(TTVtoFPGlue));
215 functionGlue->glue[0] |= ((UInt32)tvp >> 16);
216 functionGlue->glue[1] |= ((UInt32)tvp & 0xFFFF);
217 ::MakeDataExecutable(functionGlue, sizeof(TTVtoFPGlue));
218 return functionGlue;
221 #define HOST_TO_PLUGIN_GLUE(name, fp) ((UniversalProcPtr)(SetupTVtoFPGlue(&gNetscapeFuncsGlueTable.name, (void*)fp)))
223 #else
225 #define PLUGIN_TO_HOST_GLUE(name, fp) (fp)
226 #define HOST_TO_PLUGIN_GLUE(name, fp) (fp)
228 #endif /* XP_MACOSX */
230 #pragma mark -
232 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
234 // Globals
236 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
238 #if !TARGET_API_MAC_CARBON
239 QDGlobals* gQDPtr; // Pointer to Netscape’s QuickDraw globals
240 #endif
241 short gResFile; // Refnum of the plugin’s resource file
242 NPNetscapeFuncs gNetscapeFuncs; // Function table for procs in Netscape called by plugin
244 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
246 // Wrapper functions for all calls from the plugin to Netscape.
247 // These functions let the plugin developer just call the APIs
248 // as documented and defined in npapi.h, without needing to know
249 // about the function table and call macros in npupp.h.
251 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
253 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
255 *plugin_major = NP_VERSION_MAJOR;
256 *plugin_minor = NP_VERSION_MINOR;
257 *netscape_major = gNetscapeFuncs.version >> 8; // Major version is in high byte
258 *netscape_minor = gNetscapeFuncs.version & 0xFF; // Minor version is in low byte
261 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
263 int navMinorVers = gNetscapeFuncs.version & 0xFF;
264 NPError err;
266 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
268 err = CALL_NPN(CallNPN_GetURLNotifyProc, gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
270 else
272 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
274 return err;
277 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
279 return CALL_NPN(CallNPN_GetURLProc, gNetscapeFuncs.geturl, instance, url, window);
282 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
284 int navMinorVers = gNetscapeFuncs.version & 0xFF;
285 NPError err;
287 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
289 err = CALL_NPN(CallNPN_PostURLNotifyProc, gNetscapeFuncs.posturlnotify, instance, url,
290 window, len, buf, file, notifyData);
292 else
294 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
296 return err;
299 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
301 return CALL_NPN(CallNPN_PostURLProc, gNetscapeFuncs.posturl, instance, url, window, len, buf, file);
304 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
306 return CALL_NPN(CallNPN_RequestReadProc, gNetscapeFuncs.requestread, stream, rangeList);
309 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream)
311 int navMinorVers = gNetscapeFuncs.version & 0xFF;
312 NPError err;
314 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
316 err = CALL_NPN(CallNPN_NewStreamProc, gNetscapeFuncs.newstream, instance, type, window, stream);
318 else
320 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
322 return err;
325 int32_t NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
327 int navMinorVers = gNetscapeFuncs.version & 0xFF;
328 NPError err;
330 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
332 err = CALL_NPN(CallNPN_WriteProc, gNetscapeFuncs.write, instance, stream, len, buffer);
334 else
336 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
338 return err;
341 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
343 int navMinorVers = gNetscapeFuncs.version & 0xFF;
344 NPError err;
346 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
348 err = CALL_NPN(CallNPN_DestroyStreamProc, gNetscapeFuncs.destroystream, instance, stream, reason);
350 else
352 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
354 return err;
357 void NPN_Status(NPP instance, const char* message)
359 CALL_NPN(CallNPN_StatusProc, gNetscapeFuncs.status, instance, message);
362 const char* NPN_UserAgent(NPP instance)
364 return CALL_NPN(CallNPN_UserAgentProc, gNetscapeFuncs.uagent, instance);
367 void* NPN_MemAlloc(uint32_t size)
369 return CALL_NPN(CallNPN_MemAllocProc, gNetscapeFuncs.memalloc, size);
372 void NPN_MemFree(void* ptr)
374 CALL_NPN(CallNPN_MemFreeProc, gNetscapeFuncs.memfree, ptr);
377 uint32_t NPN_MemFlush(uint32_t size)
379 return CALL_NPN(CallNPN_MemFlushProc, gNetscapeFuncs.memflush, size);
382 void NPN_ReloadPlugins(NPBool reloadPages)
384 CALL_NPN(CallNPN_ReloadPluginsProc, gNetscapeFuncs.reloadplugins, reloadPages);
387 #ifdef OJI
388 JRIEnv* NPN_GetJavaEnv(void)
390 return CallNPN_GetJavaEnvProc( gNetscapeFuncs.getJavaEnv );
393 jobject NPN_GetJavaPeer(NPP instance)
395 return CallNPN_GetJavaPeerProc( gNetscapeFuncs.getJavaPeer, instance );
397 #endif
399 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
401 return CALL_NPN(CallNPN_GetValueProc, gNetscapeFuncs.getvalue, instance, variable, value);
404 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
406 return CALL_NPN(CallNPN_SetValueProc, gNetscapeFuncs.setvalue, instance, variable, value);
409 void NPN_InvalidateRect(NPP instance, NPRect *rect)
411 CALL_NPN(CallNPN_InvalidateRectProc, gNetscapeFuncs.invalidaterect, instance, rect);
414 void NPN_InvalidateRegion(NPP instance, NPRegion region)
416 CALL_NPN(CallNPN_InvalidateRegionProc, gNetscapeFuncs.invalidateregion, instance, region);
419 void NPN_ForceRedraw(NPP instance)
421 CALL_NPN(CallNPN_ForceRedrawProc, gNetscapeFuncs.forceredraw, instance);
424 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
426 int navMinorVers = gNetscapeFuncs.version & 0xFF;
427 if( navMinorVers >= 14 )
429 return CALL_NPN(CallNPN_GetStringIdentifierProc, gNetscapeFuncs.getstringidentifier, name);
431 return NULL;
434 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
436 int navMinorVers = gNetscapeFuncs.version & 0xFF;
437 if( navMinorVers >= 14 )
439 CALL_NPN(CallNPN_GetStringIdentifiersProc, gNetscapeFuncs.getstringidentifiers, names, nameCount, identifiers);
443 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
445 int navMinorVers = gNetscapeFuncs.version & 0xFF;
446 if( navMinorVers >= 14 )
448 return CALL_NPN(CallNPN_GetIntIdentifierProc, gNetscapeFuncs.getintidentifier, intid);
450 return NULL;
453 bool NPN_IdentifierIsString(NPIdentifier identifier)
455 int navMinorVers = gNetscapeFuncs.version & 0xFF;
456 if( navMinorVers >= 14 )
458 return CALL_NPN(CallNPN_IdentifierIsStringProc, gNetscapeFuncs.identifierisstring, identifier);
460 return false;
463 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
465 int navMinorVers = gNetscapeFuncs.version & 0xFF;
466 if( navMinorVers >= 14 )
468 return CALL_NPN(CallNPN_UTF8FromIdentifierProc, gNetscapeFuncs.utf8fromidentifier, identifier);
470 return NULL;
473 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
475 int navMinorVers = gNetscapeFuncs.version & 0xFF;
476 if( navMinorVers >= 14 )
478 return CALL_NPN(CallNPN_IntFromIdentifierProc, gNetscapeFuncs.intfromidentifier, identifier);
480 return 0;
483 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
485 int navMinorVers = gNetscapeFuncs.version & 0xFF;
486 if( navMinorVers >= 14 )
488 return CALL_NPN(CallNPN_CreateObjectProc, gNetscapeFuncs.createobject, instance, aClass);
490 return NULL;
493 NPObject *NPN_RetainObject(NPObject *npobj)
495 int navMinorVers = gNetscapeFuncs.version & 0xFF;
496 if( navMinorVers >= 14 )
498 return CALL_NPN(CallNPN_RetainObjectProc, gNetscapeFuncs.retainobject, npobj);
500 return NULL;
503 void NPN_ReleaseObject(NPObject *npobj)
505 int navMinorVers = gNetscapeFuncs.version & 0xFF;
506 if( navMinorVers >= 14 )
508 CALL_NPN(CallNPN_ReleaseObjectProc, gNetscapeFuncs.releaseobject, npobj);
512 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
514 int navMinorVers = gNetscapeFuncs.version & 0xFF;
515 if( navMinorVers >= 14 )
517 return CALL_NPN(CallNPN_InvokeProc, gNetscapeFuncs.invoke, instance, npobj, methodName, args, argCount, result);
519 return false;
522 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
524 int navMinorVers = gNetscapeFuncs.version & 0xFF;
525 if( navMinorVers >= 14 )
527 return CALL_NPN(CallNPN_InvokeDefaultProc, gNetscapeFuncs.invokeDefault, instance, npobj, args, argCount, result);
529 return false;
532 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
534 int navMinorVers = gNetscapeFuncs.version & 0xFF;
535 if( navMinorVers >= 14 )
537 return CALL_NPN(CallNPN_EvaluateProc, gNetscapeFuncs.evaluate, instance, npobj, script, result);
539 return false;
542 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
544 int navMinorVers = gNetscapeFuncs.version & 0xFF;
545 if( navMinorVers >= 14 )
547 return CALL_NPN(CallNPN_GetPropertyProc, gNetscapeFuncs.getproperty, instance, npobj, propertyName, result);
549 return false;
552 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
554 int navMinorVers = gNetscapeFuncs.version & 0xFF;
555 if( navMinorVers >= 14 )
557 return CALL_NPN(CallNPN_SetPropertyProc, gNetscapeFuncs.setproperty, instance, npobj, propertyName, value);
559 return false;
562 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
564 int navMinorVers = gNetscapeFuncs.version & 0xFF;
565 if( navMinorVers >= 14 )
567 return CALL_NPN(CallNPN_RemovePropertyProc, gNetscapeFuncs.removeproperty, instance, npobj, propertyName);
569 return false;
572 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
574 int navMinorVers = gNetscapeFuncs.version & 0xFF;
575 if( navMinorVers >= 14 )
577 return CALL_NPN(CallNPN_HasPropertyProc, gNetscapeFuncs.hasproperty, instance, npobj, propertyName);
579 return false;
582 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
584 int navMinorVers = gNetscapeFuncs.version & 0xFF;
585 if( navMinorVers >= 14 )
587 return CALL_NPN(CallNPN_HasMethodProc, gNetscapeFuncs.hasmethod, instance, npobj, methodName);
589 return false;
592 void NPN_ReleaseVariantValue(NPVariant *variant)
594 int navMinorVers = gNetscapeFuncs.version & 0xFF;
595 if( navMinorVers >= 14 )
597 CALL_NPN(CallNPN_ReleaseVariantValueProc, gNetscapeFuncs.releasevariantvalue, variant);
601 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
603 int navMinorVers = gNetscapeFuncs.version & 0xFF;
604 if( navMinorVers >= 14 )
606 CALL_NPN(CallNPN_SetExceptionProc, gNetscapeFuncs.setexception, npobj, message);
610 #pragma mark -
612 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
614 // Wrapper functions for all calls from Netscape to the plugin.
615 // These functions let the plugin developer just create the APIs
616 // as documented and defined in npapi.h, without needing to
617 // install those functions in the function table or worry about
618 // setting up globals for 68K plugins.
620 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
622 NPError Private_Initialize(void);
623 void Private_Shutdown(void);
624 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
625 NPError Private_Destroy(NPP instance, NPSavedData** save);
626 NPError Private_SetWindow(NPP instance, NPWindow* window);
627 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value );
628 NPError Private_SetValue( NPP instance, NPPVariable variable, void *value );
629 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype);
630 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
631 int32_t Private_WriteReady(NPP instance, NPStream* stream);
632 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer);
633 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
634 void Private_Print(NPP instance, NPPrint* platformPrint);
635 int16_t Private_HandleEvent(NPP instance, void* event);
636 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData);
637 #ifdef OJI
638 jobject Private_GetJavaClass(void);
639 #endif // OJI
642 NPError Private_Initialize(void)
644 NPError err;
645 EnterCodeResource();
646 PLUGINDEBUGSTR("\pInitialize;g;");
647 err = NPP_Initialize();
648 ExitCodeResource();
649 return err;
652 void Private_Shutdown(void)
654 EnterCodeResource();
655 PLUGINDEBUGSTR("\pShutdown;g;");
656 NPP_Shutdown();
658 #ifdef __MWERKS__
659 __destroy_global_chain();
660 #endif
662 ExitCodeResource();
665 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
667 EnterCodeResource();
668 NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
669 PLUGINDEBUGSTR("\pNew;g;");
670 ExitCodeResource();
671 return ret;
674 NPError Private_Destroy(NPP instance, NPSavedData** save)
676 NPError err;
677 EnterCodeResource();
678 PLUGINDEBUGSTR("\pDestroy;g;");
679 err = NPP_Destroy(instance, save);
680 ExitCodeResource();
681 return err;
684 NPError Private_SetWindow(NPP instance, NPWindow* window)
686 NPError err;
687 EnterCodeResource();
688 PLUGINDEBUGSTR("\pSetWindow;g;");
689 err = NPP_SetWindow(instance, window);
690 ExitCodeResource();
691 return err;
694 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
696 NPError err;
697 EnterCodeResource();
698 PLUGINDEBUGSTR("\pGetValue;g;");
699 err = NPP_GetValue(instance, variable, value);
700 ExitCodeResource();
701 return err;
704 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
706 NPError err;
707 EnterCodeResource();
708 PLUGINDEBUGSTR("\pSetValue;g;");
709 err = NPP_SetValue(instance, variable, value);
710 ExitCodeResource();
711 return err;
714 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
716 NPError err;
717 EnterCodeResource();
718 PLUGINDEBUGSTR("\pNewStream;g;");
719 err = NPP_NewStream(instance, type, stream, seekable, stype);
720 ExitCodeResource();
721 return err;
724 int32_t Private_WriteReady(NPP instance, NPStream* stream)
726 int32_t result;
727 EnterCodeResource();
728 PLUGINDEBUGSTR("\pWriteReady;g;");
729 result = NPP_WriteReady(instance, stream);
730 ExitCodeResource();
731 return result;
734 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
736 int32_t result;
737 EnterCodeResource();
738 PLUGINDEBUGSTR("\pWrite;g;");
739 result = NPP_Write(instance, stream, offset, len, buffer);
740 ExitCodeResource();
741 return result;
744 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
746 EnterCodeResource();
747 PLUGINDEBUGSTR("\pStreamAsFile;g;");
748 NPP_StreamAsFile(instance, stream, fname);
749 ExitCodeResource();
752 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
754 NPError err;
755 EnterCodeResource();
756 PLUGINDEBUGSTR("\pDestroyStream;g;");
757 err = NPP_DestroyStream(instance, stream, reason);
758 ExitCodeResource();
759 return err;
762 int16_t Private_HandleEvent(NPP instance, void* event)
764 int16_t result;
765 EnterCodeResource();
766 PLUGINDEBUGSTR("\pHandleEvent;g;");
767 result = NPP_HandleEvent(instance, event);
768 ExitCodeResource();
769 return result;
772 void Private_Print(NPP instance, NPPrint* platformPrint)
774 EnterCodeResource();
775 PLUGINDEBUGSTR("\pPrint;g;");
776 NPP_Print(instance, platformPrint);
777 ExitCodeResource();
780 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
782 EnterCodeResource();
783 PLUGINDEBUGSTR("\pURLNotify;g;");
784 NPP_URLNotify(instance, url, reason, notifyData);
785 ExitCodeResource();
788 #ifdef OJI
789 jobject Private_GetJavaClass(void)
791 EnterCodeResource();
792 PLUGINDEBUGSTR("\pGetJavaClass;g;");
794 jobject clazz = NPP_GetJavaClass();
795 ExitCodeResource();
796 if (clazz)
798 JRIEnv* env = NPN_GetJavaEnv();
799 return (jobject)JRI_NewGlobalRef(env, clazz);
801 return NULL;
803 #endif
805 void SetUpQD(void);
806 void SetUpQD(void)
808 #if !TARGET_API_MAC_CARBON
809 ProcessSerialNumber PSN;
810 FSSpec myFSSpec;
811 Str63 name;
812 ProcessInfoRec infoRec;
813 OSErr result = noErr;
814 CFragConnectionID connID;
815 Str255 errName;
816 #endif
819 // Memorize the plugin’s resource file
820 // refnum for later use.
822 gResFile = CurResFile();
824 #if !TARGET_API_MAC_CARBON
826 // Ask the system if CFM is available.
828 long response;
829 OSErr err = Gestalt(gestaltCFMAttr, &response);
830 Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
832 ProcessInfoRec infoRec;
833 if (hasCFM)
836 // GetProcessInformation takes a process serial number and
837 // will give us back the name and FSSpec of the application.
838 // See the Process Manager in IM.
840 Str63 name;
841 FSSpec myFSSpec;
842 infoRec.processInfoLength = sizeof(ProcessInfoRec);
843 infoRec.processName = name;
844 infoRec.processAppSpec = &myFSSpec;
846 ProcessSerialNumber PSN;
847 PSN.highLongOfPSN = 0;
848 PSN.lowLongOfPSN = kCurrentProcess;
850 result = GetProcessInformation(&PSN, &infoRec);
851 if (result != noErr)
852 PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
854 else
856 // If no CFM installed, assume it must be a 68K app.
858 result = -1;
860 CFragConnectionID connID;
861 if (result == noErr)
864 // Now that we know the app name and FSSpec, we can call GetDiskFragment
865 // to get a connID to use in a subsequent call to FindSymbol (it will also
866 // return the address of “main” in app, which we ignore). If GetDiskFragment
867 // returns an error, we assume the app must be 68K.
869 Ptr mainAddr;
870 Str255 errName;
871 result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
872 kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
875 if (result == noErr)
878 // The app is a PPC code fragment, so call FindSymbol
879 // to get the exported “qd” symbol so we can access its
880 // QuickDraw globals.
882 CFragSymbolClass symClass;
883 result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
884 if (result != noErr) { // this fails if we are in NS 6
885 gQDPtr = &qd; // so we default to the standard QD globals
888 else
891 // The app is 68K, so use its A5 to compute the address
892 // of its QuickDraw globals.
894 gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
896 #endif
899 #ifdef __GNUC__
900 // gcc requires that main have an 'int' return type
901 typedef int main_return_t;
902 #else
903 typedef NPError mainReturnType;
904 #endif
906 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
907 typedef NPP_ShutdownUPP unloadupp_t;
908 #else
909 typedef NPP_ShutdownProcPtr unloadupp_t;
910 #endif
913 main_return_t main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, unloadupp_t* unloadUpp);
915 #if !TARGET_API_MAC_CARBON
916 #pragma export on
918 #if TARGET_RT_MAC_CFM
920 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
922 #endif
924 #pragma export off
925 #endif /* !TARGET_API_MAC_CARBON */
927 DEFINE_API_C(main_return_t) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, unloadupp_t* unloadUpp)
929 EnterCodeResource();
930 PLUGINDEBUGSTR("\pmain");
932 #ifdef __MWERKS__
933 __InitCode__();
934 #endif
936 NPError err = NPERR_NO_ERROR;
939 // Ensure that everything Netscape passed us is valid!
941 if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
942 err = NPERR_INVALID_FUNCTABLE_ERROR;
945 // Check the “major” version passed in Netscape’s function table.
946 // We won’t load if the major version is newer than what we expect.
947 // Also check that the function tables passed in are big enough for
948 // all the functions we need (they could be bigger, if Netscape added
949 // new APIs, but that’s OK with us -- we’ll just ignore them).
951 if (err == NPERR_NO_ERROR)
953 if ((nsTable->version >> 8) > NP_VERSION_MAJOR) // Major version is in high byte
954 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
957 if (err == NPERR_NO_ERROR)
960 // Copy all the fields of Netscape’s function table into our
961 // copy so we can call back into Netscape later. Note that
962 // we need to copy the fields one by one, rather than assigning
963 // the whole structure, because the Netscape function table
964 // could actually be bigger than what we expect.
967 int navMinorVers = nsTable->version & 0xFF;
969 gNetscapeFuncs.version = nsTable->version;
970 gNetscapeFuncs.size = nsTable->size;
971 gNetscapeFuncs.posturl = HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
972 gNetscapeFuncs.geturl = HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
973 gNetscapeFuncs.requestread = HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
974 gNetscapeFuncs.newstream = HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
975 gNetscapeFuncs.write = HOST_TO_PLUGIN_GLUE(write, nsTable->write);
976 gNetscapeFuncs.destroystream = HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
977 gNetscapeFuncs.status = HOST_TO_PLUGIN_GLUE(status, nsTable->status);
978 gNetscapeFuncs.uagent = HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
979 gNetscapeFuncs.memalloc = HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
980 gNetscapeFuncs.memfree = HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
981 gNetscapeFuncs.memflush = HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
982 gNetscapeFuncs.reloadplugins = HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
983 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
985 gNetscapeFuncs.getJavaEnv = HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
986 gNetscapeFuncs.getJavaPeer = HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
988 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
990 gNetscapeFuncs.geturlnotify = HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
991 gNetscapeFuncs.posturlnotify = HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
993 gNetscapeFuncs.getvalue = HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
994 gNetscapeFuncs.setvalue = HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
995 gNetscapeFuncs.invalidaterect = HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
996 gNetscapeFuncs.invalidateregion = HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
997 gNetscapeFuncs.forceredraw = HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
998 if( navMinorVers >= 14 )
1000 // NPRuntime support
1001 gNetscapeFuncs.getstringidentifier = HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
1002 gNetscapeFuncs.getstringidentifiers = HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
1003 gNetscapeFuncs.getintidentifier = HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
1004 gNetscapeFuncs.identifierisstring = HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
1005 gNetscapeFuncs.utf8fromidentifier = HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
1006 gNetscapeFuncs.intfromidentifier = HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
1007 gNetscapeFuncs.createobject = HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
1008 gNetscapeFuncs.retainobject = HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
1009 gNetscapeFuncs.releaseobject = HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
1010 gNetscapeFuncs.invoke = HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
1011 gNetscapeFuncs.invokeDefault = HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
1012 gNetscapeFuncs.evaluate = HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
1013 gNetscapeFuncs.getproperty = HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
1014 gNetscapeFuncs.setproperty = HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
1015 gNetscapeFuncs.removeproperty = HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
1016 gNetscapeFuncs.hasproperty = HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
1017 gNetscapeFuncs.hasmethod = HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
1018 gNetscapeFuncs.releasevariantvalue = HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
1019 gNetscapeFuncs.setexception = HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
1023 // Set up the plugin function table that Netscape will use to
1024 // call us. Netscape needs to know about our version and size
1025 // and have a UniversalProcPointer for every function we implement.
1027 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1028 pluginFuncs->size = sizeof(NPPluginFuncs);
1029 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
1030 pluginFuncs->newp = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1031 pluginFuncs->destroy = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1032 pluginFuncs->setwindow = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1033 pluginFuncs->newstream = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1034 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1035 pluginFuncs->asfile = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1036 pluginFuncs->writeready = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1037 pluginFuncs->write = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1038 pluginFuncs->print = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1039 pluginFuncs->event = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1040 pluginFuncs->getvalue = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1041 #else
1042 pluginFuncs->newp = (NPP_NewProcPtr)(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1043 pluginFuncs->destroy = (NPP_DestroyProcPtr)(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1044 pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1045 pluginFuncs->newstream = (NPP_NewStreamProcPtr)(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1046 pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1047 pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1048 pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1049 pluginFuncs->write = (NPP_WriteProcPtr)(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1050 pluginFuncs->print = (NPP_PrintProcPtr)(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1051 pluginFuncs->event = (NPP_HandleEventProcPtr)(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1052 pluginFuncs->getvalue = (NPP_GetValueProcPtr)(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1053 #endif
1054 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1056 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
1057 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1058 #else
1059 pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1060 #endif
1062 #ifdef OJI
1063 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1065 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1067 #else
1068 pluginFuncs->javaClass = NULL;
1069 #endif
1070 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
1071 *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1072 #else
1073 *unloadUpp = (NPP_ShutdownProcPtr)(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1074 #endif
1075 SetUpQD();
1076 err = Private_Initialize();
1079 ExitCodeResource();
1080 return err;
1083 #ifdef __MACH__
1086 ** netscape plugins functions when building Mach-O binary
1089 extern "C" {
1090 NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1091 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1092 NPError NP_Shutdown(void);
1096 ** netscape plugins functions when using Mach-O binary
1099 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1101 PLUGINDEBUGSTR("\pNP_Initialize");
1103 /* validate input parameters */
1105 if( NULL == nsTable )
1106 return NPERR_INVALID_FUNCTABLE_ERROR;
1109 * Check the major version passed in Netscape's function table.
1110 * We won't load if the major version is newer than what we expect.
1111 * Also check that the function tables passed in are big enough for
1112 * all the functions we need (they could be bigger, if Netscape added
1113 * new APIs, but that's OK with us -- we'll just ignore them).
1117 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1118 return NPERR_INCOMPATIBLE_VERSION_ERROR;
1120 if (nsTable->size < sizeof(NPNetscapeFuncs))
1121 return NPERR_INVALID_FUNCTABLE_ERROR;
1123 int navMinorVers = nsTable->version & 0xFF;
1126 * Copy all the fields of Netscape function table into our
1127 * copy so we can call back into Netscape later. Note that
1128 * we need to copy the fields one by one, rather than assigning
1129 * the whole structure, because the Netscape function table
1130 * could actually be bigger than what we expect.
1132 gNetscapeFuncs.version = nsTable->version;
1133 gNetscapeFuncs.size = nsTable->size;
1134 gNetscapeFuncs.posturl = nsTable->posturl;
1135 gNetscapeFuncs.geturl = nsTable->geturl;
1136 gNetscapeFuncs.requestread = nsTable->requestread;
1137 gNetscapeFuncs.newstream = nsTable->newstream;
1138 gNetscapeFuncs.write = nsTable->write;
1139 gNetscapeFuncs.destroystream = nsTable->destroystream;
1140 gNetscapeFuncs.status = nsTable->status;
1141 gNetscapeFuncs.uagent = nsTable->uagent;
1142 gNetscapeFuncs.memalloc = nsTable->memalloc;
1143 gNetscapeFuncs.memfree = nsTable->memfree;
1144 gNetscapeFuncs.memflush = nsTable->memflush;
1145 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1146 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1148 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
1149 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
1151 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1153 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
1154 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
1157 gNetscapeFuncs.getvalue = nsTable->getvalue;
1158 gNetscapeFuncs.setvalue = nsTable->setvalue;
1159 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
1160 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1161 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
1162 if( navMinorVers >= 14 )
1164 // NPRuntime support
1165 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
1166 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1167 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
1168 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
1169 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
1170 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
1171 gNetscapeFuncs.createobject = nsTable->createobject;
1172 gNetscapeFuncs.retainobject = nsTable->retainobject;
1173 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
1174 gNetscapeFuncs.invoke = nsTable->invoke;
1175 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
1176 gNetscapeFuncs.evaluate = nsTable->evaluate;
1177 gNetscapeFuncs.getproperty = nsTable->getproperty;
1178 gNetscapeFuncs.setproperty = nsTable->setproperty;
1179 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
1180 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
1181 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
1182 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
1183 gNetscapeFuncs.setexception = nsTable->setexception;
1185 return NPP_Initialize();
1188 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1190 int navMinorVers = gNetscapeFuncs.version & 0xFF;
1192 PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1194 if( pluginFuncs == NULL )
1195 return NPERR_INVALID_FUNCTABLE_ERROR;
1197 /*if (pluginFuncs->size < sizeof(NPPluginFuncs))
1198 return NPERR_INVALID_FUNCTABLE_ERROR;*/
1201 * Set up the plugin function table that Netscape will use to
1202 * call us. Netscape needs to know about our version and size
1203 * and have a UniversalProcPointer for every function we
1204 * implement.
1207 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1208 pluginFuncs->size = sizeof(NPPluginFuncs);
1209 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
1210 pluginFuncs->newp = NewNPP_NewProc(Private_New);
1211 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
1212 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
1213 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
1214 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1215 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1216 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1217 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
1218 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
1219 pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
1220 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
1221 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
1222 #else
1223 pluginFuncs->newp = (NPP_NewProcPtr)(Private_New);
1224 pluginFuncs->destroy = (NPP_DestroyProcPtr)(Private_Destroy);
1225 pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(Private_SetWindow);
1226 pluginFuncs->newstream = (NPP_NewStreamProcPtr)(Private_NewStream);
1227 pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
1228 pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
1229 pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
1230 pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
1231 pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
1232 pluginFuncs->event = (NPP_HandleEventProcPtr)(Private_HandleEvent);
1233 pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
1234 pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
1235 #endif
1236 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1238 pluginFuncs->urlnotify = Private_URLNotify;
1240 #ifdef OJI
1241 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1243 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1245 #else
1246 pluginFuncs->javaClass = NULL;
1247 #endif
1249 return NPERR_NO_ERROR;
1252 NPError NP_Shutdown(void)
1254 PLUGINDEBUGSTR("\pNP_Shutdown");
1255 NPP_Shutdown();
1256 return NPERR_NO_ERROR;
1259 #endif