Home | History | Annotate | Download | only in dev
      1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2  * Use of this source code is governed by a BSD-style license that can be
      3  * found in the LICENSE file.
      4  */
      5 #ifndef PPAPI_C_PPP_CLASS_DEPRECATED_H_
      6 #define PPAPI_C_PPP_CLASS_DEPRECATED_H_
      7 
      8 #include "ppapi/c/dev/deprecated_bool.h"
      9 #include "ppapi/c/pp_stdint.h"
     10 #include "ppapi/c/pp_var.h"
     11 
     12 /**
     13  * @file
     14  * Defines the PPP_Class_Deprecated struct.
     15  *
     16  * @addtogroup PPP
     17  * @{
     18  */
     19 
     20 struct PP_Var;
     21 
     22 /**
     23  * Interface for the plugin to implement JavaScript-accessible objects.
     24  *
     25  * This interface has no interface name. Instead, the plugin passes a pointer
     26  * to this interface to PPB_Var_Deprecated.CreateObject that corresponds to the
     27  * object being implemented.
     28  *
     29  * See the PPB_Var_Deprecated interface for more information on these functions.
     30  * This interface just allows you to implement the "back end" of those
     31  * functions, so most of the contract is specified in that interface.
     32  *
     33  * See
     34  *   http://code.google.com/p/ppapi/wiki/InterfacingWithJavaScript
     35  * for general information on using and implementing vars.
     36  */
     37 struct PPP_Class_Deprecated {
     38   /**
     39    * |name| is guaranteed to be an integer or string type var. Exception is
     40    * guaranteed non-NULL. An integer is used for |name| when implementing
     41    * array access into the object. This test should only return true for
     42    * properties that are not methods.  Use HasMethod() to handle methods.
     43    */
     44   bool (*HasProperty)(void* object,
     45                       struct PP_Var name,
     46                       struct PP_Var* exception);
     47 
     48   /**
     49    * |name| is guaranteed to be a string-type. Exception is guaranteed non-NULL.
     50    * If the method does not exist, return false and don't set the exception.
     51    * Errors in this function will probably not occur in general usage, but
     52    * if you need to throw an exception, still return false.
     53    */
     54   bool (*HasMethod)(void* object,
     55                     struct PP_Var name,
     56                     struct PP_Var* exception);
     57 
     58   /**
     59    * |name| is guaranteed to be a string-type or an integer-type var. Exception
     60    * is guaranteed non-NULL. An integer is used for |name| when implementing
     61    * array access into the object. If the property does not exist, set the
     62    * exception and return a var of type Void. A property does not exist if
     63    * a call HasProperty() for the same |name| would return false.
     64    */
     65   struct PP_Var (*GetProperty)(void* object,
     66                                struct PP_Var name,
     67                                struct PP_Var* exception);
     68 
     69   /**
     70    * Exception is guaranteed non-NULL.
     71    *
     72    * This should include all enumerable properties, including methods. Be sure
     73    * to set |*property_count| to 0 and |properties| to NULL in all failure
     74    * cases, these should never be unset when calling this function. The
     75    * pointers passed in are guaranteed not to be NULL, so you don't have to
     76    * NULL check them.
     77    *
     78    * If you have any properties, allocate the property array with
     79    * PPB_Core.MemAlloc(sizeof(PP_Var) * property_count) and add a reference
     80    * to each property on behalf of the caller. The caller is responsible for
     81    * Release()ing each var and calling PPB_Core.MemFree on the property pointer.
     82    */
     83   void (*GetAllPropertyNames)(void* object,
     84                               uint32_t* property_count,
     85                               struct PP_Var** properties,
     86                               struct PP_Var* exception);
     87 
     88   /**
     89    * |name| is guaranteed to be an integer or string type var. Exception is
     90    * guaranteed non-NULL.
     91    */
     92   void (*SetProperty)(void* object,
     93                       struct PP_Var name,
     94                       struct PP_Var value,
     95                       struct PP_Var* exception);
     96 
     97   /**
     98    * |name| is guaranteed to be an integer or string type var. Exception is
     99    * guaranteed non-NULL.
    100    */
    101   void (*RemoveProperty)(void* object,
    102                          struct PP_Var name,
    103                          struct PP_Var* exception);
    104 
    105   // TODO(brettw) need native array access here.
    106 
    107   /**
    108    * |name| is guaranteed to be a string type var. Exception is guaranteed
    109    * non-NULL
    110    */
    111   struct PP_Var (*Call)(void* object,
    112                         struct PP_Var method_name,
    113                         uint32_t argc,
    114                         struct PP_Var* argv,
    115                         struct PP_Var* exception);
    116 
    117   /** Exception is guaranteed non-NULL. */
    118   struct PP_Var (*Construct)(void* object,
    119                              uint32_t argc,
    120                              struct PP_Var* argv,
    121                              struct PP_Var* exception);
    122 
    123   /**
    124    * Called when the reference count of the object reaches 0. Normally, plugins
    125    * would free their internal data pointed to by the |object| pointer.
    126    */
    127   void (*Deallocate)(void* object);
    128 };
    129 
    130 /**
    131  * @}
    132  * End addtogroup PPP
    133  */
    134 #endif  /* PPAPI_C_PPP_CLASS_DEPRECATED_H_ */
    135 
    136