2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "../platform/WebCommon.h"
35 #include "../platform/WebString.h"
36 #include "../platform/WebVector.h"
37 #include <bindings/npruntime.h>
41 template <class T
> class Local
;
47 class WebArrayBufferView
;
52 // A haphazard collection of functions for dealing with plugins.
55 // NPN Functions ------------------------------------------------------
56 // These are all defined in npruntime.h and are well documented.
59 BLINK_EXPORT
static bool construct(NPP
, NPObject
*, const NPVariant
* args
, uint32_t argCount
, NPVariant
* result
);
62 BLINK_EXPORT
static NPObject
* createObject(NPP
, NPClass
*);
65 BLINK_EXPORT
static bool enumerate(NPP
, NPObject
*, NPIdentifier
**, uint32_t* identifierCount
);
68 BLINK_EXPORT
static bool evaluate(NPP
, NPObject
*, NPString
* script
, NPVariant
* result
);
71 BLINK_EXPORT
static bool evaluateHelper(NPP
, bool popupsAllowed
, NPObject
*, NPString
* script
, NPVariant
* result
);
73 // NPN_GetIntIdentifier
74 BLINK_EXPORT
static NPIdentifier
getIntIdentifier(int32_t number
);
77 BLINK_EXPORT
static bool getProperty(NPP
, NPObject
*, NPIdentifier property
, NPVariant
*result
);
79 // NPN_GetStringIdentifier
80 BLINK_EXPORT
static NPIdentifier
getStringIdentifier(const NPUTF8
* string
);
82 // NPN_GetStringIdentifiers
83 BLINK_EXPORT
static void getStringIdentifiers(const NPUTF8
** names
, int32_t nameCount
, NPIdentifier
*);
86 BLINK_EXPORT
static bool hasMethod(NPP
, NPObject
*, NPIdentifier method
);
89 BLINK_EXPORT
static bool hasProperty(NPP
, NPObject
*, NPIdentifier property
);
91 // NPN_IdentifierIsString
92 BLINK_EXPORT
static bool identifierIsString(NPIdentifier
);
94 // NPN_InitializeVariantWithStringCopy (though sometimes prefixed with an underscore)
95 BLINK_EXPORT
static void initializeVariantWithStringCopy(NPVariant
*, const NPString
*);
97 // NPN_IntFromIdentifier
98 BLINK_EXPORT
static int32_t intFromIdentifier(NPIdentifier
);
101 BLINK_EXPORT
static bool invoke(NPP
, NPObject
*, NPIdentifier method
, const NPVariant
* args
, uint32_t argCount
, NPVariant
* result
);
104 BLINK_EXPORT
static bool invokeDefault(NPP
, NPObject
*, const NPVariant
* args
, uint32_t argCount
, NPVariant
* result
);
107 BLINK_EXPORT
static void releaseObject(NPObject
*);
109 // NPN_ReleaseVariantValue
110 BLINK_EXPORT
static void releaseVariantValue(NPVariant
*);
112 // NPN_RemoveProperty
113 BLINK_EXPORT
static bool removeProperty(NPP
, NPObject
*, NPIdentifier
);
116 BLINK_EXPORT
static NPObject
* retainObject(NPObject
*);
119 BLINK_EXPORT
static void setException(NPObject
*, const NPUTF8
* message
);
122 BLINK_EXPORT
static bool setProperty(NPP
, NPObject
*, NPIdentifier
, const NPVariant
*);
124 // _NPN_RegisterObjectOwner
125 BLINK_EXPORT
static void registerObjectOwner(NPP
);
127 // _NPN_UnregisterObjectOwner
128 BLINK_EXPORT
static void unregisterObjectOwner(NPP
);
130 // Temporary dummy implementation of _NPN_GetObjectOwner.
131 BLINK_EXPORT
static NPP
getObjectOwner(NPObject
*);
133 // _NPN_UnregisterObject
134 BLINK_EXPORT
static void unregisterObject(NPObject
*);
136 // Unlike unregisterObject, only drops the V8 wrapper object,
137 // not touching the NPObject itself, except for decrementing
138 // its references counter.
139 BLINK_EXPORT
static void dropV8WrapperForObject(NPObject
*);
141 // NPN_UTF8FromIdentifier
142 BLINK_EXPORT
static NPUTF8
* utf8FromIdentifier(NPIdentifier
);
144 // Miscellaneous utility functions ----------------------------------------
146 // Complement to NPN_Get___Identifier functions. Extracts data from the NPIdentifier data
147 // structure. If isString is true upon return, string will be set but number's value is
148 // undefined. If iString is false, the opposite is true.
149 BLINK_EXPORT
static void extractIdentifierData(const NPIdentifier
&, const NPUTF8
*& string
, int32_t& number
, bool& isString
);
151 // DumpRenderTree support -------------------------------------------------
153 // Return true (success) if the given npobj is a range object.
154 // If so, return that range as a WebRange object.
155 BLINK_EXPORT
static bool getRange(NPObject
* range
, WebRange
*);
157 // Return true (success) if the given npobj is an ArrayBuffer object.
158 // If so, return it as a WebArrayBuffer object.
159 BLINK_EXPORT
static bool getArrayBuffer(NPObject
* arrayBuffer
, WebArrayBuffer
*);
161 // Return true (success) if the given npobj is an ArrayBufferView object.
162 // If so, return it as a WebArrayBufferView object.
163 BLINK_EXPORT
static bool getArrayBufferView(NPObject
* arrayBufferView
, WebArrayBufferView
*);
165 // Return true (success) if the given npobj is a node.
166 // If so, return that node as a WebNode object.
167 BLINK_EXPORT
static bool getNode(NPObject
* element
, WebNode
*);
169 // Return true (success) if the given npobj is an element.
170 // If so, return that element as a WebElement object.
171 BLINK_EXPORT
static bool getElement(NPObject
* element
, WebElement
*);
173 BLINK_EXPORT
static NPObject
* makeIntArray(const WebVector
<int>&);
174 BLINK_EXPORT
static NPObject
* makeStringArray(const WebVector
<WebString
>&);
176 // Exceptions -------------------------------------------------------------
178 typedef void (ExceptionHandler
)(void* data
, const NPUTF8
* message
);
180 // The exception handler will be notified of any exceptions thrown while
181 // operating on a NPObject.
182 BLINK_EXPORT
static void pushExceptionHandler(ExceptionHandler
, void* data
);
183 BLINK_EXPORT
static void popExceptionHandler();
185 // Conversion utilities to/from V8 native objects and NPVariant wrappers.
186 BLINK_EXPORT
static void toNPVariant(v8::Local
<v8::Value
>, NPObject
* root
, NPVariant
* result
);
187 BLINK_EXPORT
static v8::Local
<v8::Value
> toV8Value(const NPVariant
*);