| OLD | NEW |
| (Empty) |
| 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_PPB_CLASS_H_ | |
| 6 #define PPAPI_C_PPB_CLASS_H_ | |
| 7 | |
| 8 #include "ppapi/c/pp_module.h" | |
| 9 #include "ppapi/c/pp_resource.h" | |
| 10 #include "ppapi/c/pp_stdint.h" | |
| 11 #include "ppapi/c/pp_var.h" | |
| 12 #include "ppapi/c/ppb_var.h" | |
| 13 | |
| 14 #define PPB_CLASS_INTERFACE "PPB_Class;0.4" | |
| 15 | |
| 16 /** | |
| 17 * @file | |
| 18 * This file defines the PPB_Class struct which is an interface for | |
| 19 * implementing JavaScript-accessible objects. | |
| 20 * | |
| 21 */ | |
| 22 | |
| 23 /** | |
| 24 * @addtogroup Typedefs | |
| 25 * @{ | |
| 26 */ | |
| 27 | |
| 28 /** | |
| 29 * Function callback. | |
| 30 * | |
| 31 * native_ptr will always be the native_ptr used to create this_object. If | |
| 32 * this object was not created in this module, native_ptr will be NULL. There | |
| 33 * is no other type protection - if your module contains two objects with | |
| 34 * different native_ptr information, make sure you can handle the case of | |
| 35 * JS calling one object's function with another object set as this. | |
| 36 * | |
| 37 */ | |
| 38 typedef struct PP_Var (*PP_ClassFunction)(void* native_ptr, | |
| 39 struct PP_Var this_object, /*NOLINT*/ | |
| 40 struct PP_Var* args, | |
| 41 uint32_t argc, | |
| 42 struct PP_Var* exception); | |
| 43 /** | |
| 44 * @} | |
| 45 */ | |
| 46 | |
| 47 /** | |
| 48 * @addtogroup Typedefs | |
| 49 * @{ | |
| 50 */ | |
| 51 typedef void (*PP_ClassDestructor)(void* native_ptr); | |
| 52 /** | |
| 53 * @} | |
| 54 */ | |
| 55 | |
| 56 /** | |
| 57 * @addtogroup Structs | |
| 58 * @{ | |
| 59 */ | |
| 60 | |
| 61 /** | |
| 62 * One property of a class. | |
| 63 * | |
| 64 * It can be either a value property, in which case it need to have getter | |
| 65 * and/or setter fields set, and method NULL, or a function, in which case it | |
| 66 * needs to have method set, and getter/setter set to NULL. It is an error to | |
| 67 * have method and either getter or setter set, as it is an error to not provide | |
| 68 * any of them. | |
| 69 * | |
| 70 * Not providing a getter will be equivalent to having a getter which returns | |
| 71 * undefined. Not providing a setter will be equivalent to providing a setter | |
| 72 * which doesn't do anything. | |
| 73 * | |
| 74 */ | |
| 75 struct PP_ClassProperty { | |
| 76 const char* name; | |
| 77 PP_ClassFunction method; | |
| 78 PP_ClassFunction getter; | |
| 79 PP_ClassFunction setter; | |
| 80 uint32_t modifiers; | |
| 81 }; | |
| 82 /** | |
| 83 * @} | |
| 84 */ | |
| 85 | |
| 86 /** | |
| 87 * @addtogroup Interfaces | |
| 88 * @{ | |
| 89 */ | |
| 90 | |
| 91 /** Interface for implementing JavaScript-accessible objects. | |
| 92 * | |
| 93 * | |
| 94 * Example usage: | |
| 95 * | |
| 96 * struct PP_ClassProperty properties[] = { | |
| 97 * { "method", methodFunc }, | |
| 98 * { "hiddenMethod", hiddenMethodFunc, NULL, NULL, | |
| 99 * PP_OBJECTPROPERTY_MODIFIER_DONTENUM }, | |
| 100 * { "property", NULL, propertyGetter, propertySetter }, | |
| 101 * { "readonlyProperty", NULL, propertyGetter, NULL, | |
| 102 * PP_OBJECTPROPERTY_MODIFIER_READONLY }, | |
| 103 * { NULL } | |
| 104 * }; | |
| 105 * | |
| 106 * PP_Resource object_template = | |
| 107 * Create(module, &operator delete, NULL, properties); | |
| 108 * | |
| 109 * ... | |
| 110 * | |
| 111 * struct NativeData { int blah; ... }; // Can be anything. | |
| 112 * NativeData* native_data = new NativeData; | |
| 113 * native_data->blah = 123; // Initialize native data. | |
| 114 * | |
| 115 * PP_Var object = Instantiate(object_template, native_data); | |
| 116 * | |
| 117 * Please also see: | |
| 118 * http://code.google.com/p/ppapi/wiki/InterfacingWithJavaScript | |
| 119 * for general information on using and implementing vars. | |
| 120 */ | |
| 121 struct PPB_Class { | |
| 122 /** | |
| 123 * Creates a class containing given methods and properties. | |
| 124 * | |
| 125 * Properties list is terminated with a NULL-named property. New instances are | |
| 126 * created using Instantiate(). Each instance carries one void* of native | |
| 127 * state, which is passed to Instantiate(). When the instance is finalized, | |
| 128 * the destructor function is called to destruct the native state. | |
| 129 * | |
| 130 * If invoke handler is specified, then the instances can be used as | |
| 131 * functions. | |
| 132 */ | |
| 133 PP_Resource (*Create)(PP_Module module, | |
| 134 PP_ClassDestructor destruct, | |
| 135 PP_ClassFunction invoke, | |
| 136 struct PP_ClassProperty* properties); | |
| 137 | |
| 138 /** | |
| 139 * Creates an instance of the given class, and attaches given native pointer | |
| 140 * to it. | |
| 141 * | |
| 142 * If the class_object is invalid, throws an exception. | |
| 143 */ | |
| 144 struct PP_Var (*Instantiate)(PP_Resource class_object, | |
| 145 void* native_ptr, | |
| 146 struct PP_Var* exception); | |
| 147 }; | |
| 148 /** | |
| 149 * @} | |
| 150 */ | |
| 151 | |
| 152 | |
| 153 #endif /* PPAPI_C_PPP_CLASS_H_ */ | |
| 154 | |
| OLD | NEW |