OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/plugins/ppapi/ppb_var_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_var_deprecated_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "ppapi/c/dev/ppb_var_deprecated.h" | 9 #include "ppapi/c/dev/ppb_var_deprecated.h" |
10 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
| 12 #include "ppapi/shared_impl/ppb_var_impl.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
13 #include "webkit/plugins/ppapi/common.h" | 14 #include "webkit/plugins/ppapi/common.h" |
14 #include "webkit/plugins/ppapi/host_globals.h" | 15 #include "webkit/plugins/ppapi/host_globals.h" |
15 #include "webkit/plugins/ppapi/npapi_glue.h" | 16 #include "webkit/plugins/ppapi/npapi_glue.h" |
16 #include "webkit/plugins/ppapi/npobject_var.h" | 17 #include "webkit/plugins/ppapi/npobject_var.h" |
17 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
18 #include "webkit/plugins/ppapi/plugin_object.h" | 19 #include "webkit/plugins/ppapi/plugin_object.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "v8/include/v8.h" | |
21 | 21 |
22 using ppapi::NPObjectVar; | 22 using ppapi::NPObjectVar; |
23 using ppapi::PpapiGlobals; | 23 using ppapi::PpapiGlobals; |
24 using ppapi::StringVar; | 24 using ppapi::StringVar; |
25 using ppapi::Var; | 25 using ppapi::Var; |
26 using WebKit::WebBindings; | 26 using WebKit::WebBindings; |
27 | 27 |
28 namespace webkit { | 28 namespace webkit { |
29 namespace ppapi { | 29 namespace ppapi { |
30 | 30 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // | 102 // |
103 // This will automatically retrieve the ObjectVar from the object and throw | 103 // This will automatically retrieve the ObjectVar from the object and throw |
104 // an exception if it's invalid. At the end of construction, if there is no | 104 // an exception if it's invalid. At the end of construction, if there is no |
105 // exception, you know that there is no previously set exception, that the | 105 // exception, you know that there is no previously set exception, that the |
106 // object passed in is valid and ready to use (via the object() getter), and | 106 // object passed in is valid and ready to use (via the object() getter), and |
107 // that the TryCatch's pp_module() getter is also set up properly and ready to | 107 // that the TryCatch's pp_module() getter is also set up properly and ready to |
108 // use. | 108 // use. |
109 class ObjectAccessorTryCatch : public TryCatch { | 109 class ObjectAccessorTryCatch : public TryCatch { |
110 public: | 110 public: |
111 ObjectAccessorTryCatch(PP_Var object, PP_Var* exception) | 111 ObjectAccessorTryCatch(PP_Var object, PP_Var* exception) |
112 : TryCatch(0, exception), | 112 : TryCatch(exception), |
113 object_(NPObjectVar::FromPPVar(object)) { | 113 object_(NPObjectVar::FromPPVar(object)) { |
114 if (!object_) { | 114 if (!object_) { |
115 // No object or an invalid object was given. This means we have no module | 115 SetException(kInvalidObjectException); |
116 // to associated with the exception text, so use the magic invalid object | |
117 // exception. | |
118 SetInvalidObjectException(); | |
119 } else { | |
120 // When the object is valid, we have a valid module to associate | |
121 set_pp_module(object_->pp_module()); | |
122 } | 116 } |
123 } | 117 } |
124 | 118 |
125 NPObjectVar* object() { return object_.get(); } | 119 NPObjectVar* object() { return object_.get(); } |
126 | 120 |
127 PluginInstance* GetPluginInstance() { | 121 PluginInstance* GetPluginInstance() { |
128 return HostGlobals::Get()->GetInstance(object()->pp_instance()); | 122 return HostGlobals::Get()->GetInstance(object()->pp_instance()); |
129 } | 123 } |
130 | 124 |
131 protected: | 125 protected: |
(...skipping 29 matching lines...) Expand all Loading... |
161 } | 155 } |
162 | 156 |
163 NPIdentifier identifier() const { return identifier_; } | 157 NPIdentifier identifier() const { return identifier_; } |
164 | 158 |
165 private: | 159 private: |
166 NPIdentifier identifier_; | 160 NPIdentifier identifier_; |
167 | 161 |
168 DISALLOW_COPY_AND_ASSIGN(ObjectAccessorWithIdentifierTryCatch); | 162 DISALLOW_COPY_AND_ASSIGN(ObjectAccessorWithIdentifierTryCatch); |
169 }; | 163 }; |
170 | 164 |
171 // PPB_Var methods ------------------------------------------------------------- | |
172 | |
173 void AddRefVar(PP_Var var) { | |
174 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); | |
175 } | |
176 | |
177 void ReleaseVar(PP_Var var) { | |
178 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); | |
179 } | |
180 | |
181 PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { | |
182 return StringVar::StringToPPVar(module, data, len); | |
183 } | |
184 | |
185 const char* VarToUtf8(PP_Var var, uint32_t* len) { | |
186 StringVar* str = StringVar::FromPPVar(var); | |
187 if (!str) { | |
188 *len = 0; | |
189 return NULL; | |
190 } | |
191 *len = static_cast<uint32_t>(str->value().size()); | |
192 if (str->value().empty()) | |
193 return ""; // Don't return NULL on success. | |
194 return str->value().data(); | |
195 } | |
196 | |
197 PP_Bool HasProperty(PP_Var var, | 165 PP_Bool HasProperty(PP_Var var, |
198 PP_Var name, | 166 PP_Var name, |
199 PP_Var* exception) { | 167 PP_Var* exception) { |
200 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); | 168 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
201 if (accessor.has_exception()) | 169 if (accessor.has_exception()) |
202 return PP_FALSE; | 170 return PP_FALSE; |
203 return BoolToPPBool(WebBindings::hasProperty(NULL, | 171 return BoolToPPBool(WebBindings::hasProperty(NULL, |
204 accessor.object()->np_object(), | 172 accessor.object()->np_object(), |
205 accessor.identifier())); | 173 accessor.identifier())); |
206 } | 174 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 accessor.SetException(kUnableToGetAllPropertiesException); | 227 accessor.SetException(kUnableToGetAllPropertiesException); |
260 return; | 228 return; |
261 } | 229 } |
262 | 230 |
263 if (count == 0) | 231 if (count == 0) |
264 return; | 232 return; |
265 | 233 |
266 *property_count = count; | 234 *property_count = count; |
267 *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count)); | 235 *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count)); |
268 for (uint32_t i = 0; i < count; ++i) { | 236 for (uint32_t i = 0; i < count; ++i) { |
269 (*properties)[i] = NPIdentifierToPPVar( | 237 (*properties)[i] = NPIdentifierToPPVar(identifiers[i]); |
270 accessor.GetPluginInstance()->module()->pp_module(), | |
271 identifiers[i]); | |
272 } | 238 } |
273 free(identifiers); | 239 free(identifiers); |
274 } | 240 } |
275 | 241 |
276 void SetPropertyDeprecated(PP_Var var, | 242 void SetPropertyDeprecated(PP_Var var, |
277 PP_Var name, | 243 PP_Var name, |
278 PP_Var value, | 244 PP_Var value, |
279 PP_Var* exception) { | 245 PP_Var* exception) { |
280 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); | 246 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
281 if (accessor.has_exception()) | 247 if (accessor.has_exception()) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 PP_Var CreateObjectWithModuleDeprecated(PP_Module pp_module, | 385 PP_Var CreateObjectWithModuleDeprecated(PP_Module pp_module, |
420 const PPP_Class_Deprecated* ppp_class, | 386 const PPP_Class_Deprecated* ppp_class, |
421 void* ppp_class_data) { | 387 void* ppp_class_data) { |
422 PluginModule* module = HostGlobals::Get()->GetModule(pp_module); | 388 PluginModule* module = HostGlobals::Get()->GetModule(pp_module); |
423 if (!module) | 389 if (!module) |
424 return PP_MakeNull(); | 390 return PP_MakeNull(); |
425 return PluginObject::Create(module->GetSomeInstance(), | 391 return PluginObject::Create(module->GetSomeInstance(), |
426 ppp_class, ppp_class_data); | 392 ppp_class, ppp_class_data); |
427 } | 393 } |
428 | 394 |
429 const PPB_Var_Deprecated var_deprecated_interface = { | |
430 &AddRefVar, | |
431 &ReleaseVar, | |
432 &VarFromUtf8, | |
433 &VarToUtf8, | |
434 &HasPropertyDeprecated, | |
435 &HasMethodDeprecated, | |
436 &GetProperty, | |
437 &EnumerateProperties, | |
438 &SetPropertyDeprecated, | |
439 &DeletePropertyDeprecated, | |
440 &CallDeprecated, | |
441 &Construct, | |
442 &IsInstanceOfDeprecated, | |
443 &CreateObjectDeprecated, | |
444 &CreateObjectWithModuleDeprecated, | |
445 }; | |
446 | |
447 const PPB_Var var_interface = { | |
448 &AddRefVar, | |
449 &ReleaseVar, | |
450 &VarFromUtf8, | |
451 &VarToUtf8 | |
452 }; | |
453 | |
454 } // namespace | 395 } // namespace |
455 | 396 |
456 // static | 397 // static |
457 const PPB_Var* PPB_Var_Impl::GetVarInterface() { | 398 const PPB_Var_Deprecated* PPB_Var_Deprecated_Impl::GetVarDeprecatedInterface() { |
458 return &var_interface; | 399 static const PPB_Var_Deprecated var_deprecated_interface = { |
459 } | 400 ::ppapi::PPB_Var_Impl::GetVarInterface1_0()->AddRef, |
| 401 ::ppapi::PPB_Var_Impl::GetVarInterface1_0()->Release, |
| 402 ::ppapi::PPB_Var_Impl::GetVarInterface1_0()->VarFromUtf8, |
| 403 ::ppapi::PPB_Var_Impl::GetVarInterface1_0()->VarToUtf8, |
| 404 &HasPropertyDeprecated, |
| 405 &HasMethodDeprecated, |
| 406 &GetProperty, |
| 407 &EnumerateProperties, |
| 408 &SetPropertyDeprecated, |
| 409 &DeletePropertyDeprecated, |
| 410 &CallDeprecated, |
| 411 &Construct, |
| 412 &IsInstanceOfDeprecated, |
| 413 &CreateObjectDeprecated, |
| 414 &CreateObjectWithModuleDeprecated, |
| 415 }; |
460 | 416 |
461 // static | |
462 const PPB_Var_Deprecated* PPB_Var_Impl::GetVarDeprecatedInterface() { | |
463 return &var_deprecated_interface; | 417 return &var_deprecated_interface; |
464 } | 418 } |
465 | 419 |
466 } // namespace ppapi | 420 } // namespace ppapi |
467 } // namespace webkit | 421 } // namespace webkit |
468 | 422 |
OLD | NEW |