| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/proxy/plugin_var_tracker.h" | 5 #include "ppapi/proxy/plugin_var_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 9 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 10 #include "ppapi/c/dev/ppp_class_deprecated.h" | 12 #include "ppapi/c/dev/ppp_class_deprecated.h" |
| 11 #include "ppapi/c/ppb_var.h" | 13 #include "ppapi/c/ppb_var.h" |
| 12 #include "ppapi/proxy/file_system_resource.h" | 14 #include "ppapi/proxy/file_system_resource.h" |
| 13 #include "ppapi/proxy/media_stream_audio_track_resource.h" | 15 #include "ppapi/proxy/media_stream_audio_track_resource.h" |
| 14 #include "ppapi/proxy/media_stream_video_track_resource.h" | 16 #include "ppapi/proxy/media_stream_video_track_resource.h" |
| 15 #include "ppapi/proxy/plugin_array_buffer_var.h" | 17 #include "ppapi/proxy/plugin_array_buffer_var.h" |
| 16 #include "ppapi/proxy/plugin_dispatcher.h" | 18 #include "ppapi/proxy/plugin_dispatcher.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 Connection GetConnectionForInstance(PP_Instance instance) { | 34 Connection GetConnectionForInstance(PP_Instance instance) { |
| 33 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 35 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 34 DCHECK(dispatcher); | 36 DCHECK(dispatcher); |
| 35 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher); | 37 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher); |
| 36 } | 38 } |
| 37 | 39 |
| 38 } // namespace | 40 } // namespace |
| 39 | 41 |
| 40 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i) | 42 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32_t i) |
| 41 : dispatcher(d), | 43 : dispatcher(d), host_object_id(i) {} |
| 42 host_object_id(i) { | |
| 43 } | |
| 44 | 44 |
| 45 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const { | 45 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const { |
| 46 if (dispatcher < other.dispatcher) | 46 if (dispatcher < other.dispatcher) |
| 47 return true; | 47 return true; |
| 48 if (other.dispatcher < dispatcher) | 48 if (other.dispatcher < dispatcher) |
| 49 return false; | 49 return false; |
| 50 return host_object_id < other.host_object_id; | 50 return host_object_id < other.host_object_id; |
| 51 } | 51 } |
| 52 | 52 |
| 53 PluginVarTracker::PluginVarTracker() : VarTracker(THREAD_SAFE) { | 53 PluginVarTracker::PluginVarTracker() : VarTracker(THREAD_SAFE) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return object->dispatcher(); | 152 return object->dispatcher(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, | 155 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, |
| 156 const PP_Var& host_object) { | 156 const PP_Var& host_object) { |
| 157 CheckThreadingPreconditions(); | 157 CheckThreadingPreconditions(); |
| 158 DCHECK(host_object.type == PP_VARTYPE_OBJECT); | 158 DCHECK(host_object.type == PP_VARTYPE_OBJECT); |
| 159 | 159 |
| 160 // Convert the host object to a normal var valid in the plugin. | 160 // Convert the host object to a normal var valid in the plugin. |
| 161 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find( | 161 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find( |
| 162 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id))); | 162 HostVar(dispatcher, static_cast<int32_t>(host_object.value.as_id))); |
| 163 if (found == host_var_to_plugin_var_.end()) { | 163 if (found == host_var_to_plugin_var_.end()) { |
| 164 NOTREACHED(); | 164 NOTREACHED(); |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Now just release the object given the plugin var ID. | 168 // Now just release the object given the plugin var ID. |
| 169 ReleaseVar(found->second); | 169 ReleaseVar(found->second); |
| 170 } | 170 } |
| 171 | 171 |
| 172 PP_Var PluginVarTracker::MakeResourcePPVarFromMessage( | 172 PP_Var PluginVarTracker::MakeResourcePPVarFromMessage( |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 it != live_vars_.end(); | 296 it != live_vars_.end(); |
| 297 ++it) { | 297 ++it) { |
| 298 if (it->second.var.get() == NULL) | 298 if (it->second.var.get() == NULL) |
| 299 continue; | 299 continue; |
| 300 ProxyObjectVar* object = it->second.var->AsProxyObjectVar(); | 300 ProxyObjectVar* object = it->second.var->AsProxyObjectVar(); |
| 301 if (object && object->dispatcher() == dispatcher) | 301 if (object && object->dispatcher() == dispatcher) |
| 302 object->clear_dispatcher(); | 302 object->clear_dispatcher(); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 ArrayBufferVar* PluginVarTracker::CreateArrayBuffer(uint32 size_in_bytes) { | 306 ArrayBufferVar* PluginVarTracker::CreateArrayBuffer(uint32_t size_in_bytes) { |
| 307 return new PluginArrayBufferVar(size_in_bytes); | 307 return new PluginArrayBufferVar(size_in_bytes); |
| 308 } | 308 } |
| 309 | 309 |
| 310 ArrayBufferVar* PluginVarTracker::CreateShmArrayBuffer( | 310 ArrayBufferVar* PluginVarTracker::CreateShmArrayBuffer( |
| 311 uint32 size_in_bytes, | 311 uint32_t size_in_bytes, |
| 312 base::SharedMemoryHandle handle) { | 312 base::SharedMemoryHandle handle) { |
| 313 return new PluginArrayBufferVar(size_in_bytes, handle); | 313 return new PluginArrayBufferVar(size_in_bytes, handle); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void PluginVarTracker::PluginImplementedObjectCreated( | 316 void PluginVarTracker::PluginImplementedObjectCreated( |
| 317 PP_Instance instance, | 317 PP_Instance instance, |
| 318 const PP_Var& created_var, | 318 const PP_Var& created_var, |
| 319 const PPP_Class_Deprecated* ppp_class, | 319 const PPP_Class_Deprecated* ppp_class, |
| 320 void* ppp_class_data) { | 320 void* ppp_class_data) { |
| 321 PluginImplementedVar p; | 321 PluginImplementedVar p; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 346 bool PluginVarTracker::ValidatePluginObjectCall( | 346 bool PluginVarTracker::ValidatePluginObjectCall( |
| 347 const PPP_Class_Deprecated* ppp_class, | 347 const PPP_Class_Deprecated* ppp_class, |
| 348 void* user_data) { | 348 void* user_data) { |
| 349 UserDataToPluginImplementedVarMap::iterator found = | 349 UserDataToPluginImplementedVarMap::iterator found = |
| 350 user_data_to_plugin_.find(user_data); | 350 user_data_to_plugin_.find(user_data); |
| 351 if (found == user_data_to_plugin_.end()) | 351 if (found == user_data_to_plugin_.end()) |
| 352 return false; | 352 return false; |
| 353 return found->second.ppp_class == ppp_class; | 353 return found->second.ppp_class == ppp_class; |
| 354 } | 354 } |
| 355 | 355 |
| 356 int32 PluginVarTracker::AddVarInternal(Var* var, AddVarRefMode mode) { | 356 int32_t PluginVarTracker::AddVarInternal(Var* var, AddVarRefMode mode) { |
| 357 // Normal adding. | 357 // Normal adding. |
| 358 int32 new_id = VarTracker::AddVarInternal(var, mode); | 358 int32_t new_id = VarTracker::AddVarInternal(var, mode); |
| 359 | 359 |
| 360 // Need to add proxy objects to the host var map. | 360 // Need to add proxy objects to the host var map. |
| 361 ProxyObjectVar* proxy_object = var->AsProxyObjectVar(); | 361 ProxyObjectVar* proxy_object = var->AsProxyObjectVar(); |
| 362 if (proxy_object) { | 362 if (proxy_object) { |
| 363 HostVar host_var(proxy_object->dispatcher(), proxy_object->host_var_id()); | 363 HostVar host_var(proxy_object->dispatcher(), proxy_object->host_var_id()); |
| 364 // TODO(teravest): Change to DCHECK when http://crbug.com/276347 is | 364 // TODO(teravest): Change to DCHECK when http://crbug.com/276347 is |
| 365 // resolved. | 365 // resolved. |
| 366 CHECK(host_var_to_plugin_var_.find(host_var) == | 366 CHECK(host_var_to_plugin_var_.find(host_var) == |
| 367 host_var_to_plugin_var_.end()); // Adding an object twice, use | 367 host_var_to_plugin_var_.end()); // Adding an object twice, use |
| 368 // FindOrMakePluginVarFromHostVar. | 368 // FindOrMakePluginVarFromHostVar. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 // Clean up the host var mapping. | 436 // Clean up the host var mapping. |
| 437 DCHECK(host_var_to_plugin_var_.find(host_var) != | 437 DCHECK(host_var_to_plugin_var_.find(host_var) != |
| 438 host_var_to_plugin_var_.end()); | 438 host_var_to_plugin_var_.end()); |
| 439 host_var_to_plugin_var_.erase(host_var); | 439 host_var_to_plugin_var_.erase(host_var); |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| 442 | 442 |
| 443 PP_Var PluginVarTracker::GetOrCreateObjectVarID(ProxyObjectVar* object) { | 443 PP_Var PluginVarTracker::GetOrCreateObjectVarID(ProxyObjectVar* object) { |
| 444 // We can't use object->GetPPVar() because we don't want to affect the | 444 // We can't use object->GetPPVar() because we don't want to affect the |
| 445 // refcount, so we have to add everything manually here. | 445 // refcount, so we have to add everything manually here. |
| 446 int32 var_id = object->GetExistingVarID(); | 446 int32_t var_id = object->GetExistingVarID(); |
| 447 if (!var_id) { | 447 if (!var_id) { |
| 448 var_id = AddVarInternal(object, ADD_VAR_CREATE_WITH_NO_REFERENCE); | 448 var_id = AddVarInternal(object, ADD_VAR_CREATE_WITH_NO_REFERENCE); |
| 449 object->AssignVarID(var_id); | 449 object->AssignVarID(var_id); |
| 450 } | 450 } |
| 451 | 451 |
| 452 PP_Var ret = { PP_VARTYPE_OBJECT }; | 452 PP_Var ret = { PP_VARTYPE_OBJECT }; |
| 453 ret.value.as_id = var_id; | 453 ret.value.as_id = var_id; |
| 454 return ret; | 454 return ret; |
| 455 } | 455 } |
| 456 | 456 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 474 const PP_Var& var, | 474 const PP_Var& var, |
| 475 PluginDispatcher* dispatcher) { | 475 PluginDispatcher* dispatcher) { |
| 476 DCHECK(var.type == PP_VARTYPE_OBJECT); | 476 DCHECK(var.type == PP_VARTYPE_OBJECT); |
| 477 HostVar host_var(dispatcher, var.value.as_id); | 477 HostVar host_var(dispatcher, var.value.as_id); |
| 478 | 478 |
| 479 HostVarToPluginVarMap::iterator found = | 479 HostVarToPluginVarMap::iterator found = |
| 480 host_var_to_plugin_var_.find(host_var); | 480 host_var_to_plugin_var_.find(host_var); |
| 481 if (found == host_var_to_plugin_var_.end()) { | 481 if (found == host_var_to_plugin_var_.end()) { |
| 482 // Create a new object. | 482 // Create a new object. |
| 483 return scoped_refptr<ProxyObjectVar>( | 483 return scoped_refptr<ProxyObjectVar>( |
| 484 new ProxyObjectVar(dispatcher, static_cast<int32>(var.value.as_id))); | 484 new ProxyObjectVar(dispatcher, static_cast<int32_t>(var.value.as_id))); |
| 485 } | 485 } |
| 486 | 486 |
| 487 // Have this host var, look up the object. | 487 // Have this host var, look up the object. |
| 488 VarMap::iterator ret = live_vars_.find(found->second); | 488 VarMap::iterator ret = live_vars_.find(found->second); |
| 489 | 489 |
| 490 // We CHECK here because we currently don't fall back sanely. | 490 // We CHECK here because we currently don't fall back sanely. |
| 491 // This may be involved in a NULL dereference. http://crbug.com/276347 | 491 // This may be involved in a NULL dereference. http://crbug.com/276347 |
| 492 CHECK(ret != live_vars_.end()); | 492 CHECK(ret != live_vars_.end()); |
| 493 | 493 |
| 494 // All objects should be proxy objects. | 494 // All objects should be proxy objects. |
| 495 DCHECK(ret->second.var->AsProxyObjectVar()); | 495 DCHECK(ret->second.var->AsProxyObjectVar()); |
| 496 return scoped_refptr<ProxyObjectVar>(ret->second.var->AsProxyObjectVar()); | 496 return scoped_refptr<ProxyObjectVar>(ret->second.var->AsProxyObjectVar()); |
| 497 } | 497 } |
| 498 | 498 |
| 499 int PluginVarTracker::TrackSharedMemoryHandle(PP_Instance instance, | 499 int PluginVarTracker::TrackSharedMemoryHandle(PP_Instance instance, |
| 500 base::SharedMemoryHandle handle, | 500 base::SharedMemoryHandle handle, |
| 501 uint32 size_in_bytes) { | 501 uint32_t size_in_bytes) { |
| 502 NOTREACHED(); | 502 NOTREACHED(); |
| 503 return -1; | 503 return -1; |
| 504 } | 504 } |
| 505 | 505 |
| 506 bool PluginVarTracker::StopTrackingSharedMemoryHandle( | 506 bool PluginVarTracker::StopTrackingSharedMemoryHandle( |
| 507 int id, | 507 int id, |
| 508 PP_Instance instance, | 508 PP_Instance instance, |
| 509 base::SharedMemoryHandle* handle, | 509 base::SharedMemoryHandle* handle, |
| 510 uint32* size_in_bytes) { | 510 uint32_t* size_in_bytes) { |
| 511 NOTREACHED(); | 511 NOTREACHED(); |
| 512 return false; | 512 return false; |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namesace proxy | 515 } // namesace proxy |
| 516 } // namespace ppapi | 516 } // namespace ppapi |
| OLD | NEW |