Home | History | Annotate | Download | only in web
      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 blink {
     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     BLINK_EXPORT static bool construct(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result);
     62 
     63     // NPN_CreateObject
     64     BLINK_EXPORT static NPObject* createObject(NPP, NPClass*);
     65 
     66     // NPN_Enumerate
     67     BLINK_EXPORT static bool enumerate(NPP, NPObject*, NPIdentifier**, uint32_t* identifierCount);
     68 
     69     // NPN_Evaluate
     70     BLINK_EXPORT static bool evaluate(NPP, NPObject*, NPString* script, NPVariant* result);
     71 
     72     // NPN_EvaluateHelper
     73     BLINK_EXPORT static bool evaluateHelper(NPP, bool popupsAllowed, NPObject*, NPString* script, NPVariant* result);
     74 
     75     // NPN_GetIntIdentifier
     76     BLINK_EXPORT static NPIdentifier getIntIdentifier(int32_t number);
     77 
     78     // NPN_GetProperty
     79     BLINK_EXPORT static bool getProperty(NPP, NPObject*, NPIdentifier property, NPVariant *result);
     80 
     81     // NPN_GetStringIdentifier
     82     BLINK_EXPORT static NPIdentifier getStringIdentifier(const NPUTF8* string);
     83 
     84     // NPN_GetStringIdentifiers
     85     BLINK_EXPORT static void getStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdentifier*);
     86 
     87     // NPN_HasMethod
     88     BLINK_EXPORT static bool hasMethod(NPP, NPObject*, NPIdentifier method);
     89 
     90     // NPN_HasProperty
     91     BLINK_EXPORT static bool hasProperty(NPP, NPObject*, NPIdentifier property);
     92 
     93     // NPN_IdentifierIsString
     94     BLINK_EXPORT static bool identifierIsString(NPIdentifier);
     95 
     96     // NPN_InitializeVariantWithStringCopy (though sometimes prefixed with an underscore)
     97     BLINK_EXPORT static void initializeVariantWithStringCopy(NPVariant*, const NPString*);
     98 
     99     // NPN_IntFromIdentifier
    100     BLINK_EXPORT static int32_t intFromIdentifier(NPIdentifier);
    101 
    102     // NPN_Invoke
    103     BLINK_EXPORT static bool invoke(NPP, NPObject*, NPIdentifier method, const NPVariant* args, uint32_t argCount, NPVariant* result);
    104 
    105     // NPN_InvokeDefault
    106     BLINK_EXPORT static bool invokeDefault(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result);
    107 
    108     // NPN_ReleaseObject
    109     BLINK_EXPORT static void releaseObject(NPObject*);
    110 
    111     // NPN_ReleaseVariantValue
    112     BLINK_EXPORT static void releaseVariantValue(NPVariant*);
    113 
    114     // NPN_RemoveProperty
    115     BLINK_EXPORT static bool removeProperty(NPP, NPObject*, NPIdentifier);
    116 
    117     // NPN_RetainObject
    118     BLINK_EXPORT static NPObject* retainObject(NPObject*);
    119 
    120     // NPN_SetException
    121     BLINK_EXPORT static void setException(NPObject*, const NPUTF8* message);
    122 
    123     // NPN_SetProperty
    124     BLINK_EXPORT static bool setProperty(NPP, NPObject*, NPIdentifier, const NPVariant*);
    125 
    126     // _NPN_RegisterObjectOwner
    127     BLINK_EXPORT static void registerObjectOwner(NPP);
    128 
    129     // _NPN_UnregisterObjectOwner
    130     BLINK_EXPORT static void unregisterObjectOwner(NPP);
    131 
    132     // Temporary dummy implementation of _NPN_GetObjectOwner.
    133     BLINK_EXPORT static NPP getObjectOwner(NPObject*);
    134 
    135     // _NPN_UnregisterObject
    136     BLINK_EXPORT static void unregisterObject(NPObject*);
    137 
    138     // Unlike unregisterObject, only drops the V8 wrapper object,
    139     // not touching the NPObject itself, except for decrementing
    140     // its references counter.
    141     BLINK_EXPORT static void dropV8WrapperForObject(NPObject*);
    142 
    143     // NPN_UTF8FromIdentifier
    144     BLINK_EXPORT static NPUTF8* utf8FromIdentifier(NPIdentifier);
    145 
    146     // Miscellaneous utility functions ----------------------------------------
    147 
    148     // Complement to NPN_Get___Identifier functions.  Extracts data from the NPIdentifier data
    149     // structure.  If isString is true upon return, string will be set but number's value is
    150     // undefined.  If iString is false, the opposite is true.
    151     BLINK_EXPORT static void extractIdentifierData(const NPIdentifier&, const NPUTF8*& string, int32_t& number, bool& isString);
    152 
    153     // DumpRenderTree support -------------------------------------------------
    154 
    155     // Return true (success) if the given npobj is a range object.
    156     // If so, return that range as a WebRange object.
    157     BLINK_EXPORT static bool getRange(NPObject* range, WebRange*);
    158 
    159     // Return true (success) if the given npobj is an ArrayBuffer object.
    160     // If so, return it as a WebArrayBuffer object.
    161     BLINK_EXPORT static bool getArrayBuffer(NPObject* arrayBuffer, WebArrayBuffer*);
    162 
    163     // Return true (success) if the given npobj is an ArrayBufferView object.
    164     // If so, return it as a WebArrayBufferView object.
    165     BLINK_EXPORT static bool getArrayBufferView(NPObject* arrayBufferView, WebArrayBufferView*);
    166 
    167     // Return true (success) if the given npobj is a node.
    168     // If so, return that node as a WebNode object.
    169     BLINK_EXPORT static bool getNode(NPObject* element, WebNode*);
    170 
    171     // Return true (success) if the given npobj is an element.
    172     // If so, return that element as a WebElement object.
    173     BLINK_EXPORT static bool getElement(NPObject* element, WebElement*);
    174 
    175     BLINK_EXPORT static NPObject* makeIntArray(const WebVector<int>&);
    176     BLINK_EXPORT static NPObject* makeStringArray(const WebVector<WebString>&);
    177 
    178     // Exceptions -------------------------------------------------------------
    179 
    180     typedef void (ExceptionHandler)(void* data, const NPUTF8* message);
    181 
    182     // The exception handler will be notified of any exceptions thrown while
    183     // operating on a NPObject.
    184     BLINK_EXPORT static void pushExceptionHandler(ExceptionHandler, void* data);
    185     BLINK_EXPORT static void popExceptionHandler();
    186 
    187     // Conversion utilities to/from V8 native objects and NPVariant wrappers.
    188     BLINK_EXPORT static void toNPVariant(v8::Local<v8::Value>, NPObject* root, NPVariant* result);
    189     BLINK_EXPORT static v8::Handle<v8::Value> toV8Value(const NPVariant*);
    190 };
    191 
    192 } // namespace blink
    193 
    194 #endif
    195