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