1
/* -*- Mode: C; tab-width: 4; -*- */
2
/******************************************************************************
3
* Copyright (c) 1996 Netscape Communications. All rights reserved.
4
******************************************************************************/
8
* Netscape Client Plugin API
9
* - Function that need to be implemented by plugin developers
11
* This file defines a "Template" plugin that plugin developers can use
12
* as the basis for a real plugin. This shell just provides empty
13
* implementations of all functions that the plugin can implement
14
* that will be called by Netscape (the NPP_xxx methods defined in
17
* dp Suresh <dp@netscape.com>
26
#include "netscape_plugin_Plugin.h"
28
#include "java_lang_Class.h"
29
#include "java_lang_String.h"
33
* Define PLUGIN_TRACE to have the wrapper functions print
34
* messages to stderr whenever they are called.
39
#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
41
#define PLUGINDEBUGSTR(msg)
44
/***********************************************************************
45
* Instance state information about the plugin.
48
* Use this struct to hold per-instance information that you'll
49
* need in the various functions in this file.
50
***********************************************************************/
52
typedef struct _PluginInstance
58
/***********************************************************************
60
* Empty implementations of plugin API functions
63
* You will need to implement these functions as required by your
66
***********************************************************************/
69
NPP_GetMIMEDescription(void)
71
return("application/x-netrek:netrek:COW Netrek client");
75
NPP_GetValue(void *future, NPPVariable variable, void *value)
77
NPError err = NPERR_NO_ERROR;
80
case NPPVpluginNameString:
81
*((char **)value) = "COW Netrek plugin";
83
case NPPVpluginDescriptionString:
85
"Plugin version of COW netrek client.";
88
err = NPERR_GENERIC_ERROR;
96
PLUGINDEBUGSTR("COW-NPP_Initialize called");
97
return NPERR_NO_ERROR;
101
** We'll keep a global execution environment around to make our life
111
struct java_lang_Class* myClass;
112
PLUGINDEBUGSTR("COW-NPP_GetJavaClass entered");
113
env = NPN_GetJavaEnv();
115
return NULL; /* Java disabled */
116
/* register_COW(env); */
117
myClass = use_COW(env);
119
/* others that we're using: */
120
use_netscape_plugin_Plugin(env);
122
use_java_lang_Class(env);
123
use_java_lang_String(env);
126
if (myClass == NULL) {
128
** If our class doesn't exist (the user hasn't installed it) then
129
** don't allow any of the Java stuff to happen.
133
PLUGINDEBUGSTR("COW-NPP_GetJavaClass exited");
143
/* unregister_COW(env); */
146
unuse_netscape_plugin_Plugin(env);
148
unuse_java_lang_Class(env);
149
unuse_java_lang_String(env);
156
NPP_New(NPMIMEType pluginType,
164
PluginInstance* This;
166
if (instance == NULL)
167
return NPERR_INVALID_INSTANCE_ERROR;
169
instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
171
This = (PluginInstance*) instance->pdata;
174
return NPERR_NO_ERROR;
176
return NPERR_OUT_OF_MEMORY_ERROR;
181
NPP_Destroy(NPP instance, NPSavedData** save)
183
PluginInstance* This;
185
if (instance == NULL)
186
return NPERR_INVALID_INSTANCE_ERROR;
188
This = (PluginInstance*) instance->pdata;
190
/* PLUGIN DEVELOPERS:
191
* If desired, call NP_MemAlloc to create a
192
* NPSavedDate structure containing any state information
193
* that you want restored if this plugin instance is later
198
NPN_MemFree(instance->pdata);
199
instance->pdata = NULL;
202
return NPERR_NO_ERROR;
208
NPP_SetWindow(NPP instance, NPWindow* window)
210
PluginInstance* This;
212
if (instance == NULL)
213
return NPERR_INVALID_INSTANCE_ERROR;
216
return NPERR_NO_ERROR;
218
This = (PluginInstance*) instance->pdata;
222
* Before setting window to point to the
223
* new window, you may wish to compare the new window
224
* info to the previous window (if any) to note window
228
return NPERR_NO_ERROR;
233
NPP_NewStream(NPP instance,
240
PluginInstance* This;
242
if (instance == NULL)
243
return NPERR_INVALID_INSTANCE_ERROR;
245
This = (PluginInstance*) instance->pdata;
247
return NPERR_NO_ERROR;
251
/* PLUGIN DEVELOPERS:
252
* These next 2 functions are directly relevant in a plug-in which
253
* handles the data in a streaming manner. If you want zero bytes
254
* because no buffer space is YET available, return 0. As long as
255
* the stream has not been written to the plugin, Navigator will
256
* continue trying to send bytes. If the plugin doesn't want them,
257
* just return some large number from NPP_WriteReady(), and
258
* ignore them in NPP_Write(). For a NP_ASFILE stream, they are
259
* still called but can safely be ignored using this strategy.
262
int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
263
* mode so we can take any size stream in our
264
* write call (since we ignore it) */
267
NPP_WriteReady(NPP instance, NPStream *stream)
269
PluginInstance* This;
270
if (instance != NULL)
271
This = (PluginInstance*) instance->pdata;
273
return STREAMBUFSIZE;
278
NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
280
if (instance != NULL)
282
PluginInstance* This = (PluginInstance*) instance->pdata;
285
return len; /* The number of bytes accepted */
290
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
292
PluginInstance* This;
294
if (instance == NULL)
295
return NPERR_INVALID_INSTANCE_ERROR;
296
This = (PluginInstance*) instance->pdata;
298
return NPERR_NO_ERROR;
303
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
305
PluginInstance* This;
306
if (instance != NULL)
307
This = (PluginInstance*) instance->pdata;
312
NPP_Print(NPP instance, NPPrint* printInfo)
314
if(printInfo == NULL)
317
if (instance != NULL) {
318
PluginInstance* This = (PluginInstance*) instance->pdata;
320
if (printInfo->mode == NP_FULL) {
323
* If your plugin would like to take over
324
* printing completely when it is in full-screen mode,
325
* set printInfo->pluginPrinted to TRUE and print your
326
* plugin as you see fit. If your plugin wants Netscape
327
* to handle printing in this case, set
328
* printInfo->pluginPrinted to FALSE (the default) and
329
* do nothing. If you do want to handle printing
330
* yourself, printOne is true if the print button
331
* (as opposed to the print menu) was clicked.
332
* On the Macintosh, platformPrint is a THPrint; on
333
* Windows, platformPrint is a structure
334
* (defined in npapi.h) containing the printer name, port,
338
void* platformPrint =
339
printInfo->print.fullPrint.platformPrint;
341
printInfo->print.fullPrint.printOne;
344
printInfo->print.fullPrint.pluginPrinted = FALSE;
346
else { /* If not fullscreen, we must be embedded */
349
* If your plugin is embedded, or is full-screen
350
* but you returned false in pluginPrinted above, NPP_Print
351
* will be called with mode == NP_EMBED. The NPWindow
352
* in the printInfo gives the location and dimensions of
353
* the embedded plugin on the printed page. On the
354
* Macintosh, platformPrint is the printer port; on
355
* Windows, platformPrint is the handle to the printing
359
NPWindow* printWindow =
360
&(printInfo->print.embedPrint.window);
361
void* platformPrint =
362
printInfo->print.embedPrint.platformPrint;