bump product version to 4.1.6.2
[LibreOffice.git] / np_sdk / npsdk / npunix.c
blob24ef766873dda44bd65499b6285a111bd0ed3202
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is mozilla.org code.
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.
23 * Contributor(s):
24 * Stephen Mak <smak@sun.com>
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.
38 * ***** END LICENSE BLOCK ***** */
41 * npunix.c
43 * Netscape Client Plugin API
44 * - Wrapper function to interface with the Netscape Navigator
46 * dp Suresh <dp@netscape.com>
48 *----------------------------------------------------------------------
49 * PLUGIN DEVELOPERS:
50 * YOU WILL NOT NEED TO EDIT THIS FILE.
51 *----------------------------------------------------------------------
54 #include <sal/types.h> // just for SAL_DLLPUBLIC_EXPORT
56 #define XP_UNIX 1
58 #include <stdio.h>
59 #include "npapi.h"
60 #include "npupp.h"
61 #include "plugin.h"
64 * Define PLUGIN_TRACE to have the wrapper functions print
65 * messages to stderr whenever they are called.
68 #ifdef PLUGIN_TRACE
69 #include <stdio.h>
70 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
71 #else
72 #define PLUGINDEBUGSTR(msg)
73 #endif
76 /***********************************************************************
78 * Globals
80 ***********************************************************************/
82 static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
85 /***********************************************************************
87 * Wrapper functions : plugin calling Netscape Navigator
89 * These functions let the plugin developer just call the APIs
90 * as documented and defined in npapi.h, without needing to know
91 * about the function table and call macros in npupp.h.
93 ***********************************************************************/
95 void
96 NPN_Version(int* plugin_major, int* plugin_minor,
97 int* netscape_major, int* netscape_minor)
99 *plugin_major = NP_VERSION_MAJOR;
100 *plugin_minor = NP_VERSION_MINOR;
102 /* Major version is in high byte */
103 *netscape_major = gNetscapeFuncs.version >> 8;
104 /* Minor version is in low byte */
105 *netscape_minor = gNetscapeFuncs.version & 0xFF;
108 NPError
109 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
111 return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
112 instance, variable, r_value);
115 NPError
116 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
118 return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
119 instance, variable, value);
122 NPError
123 NPN_GetURL(NPP instance, const char* url, const char* window)
125 return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
128 NPError
129 NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
131 return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
134 NPError
135 NPN_PostURL(NPP instance, const char* url, const char* window,
136 uint32_t len, const char* buf, NPBool file)
138 return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
139 url, window, len, buf, file);
142 NPError
143 NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
144 const char* buf, NPBool file, void* notifyData)
146 return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
147 instance, url, window, len, buf, file, notifyData);
150 NPError
151 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
153 return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
154 stream, rangeList);
157 NPError
158 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
159 NPStream** stream_ptr)
161 return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
162 type, window, stream_ptr);
165 int32_t
166 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
168 return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
169 stream, len, buffer);
172 NPError
173 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
175 return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
176 instance, stream, reason);
179 void
180 NPN_Status(NPP instance, const char* message)
182 CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
185 const char*
186 NPN_UserAgent(NPP instance)
188 return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
191 void*
192 NPN_MemAlloc(uint32_t size)
194 return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
197 void NPN_MemFree(void* ptr)
199 CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
202 uint32_t NPN_MemFlush(uint32_t size)
204 return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
207 void NPN_ReloadPlugins(NPBool reloadPages)
209 CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
212 #ifdef OJI
213 JRIEnv* NPN_GetJavaEnv()
215 return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
218 jref NPN_GetJavaPeer(NPP instance)
220 return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
221 instance);
223 #endif
225 void
226 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
228 CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
229 invalidRect);
232 void
233 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
235 CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
236 invalidRegion);
239 void
240 NPN_ForceRedraw(NPP instance)
242 CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
245 /***********************************************************************
247 * Wrapper functions : Netscape Navigator -> plugin
249 * These functions let the plugin developer just create the APIs
250 * as documented and defined in npapi.h, without needing to
251 * install those functions in the function table or worry about
252 * setting up globals for 68K plugins.
254 ***********************************************************************/
256 NPError
257 Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
258 int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
260 NPError ret;
261 PLUGINDEBUGSTR("New");
262 ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
263 return ret;
266 NPError
267 Private_Destroy(NPP instance, NPSavedData** save)
269 PLUGINDEBUGSTR("Destroy");
270 return NPP_Destroy(instance, save);
273 NPError
274 Private_SetWindow(NPP instance, NPWindow* window)
276 NPError err;
277 PLUGINDEBUGSTR("SetWindow");
278 err = NPP_SetWindow(instance, window);
279 return err;
282 NPError
283 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
284 NPBool seekable, uint16_t* stype)
286 NPError err;
287 PLUGINDEBUGSTR("NewStream");
288 err = NPP_NewStream(instance, type, stream, seekable, stype);
289 return err;
292 int32_t
293 Private_WriteReady(NPP instance, NPStream* stream)
295 unsigned int result;
296 PLUGINDEBUGSTR("WriteReady");
297 result = NPP_WriteReady(instance, stream);
298 return result;
301 int32_t
302 Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
303 void* buffer)
305 unsigned int result;
306 PLUGINDEBUGSTR("Write");
307 result = NPP_Write(instance, stream, offset, len, buffer);
308 return result;
311 void
312 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
314 PLUGINDEBUGSTR("StreamAsFile");
315 NPP_StreamAsFile(instance, stream, fname);
319 NPError
320 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
322 NPError err;
323 PLUGINDEBUGSTR("DestroyStream");
324 err = NPP_DestroyStream(instance, stream, reason);
325 return err;
328 void
329 Private_URLNotify(NPP instance, const char* url,
330 NPReason reason, void* notifyData)
333 PLUGINDEBUGSTR("URLNotify");
334 NPP_URLNotify(instance, url, reason, notifyData);
339 void
340 Private_Print(NPP instance, NPPrint* platformPrint)
342 PLUGINDEBUGSTR("Print");
343 NPP_Print(instance, platformPrint);
346 #ifdef OJI
347 JRIGlobalRef
348 Private_GetJavaClass(void)
350 jref clazz = NPP_GetJavaClass();
351 if (clazz) {
352 JRIEnv* env = NPN_GetJavaEnv();
353 return JRI_NewGlobalRef(env, clazz);
355 return NULL;
357 #endif
359 /***********************************************************************
361 * These functions are located automagically by netscape.
363 ***********************************************************************/
366 * NP_GetMIMEDescription
367 * - Netscape needs to know about this symbol
368 * - Netscape uses the return value to identify when an object instance
369 * of this plugin should be created.
371 SAL_DLLPUBLIC_EXPORT char *
372 NP_GetMIMEDescription(void)
374 return (char *)NPP_GetMIMEDescription();
378 * NP_GetValue [optional]
379 * - Netscape needs to know about this symbol.
380 * - Interfaces with plugin to get values for predefined variables
381 * that the navigator needs.
383 SAL_DLLPUBLIC_EXPORT NPError
384 NP_GetValue(void* future, NPPVariable variable, void *value)
386 return NPP_GetValue(future, variable, value);
390 * NP_Initialize
391 * - Netscape needs to know about this symbol.
392 * - It calls this function after looking up its symbol before it
393 * is about to create the first ever object of this kind.
395 * PARAMETERS
396 * nsTable - The netscape function table. If developers just use these
397 * wrappers, they dont need to worry about all these function
398 * tables.
399 * RETURN
400 * pluginFuncs
401 * - This functions needs to fill the plugin function table
402 * pluginFuncs and return it. Netscape Navigator plugin
403 * library will use this function table to call the plugin.
406 SAL_DLLPUBLIC_EXPORT NPError
407 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
409 NPError err = NPERR_NO_ERROR;
411 PLUGINDEBUGSTR("NP_Initialize");
413 /* validate input parameters */
415 if ((nsTable == NULL) || (pluginFuncs == NULL))
416 err = NPERR_INVALID_FUNCTABLE_ERROR;
419 * Check the major version passed in Netscape's function table.
420 * We won't load if the major version is newer than what we expect.
421 * Also check that the function tables passed in are big enough for
422 * all the functions we need (they could be bigger, if Netscape added
423 * new APIs, but that's OK with us -- we'll just ignore them).
427 if (err == NPERR_NO_ERROR) {
428 if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
429 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
430 if (nsTable->size < sizeof(NPNetscapeFuncs))
431 err = NPERR_INVALID_FUNCTABLE_ERROR;
432 if (pluginFuncs->size < sizeof(NPPluginFuncs))
433 err = NPERR_INVALID_FUNCTABLE_ERROR;
437 if (err == NPERR_NO_ERROR) {
439 * Copy all the fields of Netscape function table into our
440 * copy so we can call back into Netscape later. Note that
441 * we need to copy the fields one by one, rather than assigning
442 * the whole structure, because the Netscape function table
443 * could actually be bigger than what we expect.
445 gNetscapeFuncs.version = nsTable->version;
446 gNetscapeFuncs.size = nsTable->size;
447 gNetscapeFuncs.posturl = nsTable->posturl;
448 gNetscapeFuncs.geturl = nsTable->geturl;
449 gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
450 gNetscapeFuncs.requestread = nsTable->requestread;
451 gNetscapeFuncs.newstream = nsTable->newstream;
452 gNetscapeFuncs.write = nsTable->write;
453 gNetscapeFuncs.destroystream = nsTable->destroystream;
454 gNetscapeFuncs.status = nsTable->status;
455 gNetscapeFuncs.uagent = nsTable->uagent;
456 gNetscapeFuncs.memalloc = nsTable->memalloc;
457 gNetscapeFuncs.memfree = nsTable->memfree;
458 gNetscapeFuncs.memflush = nsTable->memflush;
459 gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
460 #ifdef OJI
461 gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
462 gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
463 #endif
464 gNetscapeFuncs.getvalue = nsTable->getvalue;
467 * Set up the plugin function table that Netscape will use to
468 * call us. Netscape needs to know about our version and size
469 * and have a UniversalProcPointer for every function we
470 * implement.
472 pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
473 pluginFuncs->size = sizeof(NPPluginFuncs);
474 pluginFuncs->newp = NewNPP_NewProc(Private_New);
475 pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
476 pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
477 pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
478 pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
479 pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
480 pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
481 pluginFuncs->write = NewNPP_WriteProc(Private_Write);
482 pluginFuncs->print = NewNPP_PrintProc(Private_Print);
483 pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
484 pluginFuncs->event = NULL;
485 #ifdef OJI
486 pluginFuncs->javaClass = Private_GetJavaClass();
487 #endif
489 err = NPP_Initialize();
492 return err;
496 * NP_Shutdown [optional]
497 * - Netscape needs to know about this symbol.
498 * - It calls this function after looking up its symbol after
499 * the last object of this kind has been destroyed.
502 SAL_DLLPUBLIC_EXPORT void
503 NP_Shutdown(void)
505 PLUGINDEBUGSTR("NP_Shutdown");
506 NPP_Shutdown();