1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * Safari/Mozilla/Firefox plugin for VLC
4 * Copyright (C) 2009, Jean-Paul Saman <jpsaman@videolan.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
25 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
31 #include <Processes.h>
33 #include <CodeFragments.h>
35 #include <Resources.h>
36 #include <ToolUtils.h>
39 #undef TARGET_RT_MAC_CFM
42 // A4Stuff.h contains the definition of EnterCodeResource and
43 // EnterCodeResource, used for setting up the code resource’s
44 // globals for 68K (analagous to the function SetCurrentA5
45 // defined by the toolbox).
47 // A4Stuff does not exist as of CW 7. Define them to nothing.
50 #if (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) || defined(__GNUC__)
51 #define EnterCodeResource()
52 #define ExitCodeResource()
60 // The Mixed Mode procInfos defined in npupp.h assume Think C-
61 // style calling conventions. These conventions are used by
62 // Metrowerks with the exception of pointer return types, which
63 // in Metrowerks 68K are returned in A0, instead of the standard
64 // D0. Thus, since NPN_MemAlloc and NPN_UserAgent return pointers,
65 // Mixed Mode will return the values to a 68K plugin in D0, but
66 // a 68K plugin compiled by Metrowerks will expect the result in
67 // A0. The following pragma forces Metrowerks to use D0 instead.
71 #pragma pointers_in_D0
79 #ifdef HAVE_NPFUNCTIONS_H
80 #include "npfunctions.h"
85 #include "../vlcshell.h"
89 #pragma pointers_in_A0
93 // The following fix for static initializers (which fixes a previous
94 // incompatibility with some parts of PowerPlant, was submitted by
101 extern void __InitCode__(void);
103 extern void __sinit(void);
104 #define __InitCode__ __sinit
106 extern void __destroy_global_chain(void);
109 #endif // __cplusplus
113 // Define PLUGIN_TRACE to 1 to have the wrapper functions emit
114 // DebugStr messages whenever they are called.
116 #define PLUGIN_TRACE 0
119 #define PLUGINDEBUGSTR(msg) ::DebugStr(msg)
121 #define PLUGINDEBUGSTR(msg) {}
124 #if defined(XP_MACOSX) && defined(__POWERPC__) && (!defined(TARGET_RT_MAC_CFM))
126 // glue for mapping outgoing Macho function pointers to TVectors
134 TFPtoTVGlue setwindow;
135 TFPtoTVGlue newstream;
136 TFPtoTVGlue destroystream;
138 TFPtoTVGlue writeready;
142 TFPtoTVGlue urlnotify;
143 TFPtoTVGlue getvalue;
144 TFPtoTVGlue setvalue;
146 TFPtoTVGlue shutdown;
147 } gPluginFuncsGlueTable;
149 static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
151 functionGlue->glue[0] = fp;
152 functionGlue->glue[1] = 0;
156 #define PLUGIN_TO_HOST_GLUE(name, fp) (SetupFPtoTVGlue(&gPluginFuncsGlueTable.name, (void*)fp))
158 // glue for mapping netscape TVectors to Macho function pointers
166 TTVtoFPGlue requestread;
167 TTVtoFPGlue newstream;
169 TTVtoFPGlue destroystream;
172 TTVtoFPGlue memalloc;
174 TTVtoFPGlue memflush;
175 TTVtoFPGlue reloadplugins;
176 TTVtoFPGlue getJavaEnv;
177 TTVtoFPGlue getJavaPeer;
178 TTVtoFPGlue geturlnotify;
179 TTVtoFPGlue posturlnotify;
180 TTVtoFPGlue getvalue;
181 TTVtoFPGlue setvalue;
182 TTVtoFPGlue invalidaterect;
183 TTVtoFPGlue invalidateregion;
184 TTVtoFPGlue forceredraw;
186 TTVtoFPGlue getstringidentifier;
187 TTVtoFPGlue getstringidentifiers;
188 TTVtoFPGlue getintidentifier;
189 TTVtoFPGlue identifierisstring;
190 TTVtoFPGlue utf8fromidentifier;
191 TTVtoFPGlue intfromidentifier;
192 TTVtoFPGlue createobject;
193 TTVtoFPGlue retainobject;
194 TTVtoFPGlue releaseobject;
196 TTVtoFPGlue invokeDefault;
197 TTVtoFPGlue evaluate;
198 TTVtoFPGlue getproperty;
199 TTVtoFPGlue setproperty;
200 TTVtoFPGlue removeproperty;
201 TTVtoFPGlue hasproperty;
202 TTVtoFPGlue hasmethod;
203 TTVtoFPGlue releasevariantvalue;
204 TTVtoFPGlue setexception;
205 } gNetscapeFuncsGlueTable;
207 static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
209 static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
211 memcpy(functionGlue, &glueTemplate, sizeof(TTVtoFPGlue));
212 functionGlue->glue[0] |= ((UInt32)tvp >> 16);
213 functionGlue->glue[1] |= ((UInt32)tvp & 0xFFFF);
214 ::MakeDataExecutable(functionGlue, sizeof(TTVtoFPGlue));
218 #define HOST_TO_PLUGIN_GLUE(name, fp) (SetupTVtoFPGlue(&gNetscapeFuncsGlueTable.name, (void*)fp))
222 #define PLUGIN_TO_HOST_GLUE(name, fp) (fp)
223 #define HOST_TO_PLUGIN_GLUE(name, fp) (fp)
225 #endif /* XP_MACOSX */
229 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
233 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
235 #if !TARGET_API_MAC_CARBON
236 QDGlobals* gQDPtr; // Pointer to Netscape’s QuickDraw globals
238 short gResFile; // Refnum of the plugin’s resource file
239 NPNetscapeFuncs gNetscapeFuncs; // Function table for procs in Netscape called by plugin
241 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
243 // Wrapper functions for all calls from the plugin to Netscape.
244 // These functions let the plugin developer just call the APIs
245 // as documented and defined in npapi.h, without needing to know
246 // about the function table and call macros in npupp.h.
248 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
250 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
252 *plugin_major = NP_VERSION_MAJOR;
253 *plugin_minor = NP_VERSION_MINOR;
254 *netscape_major = gNetscapeFuncs.version >> 8; // Major version is in high byte
255 *netscape_minor = gNetscapeFuncs.version & 0xFF; // Minor version is in low byte
258 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
260 int navMinorVers = gNetscapeFuncs.version & 0xFF;
263 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
265 err = CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
269 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
274 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
276 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
279 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
281 int navMinorVers = gNetscapeFuncs.version & 0xFF;
284 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
286 err = CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify, instance, url,
287 window, len, buf, file, notifyData);
291 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
296 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
298 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, url, window, len, buf, file);
301 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
303 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, stream, rangeList);
306 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream)
308 int navMinorVers = gNetscapeFuncs.version & 0xFF;
311 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
313 err = CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, type, window, stream);
317 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
322 int32_t NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
324 int navMinorVers = gNetscapeFuncs.version & 0xFF;
327 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
329 err = CallNPN_WriteProc(gNetscapeFuncs.write, instance, stream, len, buffer);
333 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
338 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
340 int navMinorVers = gNetscapeFuncs.version & 0xFF;
343 if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
345 err = CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, instance, stream, reason);
349 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
354 void NPN_Status(NPP instance, const char* message)
356 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
359 const char* NPN_UserAgent(NPP instance)
361 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
364 void* NPN_MemAlloc(uint32_t size)
366 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
369 void NPN_MemFree(void* ptr)
371 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
374 uint32_t NPN_MemFlush(uint32_t size)
376 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
379 void NPN_ReloadPlugins(NPBool reloadPages)
381 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
385 JRIEnv* NPN_GetJavaEnv(void)
387 return CallNPN_GetJavaEnvProc( gNetscapeFuncs.getJavaEnv );
390 jobject NPN_GetJavaPeer(NPP instance)
392 return CallNPN_GetJavaPeerProc( gNetscapeFuncs.getJavaPeer, instance );
396 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
398 return CallNPN_GetValueProc( gNetscapeFuncs.getvalue, instance, variable, value);
401 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
403 return CallNPN_SetValueProc( gNetscapeFuncs.setvalue, instance, variable, value);
406 void NPN_InvalidateRect(NPP instance, NPRect *rect)
408 CallNPN_InvalidateRectProc( gNetscapeFuncs.invalidaterect, instance, rect);
411 void NPN_InvalidateRegion(NPP instance, NPRegion region)
413 CallNPN_InvalidateRegionProc( gNetscapeFuncs.invalidateregion, instance, region);
416 void NPN_ForceRedraw(NPP instance)
418 CallNPN_ForceRedrawProc( gNetscapeFuncs.forceredraw, instance);
421 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
423 int navMinorVers = gNetscapeFuncs.version & 0xFF;
424 if( navMinorVers >= 14 )
426 return CallNPN_GetStringIdentifierProc( gNetscapeFuncs.getstringidentifier, name);
431 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
433 int navMinorVers = gNetscapeFuncs.version & 0xFF;
434 if( navMinorVers >= 14 )
436 CallNPN_GetStringIdentifiersProc( gNetscapeFuncs.getstringidentifiers, names, nameCount, identifiers);
440 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
442 int navMinorVers = gNetscapeFuncs.version & 0xFF;
443 if( navMinorVers >= 14 )
445 return CallNPN_GetIntIdentifierProc( gNetscapeFuncs.getintidentifier, intid);
450 bool NPN_IdentifierIsString(NPIdentifier identifier)
452 int navMinorVers = gNetscapeFuncs.version & 0xFF;
453 if( navMinorVers >= 14 )
455 return CallNPN_IdentifierIsStringProc( gNetscapeFuncs.identifierisstring, identifier);
460 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
462 int navMinorVers = gNetscapeFuncs.version & 0xFF;
463 if( navMinorVers >= 14 )
465 return CallNPN_UTF8FromIdentifierProc( gNetscapeFuncs.utf8fromidentifier, identifier);
470 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
472 int navMinorVers = gNetscapeFuncs.version & 0xFF;
473 if( navMinorVers >= 14 )
475 return CallNPN_IntFromIdentifierProc( gNetscapeFuncs.intfromidentifier, identifier);
480 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
482 int navMinorVers = gNetscapeFuncs.version & 0xFF;
483 if( navMinorVers >= 14 )
485 return CallNPN_CreateObjectProc( gNetscapeFuncs.createobject, instance, aClass);
490 NPObject *NPN_RetainObject(NPObject *npobj)
492 int navMinorVers = gNetscapeFuncs.version & 0xFF;
493 if( navMinorVers >= 14 )
495 return CallNPN_RetainObjectProc( gNetscapeFuncs.retainobject, npobj);
500 void NPN_ReleaseObject(NPObject *npobj)
502 int navMinorVers = gNetscapeFuncs.version & 0xFF;
503 if( navMinorVers >= 14 )
505 CallNPN_ReleaseObjectProc( gNetscapeFuncs.releaseobject, npobj);
509 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
511 int navMinorVers = gNetscapeFuncs.version & 0xFF;
512 if( navMinorVers >= 14 )
514 return CallNPN_InvokeProc( gNetscapeFuncs.invoke, instance, npobj, methodName, args, argCount, result);
519 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
521 int navMinorVers = gNetscapeFuncs.version & 0xFF;
522 if( navMinorVers >= 14 )
524 return CallNPN_InvokeDefaultProc( gNetscapeFuncs.invokeDefault, instance, npobj, args, argCount, result);
529 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
531 int navMinorVers = gNetscapeFuncs.version & 0xFF;
532 if( navMinorVers >= 14 )
534 return CallNPN_EvaluateProc( gNetscapeFuncs.evaluate, instance, npobj, script, result);
539 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
541 int navMinorVers = gNetscapeFuncs.version & 0xFF;
542 if( navMinorVers >= 14 )
544 return CallNPN_GetPropertyProc( gNetscapeFuncs.getproperty, instance, npobj, propertyName, result);
549 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
551 int navMinorVers = gNetscapeFuncs.version & 0xFF;
552 if( navMinorVers >= 14 )
554 return CallNPN_SetPropertyProc( gNetscapeFuncs.setproperty, instance, npobj, propertyName, value);
559 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
561 int navMinorVers = gNetscapeFuncs.version & 0xFF;
562 if( navMinorVers >= 14 )
564 return CallNPN_RemovePropertyProc( gNetscapeFuncs.removeproperty, instance, npobj, propertyName);
569 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
571 int navMinorVers = gNetscapeFuncs.version & 0xFF;
572 if( navMinorVers >= 14 )
574 return CallNPN_HasPropertyProc( gNetscapeFuncs.hasproperty, instance, npobj, propertyName);
579 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
581 int navMinorVers = gNetscapeFuncs.version & 0xFF;
582 if( navMinorVers >= 14 )
584 return CallNPN_HasMethodProc( gNetscapeFuncs.hasmethod, instance, npobj, methodName);
589 void NPN_ReleaseVariantValue(NPVariant *variant)
591 int navMinorVers = gNetscapeFuncs.version & 0xFF;
592 if( navMinorVers >= 14 )
594 CallNPN_ReleaseVariantValueProc( gNetscapeFuncs.releasevariantvalue, variant);
598 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
600 int navMinorVers = gNetscapeFuncs.version & 0xFF;
601 if( navMinorVers >= 14 )
603 CallNPN_SetExceptionProc( gNetscapeFuncs.setexception, npobj, message);
609 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
611 // Wrapper functions for all calls from Netscape to the plugin.
612 // These functions let the plugin developer just create the APIs
613 // as documented and defined in npapi.h, without needing to
614 // install those functions in the function table or worry about
615 // setting up globals for 68K plugins.
617 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
619 NPError Private_Initialize(void);
620 void Private_Shutdown(void);
621 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
622 NPError Private_Destroy(NPP instance, NPSavedData** save);
623 NPError Private_SetWindow(NPP instance, NPWindow* window);
624 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value );
625 NPError Private_SetValue( NPP instance, NPPVariable variable, void *value );
626 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype);
627 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
628 int32_t Private_WriteReady(NPP instance, NPStream* stream);
629 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer);
630 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
631 void Private_Print(NPP instance, NPPrint* platformPrint);
632 int16_t Private_HandleEvent(NPP instance, void* event);
633 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData);
634 jobject Private_GetJavaClass(void);
637 NPError Private_Initialize(void)
641 PLUGINDEBUGSTR("\pInitialize;g;");
642 err = NPP_Initialize();
647 void Private_Shutdown(void)
650 PLUGINDEBUGSTR("\pShutdown;g;");
654 __destroy_global_chain();
660 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
663 NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
664 PLUGINDEBUGSTR("\pNew;g;");
669 NPError Private_Destroy(NPP instance, NPSavedData** save)
673 PLUGINDEBUGSTR("\pDestroy;g;");
674 err = NPP_Destroy(instance, save);
679 NPError Private_SetWindow(NPP instance, NPWindow* window)
683 PLUGINDEBUGSTR("\pSetWindow;g;");
684 err = NPP_SetWindow(instance, window);
689 NPError Private_GetValue( NPP instance, NPPVariable variable, void *value )
693 PLUGINDEBUGSTR("\pGetValue;g;");
694 err = NPP_GetValue(instance, variable, value);
699 NPError Private_SetValue( NPP instance, NPNVariable variable, void *value )
703 PLUGINDEBUGSTR("\pSetValue;g;");
704 err = NPP_SetValue(instance, variable, value);
709 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
713 PLUGINDEBUGSTR("\pNewStream;g;");
714 err = NPP_NewStream(instance, type, stream, seekable, stype);
719 int32_t Private_WriteReady(NPP instance, NPStream* stream)
723 PLUGINDEBUGSTR("\pWriteReady;g;");
724 result = NPP_WriteReady(instance, stream);
729 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
733 PLUGINDEBUGSTR("\pWrite;g;");
734 result = NPP_Write(instance, stream, offset, len, buffer);
739 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
742 PLUGINDEBUGSTR("\pStreamAsFile;g;");
743 NPP_StreamAsFile(instance, stream, fname);
747 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
751 PLUGINDEBUGSTR("\pDestroyStream;g;");
752 err = NPP_DestroyStream(instance, stream, reason);
757 int16_t Private_HandleEvent(NPP instance, void* event)
761 PLUGINDEBUGSTR("\pHandleEvent;g;");
762 result = NPP_HandleEvent(instance, event);
767 void Private_Print(NPP instance, NPPrint* platformPrint)
770 PLUGINDEBUGSTR("\pPrint;g;");
771 NPP_Print(instance, platformPrint);
775 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
778 PLUGINDEBUGSTR("\pURLNotify;g;");
779 NPP_URLNotify(instance, url, reason, notifyData);
784 jobject Private_GetJavaClass(void)
787 PLUGINDEBUGSTR("\pGetJavaClass;g;");
789 jobject clazz = NPP_GetJavaClass();
793 JRIEnv* env = NPN_GetJavaEnv();
794 return (jobject)JRI_NewGlobalRef(env, clazz);
803 #if !TARGET_API_MAC_CARBON
804 ProcessSerialNumber PSN;
807 ProcessInfoRec infoRec;
808 OSErr result = noErr;
809 CFragConnectionID connID;
814 // Memorize the plugin’s resource file
815 // refnum for later use.
817 gResFile = CurResFile();
819 #if !TARGET_API_MAC_CARBON
821 // Ask the system if CFM is available.
824 OSErr err = Gestalt(gestaltCFMAttr, &response);
825 Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
827 ProcessInfoRec infoRec;
831 // GetProcessInformation takes a process serial number and
832 // will give us back the name and FSSpec of the application.
833 // See the Process Manager in IM.
837 infoRec.processInfoLength = sizeof(ProcessInfoRec);
838 infoRec.processName = name;
839 infoRec.processAppSpec = &myFSSpec;
841 ProcessSerialNumber PSN;
842 PSN.highLongOfPSN = 0;
843 PSN.lowLongOfPSN = kCurrentProcess;
845 result = GetProcessInformation(&PSN, &infoRec);
847 PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
851 // If no CFM installed, assume it must be a 68K app.
855 CFragConnectionID connID;
859 // Now that we know the app name and FSSpec, we can call GetDiskFragment
860 // to get a connID to use in a subsequent call to FindSymbol (it will also
861 // return the address of “main” in app, which we ignore). If GetDiskFragment
862 // returns an error, we assume the app must be 68K.
866 result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
867 kLoadCFrag, &connID, (Ptr*)&mainAddr, errName);
873 // The app is a PPC code fragment, so call FindSymbol
874 // to get the exported “qd” symbol so we can access its
875 // QuickDraw globals.
877 CFragSymbolClass symClass;
878 result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
879 if (result != noErr) { // this fails if we are in NS 6
880 gQDPtr = &qd; // so we default to the standard QD globals
886 // The app is 68K, so use its A5 to compute the address
887 // of its QuickDraw globals.
889 gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
896 // gcc requires that main have an 'int' return type
897 int main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
899 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
902 #if !TARGET_API_MAC_CARBON
905 #if TARGET_RT_MAC_CFM
907 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
912 #endif /* !TARGET_API_MAC_CARBON */
915 DEFINE_API_C(int) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
917 DEFINE_API_C(NPError) main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
921 PLUGINDEBUGSTR("\pmain");
927 NPError err = NPERR_NO_ERROR;
930 // Ensure that everything Netscape passed us is valid!
932 if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
933 err = NPERR_INVALID_FUNCTABLE_ERROR;
936 // Check the “major” version passed in Netscape’s function table.
937 // We won’t load if the major version is newer than what we expect.
938 // Also check that the function tables passed in are big enough for
939 // all the functions we need (they could be bigger, if Netscape added
940 // new APIs, but that’s OK with us -- we’ll just ignore them).
942 if (err == NPERR_NO_ERROR)
944 if ((nsTable->version >> 8) > NP_VERSION_MAJOR) // Major version is in high byte
945 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
948 if (err == NPERR_NO_ERROR)
951 // Copy all the fields of Netscape’s function table into our
952 // copy so we can call back into Netscape later. Note that
953 // we need to copy the fields one by one, rather than assigning
954 // the whole structure, because the Netscape function table
955 // could actually be bigger than what we expect.
958 int navMinorVers = nsTable->version & 0xFF;
960 gNetscapeFuncs.version = nsTable->version;
961 gNetscapeFuncs.size = nsTable->size;
962 gNetscapeFuncs.posturl = (NPN_PostURLUPP)HOST_TO_PLUGIN_GLUE(posturl, nsTable->posturl);
963 gNetscapeFuncs.geturl = (NPN_GetURLUPP)HOST_TO_PLUGIN_GLUE(geturl, nsTable->geturl);
964 gNetscapeFuncs.requestread = (NPN_RequestReadUPP)HOST_TO_PLUGIN_GLUE(requestread, nsTable->requestread);
965 gNetscapeFuncs.newstream = (NPN_NewStreamUPP)HOST_TO_PLUGIN_GLUE(newstream, nsTable->newstream);
966 gNetscapeFuncs.write = (NPN_WriteUPP)HOST_TO_PLUGIN_GLUE(write, nsTable->write);
967 gNetscapeFuncs.destroystream = (NPN_DestroyStreamUPP)HOST_TO_PLUGIN_GLUE(destroystream, nsTable->destroystream);
968 gNetscapeFuncs.status = (NPN_StatusUPP)HOST_TO_PLUGIN_GLUE(status, nsTable->status);
969 gNetscapeFuncs.uagent = (NPN_UserAgentUPP)HOST_TO_PLUGIN_GLUE(uagent, nsTable->uagent);
970 gNetscapeFuncs.memalloc = (NPN_MemAllocUPP)HOST_TO_PLUGIN_GLUE(memalloc, nsTable->memalloc);
971 gNetscapeFuncs.memfree = (NPN_MemFreeUPP)HOST_TO_PLUGIN_GLUE(memfree, nsTable->memfree);
972 gNetscapeFuncs.memflush = (NPN_MemFlushUPP)HOST_TO_PLUGIN_GLUE(memflush, nsTable->memflush);
973 gNetscapeFuncs.reloadplugins = (NPN_ReloadPluginsUPP)HOST_TO_PLUGIN_GLUE(reloadplugins, nsTable->reloadplugins);
974 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
976 gNetscapeFuncs.getJavaEnv = (NPN_GetJavaEnvUPP)HOST_TO_PLUGIN_GLUE(getJavaEnv, nsTable->getJavaEnv);
977 gNetscapeFuncs.getJavaPeer = (NPN_GetJavaPeerUPP)HOST_TO_PLUGIN_GLUE(getJavaPeer, nsTable->getJavaPeer);
979 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
981 gNetscapeFuncs.geturlnotify = (NPN_GetURLNotifyUPP)HOST_TO_PLUGIN_GLUE(geturlnotify, nsTable->geturlnotify);
982 gNetscapeFuncs.posturlnotify = (NPN_PostURLNotifyUPP)HOST_TO_PLUGIN_GLUE(posturlnotify, nsTable->posturlnotify);
984 gNetscapeFuncs.getvalue = (NPN_GetValueUPP)HOST_TO_PLUGIN_GLUE(getvalue, nsTable->getvalue);
985 gNetscapeFuncs.setvalue = (NPN_SetValueUPP)HOST_TO_PLUGIN_GLUE(setvalue, nsTable->setvalue);
986 gNetscapeFuncs.invalidaterect = (NPN_InvalidateRectUPP)HOST_TO_PLUGIN_GLUE(invalidaterect, nsTable->invalidaterect);
987 gNetscapeFuncs.invalidateregion = (NPN_InvalidateRegionUPP)HOST_TO_PLUGIN_GLUE(invalidateregion, nsTable->invalidateregion);
988 gNetscapeFuncs.forceredraw = (NPN_ForceRedrawUPP)HOST_TO_PLUGIN_GLUE(forceredraw, nsTable->forceredraw);
989 if( navMinorVers >= 14 )
992 gNetscapeFuncs.getstringidentifier = (NPN_GetStringIdentifierUPP)HOST_TO_PLUGIN_GLUE(getstringidentifier, nsTable->getstringidentifier);
993 gNetscapeFuncs.getstringidentifiers = (NPN_GetStringIdentifiersUPP)HOST_TO_PLUGIN_GLUE(getstringidentifiers, nsTable->getstringidentifiers);
994 gNetscapeFuncs.getintidentifier = (NPN_GetIntIdentifierUPP)HOST_TO_PLUGIN_GLUE(getintidentifier, nsTable->getintidentifier);
995 gNetscapeFuncs.identifierisstring = (NPN_IdentifierIsStringUPP)HOST_TO_PLUGIN_GLUE(identifierisstring, nsTable->identifierisstring);
996 gNetscapeFuncs.utf8fromidentifier = (NPN_UTF8FromIdentifierUPP)HOST_TO_PLUGIN_GLUE(utf8fromidentifier, nsTable->utf8fromidentifier);
997 gNetscapeFuncs.intfromidentifier = (NPN_IntFromIdentifierUPP)HOST_TO_PLUGIN_GLUE(intfromidentifier, nsTable->intfromidentifier);
998 gNetscapeFuncs.createobject = (NPN_CreateObjectUPP)HOST_TO_PLUGIN_GLUE(createobject, nsTable->createobject);
999 gNetscapeFuncs.retainobject = (NPN_RetainObjectUPP)HOST_TO_PLUGIN_GLUE(retainobject, nsTable->retainobject);
1000 gNetscapeFuncs.releaseobject = (NPN_ReleaseObjectUPP)HOST_TO_PLUGIN_GLUE(releaseobject, nsTable->releaseobject);
1001 gNetscapeFuncs.invoke = (NPN_InvokeUPP)HOST_TO_PLUGIN_GLUE(invoke, nsTable->invoke);
1002 gNetscapeFuncs.invokeDefault = (NPN_InvokeDefaultUPP)HOST_TO_PLUGIN_GLUE(invokeDefault, nsTable->invokeDefault);
1003 gNetscapeFuncs.evaluate = (NPN_EvaluateUPP)HOST_TO_PLUGIN_GLUE(evaluate, nsTable->evaluate);
1004 gNetscapeFuncs.getproperty = (NPN_GetPropertyUPP)HOST_TO_PLUGIN_GLUE(getproperty, nsTable->getproperty);
1005 gNetscapeFuncs.setproperty = (NPN_SetPropertyUPP)HOST_TO_PLUGIN_GLUE(setproperty, nsTable->setproperty);
1006 gNetscapeFuncs.removeproperty = (NPN_RemovePropertyUPP)HOST_TO_PLUGIN_GLUE(removeproperty, nsTable->removeproperty);
1007 gNetscapeFuncs.hasproperty = (NPN_HasPropertyUPP)HOST_TO_PLUGIN_GLUE(hasproperty, nsTable->hasproperty);
1008 gNetscapeFuncs.hasmethod = (NPN_HasMethodUPP)HOST_TO_PLUGIN_GLUE(hasmethod, nsTable->hasmethod);
1009 gNetscapeFuncs.releasevariantvalue = (NPN_ReleaseVariantValueUPP)HOST_TO_PLUGIN_GLUE(releasevariantvalue, nsTable->releasevariantvalue);
1010 gNetscapeFuncs.setexception = (NPN_SetExceptionUPP)HOST_TO_PLUGIN_GLUE(setexception, nsTable->setexception);
1014 // Set up the plugin function table that Netscape will use to
1015 // call us. Netscape needs to know about our version and size
1016 // and have a UniversalProcPointer for every function we implement.
1018 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1019 pluginFuncs->size = sizeof(NPPluginFuncs);
1020 pluginFuncs->newp = NewNPP_NewProc(PLUGIN_TO_HOST_GLUE(newp, Private_New));
1021 pluginFuncs->destroy = NewNPP_DestroyProc(PLUGIN_TO_HOST_GLUE(destroy, Private_Destroy));
1022 pluginFuncs->setwindow = NewNPP_SetWindowProc(PLUGIN_TO_HOST_GLUE(setwindow, Private_SetWindow));
1023 pluginFuncs->newstream = NewNPP_NewStreamProc(PLUGIN_TO_HOST_GLUE(newstream, Private_NewStream));
1024 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(PLUGIN_TO_HOST_GLUE(destroystream, Private_DestroyStream));
1025 pluginFuncs->asfile = NewNPP_StreamAsFileProc(PLUGIN_TO_HOST_GLUE(asfile, Private_StreamAsFile));
1026 pluginFuncs->writeready = NewNPP_WriteReadyProc(PLUGIN_TO_HOST_GLUE(writeready, Private_WriteReady));
1027 pluginFuncs->write = NewNPP_WriteProc(PLUGIN_TO_HOST_GLUE(write, Private_Write));
1028 pluginFuncs->print = NewNPP_PrintProc(PLUGIN_TO_HOST_GLUE(print, Private_Print));
1029 pluginFuncs->event = NewNPP_HandleEventProc(PLUGIN_TO_HOST_GLUE(event, Private_HandleEvent));
1030 pluginFuncs->getvalue = NewNPP_GetValueProc(PLUGIN_TO_HOST_GLUE(getvalue, Private_GetValue));
1031 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1033 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(PLUGIN_TO_HOST_GLUE(urlnotify, Private_URLNotify));
1036 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1038 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1041 pluginFuncs->javaClass = NULL;
1043 *unloadUpp = NewNPP_ShutdownProc(PLUGIN_TO_HOST_GLUE(shutdown, Private_Shutdown));
1046 err = Private_Initialize();
1056 ** netscape plugins functions when building Mach-O binary
1060 NPError NP_Initialize(NPNetscapeFuncs* nsTable);
1061 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs);
1062 NPError NP_Shutdown(void);
1066 ** netscape plugins functions when using Mach-O binary
1069 NPError NP_Initialize(NPNetscapeFuncs* nsTable)
1071 PLUGINDEBUGSTR("\pNP_Initialize");
1073 /* validate input parameters */
1075 if( NULL == nsTable )
1076 return NPERR_INVALID_FUNCTABLE_ERROR;
1079 * Check the major version passed in Netscape's function table.
1080 * We won't load if the major version is newer than what we expect.
1081 * Also check that the function tables passed in are big enough for
1082 * all the functions we need (they could be bigger, if Netscape added
1083 * new APIs, but that's OK with us -- we'll just ignore them).
1087 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
1088 return NPERR_INCOMPATIBLE_VERSION_ERROR;
1090 if (nsTable->size < sizeof(NPNetscapeFuncs))
1091 return NPERR_INVALID_FUNCTABLE_ERROR;
1093 int navMinorVers = nsTable->version & 0xFF;
1096 * Copy all the fields of Netscape function table into our
1097 * copy so we can call back into Netscape later. Note that
1098 * we need to copy the fields one by one, rather than assigning
1099 * the whole structure, because the Netscape function table
1100 * could actually be bigger than what we expect.
1102 gNetscapeFuncs.version = nsTable->version;
1103 gNetscapeFuncs.size = nsTable->size;
1104 gNetscapeFuncs.posturl = nsTable->posturl;
1105 gNetscapeFuncs.geturl = nsTable->geturl;
1106 gNetscapeFuncs.requestread = nsTable->requestread;
1107 gNetscapeFuncs.newstream = nsTable->newstream;
1108 gNetscapeFuncs.write = nsTable->write;
1109 gNetscapeFuncs.destroystream = nsTable->destroystream;
1110 gNetscapeFuncs.status = nsTable->status;
1111 gNetscapeFuncs.uagent = nsTable->uagent;
1112 gNetscapeFuncs.memalloc = nsTable->memalloc;
1113 gNetscapeFuncs.memfree = nsTable->memfree;
1114 gNetscapeFuncs.memflush = nsTable->memflush;
1115 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
1116 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1118 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
1119 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
1121 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1123 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
1124 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
1127 gNetscapeFuncs.getvalue = nsTable->getvalue;
1128 gNetscapeFuncs.setvalue = nsTable->setvalue;
1129 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
1130 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
1131 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
1132 if( navMinorVers >= 14 )
1134 // NPRuntime support
1135 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
1136 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
1137 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
1138 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
1139 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
1140 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
1141 gNetscapeFuncs.createobject = nsTable->createobject;
1142 gNetscapeFuncs.retainobject = nsTable->retainobject;
1143 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
1144 gNetscapeFuncs.invoke = nsTable->invoke;
1145 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
1146 gNetscapeFuncs.evaluate = nsTable->evaluate;
1147 gNetscapeFuncs.getproperty = nsTable->getproperty;
1148 gNetscapeFuncs.setproperty = nsTable->setproperty;
1149 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
1150 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
1151 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
1152 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
1153 gNetscapeFuncs.setexception = nsTable->setexception;
1155 return NPP_Initialize();
1158 NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
1160 int navMinorVers = gNetscapeFuncs.version & 0xFF;
1162 PLUGINDEBUGSTR("\pNP_GetEntryPoints");
1164 if( pluginFuncs == NULL )
1165 return NPERR_INVALID_FUNCTABLE_ERROR;
1167 /*if (pluginFuncs->size < sizeof(NPPluginFuncs))
1168 return NPERR_INVALID_FUNCTABLE_ERROR;*/
1171 * Set up the plugin function table that Netscape will use to
1172 * call us. Netscape needs to know about our version and size
1173 * and have a UniversalProcPointer for every function we
1177 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
1178 pluginFuncs->size = sizeof(NPPluginFuncs);
1179 pluginFuncs->newp = NewNPP_NewProc(Private_New);
1180 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
1181 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
1182 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
1183 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
1184 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
1185 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
1186 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
1187 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
1188 pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
1189 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
1190 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
1191 if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
1193 pluginFuncs->urlnotify = Private_URLNotify;
1196 if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
1198 pluginFuncs->javaClass = (JRIGlobalRef) Private_GetJavaClass();
1201 pluginFuncs->javaClass = NULL;
1204 return NPERR_NO_ERROR;
1207 NPError NP_Shutdown(void)
1209 PLUGINDEBUGSTR("\pNP_Shutdown");
1211 return NPERR_NO_ERROR;