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/plugin_object.h" | 5 #include "webkit/plugins/ppapi/plugin_object.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "ppapi/c/dev/ppb_var_deprecated.h" | 12 #include "ppapi/c/dev/ppb_var_deprecated.h" |
13 #include "ppapi/c/dev/ppp_class_deprecated.h" | 13 #include "ppapi/c/dev/ppp_class_deprecated.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/c/pp_var.h" | 15 #include "ppapi/c/pp_var.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/resource_tracker.h" | 17 #include "ppapi/shared_impl/resource_tracker.h" |
18 #include "ppapi/shared_impl/var.h" | 18 #include "ppapi/shared_impl/var.h" |
19 #include "ppapi/shared_impl/var_tracker.h" | 19 #include "ppapi/shared_impl/var_tracker.h" |
20 #include "third_party/WebKit/public/web/WebBindings.h" | 20 #include "third_party/WebKit/public/web/WebBindings.h" |
21 #include "third_party/npapi/bindings/npapi.h" | 21 #include "third_party/npapi/bindings/npapi.h" |
22 #include "third_party/npapi/bindings/npruntime.h" | 22 #include "third_party/npapi/bindings/npruntime.h" |
23 #include "webkit/plugins/ppapi/npapi_glue.h" | 23 #include "webkit/plugins/ppapi/npapi_glue.h" |
24 #include "webkit/plugins/ppapi/plugin_module.h" | 24 #include "webkit/plugins/ppapi/plugin_module.h" |
25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
26 | 26 |
27 using ppapi::PpapiGlobals; | 27 using ppapi::PpapiGlobals; |
28 using ppapi::StringVar; | 28 using ppapi::StringVar; |
29 using ppapi::Var; | 29 using ppapi::Var; |
30 using WebKit::WebBindings; | 30 using WebKit::WebBindings; |
31 | 31 |
32 namespace webkit { | 32 namespace webkit { |
33 namespace ppapi { | 33 namespace ppapi { |
34 | 34 |
35 namespace { | 35 namespace { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // PluginObject ---------------------------------------------------------------- | 258 // PluginObject ---------------------------------------------------------------- |
259 | 259 |
260 struct PluginObject::NPObjectWrapper : public NPObject { | 260 struct PluginObject::NPObjectWrapper : public NPObject { |
261 // Points to the var object that owns this wrapper. This value may be NULL | 261 // Points to the var object that owns this wrapper. This value may be NULL |
262 // if there is no var owning this wrapper. This can happen if the plugin | 262 // if there is no var owning this wrapper. This can happen if the plugin |
263 // releases all references to the var, but a reference to the underlying | 263 // releases all references to the var, but a reference to the underlying |
264 // NPObject is still held by script on the page. | 264 // NPObject is still held by script on the page. |
265 PluginObject* obj; | 265 PluginObject* obj; |
266 }; | 266 }; |
267 | 267 |
268 PluginObject::PluginObject(PluginInstance* instance, | 268 PluginObject::PluginObject(PluginInstanceImpl* instance, |
269 NPObjectWrapper* object_wrapper, | 269 NPObjectWrapper* object_wrapper, |
270 const PPP_Class_Deprecated* ppp_class, | 270 const PPP_Class_Deprecated* ppp_class, |
271 void* ppp_class_data) | 271 void* ppp_class_data) |
272 : instance_(instance), | 272 : instance_(instance), |
273 object_wrapper_(object_wrapper), | 273 object_wrapper_(object_wrapper), |
274 ppp_class_(ppp_class), | 274 ppp_class_(ppp_class), |
275 ppp_class_data_(ppp_class_data) { | 275 ppp_class_data_(ppp_class_data) { |
276 // Make the object wrapper refer back to this class so our NPObject | 276 // Make the object wrapper refer back to this class so our NPObject |
277 // implementation can call back into the Pepper layer. | 277 // implementation can call back into the Pepper layer. |
278 object_wrapper_->obj = this; | 278 object_wrapper_->obj = this; |
279 instance_->AddPluginObject(this); | 279 instance_->AddPluginObject(this); |
280 } | 280 } |
281 | 281 |
282 PluginObject::~PluginObject() { | 282 PluginObject::~PluginObject() { |
283 // The wrapper we made for this NPObject may still have a reference to it | 283 // The wrapper we made for this NPObject may still have a reference to it |
284 // from JavaScript, so we clear out its ObjectVar back pointer which will | 284 // from JavaScript, so we clear out its ObjectVar back pointer which will |
285 // cause all calls "up" to the plugin to become NOPs. Our ObjectVar base | 285 // cause all calls "up" to the plugin to become NOPs. Our ObjectVar base |
286 // class will release our reference to the object, which may or may not | 286 // class will release our reference to the object, which may or may not |
287 // delete the NPObject. | 287 // delete the NPObject. |
288 DCHECK(object_wrapper_->obj == this); | 288 DCHECK(object_wrapper_->obj == this); |
289 object_wrapper_->obj = NULL; | 289 object_wrapper_->obj = NULL; |
290 instance_->RemovePluginObject(this); | 290 instance_->RemovePluginObject(this); |
291 } | 291 } |
292 | 292 |
293 PP_Var PluginObject::Create(PluginInstance* instance, | 293 PP_Var PluginObject::Create(PluginInstanceImpl* instance, |
294 const PPP_Class_Deprecated* ppp_class, | 294 const PPP_Class_Deprecated* ppp_class, |
295 void* ppp_class_data) { | 295 void* ppp_class_data) { |
296 // This will internally end up calling our AllocateObjectWrapper via the | 296 // This will internally end up calling our AllocateObjectWrapper via the |
297 // WrapperClass_Allocated function which will have created an object wrapper | 297 // WrapperClass_Allocated function which will have created an object wrapper |
298 // appropriate for this class (derived from NPObject). | 298 // appropriate for this class (derived from NPObject). |
299 NPObjectWrapper* wrapper = static_cast<NPObjectWrapper*>( | 299 NPObjectWrapper* wrapper = static_cast<NPObjectWrapper*>( |
300 WebBindings::createObject(instance->instanceNPP(), | 300 WebBindings::createObject(instance->instanceNPP(), |
301 const_cast<NPClass*>(&wrapper_class))); | 301 const_cast<NPClass*>(&wrapper_class))); |
302 | 302 |
303 // This object will register itself both with the NPObject and with the | 303 // This object will register itself both with the NPObject and with the |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // static | 351 // static |
352 NPObject* PluginObject::AllocateObjectWrapper() { | 352 NPObject* PluginObject::AllocateObjectWrapper() { |
353 NPObjectWrapper* wrapper = new NPObjectWrapper; | 353 NPObjectWrapper* wrapper = new NPObjectWrapper; |
354 memset(wrapper, 0, sizeof(NPObjectWrapper)); | 354 memset(wrapper, 0, sizeof(NPObjectWrapper)); |
355 return wrapper; | 355 return wrapper; |
356 } | 356 } |
357 | 357 |
358 } // namespace ppapi | 358 } // namespace ppapi |
359 } // namespace webkit | 359 } // namespace webkit |
360 | 360 |
OLD | NEW |