Back to index

lightning-sunbird  0.9+nobinonly
npmac.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00038 //
00039 // npmac.cpp
00040 //
00041 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00042 
00043 #include <Processes.h>
00044 #include <Gestalt.h>
00045 #include <CodeFragments.h>
00046 #include <Timer.h>
00047 #include <Resources.h>
00048 #include <ToolUtils.h>
00049 
00050 #define XP_MAC 1
00051 #define NDEBUG 1
00052 
00053 //
00054 // A4Stuff.h contains the definition of EnterCodeResource and 
00055 // EnterCodeResource, used for setting up the code resourceıs
00056 // globals for 68K (analagous to the function SetCurrentA5
00057 // defined by the toolbox).
00058 //
00059 #if TARGET_CPU_68K
00060 #include <A4Stuff.h>
00061 #else
00062 #define EnterCodeResource()
00063 #define ExitCodeResource()
00064 #endif
00065 
00066 #include "jri.h"
00067 #include "npapi.h"
00068 
00069 //
00070 // The Mixed Mode procInfos defined in npupp.h assume Think C-
00071 // style calling conventions.  These conventions are used by
00072 // Metrowerks with the exception of pointer return types, which
00073 // in Metrowerks 68K are returned in A0, instead of the standard
00074 // D0. Thus, since NPN_MemAlloc and NPN_UserAgent return pointers,
00075 // Mixed Mode will return the values to a 68K plugin in D0, but 
00076 // a 68K plugin compiled by Metrowerks will expect the result in
00077 // A0.  The following pragma forces Metrowerks to use D0 instead.
00078 //
00079 #ifdef __MWERKS__
00080 #ifndef powerc
00081 #pragma pointers_in_D0
00082 #endif
00083 #endif
00084 
00085 #include "npupp.h"
00086 
00087 #ifdef __MWERKS__
00088 #ifndef powerc
00089 #pragma pointers_in_A0
00090 #endif
00091 #endif
00092 
00093 // The following fix for static initializers (which fixes a preious
00094 // incompatibility with some parts of PowerPlant, was submitted by 
00095 // Jan Ulbrich.
00096 #ifdef __MWERKS__
00097        #ifdef __cplusplus
00098        extern "C" {
00099        #endif
00100               #ifndef powerc
00101                      extern void   __InitCode__(void);
00102               #else
00103                      extern void __sinit(void);
00104                      #define __InitCode__ __sinit
00105               #endif
00106               extern void   __destroy_global_chain(void);
00107        #ifdef __cplusplus
00108        }
00109        #endif // __cplusplus
00110 #endif // __MWERKS__
00111 
00112 //
00113 // Define PLUGIN_TRACE to 1 to have the wrapper functions emit
00114 // DebugStr messages whenever they are called.
00115 //
00116 #define PLUGIN_TRACE 0
00117 
00118 #if PLUGIN_TRACE
00119 #define PLUGINDEBUGSTR(msg)        ::DebugStr(msg)
00120 #else
00121 #define PLUGINDEBUGSTR
00122 #endif
00123 
00124 
00125 
00126 
00127 
00128 
00129 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00130 //
00131 // Globals
00132 //
00133 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00134 
00135 #if !TARGET_API_MAC_CARBON
00136 QDGlobals*           gQDPtr;                            // Pointer to Netscape's QuickDraw globals
00137 #endif
00138 
00139 short                gResFile;                   // Refnum of the plugin's resource file
00140 NPNetscapeFuncs      gNetscapeFuncs;             // Function table for procs in Netscape called by plugin
00141 
00142 
00143 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00144 //
00145 // Wrapper functions for all calls from the plugin to Netscape.
00146 // These functions let the plugin developer just call the APIs
00147 // as documented and defined in npapi.h, without needing to know
00148 // about the function table and call macros in npupp.h.
00149 //
00150 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00151 
00152 
00153 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
00154 {
00155        *plugin_major = NP_VERSION_MAJOR;
00156        *plugin_minor = NP_VERSION_MINOR;
00157        *netscape_major = gNetscapeFuncs.version >> 8;          // Major version is in high byte
00158        *netscape_minor = gNetscapeFuncs.version & 0xFF; // Minor version is in low byte
00159 }
00160 
00161 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
00162 {
00163        int navMinorVers = gNetscapeFuncs.version & 0xFF;
00164        NPError err;
00165        
00166        if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
00167        {
00168               err = CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
00169        }
00170        else
00171        {
00172               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00173        }
00174        return err;
00175 }
00176 
00177 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
00178 {
00179        return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
00180 }
00181 
00182 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
00183 {
00184        int navMinorVers = gNetscapeFuncs.version & 0xFF;
00185        NPError err;
00186        
00187        if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
00188        {
00189               err = CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify, instance, url, 
00190                                                                                                   window, len, buf, file, notifyData);
00191        }
00192        else
00193        {
00194               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00195        }
00196        return err;
00197 }
00198 
00199 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
00200 {
00201        return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, url, window, len, buf, file);
00202 }
00203 
00204 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
00205 {
00206        return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, stream, rangeList);
00207 }
00208 
00209 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream)
00210 {
00211        int navMinorVers = gNetscapeFuncs.version & 0xFF;
00212        NPError err;
00213        
00214        if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
00215        {
00216               err = CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, type, window, stream);
00217        }
00218        else
00219        {
00220               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00221        }
00222        return err;
00223 }
00224 
00225 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
00226 {
00227        int navMinorVers = gNetscapeFuncs.version & 0xFF;
00228        NPError err;
00229        
00230        if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
00231        {
00232               err = CallNPN_WriteProc(gNetscapeFuncs.write, instance, stream, len, buffer);
00233        }
00234        else
00235        {
00236               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00237        }
00238        return err;
00239 }
00240 
00241 NPError       NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00242 {
00243        int navMinorVers = gNetscapeFuncs.version & 0xFF;
00244        NPError err;
00245        
00246        if( navMinorVers >= NPVERS_HAS_STREAMOUTPUT )
00247        {
00248               err = CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, instance, stream, reason);
00249        }
00250        else
00251        {
00252               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00253        }
00254        return err;
00255 }
00256 
00257 void NPN_Status(NPP instance, const char* message)
00258 {
00259        CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
00260 }
00261 
00262 const char* NPN_UserAgent(NPP instance)
00263 {
00264        return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
00265 }
00266 
00267 #define DEBUG_MEMORY 0
00268 
00269 void* NPN_MemAlloc(uint32 size)
00270 {
00271 #if DEBUG_MEMORY
00272        return (void*) NewPtrClear(size);
00273 #else
00274        return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
00275 #endif
00276 }
00277 
00278 void NPN_MemFree(void* ptr)
00279 {
00280 #if DEBUG_MEMORY
00281        DisposePtr(Ptr(ptr));
00282 #else
00283        CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
00284 #endif
00285 }
00286 
00287 uint32 NPN_MemFlush(uint32 size)
00288 {
00289        return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
00290 }
00291 
00292 void NPN_ReloadPlugins(NPBool reloadPages)
00293 {
00294        CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
00295 }
00296 
00297 
00298 JRIEnv* NPN_GetJavaEnv(void)
00299 {
00300        return CallNPN_GetJavaEnvProc( gNetscapeFuncs.getJavaEnv );
00301 }
00302 
00303 jref  NPN_GetJavaPeer(NPP instance)
00304 {
00305        return CallNPN_GetJavaPeerProc( gNetscapeFuncs.getJavaPeer, instance );
00306 }
00307 
00308 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
00309 {
00310        return CallNPN_GetValueProc( gNetscapeFuncs.getvalue, instance, variable, value);
00311 }
00312 
00313 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
00314 {
00315        return CallNPN_SetValueProc( gNetscapeFuncs.setvalue, instance, variable, value);
00316 }
00317 
00318 void NPN_InvalidateRect(NPP instance, NPRect *rect)
00319 {
00320        CallNPN_InvalidateRectProc( gNetscapeFuncs.invalidaterect, instance, rect);
00321 }
00322 
00323 void NPN_InvalidateRegion(NPP instance, NPRegion region)
00324 {
00325        CallNPN_InvalidateRegionProc( gNetscapeFuncs.invalidateregion, instance, region);
00326 }
00327 
00328 void NPN_ForceRedraw(NPP instance)
00329 {
00330        CallNPN_ForceRedrawProc( gNetscapeFuncs.forceredraw, instance);
00331 }
00332 
00333 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00334 //
00335 // Wrapper functions for all calls from Netscape to the plugin.
00336 // These functions let the plugin developer just create the APIs
00337 // as documented and defined in npapi.h, without needing to 
00338 // install those functions in the function table or worry about
00339 // setting up globals for 68K plugins.
00340 //
00341 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00342 
00343 NPError       Private_Initialize(void);
00344 void          Private_Shutdown(void);
00345 NPError              Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
00346 NPError       Private_Destroy(NPP instance, NPSavedData** save);
00347 NPError              Private_SetWindow(NPP instance, NPWindow* window);
00348 NPError              Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
00349 NPError              Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
00350 int32         Private_WriteReady(NPP instance, NPStream* stream);
00351 int32         Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer);
00352 void          Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
00353 void          Private_Print(NPP instance, NPPrint* platformPrint);
00354 int16         Private_HandleEvent(NPP instance, void* event);
00355 void        Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData);
00356 jref          Private_GetJavaClass(void);
00357 NPError     Private_GetValue(NPP instance, NPPVariable variable, void *result);
00358 NPError     Private_SetValue(NPP instance, NPNVariable variable, void *value);
00359 
00360 
00361 NPError Private_Initialize(void)
00362 {
00363        NPError err;
00364        EnterCodeResource();
00365        PLUGINDEBUGSTR("\pInitialize;g;");
00366        err = NPP_Initialize();
00367        ExitCodeResource();
00368        return err;
00369 }
00370 
00371 void Private_Shutdown(void)
00372 {
00373        EnterCodeResource();
00374        PLUGINDEBUGSTR("\pShutdown;g;");
00375        NPP_Shutdown();
00376 
00377        __destroy_global_chain();
00378 
00379        ExitCodeResource();
00380 }
00381 
00382 
00383 NPError       Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
00384 {
00385        EnterCodeResource();
00386        NPError ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
00387        PLUGINDEBUGSTR("\pNew;g;");
00388        ExitCodeResource();
00389        return ret;   
00390 }
00391 
00392 NPError Private_Destroy(NPP instance, NPSavedData** save)
00393 {
00394        NPError err;
00395        EnterCodeResource();
00396        PLUGINDEBUGSTR("\pDestroy;g;");
00397        err = NPP_Destroy(instance, save);
00398        ExitCodeResource();
00399        return err;
00400 }
00401 
00402 NPError Private_SetWindow(NPP instance, NPWindow* window)
00403 {
00404        NPError err;
00405        EnterCodeResource();
00406        PLUGINDEBUGSTR("\pSetWindow;g;");
00407        err = NPP_SetWindow(instance, window);
00408        ExitCodeResource();
00409        return err;
00410 }
00411 
00412 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
00413 {
00414        NPError err;
00415        EnterCodeResource();
00416        PLUGINDEBUGSTR("\pNewStream;g;");
00417        err = NPP_NewStream(instance, type, stream, seekable, stype);
00418        ExitCodeResource();
00419        return err;
00420 }
00421 
00422 int32 Private_WriteReady(NPP instance, NPStream* stream)
00423 {
00424        int32 result;
00425        EnterCodeResource();
00426        PLUGINDEBUGSTR("\pWriteReady;g;");
00427        result = NPP_WriteReady(instance, stream);
00428        ExitCodeResource();
00429        return result;
00430 }
00431 
00432 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
00433 {
00434        int32 result;
00435        EnterCodeResource();
00436        PLUGINDEBUGSTR("\pWrite;g;");
00437        result = NPP_Write(instance, stream, offset, len, buffer);
00438        ExitCodeResource();
00439        return result;
00440 }
00441 
00442 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
00443 {
00444        EnterCodeResource();
00445        PLUGINDEBUGSTR("\pStreamAsFile;g;");
00446        NPP_StreamAsFile(instance, stream, fname);
00447        ExitCodeResource();
00448 }
00449 
00450 
00451 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00452 {
00453        NPError err;
00454        EnterCodeResource();
00455        PLUGINDEBUGSTR("\pDestroyStream;g;");
00456        err = NPP_DestroyStream(instance, stream, reason);
00457        ExitCodeResource();
00458        return err;
00459 }
00460 
00461 int16 Private_HandleEvent(NPP instance, void* event)
00462 {
00463        int16 result;
00464        EnterCodeResource();
00465        PLUGINDEBUGSTR("\pHandleEvent;g;");
00466        result = NPP_HandleEvent(instance, event);
00467        ExitCodeResource();
00468        return result;
00469 }
00470 
00471 void Private_Print(NPP instance, NPPrint* platformPrint)
00472 {
00473        EnterCodeResource();
00474        PLUGINDEBUGSTR("\pPrint;g;");
00475        NPP_Print(instance, platformPrint);
00476        ExitCodeResource();
00477 }
00478 
00479 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
00480 {
00481        EnterCodeResource();
00482        PLUGINDEBUGSTR("\pURLNotify;g;");
00483        NPP_URLNotify(instance, url, reason, notifyData);
00484        ExitCodeResource();
00485 }
00486 
00487 
00488 jref Private_GetJavaClass(void)
00489 {
00490        EnterCodeResource();
00491        PLUGINDEBUGSTR("\pGetJavaClass;g;");
00492 
00493     jref clazz = NPP_GetJavaClass();
00494     ExitCodeResource();
00495     if (clazz)
00496     {
00497               JRIEnv* env = NPN_GetJavaEnv();
00498               return (jref)JRI_NewGlobalRef(env, clazz);
00499     }
00500     return NULL;
00501 }
00502 
00503 NPError Private_GetValue(NPP instance, NPPVariable variable, void *result)
00504 {
00505        NPError err;
00506        EnterCodeResource();
00507        PLUGINDEBUGSTR("\pGetValue;g;");
00508        err = NPP_GetValue(instance, variable, result);
00509        ExitCodeResource();
00510        return err;
00511 }
00512 
00513 NPError Private_SetValue(NPP instance, NPNVariable variable, void *value)
00514 {
00515        NPError err;
00516        EnterCodeResource();
00517        PLUGINDEBUGSTR("\pSetValue;g;");
00518        err = NPP_SetValue(instance, variable, value);
00519        ExitCodeResource();
00520        return err;
00521 }
00522 
00523 void SetUpQD(void);
00524 
00525 void SetUpQD(void)
00526 {
00527        ProcessSerialNumber PSN;
00528        FSSpec                      myFSSpec;
00529        Str63                       name;
00530        ProcessInfoRec              infoRec;
00531        OSErr                       result = noErr;
00532        CFragConnectionID    connID;
00533        Str255                             errName;
00534        
00535        //
00536        // Memorize the pluginıs resource file 
00537        // refnum for later use.
00538        //
00539        gResFile = CurResFile();
00540        
00541 #if !TARGET_API_MAC_CARBON
00542        //
00543        // Ask the system if CFM is available.
00544        //
00545        long response;
00546        OSErr err = Gestalt(gestaltCFMAttr, &response);
00547        Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);
00548                      
00549        if (hasCFM)
00550        {
00551               //
00552               // GetProcessInformation takes a process serial number and 
00553               // will give us back the name and FSSpec of the application.
00554               // See the Process Manager in IM.
00555               //
00556               infoRec.processInfoLength = sizeof(ProcessInfoRec);
00557               infoRec.processName = name;
00558               infoRec.processAppSpec = &myFSSpec;
00559               
00560               PSN.highLongOfPSN = 0;
00561               PSN.lowLongOfPSN = kCurrentProcess;
00562               
00563               result = GetProcessInformation(&PSN, &infoRec);
00564               if (result != noErr)
00565                      PLUGINDEBUGSTR("\pFailed in GetProcessInformation");
00566               }
00567        else
00568               //
00569               // If no CFM installed, assume it must be a 68K app.
00570               //
00571               result = -1;         
00572               
00573        if (result == noErr)
00574        {
00575               //
00576               // Now that we know the app name and FSSpec, we can call GetDiskFragment
00577               // to get a connID to use in a subsequent call to FindSymbol (it will also
00578               // return the address of ³main² in app, which we ignore).  If GetDiskFragment 
00579               // returns an error, we assume the app must be 68K.
00580               //
00581               Ptr mainAddr;        
00582               result =  GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName,
00583                                                           kReferenceCFrag, &connID, (Ptr*)&mainAddr, errName);
00584        }
00585 
00586        if (result == noErr) 
00587        {
00588               //
00589               // The app is a PPC code fragment, so call FindSymbol
00590               // to get the exported ³qd² symbol so we can access its
00591               // QuickDraw globals.
00592               //
00593               CFragSymbolClass symClass;
00594               result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
00595               if (result != noErr)
00596                      PLUGINDEBUGSTR("\pFailed in FindSymbol qd");
00597        }
00598        else
00599        {
00600               //
00601               // The app is 68K, so use its A5 to compute the address
00602               // of its QuickDraw globals.
00603               //
00604               gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr)));
00605        }
00606 #endif /* !TARGET_API_MAC_CARBON */
00607 }
00608 
00609 
00610 
00611 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp);
00612 
00613 #pragma export on
00614 
00615 #if !TARGET_API_MAC_CARBON
00616 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main);
00617 #endif
00618 
00619 #pragma export off
00620  
00621 
00622 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownUPP* unloadUpp)
00623 {
00624        EnterCodeResource();
00625        PLUGINDEBUGSTR("\pmain");
00626 
00627        NPError err = NPERR_NO_ERROR;
00628        
00629        //
00630        // Ensure that everything Netscape passed us is valid!
00631        //
00632        if ((nsTable == NULL) || (pluginFuncs == NULL) || (unloadUpp == NULL))
00633               err = NPERR_INVALID_FUNCTABLE_ERROR;
00634        
00635        //
00636        // Check the ³major² version passed in Netscapeıs function table.
00637        // We wonıt load if the major version is newer than what we expect.
00638        // Also check that the function tables passed in are big enough for
00639        // all the functions we need (they could be bigger, if Netscape added
00640        // new APIs, but thatıs OK with us -- weıll just ignore them).
00641        //
00642        if (err == NPERR_NO_ERROR)
00643        {
00644               if ((nsTable->version >> 8) > NP_VERSION_MAJOR)         // Major version is in high byte
00645                      err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00646 //            if (nsTable->size < sizeof(NPNetscapeFuncs))
00647 //                   err = NPERR_INVALID_FUNCTABLE_ERROR;
00648 //            if (pluginFuncs->size < sizeof(NPPluginFuncs))          
00649 //                   err = NPERR_INVALID_FUNCTABLE_ERROR;
00650        }
00651               
00652        
00653        if (err == NPERR_NO_ERROR)
00654        {
00655               //
00656               // Copy all the fields of Netscapeıs function table into our
00657               // copy so we can call back into Netscape later.  Note that
00658               // we need to copy the fields one by one, rather than assigning
00659               // the whole structure, because the Netscape function table
00660               // could actually be bigger than what we expect.
00661               //
00662               
00663               int navMinorVers = nsTable->version & 0xFF;
00664 
00665               gNetscapeFuncs.version = nsTable->version;
00666               gNetscapeFuncs.size = nsTable->size;
00667               gNetscapeFuncs.posturl = nsTable->posturl;
00668               gNetscapeFuncs.geturl = nsTable->geturl;
00669               gNetscapeFuncs.requestread = nsTable->requestread;
00670               gNetscapeFuncs.newstream = nsTable->newstream;
00671               gNetscapeFuncs.write = nsTable->write;
00672               gNetscapeFuncs.destroystream = nsTable->destroystream;
00673               gNetscapeFuncs.status = nsTable->status;
00674               gNetscapeFuncs.uagent = nsTable->uagent;
00675               gNetscapeFuncs.memalloc = nsTable->memalloc;
00676               gNetscapeFuncs.memfree = nsTable->memfree;
00677               gNetscapeFuncs.memflush = nsTable->memflush;
00678               gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
00679               if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
00680               {
00681                      gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
00682                      gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
00683               }
00684               if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
00685               {      
00686                      gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
00687                      gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
00688               }
00689               gNetscapeFuncs.getvalue = nsTable->getvalue;
00690               gNetscapeFuncs.setvalue = nsTable->setvalue;
00691               gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
00692               gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
00693               gNetscapeFuncs.forceredraw = nsTable->forceredraw;
00694 
00695               // defer static constructors until the global functions are initialized.
00696               __InitCode__();
00697               
00698               //
00699               // Set up the plugin function table that Netscape will use to
00700               // call us.  Netscape needs to know about our version and size
00701               // and have a UniversalProcPointer for every function we implement.
00702               //
00703               pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
00704               pluginFuncs->size = sizeof(NPPluginFuncs);
00705               pluginFuncs->newp = NewNPP_NewProc(Private_New);
00706               pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
00707               pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
00708               pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
00709               pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
00710               pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
00711               pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
00712               pluginFuncs->write = NewNPP_WriteProc(Private_Write);
00713               pluginFuncs->print = NewNPP_PrintProc(Private_Print);
00714               pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);     
00715               if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
00716               {      
00717                      pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);                   
00718               }
00719               if( navMinorVers >= NPVERS_HAS_LIVECONNECT )
00720               {
00721                      pluginFuncs->javaClass      = (JRIGlobalRef) Private_GetJavaClass();
00722                      pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
00723                      pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
00724               }
00725               *unloadUpp = NewNPP_ShutdownProc(Private_Shutdown);
00726               SetUpQD();
00727               err = Private_Initialize();
00728        }
00729        
00730        ExitCodeResource();
00731        return err;
00732 }