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_GetValue(NPP instance, NPNVariable variable, void *r_value)
106 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
107 return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
108 instance, variable, r_value);
110 return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
115 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
117 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
118 return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
119 instance, variable, value);
121 return (*gNetscapeFuncs.setvalue)(instance, variable, value);
126 NPN_GetURL(NPP instance, const char* url, const char* window)
128 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
129 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
131 return (*gNetscapeFuncs.geturl)(instance, url, window);
136 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
138 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
139 return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
141 return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
146 NPN_PostURL(NPP instance, const char* url, const char* window,
147 uint32_t len, const char* buf, NPBool file)
149 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
150 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
151 url, window, len, buf, file);
153 return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
158 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
159 const char* buf, NPBool file, void* notifyData)
161 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
162 return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
163 instance, url, window, len, buf, file, notifyData);
165 return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);
171 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
173 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
174 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
177 return (*gNetscapeFuncs.requestread)(stream, rangeList);
182 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
183 NPStream** stream_ptr)
185 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
186 return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
187 type, window, stream_ptr);
189 return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
194 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
196 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
197 return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
198 stream, len, buffer);
200 return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
205 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
207 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
208 return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
209 instance, stream, reason);
211 return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
216 NPN_Status(NPP instance, const char* message)
218 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
219 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
221 (*gNetscapeFuncs.status)(instance, message);
226 NPN_UserAgent(NPP instance)
228 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
229 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
231 return (*gNetscapeFuncs.uagent)(instance);
235 void *NPN_MemAlloc(uint32_t size)
237 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
238 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
240 return (*gNetscapeFuncs.memalloc)(size);
244 void NPN_MemFree(void* ptr)
246 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
247 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
249 (*gNetscapeFuncs.memfree)(ptr);
253 uint32_t NPN_MemFlush(uint32_t size)
255 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
256 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
258 return (*gNetscapeFuncs.memflush)(size);
262 void NPN_ReloadPlugins(NPBool reloadPages)
264 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
265 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
267 (*gNetscapeFuncs.reloadplugins)(reloadPages);
272 JRIEnv* NPN_GetJavaEnv()
274 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
275 return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
277 return (*gNetscapeFuncs.getJavaEnv);
281 jref NPN_GetJavaPeer(NPP instance)
283 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
284 return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
287 return (*gNetscapeFuncs.getJavaPeer)(instance);
293 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
295 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
296 CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
299 (*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
304 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
306 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
307 CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
310 (*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
315 NPN_ForceRedraw(NPP instance)
317 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
318 CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
320 (*gNetscapeFuncs.forceredraw)(instance);
324 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
326 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
327 CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
330 (*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
334 void NPN_PopPopupsEnabledState(NPP instance)
336 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
337 CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
340 (*gNetscapeFuncs.poppopupsenabledstate)(instance);
344 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
346 int minor = gNetscapeFuncs.version & 0xFF;
349 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
350 return CallNPN_GetStringIdentifierProc(
351 gNetscapeFuncs.getstringidentifier, name);
353 return (*gNetscapeFuncs.getstringidentifier)(name);
359 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
360 NPIdentifier *identifiers)
362 int minor = gNetscapeFuncs.version & 0xFF;
365 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
366 CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
367 names, nameCount, identifiers);
369 (*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
374 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
376 int minor = gNetscapeFuncs.version & 0xFF;
379 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
380 return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
382 return (*gNetscapeFuncs.getintidentifier)(intid);
388 bool NPN_IdentifierIsString(NPIdentifier identifier)
390 int minor = gNetscapeFuncs.version & 0xFF;
393 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
394 return CallNPN_IdentifierIsStringProc(
395 gNetscapeFuncs.identifierisstring,
398 return (*gNetscapeFuncs.identifierisstring)(identifier);
404 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
406 int minor = gNetscapeFuncs.version & 0xFF;
409 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
410 return CallNPN_UTF8FromIdentifierProc(
411 gNetscapeFuncs.utf8fromidentifier,
414 return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
420 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
422 int minor = gNetscapeFuncs.version & 0xFF;
425 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
426 return CallNPN_IntFromIdentifierProc(
427 gNetscapeFuncs.intfromidentifier,
430 return (*gNetscapeFuncs.intfromidentifier)(identifier);
436 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
438 int minor = gNetscapeFuncs.version & 0xFF;
440 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
441 return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
443 return (*gNetscapeFuncs.createobject)(npp, aClass);
448 NPObject *NPN_RetainObject(NPObject *obj)
450 int minor = gNetscapeFuncs.version & 0xFF;
452 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
453 return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
455 return (*gNetscapeFuncs.retainobject)(obj);
460 void NPN_ReleaseObject(NPObject *obj)
462 int minor = gNetscapeFuncs.version & 0xFF;
464 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
465 CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
467 (*gNetscapeFuncs.releaseobject)(obj);
471 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
472 const NPVariant *args, uint32_t argCount, NPVariant *result)
474 int minor = gNetscapeFuncs.version & 0xFF;
476 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
477 return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
478 args, argCount, result);
480 return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
485 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
486 uint32_t argCount, NPVariant *result)
488 int minor = gNetscapeFuncs.version & 0xFF;
490 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
491 return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
492 args, argCount, result);
494 return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
499 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
502 int minor = gNetscapeFuncs.version & 0xFF;
504 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
505 return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
508 return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
513 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
516 int minor = gNetscapeFuncs.version & 0xFF;
518 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
519 return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
520 propertyName, result);
522 return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
527 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
528 const NPVariant *value)
530 int minor = gNetscapeFuncs.version & 0xFF;
532 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
533 return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
534 propertyName, value);
536 return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
541 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
543 int minor = gNetscapeFuncs.version & 0xFF;
545 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
546 return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
549 return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
554 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
556 int minor = gNetscapeFuncs.version & 0xFF;
558 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
559 return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
562 return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
567 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
569 int minor = gNetscapeFuncs.version & 0xFF;
571 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
572 return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
575 return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
580 void NPN_ReleaseVariantValue(NPVariant *variant)
582 int minor = gNetscapeFuncs.version & 0xFF;
584 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
585 CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
587 (*gNetscapeFuncs.releasevariantvalue)(variant);
591 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
593 int minor = gNetscapeFuncs.version & 0xFF;
595 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
596 CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
598 (*gNetscapeFuncs.setexception)(obj, message);
602 /***********************************************************************
604 * Wrapper functions : Netscape Navigator -> plugin
606 * These functions let the plugin developer just create the APIs
607 * as documented and defined in npapi.h, without needing to
608 * install those functions in the function table or worry about
609 * setting up globals for 68K plugins.
611 ***********************************************************************/
613 /* Function prototypes */
614 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
615 int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
616 NPError Private_Destroy(NPP instance, NPSavedData** save);
617 NPError Private_SetWindow(NPP instance, NPWindow* window);
618 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
619 NPBool seekable, uint16_t* stype);
620 int32_t Private_WriteReady(NPP instance, NPStream* stream);
621 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
622 int32_t len, void* buffer);
623 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
624 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
625 void Private_URLNotify(NPP instance, const char* url,
626 NPReason reason, void* notifyData);
627 void Private_Print(NPP instance, NPPrint* platformPrint);
628 NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
629 NPError Private_SetValue(NPP instance, NPPVariable variable, void *r_value);
631 JRIGlobalRef Private_GetJavaClass(void);
634 /* function implementations */
636 Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
637 int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
640 PLUGINDEBUGSTR("New");
641 ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
646 Private_Destroy(NPP instance, NPSavedData** save)
648 PLUGINDEBUGSTR("Destroy");
649 return NPP_Destroy(instance, save);
653 Private_SetWindow(NPP instance, NPWindow* window)
656 PLUGINDEBUGSTR("SetWindow");
657 err = NPP_SetWindow(instance, window);
662 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
663 NPBool seekable, uint16_t* stype)
666 PLUGINDEBUGSTR("NewStream");
667 err = NPP_NewStream(instance, type, stream, seekable, stype);
672 Private_WriteReady(NPP instance, NPStream* stream)
675 PLUGINDEBUGSTR("WriteReady");
676 result = NPP_WriteReady(instance, stream);
681 Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
685 PLUGINDEBUGSTR("Write");
686 result = NPP_Write(instance, stream, offset, len, buffer);
691 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
693 PLUGINDEBUGSTR("StreamAsFile");
694 NPP_StreamAsFile(instance, stream, fname);
699 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
702 PLUGINDEBUGSTR("DestroyStream");
703 err = NPP_DestroyStream(instance, stream, reason);
708 Private_URLNotify(NPP instance, const char* url,
709 NPReason reason, void* notifyData)
711 PLUGINDEBUGSTR("URLNotify");
712 NPP_URLNotify(instance, url, reason, notifyData);
716 Private_Print(NPP instance, NPPrint* platformPrint)
718 PLUGINDEBUGSTR("Print");
719 NPP_Print(instance, platformPrint);
723 Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
725 PLUGINDEBUGSTR("GetValue");
726 return NPP_GetValue(instance, variable, r_value);
730 Private_SetValue(NPP instance, NPPVariable variable, void *r_value)
732 PLUGINDEBUGSTR("SetValue");
733 return NPP_SetValue(instance, variable, r_value);
738 Private_GetJavaClass(void)
740 jref clazz = NPP_GetJavaClass();
742 JRIEnv* env = NPN_GetJavaEnv();
743 return JRI_NewGlobalRef(env, clazz);
749 /***********************************************************************
751 * These functions are located automagically by netscape.
753 ***********************************************************************/
756 * NP_GetMIMEDescription
757 * - Netscape needs to know about this symbol
758 * - Netscape uses the return value to identify when an object instance
759 * of this plugin should be created.
762 NP_GetMIMEDescription(void)
764 return NPP_GetMIMEDescription();
768 * NP_GetValue [optional]
769 * - Netscape needs to know about this symbol.
770 * - Interfaces with plugin to get values for predefined variables
771 * that the navigator needs.
774 NP_GetValue(void* future, NPPVariable variable, void *value)
776 return NPP_GetValue(future, variable, value);
781 * - Netscape needs to know about this symbol.
782 * - It calls this function after looking up its symbol before it
783 * is about to create the first ever object of this kind.
786 * nsTable - The netscape function table. If developers just use these
787 * wrappers, they don't need to worry about all these function
791 * - This functions needs to fill the plugin function table
792 * pluginFuncs and return it. Netscape Navigator plugin
793 * library will use this function table to call the plugin.
797 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
799 NPError err = NPERR_NO_ERROR;
801 PLUGINDEBUGSTR("NP_Initialize");
803 /* validate input parameters */
804 if ((nsTable == NULL) || (pluginFuncs == NULL))
805 err = NPERR_INVALID_FUNCTABLE_ERROR;
808 * Check the major version passed in Netscape's function table.
809 * We won't load if the major version is newer than what we expect.
810 * Also check that the function tables passed in are big enough for
811 * all the functions we need (they could be bigger, if Netscape added
812 * new APIs, but that's OK with us -- we'll just ignore them).
815 if (err == NPERR_NO_ERROR) {
816 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
817 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
818 if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
819 err = NPERR_INVALID_FUNCTABLE_ERROR;
820 if (pluginFuncs->size < sizeof(NPPluginFuncs))
821 err = NPERR_INVALID_FUNCTABLE_ERROR;
824 if (err == NPERR_NO_ERROR)
827 * Copy all the fields of Netscape function table into our
828 * copy so we can call back into Netscape later. Note that
829 * we need to copy the fields one by one, rather than assigning
830 * the whole structure, because the Netscape function table
831 * could actually be bigger than what we expect.
833 int minor = nsTable->version & 0xFF;
835 gNetscapeFuncs.version = nsTable->version;
836 gNetscapeFuncs.size = nsTable->size;
837 gNetscapeFuncs.posturl = nsTable->posturl;
838 gNetscapeFuncs.geturl = nsTable->geturl;
839 gNetscapeFuncs.requestread = nsTable->requestread;
840 gNetscapeFuncs.newstream = nsTable->newstream;
841 gNetscapeFuncs.write = nsTable->write;
842 gNetscapeFuncs.destroystream = nsTable->destroystream;
843 gNetscapeFuncs.status = nsTable->status;
844 gNetscapeFuncs.uagent = nsTable->uagent;
845 gNetscapeFuncs.memalloc = nsTable->memalloc;
846 gNetscapeFuncs.memfree = nsTable->memfree;
847 gNetscapeFuncs.memflush = nsTable->memflush;
848 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
850 if( minor >= NPVERS_HAS_LIVECONNECT )
852 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
853 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
856 gNetscapeFuncs.getvalue = nsTable->getvalue;
857 gNetscapeFuncs.setvalue = nsTable->setvalue;
859 if( minor >= NPVERS_HAS_NOTIFICATION )
861 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
862 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
865 if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
867 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
868 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
869 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
870 /* npruntime support */
873 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
874 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
875 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
876 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
877 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
878 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
879 gNetscapeFuncs.createobject = nsTable->createobject;
880 gNetscapeFuncs.retainobject = nsTable->retainobject;
881 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
882 gNetscapeFuncs.invoke = nsTable->invoke;
883 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
884 gNetscapeFuncs.evaluate = nsTable->evaluate;
885 gNetscapeFuncs.getproperty = nsTable->getproperty;
886 gNetscapeFuncs.setproperty = nsTable->setproperty;
887 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
888 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
889 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
890 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
891 gNetscapeFuncs.setexception = nsTable->setexception;
896 gNetscapeFuncs.invalidaterect = NULL;
897 gNetscapeFuncs.invalidateregion = NULL;
898 gNetscapeFuncs.forceredraw = NULL;
899 gNetscapeFuncs.getstringidentifier = NULL;
900 gNetscapeFuncs.getstringidentifiers = NULL;
901 gNetscapeFuncs.getintidentifier = NULL;
902 gNetscapeFuncs.identifierisstring = NULL;
903 gNetscapeFuncs.utf8fromidentifier = NULL;
904 gNetscapeFuncs.intfromidentifier = NULL;
905 gNetscapeFuncs.createobject = NULL;
906 gNetscapeFuncs.retainobject = NULL;
907 gNetscapeFuncs.releaseobject = NULL;
908 gNetscapeFuncs.invoke = NULL;
909 gNetscapeFuncs.invokeDefault = NULL;
910 gNetscapeFuncs.evaluate = NULL;
911 gNetscapeFuncs.getproperty = NULL;
912 gNetscapeFuncs.setproperty = NULL;
913 gNetscapeFuncs.removeproperty = NULL;
914 gNetscapeFuncs.hasproperty = NULL;
915 gNetscapeFuncs.releasevariantvalue = NULL;
916 gNetscapeFuncs.setexception = NULL;
919 ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
921 gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
922 gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
926 gNetscapeFuncs.pushpopupsenabledstate = NULL;
927 gNetscapeFuncs.poppopupsenabledstate = NULL;
931 * Set up the plugin function table that Netscape will use to
932 * call us. Netscape needs to know about our version and size
933 * and have a UniversalProcPointer for every function we
936 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
937 pluginFuncs->size = sizeof(NPPluginFuncs);
938 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
939 pluginFuncs->newp = NewNPP_NewProc(Private_New);
940 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
941 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
942 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
943 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
944 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
945 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
946 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
947 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
948 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
949 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
951 pluginFuncs->newp = (NPP_NewProcPtr)(Private_New);
952 pluginFuncs->destroy = (NPP_DestroyProcPtr)(Private_Destroy);
953 pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(Private_SetWindow);
954 pluginFuncs->newstream = (NPP_NewStreamProcPtr)(Private_NewStream);
955 pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
956 pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
957 pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
958 pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
959 pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
960 pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
961 pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
963 pluginFuncs->event = NULL;
964 if( minor >= NPVERS_HAS_NOTIFICATION )
966 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
967 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
969 pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
973 if( minor >= NPVERS_HAS_LIVECONNECT )
974 pluginFuncs->javaClass = Private_GetJavaClass();
976 pluginFuncs->javaClass = NULL;
978 pluginFuncs->javaClass = NULL;
981 err = NPP_Initialize();
988 * NP_Shutdown [optional]
989 * - Netscape needs to know about this symbol.
990 * - It calls this function after looking up its symbol after
991 * the last object of this kind has been destroyed.
997 PLUGINDEBUGSTR("NP_Shutdown");
999 return NPERR_NO_ERROR;