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 #ifdef XP_MACOSX && !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();
637 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
640 NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
641 PLUGINDEBUGSTR("\pNew;g;");
646 NPError Private_Destroy(NPP instance, NPSavedData** save)
650 PLUGINDEBUGSTR("\pDestroy;g;");
651 err = NPP_Destroy(instance, save);
656 NPError Private_SetWindow(NPP instance, NPWindow* window)
660 PLUGINDEBUGSTR("\pSetWindow;g;");
661 err = NPP_SetWindow(instance, window);
666 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
670 PLUGINDEBUGSTR("\pGetValue;g;");
671 err = NPP_GetValue( instance, variable, value);
676 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
680 PLUGINDEBUGSTR("\pSetValue;g;");
681 err = NPERR_NO_ERROR; //NPP_SetValue( instance, variable, value);
686 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
690 PLUGINDEBUGSTR("\pNewStream;g;");
691 err = NPP_NewStream(instance, type, stream, seekable, stype);
696 int32 Private_WriteReady(NPP instance, NPStream* stream)
700 PLUGINDEBUGSTR("\pWriteReady;g;");
701 result = NPP_WriteReady(instance, stream);
706 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
710 PLUGINDEBUGSTR("\pWrite;g;");
711 result = NPP_Write(instance, stream, offset, len, buffer);
716 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
719 PLUGINDEBUGSTR("\pStreamAsFile;g;");
720 NPP_StreamAsFile(instance, stream, fname);
725 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
729 PLUGINDEBUGSTR("\pDestroyStream;g;");
730 err = NPP_DestroyStream(instance, stream, reason);
735 int16 Private_HandleEvent(NPP instance, void* event)
739 PLUGINDEBUGSTR("\pHandleEvent;g;");
740 result = NPP_HandleEvent(instance, event);
745 void Private_Print(NPP instance, NPPrint* platformPrint)
748 PLUGINDEBUGSTR("\pPrint;g;");
749 NPP_Print(instance, platformPrint);
753 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
756 PLUGINDEBUGSTR("\pURLNotify;g;");
757 NPP_URLNotify(instance, url, reason, notifyData);
762 jobject Private_GetJavaClass(void)
765 PLUGINDEBUGSTR("\pGetJavaClass;g;");
767 jobject clazz = NPP_GetJavaClass();
771 JRIEnv* env = NPN_GetJavaEnv();
772 return (jobject)JRI_NewGlobalRef(env, clazz);
781 #if !TARGET_API_MAC_CARBON
782 ProcessSerialNumber PSN;
785 ProcessInfoRec infoRec;
786 OSErr result = noErr;
787 CFragConnectionID connID;
792 // Memorize the plugin’s resource file
793 // refnum for later use.
795 gResFile = CurResFile();
797 #if !TARGET_API_MAC_CARBON
799 // Ask the system if CFM is available.
802 OSErr err = Gestalt(gestaltCFMAttr, &response);
803 Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
805 ProcessInfoRec infoRec;
809 // GetProcessInformation takes a process serial number and
810 // will give us back the name and FSSpec of the application.
811 // See the Process Manager in IM.
815 infoRec.processInfoLength = sizeof(ProcessInfoRec);
816 infoRec.processName = name;
817 infoRec.processAppSpec = &myFSSpec;
819 ProcessSerialNumber PSN;
820 PSN.highLongOfPSN = 0;
821 PSN.lowLongOfPSN = kCurrentProcess;
823 result = GetProcessInformation(&PSN, &infoRec);
825 PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
829 // If no CFM installed, assume it must be a 68K app.
833 CFragConnectionID connID;
837 // Now that we know the app name and FSSpec, we can call GetDiskFragment
838 // to get a connID to use in a subsequent call to FindSymbol (it will also
839 // return the address of “main” in app, which we ignore). If GetDiskFragment
840 // returns an error, we assume the app must be 68K.
844 result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
845 kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
851 // The app is a PPC code fragment, so call FindSymbol
852 // to get the exported “qd” symbol so we can access its
853 // QuickDraw globals.
855 CFragSymbolClass symClass;
856 result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
857 if (result != noErr) { // this fails if we are in NS 6
858 gQDPtr = &qd; // so we default to the standard QD globals
864 // The app is 68K, so use its A5 to compute the address
865 // of its QuickDraw globals.
867 gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
874 // gcc requires that main have an 'int' return type
875 int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
877 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
880 #if !TARGET_API_MAC_CARBON
883 #if TARGET_RT_MAC_CFM
885 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
890 #endif /* !TARGET_API_MAC_CARBON */
893 DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
895 DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
899 PLUGINDEBUGSTR("\pmain");
905 NPError err = NPERR_NO_ERROR;
908 // Ensure that everything Netscape passed us is valid!
910 if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
911 err = NPERR_INVALID_FUNCTABLE_ERROR;
914 // Check the “major” version passed in Netscape’s function table.
915 // We won’t load if the major version is newer than what we expect.
916 // Also check that the function tables passed in are big enough for
917 // all the functions we need (they could be bigger, if Netscape added
918 // new APIs, but that’s OK with us -- we’ll just ignore them).
920 if (err == NPERR_NO_ERROR)
922 if ((nsTable->version >> 8) > NP_VERSION_MAJOR) // Major version is in high byte
923 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
927 if (err == NPERR_NO_ERROR)
930 // Copy all the fields of Netscape’s function table into our
931 // copy so we can call back into Netscape later. Note that
932 // we need to copy the fields one by one, rather than assigning
933 // the whole structure, because the Netscape function table
934 // could actually be bigger than what we expect.
937 int navMinorVers = nsTable->version & 0xFF;
939 gNetscapeFuncs.version = nsTable->version;
940 gNetscapeFuncs.size = nsTable->size;
941 gNetscapeFuncs.posturl = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
942 gNetscapeFuncs.geturl = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
943 gNetscapeFuncs.requestread = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
944 gNetscapeFuncs.newstream = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
945 gNetscapeFuncs.write = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
946 gNetscapeFuncs.destroystream = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
947 gNetscapeFuncs.status = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
948 gNetscapeFuncs.uagent = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
949 gNetscapeFuncs.memalloc = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
950 gNetscapeFuncs.memfree = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
951 gNetscapeFuncs.memflush = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
952 gNetscapeFuncs.reloadplugins = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
953 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
955 gNetscapeFuncs.getJavaEnv = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
956 gNetscapeFuncs.getJavaPeer = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
958 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
960 gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
961 gNetscapeFuncs.posturlnotify = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
963 gNetscapeFuncs.getvalue = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
964 gNetscapeFuncs.setvalue = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
965 gNetscapeFuncs.invalidaterect = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
966 gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
967 gNetscapeFuncs.forceredraw = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
968 if( navMinorVers >= 14 )
971 gNetscapeFuncs.getstringidentifier = (NPN_GetStringIdentifierUPP)HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
972 gNetscapeFuncs.getstringidentifiers = (NPN_GetStringIdentifiersUPP)HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
973 gNetscapeFuncs.getintidentifier = (NPN_GetIntIdentifierUPP)HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
974 gNetscapeFuncs.identifierisstring = (NPN_IdentifierIsStringUPP)HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
975 gNetscapeFuncs.utf8fromidentifier = (NPN_UTF8FromIdentifierUPP)HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
976 gNetscapeFuncs.intfromidentifier = (NPN_IntFromIdentifierUPP)HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
977 gNetscapeFuncs.createobject = (NPN_CreateObjectUPP)HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
978 gNetscapeFuncs.retainobject = (NPN_RetainObjectUPP)HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
979 gNetscapeFuncs.releaseobject = (NPN_ReleaseObjectUPP)HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
980 gNetscapeFuncs.invoke = (NPN_InvokeUPP)HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
981 gNetscapeFuncs.invokeDefault = (NPN_InvokeDefaultUPP)HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
982 gNetscapeFuncs.evaluate = (NPN_EvaluateUPP)HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
983 gNetscapeFuncs.getproperty = (NPN_GetPropertyUPP)HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
984 gNetscapeFuncs.setproperty = (NPN_SetPropertyUPP)HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
985 gNetscapeFuncs.removeproperty = (NPN_RemovePropertyUPP)HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
986 gNetscapeFuncs.hasproperty = (NPN_HasPropertyUPP)HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
987 gNetscapeFuncs.hasmethod = (NPN_HasMethodUPP)HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
988 gNetscapeFuncs.releasevariantvalue = (NPN_ReleaseVariantValueUPP)HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
989 gNetscapeFuncs.setexception = (NPN_SetExceptionUPP)HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
993 // Set up the plugin function table that Netscape will use to
994 // call us. Netscape needs to know about our version and size
995 // and have a UniversalProcPointer for every function we implement.
997 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
998 pluginFuncs->size = sizeof(NPPluginFuncs);
999 pluginFuncs->newp = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1000 pluginFuncs->destroy = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1001 pluginFuncs->setwindow = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1002 pluginFuncs->newstream = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1003 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1004 pluginFuncs->asfile = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1005 pluginFuncs->writeready = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1006 pluginFuncs->write = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1007 pluginFuncs->print = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1008 pluginFuncs->event = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1009 pluginFuncs->getvalue = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1010 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1012 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1015 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1017 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1020 pluginFuncs->javaClass = NULL;
1022 *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1025 err = Private_Initialize();
1035 ** netscape plugins functions when building Mach-O binary
1039 NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1040 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1041 NPError NP_Shutdown(void);
1045 ** netscape plugins functions when using Mach-O binary
1048 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1050 PLUGINDEBUGSTR("\pNP_Initialize");
1052 /* validate input parameters */
1054 if( NULL == nsTable )
1055 return NPERR_INVALID_FUNCTABLE_ERROR;
1058 * Check the major version passed in Netscape's function table.
1059 * We won't load if the major version is newer than what we expect.
1060 * Also check that the function tables passed in are big enough for
1061 * all the functions we need (they could be bigger, if Netscape added
1062 * new APIs, but that's OK with us -- we'll just ignore them).
1066 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1067 return NPERR_INCOMPATIBLE_VERSION_ERROR;
1069 if (nsTable->size < sizeof(NPNetscapeFuncs))
1070 return NPERR_INVALID_FUNCTABLE_ERROR;
1073 int navMinorVers = nsTable->version & 0xFF;
1076 * Copy all the fields of Netscape function table into our
1077 * copy so we can call back into Netscape later. Note that
1078 * we need to copy the fields one by one, rather than assigning
1079 * the whole structure, because the Netscape function table
1080 * could actually be bigger than what we expect.
1082 gNetscapeFuncs.version = nsTable->version;
1083 gNetscapeFuncs.size = nsTable->size;
1084 gNetscapeFuncs.posturl = nsTable->posturl;
1085 gNetscapeFuncs.geturl = nsTable->geturl;
1086 gNetscapeFuncs.requestread = nsTable->requestread;
1087 gNetscapeFuncs.newstream = nsTable->newstream;
1088 gNetscapeFuncs.write = nsTable->write;
1089 gNetscapeFuncs.destroystream = nsTable->destroystream;
1090 gNetscapeFuncs.status = nsTable->status;
1091 gNetscapeFuncs.uagent = nsTable->uagent;
1092 gNetscapeFuncs.memalloc = nsTable->memalloc;
1093 gNetscapeFuncs.memfree = nsTable->memfree;
1094 gNetscapeFuncs.memflush = nsTable->memflush;
1095 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1096 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1098 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
1099 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
1101 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1103 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
1104 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
1107 gNetscapeFuncs.getvalue = nsTable->getvalue;
1108 gNetscapeFuncs.setvalue = nsTable->setvalue;
1109 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
1110 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1111 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
1112 if( navMinorVers >= 14 )
1114 // NPRuntime support
1115 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
1116 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1117 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
1118 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
1119 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
1120 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
1121 gNetscapeFuncs.createobject = nsTable->createobject;
1122 gNetscapeFuncs.retainobject = nsTable->retainobject;
1123 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
1124 gNetscapeFuncs.invoke = nsTable->invoke;
1125 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
1126 gNetscapeFuncs.evaluate = nsTable->evaluate;
1127 gNetscapeFuncs.getproperty = nsTable->getproperty;
1128 gNetscapeFuncs.setproperty = nsTable->setproperty;
1129 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
1130 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
1131 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
1132 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
1133 gNetscapeFuncs.setexception = nsTable->setexception;
1135 return NPP_Initialize();
1138 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1140 int navMinorVers = gNetscapeFuncs.version & 0xFF;
1142 PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1144 if( pluginFuncs == NULL )
1145 return NPERR_INVALID_FUNCTABLE_ERROR;
1147 /*if (pluginFuncs->size < sizeof(NPPluginFuncs))
1148 return NPERR_INVALID_FUNCTABLE_ERROR;*/
1151 * Set up the plugin function table that Netscape will use to
1152 * call us. Netscape needs to know about our version and size
1153 * and have a UniversalProcPointer for every function we
1157 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1158 pluginFuncs->size = sizeof(NPPluginFuncs);
1159 pluginFuncs->newp = Private_New;
1160 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
1161 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
1162 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
1163 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1164 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1165 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1166 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
1167 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
1168 pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
1169 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
1170 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
1171 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1173 pluginFuncs->urlnotify = Private_URLNotify;
1176 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1178 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1181 pluginFuncs->javaClass = NULL;
1184 return NPERR_NO_ERROR;
1187 NPError NP_Shutdown(void)
1189 PLUGINDEBUGSTR("\pNP_Shutdown");
1191 return NPERR_NO_ERROR;