1 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
5 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
11 #include <Processes.h>
13 #include <CodeFragments.h>
15 #include <Resources.h>
16 #include <ToolUtils.h>
19 #undef TARGET_RT_MAC_CFM
22 // A4Stuff.h contains the definition of EnterCodeResource and
23 // EnterCodeResource, used for setting up the code resource’s
24 // globals for 68K (analagous to the function SetCurrentA5
25 // defined by the toolbox).
27 // A4Stuff does not exist as of CW 7. Define them to nothing.
30 #if (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) || defined(__GNUC__)
31 #define EnterCodeResource()
32 #define ExitCodeResource()
40 // The Mixed Mode procInfos defined in npupp.h assume Think C-
41 // style calling conventions. These conventions are used by
42 // Metrowerks with the exception of pointer return types, which
43 // in Metrowerks 68K are returned in A0, instead of the standard
44 // D0. Thus, since NPN_MemAlloc and NPN_UserAgent return pointers,
45 // Mixed Mode will return the values to a 68K plugin in D0, but
46 // a 68K plugin compiled by Metrowerks will expect the result in
47 // A0. The following pragma forces Metrowerks to use D0 instead.
51 #pragma pointers_in_D0
59 #ifdef HAVE_NPFUNCTIONS_H
60 #include "npfunctions.h"
65 #include "../vlcshell.h"
69 #pragma pointers_in_A0
73 // The following fix for static initializers (which fixes a previous
74 // incompatibility with some parts of PowerPlant, was submitted by
81 extern void __InitCode__(void);
83 extern void __sinit(void);
84 #define __InitCode__ __sinit
86 extern void __destroy_global_chain(void);
93 // Define PLUGIN_TRACE to 1 to have the wrapper functions emit
94 // DebugStr messages whenever they are called.
96 #define PLUGIN_TRACE 0
99 #define PLUGINDEBUGSTR(msg) ::DebugStr(msg)
101 #define PLUGINDEBUGSTR(msg) {}
104 #if defined(XP_MACOSX) && defined(__POWERPC__) && (!defined(TARGET_RT_MAC_CFM))
106 // glue for mapping outgoing Macho function pointers to TVectors
114 TFPtoTVGlue setwindow;
115 TFPtoTVGlue newstream;
116 TFPtoTVGlue destroystream;
118 TFPtoTVGlue writeready;
122 TFPtoTVGlue urlnotify;
123 TFPtoTVGlue getvalue;
124 TFPtoTVGlue setvalue;
126 TFPtoTVGlue shutdown;
127 } gPluginFuncsGlueTable;
129 static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
131 functionGlue->glue[0] = fp;
132 functionGlue->glue[1] = 0;
136 #define PLUGIN_TO_HOST_GLUE(name, fp) (SetupFPtoTVGlue(&gPluginFuncsGlueTable.name, (void*)fp))
138 // glue for mapping netscape TVectors to Macho function pointers
146 TTVtoFPGlue requestread;
147 TTVtoFPGlue newstream;
149 TTVtoFPGlue destroystream;
152 TTVtoFPGlue memalloc;
154 TTVtoFPGlue memflush;
155 TTVtoFPGlue reloadplugins;
156 TTVtoFPGlue getJavaEnv;
157 TTVtoFPGlue getJavaPeer;
158 TTVtoFPGlue geturlnotify;
159 TTVtoFPGlue posturlnotify;
160 TTVtoFPGlue getvalue;
161 TTVtoFPGlue setvalue;
162 TTVtoFPGlue invalidaterect;
163 TTVtoFPGlue invalidateregion;
164 TTVtoFPGlue forceredraw;
166 TTVtoFPGlue getstringidentifier;
167 TTVtoFPGlue getstringidentifiers;
168 TTVtoFPGlue getintidentifier;
169 TTVtoFPGlue identifierisstring;
170 TTVtoFPGlue utf8fromidentifier;
171 TTVtoFPGlue intfromidentifier;
172 TTVtoFPGlue createobject;
173 TTVtoFPGlue retainobject;
174 TTVtoFPGlue releaseobject;
176 TTVtoFPGlue invokeDefault;
177 TTVtoFPGlue evaluate;
178 TTVtoFPGlue getproperty;
179 TTVtoFPGlue setproperty;
180 TTVtoFPGlue removeproperty;
181 TTVtoFPGlue hasproperty;
182 TTVtoFPGlue hasmethod;
183 TTVtoFPGlue releasevariantvalue;
184 TTVtoFPGlue setexception;
185 } gNetscapeFuncsGlueTable;
187 static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
189 static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
191 memcpy(functionGlue, &glueTemplate, sizeof(TTVtoFPGlue));
192 functionGlue->glue[0] |= ((UInt32)tvp >> 16);
193 functionGlue->glue[1] |= ((UInt32)tvp & 0xFFFF);
194 ::MakeDataExecutable(functionGlue, sizeof(TTVtoFPGlue));
198 #define HOST_TO_PLUGIN_GLUE(name, fp) (SetupTVtoFPGlue(&gNetscapeFuncsGlueTable.name, (void*)fp))
202 #define PLUGIN_TO_HOST_GLUE(name, fp) (fp)
203 #define HOST_TO_PLUGIN_GLUE(name, fp) (fp)
205 #endif /* XP_MACOSX */
211 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
215 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
217 #if !TARGET_API_MAC_CARBON
218 QDGlobals* gQDPtr; // Pointer to Netscape’s QuickDraw globals
220 short gResFile; // Refnum of the plugin’s resource file
221 NPNetscapeFuncs gNetscapeFuncs; // Function table for procs in Netscape called by plugin
223 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
225 // Wrapper functions for all calls from the plugin to Netscape.
226 // These functions let the plugin developer just call the APIs
227 // as documented and defined in npapi.h, without needing to know
228 // about the function table and call macros in npupp.h.
230 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
233 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
235 *plugin_major = NP_VERSION_MAJOR;
236 *plugin_minor = NP_VERSION_MINOR;
237 *netscape_major = gNetscapeFuncs.version >> 8; // Major version is in high byte
238 *netscape_minor = gNetscapeFuncs.version & 0xFF; // Minor version is in low byte
241 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
243 int navMinorVers = gNetscapeFuncs.version & 0xFF;
246 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
248 err = CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
252 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
257 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
259 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
262 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
264 int navMinorVers = gNetscapeFuncs.version & 0xFF;
267 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
269 err = CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify, instance, url,
270 window, len, buf, file, notifyData);
274 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
279 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
281 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, url, window, len, buf, file);
284 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
286 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, stream, rangeList);
289 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream)
291 int navMinorVers = gNetscapeFuncs.version & 0xFF;
294 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
296 err = CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, type, window, stream);
300 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
305 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
307 int navMinorVers = gNetscapeFuncs.version & 0xFF;
310 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
312 err = CallNPN_WriteProc(gNetscapeFuncs.write, instance, stream, len, buffer);
316 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
321 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
323 int navMinorVers = gNetscapeFuncs.version & 0xFF;
326 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
328 err = CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, instance, stream, reason);
332 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
337 void NPN_Status(NPP instance, const char* message)
339 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
342 const char* NPN_UserAgent(NPP instance)
344 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
347 void* NPN_MemAlloc(uint32 size)
349 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
352 void NPN_MemFree(void* ptr)
354 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
357 uint32 NPN_MemFlush(uint32 size)
359 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
362 void NPN_ReloadPlugins(NPBool reloadPages)
364 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
368 JRIEnv* NPN_GetJavaEnv(void)
370 return CallNPN_GetJavaEnvProc( gNetscapeFuncs.getJavaEnv );
373 jobject NPN_GetJavaPeer(NPP instance)
375 return CallNPN_GetJavaPeerProc( gNetscapeFuncs.getJavaPeer, instance );
379 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
381 return CallNPN_GetValueProc( gNetscapeFuncs.getvalue, instance, variable, value);
384 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
386 return CallNPN_SetValueProc( gNetscapeFuncs.setvalue, instance, variable, value);
389 void NPN_InvalidateRect(NPP instance, NPRect *rect)
391 CallNPN_InvalidateRectProc( gNetscapeFuncs.invalidaterect, instance, rect);
394 void NPN_InvalidateRegion(NPP instance, NPRegion region)
396 CallNPN_InvalidateRegionProc( gNetscapeFuncs.invalidateregion, instance, region);
399 void NPN_ForceRedraw(NPP instance)
401 CallNPN_ForceRedrawProc( gNetscapeFuncs.forceredraw, instance);
404 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
406 int navMinorVers = gNetscapeFuncs.version & 0xFF;
407 if( navMinorVers >= 14 )
409 return CallNPN_GetStringIdentifierProc( gNetscapeFuncs.getstringidentifier, name);
414 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
416 int navMinorVers = gNetscapeFuncs.version & 0xFF;
417 if( navMinorVers >= 14 )
419 CallNPN_GetStringIdentifiersProc( gNetscapeFuncs.getstringidentifiers, names, nameCount, identifiers);
423 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
425 int navMinorVers = gNetscapeFuncs.version & 0xFF;
426 if( navMinorVers >= 14 )
428 return CallNPN_GetIntIdentifierProc( gNetscapeFuncs.getintidentifier, intid);
433 bool NPN_IdentifierIsString(NPIdentifier identifier)
435 int navMinorVers = gNetscapeFuncs.version & 0xFF;
436 if( navMinorVers >= 14 )
438 return CallNPN_IdentifierIsStringProc( gNetscapeFuncs.identifierisstring, identifier);
443 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
445 int navMinorVers = gNetscapeFuncs.version & 0xFF;
446 if( navMinorVers >= 14 )
448 return CallNPN_UTF8FromIdentifierProc( gNetscapeFuncs.utf8fromidentifier, identifier);
453 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
455 int navMinorVers = gNetscapeFuncs.version & 0xFF;
456 if( navMinorVers >= 14 )
458 return CallNPN_IntFromIdentifierProc( gNetscapeFuncs.intfromidentifier, identifier);
463 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
465 int navMinorVers = gNetscapeFuncs.version & 0xFF;
466 if( navMinorVers >= 14 )
468 return CallNPN_CreateObjectProc( gNetscapeFuncs.createobject, instance, aClass);
473 NPObject *NPN_RetainObject(NPObject *npobj)
475 int navMinorVers = gNetscapeFuncs.version & 0xFF;
476 if( navMinorVers >= 14 )
478 return CallNPN_RetainObjectProc( gNetscapeFuncs.retainobject, npobj);
483 void NPN_ReleaseObject(NPObject *npobj)
485 int navMinorVers = gNetscapeFuncs.version & 0xFF;
486 if( navMinorVers >= 14 )
488 CallNPN_ReleaseObjectProc( gNetscapeFuncs.releaseobject, npobj);
492 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
494 int navMinorVers = gNetscapeFuncs.version & 0xFF;
495 if( navMinorVers >= 14 )
497 return CallNPN_InvokeProc( gNetscapeFuncs.invoke, instance, npobj, methodName, args, argCount, result);
502 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
504 int navMinorVers = gNetscapeFuncs.version & 0xFF;
505 if( navMinorVers >= 14 )
507 return CallNPN_InvokeDefaultProc( gNetscapeFuncs.invokeDefault, instance, npobj, args, argCount, result);
512 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
514 int navMinorVers = gNetscapeFuncs.version & 0xFF;
515 if( navMinorVers >= 14 )
517 return CallNPN_EvaluateProc( gNetscapeFuncs.evaluate, instance, npobj, script, result);
522 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
524 int navMinorVers = gNetscapeFuncs.version & 0xFF;
525 if( navMinorVers >= 14 )
527 return CallNPN_GetPropertyProc( gNetscapeFuncs.getproperty, instance, npobj, propertyName, result);
532 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
534 int navMinorVers = gNetscapeFuncs.version & 0xFF;
535 if( navMinorVers >= 14 )
537 return CallNPN_SetPropertyProc( gNetscapeFuncs.setproperty, instance, npobj, propertyName, value);
542 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
544 int navMinorVers = gNetscapeFuncs.version & 0xFF;
545 if( navMinorVers >= 14 )
547 return CallNPN_RemovePropertyProc( gNetscapeFuncs.removeproperty, instance, npobj, propertyName);
552 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
554 int navMinorVers = gNetscapeFuncs.version & 0xFF;
555 if( navMinorVers >= 14 )
557 return CallNPN_HasPropertyProc( gNetscapeFuncs.hasproperty, instance, npobj, propertyName);
562 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
564 int navMinorVers = gNetscapeFuncs.version & 0xFF;
565 if( navMinorVers >= 14 )
567 return CallNPN_HasMethodProc( gNetscapeFuncs.hasmethod, instance, npobj, methodName);
572 void NPN_ReleaseVariantValue(NPVariant *variant)
574 int navMinorVers = gNetscapeFuncs.version & 0xFF;
575 if( navMinorVers >= 14 )
577 CallNPN_ReleaseVariantValueProc( gNetscapeFuncs.releasevariantvalue, variant);
581 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
583 int navMinorVers = gNetscapeFuncs.version & 0xFF;
584 if( navMinorVers >= 14 )
586 CallNPN_SetExceptionProc( gNetscapeFuncs.setexception, npobj, message);
592 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
594 // Wrapper functions for all calls from Netscape to the plugin.
595 // These functions let the plugin developer just create the APIs
596 // as documented and defined in npapi.h, without needing to
597 // install those functions in the function table or worry about
598 // setting up globals for 68K plugins.
600 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
602 NPError Private_Initialize(void);
603 void Private_Shutdown(void);
604 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
605 NPError Private_Destroy(NPP instance, NPSavedData** save);
606 NPError Private_SetWindow(NPP instance, NPWindow* window);
607 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value );
608 NPError Private_SetValue( NPP instance, NPPVariable variable, void *value );
609 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
610 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
611 int32 Private_WriteReady(NPP instance, NPStream* stream);
612 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer);
613 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
614 void Private_Print(NPP instance, NPPrint* platformPrint);
615 int16 Private_HandleEvent(NPP instance, void* event);
616 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData);
617 jobject Private_GetJavaClass(void);
620 NPError Private_Initialize(void)
624 PLUGINDEBUGSTR("\pInitialize;g;");
625 err = NPP_Initialize();
630 void Private_Shutdown(void)
633 PLUGINDEBUGSTR("\pShutdown;g;");
637 __destroy_global_chain();
643 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
646 NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
647 PLUGINDEBUGSTR("\pNew;g;");
652 NPError Private_Destroy(NPP instance, NPSavedData** save)
656 PLUGINDEBUGSTR("\pDestroy;g;");
657 err = NPP_Destroy(instance, save);
662 NPError Private_SetWindow(NPP instance, NPWindow* window)
666 PLUGINDEBUGSTR("\pSetWindow;g;");
667 err = NPP_SetWindow(instance, window);
672 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
676 PLUGINDEBUGSTR("\pGetValue;g;");
677 err = NPP_GetValue(instance, variable, value);
682 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
686 PLUGINDEBUGSTR("\pSetValue;g;");
687 err = NPP_SetValue(instance, variable, value);
692 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
696 PLUGINDEBUGSTR("\pNewStream;g;");
697 err = NPP_NewStream(instance, type, stream, seekable, stype);
702 int32 Private_WriteReady(NPP instance, NPStream* stream)
706 PLUGINDEBUGSTR("\pWriteReady;g;");
707 result = NPP_WriteReady(instance, stream);
712 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
716 PLUGINDEBUGSTR("\pWrite;g;");
717 result = NPP_Write(instance, stream, offset, len, buffer);
722 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
725 PLUGINDEBUGSTR("\pStreamAsFile;g;");
726 NPP_StreamAsFile(instance, stream, fname);
730 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
734 PLUGINDEBUGSTR("\pDestroyStream;g;");
735 err = NPP_DestroyStream(instance, stream, reason);
740 int16 Private_HandleEvent(NPP instance, void* event)
744 PLUGINDEBUGSTR("\pHandleEvent;g;");
745 result = NPP_HandleEvent(instance, event);
750 void Private_Print(NPP instance, NPPrint* platformPrint)
753 PLUGINDEBUGSTR("\pPrint;g;");
754 NPP_Print(instance, platformPrint);
758 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
761 PLUGINDEBUGSTR("\pURLNotify;g;");
762 NPP_URLNotify(instance, url, reason, notifyData);
767 jobject Private_GetJavaClass(void)
770 PLUGINDEBUGSTR("\pGetJavaClass;g;");
772 jobject clazz = NPP_GetJavaClass();
776 JRIEnv* env = NPN_GetJavaEnv();
777 return (jobject)JRI_NewGlobalRef(env, clazz);
786 #if !TARGET_API_MAC_CARBON
787 ProcessSerialNumber PSN;
790 ProcessInfoRec infoRec;
791 OSErr result = noErr;
792 CFragConnectionID connID;
797 // Memorize the plugin’s resource file
798 // refnum for later use.
800 gResFile = CurResFile();
802 #if !TARGET_API_MAC_CARBON
804 // Ask the system if CFM is available.
807 OSErr err = Gestalt(gestaltCFMAttr, &response);
808 Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
810 ProcessInfoRec infoRec;
814 // GetProcessInformation takes a process serial number and
815 // will give us back the name and FSSpec of the application.
816 // See the Process Manager in IM.
820 infoRec.processInfoLength = sizeof(ProcessInfoRec);
821 infoRec.processName = name;
822 infoRec.processAppSpec = &myFSSpec;
824 ProcessSerialNumber PSN;
825 PSN.highLongOfPSN = 0;
826 PSN.lowLongOfPSN = kCurrentProcess;
828 result = GetProcessInformation(&PSN, &infoRec);
830 PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
834 // If no CFM installed, assume it must be a 68K app.
838 CFragConnectionID connID;
842 // Now that we know the app name and FSSpec, we can call GetDiskFragment
843 // to get a connID to use in a subsequent call to FindSymbol (it will also
844 // return the address of “main” in app, which we ignore). If GetDiskFragment
845 // returns an error, we assume the app must be 68K.
849 result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
850 kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
856 // The app is a PPC code fragment, so call FindSymbol
857 // to get the exported “qd” symbol so we can access its
858 // QuickDraw globals.
860 CFragSymbolClass symClass;
861 result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
862 if (result != noErr) { // this fails if we are in NS 6
863 gQDPtr = &qd; // so we default to the standard QD globals
869 // The app is 68K, so use its A5 to compute the address
870 // of its QuickDraw globals.
872 gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
879 // gcc requires that main have an 'int' return type
880 int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
882 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
885 #if !TARGET_API_MAC_CARBON
888 #if TARGET_RT_MAC_CFM
890 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
895 #endif /* !TARGET_API_MAC_CARBON */
898 DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
900 DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
904 PLUGINDEBUGSTR("\pmain");
910 NPError err = NPERR_NO_ERROR;
913 // Ensure that everything Netscape passed us is valid!
915 if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
916 err = NPERR_INVALID_FUNCTABLE_ERROR;
919 // Check the “major” version passed in Netscape’s function table.
920 // We won’t load if the major version is newer than what we expect.
921 // Also check that the function tables passed in are big enough for
922 // all the functions we need (they could be bigger, if Netscape added
923 // new APIs, but that’s OK with us -- we’ll just ignore them).
925 if (err == NPERR_NO_ERROR)
927 if ((nsTable->version >> 8) > NP_VERSION_MAJOR) // Major version is in high byte
928 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
931 if (err == NPERR_NO_ERROR)
934 // Copy all the fields of Netscape’s function table into our
935 // copy so we can call back into Netscape later. Note that
936 // we need to copy the fields one by one, rather than assigning
937 // the whole structure, because the Netscape function table
938 // could actually be bigger than what we expect.
941 int navMinorVers = nsTable->version & 0xFF;
943 gNetscapeFuncs.version = nsTable->version;
944 gNetscapeFuncs.size = nsTable->size;
945 gNetscapeFuncs.posturl = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
946 gNetscapeFuncs.geturl = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
947 gNetscapeFuncs.requestread = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
948 gNetscapeFuncs.newstream = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
949 gNetscapeFuncs.write = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
950 gNetscapeFuncs.destroystream = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
951 gNetscapeFuncs.status = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
952 gNetscapeFuncs.uagent = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
953 gNetscapeFuncs.memalloc = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
954 gNetscapeFuncs.memfree = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
955 gNetscapeFuncs.memflush = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
956 gNetscapeFuncs.reloadplugins = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
957 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
959 gNetscapeFuncs.getJavaEnv = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
960 gNetscapeFuncs.getJavaPeer = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
962 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
964 gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
965 gNetscapeFuncs.posturlnotify = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
967 gNetscapeFuncs.getvalue = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
968 gNetscapeFuncs.setvalue = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
969 gNetscapeFuncs.invalidaterect = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
970 gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
971 gNetscapeFuncs.forceredraw = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
972 if( navMinorVers >= 14 )
975 gNetscapeFuncs.getstringidentifier = (NPN_GetStringIdentifierUPP)HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
976 gNetscapeFuncs.getstringidentifiers = (NPN_GetStringIdentifiersUPP)HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
977 gNetscapeFuncs.getintidentifier = (NPN_GetIntIdentifierUPP)HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
978 gNetscapeFuncs.identifierisstring = (NPN_IdentifierIsStringUPP)HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
979 gNetscapeFuncs.utf8fromidentifier = (NPN_UTF8FromIdentifierUPP)HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
980 gNetscapeFuncs.intfromidentifier = (NPN_IntFromIdentifierUPP)HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
981 gNetscapeFuncs.createobject = (NPN_CreateObjectUPP)HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
982 gNetscapeFuncs.retainobject = (NPN_RetainObjectUPP)HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
983 gNetscapeFuncs.releaseobject = (NPN_ReleaseObjectUPP)HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
984 gNetscapeFuncs.invoke = (NPN_InvokeUPP)HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
985 gNetscapeFuncs.invokeDefault = (NPN_InvokeDefaultUPP)HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
986 gNetscapeFuncs.evaluate = (NPN_EvaluateUPP)HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
987 gNetscapeFuncs.getproperty = (NPN_GetPropertyUPP)HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
988 gNetscapeFuncs.setproperty = (NPN_SetPropertyUPP)HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
989 gNetscapeFuncs.removeproperty = (NPN_RemovePropertyUPP)HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
990 gNetscapeFuncs.hasproperty = (NPN_HasPropertyUPP)HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
991 gNetscapeFuncs.hasmethod = (NPN_HasMethodUPP)HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
992 gNetscapeFuncs.releasevariantvalue = (NPN_ReleaseVariantValueUPP)HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
993 gNetscapeFuncs.setexception = (NPN_SetExceptionUPP)HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
997 // Set up the plugin function table that Netscape will use to
998 // call us. Netscape needs to know about our version and size
999 // and have a UniversalProcPointer for every function we implement.
1001 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1002 pluginFuncs->size = sizeof(NPPluginFuncs);
1003 pluginFuncs->newp = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1004 pluginFuncs->destroy = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1005 pluginFuncs->setwindow = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1006 pluginFuncs->newstream = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1007 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1008 pluginFuncs->asfile = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1009 pluginFuncs->writeready = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1010 pluginFuncs->write = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1011 pluginFuncs->print = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1012 pluginFuncs->event = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1013 pluginFuncs->getvalue = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1014 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1016 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1019 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1021 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1024 pluginFuncs->javaClass = NULL;
1026 *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1029 err = Private_Initialize();
1039 ** netscape plugins functions when building Mach-O binary
1043 NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1044 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1045 NPError NP_Shutdown(void);
1049 ** netscape plugins functions when using Mach-O binary
1052 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1054 PLUGINDEBUGSTR("\pNP_Initialize");
1056 /* validate input parameters */
1058 if( NULL == nsTable )
1059 return NPERR_INVALID_FUNCTABLE_ERROR;
1062 * Check the major version passed in Netscape's function table.
1063 * We won't load if the major version is newer than what we expect.
1064 * Also check that the function tables passed in are big enough for
1065 * all the functions we need (they could be bigger, if Netscape added
1066 * new APIs, but that's OK with us -- we'll just ignore them).
1070 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1071 return NPERR_INCOMPATIBLE_VERSION_ERROR;
1073 if (nsTable->size < sizeof(NPNetscapeFuncs))
1074 return NPERR_INVALID_FUNCTABLE_ERROR;
1076 int navMinorVers = nsTable->version & 0xFF;
1079 * Copy all the fields of Netscape function table into our
1080 * copy so we can call back into Netscape later. Note that
1081 * we need to copy the fields one by one, rather than assigning
1082 * the whole structure, because the Netscape function table
1083 * could actually be bigger than what we expect.
1085 gNetscapeFuncs.version = nsTable->version;
1086 gNetscapeFuncs.size = nsTable->size;
1087 gNetscapeFuncs.posturl = nsTable->posturl;
1088 gNetscapeFuncs.geturl = nsTable->geturl;
1089 gNetscapeFuncs.requestread = nsTable->requestread;
1090 gNetscapeFuncs.newstream = nsTable->newstream;
1091 gNetscapeFuncs.write = nsTable->write;
1092 gNetscapeFuncs.destroystream = nsTable->destroystream;
1093 gNetscapeFuncs.status = nsTable->status;
1094 gNetscapeFuncs.uagent = nsTable->uagent;
1095 gNetscapeFuncs.memalloc = nsTable->memalloc;
1096 gNetscapeFuncs.memfree = nsTable->memfree;
1097 gNetscapeFuncs.memflush = nsTable->memflush;
1098 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1099 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1101 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
1102 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
1104 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1106 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
1107 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
1110 gNetscapeFuncs.getvalue = nsTable->getvalue;
1111 gNetscapeFuncs.setvalue = nsTable->setvalue;
1112 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
1113 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1114 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
1115 if( navMinorVers >= 14 )
1117 // NPRuntime support
1118 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
1119 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1120 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
1121 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
1122 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
1123 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
1124 gNetscapeFuncs.createobject = nsTable->createobject;
1125 gNetscapeFuncs.retainobject = nsTable->retainobject;
1126 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
1127 gNetscapeFuncs.invoke = nsTable->invoke;
1128 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
1129 gNetscapeFuncs.evaluate = nsTable->evaluate;
1130 gNetscapeFuncs.getproperty = nsTable->getproperty;
1131 gNetscapeFuncs.setproperty = nsTable->setproperty;
1132 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
1133 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
1134 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
1135 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
1136 gNetscapeFuncs.setexception = nsTable->setexception;
1138 return NPP_Initialize();
1141 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1143 int navMinorVers = gNetscapeFuncs.version & 0xFF;
1145 PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1147 if( pluginFuncs == NULL )
1148 return NPERR_INVALID_FUNCTABLE_ERROR;
1150 /*if (pluginFuncs->size < sizeof(NPPluginFuncs))
1151 return NPERR_INVALID_FUNCTABLE_ERROR;*/
1154 * Set up the plugin function table that Netscape will use to
1155 * call us. Netscape needs to know about our version and size
1156 * and have a UniversalProcPointer for every function we
1160 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1161 pluginFuncs->size = sizeof(NPPluginFuncs);
1162 pluginFuncs->newp = NewNPP_NewProc(Private_New);
1163 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
1164 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
1165 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
1166 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1167 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1168 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1169 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
1170 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
1171 pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
1172 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
1173 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
1174 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1176 pluginFuncs->urlnotify = Private_URLNotify;
1179 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1181 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1184 pluginFuncs->javaClass = NULL;
1187 return NPERR_NO_ERROR;
1190 NPError NP_Shutdown(void)
1192 PLUGINDEBUGSTR("\pNP_Shutdown");
1194 return NPERR_NO_ERROR;