~netrek-developers/netrek-client-cow/trunk

« back to all changes in this revision

Viewing changes to _darcs/pristine/java/plugin.c

  • Committer: Collin Pruitt
  • Date: 2009-05-12 04:30:09 UTC
  • Revision ID: collinp111@gmail.com-20090512043009-3jsjojoyrk16oass
Initial upload - updated from http://james.tooraweenah.com/darcs/netrek-client-cow/ using darcs (hince the existnace of _darcs), fully patched.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; -*- */
 
2
/******************************************************************************
 
3
 * Copyright (c) 1996 Netscape Communications. All rights reserved.
 
4
 ******************************************************************************/
 
5
/*
 
6
 * UnixShell.c
 
7
 *
 
8
 * Netscape Client Plugin API
 
9
 * - Function that need to be implemented by plugin developers
 
10
 *
 
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 
 
15
 * npapi.h). 
 
16
 *
 
17
 * dp Suresh <dp@netscape.com>
 
18
 *
 
19
 */
 
20
 
 
21
#include <stdio.h>
 
22
#include "npapi.h"
 
23
 
 
24
#define IMPLEMENT_COW
 
25
#include "COW.h"
 
26
#include "netscape_plugin_Plugin.h"
 
27
/*
 
28
#include "java_lang_Class.h"
 
29
#include "java_lang_String.h"
 
30
*/
 
31
 
 
32
/*
 
33
 * Define PLUGIN_TRACE to have the wrapper functions print
 
34
 * messages to stderr whenever they are called.
 
35
 */
 
36
 
 
37
#ifdef PLUGIN_TRACE
 
38
#include <stdio.h>
 
39
#define PLUGINDEBUGSTR(msg)     fprintf(stderr, "%s\n", msg)
 
40
#else
 
41
#define PLUGINDEBUGSTR(msg)
 
42
#endif
 
43
 
 
44
/***********************************************************************
 
45
 * Instance state information about the plugin.
 
46
 *
 
47
 * PLUGIN DEVELOPERS:
 
48
 *      Use this struct to hold per-instance information that you'll
 
49
 *      need in the various functions in this file.
 
50
 ***********************************************************************/
 
51
 
 
52
typedef struct _PluginInstance
 
53
{
 
54
    int nothing;
 
55
} PluginInstance;
 
56
 
 
57
 
 
58
/***********************************************************************
 
59
 *
 
60
 * Empty implementations of plugin API functions
 
61
 *
 
62
 * PLUGIN DEVELOPERS:
 
63
 *      You will need to implement these functions as required by your
 
64
 *      plugin.
 
65
 *
 
66
 ***********************************************************************/
 
67
 
 
68
char*
 
69
NPP_GetMIMEDescription(void)
 
70
{
 
71
        return("application/x-netrek:netrek:COW Netrek client");
 
72
}
 
73
 
 
74
NPError
 
75
NPP_GetValue(void *future, NPPVariable variable, void *value)
 
76
{
 
77
        NPError err = NPERR_NO_ERROR;
 
78
 
 
79
        switch (variable) {
 
80
                case NPPVpluginNameString:
 
81
                        *((char **)value) = "COW Netrek plugin";
 
82
                        break;
 
83
                case NPPVpluginDescriptionString:
 
84
                        *((char **)value) =
 
85
                                "Plugin version of COW netrek client.";
 
86
                        break;
 
87
                default:
 
88
                        err = NPERR_GENERIC_ERROR;
 
89
        }
 
90
        return err;
 
91
}
 
92
 
 
93
NPError
 
94
NPP_Initialize(void)
 
95
{
 
96
  PLUGINDEBUGSTR("COW-NPP_Initialize called");
 
97
  return NPERR_NO_ERROR;
 
98
}
 
99
 
 
100
/*
 
101
** We'll keep a global execution environment around to make our life
 
102
** simpler.
 
103
*/
 
104
static JRIEnv* env;
 
105
 
 
106
 
 
107
jref
 
108
NPP_GetJavaClass()
 
109
{
 
110
 
 
111
  struct java_lang_Class* myClass;
 
112
  PLUGINDEBUGSTR("COW-NPP_GetJavaClass entered");
 
113
  env = NPN_GetJavaEnv();
 
114
  if (env == NULL)
 
115
        return NULL;            /* Java disabled */
 
116
  /* register_COW(env); */
 
117
  myClass = use_COW(env);
 
118
 
 
119
  /* others that we're using: */
 
120
  use_netscape_plugin_Plugin(env);
 
121
/*
 
122
  use_java_lang_Class(env);
 
123
  use_java_lang_String(env);
 
124
*/
 
125
 
 
126
  if (myClass == NULL) {
 
127
        /*
 
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.
 
130
         */
 
131
        env = NULL;
 
132
  }
 
133
  PLUGINDEBUGSTR("COW-NPP_GetJavaClass exited");
 
134
 
 
135
  return myClass;
 
136
}
 
137
 
 
138
void
 
139
NPP_Shutdown(void)
 
140
{
 
141
  if (env)
 
142
        {
 
143
          /* unregister_COW(env); */
 
144
          unuse_COW(env); 
 
145
 
 
146
          unuse_netscape_plugin_Plugin(env);
 
147
/*
 
148
          unuse_java_lang_Class(env);
 
149
          unuse_java_lang_String(env);
 
150
*/
 
151
        }
 
152
}
 
153
 
 
154
 
 
155
NPError 
 
156
NPP_New(NPMIMEType pluginType,
 
157
        NPP instance,
 
158
        uint16 mode,
 
159
        int16 argc,
 
160
        char* argn[],
 
161
        char* argv[],
 
162
        NPSavedData* saved)
 
163
{
 
164
        PluginInstance* This;
 
165
 
 
166
        if (instance == NULL)
 
167
                return NPERR_INVALID_INSTANCE_ERROR;
 
168
                
 
169
        instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
 
170
        
 
171
        This = (PluginInstance*) instance->pdata;
 
172
 
 
173
        if (This != NULL)
 
174
                return NPERR_NO_ERROR;
 
175
        else
 
176
                return NPERR_OUT_OF_MEMORY_ERROR;
 
177
}
 
178
 
 
179
 
 
180
NPError 
 
181
NPP_Destroy(NPP instance, NPSavedData** save)
 
182
{
 
183
        PluginInstance* This;
 
184
 
 
185
        if (instance == NULL)
 
186
                return NPERR_INVALID_INSTANCE_ERROR;
 
187
 
 
188
        This = (PluginInstance*) instance->pdata;
 
189
 
 
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
 
194
         *      recreated.
 
195
         */
 
196
 
 
197
        if (This != NULL) {
 
198
                NPN_MemFree(instance->pdata);
 
199
                instance->pdata = NULL;
 
200
        }
 
201
 
 
202
        return NPERR_NO_ERROR;
 
203
}
 
204
 
 
205
 
 
206
 
 
207
NPError 
 
208
NPP_SetWindow(NPP instance, NPWindow* window)
 
209
{
 
210
        PluginInstance* This;
 
211
 
 
212
        if (instance == NULL)
 
213
                return NPERR_INVALID_INSTANCE_ERROR;
 
214
 
 
215
        if (window == NULL)
 
216
                return NPERR_NO_ERROR;
 
217
 
 
218
        This = (PluginInstance*) instance->pdata;
 
219
 
 
220
        /*
 
221
         * PLUGIN DEVELOPERS:
 
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
 
225
         *      size changes, etc.
 
226
         */
 
227
 
 
228
        return NPERR_NO_ERROR;
 
229
}
 
230
 
 
231
 
 
232
NPError 
 
233
NPP_NewStream(NPP instance,
 
234
                          NPMIMEType type,
 
235
                          NPStream *stream, 
 
236
                          NPBool seekable,
 
237
                          uint16 *stype)
 
238
{
 
239
        NPByteRange range;
 
240
        PluginInstance* This;
 
241
 
 
242
        if (instance == NULL)
 
243
                return NPERR_INVALID_INSTANCE_ERROR;
 
244
 
 
245
        This = (PluginInstance*) instance->pdata;
 
246
 
 
247
        return NPERR_NO_ERROR;
 
248
}
 
249
 
 
250
 
 
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.
 
260
 */
 
261
 
 
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) */
 
265
 
 
266
int32 
 
267
NPP_WriteReady(NPP instance, NPStream *stream)
 
268
{
 
269
        PluginInstance* This;
 
270
        if (instance != NULL)
 
271
                This = (PluginInstance*) instance->pdata;
 
272
 
 
273
        return STREAMBUFSIZE;
 
274
}
 
275
 
 
276
 
 
277
int32 
 
278
NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
 
279
{
 
280
        if (instance != NULL)
 
281
        {
 
282
                PluginInstance* This = (PluginInstance*) instance->pdata;
 
283
        }
 
284
 
 
285
        return len;             /* The number of bytes accepted */
 
286
}
 
287
 
 
288
 
 
289
NPError 
 
290
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
 
291
{
 
292
        PluginInstance* This;
 
293
 
 
294
        if (instance == NULL)
 
295
                return NPERR_INVALID_INSTANCE_ERROR;
 
296
        This = (PluginInstance*) instance->pdata;
 
297
 
 
298
        return NPERR_NO_ERROR;
 
299
}
 
300
 
 
301
 
 
302
void 
 
303
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
 
304
{
 
305
        PluginInstance* This;
 
306
        if (instance != NULL)
 
307
                This = (PluginInstance*) instance->pdata;
 
308
}
 
309
 
 
310
 
 
311
void 
 
312
NPP_Print(NPP instance, NPPrint* printInfo)
 
313
{
 
314
        if(printInfo == NULL)
 
315
                return;
 
316
 
 
317
        if (instance != NULL) {
 
318
                PluginInstance* This = (PluginInstance*) instance->pdata;
 
319
        
 
320
                if (printInfo->mode == NP_FULL) {
 
321
                    /*
 
322
                     * PLUGIN DEVELOPERS:
 
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,
 
335
                     *  etc.
 
336
                     */
 
337
 
 
338
                        void* platformPrint =
 
339
                                printInfo->print.fullPrint.platformPrint;
 
340
                        NPBool printOne =
 
341
                                printInfo->print.fullPrint.printOne;
 
342
                        
 
343
                        /* Do the default*/
 
344
                        printInfo->print.fullPrint.pluginPrinted = FALSE;
 
345
                }
 
346
                else {  /* If not fullscreen, we must be embedded */
 
347
                    /*
 
348
                     * PLUGIN DEVELOPERS:
 
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
 
356
                     *  device context.
 
357
                     */
 
358
 
 
359
                        NPWindow* printWindow =
 
360
                                &(printInfo->print.embedPrint.window);
 
361
                        void* platformPrint =
 
362
                                printInfo->print.embedPrint.platformPrint;
 
363
                }
 
364
        }
 
365
}
 
366