1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 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 13 * distribution. 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. 17 * 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. 29 */ 30 31 #ifndef WebBindings_h 32 #define WebBindings_h 33 34 #include "../platform/WebCommon.h" 35 #include "../platform/WebString.h" 36 #include "../platform/WebVector.h" 37 #include <bindings/npruntime.h> 38 39 namespace v8 { 40 class Value; 41 template <class T> class Handle; 42 template <class T> class Local; 43 } 44 45 namespace WebKit { 46 47 class WebArrayBuffer; 48 class WebArrayBufferView; 49 class WebDragData; 50 class WebElement; 51 class WebNode; 52 class WebRange; 53 54 // A haphazard collection of functions for dealing with plugins. 55 class WebBindings { 56 public: 57 // NPN Functions ------------------------------------------------------ 58 // These are all defined in npruntime.h and are well documented. 59 60 // NPN_Construct 61 WEBKIT_EXPORT static bool construct(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result); 62 63 // NPN_CreateObject 64 WEBKIT_EXPORT static NPObject* createObject(NPP, NPClass*); 65 66 // NPN_Enumerate 67 WEBKIT_EXPORT static bool enumerate(NPP, NPObject*, NPIdentifier**, uint32_t* identifierCount); 68 69 // NPN_Evaluate 70 WEBKIT_EXPORT static bool evaluate(NPP, NPObject*, NPString* script, NPVariant* result); 71 72 // NPN_EvaluateHelper 73 WEBKIT_EXPORT static bool evaluateHelper(NPP, bool popupsAllowed, NPObject*, NPString* script, NPVariant* result); 74 75 // NPN_GetIntIdentifier 76 WEBKIT_EXPORT static NPIdentifier getIntIdentifier(int32_t number); 77 78 // NPN_GetProperty 79 WEBKIT_EXPORT static bool getProperty(NPP, NPObject*, NPIdentifier property, NPVariant *result); 80 81 // NPN_GetStringIdentifier 82 WEBKIT_EXPORT static NPIdentifier getStringIdentifier(const NPUTF8* string); 83 84 // NPN_GetStringIdentifiers 85 WEBKIT_EXPORT static void getStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdentifier*); 86 87 // NPN_HasMethod 88 WEBKIT_EXPORT static bool hasMethod(NPP, NPObject*, NPIdentifier method); 89 90 // NPN_HasProperty 91 WEBKIT_EXPORT static bool hasProperty(NPP, NPObject*, NPIdentifier property); 92 93 // NPN_IdentifierIsString 94 WEBKIT_EXPORT static bool identifierIsString(NPIdentifier); 95 96 // NPN_InitializeVariantWithStringCopy (though sometimes prefixed with an underscore) 97 WEBKIT_EXPORT static void initializeVariantWithStringCopy(NPVariant*, const NPString*); 98 99 // NPN_IntFromIdentifier 100 WEBKIT_EXPORT static int32_t intFromIdentifier(NPIdentifier); 101 102 // NPN_Invoke 103 WEBKIT_EXPORT static bool invoke(NPP, NPObject*, NPIdentifier method, const NPVariant* args, uint32_t argCount, NPVariant* result); 104 105 // NPN_InvokeDefault 106 WEBKIT_EXPORT static bool invokeDefault(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result); 107 108 // NPN_ReleaseObject 109 WEBKIT_EXPORT static void releaseObject(NPObject*); 110 111 // NPN_ReleaseVariantValue 112 WEBKIT_EXPORT static void releaseVariantValue(NPVariant*); 113 114 // NPN_RemoveProperty 115 WEBKIT_EXPORT static bool removeProperty(NPP, NPObject*, NPIdentifier); 116 117 // NPN_RetainObject 118 WEBKIT_EXPORT static NPObject* retainObject(NPObject*); 119 120 // NPN_SetException 121 WEBKIT_EXPORT static void setException(NPObject*, const NPUTF8* message); 122 123 // NPN_SetProperty 124 WEBKIT_EXPORT static bool setProperty(NPP, NPObject*, NPIdentifier, const NPVariant*); 125 126 // _NPN_RegisterObjectOwner 127 WEBKIT_EXPORT static void registerObjectOwner(NPP); 128 129 // _NPN_UnregisterObjectOwner 130 WEBKIT_EXPORT static void unregisterObjectOwner(NPP); 131 132 // Temporary dummy implementation of _NPN_GetObjectOwner. 133 WEBKIT_EXPORT static NPP getObjectOwner(NPObject*); 134 135 // _NPN_UnregisterObject 136 WEBKIT_EXPORT static void unregisterObject(NPObject*); 137 138 // NPN_UTF8FromIdentifier 139 WEBKIT_EXPORT static NPUTF8* utf8FromIdentifier(NPIdentifier); 140 141 // Miscellaneous utility functions ---------------------------------------- 142 143 // Complement to NPN_Get___Identifier functions. Extracts data from the NPIdentifier data 144 // structure. If isString is true upon return, string will be set but number's value is 145 // undefined. If iString is false, the opposite is true. 146 WEBKIT_EXPORT static void extractIdentifierData(const NPIdentifier&, const NPUTF8*& string, int32_t& number, bool& isString); 147 148 // DumpRenderTree support ------------------------------------------------- 149 150 // Return true (success) if the given npobj is a range object. 151 // If so, return that range as a WebRange object. 152 WEBKIT_EXPORT static bool getRange(NPObject* range, WebRange*); 153 154 // Return true (success) if the given npobj is an ArrayBuffer object. 155 // If so, return it as a WebArrayBuffer object. 156 WEBKIT_EXPORT static bool getArrayBuffer(NPObject* arrayBuffer, WebArrayBuffer*); 157 158 // Return true (success) if the given npobj is an ArrayBufferView object. 159 // If so, return it as a WebArrayBufferView object. 160 WEBKIT_EXPORT static bool getArrayBufferView(NPObject* arrayBufferView, WebArrayBufferView*); 161 162 // Return true (success) if the given npobj is a node. 163 // If so, return that node as a WebNode object. 164 WEBKIT_EXPORT static bool getNode(NPObject* element, WebNode*); 165 166 // Return true (success) if the given npobj is an element. 167 // If so, return that element as a WebElement object. 168 WEBKIT_EXPORT static bool getElement(NPObject* element, WebElement*); 169 170 WEBKIT_EXPORT static NPObject* makeIntArray(const WebVector<int>&); 171 WEBKIT_EXPORT static NPObject* makeStringArray(const WebVector<WebString>&); 172 173 // Exceptions ------------------------------------------------------------- 174 175 typedef void (ExceptionHandler)(void* data, const NPUTF8* message); 176 177 // The exception handler will be notified of any exceptions thrown while 178 // operating on a NPObject. 179 WEBKIT_EXPORT static void pushExceptionHandler(ExceptionHandler, void* data); 180 WEBKIT_EXPORT static void popExceptionHandler(); 181 182 // Conversion utilities to/from V8 native objects and NPVariant wrappers. 183 WEBKIT_EXPORT static void toNPVariant(v8::Local<v8::Value>, NPObject* root, NPVariant* result); 184 WEBKIT_EXPORT static v8::Handle<v8::Value> toV8Value(const NPVariant*); 185 }; 186 187 } // namespace WebKit 188 189 #endif 190