dom/plugins/base/npruntime.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /*
michael@0 3 * Copyright (c) 2004, Apple Computer, Inc. and The Mozilla Foundation.
michael@0 4 * All rights reserved.
michael@0 5 *
michael@0 6 * Redistribution and use in source and binary forms, with or without
michael@0 7 * modification, are permitted provided that the following conditions are
michael@0 8 * met:
michael@0 9 *
michael@0 10 * 1. Redistributions of source code must retain the above copyright
michael@0 11 * notice, this list of conditions and the following disclaimer.
michael@0 12 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 13 * notice, this list of conditions and the following disclaimer in the
michael@0 14 * documentation and/or other materials provided with the distribution.
michael@0 15 * 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla
michael@0 16 * Foundation ("Mozilla") nor the names of their contributors may be used
michael@0 17 * to endorse or promote products derived from this software without
michael@0 18 * specific prior written permission.
michael@0 19 *
michael@0 20 * THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS
michael@0 21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
michael@0 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
michael@0 23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE, MOZILLA OR
michael@0 24 * THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
michael@0 26 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 31 *
michael@0 32 */
michael@0 33 #ifndef _NP_RUNTIME_H_
michael@0 34 #define _NP_RUNTIME_H_
michael@0 35
michael@0 36 #ifdef __cplusplus
michael@0 37 extern "C" {
michael@0 38 #endif
michael@0 39
michael@0 40 #include "nptypes.h"
michael@0 41
michael@0 42 /*
michael@0 43 This API is used to facilitate binding code written in C to script
michael@0 44 objects. The API in this header does not assume the presence of a
michael@0 45 user agent. That is, it can be used to bind C code to scripting
michael@0 46 environments outside of the context of a user agent.
michael@0 47
michael@0 48 However, the normal use of the this API is in the context of a
michael@0 49 scripting environment running in a browser or other user agent.
michael@0 50 In particular it is used to support the extended Netscape
michael@0 51 script-ability API for plugins (NP-SAP). NP-SAP is an extension
michael@0 52 of the Netscape plugin API. As such we have adopted the use of
michael@0 53 the "NP" prefix for this API.
michael@0 54
michael@0 55 The following NP{N|P}Variables were added to the Netscape plugin
michael@0 56 API (in npapi.h):
michael@0 57
michael@0 58 NPNVWindowNPObject
michael@0 59 NPNVPluginElementNPObject
michael@0 60 NPPVpluginScriptableNPObject
michael@0 61
michael@0 62 These variables are exposed through NPN_GetValue() and
michael@0 63 NPP_GetValue() (respectively) and are used to establish the
michael@0 64 initial binding between the user agent and native code. The DOM
michael@0 65 objects in the user agent can be examined and manipulated using
michael@0 66 the NPN_ functions that operate on NPObjects described in this
michael@0 67 header.
michael@0 68
michael@0 69 To the extent possible the assumptions about the scripting
michael@0 70 language used by the scripting environment have been minimized.
michael@0 71 */
michael@0 72
michael@0 73 #define NP_BEGIN_MACRO do {
michael@0 74 #define NP_END_MACRO } while (0)
michael@0 75
michael@0 76 /*
michael@0 77 Objects (non-primitive data) passed between 'C' and script is
michael@0 78 always wrapped in an NPObject. The 'interface' of an NPObject is
michael@0 79 described by an NPClass.
michael@0 80 */
michael@0 81 typedef struct NPObject NPObject;
michael@0 82 typedef struct NPClass NPClass;
michael@0 83
michael@0 84 typedef char NPUTF8;
michael@0 85 typedef struct _NPString {
michael@0 86 const NPUTF8 *UTF8Characters;
michael@0 87 uint32_t UTF8Length;
michael@0 88 } NPString;
michael@0 89
michael@0 90 typedef enum {
michael@0 91 NPVariantType_Void,
michael@0 92 NPVariantType_Null,
michael@0 93 NPVariantType_Bool,
michael@0 94 NPVariantType_Int32,
michael@0 95 NPVariantType_Double,
michael@0 96 NPVariantType_String,
michael@0 97 NPVariantType_Object
michael@0 98 } NPVariantType;
michael@0 99
michael@0 100 typedef struct _NPVariant {
michael@0 101 NPVariantType type;
michael@0 102 union {
michael@0 103 bool boolValue;
michael@0 104 int32_t intValue;
michael@0 105 double doubleValue;
michael@0 106 NPString stringValue;
michael@0 107 NPObject *objectValue;
michael@0 108 } value;
michael@0 109 } NPVariant;
michael@0 110
michael@0 111 /*
michael@0 112 NPN_ReleaseVariantValue is called on all 'out' parameters
michael@0 113 references. Specifically it is to be called on variants that own
michael@0 114 their value, as is the case with all non-const NPVariant*
michael@0 115 arguments after a successful call to any methods (except this one)
michael@0 116 in this API.
michael@0 117
michael@0 118 After calling NPN_ReleaseVariantValue, the type of the variant
michael@0 119 will be NPVariantType_Void.
michael@0 120 */
michael@0 121 void NPN_ReleaseVariantValue(NPVariant *variant);
michael@0 122
michael@0 123 #define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void)
michael@0 124 #define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null)
michael@0 125 #define NPVARIANT_IS_BOOLEAN(_v) ((_v).type == NPVariantType_Bool)
michael@0 126 #define NPVARIANT_IS_INT32(_v) ((_v).type == NPVariantType_Int32)
michael@0 127 #define NPVARIANT_IS_DOUBLE(_v) ((_v).type == NPVariantType_Double)
michael@0 128 #define NPVARIANT_IS_STRING(_v) ((_v).type == NPVariantType_String)
michael@0 129 #define NPVARIANT_IS_OBJECT(_v) ((_v).type == NPVariantType_Object)
michael@0 130
michael@0 131 #define NPVARIANT_TO_BOOLEAN(_v) ((_v).value.boolValue)
michael@0 132 #define NPVARIANT_TO_INT32(_v) ((_v).value.intValue)
michael@0 133 #define NPVARIANT_TO_DOUBLE(_v) ((_v).value.doubleValue)
michael@0 134 #define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue)
michael@0 135 #define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue)
michael@0 136
michael@0 137 #define VOID_TO_NPVARIANT(_v) \
michael@0 138 NP_BEGIN_MACRO \
michael@0 139 (_v).type = NPVariantType_Void; \
michael@0 140 (_v).value.objectValue = NULL; \
michael@0 141 NP_END_MACRO
michael@0 142
michael@0 143 #define NULL_TO_NPVARIANT(_v) \
michael@0 144 NP_BEGIN_MACRO \
michael@0 145 (_v).type = NPVariantType_Null; \
michael@0 146 (_v).value.objectValue = NULL; \
michael@0 147 NP_END_MACRO
michael@0 148
michael@0 149 #define BOOLEAN_TO_NPVARIANT(_val, _v) \
michael@0 150 NP_BEGIN_MACRO \
michael@0 151 (_v).type = NPVariantType_Bool; \
michael@0 152 (_v).value.boolValue = !!(_val); \
michael@0 153 NP_END_MACRO
michael@0 154
michael@0 155 #define INT32_TO_NPVARIANT(_val, _v) \
michael@0 156 NP_BEGIN_MACRO \
michael@0 157 (_v).type = NPVariantType_Int32; \
michael@0 158 (_v).value.intValue = _val; \
michael@0 159 NP_END_MACRO
michael@0 160
michael@0 161 #define DOUBLE_TO_NPVARIANT(_val, _v) \
michael@0 162 NP_BEGIN_MACRO \
michael@0 163 (_v).type = NPVariantType_Double; \
michael@0 164 (_v).value.doubleValue = _val; \
michael@0 165 NP_END_MACRO
michael@0 166
michael@0 167 #define STRINGZ_TO_NPVARIANT(_val, _v) \
michael@0 168 NP_BEGIN_MACRO \
michael@0 169 (_v).type = NPVariantType_String; \
michael@0 170 NPString str = { _val, (uint32_t)(strlen(_val)) }; \
michael@0 171 (_v).value.stringValue = str; \
michael@0 172 NP_END_MACRO
michael@0 173
michael@0 174 #define STRINGN_TO_NPVARIANT(_val, _len, _v) \
michael@0 175 NP_BEGIN_MACRO \
michael@0 176 (_v).type = NPVariantType_String; \
michael@0 177 NPString str = { _val, (uint32_t)(_len) }; \
michael@0 178 (_v).value.stringValue = str; \
michael@0 179 NP_END_MACRO
michael@0 180
michael@0 181 #define OBJECT_TO_NPVARIANT(_val, _v) \
michael@0 182 NP_BEGIN_MACRO \
michael@0 183 (_v).type = NPVariantType_Object; \
michael@0 184 (_v).value.objectValue = _val; \
michael@0 185 NP_END_MACRO
michael@0 186
michael@0 187
michael@0 188 /*
michael@0 189 Type mappings (JavaScript types have been used for illustration
michael@0 190 purposes):
michael@0 191
michael@0 192 JavaScript to C (NPVariant with type:)
michael@0 193 undefined NPVariantType_Void
michael@0 194 null NPVariantType_Null
michael@0 195 Boolean NPVariantType_Bool
michael@0 196 Number NPVariantType_Double or NPVariantType_Int32
michael@0 197 String NPVariantType_String
michael@0 198 Object NPVariantType_Object
michael@0 199
michael@0 200 C (NPVariant with type:) to JavaScript
michael@0 201 NPVariantType_Void undefined
michael@0 202 NPVariantType_Null null
michael@0 203 NPVariantType_Bool Boolean
michael@0 204 NPVariantType_Int32 Number
michael@0 205 NPVariantType_Double Number
michael@0 206 NPVariantType_String String
michael@0 207 NPVariantType_Object Object
michael@0 208 */
michael@0 209
michael@0 210 typedef void *NPIdentifier;
michael@0 211
michael@0 212 /*
michael@0 213 NPObjects have methods and properties. Methods and properties are
michael@0 214 identified with NPIdentifiers. These identifiers may be reflected
michael@0 215 in script. NPIdentifiers can be either strings or integers, IOW,
michael@0 216 methods and properties can be identified by either strings or
michael@0 217 integers (i.e. foo["bar"] vs foo[1]). NPIdentifiers can be
michael@0 218 compared using ==. In case of any errors, the requested
michael@0 219 NPIdentifier(s) will be NULL. NPIdentifier lifetime is controlled
michael@0 220 by the browser. Plugins do not need to worry about memory management
michael@0 221 with regards to NPIdentifiers.
michael@0 222 */
michael@0 223 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name);
michael@0 224 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
michael@0 225 NPIdentifier *identifiers);
michael@0 226 NPIdentifier NPN_GetIntIdentifier(int32_t intid);
michael@0 227 bool NPN_IdentifierIsString(NPIdentifier identifier);
michael@0 228
michael@0 229 /*
michael@0 230 The NPUTF8 returned from NPN_UTF8FromIdentifier SHOULD be freed.
michael@0 231 */
michael@0 232 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier);
michael@0 233
michael@0 234 /*
michael@0 235 Get the integer represented by identifier. If identifier is not an
michael@0 236 integer identifier, the behaviour is undefined.
michael@0 237 */
michael@0 238 int32_t NPN_IntFromIdentifier(NPIdentifier identifier);
michael@0 239
michael@0 240 /*
michael@0 241 NPObject behavior is implemented using the following set of
michael@0 242 callback functions.
michael@0 243
michael@0 244 The NPVariant *result argument of these functions (where
michael@0 245 applicable) should be released using NPN_ReleaseVariantValue().
michael@0 246 */
michael@0 247 typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass);
michael@0 248 typedef void (*NPDeallocateFunctionPtr)(NPObject *npobj);
michael@0 249 typedef void (*NPInvalidateFunctionPtr)(NPObject *npobj);
michael@0 250 typedef bool (*NPHasMethodFunctionPtr)(NPObject *npobj, NPIdentifier name);
michael@0 251 typedef bool (*NPInvokeFunctionPtr)(NPObject *npobj, NPIdentifier name,
michael@0 252 const NPVariant *args, uint32_t argCount,
michael@0 253 NPVariant *result);
michael@0 254 typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj,
michael@0 255 const NPVariant *args,
michael@0 256 uint32_t argCount,
michael@0 257 NPVariant *result);
michael@0 258 typedef bool (*NPHasPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
michael@0 259 typedef bool (*NPGetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name,
michael@0 260 NPVariant *result);
michael@0 261 typedef bool (*NPSetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name,
michael@0 262 const NPVariant *value);
michael@0 263 typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj,
michael@0 264 NPIdentifier name);
michael@0 265 typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value,
michael@0 266 uint32_t *count);
michael@0 267 typedef bool (*NPConstructFunctionPtr)(NPObject *npobj,
michael@0 268 const NPVariant *args,
michael@0 269 uint32_t argCount,
michael@0 270 NPVariant *result);
michael@0 271
michael@0 272 /*
michael@0 273 NPObjects returned by create, retain, invoke, and getProperty pass
michael@0 274 a reference count to the caller. That is, the callee adds a
michael@0 275 reference count which passes to the caller. It is the caller's
michael@0 276 responsibility to release the returned object.
michael@0 277
michael@0 278 NPInvokeFunctionPtr function may return 0 to indicate a void
michael@0 279 result.
michael@0 280
michael@0 281 NPInvalidateFunctionPtr is called by the scripting environment
michael@0 282 when the native code is shutdown. Any attempt to message a
michael@0 283 NPObject instance after the invalidate callback has been
michael@0 284 called will result in undefined behavior, even if the native code
michael@0 285 is still retaining those NPObject instances. (The runtime
michael@0 286 will typically return immediately, with 0 or NULL, from an
michael@0 287 attempt to dispatch to a NPObject, but this behavior should not
michael@0 288 be depended upon.)
michael@0 289
michael@0 290 The NPEnumerationFunctionPtr function may pass an array of
michael@0 291 NPIdentifiers back to the caller. The callee allocs the memory of
michael@0 292 the array using NPN_MemAlloc(), and it's the caller's responsibility
michael@0 293 to release it using NPN_MemFree().
michael@0 294 */
michael@0 295 struct NPClass
michael@0 296 {
michael@0 297 uint32_t structVersion;
michael@0 298 NPAllocateFunctionPtr allocate;
michael@0 299 NPDeallocateFunctionPtr deallocate;
michael@0 300 NPInvalidateFunctionPtr invalidate;
michael@0 301 NPHasMethodFunctionPtr hasMethod;
michael@0 302 NPInvokeFunctionPtr invoke;
michael@0 303 NPInvokeDefaultFunctionPtr invokeDefault;
michael@0 304 NPHasPropertyFunctionPtr hasProperty;
michael@0 305 NPGetPropertyFunctionPtr getProperty;
michael@0 306 NPSetPropertyFunctionPtr setProperty;
michael@0 307 NPRemovePropertyFunctionPtr removeProperty;
michael@0 308 NPEnumerationFunctionPtr enumerate;
michael@0 309 NPConstructFunctionPtr construct;
michael@0 310 };
michael@0 311
michael@0 312 #define NP_CLASS_STRUCT_VERSION 3
michael@0 313
michael@0 314 #define NP_CLASS_STRUCT_VERSION_ENUM 2
michael@0 315 #define NP_CLASS_STRUCT_VERSION_CTOR 3
michael@0 316
michael@0 317 #define NP_CLASS_STRUCT_VERSION_HAS_ENUM(npclass) \
michael@0 318 ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM)
michael@0 319
michael@0 320 #define NP_CLASS_STRUCT_VERSION_HAS_CTOR(npclass) \
michael@0 321 ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_CTOR)
michael@0 322
michael@0 323 struct NPObject {
michael@0 324 NPClass *_class;
michael@0 325 uint32_t referenceCount;
michael@0 326 /*
michael@0 327 * Additional space may be allocated here by types of NPObjects
michael@0 328 */
michael@0 329 };
michael@0 330
michael@0 331 /*
michael@0 332 If the class has an allocate function, NPN_CreateObject invokes
michael@0 333 that function, otherwise a NPObject is allocated and
michael@0 334 returned. This method will initialize the referenceCount member of
michael@0 335 the NPObject to 1.
michael@0 336 */
michael@0 337 NPObject *NPN_CreateObject(NPP npp, NPClass *aClass);
michael@0 338
michael@0 339 /*
michael@0 340 Increment the NPObject's reference count.
michael@0 341 */
michael@0 342 NPObject *NPN_RetainObject(NPObject *npobj);
michael@0 343
michael@0 344 /*
michael@0 345 Decremented the NPObject's reference count. If the reference
michael@0 346 count goes to zero, the class's destroy function is invoke if
michael@0 347 specified, otherwise the object is freed directly.
michael@0 348 */
michael@0 349 void NPN_ReleaseObject(NPObject *npobj);
michael@0 350
michael@0 351 /*
michael@0 352 Functions to access script objects represented by NPObject.
michael@0 353
michael@0 354 Calls to script objects are synchronous. If a function returns a
michael@0 355 value, it will be supplied via the result NPVariant
michael@0 356 argument. Successful calls will return true, false will be
michael@0 357 returned in case of an error.
michael@0 358
michael@0 359 Calls made from plugin code to script must be made from the thread
michael@0 360 on which the plugin was initialized.
michael@0 361 */
michael@0 362
michael@0 363 bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName,
michael@0 364 const NPVariant *args, uint32_t argCount, NPVariant *result);
michael@0 365 bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args,
michael@0 366 uint32_t argCount, NPVariant *result);
michael@0 367 bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script,
michael@0 368 NPVariant *result);
michael@0 369 bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
michael@0 370 NPVariant *result);
michael@0 371 bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
michael@0 372 const NPVariant *value);
michael@0 373 bool NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
michael@0 374 bool NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
michael@0 375 bool NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName);
michael@0 376 bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
michael@0 377 uint32_t *count);
michael@0 378 bool NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args,
michael@0 379 uint32_t argCount, NPVariant *result);
michael@0 380
michael@0 381 /*
michael@0 382 NPN_SetException may be called to trigger a script exception upon
michael@0 383 return from entry points into NPObjects. Typical usage:
michael@0 384
michael@0 385 NPN_SetException (npobj, message);
michael@0 386 */
michael@0 387 void NPN_SetException(NPObject *npobj, const NPUTF8 *message);
michael@0 388
michael@0 389 #ifdef __cplusplus
michael@0 390 }
michael@0 391 #endif
michael@0 392
michael@0 393 #endif

mercurial