1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* Mozilla/Firefox plugin for VLC
4
* Copyright (C) 2009, Jean-Paul Saman <jpsaman@videolan.org>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
* The Original Code is mozilla.org code.
22
* The Initial Developer of the Original Code is
23
* Netscape Communications Corporation.
24
* Portions created by the Initial Developer are Copyright (C) 1998
25
* the Initial Developer. All Rights Reserved.
28
* Stephen Mak <smak@sun.com>
35
* Netscape Client Plugin API
36
* - Wrapper function to interface with the Netscape Navigator
38
* dp Suresh <dp@netscape.com>
40
*----------------------------------------------------------------------
42
* YOU WILL NOT NEED TO EDIT THIS FILE.
43
*----------------------------------------------------------------------
53
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
56
#include "npfunctions.h"
59
#include "../vlcshell.h"
62
* Define PLUGIN_TRACE to have the wrapper functions print
63
* messages to stderr whenever they are called.
68
#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
70
#define PLUGINDEBUGSTR(msg)
73
/***********************************************************************
77
***********************************************************************/
79
static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
81
/***********************************************************************
83
* Wrapper functions : plugin calling Netscape Navigator
85
* These functions let the plugin developer just call the APIs
86
* as documented and defined in npapi.h, without needing to know
87
* about the function table and call macros in npupp.h.
89
***********************************************************************/
92
NPN_Version(int* plugin_major, int* plugin_minor,
93
int* netscape_major, int* netscape_minor)
95
*plugin_major = NP_VERSION_MAJOR;
96
*plugin_minor = NP_VERSION_MINOR;
98
/* Major version is in high byte */
99
*netscape_major = gNetscapeFuncs.version >> 8;
100
/* Minor version is in low byte */
101
*netscape_minor = gNetscapeFuncs.version & 0xFF;
105
NPN_PluginThreadAsyncCall(NPP plugin,
106
void (*func)(void *),
109
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
110
return (*gNetscapeFuncs.pluginthreadasynccall)(plugin, func, userData);
115
NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
117
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
118
return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
119
instance, variable, r_value);
121
return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
126
NPN_SetValue(NPP instance, NPPVariable variable, void *value)
128
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
129
return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
130
instance, variable, value);
132
return (*gNetscapeFuncs.setvalue)(instance, variable, value);
137
NPN_GetURL(NPP instance, const char* url, const char* window)
139
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
140
return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
142
return (*gNetscapeFuncs.geturl)(instance, url, window);
147
NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
149
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
150
return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
152
return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
157
NPN_PostURL(NPP instance, const char* url, const char* window,
158
uint32_t len, const char* buf, NPBool file)
160
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
161
return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
162
url, window, len, buf, file);
164
return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
169
NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
170
const char* buf, NPBool file, void* notifyData)
172
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
173
return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
174
instance, url, window, len, buf, file, notifyData);
176
return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);
182
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
184
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
185
return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
188
return (*gNetscapeFuncs.requestread)(stream, rangeList);
193
NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
194
NPStream** stream_ptr)
196
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
197
return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
198
type, window, stream_ptr);
200
return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
205
NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
207
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
208
return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
209
stream, len, buffer);
211
return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
216
NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
218
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
219
return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
220
instance, stream, reason);
222
return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
227
NPN_Status(NPP instance, const char* message)
229
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
230
CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
232
(*gNetscapeFuncs.status)(instance, message);
237
NPN_UserAgent(NPP instance)
239
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
240
return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
242
return (*gNetscapeFuncs.uagent)(instance);
246
void *NPN_MemAlloc(uint32_t size)
248
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
249
return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
251
return (*gNetscapeFuncs.memalloc)(size);
255
void NPN_MemFree(void* ptr)
257
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
258
CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
260
(*gNetscapeFuncs.memfree)(ptr);
264
uint32_t NPN_MemFlush(uint32_t size)
266
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
267
return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
269
return (*gNetscapeFuncs.memflush)(size);
273
void NPN_ReloadPlugins(NPBool reloadPages)
275
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
276
CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
278
(*gNetscapeFuncs.reloadplugins)(reloadPages);
283
JRIEnv* NPN_GetJavaEnv()
285
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
286
return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
288
return (*gNetscapeFuncs.getJavaEnv);
292
jref NPN_GetJavaPeer(NPP instance)
294
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
295
return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
298
return (*gNetscapeFuncs.getJavaPeer)(instance);
304
NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
306
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
307
CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
310
(*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
315
NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
317
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
318
CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
321
(*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
326
NPN_ForceRedraw(NPP instance)
328
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
329
CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
331
(*gNetscapeFuncs.forceredraw)(instance);
335
void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
337
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
338
CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
341
(*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
345
void NPN_PopPopupsEnabledState(NPP instance)
347
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
348
CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
351
(*gNetscapeFuncs.poppopupsenabledstate)(instance);
355
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
357
int minor = gNetscapeFuncs.version & 0xFF;
360
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
361
return CallNPN_GetStringIdentifierProc(
362
gNetscapeFuncs.getstringidentifier, name);
364
return (*gNetscapeFuncs.getstringidentifier)(name);
370
void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
371
NPIdentifier *identifiers)
373
int minor = gNetscapeFuncs.version & 0xFF;
376
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
377
CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
378
names, nameCount, identifiers);
380
(*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
385
NPIdentifier NPN_GetIntIdentifier(int32_t intid)
387
int minor = gNetscapeFuncs.version & 0xFF;
390
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
391
return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
393
return (*gNetscapeFuncs.getintidentifier)(intid);
399
bool NPN_IdentifierIsString(NPIdentifier identifier)
401
int minor = gNetscapeFuncs.version & 0xFF;
404
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
405
return CallNPN_IdentifierIsStringProc(
406
gNetscapeFuncs.identifierisstring,
409
return (*gNetscapeFuncs.identifierisstring)(identifier);
415
NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
417
int minor = gNetscapeFuncs.version & 0xFF;
420
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
421
return CallNPN_UTF8FromIdentifierProc(
422
gNetscapeFuncs.utf8fromidentifier,
425
return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
431
int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
433
int minor = gNetscapeFuncs.version & 0xFF;
436
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
437
return CallNPN_IntFromIdentifierProc(
438
gNetscapeFuncs.intfromidentifier,
441
return (*gNetscapeFuncs.intfromidentifier)(identifier);
447
NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
449
int minor = gNetscapeFuncs.version & 0xFF;
451
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
452
return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
454
return (*gNetscapeFuncs.createobject)(npp, aClass);
459
NPObject *NPN_RetainObject(NPObject *obj)
461
int minor = gNetscapeFuncs.version & 0xFF;
463
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
464
return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
466
return (*gNetscapeFuncs.retainobject)(obj);
471
void NPN_ReleaseObject(NPObject *obj)
473
int minor = gNetscapeFuncs.version & 0xFF;
475
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
476
CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
478
(*gNetscapeFuncs.releaseobject)(obj);
482
bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
483
const NPVariant *args, uint32_t argCount, NPVariant *result)
485
int minor = gNetscapeFuncs.version & 0xFF;
487
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
488
return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
489
args, argCount, result);
491
return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
496
bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
497
uint32_t argCount, NPVariant *result)
499
int minor = gNetscapeFuncs.version & 0xFF;
501
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
502
return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
503
args, argCount, result);
505
return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
510
bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
513
int minor = gNetscapeFuncs.version & 0xFF;
515
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
516
return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
519
return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
524
bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
527
int minor = gNetscapeFuncs.version & 0xFF;
529
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
530
return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
531
propertyName, result);
533
return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
538
bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
539
const NPVariant *value)
541
int minor = gNetscapeFuncs.version & 0xFF;
543
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
544
return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
545
propertyName, value);
547
return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
552
bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
554
int minor = gNetscapeFuncs.version & 0xFF;
556
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
557
return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
560
return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
565
bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
567
int minor = gNetscapeFuncs.version & 0xFF;
569
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
570
return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
573
return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
578
bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
580
int minor = gNetscapeFuncs.version & 0xFF;
582
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
583
return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
586
return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
591
void NPN_ReleaseVariantValue(NPVariant *variant)
593
int minor = gNetscapeFuncs.version & 0xFF;
595
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
596
CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
598
(*gNetscapeFuncs.releasevariantvalue)(variant);
602
void NPN_SetException(NPObject* obj, const NPUTF8 *message)
604
int minor = gNetscapeFuncs.version & 0xFF;
606
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
607
CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
609
(*gNetscapeFuncs.setexception)(obj, message);
613
/***********************************************************************
615
* Wrapper functions : Netscape Navigator -> plugin
617
* These functions let the plugin developer just create the APIs
618
* as documented and defined in npapi.h, without needing to
619
* install those functions in the function table or worry about
620
* setting up globals for 68K plugins.
622
***********************************************************************/
624
/* Function prototypes */
625
NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
626
int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
627
NPError Private_Destroy(NPP instance, NPSavedData** save);
628
NPError Private_SetWindow(NPP instance, NPWindow* window);
629
NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
630
NPBool seekable, uint16_t* stype);
631
int32_t Private_WriteReady(NPP instance, NPStream* stream);
632
int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
633
int32_t len, void* buffer);
634
void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
635
NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
636
void Private_URLNotify(NPP instance, const char* url,
637
NPReason reason, void* notifyData);
638
void Private_Print(NPP instance, NPPrint* platformPrint);
639
NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
640
NPError Private_SetValue(NPP instance, NPNVariable variable, void *r_value);
642
JRIGlobalRef Private_GetJavaClass(void);
645
/* function implementations */
647
Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
648
int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
651
PLUGINDEBUGSTR("New");
652
ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
657
Private_Destroy(NPP instance, NPSavedData** save)
659
PLUGINDEBUGSTR("Destroy");
660
return NPP_Destroy(instance, save);
664
Private_SetWindow(NPP instance, NPWindow* window)
667
PLUGINDEBUGSTR("SetWindow");
668
err = NPP_SetWindow(instance, window);
673
Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
674
NPBool seekable, uint16_t* stype)
677
PLUGINDEBUGSTR("NewStream");
678
err = NPP_NewStream(instance, type, stream, seekable, stype);
683
Private_WriteReady(NPP instance, NPStream* stream)
686
PLUGINDEBUGSTR("WriteReady");
687
result = NPP_WriteReady(instance, stream);
692
Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
696
PLUGINDEBUGSTR("Write");
697
result = NPP_Write(instance, stream, offset, len, buffer);
702
Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
704
PLUGINDEBUGSTR("StreamAsFile");
705
NPP_StreamAsFile(instance, stream, fname);
710
Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
713
PLUGINDEBUGSTR("DestroyStream");
714
err = NPP_DestroyStream(instance, stream, reason);
719
Private_URLNotify(NPP instance, const char* url,
720
NPReason reason, void* notifyData)
722
PLUGINDEBUGSTR("URLNotify");
723
NPP_URLNotify(instance, url, reason, notifyData);
727
Private_Print(NPP instance, NPPrint* platformPrint)
729
PLUGINDEBUGSTR("Print");
730
NPP_Print(instance, platformPrint);
734
Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
736
PLUGINDEBUGSTR("GetValue");
737
return NPP_GetValue(instance, variable, r_value);
741
Private_SetValue(NPP instance, NPNVariable variable, void *r_value)
743
PLUGINDEBUGSTR("SetValue");
744
return NPP_SetValue(instance, variable, r_value);
749
Private_GetJavaClass(void)
751
jref clazz = NPP_GetJavaClass();
753
JRIEnv* env = NPN_GetJavaEnv();
754
return JRI_NewGlobalRef(env, clazz);
760
/***********************************************************************
762
* These functions are located automagically by netscape.
764
***********************************************************************/
767
* NP_GetMIMEDescription
768
* - Netscape needs to know about this symbol
769
* - Netscape uses the return value to identify when an object instance
770
* of this plugin should be created.
772
NPP_GET_MIME_CONST char *
773
NP_GetMIMEDescription(void)
775
return NPP_GetMIMEDescription();
779
* NP_GetValue [optional]
780
* - Netscape needs to know about this symbol.
781
* - Interfaces with plugin to get values for predefined variables
782
* that the navigator needs.
785
NP_GetValue(void* future, NPPVariable variable, void *value)
787
return NPP_GetValue((NPP)future, variable, value);
792
* - Netscape needs to know about this symbol.
793
* - It calls this function after looking up its symbol before it
794
* is about to create the first ever object of this kind.
797
* nsTable - The netscape function table. If developers just use these
798
* wrappers, they don't need to worry about all these function
802
* - This functions needs to fill the plugin function table
803
* pluginFuncs and return it. Netscape Navigator plugin
804
* library will use this function table to call the plugin.
808
NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
810
NPError err = NPERR_NO_ERROR;
812
PLUGINDEBUGSTR("NP_Initialize");
814
/* validate input parameters */
815
if ((nsTable == NULL) || (pluginFuncs == NULL))
816
err = NPERR_INVALID_FUNCTABLE_ERROR;
819
* Check the major version passed in Netscape's function table.
820
* We won't load if the major version is newer than what we expect.
821
* Also check that the function tables passed in are big enough for
822
* all the functions we need (they could be bigger, if Netscape added
823
* new APIs, but that's OK with us -- we'll just ignore them).
826
if (err == NPERR_NO_ERROR) {
827
if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
828
err = NPERR_INCOMPATIBLE_VERSION_ERROR;
829
if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
830
err = NPERR_INVALID_FUNCTABLE_ERROR;
831
if (pluginFuncs->size < sizeof(NPPluginFuncs))
832
err = NPERR_INVALID_FUNCTABLE_ERROR;
835
if (err == NPERR_NO_ERROR)
838
* Copy all the fields of Netscape function table into our
839
* copy so we can call back into Netscape later. Note that
840
* we need to copy the fields one by one, rather than assigning
841
* the whole structure, because the Netscape function table
842
* could actually be bigger than what we expect.
844
int minor = nsTable->version & 0xFF;
846
gNetscapeFuncs.version = nsTable->version;
847
gNetscapeFuncs.size = nsTable->size;
848
gNetscapeFuncs.posturl = nsTable->posturl;
849
gNetscapeFuncs.geturl = nsTable->geturl;
850
gNetscapeFuncs.requestread = nsTable->requestread;
851
gNetscapeFuncs.newstream = nsTable->newstream;
852
gNetscapeFuncs.write = nsTable->write;
853
gNetscapeFuncs.destroystream = nsTable->destroystream;
854
gNetscapeFuncs.status = nsTable->status;
855
gNetscapeFuncs.uagent = nsTable->uagent;
856
gNetscapeFuncs.memalloc = nsTable->memalloc;
857
gNetscapeFuncs.memfree = nsTable->memfree;
858
gNetscapeFuncs.memflush = nsTable->memflush;
859
gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
860
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
861
gNetscapeFuncs.pluginthreadasynccall =
862
nsTable->pluginthreadasynccall;
865
if( minor >= NPVERS_HAS_LIVECONNECT )
867
gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
868
gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
871
gNetscapeFuncs.getvalue = nsTable->getvalue;
872
gNetscapeFuncs.setvalue = nsTable->setvalue;
874
if( minor >= NPVERS_HAS_NOTIFICATION )
876
gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
877
gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
880
if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
882
gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
883
gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
884
gNetscapeFuncs.forceredraw = nsTable->forceredraw;
885
/* npruntime support */
888
gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
889
gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
890
gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
891
gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
892
gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
893
gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
894
gNetscapeFuncs.createobject = nsTable->createobject;
895
gNetscapeFuncs.retainobject = nsTable->retainobject;
896
gNetscapeFuncs.releaseobject = nsTable->releaseobject;
897
gNetscapeFuncs.invoke = nsTable->invoke;
898
gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
899
gNetscapeFuncs.evaluate = nsTable->evaluate;
900
gNetscapeFuncs.getproperty = nsTable->getproperty;
901
gNetscapeFuncs.setproperty = nsTable->setproperty;
902
gNetscapeFuncs.removeproperty = nsTable->removeproperty;
903
gNetscapeFuncs.hasproperty = nsTable->hasproperty;
904
gNetscapeFuncs.hasmethod = nsTable->hasmethod;
905
gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
906
gNetscapeFuncs.setexception = nsTable->setexception;
911
gNetscapeFuncs.invalidaterect = NULL;
912
gNetscapeFuncs.invalidateregion = NULL;
913
gNetscapeFuncs.forceredraw = NULL;
914
gNetscapeFuncs.getstringidentifier = NULL;
915
gNetscapeFuncs.getstringidentifiers = NULL;
916
gNetscapeFuncs.getintidentifier = NULL;
917
gNetscapeFuncs.identifierisstring = NULL;
918
gNetscapeFuncs.utf8fromidentifier = NULL;
919
gNetscapeFuncs.intfromidentifier = NULL;
920
gNetscapeFuncs.createobject = NULL;
921
gNetscapeFuncs.retainobject = NULL;
922
gNetscapeFuncs.releaseobject = NULL;
923
gNetscapeFuncs.invoke = NULL;
924
gNetscapeFuncs.invokeDefault = NULL;
925
gNetscapeFuncs.evaluate = NULL;
926
gNetscapeFuncs.getproperty = NULL;
927
gNetscapeFuncs.setproperty = NULL;
928
gNetscapeFuncs.removeproperty = NULL;
929
gNetscapeFuncs.hasproperty = NULL;
930
gNetscapeFuncs.releasevariantvalue = NULL;
931
gNetscapeFuncs.setexception = NULL;
934
((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
936
gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
937
gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
941
gNetscapeFuncs.pushpopupsenabledstate = NULL;
942
gNetscapeFuncs.poppopupsenabledstate = NULL;
946
* Set up the plugin function table that Netscape will use to
947
* call us. Netscape needs to know about our version and size
948
* and have a UniversalProcPointer for every function we
951
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
952
pluginFuncs->size = sizeof(NPPluginFuncs);
953
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
954
pluginFuncs->newp = NewNPP_NewProc(Private_New);
955
pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
956
pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
957
pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
958
pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
959
pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
960
pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
961
pluginFuncs->write = NewNPP_WriteProc(Private_Write);
962
pluginFuncs->print = NewNPP_PrintProc(Private_Print);
963
pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
964
pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
966
pluginFuncs->newp = (NPP_NewProcPtr)(Private_New);
967
pluginFuncs->destroy = (NPP_DestroyProcPtr)(Private_Destroy);
968
pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(Private_SetWindow);
969
pluginFuncs->newstream = (NPP_NewStreamProcPtr)(Private_NewStream);
970
pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
971
pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
972
pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
973
pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
974
pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
975
pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
976
pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
978
pluginFuncs->event = NULL;
979
if( minor >= NPVERS_HAS_NOTIFICATION )
981
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
982
pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
984
pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
988
if( minor >= NPVERS_HAS_LIVECONNECT )
989
pluginFuncs->javaClass = Private_GetJavaClass();
991
pluginFuncs->javaClass = NULL;
993
pluginFuncs->javaClass = NULL;
996
err = NPP_Initialize();
1003
* NP_Shutdown [optional]
1004
* - Netscape needs to know about this symbol.
1005
* - It calls this function after looking up its symbol after
1006
* the last object of this kind has been destroyed.
1012
PLUGINDEBUGSTR("NP_Shutdown");
1014
return NPERR_NO_ERROR;