Remove obsolete feisty script
[vlc/asuraparaju-public.git] / projects / mozilla / support / npunix.c
blob9eb851cf905fef64e91e3910676d48e6c0185a97
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.
27 * Contributor(s):
28 * Stephen Mak <smak@sun.com>
33 * npunix.c
35 * Netscape Client Plugin API
36 * - Wrapper function to interface with the Netscape Navigator
38 * dp Suresh <dp@netscape.com>
40 *----------------------------------------------------------------------
41 * PLUGIN DEVELOPERS:
42 * YOU WILL NOT NEED TO EDIT THIS FILE.
43 *----------------------------------------------------------------------
46 #include "config.h"
48 #define XP_UNIX 1
50 #include <npapi.h>
51 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
52 #include "npupp.h"
53 #else
54 #include "npfunctions.h"
55 #endif
57 #include "../vlcshell.h"
60 * Define PLUGIN_TRACE to have the wrapper functions print
61 * messages to stderr whenever they are called.
64 #ifdef PLUGIN_TRACE
65 #include <stdio.h>
66 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
67 #else
68 #define PLUGINDEBUGSTR(msg)
69 #endif
71 /***********************************************************************
73 * Globals
75 ***********************************************************************/
77 static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
79 /***********************************************************************
81 * Wrapper functions : plugin calling Netscape Navigator
83 * These functions let the plugin developer just call the APIs
84 * as documented and defined in npapi.h, without needing to know
85 * about the function table and call macros in npupp.h.
87 ***********************************************************************/
89 void
90 NPN_Version(int* plugin_major, int* plugin_minor,
91 int* netscape_major, int* netscape_minor)
93 *plugin_major = NP_VERSION_MAJOR;
94 *plugin_minor = NP_VERSION_MINOR;
96 /* Major version is in high byte */
97 *netscape_major = gNetscapeFuncs.version >> 8;
98 /* Minor version is in low byte */
99 *netscape_minor = gNetscapeFuncs.version & 0xFF;
102 void
103 NPN_PluginThreadAsyncCall(NPP plugin,
104 void (*func)(void *),
105 void *userData)
107 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
108 return (*gNetscapeFuncs.pluginthreadasynccall)(plugin, func, userData);
109 #endif
112 NPError
113 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
115 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
116 return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
117 instance, variable, r_value);
118 #else
119 return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
120 #endif
123 NPError
124 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
126 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
127 return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
128 instance, variable, value);
129 #else
130 return (*gNetscapeFuncs.setvalue)(instance, variable, value);
131 #endif
134 NPError
135 NPN_GetURL(NPP instance, const char* url, const char* window)
137 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
138 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
139 #else
140 return (*gNetscapeFuncs.geturl)(instance, url, window);
141 #endif
144 NPError
145 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
147 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
148 return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
149 #else
150 return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
151 #endif
154 NPError
155 NPN_PostURL(NPP instance, const char* url, const char* window,
156 uint32_t len, const char* buf, NPBool file)
158 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
159 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
160 url, window, len, buf, file);
161 #else
162 return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
163 #endif
166 NPError
167 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
168 const char* buf, NPBool file, void* notifyData)
170 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
171 return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
172 instance, url, window, len, buf, file, notifyData);
173 #else
174 return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);
176 #endif
179 NPError
180 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
182 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
183 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
184 stream, rangeList);
185 #else
186 return (*gNetscapeFuncs.requestread)(stream, rangeList);
187 #endif
190 NPError
191 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
192 NPStream** stream_ptr)
194 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
195 return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
196 type, window, stream_ptr);
197 #else
198 return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
199 #endif
202 int32_t
203 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
205 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
206 return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
207 stream, len, buffer);
208 #else
209 return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
210 #endif
213 NPError
214 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
216 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
217 return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
218 instance, stream, reason);
219 #else
220 return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
221 #endif
224 void
225 NPN_Status(NPP instance, const char* message)
227 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
228 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
229 #else
230 (*gNetscapeFuncs.status)(instance, message);
231 #endif
234 const char*
235 NPN_UserAgent(NPP instance)
237 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
238 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
239 #else
240 return (*gNetscapeFuncs.uagent)(instance);
241 #endif
244 void *NPN_MemAlloc(uint32_t size)
246 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
247 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
248 #else
249 return (*gNetscapeFuncs.memalloc)(size);
250 #endif
253 void NPN_MemFree(void* ptr)
255 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
256 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
257 #else
258 (*gNetscapeFuncs.memfree)(ptr);
259 #endif
262 uint32_t NPN_MemFlush(uint32_t size)
264 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
265 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
266 #else
267 return (*gNetscapeFuncs.memflush)(size);
268 #endif
271 void NPN_ReloadPlugins(NPBool reloadPages)
273 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
274 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
275 #else
276 (*gNetscapeFuncs.reloadplugins)(reloadPages);
277 #endif
280 #ifdef OJI
281 JRIEnv* NPN_GetJavaEnv()
283 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
284 return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
285 #else
286 return (*gNetscapeFuncs.getJavaEnv);
287 #endif
290 jref NPN_GetJavaPeer(NPP instance)
292 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
293 return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
294 instance);
295 #else
296 return (*gNetscapeFuncs.getJavaPeer)(instance);
297 #endif
299 #endif
301 void
302 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
304 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
305 CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
306 invalidRect);
307 #else
308 (*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
309 #endif
312 void
313 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
315 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
316 CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
317 invalidRegion);
318 #else
319 (*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
320 #endif
323 void
324 NPN_ForceRedraw(NPP instance)
326 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
327 CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
328 #else
329 (*gNetscapeFuncs.forceredraw)(instance);
330 #endif
333 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
335 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
336 CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
337 instance, enabled);
338 #else
339 (*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
340 #endif
343 void NPN_PopPopupsEnabledState(NPP instance)
345 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
346 CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
347 instance);
348 #else
349 (*gNetscapeFuncs.poppopupsenabledstate)(instance);
350 #endif
353 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
355 int minor = gNetscapeFuncs.version & 0xFF;
356 if( minor >= 14 )
358 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
359 return CallNPN_GetStringIdentifierProc(
360 gNetscapeFuncs.getstringidentifier, name);
361 #else
362 return (*gNetscapeFuncs.getstringidentifier)(name);
363 #endif
365 return NULL;
368 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
369 NPIdentifier *identifiers)
371 int minor = gNetscapeFuncs.version & 0xFF;
372 if( minor >= 14 )
374 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
375 CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
376 names, nameCount, identifiers);
377 #else
378 (*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
379 #endif
383 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
385 int minor = gNetscapeFuncs.version & 0xFF;
386 if( minor >= 14 )
388 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
389 return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
390 #else
391 return (*gNetscapeFuncs.getintidentifier)(intid);
392 #endif
394 return NULL;
397 bool NPN_IdentifierIsString(NPIdentifier identifier)
399 int minor = gNetscapeFuncs.version & 0xFF;
400 if( minor >= 14 )
402 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
403 return CallNPN_IdentifierIsStringProc(
404 gNetscapeFuncs.identifierisstring,
405 identifier);
406 #else
407 return (*gNetscapeFuncs.identifierisstring)(identifier);
408 #endif
410 return false;
413 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
415 int minor = gNetscapeFuncs.version & 0xFF;
416 if( minor >= 14 )
418 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
419 return CallNPN_UTF8FromIdentifierProc(
420 gNetscapeFuncs.utf8fromidentifier,
421 identifier);
422 #else
423 return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
424 #endif
426 return NULL;
429 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
431 int minor = gNetscapeFuncs.version & 0xFF;
432 if( minor >= 14 )
434 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
435 return CallNPN_IntFromIdentifierProc(
436 gNetscapeFuncs.intfromidentifier,
437 identifier);
438 #else
439 return (*gNetscapeFuncs.intfromidentifier)(identifier);
440 #endif
442 return 0;
445 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
447 int minor = gNetscapeFuncs.version & 0xFF;
448 if( minor >= 14 )
449 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
450 return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
451 #else
452 return (*gNetscapeFuncs.createobject)(npp, aClass);
453 #endif
454 return NULL;
457 NPObject *NPN_RetainObject(NPObject *obj)
459 int minor = gNetscapeFuncs.version & 0xFF;
460 if( minor >= 14 )
461 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
462 return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
463 #else
464 return (*gNetscapeFuncs.retainobject)(obj);
465 #endif
466 return NULL;
469 void NPN_ReleaseObject(NPObject *obj)
471 int minor = gNetscapeFuncs.version & 0xFF;
472 if( minor >= 14 )
473 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
474 CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
475 #else
476 (*gNetscapeFuncs.releaseobject)(obj);
477 #endif
480 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
481 const NPVariant *args, uint32_t argCount, NPVariant *result)
483 int minor = gNetscapeFuncs.version & 0xFF;
484 if( minor >= 14 )
485 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
486 return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
487 args, argCount, result);
488 #else
489 return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
490 #endif
491 return false;
494 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
495 uint32_t argCount, NPVariant *result)
497 int minor = gNetscapeFuncs.version & 0xFF;
498 if( minor >= 14 )
499 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
500 return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
501 args, argCount, result);
502 #else
503 return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
504 #endif
505 return false;
508 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
509 NPVariant *result)
511 int minor = gNetscapeFuncs.version & 0xFF;
512 if( minor >= 14 )
513 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
514 return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
515 script, result);
516 #else
517 return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
518 #endif
519 return false;
522 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
523 NPVariant *result)
525 int minor = gNetscapeFuncs.version & 0xFF;
526 if( minor >= 14 )
527 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
528 return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
529 propertyName, result);
530 #else
531 return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
532 #endif
533 return false;
536 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
537 const NPVariant *value)
539 int minor = gNetscapeFuncs.version & 0xFF;
540 if( minor >= 14 )
541 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
542 return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
543 propertyName, value);
544 #else
545 return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
546 #endif
547 return false;
550 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
552 int minor = gNetscapeFuncs.version & 0xFF;
553 if( minor >= 14 )
554 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
555 return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
556 propertyName);
557 #else
558 return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
559 #endif
560 return false;
563 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
565 int minor = gNetscapeFuncs.version & 0xFF;
566 if( minor >= 14 )
567 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
568 return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
569 propertyName);
570 #else
571 return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
572 #endif
573 return false;
576 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
578 int minor = gNetscapeFuncs.version & 0xFF;
579 if( minor >= 14 )
580 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
581 return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
582 obj, methodName);
583 #else
584 return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
585 #endif
586 return false;
589 void NPN_ReleaseVariantValue(NPVariant *variant)
591 int minor = gNetscapeFuncs.version & 0xFF;
592 if( minor >= 14 )
593 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
594 CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
595 #else
596 (*gNetscapeFuncs.releasevariantvalue)(variant);
597 #endif
600 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
602 int minor = gNetscapeFuncs.version & 0xFF;
603 if( minor >= 14 )
604 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
605 CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
606 #else
607 (*gNetscapeFuncs.setexception)(obj, message);
608 #endif
611 /***********************************************************************
613 * Wrapper functions : Netscape Navigator -> plugin
615 * These functions let the plugin developer just create the APIs
616 * as documented and defined in npapi.h, without needing to
617 * install those functions in the function table or worry about
618 * setting up globals for 68K plugins.
620 ***********************************************************************/
622 /* Function prototypes */
623 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
624 int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
625 NPError Private_Destroy(NPP instance, NPSavedData** save);
626 NPError Private_SetWindow(NPP instance, NPWindow* window);
627 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
628 NPBool seekable, uint16_t* stype);
629 int32_t Private_WriteReady(NPP instance, NPStream* stream);
630 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
631 int32_t len, void* buffer);
632 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
633 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
634 void Private_URLNotify(NPP instance, const char* url,
635 NPReason reason, void* notifyData);
636 void Private_Print(NPP instance, NPPrint* platformPrint);
637 NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
638 NPError Private_SetValue(NPP instance, NPPVariable variable, void *r_value);
639 #ifdef OJI
640 JRIGlobalRef Private_GetJavaClass(void);
641 #endif
643 /* function implementations */
644 NPError
645 Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
646 int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
648 NPError ret;
649 PLUGINDEBUGSTR("New");
650 ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
651 return ret;
654 NPError
655 Private_Destroy(NPP instance, NPSavedData** save)
657 PLUGINDEBUGSTR("Destroy");
658 return NPP_Destroy(instance, save);
661 NPError
662 Private_SetWindow(NPP instance, NPWindow* window)
664 NPError err;
665 PLUGINDEBUGSTR("SetWindow");
666 err = NPP_SetWindow(instance, window);
667 return err;
670 NPError
671 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
672 NPBool seekable, uint16_t* stype)
674 NPError err;
675 PLUGINDEBUGSTR("NewStream");
676 err = NPP_NewStream(instance, type, stream, seekable, stype);
677 return err;
680 int32_t
681 Private_WriteReady(NPP instance, NPStream* stream)
683 unsigned int result;
684 PLUGINDEBUGSTR("WriteReady");
685 result = NPP_WriteReady(instance, stream);
686 return result;
689 int32_t
690 Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
691 void* buffer)
693 unsigned int result;
694 PLUGINDEBUGSTR("Write");
695 result = NPP_Write(instance, stream, offset, len, buffer);
696 return result;
699 void
700 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
702 PLUGINDEBUGSTR("StreamAsFile");
703 NPP_StreamAsFile(instance, stream, fname);
707 NPError
708 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
710 NPError err;
711 PLUGINDEBUGSTR("DestroyStream");
712 err = NPP_DestroyStream(instance, stream, reason);
713 return err;
716 void
717 Private_URLNotify(NPP instance, const char* url,
718 NPReason reason, void* notifyData)
720 PLUGINDEBUGSTR("URLNotify");
721 NPP_URLNotify(instance, url, reason, notifyData);
724 void
725 Private_Print(NPP instance, NPPrint* platformPrint)
727 PLUGINDEBUGSTR("Print");
728 NPP_Print(instance, platformPrint);
731 NPError
732 Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
734 PLUGINDEBUGSTR("GetValue");
735 return NPP_GetValue(instance, variable, r_value);
738 NPError
739 Private_SetValue(NPP instance, NPPVariable variable, void *r_value)
741 PLUGINDEBUGSTR("SetValue");
742 return NPP_SetValue(instance, variable, r_value);
745 #ifdef OJI
746 JRIGlobalRef
747 Private_GetJavaClass(void)
749 jref clazz = NPP_GetJavaClass();
750 if (clazz) {
751 JRIEnv* env = NPN_GetJavaEnv();
752 return JRI_NewGlobalRef(env, clazz);
754 return NULL;
756 #endif
758 /***********************************************************************
760 * These functions are located automagically by netscape.
762 ***********************************************************************/
765 * NP_GetMIMEDescription
766 * - Netscape needs to know about this symbol
767 * - Netscape uses the return value to identify when an object instance
768 * of this plugin should be created.
770 char *
771 NP_GetMIMEDescription(void)
773 return NPP_GetMIMEDescription();
777 * NP_GetValue [optional]
778 * - Netscape needs to know about this symbol.
779 * - Interfaces with plugin to get values for predefined variables
780 * that the navigator needs.
782 NPError
783 NP_GetValue(void* future, NPPVariable variable, void *value)
785 return NPP_GetValue(future, variable, value);
789 * NP_Initialize
790 * - Netscape needs to know about this symbol.
791 * - It calls this function after looking up its symbol before it
792 * is about to create the first ever object of this kind.
794 * PARAMETERS
795 * nsTable - The netscape function table. If developers just use these
796 * wrappers, they don't need to worry about all these function
797 * tables.
798 * RETURN
799 * pluginFuncs
800 * - This functions needs to fill the plugin function table
801 * pluginFuncs and return it. Netscape Navigator plugin
802 * library will use this function table to call the plugin.
805 NPError
806 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
808 NPError err = NPERR_NO_ERROR;
810 PLUGINDEBUGSTR("NP_Initialize");
812 /* validate input parameters */
813 if ((nsTable == NULL) || (pluginFuncs == NULL))
814 err = NPERR_INVALID_FUNCTABLE_ERROR;
817 * Check the major version passed in Netscape's function table.
818 * We won't load if the major version is newer than what we expect.
819 * Also check that the function tables passed in are big enough for
820 * all the functions we need (they could be bigger, if Netscape added
821 * new APIs, but that's OK with us -- we'll just ignore them).
824 if (err == NPERR_NO_ERROR) {
825 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
826 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
827 if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
828 err = NPERR_INVALID_FUNCTABLE_ERROR;
829 if (pluginFuncs->size < sizeof(NPPluginFuncs))
830 err = NPERR_INVALID_FUNCTABLE_ERROR;
833 if (err == NPERR_NO_ERROR)
836 * Copy all the fields of Netscape function table into our
837 * copy so we can call back into Netscape later. Note that
838 * we need to copy the fields one by one, rather than assigning
839 * the whole structure, because the Netscape function table
840 * could actually be bigger than what we expect.
842 int minor = nsTable->version & 0xFF;
844 gNetscapeFuncs.version = nsTable->version;
845 gNetscapeFuncs.size = nsTable->size;
846 gNetscapeFuncs.posturl = nsTable->posturl;
847 gNetscapeFuncs.geturl = nsTable->geturl;
848 gNetscapeFuncs.requestread = nsTable->requestread;
849 gNetscapeFuncs.newstream = nsTable->newstream;
850 gNetscapeFuncs.write = nsTable->write;
851 gNetscapeFuncs.destroystream = nsTable->destroystream;
852 gNetscapeFuncs.status = nsTable->status;
853 gNetscapeFuncs.uagent = nsTable->uagent;
854 gNetscapeFuncs.memalloc = nsTable->memalloc;
855 gNetscapeFuncs.memfree = nsTable->memfree;
856 gNetscapeFuncs.memflush = nsTable->memflush;
857 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
858 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
859 gNetscapeFuncs.pluginthreadasynccall =
860 nsTable->pluginthreadasynccall;
861 #endif
862 #ifdef OJI
863 if( minor >= NPVERS_HAS_LIVECONNECT )
865 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
866 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
868 #endif
869 gNetscapeFuncs.getvalue = nsTable->getvalue;
870 gNetscapeFuncs.setvalue = nsTable->setvalue;
872 if( minor >= NPVERS_HAS_NOTIFICATION )
874 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
875 gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
878 if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
880 gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
881 gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
882 gNetscapeFuncs.forceredraw = nsTable->forceredraw;
883 /* npruntime support */
884 if (minor >= 14)
886 gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
887 gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
888 gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
889 gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
890 gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
891 gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
892 gNetscapeFuncs.createobject = nsTable->createobject;
893 gNetscapeFuncs.retainobject = nsTable->retainobject;
894 gNetscapeFuncs.releaseobject = nsTable->releaseobject;
895 gNetscapeFuncs.invoke = nsTable->invoke;
896 gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
897 gNetscapeFuncs.evaluate = nsTable->evaluate;
898 gNetscapeFuncs.getproperty = nsTable->getproperty;
899 gNetscapeFuncs.setproperty = nsTable->setproperty;
900 gNetscapeFuncs.removeproperty = nsTable->removeproperty;
901 gNetscapeFuncs.hasproperty = nsTable->hasproperty;
902 gNetscapeFuncs.hasmethod = nsTable->hasmethod;
903 gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
904 gNetscapeFuncs.setexception = nsTable->setexception;
907 else
909 gNetscapeFuncs.invalidaterect = NULL;
910 gNetscapeFuncs.invalidateregion = NULL;
911 gNetscapeFuncs.forceredraw = NULL;
912 gNetscapeFuncs.getstringidentifier = NULL;
913 gNetscapeFuncs.getstringidentifiers = NULL;
914 gNetscapeFuncs.getintidentifier = NULL;
915 gNetscapeFuncs.identifierisstring = NULL;
916 gNetscapeFuncs.utf8fromidentifier = NULL;
917 gNetscapeFuncs.intfromidentifier = NULL;
918 gNetscapeFuncs.createobject = NULL;
919 gNetscapeFuncs.retainobject = NULL;
920 gNetscapeFuncs.releaseobject = NULL;
921 gNetscapeFuncs.invoke = NULL;
922 gNetscapeFuncs.invokeDefault = NULL;
923 gNetscapeFuncs.evaluate = NULL;
924 gNetscapeFuncs.getproperty = NULL;
925 gNetscapeFuncs.setproperty = NULL;
926 gNetscapeFuncs.removeproperty = NULL;
927 gNetscapeFuncs.hasproperty = NULL;
928 gNetscapeFuncs.releasevariantvalue = NULL;
929 gNetscapeFuncs.setexception = NULL;
931 if (nsTable->size >=
932 ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
934 gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
935 gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
937 else
939 gNetscapeFuncs.pushpopupsenabledstate = NULL;
940 gNetscapeFuncs.poppopupsenabledstate = NULL;
944 * Set up the plugin function table that Netscape will use to
945 * call us. Netscape needs to know about our version and size
946 * and have a UniversalProcPointer for every function we
947 * implement.
949 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
950 pluginFuncs->size = sizeof(NPPluginFuncs);
951 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
952 pluginFuncs->newp = NewNPP_NewProc(Private_New);
953 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
954 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
955 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
956 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
957 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
958 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
959 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
960 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
961 pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
962 pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
963 #else
964 pluginFuncs->newp = (NPP_NewProcPtr)(Private_New);
965 pluginFuncs->destroy = (NPP_DestroyProcPtr)(Private_Destroy);
966 pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(Private_SetWindow);
967 pluginFuncs->newstream = (NPP_NewStreamProcPtr)(Private_NewStream);
968 pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
969 pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
970 pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
971 pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
972 pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
973 pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
974 pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
975 #endif
976 pluginFuncs->event = NULL;
977 if( minor >= NPVERS_HAS_NOTIFICATION )
979 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
980 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
981 #else
982 pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
983 #endif
985 #ifdef OJI
986 if( minor >= NPVERS_HAS_LIVECONNECT )
987 pluginFuncs->javaClass = Private_GetJavaClass();
988 else
989 pluginFuncs->javaClass = NULL;
990 #else
991 pluginFuncs->javaClass = NULL;
992 #endif
994 err = NPP_Initialize();
997 return err;
1001 * NP_Shutdown [optional]
1002 * - Netscape needs to know about this symbol.
1003 * - It calls this function after looking up its symbol after
1004 * the last object of this kind has been destroyed.
1007 NPError
1008 NP_Shutdown(void)
1010 PLUGINDEBUGSTR("NP_Shutdown");
1011 NPP_Shutdown();
1012 return NPERR_NO_ERROR;