~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/xrx/plugin/Main.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: Main.c,v 1.5 2001/02/09 02:05:57 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1996, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
 
17
ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
 
18
SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABIL-
 
19
ITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
21
IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall
 
24
not be used in advertising or otherwise to promote the sale, use or
 
25
other dealings in this Software without prior written authorization from
 
26
The Open Group.
 
27
 
 
28
*/
 
29
/* $XFree86: xc/programs/xrx/plugin/Main.c,v 1.8 2001/12/14 20:02:17 dawes Exp $ */
 
30
 
 
31
/*
 
32
 * RX plug-in module based on the UnixTemplate file provided by Netcape.
 
33
 */
 
34
 
 
35
/* -*- Mode: C; tab-width: 4; -*- */
 
36
/******************************************************************************
 
37
 * Copyright 1996 Netscape Communications. All rights reserved.
 
38
 ******************************************************************************/
 
39
/*
 
40
 * UnixShell.c
 
41
 *
 
42
 * Netscape Client Plugin API
 
43
 * - Function that need to be implemented by plugin developers
 
44
 *
 
45
 * This file defines a "Template" plugin that plugin developers can use
 
46
 * as the basis for a real plugin.  This shell just provides empty
 
47
 * implementations of all functions that the plugin can implement
 
48
 * that will be called by Netscape (the NPP_xxx methods defined in 
 
49
 * npapi.h). 
 
50
 *
 
51
 * dp Suresh <dp@netscape.com>
 
52
 *
 
53
 */
 
54
 
 
55
#include <ctype.h>
 
56
#include <stdlib.h>
 
57
#include "RxPlugin.h"
 
58
#include "X11/StringDefs.h"
 
59
 
 
60
 
 
61
/***********************************************************************
 
62
 * Utility functions to deal with list of arguments
 
63
 ***********************************************************************/
 
64
 
 
65
/* Free list of arguments */
 
66
static void
 
67
FreeArgs(char* argn[], char* argv[], int argc)
 
68
{
 
69
    int i;
 
70
    if (argc != 0) {
 
71
        for (i = 0; i < argc; i++) {
 
72
            NPN_MemFree(argn[i]);
 
73
            NPN_MemFree(argv[i]);
 
74
        }
 
75
        NPN_MemFree(argn);
 
76
        NPN_MemFree(argv);
 
77
    }
 
78
}
 
79
 
 
80
/* Copy list 2 to list 1 */
 
81
static NPError
 
82
CopyArgs(char** argn1[], char** argv1[], int16* argc1,
 
83
         char* argn2[], char* argv2[], int16 argc2)
 
84
{
 
85
    char **argn, **argv;
 
86
    int i;
 
87
 
 
88
    argn = (char **)NPN_MemAlloc(sizeof(char *) * argc2);
 
89
    if (!argn)
 
90
        return NPERR_OUT_OF_MEMORY_ERROR;
 
91
    argv = (char **)NPN_MemAlloc(sizeof(char *) * argc2);
 
92
    if (!argv) {
 
93
        NPN_MemFree(argn);
 
94
        return NPERR_OUT_OF_MEMORY_ERROR;
 
95
    }
 
96
    memset(argn, 0, sizeof(char *) * argc2);
 
97
    memset(argv, 0, sizeof(char *) * argc2);
 
98
    for (i = 0; i < argc2; i++) {
 
99
        char *name, *value;
 
100
        name = (char *)NPN_MemAlloc(strlen(argn2[i]) + 1);
 
101
        if (!name) {
 
102
            FreeArgs(argn, argv, i - 1);
 
103
            return NPERR_OUT_OF_MEMORY_ERROR;
 
104
        }
 
105
        strcpy(name, argn2[i]);
 
106
        value = (char *)NPN_MemAlloc(strlen(argv2[i]) + 1);
 
107
        if (!value) {
 
108
            NPN_MemFree(name);
 
109
            FreeArgs(argn, argv, i - 1);
 
110
            return NPERR_OUT_OF_MEMORY_ERROR;
 
111
        }
 
112
        strcpy(value, argv2[i]);
 
113
        argn[i] = name;
 
114
        argv[i] = value;
 
115
    }
 
116
    *argc1 = argc2;
 
117
    *argn1 = argn;
 
118
    *argv1 = argv;
 
119
 
 
120
    return NPERR_NO_ERROR;
 
121
}
 
122
 
 
123
 
 
124
char*
 
125
NPP_GetMIMEDescription(void)
 
126
{
 
127
    return(PLUGIN_MIME_DESCRIPTION);
 
128
}
 
129
 
 
130
NPError
 
131
NPP_GetValue(void *future, NPPVariable variable, void *value)
 
132
{
 
133
    NPError err = NPERR_NO_ERROR;
 
134
 
 
135
    switch (variable) {
 
136
    case NPPVpluginNameString:
 
137
        *((char **)value) = PLUGIN_NAME;
 
138
        break;
 
139
    case NPPVpluginDescriptionString:
 
140
        *((char **)value) = PLUGIN_DESCRIPTION;
 
141
        break;
 
142
    default:
 
143
        err = NPERR_GENERIC_ERROR;
 
144
    }
 
145
    return err;
 
146
}
 
147
 
 
148
jref
 
149
NPP_GetJavaClass()
 
150
{
 
151
    return NULL;
 
152
}
 
153
 
 
154
NPError 
 
155
NPP_New(NPMIMEType pluginType,
 
156
        NPP instance,
 
157
        uint16 mode,
 
158
        int16 argc,
 
159
        char* argn[],
 
160
        char* argv[],
 
161
        NPSavedData* saved)
 
162
{
 
163
    PluginInstance* This;
 
164
 
 
165
    if (instance == NULL)
 
166
        return NPERR_INVALID_INSTANCE_ERROR;
 
167
 
 
168
    instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
 
169
        
 
170
    This = (PluginInstance*) instance->pdata;
 
171
 
 
172
    if (This == NULL)
 
173
        return NPERR_OUT_OF_MEMORY_ERROR;
 
174
 
 
175
    This->instance = instance;
 
176
    if (argc != 0) {            /* copy the arguments list */
 
177
        if (CopyArgs(&This->argn, &This->argv, &This->argc,
 
178
                     argn, argv, argc) == NPERR_OUT_OF_MEMORY_ERROR) {
 
179
            NPN_MemFree(This);
 
180
            return NPERR_OUT_OF_MEMORY_ERROR;
 
181
        }
 
182
    } else {
 
183
        This->argc = 0;
 
184
        This->argn = This->argv = NULL;
 
185
    }
 
186
    This->parse_reply = 0;
 
187
    This->status = 0;
 
188
    This->dont_reparent = RxUndef;
 
189
    This->state = LOADING;
 
190
    This->status_widget = NULL;
 
191
    This->plugin_widget = NULL;
 
192
    RxpNew(This);
 
193
 
 
194
    return NPERR_NO_ERROR;
 
195
}
 
196
 
 
197
 
 
198
NPError 
 
199
NPP_Destroy(NPP instance, NPSavedData** save)
 
200
{
 
201
    PluginInstance* This;
 
202
 
 
203
    if (instance == NULL)
 
204
        return NPERR_INVALID_INSTANCE_ERROR;
 
205
 
 
206
    This = (PluginInstance*) instance->pdata;
 
207
 
 
208
    /* PLUGIN DEVELOPERS:
 
209
     *  If desired, call NP_MemAlloc to create a
 
210
     *  NPSavedDate structure containing any state information
 
211
     *  that you want restored if this plugin instance is later
 
212
     *  recreated.
 
213
     */
 
214
 
 
215
    if (This != NULL) {
 
216
        RxpDestroy(This);
 
217
        if (This->argc != 0)
 
218
            FreeArgs(This->argn, This->argv, This->argc);
 
219
        if (This->query != NULL)
 
220
            NPN_MemFree(This->query);
 
221
        NPN_MemFree(instance->pdata);
 
222
        instance->pdata = NULL;
 
223
    }
 
224
 
 
225
    return NPERR_NO_ERROR;
 
226
}
 
227
 
 
228
 
 
229
/* private buffer structure */
 
230
typedef struct {
 
231
    char *buf;
 
232
    uint32 size;
 
233
} RxStreamBuf;
 
234
 
 
235
NPError 
 
236
NPP_NewStream(NPP instance,
 
237
              NPMIMEType type,
 
238
              NPStream *stream, 
 
239
              NPBool seekable,
 
240
              uint16 *stype)
 
241
{
 
242
    PluginInstance* This;
 
243
    RxStreamBuf *streambuf;
 
244
 
 
245
    if (instance == NULL)
 
246
        return NPERR_INVALID_INSTANCE_ERROR;
 
247
 
 
248
    This = (PluginInstance*) instance->pdata;
 
249
 
 
250
    if (This->parse_reply != 0)
 
251
        return NPERR_NO_ERROR;
 
252
 
 
253
    /* malloc structure to store RX document */
 
254
    streambuf = (RxStreamBuf *) NPN_MemAlloc(sizeof(RxStreamBuf));
 
255
    if (streambuf == NULL)
 
256
        return NPERR_OUT_OF_MEMORY_ERROR;
 
257
 
 
258
    streambuf->buf = NULL;
 
259
    streambuf->size = 0;
 
260
    stream->pdata = (void *) streambuf;
 
261
 
 
262
    return NPERR_NO_ERROR;
 
263
}
 
264
 
 
265
 
 
266
/* PLUGIN DEVELOPERS:
 
267
 *      These next 2 functions are directly relevant in a plug-in which
 
268
 *      handles the data in a streaming manner. If you want zero bytes
 
269
 *      because no buffer space is YET available, return 0. As long as
 
270
 *      the stream has not been written to the plugin, Navigator will
 
271
 *      continue trying to send bytes.  If the plugin doesn't want them,
 
272
 *      just return some large number from NPP_WriteReady(), and
 
273
 *      ignore them in NPP_Write().  For a NP_ASFILE stream, they are
 
274
 *      still called but can safely be ignored using this strategy.
 
275
 */
 
276
 
 
277
int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
 
278
                                   * mode so we can take any size stream in our
 
279
                                   * write call (since we ignore it) */
 
280
 
 
281
int32 
 
282
NPP_WriteReady(NPP instance, NPStream *stream)
 
283
{
 
284
    PluginInstance* This;
 
285
    if (instance != NULL)
 
286
        This = (PluginInstance*) instance->pdata;
 
287
 
 
288
    return STREAMBUFSIZE;
 
289
}
 
290
 
 
291
int32 
 
292
NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buf)
 
293
{
 
294
    PluginInstance* This;
 
295
 
 
296
    if (instance == NULL)
 
297
        return len;
 
298
 
 
299
    This = (PluginInstance*) instance->pdata;
 
300
 
 
301
    if (This->parse_reply == 0) {
 
302
        /* copy stream buffer to private storage, concatenating if necessary:
 
303
         * since Netscape doesn't provide an NPN_MemRealloc we must do
 
304
         * a new malloc, copy, and free :-(
 
305
         */
 
306
        RxStreamBuf *streambuf = (RxStreamBuf *) stream->pdata;
 
307
        uint32 size = streambuf->size;
 
308
        char *cbuf;
 
309
 
 
310
        /* if first chunk add 1 for null terminating character */
 
311
        if (size == 0)
 
312
            size++;
 
313
 
 
314
        size += len;
 
315
        cbuf = (char *) NPN_MemAlloc(size);
 
316
        if (cbuf == NULL)
 
317
            return -1;
 
318
        if (streambuf->size != 0) {
 
319
            memcpy(cbuf, streambuf->buf, streambuf->size - 1);
 
320
            memcpy(cbuf + streambuf->size - 1, ((char *)buf), len);
 
321
            /* free old storage */
 
322
            NPN_MemFree((void *) streambuf->buf);
 
323
        } else
 
324
            memcpy(cbuf, ((char *)buf), len);
 
325
        cbuf[size - 1] = '\0';
 
326
        /* store new buffer */
 
327
        streambuf->buf = cbuf;
 
328
        streambuf->size = size;
 
329
#ifdef PLUGIN_TRACE
 
330
        fprintf(stderr, "write %s:\n", PLUGIN_NAME);
 
331
        fwrite(buf, len, 1, stderr);
 
332
        fprintf(stderr, "\n");
 
333
#endif
 
334
    } else {
 
335
        int l = len;
 
336
        if (This->parse_reply == 1) {
 
337
            /* look for status line */
 
338
            char *ptr = strchr(buf, '\n');
 
339
            if (ptr != NULL && isdigit(((char *)buf)[0])) {
 
340
                This->status = (short) atoi((char *)buf);
 
341
                /* skip status line */
 
342
                l -= ptr - (char *)buf + 1;
 
343
                buf = ptr + 1;
 
344
                if (This->status != 0) {
 
345
                    fprintf(stderr,
 
346
                            "%s: Application failed to start properly\n",
 
347
                            PLUGIN_NAME);
 
348
                }
 
349
            }
 
350
            This->parse_reply = 2;
 
351
        }
 
352
        /* simply prints out whatever we get, and let netscape display it
 
353
           in a dialog */
 
354
        fwrite(buf, l, 1, stderr);
 
355
    }
 
356
 
 
357
    return len;                 /* The number of bytes accepted */
 
358
}
 
359
 
 
360
void
 
361
StartApplication(PluginInstance* This)
 
362
{
 
363
    NPError err;
 
364
 
 
365
#ifndef NO_STARTING_STATE
 
366
    RxpSetStatusWidget(This, STARTING);
 
367
#else
 
368
    RxpSetStatusWidget(This, RUNNING);
 
369
#endif
 
370
 
 
371
    /* perform GET request
 
372
     * throwing away the response.
 
373
     */
 
374
    err = NPN_GetURL(This->instance, This->query, NULL);
 
375
    This->parse_reply = 1;      /* we want to print out the answer  */
 
376
}
 
377
 
 
378
void
 
379
StartCB(Widget widget, XtPointer client_data, XtPointer call_data)
 
380
{
 
381
    PluginInstance* This = (PluginInstance*) client_data;
 
382
#if 0
 
383
    XtUnmapWidget(widget);
 
384
#endif
 
385
    XtDestroyWidget(widget);
 
386
    StartApplication(This);
 
387
}
 
388
 
 
389
#if defined(linux) || (defined(sun) && !defined(SVR4))
 
390
/* deficient linux linker semantics  */
 
391
static WidgetClass xmLabelGadgetClass;
 
392
static WidgetClass xmPushButtonGadgetClass;
 
393
#else
 
394
extern WidgetClass xmLabelGadgetClass;
 
395
extern WidgetClass xmPushButtonGadgetClass;
 
396
#endif
 
397
 
 
398
void
 
399
RxpSetStatusWidget(PluginInstance* This, PluginState state)
 
400
{
 
401
    Arg args[5];
 
402
    int n;
 
403
    XrmDatabase db;
 
404
    char* return_type;
 
405
    XrmValue return_value;
 
406
 
 
407
    if (This->status_widget) {
 
408
        XtDestroyWidget(This->status_widget);
 
409
        This->status_widget = NULL;
 
410
    }
 
411
    if (This->plugin_widget == NULL)
 
412
        return;
 
413
 
 
414
    db = XtDatabase (XtDisplay (This->plugin_widget));
 
415
 
 
416
    if (!XrmGetResource (db, "RxPlugin_BeenHere", "RxPlugin_BeenHere",
 
417
                    &return_type, &return_value)) {
 
418
 
 
419
        XrmPutStringResource (&db, "*Rx_Loading.labelString", "Loading...");
 
420
        XrmPutStringResource (&db, "*Rx_Starting.labelString", "Starting...");
 
421
        XrmPutStringResource (&db, "*Rx_Start.labelString", "Start");
 
422
        XrmPutStringResource (&db, "RxPlugin_BeenHere", "YES");
 
423
    }
 
424
#if defined(linux) || (defined(sun) && !defined(SVR4))
 
425
    /*
 
426
        lame loader semantics mean we have to go fishing around to
 
427
        come up with widget class records so we can create some widgets.
 
428
 
 
429
        Names of widgets changed in 4.x, so look for those names too
 
430
        for linux.
 
431
 
 
432
        If Microsoft ever does IE for Linux we'll have to figure out
 
433
        those names too.
 
434
    */
 
435
    if (xmLabelGadgetClass == NULL) {
 
436
        Widget w;
 
437
 
 
438
        w = XtNameToWidget (This->toplevel_widget, "*topLeftArea.urlLabel");
 
439
        if (w == NULL)
 
440
            w = XtNameToWidget (This->toplevel_widget, "*urlBar.urlLocationLabel");
 
441
        xmLabelGadgetClass = XtClass (w);
 
442
        w = XtNameToWidget (This->toplevel_widget, "*toolBar.abort");
 
443
        if (w == NULL)
 
444
            w = XtNameToWidget (This->toplevel_widget, "*PopupMenu.openCustomUrl");
 
445
        xmPushButtonGadgetClass = XtClass (w);
 
446
    }
 
447
#endif
 
448
 
 
449
    n = 0;
 
450
    XtSetArg(args[n], "shadowThickness", 1); n++;
 
451
    XtSetArg(args[n], XtNwidth, This->width); n++;
 
452
    XtSetArg(args[n], XtNheight, This->height); n++;
 
453
    if (state == LOADING) {
 
454
        /* create a label */
 
455
        This->status_widget =
 
456
            XtCreateManagedWidget("Rx_Loading", xmLabelGadgetClass,
 
457
                This->plugin_widget, args, n);
 
458
#ifndef NO_STARTING_STATE
 
459
    } else if (state == STARTING) {
 
460
        /* create a label */
 
461
        This->status_widget =
 
462
            XtCreateManagedWidget("Rx_Starting", xmLabelGadgetClass,
 
463
                This->plugin_widget, args, n);
 
464
#endif
 
465
    } else if (state == WAITING) {
 
466
        /* create a push button */
 
467
        This->status_widget =
 
468
            XtCreateManagedWidget("Rx_Start", xmPushButtonGadgetClass,
 
469
                This->plugin_widget, args, n);
 
470
        XtAddCallback(This->status_widget, "activateCallback", StartCB, This);
 
471
    } else if (state == RUNNING) {
 
472
        /* nothing else to be done */
 
473
    }
 
474
    This->state = state;
 
475
}
 
476
 
 
477
 
 
478
NPError 
 
479
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
 
480
{
 
481
    PluginInstance* This;
 
482
    RxStreamBuf *streambuf = (RxStreamBuf *) stream->pdata;
 
483
    char **rx_argn, **rx_argv;
 
484
    int rx_argc;
 
485
    RxParams params;
 
486
    RxReturnParams return_params;
 
487
    NPError status = NPERR_NO_ERROR;
 
488
 
 
489
    if (instance == NULL)
 
490
        return NPERR_INVALID_INSTANCE_ERROR;
 
491
 
 
492
    This = (PluginInstance*) instance->pdata;
 
493
 
 
494
    if (This->parse_reply != 0) {
 
495
        fflush(stderr);
 
496
        if (This->status != 0)  /* if error occured change widget status */
 
497
            RxpSetStatusWidget(This, WAITING);
 
498
        return NPRES_DONE;
 
499
    }
 
500
 
 
501
    memset(&params, 0, sizeof(RxParams));
 
502
    memset(&return_params, 0, sizeof(RxReturnParams));
 
503
    rx_argc = 0;
 
504
 
 
505
    if (reason != NPRES_DONE) {
 
506
        status = NPERR_GENERIC_ERROR;
 
507
        goto exit;
 
508
    }
 
509
 
 
510
    /* read params from stream */
 
511
    if (RxReadParams(streambuf->buf, &rx_argn, &rx_argv, &rx_argc) != 0) {
 
512
        fprintf(stderr, "%s: invalid file %s\n", PLUGIN_NAME, stream->url);
 
513
        status = NPERR_GENERIC_ERROR;
 
514
        goto exit;
 
515
    }
 
516
 
 
517
    RxInitializeParams(&params);
 
518
 
 
519
    /* parse RX params */
 
520
    if (RxParseParams(rx_argn, rx_argv, rx_argc, &params, 0) != 0) {
 
521
        fprintf(stderr, "%s: invalid RX params\n", PLUGIN_NAME);
 
522
        status = NPERR_GENERIC_ERROR;
 
523
        goto exit;
 
524
    }
 
525
 
 
526
    /* parse HTML params */
 
527
    if (RxParseParams(This->argn, This->argv, This->argc, &params, 0) != 0) {
 
528
        fprintf(stderr, "%s: invalid HTML params\n", PLUGIN_NAME);
 
529
        status = NPERR_GENERIC_ERROR;
 
530
        goto exit;
 
531
    }
 
532
 
 
533
    /* set up return parameters */
 
534
    if (RxpProcessParams(This, &params, &return_params) != 0) {
 
535
        fprintf(stderr, "%s: failed to process params\n", PLUGIN_NAME);
 
536
        status = NPERR_GENERIC_ERROR;
 
537
        goto exit;
 
538
    }
 
539
 
 
540
    /* make query */
 
541
    This->query = RxBuildRequest(&return_params);
 
542
    if (This->query == NULL) {
 
543
        fprintf(stderr, "%s: failed to make query\n", PLUGIN_NAME);
 
544
        status = NPERR_GENERIC_ERROR;
 
545
        goto exit;
 
546
    }
 
547
 
 
548
    if (params.auto_start != RxFalse) /* default is auto start */
 
549
        StartApplication(This);
 
550
    else
 
551
        RxpSetStatusWidget(This, WAITING);
 
552
 
 
553
exit:
 
554
    /* free all forms of params */
 
555
    FreeArgs(rx_argn, rx_argv, rx_argc);
 
556
    FreeArgs(This->argn, This->argv, This->argc);
 
557
    This->argc = 0;
 
558
    RxFreeParams(&params);
 
559
    RxFreeReturnParams(&return_params);
 
560
    /* free private storage */
 
561
    if (streambuf->buf != NULL)
 
562
        NPN_MemFree(streambuf->buf);
 
563
    NPN_MemFree(stream->pdata);
 
564
 
 
565
    return status;
 
566
}
 
567
 
 
568
void 
 
569
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
 
570
{
 
571
    /*
 
572
    PluginInstance* This;
 
573
    if (instance != NULL)
 
574
        This = (PluginInstance*) instance->pdata;
 
575
     */
 
576
}
 
577
 
 
578
 
 
579
void 
 
580
NPP_Print(NPP instance, NPPrint* printInfo)
 
581
{
 
582
    if(printInfo == NULL)
 
583
        return;
 
584
 
 
585
    if (instance != NULL) {
 
586
#if 0
 
587
        PluginInstance* This = (PluginInstance*) instance->pdata;
 
588
#endif
 
589
        
 
590
        if (printInfo->mode == NP_FULL) {
 
591
            /*
 
592
             * PLUGIN DEVELOPERS:
 
593
             *  If your plugin would like to take over
 
594
             *  printing completely when it is in full-screen mode,
 
595
             *  set printInfo->pluginPrinted to TRUE and print your
 
596
             *  plugin as you see fit.  If your plugin wants Netscape
 
597
             *  to handle printing in this case, set
 
598
             *  printInfo->pluginPrinted to FALSE (the default) and
 
599
             *  do nothing.  If you do want to handle printing
 
600
             *  yourself, printOne is true if the print button
 
601
             *  (as opposed to the print menu) was clicked.
 
602
             *  On the Macintosh, platformPrint is a THPrint; on
 
603
             *  Windows, platformPrint is a structure
 
604
             *  (defined in npapi.h) containing the printer name, port,
 
605
             *  etc.
 
606
             */
 
607
 
 
608
            /*
 
609
            void* platformPrint =
 
610
                printInfo->print.fullPrint.platformPrint;
 
611
            NPBool printOne =
 
612
                printInfo->print.fullPrint.printOne;
 
613
             */
 
614
                        
 
615
            /* Do the default*/
 
616
            printInfo->print.fullPrint.pluginPrinted = FALSE;
 
617
        }
 
618
#if 0
 
619
        else {  /* If not fullscreen, we must be embedded */
 
620
            /*
 
621
             * PLUGIN DEVELOPERS:
 
622
             *  If your plugin is embedded, or is full-screen
 
623
             *  but you returned false in pluginPrinted above, NPP_Print
 
624
             *  will be called with mode == NP_EMBED.  The NPWindow
 
625
             *  in the printInfo gives the location and dimensions of
 
626
             *  the embedded plugin on the printed page.  On the
 
627
             *  Macintosh, platformPrint is the printer port; on
 
628
             *  Windows, platformPrint is the handle to the printing
 
629
             *  device context.
 
630
             */
 
631
 
 
632
            NPWindow* printWindow =
 
633
                &(printInfo->print.embedPrint.window);
 
634
            void* platformPrint =
 
635
                printInfo->print.embedPrint.platformPrint;
 
636
        }
 
637
#endif
 
638
    }
 
639
}