15267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/* 25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright (C) 2009 Google Inc. All rights reserved. 35267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 45267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * modification, are permitted provided that the following conditions are 65267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * met: 75267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 85267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 95267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * * Redistributions in binary form must reproduce the above 115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * in the documentation and/or other materials provided with the 135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * distribution. 145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * contributors may be used to endorse or promote products derived from 165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * this software without specific prior written permission. 175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */ 305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#ifndef WebBindings_h 325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#define WebBindings_h 335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "../platform/WebCommon.h" 355267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "../platform/WebString.h" 365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "../platform/WebVector.h" 375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include <bindings/npruntime.h> 385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)namespace v8 { 405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class Value; 415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)template <class T> class Handle; 425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)template <class T> class Local; 435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)} 445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)namespace WebKit { 465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebArrayBuffer; 485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebArrayBufferView; 495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebDragData; 505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebElement; 515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebNode; 525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebRange; 535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// A haphazard collection of functions for dealing with plugins. 555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebBindings { 565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)public: 575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN Functions ------------------------------------------------------ 585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // These are all defined in npruntime.h and are well documented. 595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_Construct 615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool construct(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result); 625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_CreateObject 645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPObject* createObject(NPP, NPClass*); 655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_Enumerate 675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool enumerate(NPP, NPObject*, NPIdentifier**, uint32_t* identifierCount); 685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 695267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_Evaluate 705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool evaluate(NPP, NPObject*, NPString* script, NPVariant* result); 715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_EvaluateHelper 735267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool evaluateHelper(NPP, bool popupsAllowed, NPObject*, NPString* script, NPVariant* result); 745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_GetIntIdentifier 765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPIdentifier getIntIdentifier(int32_t number); 775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_GetProperty 795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool getProperty(NPP, NPObject*, NPIdentifier property, NPVariant *result); 805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_GetStringIdentifier 825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPIdentifier getStringIdentifier(const NPUTF8* string); 835267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_GetStringIdentifiers 855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void getStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdentifier*); 865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_HasMethod 885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool hasMethod(NPP, NPObject*, NPIdentifier method); 895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 905267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_HasProperty 915267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool hasProperty(NPP, NPObject*, NPIdentifier property); 925267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 935267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_IdentifierIsString 945267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool identifierIsString(NPIdentifier); 955267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 965267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_InitializeVariantWithStringCopy (though sometimes prefixed with an underscore) 975267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void initializeVariantWithStringCopy(NPVariant*, const NPString*); 985267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 995267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_IntFromIdentifier 1005267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static int32_t intFromIdentifier(NPIdentifier); 1015267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1025267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_Invoke 1035267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool invoke(NPP, NPObject*, NPIdentifier method, const NPVariant* args, uint32_t argCount, NPVariant* result); 1045267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1055267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_InvokeDefault 1065267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool invokeDefault(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result); 1075267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1085267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_ReleaseObject 1095267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void releaseObject(NPObject*); 1105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_ReleaseVariantValue 1125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void releaseVariantValue(NPVariant*); 1135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_RemoveProperty 1155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool removeProperty(NPP, NPObject*, NPIdentifier); 1165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_RetainObject 1185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPObject* retainObject(NPObject*); 1195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_SetException 1215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void setException(NPObject*, const NPUTF8* message); 1225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_SetProperty 1245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool setProperty(NPP, NPObject*, NPIdentifier, const NPVariant*); 1255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // _NPN_RegisterObjectOwner 1275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void registerObjectOwner(NPP); 1285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // _NPN_UnregisterObjectOwner 1305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void unregisterObjectOwner(NPP); 1315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 132e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // Temporary dummy implementation of _NPN_GetObjectOwner. 133591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch WEBKIT_EXPORT static NPP getObjectOwner(NPObject*); 134591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 135e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // _NPN_UnregisterObject 1365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void unregisterObject(NPObject*); 1375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // NPN_UTF8FromIdentifier 1395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPUTF8* utf8FromIdentifier(NPIdentifier); 1405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Miscellaneous utility functions ---------------------------------------- 1425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Complement to NPN_Get___Identifier functions. Extracts data from the NPIdentifier data 1445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // structure. If isString is true upon return, string will be set but number's value is 1455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // undefined. If iString is false, the opposite is true. 1465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void extractIdentifierData(const NPIdentifier&, const NPUTF8*& string, int32_t& number, bool& isString); 1475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // DumpRenderTree support ------------------------------------------------- 1495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Return true (success) if the given npobj is a range object. 1515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // If so, return that range as a WebRange object. 1525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool getRange(NPObject* range, WebRange*); 1535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Return true (success) if the given npobj is an ArrayBuffer object. 1555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // If so, return it as a WebArrayBuffer object. 1565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool getArrayBuffer(NPObject* arrayBuffer, WebArrayBuffer*); 1575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Return true (success) if the given npobj is an ArrayBufferView object. 1595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // If so, return it as a WebArrayBufferView object. 1605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool getArrayBufferView(NPObject* arrayBufferView, WebArrayBufferView*); 1615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Return true (success) if the given npobj is a node. 1635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // If so, return that node as a WebNode object. 1645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool getNode(NPObject* element, WebNode*); 1655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Return true (success) if the given npobj is an element. 1675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // If so, return that element as a WebElement object. 1685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static bool getElement(NPObject* element, WebElement*); 1695267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPObject* makeIntArray(const WebVector<int>&); 1715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static NPObject* makeStringArray(const WebVector<WebString>&); 1725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1735267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Exceptions ------------------------------------------------------------- 1745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) typedef void (ExceptionHandler)(void* data, const NPUTF8* message); 1765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // The exception handler will be notified of any exceptions thrown while 1785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // operating on a NPObject. 1795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void pushExceptionHandler(ExceptionHandler, void* data); 1805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static void popExceptionHandler(); 1815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // Conversion utilities to/from V8 native objects and NPVariant wrappers. 183e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch WEBKIT_EXPORT static void toNPVariant(v8::Local<v8::Value>, NPObject* root, NPVariant* result); 1845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) WEBKIT_EXPORT static v8::Handle<v8::Value> toV8Value(const NPVariant*); 1855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)}; 1865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)} // namespace WebKit 1885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 1895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#endif 190