npunix.cpp 32.1 KB
Newer Older
1 2
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
3 4
 * Mozilla/Firefox plugin for VLC
 * Copyright (C) 2009, Jean-Paul Saman <jpsaman@videolan.org>
5
 *
6 7 8 9
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11 12 13 14 15 16 17 18
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
 *
20 21
 * The Original Code is mozilla.org code.
 *
22 23 24 25
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1998
 * the Initial Developer. All Rights Reserved.
26
 *
27
 * Contributor(s):
28 29
 *   Stephen Mak <smak@sun.com>
 *
30
 */
31

32 33 34 35 36 37 38 39 40 41
/*
 * npunix.c
 *
 * Netscape Client Plugin API
 * - Wrapper function to interface with the Netscape Navigator
 *
 * dp Suresh <dp@netscape.com>
 *
 *----------------------------------------------------------------------
 * PLUGIN DEVELOPERS:
42
 *  YOU WILL NOT NEED TO EDIT THIS FILE.
43 44 45
 *----------------------------------------------------------------------
 */

46 47 48
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
49

50 51
#define XP_UNIX 1

52
#include <npapi.h>
53 54
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
#include "npupp.h" 
55
#else
56
#include "npfunctions.h"
57 58 59
#endif

#include "../vlcshell.h"
60 61 62 63 64 65 66 67

/*
 * Define PLUGIN_TRACE to have the wrapper functions print
 * messages to stderr whenever they are called.
 */

#ifdef PLUGIN_TRACE
#include <stdio.h>
68
#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
69 70 71 72 73 74 75 76 77 78
#else
#define PLUGINDEBUGSTR(msg)
#endif

/***********************************************************************
 *
 * Globals
 *
 ***********************************************************************/

79
static NPNetscapeFuncs   gNetscapeFuncs;    /* Netscape Function table */
80 81 82 83 84 85 86 87 88 89 90 91 92

/***********************************************************************
 *
 * Wrapper functions : plugin calling Netscape Navigator
 *
 * These functions let the plugin developer just call the APIs
 * as documented and defined in npapi.h, without needing to know
 * about the function table and call macros in npupp.h.
 *
 ***********************************************************************/

void
NPN_Version(int* plugin_major, int* plugin_minor,
93
         int* netscape_major, int* netscape_minor)
94
{
95 96
    *plugin_major = NP_VERSION_MAJOR;
    *plugin_minor = NP_VERSION_MINOR;
97

98 99 100 101
    /* Major version is in high byte */
    *netscape_major = gNetscapeFuncs.version >> 8;
    /* Minor version is in low byte */
    *netscape_minor = gNetscapeFuncs.version & 0xFF;
102 103
}

104 105 106 107 108 109 110 111 112 113
void
NPN_PluginThreadAsyncCall(NPP plugin,
                          void (*func)(void *),
                          void *userData)
{
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
    return (*gNetscapeFuncs.pluginthreadasynccall)(plugin, func, userData);
#endif
}

114 115 116
NPError
NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
{
117
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
118 119
    return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
                    instance, variable, r_value);
120 121 122
#else
    return (*gNetscapeFuncs.getvalue)(instance, variable, r_value);
#endif
123 124 125 126 127
}

NPError
NPN_SetValue(NPP instance, NPPVariable variable, void *value)
{
128
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
129 130
    return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
                    instance, variable, value);
131 132 133
#else
    return (*gNetscapeFuncs.setvalue)(instance, variable, value);
#endif
134 135 136 137 138
}

NPError
NPN_GetURL(NPP instance, const char* url, const char* window)
{
139
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
140
    return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
141 142 143
#else
    return (*gNetscapeFuncs.geturl)(instance, url, window);
#endif
144 145 146 147 148
}

NPError
NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
{
149
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
150
    return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
151 152 153
#else
    return (*gNetscapeFuncs.geturlnotify)(instance, url, window, notifyData);
#endif
154 155 156 157
}

NPError
NPN_PostURL(NPP instance, const char* url, const char* window,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
158
         uint32_t len, const char* buf, NPBool file)
159
{
160
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
161 162
    return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
                    url, window, len, buf, file);
163 164 165
#else
    return (*gNetscapeFuncs.posturl)(instance, url, window, len, buf, file);
#endif
166 167 168
}

NPError
Jean-Paul Saman's avatar
Jean-Paul Saman committed
169
NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
170
                  const char* buf, NPBool file, void* notifyData)
171
{
172
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
173 174
    return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
            instance, url, window, len, buf, file, notifyData);
175 176 177 178
#else
    return (*gNetscapeFuncs.posturlnotify)(instance, url, window, len, buf, file, notifyData);

#endif
179 180 181 182 183
}

NPError
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{
184
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
185 186
    return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
                    stream, rangeList);
187 188 189
#else
    return (*gNetscapeFuncs.requestread)(stream, rangeList);
#endif
190 191 192 193
}

NPError
NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
194
          NPStream** stream_ptr)
195
{
196
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
197 198
    return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
                    type, window, stream_ptr);
199 200 201
#else
    return (*gNetscapeFuncs.newstream)(instance, type, window, stream_ptr);
#endif
202 203
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
204 205
int32_t
NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
206
{
207
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
208 209
    return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
                    stream, len, buffer);
210 211 212
#else
    return (*gNetscapeFuncs.write)(instance, stream, len, buffer);
#endif
213 214 215 216 217
}

NPError
NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{
218
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
219 220
    return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
                        instance, stream, reason);
221 222 223
#else
    return (*gNetscapeFuncs.destroystream)(instance, stream, reason);
#endif
224 225 226 227 228
}

void
NPN_Status(NPP instance, const char* message)
{
229
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
230
    CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
231 232 233
#else
    (*gNetscapeFuncs.status)(instance, message);
#endif
234 235 236 237 238
}

const char*
NPN_UserAgent(NPP instance)
{
239
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
240
    return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
241 242 243
#else
    return (*gNetscapeFuncs.uagent)(instance);
#endif
244 245
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
246
void *NPN_MemAlloc(uint32_t size)
247
{
248
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
249
    return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
250 251 252
#else
    return (*gNetscapeFuncs.memalloc)(size);
#endif
253 254 255 256
}

void NPN_MemFree(void* ptr)
{
257
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
258
    CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
259 260 261
#else
    (*gNetscapeFuncs.memfree)(ptr);
#endif
262 263
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
264
uint32_t NPN_MemFlush(uint32_t size)
265
{
266
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
267
    return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
268 269 270
#else
    return (*gNetscapeFuncs.memflush)(size);
#endif
271 272 273 274
}

void NPN_ReloadPlugins(NPBool reloadPages)
{
275
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
276
    CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
277 278 279
#else
    (*gNetscapeFuncs.reloadplugins)(reloadPages);
#endif
280 281
}

282
#ifdef OJI
283 284
JRIEnv* NPN_GetJavaEnv()
{
285
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
286
    return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
287 288 289
#else
    return (*gNetscapeFuncs.getJavaEnv);
#endif
290 291 292 293
}

jref NPN_GetJavaPeer(NPP instance)
{
294
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
295 296
    return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
                       instance);
297 298 299
#else
    return (*gNetscapeFuncs.getJavaPeer)(instance);
#endif
300
}
301
#endif
302

303 304 305
void
NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
{
306
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
307 308
    CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
        invalidRect);
309 310 311
#else
    (*gNetscapeFuncs.invalidaterect)(instance, invalidRect);
#endif
312 313 314 315 316
}

void
NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
{
317
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
318 319
    CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
        invalidRegion);
320 321 322
#else
    (*gNetscapeFuncs.invalidateregion)(instance, invalidRegion);
#endif
323 324 325 326 327
}

void
NPN_ForceRedraw(NPP instance)
{
328
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
329
    CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
330 331 332
#else
    (*gNetscapeFuncs.forceredraw)(instance);
#endif
333 334
}

335 336
void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
{
337
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
338 339
    CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
        instance, enabled);
340 341 342
#else
    (*gNetscapeFuncs.pushpopupsenabledstate)(instance, enabled);
#endif
343 344 345 346
}

void NPN_PopPopupsEnabledState(NPP instance)
{
347
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
348 349
    CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
        instance);
350 351 352
#else
    (*gNetscapeFuncs.poppopupsenabledstate)(instance);
#endif
353 354
}

355 356
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
{
357 358 359
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
    {
360
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
361 362
        return CallNPN_GetStringIdentifierProc(
                        gNetscapeFuncs.getstringidentifier, name);
363 364 365
#else
        return (*gNetscapeFuncs.getstringidentifier)(name);
#endif
366 367
    }
    return NULL;
368 369
}

370 371
void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
                              NPIdentifier *identifiers)
372
{
373 374 375
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
    {
376
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
377 378
        CallNPN_GetStringIdentifiersProc(gNetscapeFuncs.getstringidentifiers,
                                         names, nameCount, identifiers);
379 380 381
#else
        (*gNetscapeFuncs.getstringidentifiers)(names, nameCount, identifiers);
#endif
382
    }
383 384 385 386
}

NPIdentifier NPN_GetIntIdentifier(int32_t intid)
{
387 388 389
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
    {
390
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
391
        return CallNPN_GetIntIdentifierProc(gNetscapeFuncs.getintidentifier, intid);
392 393 394
#else
        return (*gNetscapeFuncs.getintidentifier)(intid);
#endif
395 396
    }
    return NULL;
397 398 399 400
}

bool NPN_IdentifierIsString(NPIdentifier identifier)
{
401 402 403
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
    {
404
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
405 406 407
        return CallNPN_IdentifierIsStringProc(
                        gNetscapeFuncs.identifierisstring,
                        identifier);
408 409 410
#else
        return (*gNetscapeFuncs.identifierisstring)(identifier);
#endif
411 412
    }
    return false;
413 414 415 416
}

NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
{
417 418 419
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
    {
420
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
421 422 423
        return CallNPN_UTF8FromIdentifierProc(
                            gNetscapeFuncs.utf8fromidentifier,
                            identifier);
424 425 426
#else
        return (*gNetscapeFuncs.utf8fromidentifier)(identifier);
#endif
427 428
    }
    return NULL;
429 430 431 432
}

int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
{
433 434 435
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
    {
436
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
437 438 439
        return CallNPN_IntFromIdentifierProc(
                        gNetscapeFuncs.intfromidentifier,
                        identifier);
440 441 442
#else
        return (*gNetscapeFuncs.intfromidentifier)(identifier);
#endif
443 444
    }
    return 0;
445 446
}

447
NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
448
{
449 450
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
451
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
452
        return CallNPN_CreateObjectProc(gNetscapeFuncs.createobject, npp, aClass);
453 454 455
#else
        return (*gNetscapeFuncs.createobject)(npp, aClass);
#endif
456
    return NULL;
457 458
}

459
NPObject *NPN_RetainObject(NPObject *obj)
460
{
461 462
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
463
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
464
        return CallNPN_RetainObjectProc(gNetscapeFuncs.retainobject, obj);
465 466 467
#else
        return (*gNetscapeFuncs.retainobject)(obj);
#endif
468
    return NULL;
469 470
}

471
void NPN_ReleaseObject(NPObject *obj)
472
{
473 474
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
475
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
476
        CallNPN_ReleaseObjectProc(gNetscapeFuncs.releaseobject, obj);
477 478 479
#else
        (*gNetscapeFuncs.releaseobject)(obj);
#endif
480 481
}

482 483
bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
                const NPVariant *args, uint32_t argCount, NPVariant *result)
484
{
485 486
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
487
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
488 489
        return CallNPN_InvokeProc(gNetscapeFuncs.invoke, npp, obj, methodName,
                                  args, argCount, result);
490 491 492
#else
        return (*gNetscapeFuncs.invoke)(npp, obj, methodName, args, argCount, result);
#endif
493
    return false;
494 495
}

496 497
bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
                       uint32_t argCount, NPVariant *result)
498
{
499 500
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
501
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
502 503
        return CallNPN_InvokeDefaultProc(gNetscapeFuncs.invokeDefault, npp, obj,
                                         args, argCount, result);
504 505 506
#else
        return (*gNetscapeFuncs.invokeDefault)(npp, obj, args, argCount, result);
#endif
507
    return false;
508 509
}

510 511
bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
                  NPVariant *result)
512
{
513 514
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
515
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
516 517
        return CallNPN_EvaluateProc(gNetscapeFuncs.evaluate, npp, obj,
                                    script, result);
518 519 520
#else
        return (*gNetscapeFuncs.evaluate)(npp, obj, script, result);
#endif
521
    return false;
522 523
}

524 525
bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
                     NPVariant *result)
526
{
527 528
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
529
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
530 531
        return CallNPN_GetPropertyProc(gNetscapeFuncs.getproperty, npp, obj,
                                       propertyName, result);
532 533 534
#else
        return (*gNetscapeFuncs.getproperty)(npp, obj, propertyName, result);
#endif
535
    return false;
536 537
}

538 539
bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
                     const NPVariant *value)
540
{
541 542
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
543
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
544 545
        return CallNPN_SetPropertyProc(gNetscapeFuncs.setproperty, npp, obj,
                                       propertyName, value);
546 547 548
#else
        return (*gNetscapeFuncs.setproperty)(npp, obj, propertyName, value);
#endif
549
    return false;
550 551
}

552
bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
553
{
554 555
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
556
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
557 558
        return CallNPN_RemovePropertyProc(gNetscapeFuncs.removeproperty, npp, obj,
                                          propertyName);
559 560 561
#else
        return (*gNetscapeFuncs.removeproperty)(npp, obj, propertyName);
#endif
562
    return false;
563 564
}

565
bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
566
{
567 568
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
569
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
570 571
        return CallNPN_HasPropertyProc(gNetscapeFuncs.hasproperty, npp, obj,
                                       propertyName);
572 573 574
#else
        return (*gNetscapeFuncs.hasproperty)(npp, obj, propertyName);
#endif
575
    return false;
576 577
}

578
bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
579
{
580 581
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
582
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
583 584
        return CallNPN_HasMethodProc(gNetscapeFuncs.hasmethod, npp,
                                     obj, methodName);
585 586 587
#else
        return (*gNetscapeFuncs.hasmethod)(npp, obj, methodName);
#endif
588
    return false;
589 590 591 592
}

void NPN_ReleaseVariantValue(NPVariant *variant)
{
593 594
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
595
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
596
        CallNPN_ReleaseVariantValueProc(gNetscapeFuncs.releasevariantvalue, variant);
597 598 599
#else
        (*gNetscapeFuncs.releasevariantvalue)(variant);
#endif
600 601
}

602
void NPN_SetException(NPObject* obj, const NPUTF8 *message)
603
{
604 605
    int minor = gNetscapeFuncs.version & 0xFF;
    if( minor >= 14 )
606
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
607
        CallNPN_SetExceptionProc(gNetscapeFuncs.setexception, obj, message);
608 609 610
#else
        (*gNetscapeFuncs.setexception)(obj, message);
#endif
611
}
612

613 614 615 616 617
/***********************************************************************
 *
 * Wrapper functions : Netscape Navigator -> plugin
 *
 * These functions let the plugin developer just create the APIs
618
 * as documented and defined in npapi.h, without needing to 
619 620 621 622 623
 * install those functions in the function table or worry about
 * setting up globals for 68K plugins.
 *
 ***********************************************************************/

624
/* Function prototypes */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
625 626
NPError Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
        int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
627 628 629
NPError Private_Destroy(NPP instance, NPSavedData** save);
NPError Private_SetWindow(NPP instance, NPWindow* window);
NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
630 631 632 633
                          NPBool seekable, uint16_t* stype);
int32_t Private_WriteReady(NPP instance, NPStream* stream);
int32_t Private_Write(NPP instance, NPStream* stream, int32_t offset,
                    int32_t len, void* buffer);
634 635 636 637 638 639
void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
void Private_URLNotify(NPP instance, const char* url,
                       NPReason reason, void* notifyData);
void Private_Print(NPP instance, NPPrint* platformPrint);
NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
640
NPError Private_SetValue(NPP instance, NPNVariable variable, void *r_value);
641 642 643 644 645
#ifdef OJI
JRIGlobalRef Private_GetJavaClass(void);
#endif

/* function implementations */
646
NPError
Jean-Paul Saman's avatar
Jean-Paul Saman committed
647 648
Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
        int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
649
{
650 651 652
    NPError ret;
    PLUGINDEBUGSTR("New");
    ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
653
    return ret; 
654 655 656 657 658
}

NPError
Private_Destroy(NPP instance, NPSavedData** save)
{
659 660
    PLUGINDEBUGSTR("Destroy");
    return NPP_Destroy(instance, save);
661 662 663 664 665
}

NPError
Private_SetWindow(NPP instance, NPWindow* window)
{
666 667 668 669
    NPError err;
    PLUGINDEBUGSTR("SetWindow");
    err = NPP_SetWindow(instance, window);
    return err;
670 671 672 673
}

NPError
Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
674
            NPBool seekable, uint16_t* stype)
675
{
676 677 678 679
    NPError err;
    PLUGINDEBUGSTR("NewStream");
    err = NPP_NewStream(instance, type, stream, seekable, stype);
    return err;
680 681
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
682
int32_t
683 684
Private_WriteReady(NPP instance, NPStream* stream)
{
685 686 687 688
    unsigned int result;
    PLUGINDEBUGSTR("WriteReady");
    result = NPP_WriteReady(instance, stream);
    return result;
689 690
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
691 692
int32_t
Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
693
        void* buffer)
694
{
695 696 697 698
    unsigned int result;
    PLUGINDEBUGSTR("Write");
    result = NPP_Write(instance, stream, offset, len, buffer);
    return result;
699 700 701 702 703
}

void
Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
{
704 705
    PLUGINDEBUGSTR("StreamAsFile");
    NPP_StreamAsFile(instance, stream, fname);
706 707
}

708

709 710 711
NPError
Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{
712 713 714 715 716 717 718 719 720 721 722 723
    NPError err;
    PLUGINDEBUGSTR("DestroyStream");
    err = NPP_DestroyStream(instance, stream, reason);
    return err;
}

void
Private_URLNotify(NPP instance, const char* url,
                NPReason reason, void* notifyData)
{
    PLUGINDEBUGSTR("URLNotify");
    NPP_URLNotify(instance, url, reason, notifyData);
724 725 726 727 728
}

void
Private_Print(NPP instance, NPPrint* platformPrint)
{
729 730 731 732
    PLUGINDEBUGSTR("Print");
    NPP_Print(instance, platformPrint);
}

733 734 735 736 737 738 739 740
NPError
Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
{
    PLUGINDEBUGSTR("GetValue");
    return NPP_GetValue(instance, variable, r_value);
}

NPError
741
Private_SetValue(NPP instance, NPNVariable variable, void *r_value)
742 743 744 745 746
{
    PLUGINDEBUGSTR("SetValue");
    return NPP_SetValue(instance, variable, r_value);
}

747
#ifdef OJI
748 749 750 751 752
JRIGlobalRef
Private_GetJavaClass(void)
{
    jref clazz = NPP_GetJavaClass();
    if (clazz) {
753 754
    JRIEnv* env = NPN_GetJavaEnv();
    return JRI_NewGlobalRef(env, clazz);
755 756 757
    }
    return NULL;
}
758
#endif
759

760
/*********************************************************************** 
761 762 763 764 765 766 767
 *
 * These functions are located automagically by netscape.
 *
 ***********************************************************************/

/*
 * NP_GetMIMEDescription
768 769 770
 *  - Netscape needs to know about this symbol
 *  - Netscape uses the return value to identify when an object instance
 *    of this plugin should be created.
771
 */
772
NPP_GET_MIME_CONST char * NP_GetMIMEDescription(void)
773
{
774
    return NPP_GetMIMEDescription();
775 776 777 778
}

/*
 * NP_GetValue [optional]
779 780 781
 *  - Netscape needs to know about this symbol.
 *  - Interfaces with plugin to get values for predefined variables
 *    that the navigator needs.
782 783
 */
NPError
784
NP_GetValue(void* future, NPPVariable variable, void *value)
785
{
786
    return NPP_GetValue((NPP)future, variable, value);
787 788 789 790
}

/*
 * NP_Initialize
791 792 793
 *  - Netscape needs to know about this symbol.
 *  - It calls this function after looking up its symbol before it
 *    is about to create the first ever object of this kind.
794 795
 *
 * PARAMETERS
796
 *    nsTable   - The netscape function table. If developers just use these
797
 *        wrappers, they don't need to worry about all these function
798
 *        tables.
799 800
 * RETURN
 *    pluginFuncs
801 802 803
 *      - This functions needs to fill the plugin function table
 *        pluginFuncs and return it. Netscape Navigator plugin
 *        library will use this function table to call the plugin.
804 805 806 807 808
 *
 */
NPError
NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
{
809 810 811 812
    NPError err = NPERR_NO_ERROR;

    PLUGINDEBUGSTR("NP_Initialize");

813
    /* validate input parameters */
814 815
    if ((nsTable == NULL) || (pluginFuncs == NULL))
        err = NPERR_INVALID_FUNCTABLE_ERROR;
816

817 818 819 820 821 822 823 824 825 826 827
    /*
     * Check the major version passed in Netscape's function table.
     * We won't load if the major version is newer than what we expect.
     * Also check that the function tables passed in are big enough for
     * all the functions we need (they could be bigger, if Netscape added
     * new APIs, but that's OK with us -- we'll just ignore them).
     *
     */
    if (err == NPERR_NO_ERROR) {
        if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
            err = NPERR_INCOMPATIBLE_VERSION_ERROR;
828
        if (nsTable->size < ((char *)&nsTable->posturlnotify - (char *)nsTable))
829
            err = NPERR_INVALID_FUNCTABLE_ERROR;
830
        if (pluginFuncs->size < sizeof(NPPluginFuncs))
831 832
            err = NPERR_INVALID_FUNCTABLE_ERROR;
    }
833 834 835

    if (err == NPERR_NO_ERROR)
    {
836 837 838 839 840 841 842
        /*
         * Copy all the fields of Netscape function table into our
         * copy so we can call back into Netscape later.  Note that
         * we need to copy the fields one by one, rather than assigning
         * the whole structure, because the Netscape function table
         * could actually be bigger than what we expect.
         */
843 844
        int minor = nsTable->version & 0xFF;

845 846 847 848 849 850 851 852 853 854 855 856 857 858
        gNetscapeFuncs.version       = nsTable->version;
        gNetscapeFuncs.size          = nsTable->size;
        gNetscapeFuncs.posturl       = nsTable->posturl;
        gNetscapeFuncs.geturl        = nsTable->geturl;
        gNetscapeFuncs.requestread   = nsTable->requestread;
        gNetscapeFuncs.newstream     = nsTable->newstream;
        gNetscapeFuncs.write         = nsTable->write;
        gNetscapeFuncs.destroystream = nsTable->destroystream;
        gNetscapeFuncs.status        = nsTable->status;
        gNetscapeFuncs.uagent        = nsTable->uagent;
        gNetscapeFuncs.memalloc      = nsTable->memalloc;
        gNetscapeFuncs.memfree       = nsTable->memfree;
        gNetscapeFuncs.memflush      = nsTable->memflush;
        gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
859 860 861 862
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) >= 20)
        gNetscapeFuncs.pluginthreadasynccall =
            nsTable->pluginthreadasynccall;
#endif
863
#ifdef OJI
864 865 866 867 868
        if( minor >= NPVERS_HAS_LIVECONNECT )
        {
            gNetscapeFuncs.getJavaEnv    = nsTable->getJavaEnv;
            gNetscapeFuncs.getJavaPeer   = nsTable->getJavaPeer;
        }
869 870 871
#endif
        gNetscapeFuncs.getvalue      = nsTable->getvalue;
        gNetscapeFuncs.setvalue      = nsTable->setvalue;
872 873 874 875 876 877

        if( minor >= NPVERS_HAS_NOTIFICATION )
        {
            gNetscapeFuncs.geturlnotify  = nsTable->geturlnotify;
            gNetscapeFuncs.posturlnotify = nsTable->posturlnotify;
        }
878 879

        if (nsTable->size >= ((char *)&nsTable->setexception - (char *)nsTable))
880
        {
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
            gNetscapeFuncs.invalidaterect = nsTable->invalidaterect;
            gNetscapeFuncs.invalidateregion = nsTable->invalidateregion;
            gNetscapeFuncs.forceredraw = nsTable->forceredraw;
            /* npruntime support */
            if (minor >= 14)
            {
                gNetscapeFuncs.getstringidentifier = nsTable->getstringidentifier;
                gNetscapeFuncs.getstringidentifiers = nsTable->getstringidentifiers;
                gNetscapeFuncs.getintidentifier = nsTable->getintidentifier;
                gNetscapeFuncs.identifierisstring = nsTable->identifierisstring;
                gNetscapeFuncs.utf8fromidentifier = nsTable->utf8fromidentifier;
                gNetscapeFuncs.intfromidentifier = nsTable->intfromidentifier;
                gNetscapeFuncs.createobject = nsTable->createobject;
                gNetscapeFuncs.retainobject = nsTable->retainobject;
                gNetscapeFuncs.releaseobject = nsTable->releaseobject;
                gNetscapeFuncs.invoke = nsTable->invoke;
                gNetscapeFuncs.invokeDefault = nsTable->invokeDefault;
                gNetscapeFuncs.evaluate = nsTable->evaluate;
                gNetscapeFuncs.getproperty = nsTable->getproperty;
                gNetscapeFuncs.setproperty = nsTable->setproperty;
                gNetscapeFuncs.removeproperty = nsTable->removeproperty;
                gNetscapeFuncs.hasproperty = nsTable->hasproperty;
                gNetscapeFuncs.hasmethod = nsTable->hasmethod;
                gNetscapeFuncs.releasevariantvalue = nsTable->releasevariantvalue;
                gNetscapeFuncs.setexception = nsTable->setexception;
            }
907
        }
908
        else
909
        {
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
            gNetscapeFuncs.invalidaterect = NULL;
            gNetscapeFuncs.invalidateregion = NULL;
            gNetscapeFuncs.forceredraw = NULL;
            gNetscapeFuncs.getstringidentifier = NULL;
            gNetscapeFuncs.getstringidentifiers = NULL;
            gNetscapeFuncs.getintidentifier = NULL;
            gNetscapeFuncs.identifierisstring = NULL;
            gNetscapeFuncs.utf8fromidentifier = NULL;
            gNetscapeFuncs.intfromidentifier = NULL;
            gNetscapeFuncs.createobject = NULL;
            gNetscapeFuncs.retainobject = NULL;
            gNetscapeFuncs.releaseobject = NULL;
            gNetscapeFuncs.invoke = NULL;
            gNetscapeFuncs.invokeDefault = NULL;
            gNetscapeFuncs.evaluate = NULL;
            gNetscapeFuncs.getproperty = NULL;
            gNetscapeFuncs.setproperty = NULL;
            gNetscapeFuncs.removeproperty = NULL;
            gNetscapeFuncs.hasproperty = NULL;
            gNetscapeFuncs.releasevariantvalue = NULL;
            gNetscapeFuncs.setexception = NULL;
931
        }
932 933
        if (nsTable->size >=
            ((char *)&nsTable->poppopupsenabledstate - (char *)nsTable))
934
        {
935 936
            gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
            gNetscapeFuncs.poppopupsenabledstate  = nsTable->poppopupsenabledstate;
937
        }
938
        else
939
        {
940 941
            gNetscapeFuncs.pushpopupsenabledstate = NULL;
            gNetscapeFuncs.poppopupsenabledstate  = NULL;
942
        }
943 944 945 946 947 948 949 950 951

        /*
         * Set up the plugin function table that Netscape will use to
         * call us.  Netscape needs to know about our version and size
         * and have a UniversalProcPointer for every function we
         * implement.
         */
        pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
        pluginFuncs->size       = sizeof(NPPluginFuncs);
952
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
953 954 955 956 957 958 959 960 961
        pluginFuncs->newp       = NewNPP_NewProc(Private_New);
        pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
        pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
        pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
        pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
        pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
        pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
        pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
        pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
962 963
        pluginFuncs->getvalue   = NewNPP_GetValueProc(Private_GetValue);
        pluginFuncs->setvalue   = NewNPP_SetValueProc(Private_SetValue);
964 965 966 967 968 969 970 971 972 973 974 975 976
#else
        pluginFuncs->newp       = (NPP_NewProcPtr)(Private_New);
        pluginFuncs->destroy    = (NPP_DestroyProcPtr)(Private_Destroy);
        pluginFuncs->setwindow  = (NPP_SetWindowProcPtr)(Private_SetWindow);
        pluginFuncs->newstream  = (NPP_NewStreamProcPtr)(Private_NewStream);
        pluginFuncs->destroystream = (NPP_DestroyStreamProcPtr)(Private_DestroyStream);
        pluginFuncs->asfile     = (NPP_StreamAsFileProcPtr)(Private_StreamAsFile);
        pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
        pluginFuncs->write      = (NPP_WriteProcPtr)(Private_Write);
        pluginFuncs->print      = (NPP_PrintProcPtr)(Private_Print);
        pluginFuncs->getvalue   = (NPP_GetValueProcPtr)(Private_GetValue);
        pluginFuncs->setvalue   = (NPP_SetValueProcPtr)(Private_SetValue);
#endif
977
        pluginFuncs->event      = NULL;
978 979
        if( minor >= NPVERS_HAS_NOTIFICATION )
        {
980
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
981
            pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
982 983 984
#else
            pluginFuncs->urlnotify = (NPP_URLNotifyProcPtr)(Private_URLNotify);
#endif
985
        }
986
#ifdef OJI
987 988 989 990 991 992
        if( minor >= NPVERS_HAS_LIVECONNECT )
            pluginFuncs->javaClass  = Private_GetJavaClass();
        else
            pluginFuncs->javaClass = NULL;
#else
        pluginFuncs->javaClass = NULL;
993
#endif
994

995 996
        err = NPP_Initialize();
    }
997

998
    return err;
999 1000 1001 1002
}

/*
 * NP_Shutdown [optional]
1003 1004 1005
 *  - Netscape needs to know about this symbol.
 *  - It calls this function after looking up its symbol after
 *    the last object of this kind has been destroyed.
1006 1007 1008 1009 1010
 *
 */
NPError
NP_Shutdown(void)
{
1011 1012 1013
    PLUGINDEBUGSTR("NP_Shutdown");
    NPP_Shutdown();
    return NPERR_NO_ERROR;
1014
}