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
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.
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 ***** */
43 * Netscape Client Plugin API
44 * - Wrapper function to interface with the Netscape Navigator
46 * dp Suresh <dp@netscape.com>
48 *----------------------------------------------------------------------
50 * YOU WILL NOT NEED TO EDIT THIS FILE.
51 *----------------------------------------------------------------------
58 #include "npfunctions.h"
61 * Define PLUGIN_TRACE to have the wrapper functions print
62 * messages to stderr whenever they are called.
67 #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
69 #define PLUGINDEBUGSTR(msg)
73 /***********************************************************************
77 ***********************************************************************/
79 static NPNetscapeFuncs gNetscapeFuncs
; /* Netscape Function table */
82 /***********************************************************************
84 * Wrapper functions : plugin calling Netscape Navigator
86 * These functions let the plugin developer just call the APIs
87 * as documented and defined in npapi.h.
89 ***********************************************************************/
92 NPN_Version(int* plugin_major
, int* plugin_minor
,
93 int* netscape_major
, int* netscape_minor
)
95 *plugin_major
= NP_VERSION_MAJOR
;
96 *plugin_minor
= NP_VERSION_MINOR
;
98 /* Major version is in high byte */
99 *netscape_major
= gNetscapeFuncs
.version
>> 8;
100 /* Minor version is in low byte */
101 *netscape_minor
= gNetscapeFuncs
.version
& 0xFF;
105 NPN_GetValue(NPP instance
, NPNVariable variable
, void *r_value
)
107 return (*gNetscapeFuncs
.getvalue
)(instance
, variable
, r_value
);
111 NPN_SetValue(NPP instance
, NPPVariable variable
, void *value
)
113 return (*gNetscapeFuncs
.setvalue
)(instance
, variable
, value
);
117 NPN_GetURL(NPP instance
, const char* url
, const char* window
)
119 return (*gNetscapeFuncs
.geturl
)(instance
, url
, window
);
123 NPN_GetURLNotify(NPP instance
, const char* url
, const char* window
, void* notifyData
)
125 return (*gNetscapeFuncs
.geturlnotify
)(instance
, url
, window
, notifyData
);
129 NPN_PostURL(NPP instance
, const char* url
, const char* window
,
130 uint32_t len
, const char* buf
, NPBool file
)
132 return (*gNetscapeFuncs
.posturl
)(instance
, url
, window
, len
, buf
, file
);
136 NPN_PostURLNotify(NPP instance
, const char* url
, const char* window
, uint32_t len
,
137 const char* buf
, NPBool file
, void* notifyData
)
139 return (*gNetscapeFuncs
.posturlnotify
)(instance
, url
, window
, len
, buf
, file
, notifyData
);
143 NPN_RequestRead(NPStream
* stream
, NPByteRange
* rangeList
)
145 return (*gNetscapeFuncs
.requestread
)(stream
, rangeList
);
149 NPN_NewStream(NPP instance
, NPMIMEType type
, const char *window
,
150 NPStream
** stream_ptr
)
152 return (*gNetscapeFuncs
.newstream
)(instance
, type
, window
, stream_ptr
);
156 NPN_Write(NPP instance
, NPStream
* stream
, int32_t len
, void* buffer
)
158 return (*gNetscapeFuncs
.write
)(instance
, stream
, len
, buffer
);
162 NPN_DestroyStream(NPP instance
, NPStream
* stream
, NPError reason
)
164 return (*gNetscapeFuncs
.destroystream
)(instance
, stream
, reason
);
168 NPN_Status(NPP instance
, const char* message
)
170 (*gNetscapeFuncs
.status
)(instance
, message
);
174 NPN_UserAgent(NPP instance
)
176 return (*gNetscapeFuncs
.uagent
)(instance
);
180 NPN_MemAlloc(uint32_t size
)
182 return (*gNetscapeFuncs
.memalloc
)(size
);
185 void NPN_MemFree(void* ptr
)
187 (*gNetscapeFuncs
.memfree
)(ptr
);
190 uint32_t NPN_MemFlush(uint32_t size
)
192 return (*gNetscapeFuncs
.memflush
)(size
);
195 void NPN_ReloadPlugins(NPBool reloadPages
)
197 (*gNetscapeFuncs
.reloadplugins
)(reloadPages
);
201 NPN_InvalidateRect(NPP instance
, NPRect
*invalidRect
)
203 (*gNetscapeFuncs
.invalidaterect
)(instance
, invalidRect
);
207 NPN_InvalidateRegion(NPP instance
, NPRegion invalidRegion
)
209 (*gNetscapeFuncs
.invalidateregion
)(instance
, invalidRegion
);
213 NPN_ForceRedraw(NPP instance
)
215 (*gNetscapeFuncs
.forceredraw
)(instance
);
218 void NPN_PushPopupsEnabledState(NPP instance
, NPBool enabled
)
220 (*gNetscapeFuncs
.pushpopupsenabledstate
)(instance
, enabled
);
223 void NPN_PopPopupsEnabledState(NPP instance
)
225 (*gNetscapeFuncs
.poppopupsenabledstate
)(instance
);
230 /***********************************************************************
232 * Wrapper functions : Netscape Navigator -> plugin
234 * These functions let the plugin developer just create the APIs
235 * as documented and defined in npapi.h, without needing to
236 * install those functions in the function table or worry about
237 * setting up globals for 68K plugins.
239 ***********************************************************************/
242 Private_New(NPMIMEType pluginType
, NPP instance
, uint16_t mode
,
243 int16_t argc
, char* argn
[], char* argv
[], NPSavedData
* saved
)
246 PLUGINDEBUGSTR("New");
247 ret
= NPP_New(pluginType
, instance
, mode
, argc
, argn
, argv
, saved
);
252 Private_Destroy(NPP instance
, NPSavedData
** save
)
254 PLUGINDEBUGSTR("Destroy");
255 return NPP_Destroy(instance
, save
);
259 Private_SetWindow(NPP instance
, NPWindow
* window
)
262 PLUGINDEBUGSTR("SetWindow");
263 err
= NPP_SetWindow(instance
, window
);
268 Private_NewStream(NPP instance
, NPMIMEType type
, NPStream
* stream
,
269 NPBool seekable
, uint16_t* stype
)
272 PLUGINDEBUGSTR("NewStream");
273 err
= NPP_NewStream(instance
, type
, stream
, seekable
, stype
);
278 Private_WriteReady(NPP instance
, NPStream
* stream
)
281 PLUGINDEBUGSTR("WriteReady");
282 result
= NPP_WriteReady(instance
, stream
);
287 Private_Write(NPP instance
, NPStream
* stream
, int32_t offset
, int32_t len
,
291 PLUGINDEBUGSTR("Write");
292 result
= NPP_Write(instance
, stream
, offset
, len
, buffer
);
297 Private_StreamAsFile(NPP instance
, NPStream
* stream
, const char* fname
)
299 PLUGINDEBUGSTR("StreamAsFile");
300 NPP_StreamAsFile(instance
, stream
, fname
);
305 Private_DestroyStream(NPP instance
, NPStream
* stream
, NPError reason
)
308 PLUGINDEBUGSTR("DestroyStream");
309 err
= NPP_DestroyStream(instance
, stream
, reason
);
314 Private_URLNotify(NPP instance
, const char* url
,
315 NPReason reason
, void* notifyData
)
318 PLUGINDEBUGSTR("URLNotify");
319 NPP_URLNotify(instance
, url
, reason
, notifyData
);
325 Private_Print(NPP instance
, NPPrint
* platformPrint
)
327 PLUGINDEBUGSTR("Print");
328 NPP_Print(instance
, platformPrint
);
331 /***********************************************************************
333 * These functions are located automagically by netscape.
335 ***********************************************************************/
338 * NP_GetPluginVersion [optional]
339 * - The browser uses the return value to indicate to the user what version of
340 * this plugin is installed.
343 NP_GetPluginVersion(void)
349 * NP_GetMIMEDescription
350 * - Netscape needs to know about this symbol
351 * - Netscape uses the return value to identify when an object instance
352 * of this plugin should be created.
355 NP_GetMIMEDescription(void)
357 return NPP_GetMIMEDescription();
361 * NP_GetValue [optional]
362 * - Netscape needs to know about this symbol.
363 * - Interfaces with plugin to get values for predefined variables
364 * that the navigator needs.
367 NP_GetValue(void* future
, NPPVariable variable
, void *value
)
369 return NPP_GetValue(future
, variable
, value
);
374 * - Netscape needs to know about this symbol.
375 * - It calls this function after looking up its symbol before it
376 * is about to create the first ever object of this kind.
379 * nsTable - The netscape function table. If developers just use these
380 * wrappers, they don't need to worry about all these function
384 * - This functions needs to fill the plugin function table
385 * pluginFuncs and return it. Netscape Navigator plugin
386 * library will use this function table to call the plugin.
390 NP_Initialize(NPNetscapeFuncs
* nsTable
, NPPluginFuncs
* pluginFuncs
)
392 NPError err
= NPERR_NO_ERROR
;
394 PLUGINDEBUGSTR("NP_Initialize");
396 /* validate input parameters */
398 if ((nsTable
== NULL
) || (pluginFuncs
== NULL
))
399 err
= NPERR_INVALID_FUNCTABLE_ERROR
;
402 * Check the major version passed in Netscape's function table.
403 * We won't load if the major version is newer than what we expect.
404 * Also check that the function tables passed in are big enough for
405 * all the functions we need (they could be bigger, if Netscape added
406 * new APIs, but that's OK with us -- we'll just ignore them).
410 if (err
== NPERR_NO_ERROR
) {
411 if ((nsTable
->version
>> 8) > NP_VERSION_MAJOR
)
412 err
= NPERR_INCOMPATIBLE_VERSION_ERROR
;
413 if (nsTable
->size
< sizeof(NPNetscapeFuncs
))
414 err
= NPERR_INVALID_FUNCTABLE_ERROR
;
415 if (pluginFuncs
->size
< sizeof(NPPluginFuncs
))
416 err
= NPERR_INVALID_FUNCTABLE_ERROR
;
420 if (err
== NPERR_NO_ERROR
) {
422 * Copy all the fields of Netscape function table into our
423 * copy so we can call back into Netscape later. Note that
424 * we need to copy the fields one by one, rather than assigning
425 * the whole structure, because the Netscape function table
426 * could actually be bigger than what we expect.
428 gNetscapeFuncs
.version
= nsTable
->version
;
429 gNetscapeFuncs
.size
= nsTable
->size
;
430 gNetscapeFuncs
.posturl
= nsTable
->posturl
;
431 gNetscapeFuncs
.geturl
= nsTable
->geturl
;
432 gNetscapeFuncs
.geturlnotify
= nsTable
->geturlnotify
;
433 gNetscapeFuncs
.requestread
= nsTable
->requestread
;
434 gNetscapeFuncs
.newstream
= nsTable
->newstream
;
435 gNetscapeFuncs
.write
= nsTable
->write
;
436 gNetscapeFuncs
.destroystream
= nsTable
->destroystream
;
437 gNetscapeFuncs
.status
= nsTable
->status
;
438 gNetscapeFuncs
.uagent
= nsTable
->uagent
;
439 gNetscapeFuncs
.memalloc
= nsTable
->memalloc
;
440 gNetscapeFuncs
.memfree
= nsTable
->memfree
;
441 gNetscapeFuncs
.memflush
= nsTable
->memflush
;
442 gNetscapeFuncs
.reloadplugins
= nsTable
->reloadplugins
;
443 gNetscapeFuncs
.getJavaEnv
= NULL
;
444 gNetscapeFuncs
.getJavaPeer
= NULL
;
445 gNetscapeFuncs
.getvalue
= nsTable
->getvalue
;
446 gNetscapeFuncs
.pushpopupsenabledstate
= nsTable
->pushpopupsenabledstate
;
447 gNetscapeFuncs
.poppopupsenabledstate
= nsTable
->poppopupsenabledstate
;
450 * Set up the plugin function table that Netscape will use to
451 * call us. Netscape needs to know about our version and size
452 * and have a UniversalProcPointer for every function we
455 pluginFuncs
->version
= (NP_VERSION_MAJOR
<< 8) + NP_VERSION_MINOR
;
456 pluginFuncs
->size
= sizeof(NPPluginFuncs
);
457 pluginFuncs
->newp
= (NPP_NewProcPtr
)(Private_New
);
458 pluginFuncs
->destroy
= (NPP_DestroyProcPtr
)(Private_Destroy
);
459 pluginFuncs
->setwindow
= (NPP_SetWindowProcPtr
)(Private_SetWindow
);
460 pluginFuncs
->newstream
= (NPP_NewStreamProcPtr
)(Private_NewStream
);
461 pluginFuncs
->destroystream
= (NPP_DestroyStreamProcPtr
)(Private_DestroyStream
);
462 pluginFuncs
->asfile
= (NPP_StreamAsFileProcPtr
)(Private_StreamAsFile
);
463 pluginFuncs
->writeready
= (NPP_WriteReadyProcPtr
)(Private_WriteReady
);
464 pluginFuncs
->write
= (NPP_WriteProcPtr
)(Private_Write
);
465 pluginFuncs
->print
= (NPP_PrintProcPtr
)(Private_Print
);
466 pluginFuncs
->urlnotify
= (NPP_URLNotifyProcPtr
)(Private_URLNotify
);
467 pluginFuncs
->event
= NULL
;
468 pluginFuncs
->javaClass
= NULL
;
470 err
= NPP_Initialize();
477 * NP_Shutdown [optional]
478 * - Netscape needs to know about this symbol.
479 * - It calls this function after looking up its symbol after
480 * the last object of this kind has been destroyed.
486 PLUGINDEBUGSTR("NP_Shutdown");
488 return NPERR_NO_ERROR
;