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.
5 #ifndef PPAPI_C_PPB_VAR_DEPRECATED_H_
6 #define PPAPI_C_PPB_VAR_DEPRECATED_H_
8 #include "ppapi/c/dev/deprecated_bool.h"
9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_module.h"
11 #include "ppapi/c/pp_stdint.h"
12 #include "ppapi/c/pp_var.h"
14 struct PPP_Class_Deprecated
;
16 #define PPB_VAR_DEPRECATED_INTERFACE_0_3 "PPB_Var(Deprecated);0.3"
17 #define PPB_VAR_DEPRECATED_INTERFACE PPB_VAR_DEPRECATED_INTERFACE_0_3
21 * Defines the PPB_Var_Deprecated struct.
22 * See http://code.google.com/p/ppapi/wiki/InterfacingWithJavaScript
23 * for general information on using this interface.
24 * {PENDING: Should the generated doc really be pointing to methods?}
30 struct PPB_Var_Deprecated
{
32 * Adds a reference to the given var. If this is not a refcounted object,
33 * this function will do nothing so you can always call it no matter what the
36 void (*AddRef
)(struct PP_Var var
);
39 * Removes a reference to given var, deleting it if the internal refcount
40 * becomes 0. If the given var is not a refcounted object, this function will
41 * do nothing so you can always call it no matter what the type.
43 void (*Release
)(struct PP_Var var
);
46 * Creates a string var from a string. The string must be encoded in valid
47 * UTF-8 and is NOT NULL-terminated, the length must be specified in |len|.
48 * It is an error if the string is not valid UTF-8.
50 * If the length is 0, the |data| pointer will not be dereferenced and may
51 * be NULL. Note, however, that if you do this, the "NULL-ness" will not be
52 * preserved, as VarToUtf8 will never return NULL on success, even for empty
55 * The resulting object will be a refcounted string object. It will be
56 * AddRef()ed for the caller. When the caller is done with it, it should be
59 * On error (basically out of memory to allocate the string, or input that
60 * is not valid UTF-8), this function will return a Null var.
62 struct PP_Var (*VarFromUtf8
)(PP_Module module
,
63 const char* data
, uint32_t len
);
66 * Converts a string-type var to a char* encoded in UTF-8. This string is NOT
67 * NULL-terminated. The length will be placed in |*len|. If the string is
68 * valid but empty the return value will be non-NULL, but |*len| will still
71 * If the var is not a string, this function will return NULL and |*len| will
74 * The returned buffer will be valid as long as the underlying var is alive.
75 * If the plugin frees its reference, the string will be freed and the pointer
76 * will be to random memory.
78 const char* (*VarToUtf8
)(struct PP_Var var
, uint32_t* len
);
81 * Returns true if the property with the given name exists on the given
82 * object, false if it does not. Methods are also counted as properties.
84 * The name can either be a string or an integer var. It is an error to pass
85 * another type of var as the name.
87 * If you pass an invalid name or object, the exception will be set (if it is
88 * non-NULL, and the return value will be false).
90 bool (*HasProperty
)(struct PP_Var object
,
92 struct PP_Var
* exception
);
95 * Identical to HasProperty, except that HasMethod additionally checks if the
96 * property is a function.
98 bool (*HasMethod
)(struct PP_Var object
,
100 struct PP_Var
* exception
);
103 * Returns the value of the given property. If the property doesn't exist, the
104 * exception (if non-NULL) will be set and a "Void" var will be returned.
106 struct PP_Var (*GetProperty
)(struct PP_Var object
,
108 struct PP_Var
* exception
);
111 * Retrieves all property names on the given object. Property names include
114 * If there is a failure, the given exception will be set (if it is non-NULL).
115 * On failure, |*properties| will be set to NULL and |*property_count| will be
118 * A pointer to the array of property names will be placesd in |*properties|.
119 * The caller is responsible for calling Release() on each of these properties
120 * (as per normal refcounted memory management) as well as freeing the array
121 * pointer with PPB_Core.MemFree().
123 * This function returns all "enumerable" properties. Some JavaScript
124 * properties are "hidden" and these properties won't be retrieved by this
125 * function, yet you can still set and get them.
128 * <pre> uint32_t count;
129 * PP_Var* properties;
130 * ppb_var.GetAllPropertyNames(object, &count, &properties);
132 * ...use the properties here...
134 * for (uint32_t i = 0; i < count; i++)
135 * ppb_var.Release(properties[i]);
136 * ppb_core.MemFree(properties); </pre>
138 void (*GetAllPropertyNames
)(struct PP_Var object
,
139 uint32_t* property_count
,
140 struct PP_Var
** properties
,
141 struct PP_Var
* exception
);
144 * Sets the property with the given name on the given object. The exception
145 * will be set, if it is non-NULL, on failure.
147 void (*SetProperty
)(struct PP_Var object
,
150 struct PP_Var
* exception
);
153 * Removes the given property from the given object. The property name must
154 * be an string or integer var, using other types will throw an exception
155 * (assuming the exception pointer is non-NULL).
157 void (*RemoveProperty
)(struct PP_Var object
,
159 struct PP_Var
* exception
);
161 // TODO(brettw) need native array access here.
164 * Invoke the function |method_name| on the given object. If |method_name|
165 * is a Null var, the default method will be invoked, which is how you can
166 * invoke function objects.
168 * Unless it is type Null, |method_name| must be a string. Unlike other
169 * Var functions, integer lookup is not supported since you can't call
170 * functions on integers in JavaScript.
172 * Pass the arguments to the function in order in the |argv| array, and the
173 * number of arguments in the |argc| parameter. |argv| can be NULL if |argc|
177 * Call(obj, VarFromUtf8("DoIt"), 0, NULL, NULL) = obj.DoIt() in JavaScript.
178 * Call(obj, PP_MakeNull(), 0, NULL, NULL) = obj() in JavaScript.
180 struct PP_Var (*Call
)(struct PP_Var object
,
181 struct PP_Var method_name
,
184 struct PP_Var
* exception
);
187 * Invoke the object as a constructor.
189 * For example, if |object| is |String|, this is like saying |new String| in
192 struct PP_Var (*Construct
)(struct PP_Var object
,
195 struct PP_Var
* exception
);
198 * If the object is an instance of the given class, then this method returns
199 * true and sets *object_data to the value passed to CreateObject provided
200 * object_data is non-NULL. Otherwise, this method returns false.
202 bool (*IsInstanceOf
)(struct PP_Var var
,
203 const struct PPP_Class_Deprecated
* object_class
,
207 * Creates an object that the plugin implements. The plugin supplies a
208 * pointer to the class interface it implements for that object, and its
209 * associated internal data that represents that object. This object data
210 * must be unique among all "live" objects.
212 * The returned object will have a reference count of 1. When the reference
213 * count reached 0, the class' Destruct function wlil be called.
215 * On failure, this will return a null var. This probably means the module
218 * Example: Say we're implementing a "Point" object.
219 * <pre> void PointDestruct(void* object) {
220 * delete (Point*)object;
223 * const PPP_Class_Deprecated point_class = {
224 * ... all the other class functions go here ...
228 * * The plugin's internal object associated with the point.
233 * PP_Var MakePoint(int x, int y) {
234 * return CreateObject(&point_class, new Point(x, y));
237 struct PP_Var (*CreateObject
)(PP_Instance instance
,
238 const struct PPP_Class_Deprecated
* object_class
,
241 // Like CreateObject but takes a module. This will be deleted when all callers
242 // can be changed to use the PP_Instance CreateObject one.
243 struct PP_Var (*CreateObjectWithModuleDeprecated
)(
245 const struct PPP_Class_Deprecated
* object_class
,
253 #endif /* PPAPI_C_PPB_VAR_DEPRECATED_H_ */