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 *----------------------------------------------------------------------
52 #ifdef HAVE_NPFUNCTIONS_H
53 #include <npfunctions.h>
58 #include "../vlcshell.h"
61 * Define PLUGIN_TRACE to have the wrapper functions print
62 * messages to stderr whenever they are called.
67 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
69 #define PLUGINDEBUGSTR(msg)
72 /***********************************************************************
76 ***********************************************************************/
78 static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
80 /***********************************************************************
82 * Wrapper functions : plugin calling Netscape Navigator
84 * These functions let the plugin developer just call the APIs
85 * as documented and defined in npapi.h, without needing to know
86 * about the function table and call macros in npupp.h.
88 ***********************************************************************/
91 NPN_Version(int* plugin_major, int* plugin_minor,
92 int* netscape_major, int* netscape_minor)
94 *plugin_major = NP_VERSION_MAJOR;
95 *plugin_minor = NP_VERSION_MINOR;
97 /* Major version is in high byte */
98 *netscape_major = gNetscapeFuncs.version >> 8;
99 /* Minor version is in low byte */
100 *netscape_minor = gNetscapeFuncs.version & 0xFF;
104 NPN_PluginThreadAsyncCall(NPP plugin,
105 void (*func)(void *),
108 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
109 return (*gNetscapeFuncs.pluginthreadasynccall)(plugin, func, userData);
114 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
116 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
117 return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
118 instance, variable, r_value);
120 return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
125 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
127 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
128 return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
129 instance, variable, value);
131 return (*gNetscapeFuncs.setvalue)(instance, variable, value);
136 NPN_GetURL(NPP instance, const char* url, const char* window)
138 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
139 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
141 return (*gNetscapeFuncs.geturl)(instance, url, window);
146 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
148 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
149 return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
151 return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
156 NPN_PostURL(NPP instance, const char* url, const char* window,
157 uint32_t len, const char* buf, NPBool file)
159 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
160 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
161 url, window, len, buf, file);
163 return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
168 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
169 const char* buf, NPBool file, void* notifyData)
171 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
172 return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
173 instance, url, window, len, buf, file, notifyData);
175 return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);
181 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
183 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
184 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
187 return (*gNetscapeFuncs.requestread)(stream, rangeList);
192 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
193 NPStream** stream_ptr)
195 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
196 return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
197 type, window, stream_ptr);
199 return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
204 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
206 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
207 return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
208 stream, len, buffer);
210 return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
215 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
217 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
218 return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
219 instance, stream, reason);
221 return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
226 NPN_Status(NPP instance, const char* message)
228 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
229 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
231 (*gNetscapeFuncs.status)(instance, message);
236 NPN_UserAgent(NPP instance)
238 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
239 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
241 return (*gNetscapeFuncs.uagent)(instance);
245 void *NPN_MemAlloc(uint32_t size)
247 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
248 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
250 return (*gNetscapeFuncs.memalloc)(size);
254 void NPN_MemFree(void* ptr)
256 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
257 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
259 (*gNetscapeFuncs.memfree)(ptr);
263 uint32_t NPN_MemFlush(uint32_t size)
265 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
266 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
268 return (*gNetscapeFuncs.memflush)(size);
272 void NPN_ReloadPlugins(NPBool reloadPages)
274 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
275 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
277 (*gNetscapeFuncs.reloadplugins)(reloadPages);
282 JRIEnv* NPN_GetJavaEnv()
284 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
285 return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
287 return (*gNetscapeFuncs.getJavaEnv);
291 jref NPN_GetJavaPeer(NPP instance)
293 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
294 return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
297 return (*gNetscapeFuncs.getJavaPeer)(instance);
303 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
305 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
306 CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
309 (*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
314 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
316 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
317 CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
320 (*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
325 NPN_ForceRedraw(NPP instance)
327 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
328 CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
330 (*gNetscapeFuncs.forceredraw)(instance);
334 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
336 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
337 CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
340 (*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
344 void NPN_PopPopupsEnabledState(NPP instance)
346 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
347 CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
350 (*gNetscapeFuncs.poppopupsenabledstate)(instance);
354 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
356 int minor = gNetscapeFuncs.version & 0xFF;
359 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
360 return CallNPN_GetStringIdentifierProc(
361 gNetscapeFuncs.getstringidentifier, name);
363 return (*gNetscapeFuncs.getstringidentifier)(name);
369 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
370 NPIdentifier *identifiers)
372 int minor = gNetscapeFuncs.version & 0xFF;
375 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
376 CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
377 names, nameCount, identifiers);
379 (*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
384 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
386 int minor = gNetscapeFuncs.version & 0xFF;
389 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
390 return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
392 return (*gNetscapeFuncs.getintidentifier)(intid);
398 bool NPN_IdentifierIsString(NPIdentifier identifier)
400 int minor = gNetscapeFuncs.version & 0xFF;
403 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
404 return CallNPN_IdentifierIsStringProc(
405 gNetscapeFuncs.identifierisstring,
408 return (*gNetscapeFuncs.identifierisstring)(identifier);
414 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
416 int minor = gNetscapeFuncs.version & 0xFF;
419 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
420 return CallNPN_UTF8FromIdentifierProc(
421 gNetscapeFuncs.utf8fromidentifier,
424 return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
430 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
432 int minor = gNetscapeFuncs.version & 0xFF;
435 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
436 return CallNPN_IntFromIdentifierProc(
437 gNetscapeFuncs.intfromidentifier,
440 return (*gNetscapeFuncs.intfromidentifier)(identifier);
446 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
448 int minor = gNetscapeFuncs.version & 0xFF;
450 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
451 return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
453 return (*gNetscapeFuncs.createobject)(npp, aClass);
458 NPObject *NPN_RetainObject(NPObject *obj)
460 int minor = gNetscapeFuncs.version & 0xFF;
462 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
463 return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
465 return (*gNetscapeFuncs.retainobject)(obj);
470 void NPN_ReleaseObject(NPObject *obj)
472 int minor = gNetscapeFuncs.version & 0xFF;
474 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
475 CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
477 (*gNetscapeFuncs.releaseobject)(obj);
481 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
482 const NPVariant *args, uint32_t argCount, NPVariant *result)
484 int minor = gNetscapeFuncs.version & 0xFF;
486 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
487 return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
488 args, argCount, result);
490 return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
495 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
496 uint32_t argCount, NPVariant *result)
498 int minor = gNetscapeFuncs.version & 0xFF;
500 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
501 return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
502 args, argCount, result);
504 return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
509 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
512 int minor = gNetscapeFuncs.version & 0xFF;
514 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
515 return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
518 return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
523 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
526 int minor = gNetscapeFuncs.version & 0xFF;
528 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
529 return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
530 propertyName, result);
532 return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
537 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
538 const NPVariant *value)
540 int minor = gNetscapeFuncs.version & 0xFF;
542 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
543 return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
544 propertyName, value);
546 return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
551 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
553 int minor = gNetscapeFuncs.version & 0xFF;
555 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
556 return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
559 return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
564 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
566 int minor = gNetscapeFuncs.version & 0xFF;
568 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
569 return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
572 return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
577 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
579 int minor = gNetscapeFuncs.version & 0xFF;
581 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
582 return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
585 return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
590 void NPN_ReleaseVariantValue(NPVariant *variant)
592 int minor = gNetscapeFuncs.version & 0xFF;
594 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
595 CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
597 (*gNetscapeFuncs.releasevariantvalue)(variant);
601 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
603 int minor = gNetscapeFuncs.version & 0xFF;
605 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
606 CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
608 (*gNetscapeFuncs.setexception)(obj, message);
612 /***********************************************************************
614 * Wrapper functions : Netscape Navigator -> plugin
616 * These functions let the plugin developer just create the APIs
617 * as documented and defined in npapi.h, without needing to
618 * install those functions in the function table or worry about
619 * setting up globals for 68K plugins.
621 ***********************************************************************/
623 /* Function prototypes */
624 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
625 int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
626 NPError Private_Destroy(NPP instance, NPSavedData** save);
627 NPError Private_SetWindow(NPP instance, NPWindow* window);
628 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
629 NPBool seekable, uint16_t* stype);
630 int32_t Private_WriteReady(NPP instance, NPStream* stream);
631 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
632 int32_t len, void* buffer);
633 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
634 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
635 void Private_URLNotify(NPP instance, const char* url,
636 NPReason reason, void* notifyData);
637 void Private_Print(NPP instance, NPPrint* platformPrint);
638 NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
639 NPError Private_SetValue(NPP instance, NPPVariable variable, void *r_value);
641 JRIGlobalRef Private_GetJavaClass(void);
644 /* function implementations */
646 Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
647 int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
650 PLUGINDEBUGSTR("New");
651 ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
656 Private_Destroy(NPP instance, NPSavedData** save)
658 PLUGINDEBUGSTR("Destroy");
659 return NPP_Destroy(instance, save);
663 Private_SetWindow(NPP instance, NPWindow* window)
666 PLUGINDEBUGSTR("SetWindow");
667 err = NPP_SetWindow(instance, window);
672 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
673 NPBool seekable, uint16_t* stype)
676 PLUGINDEBUGSTR("NewStream");
677 err = NPP_NewStream(instance, type, stream, seekable, stype);
682 Private_WriteReady(NPP instance, NPStream* stream)
685 PLUGINDEBUGSTR("WriteReady");
686 result = NPP_WriteReady(instance, stream);
691 Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
695 PLUGINDEBUGSTR("Write");
696 result = NPP_Write(instance, stream, offset, len, buffer);
701 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
703 PLUGINDEBUGSTR("StreamAsFile");
704 NPP_StreamAsFile(instance, stream, fname);
709 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
712 PLUGINDEBUGSTR("DestroyStream");
713 err = NPP_DestroyStream(instance, stream, reason);
718 Private_URLNotify(NPP instance, const char* url,
719 NPReason reason, void* notifyData)
721 PLUGINDEBUGSTR("URLNotify");
722 NPP_URLNotify(instance, url, reason, notifyData);
726 Private_Print(NPP instance, NPPrint* platformPrint)
728 PLUGINDEBUGSTR("Print");
729 NPP_Print(instance, platformPrint);
733 Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
735 PLUGINDEBUGSTR("GetValue");
736 return NPP_GetValue(instance, variable, r_value);
740 Private_SetValue(NPP instance, NPPVariable variable, void *r_value)
742 PLUGINDEBUGSTR("SetValue");
743 return NPP_SetValue(instance, variable, r_value);
748 Private_GetJavaClass(void)
750 jref clazz = NPP_GetJavaClass();
752 JRIEnv* env = NPN_GetJavaEnv();
753 return JRI_NewGlobalRef(env, clazz);
759 /***********************************************************************
761 * These functions are located automagically by netscape.
763 ***********************************************************************/
766 * NP_GetMIMEDescription
767 * - Netscape needs to know about this symbol
768 * - Netscape uses the return value to identify when an object instance
769 * of this plugin should be created.
772 NP_GetMIMEDescription(void)
774 return NPP_GetMIMEDescription();
778 * NP_GetValue [optional]
779 * - Netscape needs to know about this symbol.
780 * - Interfaces with plugin to get values for predefined variables
781 * that the navigator needs.
784 NP_GetValue(void* future, NPPVariable variable, void *value)
786 return NPP_GetValue(future, variable, value);
791 * - Netscape needs to know about this symbol.
792 * - It calls this function after looking up its symbol before it
793 * is about to create the first ever object of this kind.
796 * nsTable - The netscape function table. If developers just use these
797 * wrappers, they don't need to worry about all these function
801 * - This functions needs to fill the plugin function table
802 * pluginFuncs and return it. Netscape Navigator plugin
803 * library will use this function table to call the plugin.
807 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
809 NPError err = NPERR_NO_ERROR;
811 PLUGINDEBUGSTR("NP_Initialize");
813 /* validate input parameters */
814 if ((nsTable == NULL) || (pluginFuncs == NULL))
815 err = NPERR_INVALID_FUNCTABLE_ERROR;
818 * Check the major version passed in Netscape's function table.
819 * We won't load if the major version is newer than what we expect.
820 * Also check that the function tables passed in are big enough for
821 * all the functions we need (they could be bigger, if Netscape added
822 * new APIs, but that's OK with us -- we'll just ignore them).
825 if (err == NPERR_NO_ERROR) {
826 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
827 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
828 if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
829 err = NPERR_INVALID_FUNCTABLE_ERROR;
830 if (pluginFuncs->size < sizeof(NPPluginFuncs))
831 err = NPERR_INVALID_FUNCTABLE_ERROR;
834 if (err == NPERR_NO_ERROR)
837 * Copy all the fields of Netscape function table into our
838 * copy so we can call back into Netscape later. Note that
839 * we need to copy the fields one by one, rather than assigning
840 * the whole structure, because the Netscape function table
841 * could actually be bigger than what we expect.
843 int minor = nsTable->version & 0xFF;
845 gNetscapeFuncs.version = nsTable->version;
846 gNetscapeFuncs.size = nsTable->size;
847 gNetscapeFuncs.posturl = nsTable->posturl;
848 gNetscapeFuncs.geturl = nsTable->geturl;
849 gNetscapeFuncs.requestread = nsTable->requestread;
850 gNetscapeFuncs.newstream = nsTable->newstream;
851 gNetscapeFuncs.write = nsTable->write;
852 gNetscapeFuncs.destroystream = nsTable->destroystream;
853 gNetscapeFuncs.status = nsTable->status;
854 gNetscapeFuncs.uagent = nsTable->uagent;
855 gNetscapeFuncs.memalloc = nsTable->memalloc;
856 gNetscapeFuncs.memfree = nsTable->memfree;
857 gNetscapeFuncs.memflush = nsTable->memflush;
858 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
859 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
860 gNetscapeFuncs.pluginthreadasynccall =
861 nsTable->pluginthreadasynccall;
864 if( minor >= NPVERS_HAS_LIVECONNECT )
866 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
867 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
870 gNetscapeFuncs.getvalue = nsTable->getvalue;
871 gNetscapeFuncs.setvalue = nsTable->setvalue;
873 if( minor >= NPVERS_HAS_NOTIFICATION )
875 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
876 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
879 if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
881 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
882 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
883 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
884 /* npruntime support */
887 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
888 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
889 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
890 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
891 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
892 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
893 gNetscapeFuncs.createobject = nsTable->createobject;
894 gNetscapeFuncs.retainobject = nsTable->retainobject;
895 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
896 gNetscapeFuncs.invoke = nsTable->invoke;
897 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
898 gNetscapeFuncs.evaluate = nsTable->evaluate;
899 gNetscapeFuncs.getproperty = nsTable->getproperty;
900 gNetscapeFuncs.setproperty = nsTable->setproperty;
901 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
902 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
903 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
904 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
905 gNetscapeFuncs.setexception = nsTable->setexception;
910 gNetscapeFuncs.invalidaterect = NULL;
911 gNetscapeFuncs.invalidateregion = NULL;
912 gNetscapeFuncs.forceredraw = NULL;
913 gNetscapeFuncs.getstringidentifier = NULL;
914 gNetscapeFuncs.getstringidentifiers = NULL;
915 gNetscapeFuncs.getintidentifier = NULL;
916 gNetscapeFuncs.identifierisstring = NULL;
917 gNetscapeFuncs.utf8fromidentifier = NULL;
918 gNetscapeFuncs.intfromidentifier = NULL;
919 gNetscapeFuncs.createobject = NULL;
920 gNetscapeFuncs.retainobject = NULL;
921 gNetscapeFuncs.releaseobject = NULL;
922 gNetscapeFuncs.invoke = NULL;
923 gNetscapeFuncs.invokeDefault = NULL;
924 gNetscapeFuncs.evaluate = NULL;
925 gNetscapeFuncs.getproperty = NULL;
926 gNetscapeFuncs.setproperty = NULL;
927 gNetscapeFuncs.removeproperty = NULL;
928 gNetscapeFuncs.hasproperty = NULL;
929 gNetscapeFuncs.releasevariantvalue = NULL;
930 gNetscapeFuncs.setexception = NULL;
933 ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
935 gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
936 gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
940 gNetscapeFuncs.pushpopupsenabledstate = NULL;
941 gNetscapeFuncs.poppopupsenabledstate = NULL;
945 * Set up the plugin function table that Netscape will use to
946 * call us. Netscape needs to know about our version and size
947 * and have a UniversalProcPointer for every function we
950 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
951 pluginFuncs->size = sizeof(NPPluginFuncs);
952 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
953 pluginFuncs->newp = NewNPP_NewProc(Private_New);
954 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
955 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
956 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
957 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
958 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
959 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
960 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
961 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
962 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
963 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
965 pluginFuncs->newp = (NPP_NewProcPtr)(Private_New);
966 pluginFuncs->destroy = (NPP_DestroyProcPtr)(Private_Destroy);
967 pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(Private_SetWindow);
968 pluginFuncs->newstream = (NPP_NewStreamProcPtr)(Private_NewStream);
969 pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
970 pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
971 pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
972 pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
973 pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
974 pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
975 pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
977 pluginFuncs->event = NULL;
978 if( minor >= NPVERS_HAS_NOTIFICATION )
980 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
981 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
983 pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
987 if( minor >= NPVERS_HAS_LIVECONNECT )
988 pluginFuncs->javaClass = Private_GetJavaClass();
990 pluginFuncs->javaClass = NULL;
992 pluginFuncs->javaClass = NULL;
995 err = NPP_Initialize();
1002 * NP_Shutdown [optional]
1003 * - Netscape needs to know about this symbol.
1004 * - It calls this function after looking up its symbol after
1005 * the last object of this kind has been destroyed.
1011 PLUGINDEBUGSTR("NP_Shutdown");
1013 return NPERR_NO_ERROR;