Back to index

lightning-sunbird  0.9+nobinonly
npwin.cpp
Go to the documentation of this file.
00001 /* IMPORTANT NOTE - This file has been hacked to add support for NPP_GetValue & NPP_SetValue! */
00002 
00003 /* npwin.cpp */
00004 
00005 //\\// INCLUDE
00006 //#include "StdAfx.h"
00007 
00008 // netscape
00009 #ifndef _NPAPI_H_
00010 #include "npapi.h"
00011 #endif
00012 #ifndef _NPUPP_H_
00013 #include "npupp.h"
00014 #endif
00015 
00016 //\\// DEFINE
00017 #ifdef WIN32
00018     #define NP_EXPORT
00019 #else
00020     #define NP_EXPORT _export
00021 #endif
00022 
00023 //\\// GLOBAL DATA
00024 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
00025 JRIGlobalRef Private_GetJavaClass(void);
00026 
00027 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00029 // Private_GetJavaClass (global function)
00030 //
00031 //     Given a Java class reference (thru NPP_GetJavaClass) inform JRT
00032 //     of this class existence
00033 //
00034 JRIGlobalRef
00035 Private_GetJavaClass(void)
00036 {
00037     jref clazz = NPP_GetJavaClass();
00038     if (clazz) {
00039               JRIEnv* env = NPN_GetJavaEnv();
00040               return JRI_NewGlobalRef(env, clazz);
00041     }
00042     return NULL;
00043 }
00044 
00045 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00047 //                                        PLUGIN DLL entry points   
00048 //
00049 // These are the Windows specific DLL entry points. They must be exoprted
00050 //
00051 
00052 // we need these to be global since we have to fill one of its field
00053 // with a data (class) which requires knowlwdge of the navigator
00054 // jump-table. This jump table is known at Initialize time (NP_Initialize)
00055 // which is called after NP_GetEntryPoint
00056 static NPPluginFuncs* g_pluginFuncs;
00057 
00058 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00060 // NP_GetEntryPoints
00061 //
00062 //     fills in the func table used by Navigator to call entry points in
00063 //  plugin DLL.  Note that these entry points ensure that DS is loaded
00064 //  by using the NP_LOADDS macro, when compiling for Win16
00065 //
00066 NPError WINAPI NP_EXPORT
00067 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
00068 {
00069     // trap a NULL ptr 
00070     if(pFuncs == NULL)
00071         return NPERR_INVALID_FUNCTABLE_ERROR;
00072 
00073     // if the plugin's function table is smaller than the plugin expects,
00074     // then they are incompatible, and should return an error 
00075 
00076     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
00077     pFuncs->newp          = NPP_New;
00078     pFuncs->destroy       = NPP_Destroy;
00079     pFuncs->setwindow     = NPP_SetWindow;
00080     pFuncs->newstream     = NPP_NewStream;
00081     pFuncs->destroystream = NPP_DestroyStream;
00082     pFuncs->asfile        = NPP_StreamAsFile;
00083     pFuncs->writeready    = NPP_WriteReady;
00084     pFuncs->write         = NPP_Write;
00085     pFuncs->print         = NPP_Print;
00086     pFuncs->event         = 0;       
00087 #ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
00088     pFuncs->getvalue      = NPP_GetValue;
00089     pFuncs->setvalue      = NPP_SetValue;
00090 #endif
00091 
00092        g_pluginFuncs          = pFuncs;
00093 
00094     return NPERR_NO_ERROR;
00095 }
00096 
00097 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00099 // NP_Initialize
00100 //
00101 //     called immediately after the plugin DLL is loaded
00102 //
00103 NPError WINAPI NP_EXPORT 
00104 NP_Initialize(NPNetscapeFuncs* pFuncs)
00105 {
00106     // trap a NULL ptr 
00107     if(pFuncs == NULL)
00108         return NPERR_INVALID_FUNCTABLE_ERROR;
00109 
00110     g_pNavigatorFuncs = pFuncs; // save it for future reference 
00111 
00112     // if the plugin's major ver level is lower than the Navigator's,
00113     // then they are incompatible, and should return an error 
00114     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
00115         return NPERR_INCOMPATIBLE_VERSION_ERROR;
00116 
00117        // We have to defer these assignments until g_pNavigatorFuncs is set
00118     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
00119 
00120        if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
00121               g_pluginFuncs->urlnotify = NPP_URLNotify;
00122        }
00123        
00124 #ifdef WIN32 // An ugly hack, because Win16 lags behind in Java
00125        if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
00126 #else
00127        if( navMinorVers >= NPVERS_WIN16_HAS_LIVECONNECT )
00128 #endif // WIN32
00129               g_pluginFuncs->javaClass = Private_GetJavaClass();
00130        }
00131 
00132        // NPP_Initialize is a standard (cross-platform) initialize function.
00133     return NPP_Initialize();
00134 }
00135 
00136 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00138 // NP_Shutdown
00139 //
00140 //     called immediately before the plugin DLL is unloaded.
00141 //     This functio shuold check for some ref count on the dll to see if it is
00142 //     unloadable or it needs to stay in memory. 
00143 //
00144 NPError WINAPI NP_EXPORT 
00145 NP_Shutdown()
00146 {
00147     NPP_Shutdown();
00148     g_pNavigatorFuncs = NULL;
00149     return NPERR_NO_ERROR;
00150 }
00151 
00152 //                                        END - PLUGIN DLL entry points   
00154 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00155 
00156 /*    NAVIGATOR Entry points    */
00157 
00158 /* These entry points expect to be called from within the plugin.  The
00159    noteworthy assumption is that DS has already been set to point to the
00160    plugin's DLL data segment.  Don't call these functions from outside
00161    the plugin without ensuring DS is set to the DLLs data segment first,
00162    typically using the NP_LOADDS macro
00163 */
00164 
00165 /* returns the major/minor version numbers of the Plugin API for the plugin
00166    and the Navigator
00167 */
00168 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
00169 {
00170     *plugin_major   = NP_VERSION_MAJOR;
00171     *plugin_minor   = NP_VERSION_MINOR;
00172     *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
00173     *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
00174 }
00175 
00176 /* causes the specified URL to be fetched and streamed in
00177 */
00178 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
00179 
00180 {
00181        int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
00182        NPError err;
00183        if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
00184               err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
00185        }
00186        else {
00187               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00188        }
00189        return err;
00190 }
00191 
00192 
00193 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
00194 {
00195     return g_pNavigatorFuncs->geturl(instance, url, target);
00196 }
00197 
00198 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
00199 {
00200        int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
00201        NPError err;
00202        if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
00203               err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
00204        }
00205        else {
00206               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00207        }
00208        return err;
00209 }
00210 
00211 
00212 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
00213 {
00214     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
00215 }
00216 
00217 /* Requests that a number of bytes be provided on a stream.  Typically
00218    this would be used if a stream was in "pull" mode.  An optional
00219    position can be provided for streams which are seekable.
00220 */
00221 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
00222 {
00223     return g_pNavigatorFuncs->requestread(stream, rangeList);
00224 }
00225 
00226 /* Creates a new stream of data from the plug-in to be interpreted
00227    by Netscape in the current window.
00228 */
00229 NPError NPN_NewStream(NPP instance, NPMIMEType type, 
00230                                                         const char* target, NPStream** stream)
00231 {
00232        int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
00233        NPError err;
00234 
00235        if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
00236               err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
00237        }
00238        else {
00239               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00240        }
00241        return err;
00242 }
00243 
00244 /* Provides len bytes of data.
00245 */
00246 int32 NPN_Write(NPP instance, NPStream *stream,
00247                 int32 len, void *buffer)
00248 {
00249        int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
00250        int32 result;
00251 
00252        if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
00253               result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
00254        }
00255        else {
00256               result = -1;
00257        }
00258        return result;
00259 }
00260 
00261 /* Closes a stream object.  
00262 reason indicates why the stream was closed.
00263 */
00264 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00265 {
00266        int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
00267        NPError err;
00268 
00269        if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
00270               err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
00271        }
00272        else {
00273               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00274        }
00275        return err;
00276 }
00277 
00278 /* Provides a text status message in the Netscape client user interface
00279 */
00280 void NPN_Status(NPP instance, const char *message)
00281 {
00282     g_pNavigatorFuncs->status(instance, message);
00283 }
00284 
00285 /* returns the user agent string of Navigator, which contains version info
00286 */
00287 const char* NPN_UserAgent(NPP instance)
00288 {
00289     return g_pNavigatorFuncs->uagent(instance);
00290 }
00291 
00292 /* allocates memory from the Navigator's memory space.  Necessary so that
00293    saved instance data may be freed by Navigator when exiting.
00294 */
00295 
00296 
00297 void* NPN_MemAlloc(uint32 size)
00298 {
00299     return g_pNavigatorFuncs->memalloc(size);
00300 }
00301 
00302 /* reciprocal of MemAlloc() above
00303 */
00304 void NPN_MemFree(void* ptr)
00305 {
00306     g_pNavigatorFuncs->memfree(ptr);
00307 }
00308 
00309 /* private function to Netscape.  do not use!
00310 */
00311 void NPN_ReloadPlugins(NPBool reloadPages)
00312 {
00313     g_pNavigatorFuncs->reloadplugins(reloadPages);
00314 }
00315 
00316 JRIEnv* NPN_GetJavaEnv(void)
00317 {
00318        return g_pNavigatorFuncs->getJavaEnv();
00319 }
00320 
00321 jref NPN_GetJavaPeer(NPP instance)
00322 {
00323        return g_pNavigatorFuncs->getJavaPeer(instance);
00324 }
00325 
00326 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
00327 {
00328     return g_pNavigatorFuncs->getvalue(instance, variable, result);
00329 }