"Fossies" - the Fresh Open Source Software Archive 
Member "mozplugger-2.1.6/npapi/npn_funcs.c" (17 Apr 2014, 22961 Bytes) of package /linux/www/old/mozplugger-2.1.6.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is mozilla.org code.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Stephen Mak <smak@sun.com>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 #include <stdio.h>
41 #include <string.h>
42
43 #include "npapi.h"
44 #include "npruntime.h"
45 #include "npn_func_tab.h"
46 #include "npn_funcs.h"
47
48 /***********************************************************************
49 *
50 * Globals
51 *
52 ***********************************************************************/
53
54 static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
55
56
57 /***********************************************************************
58 *
59 * Wrapper functions : plugin calling Netscape Navigator
60 *
61 * These functions let the plugin developer just call the APIs
62 * as documented and defined in npapi.h, without needing to know
63 * about the function table and call macros in npupp.h.
64 *
65 ***********************************************************************/
66
67 void NPN_Version(int * netscape_major, int * netscape_minor)
68 {
69 /* Major version is in high byte */
70 *netscape_major = gNetscapeFuncs.version >> 8;
71 /* Minor version is in low byte */
72 *netscape_minor = gNetscapeFuncs.version & 0xFF;
73 }
74
75 /******************************************************************************/
76 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
77 {
78 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
79 NPN_GetValueProcPtr func = gNetscapeFuncs.getvalue;
80 if(func)
81 {
82 retVal = (*func)(instance, variable, r_value);
83 }
84 return retVal;
85 }
86
87 /******************************************************************************/
88 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
89 {
90 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
91 NPN_SetValueProcPtr func = gNetscapeFuncs.setvalue;
92 if(func)
93 {
94 retVal = (*func)(instance, variable, value);
95 }
96 return retVal;
97 }
98
99 /******************************************************************************/
100 NPError NPN_GetURL(NPP instance, const char* url, const char* window)
101 {
102 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
103 NPN_GetURLProcPtr func = gNetscapeFuncs.geturl;
104 if(func)
105 {
106 retVal = (*func)(instance, url, window);
107 }
108 return retVal;
109 }
110
111 /******************************************************************************/
112 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window,
113 void* notifyData)
114 {
115 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
116 NPN_GetURLNotifyProcPtr func = gNetscapeFuncs.geturlnotify;
117 if(func)
118 {
119 retVal = (*func)(instance, url, window, notifyData);
120 }
121 return retVal;
122 }
123
124 /******************************************************************************/
125 NPError NPN_PostURL(NPP instance, const char* url, const char* window,
126 uint32_t len, const char* buf, NPBool file)
127 {
128 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
129 NPN_PostURLProcPtr func = gNetscapeFuncs.posturl;
130 if(func)
131 {
132 retVal = (*func)(instance, url, window, len, buf, file);
133 }
134 return retVal;
135 }
136
137 /******************************************************************************/
138 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window,
139 uint32_t len, const char* buf, NPBool file, void* notifyData)
140 {
141 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
142 NPN_PostURLNotifyProcPtr func = gNetscapeFuncs.posturlnotify;
143 if(func)
144 {
145 retVal = (*func)(instance, url, window, len, buf, file, notifyData);
146 }
147 return retVal;
148 }
149
150 /******************************************************************************/
151 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
152 {
153 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
154 NPN_RequestReadProcPtr func = gNetscapeFuncs.requestread;
155 if(func)
156 {
157 retVal = (*func)(stream, rangeList);
158 }
159 return retVal;
160 }
161
162 /******************************************************************************/
163 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
164 NPStream** stream_ptr)
165 {
166 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
167 NPN_NewStreamProcPtr func = gNetscapeFuncs.newstream;
168 if(func)
169 {
170 retVal = (*func)(instance, type, window, stream_ptr);
171 }
172 return retVal;
173 }
174
175 /******************************************************************************/
176 int32_t NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
177 {
178 int32_t retVal = 0;
179 NPN_WriteProcPtr func = gNetscapeFuncs.write;
180 if(func)
181 {
182 retVal = (*func)(instance, stream, len, buffer);
183 }
184 return retVal;
185 }
186
187 /******************************************************************************/
188 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
189 {
190 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
191 NPN_DestroyStreamProcPtr func = gNetscapeFuncs.destroystream;
192 if(func)
193 {
194 retVal = (*func)(instance, stream, reason);
195 }
196 return retVal;
197 }
198
199 /******************************************************************************/
200 void NPN_Status(NPP instance, const char* message)
201 {
202 NPN_StatusProcPtr func = gNetscapeFuncs.status;
203 if(func)
204 {
205 (*func)(instance, message);
206 }
207 }
208
209 /******************************************************************************/
210 const char* NPN_UserAgent(NPP instance)
211 {
212 const char * retVal = 0;
213 NPN_UserAgentProcPtr func = gNetscapeFuncs.uagent;
214 if(func)
215 {
216 retVal = (*func)(instance);
217 }
218 return retVal;
219 }
220
221 /******************************************************************************/
222 void* NPN_MemAlloc(uint32_t size)
223 {
224 void * retVal = 0;
225 NPN_MemAllocProcPtr func = gNetscapeFuncs.memalloc;
226 if(func)
227 {
228 retVal = (*func)(size);
229 }
230 return retVal;
231 }
232
233 /******************************************************************************/
234 void NPN_MemFree(void* ptr)
235 {
236 NPN_MemFreeProcPtr func = gNetscapeFuncs.memfree;
237 if(func)
238 {
239 (*func)(ptr);
240 }
241 }
242
243 /******************************************************************************/
244 uint32_t NPN_MemFlush(uint32_t size)
245 {
246 uint32_t retVal = 0;
247 NPN_MemFlushProcPtr func = gNetscapeFuncs.memflush;
248 if(func)
249 {
250 retVal = (*func)(size);
251 }
252 return retVal;
253 }
254
255 /******************************************************************************/
256 void NPN_ReloadPlugins(NPBool reloadPages)
257 {
258 NPN_ReloadPluginsProcPtr func = gNetscapeFuncs.reloadplugins;
259 if(func)
260 {
261 (*func)(reloadPages);
262 }
263 }
264
265 /******************************************************************************/
266 void NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
267 {
268 NPN_InvalidateRectProcPtr func = gNetscapeFuncs.invalidaterect;
269 if(func)
270 {
271 (*func)(instance, invalidRect);
272 }
273 }
274
275 /******************************************************************************/
276 void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
277 {
278 NPN_InvalidateRegionProcPtr func = gNetscapeFuncs.invalidateregion;
279 if(func)
280 {
281 (*func)(instance, invalidRegion);
282 }
283 }
284
285 /******************************************************************************/
286 void NPN_ForceRedraw(NPP instance)
287 {
288 NPN_ForceRedrawProcPtr func = gNetscapeFuncs.forceredraw;
289 if(func)
290 {
291 (*func)(instance);
292 }
293 }
294
295 /******************************************************************************/
296 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
297 {
298 NPN_PushPopupsEnabledStateProcPtr func
299 = gNetscapeFuncs.pushpopupsenabledstate;
300 if(func)
301 {
302 (*func)(instance, enabled);
303 }
304 }
305
306 /******************************************************************************/
307 void NPN_PopPopupsEnabledState(NPP instance)
308 {
309 NPN_PopPopupsEnabledStateProcPtr func
310 = gNetscapeFuncs.poppopupsenabledstate;
311 if(func)
312 {
313 (*func)(instance);
314 }
315 }
316
317 /******************************************************************************/
318 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
319 {
320 NPIdentifier retVal = 0;
321 NPN_GetStringIdentifierProcPtr func = gNetscapeFuncs.getstringidentifier;
322 if(func)
323 {
324 retVal = (*func)(name);
325 }
326 return retVal;
327 }
328
329 /******************************************************************************/
330 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
331 NPIdentifier *identifiers)
332 {
333 NPN_GetStringIdentifiersProcPtr func = gNetscapeFuncs.getstringidentifiers;
334 if(func)
335 {
336 (*func)(names, nameCount, identifiers);
337 }
338 }
339
340 /******************************************************************************/
341 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
342 {
343 NPIdentifier retVal = 0;
344 NPN_GetIntIdentifierProcPtr func = gNetscapeFuncs.getintidentifier;
345 if(func)
346 {
347 retVal = (*func)(intid);
348 }
349 return retVal;
350 }
351
352 /******************************************************************************/
353 bool NPN_IdentifierIsString(NPIdentifier identifier)
354 {
355 bool retVal = false;
356 NPN_IdentifierIsStringProcPtr func = gNetscapeFuncs.identifierisstring;
357 if(func)
358 {
359 retVal = (*func)(identifier);
360 }
361 return retVal;
362 }
363
364 /******************************************************************************/
365 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
366 {
367 NPUTF8 * retVal = 0;
368 NPN_UTF8FromIdentifierProcPtr func = gNetscapeFuncs.utf8fromidentifier;
369 if(func)
370 {
371 retVal = (*func)(identifier);
372 }
373 return retVal;
374 }
375
376 /******************************************************************************/
377 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
378 {
379 int32_t retVal = 0;
380 NPN_IntFromIdentifierProcPtr func = gNetscapeFuncs.intfromidentifier;
381 if(func)
382 {
383 retVal = (*func)(identifier);
384 }
385 return retVal;
386 }
387
388 /******************************************************************************/
389 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
390 {
391 NPObject * retVal = 0;
392 NPN_CreateObjectProcPtr func = gNetscapeFuncs.createobject;
393 if(func)
394 {
395 retVal = (*func)( npp, aClass);
396 }
397 return retVal;
398 }
399
400 /******************************************************************************/
401 NPObject *NPN_RetainObject(NPObject *obj)
402 {
403 NPObject * retVal = 0;
404 NPN_RetainObjectProcPtr func = gNetscapeFuncs.retainobject;
405 if(func)
406 {
407 retVal = (*func)( obj);
408 }
409 return retVal;
410 }
411
412 /******************************************************************************/
413 void NPN_ReleaseObject(NPObject *obj)
414 {
415 NPN_ReleaseObjectProcPtr func = gNetscapeFuncs.releaseobject;
416 if(func)
417 {
418 (*func)(obj);
419 }
420 }
421
422 /******************************************************************************/
423 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
424 const NPVariant *args, uint32_t argCount, NPVariant *result)
425 {
426 bool retVal = false;
427 NPN_InvokeProcPtr func = gNetscapeFuncs.invoke;
428 if(func)
429 {
430 retVal = (*func)(npp, obj, methodName, args, argCount, result);
431 }
432 return retVal;
433 }
434
435 /******************************************************************************/
436 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
437 uint32_t argCount, NPVariant *result)
438 {
439 bool retVal = false;
440 NPN_InvokeDefaultProcPtr func = gNetscapeFuncs.invokeDefault;
441 if(func)
442 {
443 retVal = (*func)(npp, obj, args, argCount, result);
444 }
445 return retVal;
446 }
447
448 /******************************************************************************/
449 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script, NPVariant *result)
450 {
451 bool retVal = false;
452 NPN_EvaluateProcPtr func = gNetscapeFuncs.evaluate;
453 if(func)
454 {
455 retVal = (*func)(npp, obj, script, result);
456 }
457 return retVal;
458 }
459
460 /******************************************************************************/
461 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
462 NPVariant *result)
463 {
464 bool retVal = false;
465 NPN_GetPropertyProcPtr func = gNetscapeFuncs.getproperty;
466 if(func)
467 {
468 retVal = (*func)(npp, obj, propertyName, result);
469 }
470 return retVal;
471 }
472
473 /******************************************************************************/
474 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
475 const NPVariant *value)
476 {
477 bool retVal = false;
478 NPN_SetPropertyProcPtr func = gNetscapeFuncs.setproperty;
479 if(func)
480 {
481 retVal = (*func)(npp, obj, propertyName, value);
482 }
483 return retVal;
484 }
485
486 /******************************************************************************/
487 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
488 {
489 bool retVal = false;
490 NPN_RemovePropertyProcPtr func = gNetscapeFuncs.removeproperty;
491 if(func)
492 {
493 retVal = (*func)(npp, obj, propertyName);
494 }
495 return retVal;
496 }
497
498 /******************************************************************************/
499 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
500 {
501 bool retVal = false;
502 NPN_HasPropertyProcPtr func = gNetscapeFuncs.hasproperty;
503 if(func)
504 {
505 retVal = (*func)(npp, obj, propertyName);
506 }
507 return retVal;
508 }
509
510 /******************************************************************************/
511 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
512 {
513 bool retVal = false;
514 NPN_HasMethodProcPtr func = gNetscapeFuncs.hasmethod;
515 if(func)
516 {
517 retVal = (*func)(npp, obj, methodName);
518 }
519 return retVal;
520 }
521
522 /******************************************************************************/
523 void NPN_ReleaseVariantValue(NPVariant *variant)
524 {
525 NPN_ReleaseVariantValueProcPtr func = gNetscapeFuncs.releasevariantvalue;
526 if(func)
527 {
528 (*func)(variant);
529 }
530 }
531
532 /******************************************************************************/
533 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
534 {
535 NPN_SetExceptionProcPtr func = gNetscapeFuncs.setexception;
536 if(func)
537 {
538 (*func)(obj, message);
539 }
540 }
541
542 /******************************************************************************/
543 bool NPN_Enumerate(NPP npp, NPObject *obj, NPIdentifier **identifier,
544 uint32_t *count)
545 {
546 NPN_EnumerateProcPtr func = gNetscapeFuncs.enumerate;
547 bool retVal = false;
548 if(func)
549 {
550 retVal = (*func)(npp, obj, identifier, count);
551 }
552 return retVal;
553 }
554
555 /******************************************************************************/
556 void NPN_PluginThreadAsyncCall(NPP instance, void (*func)(void *),
557 void *userData)
558 {
559 NPN_PluginThreadAsyncCallProcPtr func2
560 = gNetscapeFuncs.pluginthreadasynccall;
561 if(func2)
562 {
563 (*func2)(instance, func, userData);
564 }
565 }
566
567 /******************************************************************************/
568 bool NPN_Construct(NPP npp, NPObject* obj, const NPVariant *args,
569 uint32_t argCount, NPVariant *result)
570 {
571 NPN_ConstructProcPtr func = gNetscapeFuncs.construct;
572 bool retVal= false;
573 if(func)
574 {
575 retVal = (*func)(npp, obj, args, argCount, result);
576 }
577 return retVal;
578 }
579
580 /******************************************************************************/
581 NPError NPN_GetValueForURL(NPP npp, NPNURLVariable variable, const char *url,
582 char **value, uint32_t *len)
583 {
584 NPN_GetValueForURLPtr func = gNetscapeFuncs.getvalueforurl;
585 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
586 if(func)
587 {
588 retVal = (*func)(npp, variable, url, value, len);
589 }
590 return retVal;
591 }
592
593 /******************************************************************************/
594 NPError NPN_SetValueForURL(NPP npp, NPNURLVariable variable, const char *url,
595 const char *value, uint32_t len)
596 {
597 NPN_SetValueForURLPtr func = gNetscapeFuncs.setvalueforurl;
598 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
599 if(func)
600 {
601 retVal = (*func)(npp, variable, url, value, len);
602 }
603 return retVal;
604 }
605
606 /******************************************************************************/
607 NPError NPN_GetAuthenticationInfo(NPP npp, const char *protocol,
608 const char *host, int32_t port,
609 const char *scheme, const char *realm,
610 char **username, uint32_t *ulen,
611 char **password, uint32_t *plen)
612 {
613 NPN_GetAuthenticationInfoPtr func = gNetscapeFuncs.getauthenticationinfo;
614 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
615 if(func)
616 {
617 retVal = (*func)(npp, protocol, host, port, scheme, realm, username,
618 ulen, password, plen);
619 }
620 return retVal;
621 }
622
623 /******************************************************************************/
624 uint32_t NPN_ScheduleTimer(NPP instance, uint32_t interval, NPBool repeat,
625 void (*timerFunc)(NPP npp, uint32_t timerID))
626 {
627 NPN_ScheduleTimerPtr func = gNetscapeFuncs.scheduletimer;
628 uint32_t retVal = 0;
629 if(func)
630 {
631 retVal = (*func)(instance, interval, repeat, timerFunc);
632 }
633 return retVal;
634 }
635
636 /******************************************************************************/
637 void NPN_UnscheduleTimer(NPP instance, uint32_t timerID)
638 {
639 NPN_UnscheduleTimerPtr func = gNetscapeFuncs.unscheduletimer;
640 if(func)
641 {
642 (*func)(instance, timerID);
643 }
644 }
645
646 /******************************************************************************/
647 NPError NPN_PopUpContextMenu(NPP instance, NPMenu* menu)
648 {
649 NPN_PopUpContextMenuPtr func = gNetscapeFuncs.popupcontextmenu;
650 NPError retVal = NPERR_INVALID_FUNCTABLE_ERROR;
651 if(func)
652 {
653 retVal = (*func)(instance, menu);
654 }
655 return retVal;
656 }
657
658 /******************************************************************************/
659 NPBool NPN_ConvertPoint(NPP instance, double sourceX, double sourceY,
660 NPCoordinateSpace sourceSpace, double *destX,
661 double *destY, NPCoordinateSpace destSpace)
662 {
663 NPN_ConvertPointPtr func = gNetscapeFuncs.convertpoint;
664 NPBool retVal = false;
665 if(func)
666 {
667 retVal = (*func)(instance, sourceX, sourceY, sourceSpace, destX,
668 destY, destSpace);
669 }
670 return retVal;
671 }
672
673 /******************************************************************************/
674 NPBool NPN_HandleEvent(NPP instance, void *event, NPBool handled)
675 {
676 NPN_HandleEventPtr func = gNetscapeFuncs.handleevent;
677 NPBool retVal = false;
678 if(func)
679 {
680 retVal = (*func)(instance, event, handled);
681 }
682 return retVal;
683 }
684
685 /******************************************************************************/
686 NPBool NPN_UnfocusInstance(NPP instance, NPFocusDirection direction)
687 {
688 NPN_UnfocusInstancePtr func = gNetscapeFuncs.unfocusinstance;
689 NPBool retVal = false;
690 if(func)
691 {
692 retVal = (*func)(instance, direction);
693 }
694 return retVal;
695 }
696
697
698 /******************************************************************************/
699 void NPN_URLRedirectResponse(NPP instance, void* notifyData, NPBool allow)
700 {
701 NPN_URLRedirectResponsePtr func = gNetscapeFuncs.urlredirectresponse;
702 if(func)
703 {
704 (*func)(instance, notifyData, allow);
705 }
706 }
707
708 /******************************************************************************/
709 NPError NPN_InitFuncTable(const NPNetscapeFuncs * nsTable)
710 {
711 NPError err = NPERR_NO_ERROR;
712
713 /* Zero everything */
714 memset(&gNetscapeFuncs, 0, sizeof(gNetscapeFuncs));
715
716 /* validate input parameters */
717 if(nsTable != NULL)
718 {
719 uint32_t size;
720
721 /*
722 * Check the major version passed in Netscape's function table.
723 */
724
725 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
726 {
727 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
728 }
729
730 if (nsTable->size > sizeof(NPNetscapeFuncs))
731 {
732 /* Looks like more functions provided than we know about..*/
733 size = sizeof(NPNetscapeFuncs);
734 }
735 else
736 {
737 /* Copy across only those entries that were passed in (i.e. size) */
738 size = nsTable->size;
739 }
740
741 memcpy(&gNetscapeFuncs, nsTable, size);
742 gNetscapeFuncs.size = size;
743 }
744 else
745 {
746 err = NPERR_INVALID_FUNCTABLE_ERROR;
747 }
748 return err;
749 }