1 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
5 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
11 #include <CodeFragments.h>
13 #include <Resources.h>
14 #include <ToolUtils.h>
17 #undef TARGET_RT_MAC_CFM
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).
25 // A4Stuff does not exist as of CW 7. Define them to nothing.
28 #if (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) || defined(__GNUC__)
29 #define EnterCodeResource()
30 #define ExitCodeResource()
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.
49 #pragma pointers_in_D0
61 #pragma pointers_in_A0
65 // The following fix for static initializers (which fixes a previous
66 // incompatibility with some parts of PowerPlant, was submitted by
73 extern void __InitCode__(void);
75 extern void __sinit(void);
76 #define __InitCode__ __sinit
78 extern void __destroy_global_chain(void);
85 // Define PLUGIN_TRACE to 1 to have the wrapper functions emit
86 // DebugStr messages whenever they are called.
88 #define PLUGIN_TRACE 0
91 #define PLUGINDEBUGSTR(msg) ::DebugStr(msg)
93 #define PLUGINDEBUGSTR(msg) {}
97 #if defined(XP_MACOSX) && defined(__POWERPC__) && (!defined(TARGET_RT_MAC_CFM))
99 // glue for mapping outgoing Macho function pointers to TVectors
107 TFPtoTVGlue setwindow;
108 TFPtoTVGlue newstream;
109 TFPtoTVGlue destroystream;
111 TFPtoTVGlue writeready;
115 TFPtoTVGlue urlnotify;
116 TFPtoTVGlue getvalue;
117 TFPtoTVGlue setvalue;
119 TFPtoTVGlue shutdown;
120 } gPluginFuncsGlueTable;
122 static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
124 functionGlue->glue[0] = fp;
125 functionGlue->glue[1] = 0;
129 #define PLUGIN_TO_HOST_GLUE(name, fp) (SetupFPtoTVGlue(&gPluginFuncsGlueTable.name, (void*)fp))
131 // glue for mapping netscape TVectors to Macho function pointers
139 TTVtoFPGlue requestread;
140 TTVtoFPGlue newstream;
142 TTVtoFPGlue destroystream;
145 TTVtoFPGlue memalloc;
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;
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;
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;
180 static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
182 static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
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));
191 #define HOST_TO_PLUGIN_GLUE(name, fp) (SetupTVtoFPGlue(&gNetscapeFuncsGlueTable.name, (void*)fp))
195 #define PLUGIN_TO_HOST_GLUE(name, fp) (fp)
196 #define HOST_TO_PLUGIN_GLUE(name, fp) (fp)
198 #endif /* XP_MACOSX */
204 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
208 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
210 #if !TARGET_API_MAC_CARBON
211 QDGlobals* gQDPtr; // Pointer to Netscape’s QuickDraw globals
213 short gResFile; // Refnum of the plugin’s resource file
214 NPNetscapeFuncs gNetscapeFuncs; // Function table for procs in Netscape called by plugin
216 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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.
223 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
226 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
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
234 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
236 int navMinorVers = gNetscapeFuncs.version & 0xFF;
239 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
241 err = CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
245 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
250 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
252 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
255 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
257 int navMinorVers = gNetscapeFuncs.version & 0xFF;
260 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
262 err = CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify, instance, url,
263 window, len, buf, file, notifyData);
267 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
272 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
274 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, url, window, len, buf, file);
277 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
279 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, stream, rangeList);
282 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream)
284 int navMinorVers = gNetscapeFuncs.version & 0xFF;
287 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
289 err = CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, type, window, stream);
293 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
298 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
300 int navMinorVers = gNetscapeFuncs.version & 0xFF;
303 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
305 err = CallNPN_WriteProc(gNetscapeFuncs.write, instance, stream, len, buffer);
309 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
314 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
316 int navMinorVers = gNetscapeFuncs.version & 0xFF;
319 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
321 err = CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, instance, stream, reason);
325 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
330 void NPN_Status(NPP instance, const char* message)
332 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
335 const char* NPN_UserAgent(NPP instance)
337 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
340 void* NPN_MemAlloc(uint32 size)
342 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
345 void NPN_MemFree(void* ptr)
347 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
350 uint32 NPN_MemFlush(uint32 size)
352 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
355 void NPN_ReloadPlugins(NPBool reloadPages)
357 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
361 JRIEnv* NPN_GetJavaEnv(void)
363 return CallNPN_GetJavaEnvProc( gNetscapeFuncs.getJavaEnv );
366 jobject NPN_GetJavaPeer(NPP instance)
368 return CallNPN_GetJavaPeerProc( gNetscapeFuncs.getJavaPeer, instance );
372 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
374 return CallNPN_GetValueProc( gNetscapeFuncs.getvalue, instance, variable, value);
377 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
379 return CallNPN_SetValueProc( gNetscapeFuncs.setvalue, instance, variable, value);
382 void NPN_InvalidateRect(NPP instance, NPRect *rect)
384 CallNPN_InvalidateRectProc( gNetscapeFuncs.invalidaterect, instance, rect);
387 void NPN_InvalidateRegion(NPP instance, NPRegion region)
389 CallNPN_InvalidateRegionProc( gNetscapeFuncs.invalidateregion, instance, region);
392 void NPN_ForceRedraw(NPP instance)
394 CallNPN_ForceRedrawProc( gNetscapeFuncs.forceredraw, instance);
397 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
399 int navMinorVers = gNetscapeFuncs.version & 0xFF;
400 if( navMinorVers >= 14 )
402 return CallNPN_GetStringIdentifierProc( gNetscapeFuncs.getstringidentifier, name);
407 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
409 int navMinorVers = gNetscapeFuncs.version & 0xFF;
410 if( navMinorVers >= 14 )
412 CallNPN_GetStringIdentifiersProc( gNetscapeFuncs.getstringidentifiers, names, nameCount, identifiers);
416 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
418 int navMinorVers = gNetscapeFuncs.version & 0xFF;
419 if( navMinorVers >= 14 )
421 return CallNPN_GetIntIdentifierProc( gNetscapeFuncs.getintidentifier, intid);
426 bool NPN_IdentifierIsString(NPIdentifier identifier)
428 int navMinorVers = gNetscapeFuncs.version & 0xFF;
429 if( navMinorVers >= 14 )
431 return CallNPN_IdentifierIsStringProc( gNetscapeFuncs.identifierisstring, identifier);
436 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
438 int navMinorVers = gNetscapeFuncs.version & 0xFF;
439 if( navMinorVers >= 14 )
441 return CallNPN_UTF8FromIdentifierProc( gNetscapeFuncs.utf8fromidentifier, identifier);
446 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
448 int navMinorVers = gNetscapeFuncs.version & 0xFF;
449 if( navMinorVers >= 14 )
451 return CallNPN_IntFromIdentifierProc( gNetscapeFuncs.intfromidentifier, identifier);
456 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
458 int navMinorVers = gNetscapeFuncs.version & 0xFF;
459 if( navMinorVers >= 14 )
461 return CallNPN_CreateObjectProc( gNetscapeFuncs.createobject, instance, aClass);
466 NPObject *NPN_RetainObject(NPObject *npobj)
468 int navMinorVers = gNetscapeFuncs.version & 0xFF;
469 if( navMinorVers >= 14 )
471 return CallNPN_RetainObjectProc( gNetscapeFuncs.retainobject, npobj);
476 void NPN_ReleaseObject(NPObject *npobj)
478 int navMinorVers = gNetscapeFuncs.version & 0xFF;
479 if( navMinorVers >= 14 )
481 CallNPN_ReleaseObjectProc( gNetscapeFuncs.releaseobject, npobj);
485 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
487 int navMinorVers = gNetscapeFuncs.version & 0xFF;
488 if( navMinorVers >= 14 )
490 return CallNPN_InvokeProc( gNetscapeFuncs.invoke, instance, npobj, methodName, args, argCount, result);
495 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
497 int navMinorVers = gNetscapeFuncs.version & 0xFF;
498 if( navMinorVers >= 14 )
500 return CallNPN_InvokeDefaultProc( gNetscapeFuncs.invokeDefault, instance, npobj, args, argCount, result);
505 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
507 int navMinorVers = gNetscapeFuncs.version & 0xFF;
508 if( navMinorVers >= 14 )
510 return CallNPN_EvaluateProc( gNetscapeFuncs.evaluate, instance, npobj, script, result);
515 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
517 int navMinorVers = gNetscapeFuncs.version & 0xFF;
518 if( navMinorVers >= 14 )
520 return CallNPN_GetPropertyProc( gNetscapeFuncs.getproperty, instance, npobj, propertyName, result);
525 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
527 int navMinorVers = gNetscapeFuncs.version & 0xFF;
528 if( navMinorVers >= 14 )
530 return CallNPN_SetPropertyProc( gNetscapeFuncs.setproperty, instance, npobj, propertyName, value);
535 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
537 int navMinorVers = gNetscapeFuncs.version & 0xFF;
538 if( navMinorVers >= 14 )
540 return CallNPN_RemovePropertyProc( gNetscapeFuncs.removeproperty, instance, npobj, propertyName);
545 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
547 int navMinorVers = gNetscapeFuncs.version & 0xFF;
548 if( navMinorVers >= 14 )
550 return CallNPN_HasPropertyProc( gNetscapeFuncs.hasproperty, instance, npobj, propertyName);
555 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
557 int navMinorVers = gNetscapeFuncs.version & 0xFF;
558 if( navMinorVers >= 14 )
560 return CallNPN_HasMethodProc( gNetscapeFuncs.hasmethod, instance, npobj, methodName);
565 void NPN_ReleaseVariantValue(NPVariant *variant)
567 int navMinorVers = gNetscapeFuncs.version & 0xFF;
568 if( navMinorVers >= 14 )
570 CallNPN_ReleaseVariantValueProc( gNetscapeFuncs.releasevariantvalue, variant);
574 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
576 int navMinorVers = gNetscapeFuncs.version & 0xFF;
577 if( navMinorVers >= 14 )
579 CallNPN_SetExceptionProc( gNetscapeFuncs.setexception, npobj, message);
585 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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.
593 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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);
613 NPError Private_Initialize(void)
617 PLUGINDEBUGSTR("\pInitialize;g;");
618 err = NPP_Initialize();
623 void Private_Shutdown(void)
626 PLUGINDEBUGSTR("\pShutdown;g;");
630 __destroy_global_chain();
636 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
639 NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
640 PLUGINDEBUGSTR("\pNew;g;");
645 NPError Private_Destroy(NPP instance, NPSavedData** save)
649 PLUGINDEBUGSTR("\pDestroy;g;");
650 err = NPP_Destroy(instance, save);
655 NPError Private_SetWindow(NPP instance, NPWindow* window)
659 PLUGINDEBUGSTR("\pSetWindow;g;");
660 err = NPP_SetWindow(instance, window);
665 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
669 PLUGINDEBUGSTR("\pGetValue;g;");
670 err = NPP_GetValue(instance, variable, value);
675 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
679 PLUGINDEBUGSTR("\pSetValue;g;");
680 err = NPP_SetValue(instance, variable, value);
685 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
689 PLUGINDEBUGSTR("\pNewStream;g;");
690 err = NPP_NewStream(instance, type, stream, seekable, stype);
695 int32 Private_WriteReady(NPP instance, NPStream* stream)
699 PLUGINDEBUGSTR("\pWriteReady;g;");
700 result = NPP_WriteReady(instance, stream);
705 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
709 PLUGINDEBUGSTR("\pWrite;g;");
710 result = NPP_Write(instance, stream, offset, len, buffer);
715 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
718 PLUGINDEBUGSTR("\pStreamAsFile;g;");
719 NPP_StreamAsFile(instance, stream, fname);
723 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
727 PLUGINDEBUGSTR("\pDestroyStream;g;");
728 err = NPP_DestroyStream(instance, stream, reason);
733 int16 Private_HandleEvent(NPP instance, void* event)
737 PLUGINDEBUGSTR("\pHandleEvent;g;");
738 result = NPP_HandleEvent(instance, event);
743 void Private_Print(NPP instance, NPPrint* platformPrint)
746 PLUGINDEBUGSTR("\pPrint;g;");
747 NPP_Print(instance, platformPrint);
751 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
754 PLUGINDEBUGSTR("\pURLNotify;g;");
755 NPP_URLNotify(instance, url, reason, notifyData);
760 jobject Private_GetJavaClass(void)
763 PLUGINDEBUGSTR("\pGetJavaClass;g;");
765 jobject clazz = NPP_GetJavaClass();
769 JRIEnv* env = NPN_GetJavaEnv();
770 return (jobject)JRI_NewGlobalRef(env, clazz);
779 #if !TARGET_API_MAC_CARBON
780 ProcessSerialNumber PSN;
783 ProcessInfoRec infoRec;
784 OSErr result = noErr;
785 CFragConnectionID connID;
790 // Memorize the plugin’s resource file
791 // refnum for later use.
793 gResFile = CurResFile();
795 #if !TARGET_API_MAC_CARBON
797 // Ask the system if CFM is available.
800 OSErr err = Gestalt(gestaltCFMAttr, &response);
801 Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
803 ProcessInfoRec infoRec;
807 // GetProcessInformation takes a process serial number and
808 // will give us back the name and FSSpec of the application.
809 // See the Process Manager in IM.
813 infoRec.processInfoLength = sizeof(ProcessInfoRec);
814 infoRec.processName = name;
815 infoRec.processAppSpec = &myFSSpec;
817 ProcessSerialNumber PSN;
818 PSN.highLongOfPSN = 0;
819 PSN.lowLongOfPSN = kCurrentProcess;
821 result = GetProcessInformation(&PSN, &infoRec);
823 PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
827 // If no CFM installed, assume it must be a 68K app.
831 CFragConnectionID connID;
835 // Now that we know the app name and FSSpec, we can call GetDiskFragment
836 // to get a connID to use in a subsequent call to FindSymbol (it will also
837 // return the address of “main” in app, which we ignore). If GetDiskFragment
838 // returns an error, we assume the app must be 68K.
842 result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
843 kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
849 // The app is a PPC code fragment, so call FindSymbol
850 // to get the exported “qd” symbol so we can access its
851 // QuickDraw globals.
853 CFragSymbolClass symClass;
854 result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
855 if (result != noErr) { // this fails if we are in NS 6
856 gQDPtr = &qd; // so we default to the standard QD globals
862 // The app is 68K, so use its A5 to compute the address
863 // of its QuickDraw globals.
865 gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
872 // gcc requires that main have an 'int' return type
873 int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
875 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
878 #if !TARGET_API_MAC_CARBON
881 #if TARGET_RT_MAC_CFM
883 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
888 #endif /* !TARGET_API_MAC_CARBON */
891 DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
893 DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
897 PLUGINDEBUGSTR("\pmain");
903 NPError err = NPERR_NO_ERROR;
906 // Ensure that everything Netscape passed us is valid!
908 if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
909 err = NPERR_INVALID_FUNCTABLE_ERROR;
912 // Check the “major” version passed in Netscape’s function table.
913 // We won’t load if the major version is newer than what we expect.
914 // Also check that the function tables passed in are big enough for
915 // all the functions we need (they could be bigger, if Netscape added
916 // new APIs, but that’s OK with us -- we’ll just ignore them).
918 if (err == NPERR_NO_ERROR)
920 if ((nsTable->version >> 8) > NP_VERSION_MAJOR) // Major version is in high byte
921 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
924 if (err == NPERR_NO_ERROR)
927 // Copy all the fields of Netscape’s function table into our
928 // copy so we can call back into Netscape later. Note that
929 // we need to copy the fields one by one, rather than assigning
930 // the whole structure, because the Netscape function table
931 // could actually be bigger than what we expect.
934 int navMinorVers = nsTable->version & 0xFF;
936 gNetscapeFuncs.version = nsTable->version;
937 gNetscapeFuncs.size = nsTable->size;
938 gNetscapeFuncs.posturl = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
939 gNetscapeFuncs.geturl = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
940 gNetscapeFuncs.requestread = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
941 gNetscapeFuncs.newstream = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
942 gNetscapeFuncs.write = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
943 gNetscapeFuncs.destroystream = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
944 gNetscapeFuncs.status = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
945 gNetscapeFuncs.uagent = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
946 gNetscapeFuncs.memalloc = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
947 gNetscapeFuncs.memfree = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
948 gNetscapeFuncs.memflush = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
949 gNetscapeFuncs.reloadplugins = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
950 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
952 gNetscapeFuncs.getJavaEnv = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
953 gNetscapeFuncs.getJavaPeer = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
955 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
957 gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
958 gNetscapeFuncs.posturlnotify = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
960 gNetscapeFuncs.getvalue = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
961 gNetscapeFuncs.setvalue = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
962 gNetscapeFuncs.invalidaterect = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
963 gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
964 gNetscapeFuncs.forceredraw = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
965 if( navMinorVers >= 14 )
968 gNetscapeFuncs.getstringidentifier = (NPN_GetStringIdentifierUPP)HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
969 gNetscapeFuncs.getstringidentifiers = (NPN_GetStringIdentifiersUPP)HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
970 gNetscapeFuncs.getintidentifier = (NPN_GetIntIdentifierUPP)HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
971 gNetscapeFuncs.identifierisstring = (NPN_IdentifierIsStringUPP)HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
972 gNetscapeFuncs.utf8fromidentifier = (NPN_UTF8FromIdentifierUPP)HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
973 gNetscapeFuncs.intfromidentifier = (NPN_IntFromIdentifierUPP)HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
974 gNetscapeFuncs.createobject = (NPN_CreateObjectUPP)HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
975 gNetscapeFuncs.retainobject = (NPN_RetainObjectUPP)HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
976 gNetscapeFuncs.releaseobject = (NPN_ReleaseObjectUPP)HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
977 gNetscapeFuncs.invoke = (NPN_InvokeUPP)HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
978 gNetscapeFuncs.invokeDefault = (NPN_InvokeDefaultUPP)HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
979 gNetscapeFuncs.evaluate = (NPN_EvaluateUPP)HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
980 gNetscapeFuncs.getproperty = (NPN_GetPropertyUPP)HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
981 gNetscapeFuncs.setproperty = (NPN_SetPropertyUPP)HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
982 gNetscapeFuncs.removeproperty = (NPN_RemovePropertyUPP)HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
983 gNetscapeFuncs.hasproperty = (NPN_HasPropertyUPP)HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
984 gNetscapeFuncs.hasmethod = (NPN_HasMethodUPP)HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
985 gNetscapeFuncs.releasevariantvalue = (NPN_ReleaseVariantValueUPP)HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
986 gNetscapeFuncs.setexception = (NPN_SetExceptionUPP)HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
990 // Set up the plugin function table that Netscape will use to
991 // call us. Netscape needs to know about our version and size
992 // and have a UniversalProcPointer for every function we implement.
994 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
995 pluginFuncs->size = sizeof(NPPluginFuncs);
996 pluginFuncs->newp = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
997 pluginFuncs->destroy = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
998 pluginFuncs->setwindow = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
999 pluginFuncs->newstream = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1000 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1001 pluginFuncs->asfile = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1002 pluginFuncs->writeready = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1003 pluginFuncs->write = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1004 pluginFuncs->print = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1005 pluginFuncs->event = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1006 pluginFuncs->getvalue = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1007 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1009 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1012 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1014 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1017 pluginFuncs->javaClass = NULL;
1019 *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1022 err = Private_Initialize();
1032 ** netscape plugins functions when building Mach-O binary
1036 NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1037 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1038 NPError NP_Shutdown(void);
1042 ** netscape plugins functions when using Mach-O binary
1045 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1047 PLUGINDEBUGSTR("\pNP_Initialize");
1049 /* validate input parameters */
1051 if( NULL == nsTable )
1052 return NPERR_INVALID_FUNCTABLE_ERROR;
1055 * Check the major version passed in Netscape's function table.
1056 * We won't load if the major version is newer than what we expect.
1057 * Also check that the function tables passed in are big enough for
1058 * all the functions we need (they could be bigger, if Netscape added
1059 * new APIs, but that's OK with us -- we'll just ignore them).
1063 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1064 return NPERR_INCOMPATIBLE_VERSION_ERROR;
1066 if (nsTable->size < sizeof(NPNetscapeFuncs))
1067 return NPERR_INVALID_FUNCTABLE_ERROR;
1069 int navMinorVers = nsTable->version & 0xFF;
1072 * Copy all the fields of Netscape function table into our
1073 * copy so we can call back into Netscape later. Note that
1074 * we need to copy the fields one by one, rather than assigning
1075 * the whole structure, because the Netscape function table
1076 * could actually be bigger than what we expect.
1078 gNetscapeFuncs.version = nsTable->version;
1079 gNetscapeFuncs.size = nsTable->size;
1080 gNetscapeFuncs.posturl = nsTable->posturl;
1081 gNetscapeFuncs.geturl = nsTable->geturl;
1082 gNetscapeFuncs.requestread = nsTable->requestread;
1083 gNetscapeFuncs.newstream = nsTable->newstream;
1084 gNetscapeFuncs.write = nsTable->write;
1085 gNetscapeFuncs.destroystream = nsTable->destroystream;
1086 gNetscapeFuncs.status = nsTable->status;
1087 gNetscapeFuncs.uagent = nsTable->uagent;
1088 gNetscapeFuncs.memalloc = nsTable->memalloc;
1089 gNetscapeFuncs.memfree = nsTable->memfree;
1090 gNetscapeFuncs.memflush = nsTable->memflush;
1091 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1092 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1094 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
1095 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
1097 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1099 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
1100 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
1103 gNetscapeFuncs.getvalue = nsTable->getvalue;
1104 gNetscapeFuncs.setvalue = nsTable->setvalue;
1105 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
1106 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1107 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
1108 if( navMinorVers >= 14 )
1110 // NPRuntime support
1111 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
1112 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1113 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
1114 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
1115 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
1116 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
1117 gNetscapeFuncs.createobject = nsTable->createobject;
1118 gNetscapeFuncs.retainobject = nsTable->retainobject;
1119 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
1120 gNetscapeFuncs.invoke = nsTable->invoke;
1121 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
1122 gNetscapeFuncs.evaluate = nsTable->evaluate;
1123 gNetscapeFuncs.getproperty = nsTable->getproperty;
1124 gNetscapeFuncs.setproperty = nsTable->setproperty;
1125 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
1126 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
1127 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
1128 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
1129 gNetscapeFuncs.setexception = nsTable->setexception;
1131 return NPP_Initialize();
1134 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1136 int navMinorVers = gNetscapeFuncs.version & 0xFF;
1138 PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1140 if( pluginFuncs == NULL )
1141 return NPERR_INVALID_FUNCTABLE_ERROR;
1143 /*if (pluginFuncs->size < sizeof(NPPluginFuncs))
1144 return NPERR_INVALID_FUNCTABLE_ERROR;*/
1147 * Set up the plugin function table that Netscape will use to
1148 * call us. Netscape needs to know about our version and size
1149 * and have a UniversalProcPointer for every function we
1153 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1154 pluginFuncs->size = sizeof(NPPluginFuncs);
1155 pluginFuncs->newp = NewNPP_NewProc(Private_New);
1156 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
1157 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
1158 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
1159 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1160 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1161 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1162 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
1163 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
1164 pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
1165 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
1166 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
1167 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1169 pluginFuncs->urlnotify = Private_URLNotify;
1172 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1174 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1177 pluginFuncs->javaClass = NULL;
1180 return NPERR_NO_ERROR;
1183 NPError NP_Shutdown(void)
1185 PLUGINDEBUGSTR("\pNP_Shutdown");
1187 return NPERR_NO_ERROR;