OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/shared/ppapi_proxy/plugin_var.h" | 7 #include "native_client/src/shared/ppapi_proxy/plugin_var.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (var.type == PP_VARTYPE_STRING) { | 77 if (var.type == PP_VARTYPE_STRING) { |
78 return reinterpret_cast<StrImpl*>(var.value.as_id); | 78 return reinterpret_cast<StrImpl*>(var.value.as_id); |
79 } else { | 79 } else { |
80 return NULL; | 80 return NULL; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void AddRef(PP_Var var) { | 84 void AddRef(PP_Var var) { |
85 ObjImpl* obj_impl = VarToObjImpl(var); | 85 ObjImpl* obj_impl = VarToObjImpl(var); |
86 if (obj_impl != NULL) { | 86 if (obj_impl != NULL) { |
87 DebugPrintf("PluginVar::AddRef: %"NACL_PRIu64"\n", obj_impl->id()); | 87 DebugPrintf("Plugin::PPB_Var::AddRef: %"NACL_PRIu64"\n", obj_impl->id()); |
88 obj_impl->AddRef(); | 88 obj_impl->AddRef(); |
89 } | 89 } |
90 StrImpl* str_impl = VarToStrImpl(var); | 90 StrImpl* str_impl = VarToStrImpl(var); |
91 if (str_impl != NULL) { | 91 if (str_impl != NULL) { |
92 DebugPrintf("PluginVar::AddRef: '%s'\n", str_impl->str().c_str()); | 92 DebugPrintf("Plugin::PPB_Var::AddRef: '%s'\n", str_impl->str().c_str()); |
93 str_impl->AddRef(); | 93 str_impl->AddRef(); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void Release(PP_Var var) { | 97 void Release(PP_Var var) { |
98 ObjImpl* obj_impl = VarToObjImpl(var); | 98 ObjImpl* obj_impl = VarToObjImpl(var); |
99 if (obj_impl != NULL) { | 99 if (obj_impl != NULL) { |
100 DebugPrintf("PluginVar::Release: object(%"NACL_PRIu64")\n", obj_impl->id()); | 100 DebugPrintf("Plugin::PPB_Var::Release: object(%"NACL_PRIu64")\n", |
| 101 obj_impl->id()); |
101 obj_impl->Release(); | 102 obj_impl->Release(); |
102 if (obj_impl->ref_count() == 0) { | 103 if (obj_impl->ref_count() == 0) { |
103 if (obj_impl->object_class() == NULL) { | 104 if (obj_impl->object_class() == NULL) { |
104 free(obj_impl->object_data()); | 105 free(obj_impl->object_data()); |
105 } else { | 106 } else { |
106 obj_impl->object_class()->Deallocate(obj_impl->object_data()); | 107 obj_impl->object_class()->Deallocate(obj_impl->object_data()); |
107 } | 108 } |
108 delete obj_impl; | 109 delete obj_impl; |
109 } | 110 } |
110 } | 111 } |
111 StrImpl* str_impl = VarToStrImpl(var); | 112 StrImpl* str_impl = VarToStrImpl(var); |
112 if (str_impl != NULL) { | 113 if (str_impl != NULL) { |
113 DebugPrintf("PluginVar::Release: string('%s')\n", str_impl->str().c_str()); | 114 DebugPrintf("Plugin::PPB_Var::Release: string('%s')\n", |
| 115 str_impl->str().c_str()); |
114 str_impl->Release(); | 116 str_impl->Release(); |
115 if (str_impl->ref_count() == 0) { | 117 if (str_impl->ref_count() == 0) { |
116 delete str_impl; | 118 delete str_impl; |
117 } | 119 } |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 PP_Var VarFromUtf8(PP_Module module_id, const char* data, uint32_t len) { | 123 PP_Var VarFromUtf8(PP_Module module_id, const char* data, uint32_t len) { |
122 UNREFERENCED_PARAMETER(module_id); | 124 UNREFERENCED_PARAMETER(module_id); |
123 StrImpl* impl = new StrImpl(data, len); | 125 StrImpl* impl = new StrImpl(data, len); |
(...skipping 14 matching lines...) Expand all Loading... |
138 } | 140 } |
139 } | 141 } |
140 | 142 |
141 bool HasProperty(PP_Var object, | 143 bool HasProperty(PP_Var object, |
142 PP_Var name, | 144 PP_Var name, |
143 PP_Var* exception) { | 145 PP_Var* exception) { |
144 ObjImpl* impl = VarToObjImpl(object); | 146 ObjImpl* impl = VarToObjImpl(object); |
145 if (impl == NULL) { | 147 if (impl == NULL) { |
146 return false; | 148 return false; |
147 } | 149 } |
148 DebugPrintf("PluginVar::HasProperty: %"NACL_PRIu64"\n", impl->id()); | 150 DebugPrintf("Plugin::PPB_Var::HasProperty: id=%"NACL_PRIu64"\n", impl->id()); |
149 DebugPrintf(" object.type = %d; name.type = %d\n", object.type, name.type); | 151 DebugPrintf("Plugin::PPB_Var::HasProperty: " |
| 152 "object.type = %d; name.type = %d\n", object.type, name.type); |
150 const PPP_Class_Deprecated* object_class = impl->object_class(); | 153 const PPP_Class_Deprecated* object_class = impl->object_class(); |
151 if (object_class == NULL || object_class->HasProperty == NULL) { | 154 if (object_class == NULL || object_class->HasProperty == NULL) { |
152 return false; | 155 return false; |
153 } | 156 } |
154 return object_class->HasProperty(impl->object_data(), name, exception); | 157 return object_class->HasProperty(impl->object_data(), name, exception); |
155 } | 158 } |
156 | 159 |
157 bool HasMethod(PP_Var object, | 160 bool HasMethod(PP_Var object, |
158 PP_Var name, | 161 PP_Var name, |
159 PP_Var* exception) { | 162 PP_Var* exception) { |
160 ObjImpl* impl = VarToObjImpl(object); | 163 ObjImpl* impl = VarToObjImpl(object); |
161 if (impl == NULL) { | 164 if (impl == NULL) { |
162 return false; | 165 return false; |
163 } | 166 } |
164 DebugPrintf("PluginVar::HasMethod: %"NACL_PRIu64"\n", impl->id()); | 167 DebugPrintf("Plugin::PPB_Var::HasMethod: id=%"NACL_PRIu64"\n", impl->id()); |
165 const PPP_Class_Deprecated* object_class = impl->object_class(); | 168 const PPP_Class_Deprecated* object_class = impl->object_class(); |
166 if (object_class == NULL || object_class->HasMethod == NULL) { | 169 if (object_class == NULL || object_class->HasMethod == NULL) { |
167 return false; | 170 return false; |
168 } | 171 } |
169 return object_class->HasMethod(impl->object_data(), name, exception); | 172 return object_class->HasMethod(impl->object_data(), name, exception); |
170 } | 173 } |
171 | 174 |
172 PP_Var GetProperty(PP_Var object, | 175 PP_Var GetProperty(PP_Var object, |
173 PP_Var name, | 176 PP_Var name, |
174 PP_Var* exception) { | 177 PP_Var* exception) { |
175 ObjImpl* impl = VarToObjImpl(object); | 178 ObjImpl* impl = VarToObjImpl(object); |
176 if (impl == NULL) { | 179 if (impl == NULL) { |
177 return PP_MakeUndefined(); | 180 return PP_MakeUndefined(); |
178 } | 181 } |
179 DebugPrintf("PluginVar::GetProperty: %"NACL_PRIu64"\n", impl->id()); | 182 DebugPrintf("Plugin::PPB_Var::GetProperty: id=%"NACL_PRIu64"\n", impl->id()); |
180 const PPP_Class_Deprecated* object_class = impl->object_class(); | 183 const PPP_Class_Deprecated* object_class = impl->object_class(); |
181 if (object_class == NULL || object_class->GetProperty == NULL) { | 184 if (object_class == NULL || object_class->GetProperty == NULL) { |
182 return PP_MakeUndefined(); | 185 return PP_MakeUndefined(); |
183 } | 186 } |
184 return object_class->GetProperty(impl->object_data(), name, exception); | 187 return object_class->GetProperty(impl->object_data(), name, exception); |
185 } | 188 } |
186 | 189 |
187 void GetAllPropertyNames(PP_Var object, | 190 void GetAllPropertyNames(PP_Var object, |
188 uint32_t* property_count, | 191 uint32_t* property_count, |
189 PP_Var** properties, | 192 PP_Var** properties, |
190 PP_Var* exception) { | 193 PP_Var* exception) { |
191 ObjImpl* impl = VarToObjImpl(object); | 194 ObjImpl* impl = VarToObjImpl(object); |
192 if (impl == NULL) { | 195 if (impl == NULL) { |
193 return; | 196 return; |
194 } | 197 } |
195 DebugPrintf("PluginVar::GetAllPropertyNames: %"NACL_PRIu64"\n", impl->id()); | 198 DebugPrintf("Plugin::PPB_Var::GetAllPropertyNames: id=%"NACL_PRIu64"\n", |
| 199 impl->id()); |
196 const PPP_Class_Deprecated* object_class = impl->object_class(); | 200 const PPP_Class_Deprecated* object_class = impl->object_class(); |
197 if (object_class == NULL || object_class->GetAllPropertyNames == NULL) { | 201 if (object_class == NULL || object_class->GetAllPropertyNames == NULL) { |
198 return; | 202 return; |
199 } | 203 } |
200 object_class->GetAllPropertyNames(impl->object_data(), | 204 object_class->GetAllPropertyNames(impl->object_data(), |
201 property_count, | 205 property_count, |
202 properties, | 206 properties, |
203 exception); | 207 exception); |
204 } | 208 } |
205 | 209 |
206 void SetProperty(PP_Var object, | 210 void SetProperty(PP_Var object, |
207 PP_Var name, | 211 PP_Var name, |
208 PP_Var value, | 212 PP_Var value, |
209 PP_Var* exception) { | 213 PP_Var* exception) { |
210 ObjImpl* impl = VarToObjImpl(object); | 214 ObjImpl* impl = VarToObjImpl(object); |
211 if (impl == NULL) { | 215 if (impl == NULL) { |
212 return; | 216 return; |
213 } | 217 } |
214 DebugPrintf("PluginVar::SetProperty: %"NACL_PRIu64"\n", impl->id()); | 218 DebugPrintf("Plugin::PPB_Var::SetProperty: id=%"NACL_PRIu64"\n", impl->id()); |
215 const PPP_Class_Deprecated* object_class = impl->object_class(); | 219 const PPP_Class_Deprecated* object_class = impl->object_class(); |
216 if (object_class == NULL || object_class->SetProperty == NULL) { | 220 if (object_class == NULL || object_class->SetProperty == NULL) { |
217 return; | 221 return; |
218 } | 222 } |
219 object_class->SetProperty(impl->object_data(), name, value, exception); | 223 object_class->SetProperty(impl->object_data(), name, value, exception); |
220 } | 224 } |
221 | 225 |
222 void RemoveProperty(PP_Var object, | 226 void RemoveProperty(PP_Var object, |
223 PP_Var name, | 227 PP_Var name, |
224 PP_Var* exception) { | 228 PP_Var* exception) { |
225 ObjImpl* impl = VarToObjImpl(object); | 229 ObjImpl* impl = VarToObjImpl(object); |
226 if (impl == NULL) { | 230 if (impl == NULL) { |
227 return; | 231 return; |
228 } | 232 } |
229 DebugPrintf("PluginVar::RemoveProperty: %"NACL_PRIu64"\n", impl->id()); | 233 DebugPrintf("Plugin::PPB_Var::RemoveProperty: id=%"NACL_PRIu64"\n", |
| 234 impl->id()); |
230 const PPP_Class_Deprecated* object_class = impl->object_class(); | 235 const PPP_Class_Deprecated* object_class = impl->object_class(); |
231 if (object_class == NULL || object_class->RemoveProperty == NULL) { | 236 if (object_class == NULL || object_class->RemoveProperty == NULL) { |
232 return; | 237 return; |
233 } | 238 } |
234 object_class->RemoveProperty(impl->object_data(), name, exception); | 239 object_class->RemoveProperty(impl->object_data(), name, exception); |
235 } | 240 } |
236 | 241 |
237 PP_Var Call(PP_Var object, | 242 PP_Var Call(PP_Var object, |
238 PP_Var method_name, | 243 PP_Var method_name, |
239 uint32_t argc, | 244 uint32_t argc, |
240 PP_Var* argv, | 245 PP_Var* argv, |
241 PP_Var* exception) { | 246 PP_Var* exception) { |
242 ObjImpl* impl = VarToObjImpl(object); | 247 ObjImpl* impl = VarToObjImpl(object); |
243 if (impl == NULL) { | 248 if (impl == NULL) { |
244 return PP_MakeUndefined(); | 249 return PP_MakeUndefined(); |
245 } | 250 } |
246 DebugPrintf("PluginVar::Call: %"NACL_PRIu64"\n", impl->id()); | 251 DebugPrintf("Plugin::PPB_Var::Call: id=%"NACL_PRIu64"\n", impl->id()); |
247 const PPP_Class_Deprecated* object_class = impl->object_class(); | 252 const PPP_Class_Deprecated* object_class = impl->object_class(); |
248 if (object_class == NULL || object_class->Call == NULL) { | 253 if (object_class == NULL || object_class->Call == NULL) { |
249 return PP_MakeUndefined(); | 254 return PP_MakeUndefined(); |
250 } | 255 } |
251 return object_class->Call(impl->object_data(), | 256 return object_class->Call(impl->object_data(), |
252 method_name, | 257 method_name, |
253 argc, | 258 argc, |
254 argv, | 259 argv, |
255 exception); | 260 exception); |
256 } | 261 } |
257 | 262 |
258 PP_Var Construct(PP_Var object, | 263 PP_Var Construct(PP_Var object, |
259 uint32_t argc, | 264 uint32_t argc, |
260 PP_Var* argv, | 265 PP_Var* argv, |
261 PP_Var* exception) { | 266 PP_Var* exception) { |
262 ObjImpl* impl = VarToObjImpl(object); | 267 ObjImpl* impl = VarToObjImpl(object); |
263 if (impl == NULL) { | 268 if (impl == NULL) { |
264 return PP_MakeUndefined(); | 269 return PP_MakeUndefined(); |
265 } | 270 } |
266 DebugPrintf("PluginVar::Construct: %"NACL_PRIu64"\n", impl->id()); | 271 DebugPrintf("Plugin::PPB_Var::Construct: %"NACL_PRIu64"\n", impl->id()); |
267 const PPP_Class_Deprecated* object_class = impl->object_class(); | 272 const PPP_Class_Deprecated* object_class = impl->object_class(); |
268 if (object_class == NULL || object_class->Construct == NULL) { | 273 if (object_class == NULL || object_class->Construct == NULL) { |
269 return PP_MakeUndefined(); | 274 return PP_MakeUndefined(); |
270 } | 275 } |
271 return object_class->Construct(impl->object_data(), argc, argv, exception); | 276 return object_class->Construct(impl->object_data(), argc, argv, exception); |
272 } | 277 } |
273 | 278 |
274 bool IsInstanceOf(PP_Var var, | 279 bool IsInstanceOf(PP_Var var, |
275 const PPP_Class_Deprecated* object_class, | 280 const PPP_Class_Deprecated* object_class, |
276 void** object_data) { | 281 void** object_data) { |
277 ObjImpl* impl = VarToObjImpl(var); | 282 ObjImpl* impl = VarToObjImpl(var); |
278 *object_data = NULL; | 283 *object_data = NULL; |
279 if (impl == NULL) { | 284 if (impl == NULL) { |
280 return false; | 285 return false; |
281 } | 286 } |
282 DebugPrintf("PluginVar::IsInstanceOf: %"NACL_PRIu64"\n", impl->id()); | 287 DebugPrintf("Plugin::PPB_Var::IsInstanceOf: id=%"NACL_PRIu64"\n", impl->id()); |
283 DebugPrintf("is instance %p %p\n", | 288 DebugPrintf("Plugin::PPB_Var::IsInstanceOf: is instance %p %p\n", |
284 reinterpret_cast<const void*>(impl->object_class()), | 289 reinterpret_cast<const void*>(impl->object_class()), |
285 reinterpret_cast<const void*>(object_class)); | 290 reinterpret_cast<const void*>(object_class)); |
286 if (object_class != impl->object_class()) { | 291 if (object_class != impl->object_class()) { |
287 return false; | 292 return false; |
288 } | 293 } |
289 *object_data = impl->object_data(); | 294 *object_data = impl->object_data(); |
290 return true; | 295 return true; |
291 } | 296 } |
292 | 297 |
293 uint64_t GetObjectId(const void* object) { | 298 uint64_t GetObjectId(const void* object) { |
294 if (object == NULL) { | 299 if (object == NULL) { |
295 return static_cast<uint64_t>(-1); | 300 return static_cast<uint64_t>(-1); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 static_cast<uint32_t>(str.size()), | 431 static_cast<uint32_t>(str.size()), |
427 str.c_str()); | 432 str.c_str()); |
428 } | 433 } |
429 case PP_VARTYPE_OBJECT: | 434 case PP_VARTYPE_OBJECT: |
430 DebugPrintf("PP_Var(object: %"NACL_PRIu64")", GetVarId(var)); | 435 DebugPrintf("PP_Var(object: %"NACL_PRIu64")", GetVarId(var)); |
431 break; | 436 break; |
432 } | 437 } |
433 } | 438 } |
434 | 439 |
435 } // namespace ppapi_proxy | 440 } // namespace ppapi_proxy |
OLD | NEW |