FreeWRL/FreeX3D  3.0.0
npunix.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 
3 
4  FreeWRL plugin for Mozilla compatible browsers.
5  Works in Firefox 1.x - 3.0 on Linux.
6 
7  */
8 
9 /****************************************************************************
10  This file is part of the FreeWRL/FreeX3D Distribution.
11 
12  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
13 
14  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Lesser Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
26 ****************************************************************************/
27 
28 /*
29  * ***** BEGIN LICENSE BLOCK *****
30  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
31  *
32  * The contents of this file are subject to the Mozilla Public License Version
33  * 1.1 (the "License"); you may not use this file except in compliance with
34  * the License. You may obtain a copy of the License at
35  * http://www.mozilla.org/MPL/
36  *
37  * Software distributed under the License is distributed on an "AS IS" basis,
38  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
39  * for the specific language governing rights and limitations under the
40  * License.
41  *
42  * The Original Code is mozilla.org code.
43  *
44  * The Initial Developer of the Original Code is
45  * Netscape Communications Corporation.
46  * Portions created by the Initial Developer are Copyright (C) 1998
47  * the Initial Developer. All Rights Reserved.
48  *
49  * Contributor(s):
50  * Stephen Mak <smak@sun.com>
51  *
52  * Alternatively, the contents of this file may be used under the terms of
53  * either of the GNU General Public License Version 2 or later (the "GPL"),
54  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
55  * in which case the provisions of the GPL or the LGPL are applicable instead
56  * of those above. If you wish to allow use of your version of this file only
57  * under the terms of either the GPL or the LGPL, and not to allow others to
58  * use your version of this file under the terms of the MPL, indicate your
59  * decision by deleting the provisions above and replace them with the notice
60  * and other provisions required by the GPL or the LGPL. If you do not delete
61  * the provisions above, a recipient may use your version of this file under
62  * the terms of any one of the MPL, the GPL or the LGPL.
63  *
64  * ***** END LICENSE BLOCK ***** */
65 
66 #include <config.h>
67 #include <system.h>
68 
69 #define XP_UNIX 1
70 /* define OJI 1 -- auto-defined in configure.ac when JRIEnv type exists */
71 
72 #include <npapi.h>
73 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
74 #include <npupp.h>
75 #else
76 #include <npfunctions.h>
77 #endif
78 
79 /*
80  * Define PLUGIN_TRACE to have the wrapper functions print
81  * messages to stderr whenever they are called.
82  */
83 
84 #ifdef PLUGIN_TRACE
85 #include <stdio.h>
86 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
87 #else
88 #define PLUGINDEBUGSTR(msg)
89 #endif
90 
91 /***********************************************************************
92  *
93  * Globals
94  *
95  ***********************************************************************/
96 
97 static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
98 
99 /***********************************************************************
100  *
101  * Wrapper functions : plugin calling Netscape Navigator
102  *
103  * These functions let the plugin developer just call the APIs
104  * as documented and defined in npapi.h, without needing to know
105  * about the function table and call macros in npupp.h.
106  *
107  ***********************************************************************/
108 
109 void
110 NPN_Version(int* plugin_major, int* plugin_minor,
111  int* netscape_major, int* netscape_minor)
112 {
113  *plugin_major = NP_VERSION_MAJOR;
114  *plugin_minor = NP_VERSION_MINOR;
115 
116  /* Major version is in high byte */
117  *netscape_major = gNetscapeFuncs.version >> 8;
118  /* Minor version is in low byte */
119  *netscape_minor = gNetscapeFuncs.version & 0xFF;
120 }
121 
122 void
123 NPN_PluginThreadAsyncCall(NPP plugin,
124  void (*func)(void *),
125  void *userData)
126 {
127 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
128  return (*gNetscapeFuncs.pluginthreadasynccall)(plugin, func, userData);
129 #endif
130 }
131 
132 NPError
133 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
134 {
135 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
136  return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
137  instance, variable, r_value);
138 #else
139  return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
140 #endif
141 }
142 
143 NPError
144 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
145 {
146 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
147  return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
148  instance, variable, value);
149 #else
150  return (*gNetscapeFuncs.setvalue)(instance, variable, value);
151 #endif
152 }
153 
154 NPError
155 NPN_GetURL(NPP instance, const char* url, const char* window)
156 {
157 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
158  return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
159 #else
160  return (*gNetscapeFuncs.geturl)(instance, url, window);
161 #endif
162 }
163 
164 NPError
165 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
166 {
167 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
168  return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
169 #else
170  return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
171 #endif
172 }
173 
174 NPError
175 NPN_PostURL(NPP instance, const char* url, const char* window,
176  uint32_t len, const char* buf, NPBool file)
177 {
178 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
179  return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
180  url, window, len, buf, file);
181 #else
182  return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
183 #endif
184 }
185 
186 NPError
187 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
188  const char* buf, NPBool file, void* notifyData)
189 {
190 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
191  return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
192  instance, url, window, len, buf, file, notifyData);
193 #else
194  return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);
195 
196 #endif
197 }
198 
199 NPError
200 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
201 {
202 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
203  return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
204  stream, rangeList);
205 #else
206  return (*gNetscapeFuncs.requestread)(stream, rangeList);
207 #endif
208 }
209 
210 NPError
211 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
212  NPStream** stream_ptr)
213 {
214 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
215  return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
216  type, window, stream_ptr);
217 #else
218  return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
219 #endif
220 }
221 
222 int32_t
223 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
224 {
225 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
226  return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
227  stream, len, buffer);
228 #else
229  return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
230 #endif
231 }
232 
233 NPError
234 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
235 {
236 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
237  return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
238  instance, stream, reason);
239 #else
240  return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
241 #endif
242 }
243 
244 void
245 NPN_Status(NPP instance, const char* message)
246 {
247 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
248  CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
249 #else
250  (*gNetscapeFuncs.status)(instance, message);
251 #endif
252 }
253 
254 const char*
255 NPN_UserAgent(NPP instance)
256 {
257 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
258  return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
259 #else
260  return (*gNetscapeFuncs.uagent)(instance);
261 #endif
262 }
263 
264 void *NPN_MemAlloc(uint32_t size)
265 {
266 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
267  return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
268 #else
269  return (*gNetscapeFuncs.memalloc)(size);
270 #endif
271 }
272 
273 void NPN_MemFree(void* ptr)
274 {
275 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
276  CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
277 #else
278  (*gNetscapeFuncs.memfree)(ptr);
279 #endif
280 }
281 
282 uint32_t NPN_MemFlush(uint32_t size)
283 {
284 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
285  return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
286 #else
287  return (*gNetscapeFuncs.memflush)(size);
288 #endif
289 }
290 
291 void NPN_ReloadPlugins(NPBool reloadPages)
292 {
293 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
294  CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
295 #else
296  (*gNetscapeFuncs.reloadplugins)(reloadPages);
297 #endif
298 }
299 
300 #ifdef OJI
301 JRIEnv* NPN_GetJavaEnv()
302 {
303 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
304  return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
305 #else
306  return (JRIEnv*) (*gNetscapeFuncs.getJavaEnv);
307 #endif
308 }
309 
310 jref NPN_GetJavaPeer(NPP instance)
311 {
312 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
313  return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
314  instance);
315 #else
316  return (*gNetscapeFuncs.getJavaPeer)(instance);
317 #endif
318 }
319 #endif
320 
321 void
322 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
323 {
324 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
325  CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
326  invalidRect);
327 #else
328  (*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
329 #endif
330 }
331 
332 void
333 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
334 {
335 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
336  CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
337  invalidRegion);
338 #else
339  (*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
340 #endif
341 }
342 
343 void
344 NPN_ForceRedraw(NPP instance)
345 {
346 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
347  CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
348 #else
349  (*gNetscapeFuncs.forceredraw)(instance);
350 #endif
351 }
352 
353 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
354 {
355 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
356  CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
357  instance, enabled);
358 #else
359  (*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
360 #endif
361 }
362 
363 void NPN_PopPopupsEnabledState(NPP instance)
364 {
365 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
366  CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
367  instance);
368 #else
369  (*gNetscapeFuncs.poppopupsenabledstate)(instance);
370 #endif
371 }
372 
373 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
374 {
375  int minor = gNetscapeFuncs.version & 0xFF;
376  if( minor >= 14 )
377  {
378 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
379  return CallNPN_GetStringIdentifierProc(
380  gNetscapeFuncs.getstringidentifier, name);
381 #else
382  return (*gNetscapeFuncs.getstringidentifier)(name);
383 #endif
384  }
385  return NULL;
386 }
387 
388 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
389  NPIdentifier *identifiers)
390 {
391  int minor = gNetscapeFuncs.version & 0xFF;
392  if( minor >= 14 )
393  {
394 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
395  CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
396  names, nameCount, identifiers);
397 #else
398  (*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
399 #endif
400  }
401 }
402 
403 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
404 {
405  int minor = gNetscapeFuncs.version & 0xFF;
406  if( minor >= 14 )
407  {
408 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
409  return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
410 #else
411  return (*gNetscapeFuncs.getintidentifier)(intid);
412 #endif
413  }
414  return NULL;
415 }
416 
417 bool NPN_IdentifierIsString(NPIdentifier identifier)
418 {
419  int minor = gNetscapeFuncs.version & 0xFF;
420  if( minor >= 14 )
421  {
422 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
423  return CallNPN_IdentifierIsStringProc(
424  gNetscapeFuncs.identifierisstring,
425  identifier);
426 #else
427  return (*gNetscapeFuncs.identifierisstring)(identifier);
428 #endif
429  }
430  return false;
431 }
432 
433 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
434 {
435  int minor = gNetscapeFuncs.version & 0xFF;
436  if( minor >= 14 )
437  {
438 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
439  return CallNPN_UTF8FromIdentifierProc(
440  gNetscapeFuncs.utf8fromidentifier,
441  identifier);
442 #else
443  return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
444 #endif
445  }
446  return NULL;
447 }
448 
449 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
450 {
451  int minor = gNetscapeFuncs.version & 0xFF;
452  if( minor >= 14 )
453  {
454 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
455  return CallNPN_IntFromIdentifierProc(
456  gNetscapeFuncs.intfromidentifier,
457  identifier);
458 #else
459  return (*gNetscapeFuncs.intfromidentifier)(identifier);
460 #endif
461  }
462  return 0;
463 }
464 
465 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
466 {
467  int minor = gNetscapeFuncs.version & 0xFF;
468  if( minor >= 14 )
469 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
470  return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
471 #else
472  return (*gNetscapeFuncs.createobject)(npp, aClass);
473 #endif
474  return NULL;
475 }
476 
477 NPObject *NPN_RetainObject(NPObject *obj)
478 {
479  int minor = gNetscapeFuncs.version & 0xFF;
480  if( minor >= 14 )
481 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
482  return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
483 #else
484  return (*gNetscapeFuncs.retainobject)(obj);
485 #endif
486  return NULL;
487 }
488 
489 void NPN_ReleaseObject(NPObject *obj)
490 {
491  int minor = gNetscapeFuncs.version & 0xFF;
492  if( minor >= 14 )
493 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
494  CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
495 #else
496  (*gNetscapeFuncs.releaseobject)(obj);
497 #endif
498 }
499 
500 bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
501  const NPVariant *args, uint32_t argCount, NPVariant *result)
502 {
503  int minor = gNetscapeFuncs.version & 0xFF;
504  if( minor >= 14 )
505 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
506  return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
507  args, argCount, result);
508 #else
509  return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
510 #endif
511  return false;
512 }
513 
514 bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
515  uint32_t argCount, NPVariant *result)
516 {
517  int minor = gNetscapeFuncs.version & 0xFF;
518  if( minor >= 14 )
519 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
520  return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
521  args, argCount, result);
522 #else
523  return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
524 #endif
525  return false;
526 }
527 
528 bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
529  NPVariant *result)
530 {
531  int minor = gNetscapeFuncs.version & 0xFF;
532  if( minor >= 14 )
533 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
534  return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
535  script, result);
536 #else
537  return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
538 #endif
539  return false;
540 }
541 
542 bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
543  NPVariant *result)
544 {
545  int minor = gNetscapeFuncs.version & 0xFF;
546  if( minor >= 14 )
547 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
548  return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
549  propertyName, result);
550 #else
551  return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
552 #endif
553  return false;
554 }
555 
556 bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
557  const NPVariant *value)
558 {
559  int minor = gNetscapeFuncs.version & 0xFF;
560  if( minor >= 14 )
561 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
562  return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
563  propertyName, value);
564 #else
565  return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
566 #endif
567  return false;
568 }
569 
570 bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
571 {
572  int minor = gNetscapeFuncs.version & 0xFF;
573  if( minor >= 14 )
574 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
575  return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
576  propertyName);
577 #else
578  return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
579 #endif
580  return false;
581 }
582 
583 bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
584 {
585  int minor = gNetscapeFuncs.version & 0xFF;
586  if( minor >= 14 )
587 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
588  return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
589  propertyName);
590 #else
591  return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
592 #endif
593  return false;
594 }
595 
596 bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
597 {
598  int minor = gNetscapeFuncs.version & 0xFF;
599  if( minor >= 14 )
600 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
601  return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
602  obj, methodName);
603 #else
604  return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
605 #endif
606  return false;
607 }
608 
609 void NPN_ReleaseVariantValue(NPVariant *variant)
610 {
611  int minor = gNetscapeFuncs.version & 0xFF;
612  if( minor >= 14 )
613 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
614  CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
615 #else
616  (*gNetscapeFuncs.releasevariantvalue)(variant);
617 #endif
618 }
619 
620 void NPN_SetException(NPObject* obj, const NPUTF8 *message)
621 {
622  int minor = gNetscapeFuncs.version & 0xFF;
623  if( minor >= 14 )
624 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
625  CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
626 #else
627  (*gNetscapeFuncs.setexception)(obj, message);
628 #endif
629 }
630 
631 /***********************************************************************
632  *
633  * Wrapper functions : Netscape Navigator -> plugin
634  *
635  * These functions let the plugin developer just create the APIs
636  * as documented and defined in npapi.h, without needing to
637  * install those functions in the function table or worry about
638  * setting up globals for 68K plugins.
639  *
640  ***********************************************************************/
641 
642 /* Function prototypes */
643 NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
644  int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
645 NPError Private_Destroy(NPP instance, NPSavedData** save);
646 NPError Private_SetWindow(NPP instance, NPWindow* window);
647 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
648  NPBool seekable, uint16_t* stype);
649 int32_t Private_WriteReady(NPP instance, NPStream* stream);
650 int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
651  int32_t len, void* buffer);
652 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
653 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
654 void Private_URLNotify(NPP instance, const char* url,
655  NPReason reason, void* notifyData);
656 void Private_Print(NPP instance, NPPrint* platformPrint);
657 NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
658 NPError Private_SetValue(NPP instance, NPPVariable variable, void *r_value);
659 #ifdef OJI
660 JRIGlobalRef Private_GetJavaClass(void);
661 #endif
662 
663 /* function implementations */
664 NPError
665 Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
666  int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
667 {
668  NPError ret;
669  PLUGINDEBUGSTR("New");
670  ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
671  return ret;
672 }
673 
674 NPError
675 Private_Destroy(NPP instance, NPSavedData** save)
676 {
677  PLUGINDEBUGSTR("Destroy");
678  return NPP_Destroy(instance, save);
679 }
680 
681 NPError
682 Private_SetWindow(NPP instance, NPWindow* window)
683 {
684  NPError err;
685  PLUGINDEBUGSTR("SetWindow");
686  err = NPP_SetWindow(instance, window);
687  return err;
688 }
689 
690 NPError
691 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
692  NPBool seekable, uint16_t* stype)
693 {
694  NPError err;
695  PLUGINDEBUGSTR("NewStream");
696  err = NPP_NewStream(instance, type, stream, seekable, stype);
697  return err;
698 }
699 
700 int32_t
701 Private_WriteReady(NPP instance, NPStream* stream)
702 {
703  unsigned int result;
704  PLUGINDEBUGSTR("WriteReady");
705  result = NPP_WriteReady(instance, stream);
706  return result;
707 }
708 
709 int32_t
710 Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
711  void* buffer)
712 {
713  unsigned int result;
714  PLUGINDEBUGSTR("Write");
715  result = NPP_Write(instance, stream, offset, len, buffer);
716  return result;
717 }
718 
719 void
720 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
721 {
722  PLUGINDEBUGSTR("StreamAsFile");
723  NPP_StreamAsFile(instance, stream, fname);
724 }
725 
726 
727 NPError
728 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
729 {
730  NPError err;
731  PLUGINDEBUGSTR("DestroyStream");
732  err = NPP_DestroyStream(instance, stream, reason);
733  return err;
734 }
735 
736 void
737 Private_URLNotify(NPP instance, const char* url,
738  NPReason reason, void* notifyData)
739 {
740  PLUGINDEBUGSTR("URLNotify");
741  NPP_URLNotify(instance, url, reason, notifyData);
742 }
743 
744 void
745 Private_Print(NPP instance, NPPrint* platformPrint)
746 {
747  PLUGINDEBUGSTR("Print");
748  NPP_Print(instance, platformPrint);
749 }
750 
751 NPError
752 Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
753 {
754  PLUGINDEBUGSTR("GetValue");
755  return NPP_GetValue(instance, variable, r_value);
756 }
757 
758 NPError
759 Private_SetValue(NPP instance, NPPVariable variable, void *r_value)
760 {
761  PLUGINDEBUGSTR("SetValue");
762  return NPP_SetValue(instance, variable, r_value);
763 }
764 
765 #ifdef OJI
766 JRIGlobalRef
767 Private_GetJavaClass(void)
768 {
769  jref clazz = NPP_GetJavaClass();
770  if (clazz) {
771  JRIEnv* env = NPN_GetJavaEnv();
772  return JRI_NewGlobalRef(env, clazz);
773  }
774  return NULL;
775 }
776 #endif
777 
778 /***********************************************************************
779  *
780  * These functions are located automagically by netscape.
781  *
782  ***********************************************************************/
783 
784 /*
785  * NP_GetMIMEDescription
786  * - Netscape needs to know about this symbol
787  * - Netscape uses the return value to identify when an object instance
788  * of this plugin should be created.
789  */
790 #ifdef LEGACY_NPAPI
791 char *
792 #else
793 const char *
794 #endif
795 NP_GetMIMEDescription(void)
796 {
797  return NPP_GetMIMEDescription();
798 }
799 
800 /*
801  * NP_GetValue [optional]
802  * - Netscape needs to know about this symbol.
803  * - Interfaces with plugin to get values for predefined variables
804  * that the navigator needs.
805  */
806 NPError
807 NP_GetValue(void* future, NPPVariable variable, void *value)
808 {
809  return NPP_GetValue(future, variable, value);
810 }
811 
812 /*
813  * NP_Initialize
814  * - Netscape needs to know about this symbol.
815  * - It calls this function after looking up its symbol before it
816  * is about to create the first ever object of this kind.
817  *
818  * PARAMETERS
819  * nsTable - The netscape function table. If developers just use these
820  * wrappers, they don't need to worry about all these function
821  * tables.
822  * RETURN
823  * pluginFuncs
824  * - This functions needs to fill the plugin function table
825  * pluginFuncs and return it. Netscape Navigator plugin
826  * library will use this function table to call the plugin.
827  *
828  */
829 NPError
830 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
831 {
832  NPError err = NPERR_NO_ERROR;
833 
834  PLUGINDEBUGSTR("NP_Initialize");
835 
836  /* validate input parameters */
837  if ((nsTable == NULL) || (pluginFuncs == NULL))
838  err = NPERR_INVALID_FUNCTABLE_ERROR;
839 
840  /*
841  * Check the major version passed in Netscape's function table.
842  * We won't load if the major version is newer than what we expect.
843  * Also check that the function tables passed in are big enough for
844  * all the functions we need (they could be bigger, if Netscape added
845  * new APIs, but that's OK with us -- we'll just ignore them).
846  *
847  */
848  if (err == NPERR_NO_ERROR) {
849  if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
850  err = NPERR_INCOMPATIBLE_VERSION_ERROR;
851  if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
852  err = NPERR_INVALID_FUNCTABLE_ERROR;
853  if (pluginFuncs->size < sizeof(NPPluginFuncs))
854  err = NPERR_INVALID_FUNCTABLE_ERROR;
855  }
856 
857  if (err == NPERR_NO_ERROR)
858  {
859  /*
860  * Copy all the fields of Netscape function table into our
861  * copy so we can call back into Netscape later. Note that
862  * we need to copy the fields one by one, rather than assigning
863  * the whole structure, because the Netscape function table
864  * could actually be bigger than what we expect.
865  */
866  int minor = nsTable->version & 0xFF;
867 
868  gNetscapeFuncs.version = nsTable->version;
869  gNetscapeFuncs.size = nsTable->size;
870  gNetscapeFuncs.posturl = nsTable->posturl;
871  gNetscapeFuncs.geturl = nsTable->geturl;
872  gNetscapeFuncs.requestread = nsTable->requestread;
873  gNetscapeFuncs.newstream = nsTable->newstream;
874  gNetscapeFuncs.write = nsTable->write;
875  gNetscapeFuncs.destroystream = nsTable->destroystream;
876  gNetscapeFuncs.status = nsTable->status;
877  gNetscapeFuncs.uagent = nsTable->uagent;
878  gNetscapeFuncs.memalloc = nsTable->memalloc;
879  gNetscapeFuncs.memfree = nsTable->memfree;
880  gNetscapeFuncs.memflush = nsTable->memflush;
881  gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
882 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
883  gNetscapeFuncs.pluginthreadasynccall =
884  nsTable->pluginthreadasynccall;
885 #endif
886 #ifdef OJI
887  if( minor >= NPVERS_HAS_LIVECONNECT )
888  {
889  gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
890  gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
891  }
892 #endif
893  gNetscapeFuncs.getvalue = nsTable->getvalue;
894  gNetscapeFuncs.setvalue = nsTable->setvalue;
895 
896  if( minor >= NPVERS_HAS_NOTIFICATION )
897  {
898  gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
899  gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
900  }
901 
902  if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
903  {
904  gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
905  gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
906  gNetscapeFuncs.forceredraw = nsTable->forceredraw;
907  /* npruntime support */
908  if (minor >= 14)
909  {
910  gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
911  gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
912  gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
913  gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
914  gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
915  gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
916  gNetscapeFuncs.createobject = nsTable->createobject;
917  gNetscapeFuncs.retainobject = nsTable->retainobject;
918  gNetscapeFuncs.releaseobject = nsTable->releaseobject;
919  gNetscapeFuncs.invoke = nsTable->invoke;
920  gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
921  gNetscapeFuncs.evaluate = nsTable->evaluate;
922  gNetscapeFuncs.getproperty = nsTable->getproperty;
923  gNetscapeFuncs.setproperty = nsTable->setproperty;
924  gNetscapeFuncs.removeproperty = nsTable->removeproperty;
925  gNetscapeFuncs.hasproperty = nsTable->hasproperty;
926  gNetscapeFuncs.hasmethod = nsTable->hasmethod;
927  gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
928  gNetscapeFuncs.setexception = nsTable->setexception;
929  }
930  }
931  else
932  {
933  gNetscapeFuncs.invalidaterect = NULL;
934  gNetscapeFuncs.invalidateregion = NULL;
935  gNetscapeFuncs.forceredraw = NULL;
936  gNetscapeFuncs.getstringidentifier = NULL;
937  gNetscapeFuncs.getstringidentifiers = NULL;
938  gNetscapeFuncs.getintidentifier = NULL;
939  gNetscapeFuncs.identifierisstring = NULL;
940  gNetscapeFuncs.utf8fromidentifier = NULL;
941  gNetscapeFuncs.intfromidentifier = NULL;
942  gNetscapeFuncs.createobject = NULL;
943  gNetscapeFuncs.retainobject = NULL;
944  gNetscapeFuncs.releaseobject = NULL;
945  gNetscapeFuncs.invoke = NULL;
946  gNetscapeFuncs.invokeDefault = NULL;
947  gNetscapeFuncs.evaluate = NULL;
948  gNetscapeFuncs.getproperty = NULL;
949  gNetscapeFuncs.setproperty = NULL;
950  gNetscapeFuncs.removeproperty = NULL;
951  gNetscapeFuncs.hasproperty = NULL;
952  gNetscapeFuncs.releasevariantvalue = NULL;
953  gNetscapeFuncs.setexception = NULL;
954  }
955  if (nsTable->size >=
956  ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
957  {
958  gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
959  gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
960  }
961  else
962  {
963  gNetscapeFuncs.pushpopupsenabledstate = NULL;
964  gNetscapeFuncs.poppopupsenabledstate = NULL;
965  }
966 
967  /*
968  * Set up the plugin function table that Netscape will use to
969  * call us. Netscape needs to know about our version and size
970  * and have a UniversalProcPointer for every function we
971  * implement.
972  */
973  pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
974  pluginFuncs->size = sizeof(NPPluginFuncs);
975 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
976  pluginFuncs->newp = NewNPP_NewProc(Private_New);
977  pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
978  pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
979  pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
980  pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
981  pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
982  pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
983  pluginFuncs->write = NewNPP_WriteProc(Private_Write);
984  pluginFuncs->print = NewNPP_PrintProc(Private_Print);
985  pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
986  pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
987 #else
988  pluginFuncs->newp = (NPP_NewProcPtr)(Private_New);
989  pluginFuncs->destroy = (NPP_DestroyProcPtr)(Private_Destroy);
990  pluginFuncs->setwindow = (NPP_SetWindowProcPtr)(Private_SetWindow);
991  pluginFuncs->newstream = (NPP_NewStreamProcPtr)(Private_NewStream);
992  pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
993  pluginFuncs->asfile = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
994  pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
995  pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
996  pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
997  pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
998  pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
999 #endif
1000  pluginFuncs->event = NULL;
1001  if( minor >= NPVERS_HAS_NOTIFICATION )
1002  {
1003 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
1004  pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
1005 #else
1006  pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
1007 #endif
1008  }
1009 #ifdef OJI
1010  if( minor >= NPVERS_HAS_LIVECONNECT )
1011  pluginFuncs->javaClass = Private_GetJavaClass();
1012  else
1013  pluginFuncs->javaClass = NULL;
1014 #else
1015  pluginFuncs->javaClass = NULL;
1016 #endif
1017 
1018 /* err = NPP_Initialize();
1019 --note, this never did anything, so skipping the call (fixes compile warning) */
1020  }
1021 
1022  return err;
1023 }
1024 
1025 /*
1026  * NP_Shutdown [optional]
1027  * - Netscape needs to know about this symbol.
1028  * - It calls this function after looking up its symbol after
1029  * the last object of this kind has been destroyed.
1030  *
1031  */
1032 NPError
1033 NP_Shutdown(void)
1034 {
1035  PLUGINDEBUGSTR("NP_Shutdown");
1036 /* NPP_Shutdown();
1037 --note, this never did anything, so skipping the call (fixes compile warning) */
1038  return NPERR_NO_ERROR;
1039 }
Definition: npapi.h:189
Definition: npapi.h:148