1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of a Qt Solutions component.
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21
** the names of its contributors may be used to endorse or promote
22
** products derived from this software without specific prior written
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37
****************************************************************************/
39
// see http://www.mozilla.org/projects/plugins/ for details regarding the structs and API prototypes
45
#define NP_VERSION_MAJOR 0
46
#define NP_VERSION_MINOR 17
49
typedef unsigned short uint16;
51
typedef unsigned int uint32;
54
typedef unsigned char NPBool;
55
typedef int16 NPError;
56
typedef int16 NPReason;
57
typedef char* NPMIMEType;
59
typedef void *NPRegion;
60
typedef void *NPIdentifier;
64
typedef void* JRIGlobalRef;
65
typedef void* JRIEnv; // ### not quite correct, but we don't use it anyway
70
void* pdata; // plug-in private data
71
void* ndata; // browser private data
90
#elif defined(Q_WS_X11)
91
# include <X11/Xlib.h>
92
typedef XEvent NPEvent;
93
#elif defined (Q_WS_MAC)
94
typedef struct EventRecord NPEvent;
97
// Variable names for NPP_GetValue
99
NPPVpluginNameString = 1,
100
NPPVpluginDescriptionString,
101
NPPVpluginWindowBool,
102
NPPVpluginTransparentBool,
104
NPPVpluginWindowSize,
105
NPPVpluginTimerInterval,
107
NPPVpluginScriptableInstance = 10,
108
NPPVpluginScriptableIID = 11,
110
// Introduced in Mozilla 0.9.9
111
NPPVjavascriptPushCallerBool = 12,
113
// Introduced in Mozilla 1.0
114
NPPVpluginKeepLibraryInMemory = 13,
115
NPPVpluginNeedsXEmbed = 14,
117
// Introduced in Firefox 1.0
118
NPPVpluginScriptableNPObject = 15,
122
// Variable names for NPN_GetValue
127
NPNVjavascriptEnabledBool,
131
// Introduced in Mozilla 0.9.4
132
NPNVserviceManager = 10,
134
// Introduced in Mozilla 1.2
137
NPNVSupportsXEmbedBool = 14,
139
NPNVWindowNPObject = 15,
140
NPNVPluginElementNPObject = 16
145
NPWindowTypeWindow = 1, // Windowed plug-in. The window field holds a platform-specific handle to a window.
146
NPWindowTypeDrawable // Windows: HDC; Mac OS: pointer to NP_Port structure.
151
// Platform-specific handle to a native window element in the browser's window hierarchy
152
// XEmbed: "In the NPP_SetWindow call, the window parameter will be the XID of the hosting
153
// XEmbed window. As an implementation note, this is really the XID of a GtkSocket window."
155
// The x and y coordinates for the top left corner of the plug-in relative to the page
156
// (and thus relative to the origin of the drawable)
158
// The height and width of the plug-in area. Should not be modified by the plug-in.
159
uint32 width, height;
160
// Used by MAC only (Clipping rectangle in port coordinates)
163
// Contains information about the plug-in's Unix window environment
164
// points to an NPSetWindowCallbackStruct
165
void* ws_info; // probably obsolete with XEmbed
167
// The type field indicates the NPWindow type of the target area
180
NPBool pluginPrinted; // true if plugin handled fullscreen printing
181
NPBool printOne; // true if plugin should print one copy to default printer
182
void* platformPrint; // Platform-specific printing info
188
void* platformPrint; // Platform-specific printing info
193
uint16 mode; // NP_FULL or NP_EMBED
195
NPFullPrint fullPrint;
196
NPEmbedPrint embedPrint;
218
int32 offset; // negative offset means from the end
223
// Values for mode passed to NPP_New:
227
// Values for stream type passed to NPP_NewStream:
231
#define NP_ASFILEONLY 4
233
#define NP_MAXREADY (((unsigned)(~0)<<1)>>1)
235
// Values of type NPError:
236
#define NPERR_NO_ERROR 0
237
#define NPERR_GENERIC_ERROR 1
238
#define NPERR_INVALID_INSTANCE_ERROR 2
239
#define NPERR_INVALID_FUNCTABLE_ERROR 3
240
#define NPERR_MODULE_LOAD_FAILED_ERROR 4
241
#define NPERR_OUT_OF_MEMORY_ERROR 5
242
#define NPERR_INVALID_PLUGIN_ERROR 6
243
#define NPERR_INVALID_PLUGIN_DIR_ERROR 7
244
#define NPERR_INCOMPATIBLE_VERSION_ERROR 8
245
#define NPERR_INVALID_PARAM 9
246
#define NPERR_INVALID_URL 10
247
#define NPERR_FILE_NOT_FOUND 11
248
#define NPERR_NO_DATA 12
249
#define NPERR_STREAM_NOT_SEEKABLE 13
251
// Values of type NPReason:
253
#define NPRES_NETWORK_ERR 1
254
#define NPRES_USER_BREAK 2
256
// Version feature information
257
#define NPVERS_HAS_STREAMOUTPUT 8
258
#define NPVERS_HAS_NOTIFICATION 9
259
#define NPVERS_HAS_LIVECONNECT 9
260
#define NPVERS_WIN16_HAS_LIVECONNECT 10
264
# define getFocusEvent (osEvt + 16)
265
# define loseFocusEvent (osEvt + 17)
266
# define adjustCursorEvent (osEvt + 18)
267
# define QTBROWSER_USE_CFM
270
#ifdef QTBROWSER_USE_CFM
271
extern void *CFMFunctionPointerForMachOFunctionPointer(void*);
272
extern void DisposeCFMFunctionPointer(void *);
273
extern void* MachOFunctionPointerForCFMFunctionPointer(void*);
274
# define FUNCTION_POINTER(t) void*
275
# define MAKE_FUNCTION_POINTER(f) CFMFunctionPointerForMachOFunctionPointer((void*)f)
276
# define DESTROY_FUNCTION_POINTER(n) DisposeCFMFunctionPointer(n)
277
# define FIND_FUNCTION_POINTER(t, n) (*(t)MachOFunctionPointerForCFMFunctionPointer(n))
279
# define FUNCTION_POINTER(t) t
280
# define MAKE_FUNCTION_POINTER(f) f
281
# define DESTROY_FUNCTION_POINTER(n)
282
# define FIND_FUNCTION_POINTER(t, n) (*n)
285
// Plugin function prototypes
286
typedef NPError (*NPP_NewFP)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
287
typedef NPError (*NPP_DestroyFP)(NPP instance, NPSavedData** save);
288
typedef NPError (*NPP_SetWindowFP)(NPP instance, NPWindow* window);
289
typedef NPError (*NPP_NewStreamFP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
290
typedef NPError (*NPP_DestroyStreamFP)(NPP instance, NPStream* stream, NPReason reason);
291
typedef void (*NPP_StreamAsFileFP)(NPP instance, NPStream* stream, const char* fname);
292
typedef int32 (*NPP_WriteReadyFP)(NPP instance, NPStream* stream);
293
typedef int32 (*NPP_WriteFP)(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer);
294
typedef void (*NPP_PrintFP)(NPP instance, NPPrint* platformPrint);
295
typedef int16 (*NPP_HandleEventFP)(NPP instance, NPEvent* event);
296
typedef void (*NPP_URLNotifyFP)(NPP instance, const char* url, NPReason reason, void* notifyData);
297
typedef NPError (*NPP_GetValueFP)(NPP instance, NPPVariable variable, void *value);
298
typedef NPError (*NPP_SetValueFP)(NPP instance, NPPVariable variable, void *value);
300
// table of functions implemented by the plugin
301
struct NPPluginFuncs {
304
FUNCTION_POINTER(NPP_NewFP) newp;
305
FUNCTION_POINTER(NPP_DestroyFP) destroy;
306
FUNCTION_POINTER(NPP_SetWindowFP) setwindow;
307
FUNCTION_POINTER(NPP_NewStreamFP) newstream;
308
FUNCTION_POINTER(NPP_DestroyStreamFP) destroystream;
309
FUNCTION_POINTER(NPP_StreamAsFileFP) asfile;
310
FUNCTION_POINTER(NPP_WriteReadyFP) writeready;
311
FUNCTION_POINTER(NPP_WriteFP) write;
312
FUNCTION_POINTER(NPP_PrintFP) print;
313
FUNCTION_POINTER(NPP_HandleEventFP) event;
314
FUNCTION_POINTER(NPP_URLNotifyFP) urlnotify;
315
JRIGlobalRef javaClass;
316
FUNCTION_POINTER(NPP_GetValueFP) getvalue;
317
FUNCTION_POINTER(NPP_SetValueFP) setvalue;
321
// forward declarations
328
// NPObject is the type used to express objects exposed by either
329
// the plugin or by the browser. Implementation specific (i.e. plugin
330
// specific, or browser specific) members can come after the struct.
331
// In our case, the plugin specific member (aka QObject) lives in NPClass.
338
// NPClass is what virtual function tables would look like if
339
// there was no C++...
340
typedef NPObject *(*NPAllocateFP)(NPP npp, NPClass *aClass);
341
typedef void (*NPDeallocateFP)(NPObject *npobj);
342
typedef void (*NPInvalidateFP)(NPObject *npobj);
343
typedef bool (*NPHasMethodFP)(NPObject *npobj, NPIdentifier name);
344
typedef bool (*NPInvokeFP)(NPObject *npobj, NPIdentifier name,const NPVariant *args, uint32 argCount,NPVariant *result);
345
typedef bool (*NPInvokeDefaultFP)(NPObject *npobj,const NPVariant *args,uint32 argCount,NPVariant *result);
346
typedef bool (*NPHasPropertyFP)(NPObject *npobj, NPIdentifier name);
347
typedef bool (*NPGetPropertyFP)(NPObject *npobj, NPIdentifier name, NPVariant *result);
348
typedef bool (*NPSetPropertyFP)(NPObject *npobj, NPIdentifier name, const NPVariant *value);
349
typedef bool (*NPRemovePropertyFP)(NPObject *npobj, NPIdentifier name);
351
#define NP_CLASS_STRUCT_VERSION 1
355
NPClass(QtNPInstance *qtnp);
359
uint32 structVersion;
360
NPAllocateFP allocate;
361
NPDeallocateFP deallocate;
362
NPInvalidateFP invalidate;
363
NPHasMethodFP hasMethod;
365
NPInvokeDefaultFP invokeDefault;
366
NPHasPropertyFP hasProperty;
367
NPGetPropertyFP getProperty;
368
NPSetPropertyFP setProperty;
369
NPRemovePropertyFP removeProperty;
371
// User data lives here
377
const char *utf8characters;
380
// Qt specific conversion routines
381
// (no c'tor as it would be misleading that there is no d'tor in spite of memory allocation)
382
static NPString fromQString(const QString &qstr);
383
operator QString() const;
401
NPString stringValue;
402
NPObject *objectValue;
409
// Qt specific conversion routines
410
// (no c'tor as the NPP instance is required)
411
static NPVariant fromQVariant(QtNPInstance *This, const QVariant &qvariant);
412
operator QVariant() const;
421
// Browser function prototypes
422
typedef NPError (*NPN_GetURLFP)(NPP instance, const char* url, const char* window);
423
typedef NPError (*NPN_PostURLFP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file);
424
typedef NPError (*NPN_RequestReadFP)(NPStream* stream, NPByteRange* rangeList);
425
typedef NPError (*NPN_NewStreamFP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream);
426
typedef int32 (*NPN_WriteFP)(NPP instance, NPStream* stream, int32 len, void* buffer);
427
typedef NPError (*NPN_DestroyStreamFP)(NPP instance, NPStream* stream, NPReason reason);
428
typedef void (*NPN_StatusFP)(NPP instance, const char* message);
429
typedef const char* (*NPN_UserAgentFP)(NPP instance);
430
typedef void* (*NPN_MemAllocFP)(uint32 size);
431
typedef void (*NPN_MemFreeFP)(void* ptr);
432
typedef uint32 (*NPN_MemFlushFP)(uint32 size);
433
typedef void (*NPN_ReloadPluginsFP)(NPBool reloadPages);
434
typedef JRIEnv* (*NPN_GetJavaEnvFP)(void);
435
typedef jref (*NPN_GetJavaPeerFP)(NPP instance);
436
typedef NPError (*NPN_GetURLNotifyFP)(NPP instance, const char* url, const char* window, void* notifyData);
437
typedef NPError (*NPN_PostURLNotifyFP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData);
438
typedef NPError (*NPN_GetValueFP)(NPP instance, NPNVariable variable, void *ret_value);
439
typedef NPError (*NPN_SetValueFP)(NPP instance, NPPVariable variable, void *ret_value);
440
typedef void (*NPN_InvalidateRectFP)(NPP instance, NPRect *rect);
441
typedef void (*NPN_InvalidateRegionFP)(NPP instance, NPRegion *region);
442
typedef void (*NPN_ForceRedrawFP)(NPP instance);
443
typedef NPIdentifier (*NPN_GetStringIdentifierFP)(const char* name);
444
typedef void (*NPN_GetStringIdentifiersFP)(const char** names, int32 nameCount, NPIdentifier* identifiers);
445
typedef NPIdentifier (*NPN_GetIntIdentifierFP)(int32 intid);
446
typedef bool (*NPN_IdentifierIsStringFP)(NPIdentifier identifier);
447
typedef char* (*NPN_UTF8FromIdentifierFP)(NPIdentifier identifier);
448
typedef int32 (*NPN_IntFromIdentifierFP)(NPIdentifier identifier);
449
typedef NPObject* (*NPN_CreateObjectFP)(NPP npp, NPClass *aClass);
450
typedef NPObject* (*NPN_RetainObjectFP)(NPObject *obj);
451
typedef void (*NPN_ReleaseObjectFP)(NPObject *obj);
452
typedef bool (*NPN_InvokeFP)(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, int32 argCount, NPVariant *result);
453
typedef bool (*NPN_InvokeDefaultFP)(NPP npp, NPObject* obj, const NPVariant *args, int32 argCount, NPVariant *result);
454
typedef bool (*NPN_EvaluateFP)(NPP npp, NPObject *obj, NPString *script, NPVariant *result);
455
typedef bool (*NPN_GetPropertyFP)(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result);
456
typedef bool (*NPN_SetPropertyFP)(NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
457
typedef bool (*NPN_RemovePropertyFP)(NPP npp, NPObject *obj, NPIdentifier propertyName);
458
typedef bool (*NPN_HasPropertyFP)(NPP npp, NPObject *obj, NPIdentifier propertyName);
459
typedef bool (*NPN_HasMethodFP)(NPP npp, NPObject *obj, NPIdentifier methodName);
460
typedef void (*NPN_ReleaseVariantValueFP)(NPVariant *variant);
461
typedef void (*NPN_SetExceptionFP)(NPObject *obj, const char *message);
463
// function declarations
464
NPError NPN_GetURL(NPP instance, const char* url, const char* window);
465
NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file);
466
NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList);
467
NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* window, NPStream** stream);
468
int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer);
469
NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason);
470
void NPN_Status(NPP instance, const char* message);
471
const char* NPN_UserAgent(NPP instance);
472
void* NPN_MemAlloc(uint32 size);
473
void NPN_MemFree(void* ptr);
474
uint32 NPN_MemFlush(uint32 size);
475
void NPN_ReloadPlugins(NPBool reloadPages);
476
JRIEnv* NPN_GetJavaEnv(void);
477
jref NPN_GetJavaPeer(NPP instance);
478
NPError NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData);
479
NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData);
480
NPError NPN_GetValue(NPP instance, NPNVariable variable, void *ret_value);
481
NPError NPN_SetValue(NPP instance, NPPVariable variable, void *ret_value);
482
void NPN_InvalidateRect(NPP instance, NPRect *rect);
483
void NPN_InvalidateRegion(NPP instance, NPRegion *region);
484
void NPN_ForceRedraw(NPP instance);
485
NPIdentifier NPN_GetStringIdentifier(const char* name);
486
void NPN_GetStringIdentifiers(const char** names, int32 nameCount, NPIdentifier* identifiers);
487
NPIdentifier NPN_GetIntIdentifier(int32 intid);
488
bool NPN_IdentifierIsString(NPIdentifier identifier);
489
char* NPN_UTF8FromIdentifier(NPIdentifier identifier);
490
int32 NPN_IntFromIdentifier(NPIdentifier identifier);
491
NPObject* NPN_CreateObject(NPP npp, NPClass *aClass);
492
NPObject* NPN_RetainObject(NPObject *obj);
493
void NPN_ReleaseObject(NPObject *obj);
494
bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, int32 argCount, NPVariant *result);
495
bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args, int32 argCount, NPVariant *result);
496
bool NPN_Evaluate(NPP npp, NPObject *obj, NPString *script, NPVariant *result);
497
bool NPN_GetProperty(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result);
498
bool NPN_SetProperty(NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
499
bool NPN_RemoveProperty(NPP npp, NPObject *obj, NPIdentifier propertyName);
500
bool NPN_HasProperty(NPP npp, NPObject *obj, NPIdentifier propertyName);
501
bool NPN_HasMethod(NPP npp, NPObject *obj, NPIdentifier methodName);
502
void NPN_ReleaseVariantValue(NPVariant *variant);
503
void NPN_SetException(NPObject *obj, const char *message);
505
// table of function implemented by the browser
506
struct NPNetscapeFuncs {
509
FUNCTION_POINTER(NPN_GetURLFP) geturl;
510
FUNCTION_POINTER(NPN_PostURLFP) posturl;
511
FUNCTION_POINTER(NPN_RequestReadFP) requestread;
512
FUNCTION_POINTER(NPN_NewStreamFP) newstream;
513
FUNCTION_POINTER(NPN_WriteFP) write;
514
FUNCTION_POINTER(NPN_DestroyStreamFP) destroystream;
515
FUNCTION_POINTER(NPN_StatusFP) status;
516
FUNCTION_POINTER(NPN_UserAgentFP) uagent;
517
FUNCTION_POINTER(NPN_MemAllocFP) memalloc;
518
FUNCTION_POINTER(NPN_MemFreeFP) memfree;
519
FUNCTION_POINTER(NPN_MemFlushFP) memflush;
520
FUNCTION_POINTER(NPN_ReloadPluginsFP) reloadplugins;
521
FUNCTION_POINTER(NPN_GetJavaEnvFP) getJavaEnv;
522
FUNCTION_POINTER(NPN_GetJavaPeerFP) getJavaPeer;
523
FUNCTION_POINTER(NPN_GetURLNotifyFP) geturlnotify;
524
FUNCTION_POINTER(NPN_PostURLNotifyFP) posturlnotify;
525
FUNCTION_POINTER(NPN_GetValueFP) getvalue;
526
FUNCTION_POINTER(NPN_SetValueFP) setvalue;
527
FUNCTION_POINTER(NPN_InvalidateRectFP) invalidaterect;
528
FUNCTION_POINTER(NPN_InvalidateRegionFP) invalidateregion;
529
FUNCTION_POINTER(NPN_ForceRedrawFP) forceredraw;
530
FUNCTION_POINTER(NPN_GetStringIdentifierFP) getstringidentifier;
531
FUNCTION_POINTER(NPN_GetStringIdentifiersFP) getstringidentifiers;
532
FUNCTION_POINTER(NPN_GetIntIdentifierFP) getintidentifier;
533
FUNCTION_POINTER(NPN_IdentifierIsStringFP) identifierisstring;
534
FUNCTION_POINTER(NPN_UTF8FromIdentifierFP) utf8fromidentifier;
535
FUNCTION_POINTER(NPN_IntFromIdentifierFP) intfromidentifier;
536
FUNCTION_POINTER(NPN_CreateObjectFP) createobject;
537
FUNCTION_POINTER(NPN_RetainObjectFP) retainobject;
538
FUNCTION_POINTER(NPN_ReleaseObjectFP) releaseobject;
539
FUNCTION_POINTER(NPN_InvokeFP) invoke;
540
FUNCTION_POINTER(NPN_InvokeDefaultFP) invokedefault;
541
FUNCTION_POINTER(NPN_EvaluateFP) evaluate;
542
FUNCTION_POINTER(NPN_GetPropertyFP) getproperty;
543
FUNCTION_POINTER(NPN_SetPropertyFP) setproperty;
544
FUNCTION_POINTER(NPN_RemovePropertyFP) removeproperty;
545
FUNCTION_POINTER(NPN_HasPropertyFP) hasproperty;
546
FUNCTION_POINTER(NPN_HasMethodFP) hasmethod;
547
FUNCTION_POINTER(NPN_ReleaseVariantValueFP) releasevariantvalue;
548
FUNCTION_POINTER(NPN_SetExceptionFP) setexception;