00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #define XP_UNIX 1
00055
00056 #include <stdio.h>
00057 #include "npapi.h"
00058 #include "npupp.h"
00059
00060
00061
00062
00063
00064
00065 #ifdef PLUGIN_TRACE
00066 #include <stdio.h>
00067 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
00068 #else
00069 #define PLUGINDEBUGSTR(msg)
00070 #endif
00071
00072
00073
00074
00075
00076
00077
00078
00079 static NPNetscapeFuncs gNetscapeFuncs;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 void
00093 NPN_Version(int* plugin_major, int* plugin_minor,
00094 int* netscape_major, int* netscape_minor)
00095 {
00096 *plugin_major = NP_VERSION_MAJOR;
00097 *plugin_minor = NP_VERSION_MINOR;
00098
00099
00100 *netscape_major = gNetscapeFuncs.version >> 8;
00101
00102 *netscape_minor = gNetscapeFuncs.version & 0xFF;
00103 }
00104
00105 NPError
00106 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
00107 {
00108 return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
00109 instance, variable, r_value);
00110 }
00111
00112 NPError
00113 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
00114 {
00115 return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
00116 instance, variable, value);
00117 }
00118
00119 NPError
00120 NPN_GetURL(NPP instance, const char* url, const char* window)
00121 {
00122 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
00123 }
00124
00125 NPError
00126 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
00127 {
00128 return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
00129 }
00130
00131 NPError
00132 NPN_PostURL(NPP instance, const char* url, const char* window,
00133 uint32 len, const char* buf, NPBool file)
00134 {
00135 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
00136 url, window, len, buf, file);
00137 }
00138
00139 NPError
00140 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len,
00141 const char* buf, NPBool file, void* notifyData)
00142 {
00143 return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
00144 instance, url, window, len, buf, file, notifyData);
00145 }
00146
00147 NPError
00148 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
00149 {
00150 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
00151 stream, rangeList);
00152 }
00153
00154 NPError
00155 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
00156 NPStream** stream_ptr)
00157 {
00158 return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
00159 type, window, stream_ptr);
00160 }
00161
00162 int32
00163 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
00164 {
00165 return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
00166 stream, len, buffer);
00167 }
00168
00169 NPError
00170 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00171 {
00172 return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
00173 instance, stream, reason);
00174 }
00175
00176 void
00177 NPN_Status(NPP instance, const char* message)
00178 {
00179 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
00180 }
00181
00182 const char*
00183 NPN_UserAgent(NPP instance)
00184 {
00185 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
00186 }
00187
00188 void*
00189 NPN_MemAlloc(uint32 size)
00190 {
00191 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
00192 }
00193
00194 void NPN_MemFree(void* ptr)
00195 {
00196 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
00197 }
00198
00199 uint32 NPN_MemFlush(uint32 size)
00200 {
00201 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
00202 }
00203
00204 void NPN_ReloadPlugins(NPBool reloadPages)
00205 {
00206 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
00207 }
00208
00209 #ifdef OJI
00210 JRIEnv* NPN_GetJavaEnv()
00211 {
00212 return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
00213 }
00214
00215 jref NPN_GetJavaPeer(NPP instance)
00216 {
00217 return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
00218 instance);
00219 }
00220 #endif
00221
00222 void
00223 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
00224 {
00225 CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
00226 invalidRect);
00227 }
00228
00229 void
00230 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
00231 {
00232 CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
00233 invalidRegion);
00234 }
00235
00236 void
00237 NPN_ForceRedraw(NPP instance)
00238 {
00239 CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
00240 }
00241
00242 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
00243 {
00244 CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
00245 instance, enabled);
00246 }
00247
00248 void NPN_PopPopupsEnabledState(NPP instance)
00249 {
00250 CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
00251 instance);
00252 }
00253
00254 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
00255 {
00256 return CallNPN_GetStringIdentifierProc(gNetscapeFuncs.getstringidentifier,
00257 name);
00258 }
00259
00260 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
00261 NPIdentifier *identifiers)
00262 {
00263 CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
00264 names, nameCount, identifiers);
00265 }
00266
00267 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
00268 {
00269 return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
00270 }
00271
00272 bool NPN_IdentifierIsString(NPIdentifier identifier)
00273 {
00274 return CallNPN_IdentifierIsStringProc(gNetscapeFuncs.identifierisstring,
00275 identifier);
00276 }
00277
00278 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
00279 {
00280 return CallNPN_UTF8FromIdentifierProc(gNetscapeFuncs.utf8fromidentifier,
00281 identifier);
00282 }
00283
00284 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
00285 {
00286 return CallNPN_IntFromIdentifierProc(gNetscapeFuncs.intfromidentifier,
00287 identifier);
00288 }
00289
00290 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
00291 {
00292 return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
00293 }
00294
00295 NPObject *NPN_RetainObject(NPObject *obj)
00296 {
00297 return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
00298 }
00299
00300 void NPN_ReleaseObject(NPObject *obj)
00301 {
00302 CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
00303 }
00304
00305 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
00306 const NPVariant *args, uint32_t argCount, NPVariant *result)
00307 {
00308 return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
00309 args, argCount, result);
00310 }
00311
00312 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
00313 uint32_t argCount, NPVariant *result)
00314 {
00315 return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
00316 args, argCount, result);
00317 }
00318
00319 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
00320 NPVariant *result)
00321 {
00322 return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj, script, result);
00323 }
00324
00325 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
00326 NPVariant *result)
00327 {
00328 return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
00329 propertyName, result);
00330 }
00331
00332 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
00333 const NPVariant *value)
00334 {
00335 return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
00336 propertyName, value);
00337 }
00338
00339 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
00340 {
00341 return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
00342 propertyName);
00343 }
00344
00345 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
00346 {
00347 return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
00348 propertyName);
00349 }
00350
00351 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
00352 {
00353 return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp, obj, methodName);
00354 }
00355
00356 void NPN_ReleaseVariantValue(NPVariant *variant)
00357 {
00358 CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
00359 }
00360
00361 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
00362 {
00363 CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 NPError
00379 Private_New(NPMIMEType pluginType, NPP instance, uint16 mode,
00380 int16 argc, char* argn[], char* argv[], NPSavedData* saved)
00381 {
00382 NPError ret;
00383 PLUGINDEBUGSTR("New");
00384 ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
00385 return ret;
00386 }
00387
00388 NPError
00389 Private_Destroy(NPP instance, NPSavedData** save)
00390 {
00391 PLUGINDEBUGSTR("Destroy");
00392 return NPP_Destroy(instance, save);
00393 }
00394
00395 NPError
00396 Private_SetWindow(NPP instance, NPWindow* window)
00397 {
00398 NPError err;
00399 PLUGINDEBUGSTR("SetWindow");
00400 err = NPP_SetWindow(instance, window);
00401 return err;
00402 }
00403
00404 NPError
00405 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
00406 NPBool seekable, uint16* stype)
00407 {
00408 NPError err;
00409 PLUGINDEBUGSTR("NewStream");
00410 err = NPP_NewStream(instance, type, stream, seekable, stype);
00411 return err;
00412 }
00413
00414 int32
00415 Private_WriteReady(NPP instance, NPStream* stream)
00416 {
00417 unsigned int result;
00418 PLUGINDEBUGSTR("WriteReady");
00419 result = NPP_WriteReady(instance, stream);
00420 return result;
00421 }
00422
00423 int32
00424 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
00425 void* buffer)
00426 {
00427 unsigned int result;
00428 PLUGINDEBUGSTR("Write");
00429 result = NPP_Write(instance, stream, offset, len, buffer);
00430 return result;
00431 }
00432
00433 void
00434 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
00435 {
00436 PLUGINDEBUGSTR("StreamAsFile");
00437 NPP_StreamAsFile(instance, stream, fname);
00438 }
00439
00440
00441 NPError
00442 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00443 {
00444 NPError err;
00445 PLUGINDEBUGSTR("DestroyStream");
00446 err = NPP_DestroyStream(instance, stream, reason);
00447 return err;
00448 }
00449
00450 void
00451 Private_URLNotify(NPP instance, const char* url,
00452 NPReason reason, void* notifyData)
00453
00454 {
00455 PLUGINDEBUGSTR("URLNotify");
00456 NPP_URLNotify(instance, url, reason, notifyData);
00457 }
00458
00459
00460
00461 void
00462 Private_Print(NPP instance, NPPrint* platformPrint)
00463 {
00464 PLUGINDEBUGSTR("Print");
00465 NPP_Print(instance, platformPrint);
00466 }
00467
00468 #ifdef OJI
00469 JRIGlobalRef
00470 Private_GetJavaClass(void)
00471 {
00472 jref clazz = NPP_GetJavaClass();
00473 if (clazz) {
00474 JRIEnv* env = NPN_GetJavaEnv();
00475 return JRI_NewGlobalRef(env, clazz);
00476 }
00477 return NULL;
00478 }
00479 #endif
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 char *
00494 NP_GetMIMEDescription(void)
00495 {
00496 return NPP_GetMIMEDescription();
00497 }
00498
00499
00500
00501
00502
00503
00504
00505 NPError
00506 NP_GetValue(void* future, NPPVariable variable, void *value)
00507 {
00508 return NPP_GetValue(future, variable, value);
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 NPError
00529 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
00530 {
00531 NPError err = NPERR_NO_ERROR;
00532
00533 PLUGINDEBUGSTR("NP_Initialize");
00534
00535
00536
00537 if ((nsTable == NULL) || (pluginFuncs == NULL))
00538 err = NPERR_INVALID_FUNCTABLE_ERROR;
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 if (err == NPERR_NO_ERROR) {
00550 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
00551 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00552 if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
00553 err = NPERR_INVALID_FUNCTABLE_ERROR;
00554 if (pluginFuncs->size < sizeof(NPPluginFuncs))
00555 err = NPERR_INVALID_FUNCTABLE_ERROR;
00556 }
00557
00558
00559 if (err == NPERR_NO_ERROR) {
00560
00561
00562
00563
00564
00565
00566
00567 gNetscapeFuncs.version = nsTable->version;
00568 gNetscapeFuncs.size = nsTable->size;
00569 gNetscapeFuncs.posturl = nsTable->posturl;
00570 gNetscapeFuncs.geturl = nsTable->geturl;
00571 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
00572 gNetscapeFuncs.requestread = nsTable->requestread;
00573 gNetscapeFuncs.newstream = nsTable->newstream;
00574 gNetscapeFuncs.write = nsTable->write;
00575 gNetscapeFuncs.destroystream = nsTable->destroystream;
00576 gNetscapeFuncs.status = nsTable->status;
00577 gNetscapeFuncs.uagent = nsTable->uagent;
00578 gNetscapeFuncs.memalloc = nsTable->memalloc;
00579 gNetscapeFuncs.memfree = nsTable->memfree;
00580 gNetscapeFuncs.memflush = nsTable->memflush;
00581 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
00582 #ifdef OJI
00583 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
00584 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
00585 #endif
00586 gNetscapeFuncs.getvalue = nsTable->getvalue;
00587 gNetscapeFuncs.setvalue = nsTable->setvalue;
00588 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
00589
00590 if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
00591 {
00592 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
00593 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
00594 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
00595 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
00596 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
00597 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
00598 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
00599 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
00600 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
00601 gNetscapeFuncs.createobject = nsTable->createobject;
00602 gNetscapeFuncs.retainobject = nsTable->retainobject;
00603 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
00604 gNetscapeFuncs.invoke = nsTable->invoke;
00605 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
00606 gNetscapeFuncs.evaluate = nsTable->evaluate;
00607 gNetscapeFuncs.getproperty = nsTable->getproperty;
00608 gNetscapeFuncs.setproperty = nsTable->setproperty;
00609 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
00610 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
00611 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
00612 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
00613 gNetscapeFuncs.setexception = nsTable->setexception;
00614 }
00615 else
00616 {
00617 gNetscapeFuncs.invalidaterect = NULL;
00618 gNetscapeFuncs.invalidateregion = NULL;
00619 gNetscapeFuncs.forceredraw = NULL;
00620 gNetscapeFuncs.getstringidentifier = NULL;
00621 gNetscapeFuncs.getstringidentifiers = NULL;
00622 gNetscapeFuncs.getintidentifier = NULL;
00623 gNetscapeFuncs.identifierisstring = NULL;
00624 gNetscapeFuncs.utf8fromidentifier = NULL;
00625 gNetscapeFuncs.intfromidentifier = NULL;
00626 gNetscapeFuncs.createobject = NULL;
00627 gNetscapeFuncs.retainobject = NULL;
00628 gNetscapeFuncs.releaseobject = NULL;
00629 gNetscapeFuncs.invoke = NULL;
00630 gNetscapeFuncs.invokeDefault = NULL;
00631 gNetscapeFuncs.evaluate = NULL;
00632 gNetscapeFuncs.getproperty = NULL;
00633 gNetscapeFuncs.setproperty = NULL;
00634 gNetscapeFuncs.removeproperty = NULL;
00635 gNetscapeFuncs.hasproperty = NULL;
00636 gNetscapeFuncs.releasevariantvalue = NULL;
00637 gNetscapeFuncs.setexception = NULL;
00638 }
00639 if (nsTable->size >=
00640 ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
00641 {
00642 gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
00643 gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
00644 }
00645 else
00646 {
00647 gNetscapeFuncs.pushpopupsenabledstate = NULL;
00648 gNetscapeFuncs.poppopupsenabledstate = NULL;
00649 }
00650
00651 gNetscapeFuncs.pluginthreadasynccall = nsTable->pluginthreadasynccall;
00652
00653
00654
00655
00656
00657
00658
00659 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
00660 pluginFuncs->size = sizeof(NPPluginFuncs);
00661 pluginFuncs->newp = NewNPP_NewProc(Private_New);
00662 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
00663 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
00664 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
00665 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
00666 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
00667 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
00668 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
00669 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
00670 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
00671 pluginFuncs->event = NULL;
00672 #ifdef OJI
00673 pluginFuncs->javaClass = Private_GetJavaClass();
00674 #endif
00675
00676
00677 pluginFuncs->getvalue = NewNPP_GetValueProc(NP_GetValue);
00678
00679 err = NPP_Initialize();
00680 }
00681
00682 return err;
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692 NPError
00693 NP_Shutdown(void)
00694 {
00695 PLUGINDEBUGSTR("NP_Shutdown");
00696 NPP_Shutdown();
00697 return NPERR_NO_ERROR;
00698 }
00699
00700 void NPN_PluginThreadAsyncCall (NPP instance, void (*func)(void *), void
00701 *userData)
00702 {
00703 CallNPN_PluginThreadAsyncCallProc (
00704 gNetscapeFuncs.pluginthreadasynccall,
00705 instance,
00706 func,
00707 userData);
00708 }