Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

npunix.c

00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * The contents of this file are subject to the Mozilla Public
00004  * License Version 1.1 (the "License"); you may not use this file
00005  * except in compliance with the License. You may obtain a copy of
00006  * the License at http://www.mozilla.org/MPL/
00007  * 
00008  * Software distributed under the License is distributed on an "AS
00009  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00010  * implied. See the License for the specific language governing
00011  * rights and limitations under the License.
00012  * 
00013  * The Original Code is mozilla.org code.
00014  *
00015  * The Initial Developer of the Original Code is Netscape
00016  * Communications Corporation.  Portions created by Netscape are
00017  * Copyright (C) 1998 Netscape Communications Corporation. All
00018  * Rights Reserved.
00019  *
00020  * Contributor(s): 
00021  * Stephen Mak <[email protected]>
00022  */
00023 
00024 /*
00025  * npunix.c
00026  *
00027  * Netscape Client Plugin API
00028  * - Wrapper function to interface with the Netscape Navigator
00029  *
00030  * dp Suresh <[email protected]>
00031  *
00032  *----------------------------------------------------------------------
00033  * PLUGIN DEVELOPERS:
00034  *  YOU WILL NOT NEED TO EDIT THIS FILE.
00035  * TO NETSCAPE DEVELOPERS:
00036  *  OF COURSE I WILL NEED TO EDIT THIS FILE, YOU BORKED IT ALL AROUND YOU
00037  *  IGNORANT FOOLS -- sam
00038  *----------------------------------------------------------------------
00039  */
00040 
00041 #define XP_UNIX 1
00042 #define OJI 1
00043 
00044 #include <stdio.h>
00045 #include "nscore.h"
00046 #include "npapi.h"
00047 #include "npupp.h"
00048 
00049 /*
00050  * Define PLUGIN_TRACE to have the wrapper functions print
00051  * messages to stderr whenever they are called.
00052  */
00053 
00054 #ifdef PLUGIN_TRACE
00055 #include <stdio.h>
00056 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
00057 #else
00058 #define PLUGINDEBUGSTR(msg)
00059 #endif
00060 
00061 
00062 /***********************************************************************
00063  *
00064  * Globals
00065  *
00066  ***********************************************************************/
00067 
00068 static NPNetscapeFuncs   gNetscapeFuncs;    /* Netscape Function table */
00069 
00070 
00071 /***********************************************************************
00072  *
00073  * Wrapper functions : plugin calling Netscape Navigator
00074  *
00075  * These functions let the plugin developer just call the APIs
00076  * as documented and defined in npapi.h, without needing to know
00077  * about the function table and call macros in npupp.h.
00078  *
00079  ***********************************************************************/
00080 
00081 void
00082 NPN_Version(int* plugin_major, int* plugin_minor,
00083          int* netscape_major, int* netscape_minor)
00084 {
00085     *plugin_major = NP_VERSION_MAJOR;
00086     *plugin_minor = NP_VERSION_MINOR;
00087 
00088     /* Major version is in high byte */
00089     *netscape_major = gNetscapeFuncs.version >> 8;
00090     /* Minor version is in low byte */
00091     *netscape_minor = gNetscapeFuncs.version & 0xFF;
00092 }
00093 
00094 NPError
00095 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
00096 {
00097     return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
00098                     instance, variable, r_value);
00099 }
00100 
00101 NPError
00102 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
00103 {
00104     return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
00105                     instance, variable, value);
00106 }
00107 
00108 NPError
00109 NPN_GetURL(NPP instance, const char* url, const char* window)
00110 {
00111     return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
00112 }
00113 
00114 NPError
00115 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
00116 {
00117     return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
00118 }
00119 
00120 NPError
00121 NPN_PostURL(NPP instance, const char* url, const char* window,
00122          uint32 len, const char* buf, NPBool file)
00123 {
00124     return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
00125                     url, window, len, buf, file);
00126 }
00127 
00128 NPError
00129 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len,
00130                   const char* buf, NPBool file, void* notifyData)
00131 {
00132     return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
00133             instance, url, window, len, buf, file, notifyData);
00134 }
00135 
00136 NPError
00137 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
00138 {
00139     return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
00140                     stream, rangeList);
00141 }
00142 
00143 NPError
00144 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
00145           NPStream** stream_ptr)
00146 {
00147     return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
00148                     type, window, stream_ptr);
00149 }
00150 
00151 int32
00152 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
00153 {
00154     return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
00155                     stream, len, buffer);
00156 }
00157 
00158 NPError
00159 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00160 {
00161     return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
00162                         instance, stream, reason);
00163 }
00164 
00165 void
00166 NPN_Status(NPP instance, const char* message)
00167 {
00168     CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
00169 }
00170 
00171 const char*
00172 NPN_UserAgent(NPP instance)
00173 {
00174     return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
00175 }
00176 
00177 void*
00178 NPN_MemAlloc(uint32 size)
00179 {
00180     return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
00181 }
00182 
00183 void NPN_MemFree(void* ptr)
00184 {
00185     CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
00186 }
00187 
00188 uint32 NPN_MemFlush(uint32 size)
00189 {
00190     return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
00191 }
00192 
00193 void NPN_ReloadPlugins(NPBool reloadPages)
00194 {
00195     CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
00196 }
00197 
00198 JRIEnv* NPN_GetJavaEnv()
00199 {
00200     return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
00201 }
00202 
00203 jref NPN_GetJavaPeer(NPP instance)
00204 {
00205     return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
00206                        instance);
00207 }
00208 
00209 void
00210 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
00211 {
00212     CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
00213         invalidRect);
00214 }
00215 
00216 void
00217 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
00218 {
00219     CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
00220         invalidRegion);
00221 }
00222 
00223 void
00224 NPN_ForceRedraw(NPP instance)
00225 {
00226     CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
00227 }
00228 
00229 
00230 
00231 /***********************************************************************
00232  *
00233  * Wrapper functions : Netscape Navigator -> plugin
00234  *
00235  * These functions let the plugin developer just create the APIs
00236  * as documented and defined in npapi.h, without needing to 
00237  * install those functions in the function table or worry about
00238  * setting up globals for 68K plugins.
00239  *
00240  ***********************************************************************/
00241 
00242 NPError
00243 Private_New(NPMIMEType pluginType, NPP instance, uint16 mode,
00244         int16 argc, char* argn[], char* argv[], NPSavedData* saved)
00245 {
00246     NPError ret;
00247     PLUGINDEBUGSTR("New");
00248     ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
00249     return ret; 
00250 }
00251 
00252 NPError
00253 Private_Destroy(NPP instance, NPSavedData** save)
00254 {
00255     PLUGINDEBUGSTR("Destroy");
00256     return NPP_Destroy(instance, save);
00257 }
00258 
00259 NPError
00260 Private_SetWindow(NPP instance, NPWindow* window)
00261 {
00262     NPError err;
00263     PLUGINDEBUGSTR("SetWindow");
00264     err = NPP_SetWindow(instance, window);
00265     return err;
00266 }
00267 
00268 NPError
00269 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
00270             NPBool seekable, uint16* stype)
00271 {
00272     NPError err;
00273     PLUGINDEBUGSTR("NewStream");
00274     err = NPP_NewStream(instance, type, stream, seekable, stype);
00275     return err;
00276 }
00277 
00278 int32
00279 Private_WriteReady(NPP instance, NPStream* stream)
00280 {
00281     unsigned int result;
00282     PLUGINDEBUGSTR("WriteReady");
00283     result = NPP_WriteReady(instance, stream);
00284     return result;
00285 }
00286 
00287 int32
00288 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
00289         void* buffer)
00290 {
00291     unsigned int result;
00292     PLUGINDEBUGSTR("Write");
00293     result = NPP_Write(instance, stream, offset, len, buffer);
00294     return result;
00295 }
00296 
00297 void
00298 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
00299 {
00300     PLUGINDEBUGSTR("StreamAsFile");
00301     NPP_StreamAsFile(instance, stream, fname);
00302 }
00303 
00304 
00305 NPError
00306 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00307 {
00308     NPError err;
00309     PLUGINDEBUGSTR("DestroyStream");
00310     err = NPP_DestroyStream(instance, stream, reason);
00311     return err;
00312 }
00313 
00314 void
00315 Private_URLNotify(NPP instance, const char* url,
00316                 NPReason reason, void* notifyData)
00317                 
00318 {
00319     PLUGINDEBUGSTR("URLNotify");
00320     NPP_URLNotify(instance, url, reason, notifyData);
00321 }
00322 
00323 
00324 
00325 void
00326 Private_Print(NPP instance, NPPrint* platformPrint)
00327 {
00328     PLUGINDEBUGSTR("Print");
00329     NPP_Print(instance, platformPrint);
00330 }
00331 
00332 NPError
00333 Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
00334 {
00335     PLUGINDEBUGSTR("GetValue");
00336 return NPP_GetValue(instance, variable, r_value);
00337 }
00338 
00339 JRIGlobalRef
00340 Private_GetJavaClass(void)
00341 {
00342     jref clazz = NPP_GetJavaClass();
00343     if (clazz) {
00344     JRIEnv* env = NPN_GetJavaEnv();
00345     return JRI_NewGlobalRef(env, clazz);
00346     }
00347     return NULL;
00348 }
00349 
00350 /*********************************************************************** 
00351  *
00352  * These functions are located automagically by netscape.
00353  *
00354  ***********************************************************************/
00355 
00356 /*
00357  * NP_GetMIMEDescription
00358  *  - Netscape needs to know about this symbol
00359  *  - Netscape uses the return value to identify when an object instance
00360  *    of this plugin should be created.
00361  */
00362 char *
00363 NP_GetMIMEDescription(void)
00364 {
00365     return NPP_GetMIMEDescription();
00366 }
00367 
00368 /*
00369  * NP_GetValue [optional]
00370  *  - Netscape needs to know about this symbol.
00371  *  - Interfaces with plugin to get values for predefined variables
00372  *    that the navigator needs.
00373  */
00374 NPError
00375 NP_GetValue(void *future, NPPVariable variable, void *value)
00376 {
00377     return NPP_GetValue(future, variable, value);
00378 }
00379 
00380 /*
00381  * NP_Initialize
00382  *  - Netscape needs to know about this symbol.
00383  *  - It calls this function after looking up its symbol before it
00384  *    is about to create the first ever object of this kind.
00385  *
00386  * PARAMETERS
00387  *    nsTable   - The netscape function table. If developers just use these
00388  *        wrappers, they dont need to worry about all these function
00389  *        tables.
00390  * RETURN
00391  *    pluginFuncs
00392  *      - This functions needs to fill the plugin function table
00393  *        pluginFuncs and return it. Netscape Navigator plugin
00394  *        library will use this function table to call the plugin.
00395  *
00396  */
00397 NPError
00398 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
00399 {
00400     NPError err = NPERR_NO_ERROR;
00401 
00402     PLUGINDEBUGSTR("NP_Initialize");
00403     
00404     /* validate input parameters */
00405 
00406     if ((nsTable == NULL) || (pluginFuncs == NULL))
00407         err = NPERR_INVALID_FUNCTABLE_ERROR;
00408     
00409     /*
00410      * Check the major version passed in Netscape's function table.
00411      * We won't load if the major version is newer than what we expect.
00412      * Also check that the function tables passed in are big enough for
00413      * all the functions we need (they could be bigger, if Netscape added
00414      * new APIs, but that's OK with us -- we'll just ignore them).
00415      *
00416      */
00417 
00418     if (err == NPERR_NO_ERROR) {
00419         if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
00420             err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00421         if (nsTable->size < sizeof(NPNetscapeFuncs))
00422             err = NPERR_INVALID_FUNCTABLE_ERROR;
00423         if (pluginFuncs->size < sizeof(NPPluginFuncs))      
00424             err = NPERR_INVALID_FUNCTABLE_ERROR;
00425     }
00426         
00427     
00428     if (err == NPERR_NO_ERROR) {
00429         /*
00430          * Copy all the fields of Netscape function table into our
00431          * copy so we can call back into Netscape later.  Note that
00432          * we need to copy the fields one by one, rather than assigning
00433          * the whole structure, because the Netscape function table
00434          * could actually be bigger than what we expect.
00435          */
00436         gNetscapeFuncs.version       = nsTable->version;
00437         gNetscapeFuncs.size          = nsTable->size;
00438         gNetscapeFuncs.posturl       = nsTable->posturl;
00439         gNetscapeFuncs.geturl        = nsTable->geturl;
00440         gNetscapeFuncs.geturlnotify  = nsTable->geturlnotify;
00441         gNetscapeFuncs.requestread   = nsTable->requestread;
00442         gNetscapeFuncs.newstream     = nsTable->newstream;
00443         gNetscapeFuncs.write         = nsTable->write;
00444         gNetscapeFuncs.destroystream = nsTable->destroystream;
00445         gNetscapeFuncs.status        = nsTable->status;
00446         gNetscapeFuncs.uagent        = nsTable->uagent;
00447         gNetscapeFuncs.memalloc      = nsTable->memalloc;
00448         gNetscapeFuncs.memfree       = nsTable->memfree;
00449         gNetscapeFuncs.memflush      = nsTable->memflush;
00450         gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
00451         gNetscapeFuncs.getJavaEnv    = nsTable->getJavaEnv;
00452         gNetscapeFuncs.getJavaPeer   = nsTable->getJavaPeer;
00453         gNetscapeFuncs.getvalue      = nsTable->getvalue;
00454 
00455         /*
00456          * Set up the plugin function table that Netscape will use to
00457          * call us.  Netscape needs to know about our version and size
00458          * and have a UniversalProcPointer for every function we
00459          * implement.
00460          */
00461         pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
00462         pluginFuncs->size       = sizeof(NPPluginFuncs);
00463         pluginFuncs->newp       = NewNPP_NewProc(Private_New);
00464         pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
00465         pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
00466         pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
00467         pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
00468         pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
00469         pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
00470         pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
00471         pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
00472         pluginFuncs->urlnotify  = NewNPP_URLNotifyProc(Private_URLNotify);
00473         pluginFuncs->event      = NULL;
00474         pluginFuncs->javaClass  = Private_GetJavaClass();
00475         pluginFuncs->getvalue   = NewNPP_GetValueProc(Private_GetValue);
00476         
00477         err = NPP_Initialize();
00478     }
00479     
00480     return err;
00481 }
00482 
00483 /*
00484  * NP_Shutdown [optional]
00485  *  - Netscape needs to know about this symbol.
00486  *  - It calls this function after looking up its symbol after
00487  *    the last object of this kind has been destroyed.
00488  *
00489  */
00490 NPError
00491 NP_Shutdown(void)
00492 {
00493     PLUGINDEBUGSTR("NP_Shutdown");
00494     NPP_Shutdown();
00495     return NPERR_NO_ERROR;
00496 }

Generated on Tue Dec 20 10:14:59 2005 for vlc-0.8.4a by  doxygen 1.4.2