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/ppb_var_deprecated_proxy.h" | 5 #include "ppapi/proxy/ppb_var_deprecated_proxy.h" |
6 | 6 |
7 #include <stdlib.h> // For malloc | 7 #include <stdlib.h> // For malloc |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 bool IsInstanceOf(PP_Var var, | 232 bool IsInstanceOf(PP_Var var, |
233 const PPP_Class_Deprecated* ppp_class, | 233 const PPP_Class_Deprecated* ppp_class, |
234 void** ppp_class_data) { | 234 void** ppp_class_data) { |
235 ProxyAutoLock lock; | 235 ProxyAutoLock lock; |
236 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, NULL); | 236 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, NULL); |
237 if (!dispatcher) | 237 if (!dispatcher) |
238 return false; | 238 return false; |
239 | 239 |
240 PP_Bool result = PP_FALSE; | 240 PP_Bool result = PP_FALSE; |
241 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); | 241 int64_t class_int = |
242 int64 class_data_int = 0; | 242 static_cast<int64_t>(reinterpret_cast<intptr_t>(ppp_class)); |
| 243 int64_t class_data_int = 0; |
243 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated( | 244 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated( |
244 API_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var), | 245 API_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var), |
245 class_int, &class_data_int, &result)); | 246 class_int, &class_data_int, &result)); |
246 *ppp_class_data = | 247 *ppp_class_data = |
247 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int)); | 248 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int)); |
248 return PP_ToBool(result); | 249 return PP_ToBool(result); |
249 } | 250 } |
250 | 251 |
251 PP_Var CreateObject(PP_Instance instance, | 252 PP_Var CreateObject(PP_Instance instance, |
252 const PPP_Class_Deprecated* ppp_class, | 253 const PPP_Class_Deprecated* ppp_class, |
253 void* ppp_class_data) { | 254 void* ppp_class_data) { |
254 ProxyAutoLock lock; | 255 ProxyAutoLock lock; |
255 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 256 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
256 if (!dispatcher) | 257 if (!dispatcher) |
257 return PP_MakeUndefined(); | 258 return PP_MakeUndefined(); |
258 | 259 |
259 PluginVarTracker* tracker = PluginGlobals::Get()->plugin_var_tracker(); | 260 PluginVarTracker* tracker = PluginGlobals::Get()->plugin_var_tracker(); |
260 if (tracker->IsPluginImplementedObjectAlive(ppp_class_data)) | 261 if (tracker->IsPluginImplementedObjectAlive(ppp_class_data)) |
261 return PP_MakeUndefined(); // Object already exists with this user data. | 262 return PP_MakeUndefined(); // Object already exists with this user data. |
262 | 263 |
263 ReceiveSerializedVarReturnValue result; | 264 ReceiveSerializedVarReturnValue result; |
264 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); | 265 int64_t class_int = |
265 int64 data_int = | 266 static_cast<int64_t>(reinterpret_cast<intptr_t>(ppp_class)); |
266 static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class_data)); | 267 int64_t data_int = |
| 268 static_cast<int64_t>(reinterpret_cast<intptr_t>(ppp_class_data)); |
267 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated( | 269 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated( |
268 API_ID_PPB_VAR_DEPRECATED, instance, class_int, data_int, | 270 API_ID_PPB_VAR_DEPRECATED, instance, class_int, data_int, |
269 &result)); | 271 &result)); |
270 PP_Var ret_var = result.Return(dispatcher); | 272 PP_Var ret_var = result.Return(dispatcher); |
271 | 273 |
272 // Register this object as being implemented by the plugin. | 274 // Register this object as being implemented by the plugin. |
273 if (ret_var.type == PP_VARTYPE_OBJECT) { | 275 if (ret_var.type == PP_VARTYPE_OBJECT) { |
274 tracker->PluginImplementedObjectCreated(instance, ret_var, | 276 tracker->PluginImplementedObjectCreated(instance, ret_var, |
275 ppp_class, ppp_class_data); | 277 ppp_class, ppp_class_data); |
276 } | 278 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_IsInstanceOfDeprecated, | 350 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_IsInstanceOfDeprecated, |
349 OnMsgIsInstanceOfDeprecated) | 351 OnMsgIsInstanceOfDeprecated) |
350 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_CreateObjectDeprecated, | 352 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_CreateObjectDeprecated, |
351 OnMsgCreateObjectDeprecated) | 353 OnMsgCreateObjectDeprecated) |
352 IPC_MESSAGE_UNHANDLED(handled = false) | 354 IPC_MESSAGE_UNHANDLED(handled = false) |
353 IPC_END_MESSAGE_MAP() | 355 IPC_END_MESSAGE_MAP() |
354 // TODO(brettw) handle bad messages! | 356 // TODO(brettw) handle bad messages! |
355 return handled; | 357 return handled; |
356 } | 358 } |
357 | 359 |
358 void PPB_Var_Deprecated_Proxy::OnMsgAddRefObject(int64 object_id) { | 360 void PPB_Var_Deprecated_Proxy::OnMsgAddRefObject(int64_t object_id) { |
359 PP_Var var = { PP_VARTYPE_OBJECT }; | 361 PP_Var var = { PP_VARTYPE_OBJECT }; |
360 var.value.as_id = object_id; | 362 var.value.as_id = object_id; |
361 ppb_var_impl_->AddRef(var); | 363 ppb_var_impl_->AddRef(var); |
362 } | 364 } |
363 | 365 |
364 void PPB_Var_Deprecated_Proxy::OnMsgReleaseObject(int64 object_id) { | 366 void PPB_Var_Deprecated_Proxy::OnMsgReleaseObject(int64_t object_id) { |
365 // Ok, so this is super subtle. | 367 // Ok, so this is super subtle. |
366 // When the browser side sends a sync IPC message that returns a var, and the | 368 // When the browser side sends a sync IPC message that returns a var, and the |
367 // plugin wants to give ownership of that var to the browser, dropping all | 369 // plugin wants to give ownership of that var to the browser, dropping all |
368 // references, it may call ReleaseObject right after returning the result. | 370 // references, it may call ReleaseObject right after returning the result. |
369 // However, the IPC system doesn't enforce strict ordering of messages in that | 371 // However, the IPC system doesn't enforce strict ordering of messages in that |
370 // case, where a message that is set to unblock (e.g. a sync message, or in | 372 // case, where a message that is set to unblock (e.g. a sync message, or in |
371 // our case all messages coming from the plugin) that is sent *after* the | 373 // our case all messages coming from the plugin) that is sent *after* the |
372 // result may be dispatched on the browser side *before* the sync send | 374 // result may be dispatched on the browser side *before* the sync send |
373 // returned (see ipc_sync_channel.cc). In this case, that means it could | 375 // returned (see ipc_sync_channel.cc). In this case, that means it could |
374 // release the object before it is AddRef'ed on the browser side. | 376 // release the object before it is AddRef'ed on the browser side. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 SetAllowPluginReentrancy(); | 484 SetAllowPluginReentrancy(); |
483 uint32_t arg_count = 0; | 485 uint32_t arg_count = 0; |
484 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); | 486 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
485 result.Return(dispatcher(), ppb_var_impl_->Construct( | 487 result.Return(dispatcher(), ppb_var_impl_->Construct( |
486 var.Get(dispatcher()), arg_count, args, | 488 var.Get(dispatcher()), arg_count, args, |
487 exception.OutParam(dispatcher()))); | 489 exception.OutParam(dispatcher()))); |
488 } | 490 } |
489 | 491 |
490 void PPB_Var_Deprecated_Proxy::OnMsgIsInstanceOfDeprecated( | 492 void PPB_Var_Deprecated_Proxy::OnMsgIsInstanceOfDeprecated( |
491 SerializedVarReceiveInput var, | 493 SerializedVarReceiveInput var, |
492 int64 ppp_class, | 494 int64_t ppp_class, |
493 int64* ppp_class_data, | 495 int64_t* ppp_class_data, |
494 PP_Bool* result) { | 496 PP_Bool* result) { |
495 SetAllowPluginReentrancy(); | 497 SetAllowPluginReentrancy(); |
496 *result = PPP_Class_Proxy::IsInstanceOf(ppb_var_impl_, | 498 *result = PPP_Class_Proxy::IsInstanceOf(ppb_var_impl_, |
497 var.Get(dispatcher()), | 499 var.Get(dispatcher()), |
498 ppp_class, | 500 ppp_class, |
499 ppp_class_data); | 501 ppp_class_data); |
500 } | 502 } |
501 | 503 |
502 void PPB_Var_Deprecated_Proxy::OnMsgCreateObjectDeprecated( | 504 void PPB_Var_Deprecated_Proxy::OnMsgCreateObjectDeprecated( |
503 PP_Instance instance, | 505 PP_Instance instance, |
504 int64 ppp_class, | 506 int64_t ppp_class, |
505 int64 class_data, | 507 int64_t class_data, |
506 SerializedVarReturnValue result) { | 508 SerializedVarReturnValue result) { |
507 SetAllowPluginReentrancy(); | 509 SetAllowPluginReentrancy(); |
508 result.Return(dispatcher(), PPP_Class_Proxy::CreateProxiedObject( | 510 result.Return(dispatcher(), PPP_Class_Proxy::CreateProxiedObject( |
509 ppb_var_impl_, dispatcher(), instance, ppp_class, class_data)); | 511 ppb_var_impl_, dispatcher(), instance, ppp_class, class_data)); |
510 } | 512 } |
511 | 513 |
512 void PPB_Var_Deprecated_Proxy::SetAllowPluginReentrancy() { | 514 void PPB_Var_Deprecated_Proxy::SetAllowPluginReentrancy() { |
513 if (dispatcher()->IsPlugin()) | 515 if (dispatcher()->IsPlugin()) |
514 NOTREACHED(); | 516 NOTREACHED(); |
515 else | 517 else |
516 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy(); | 518 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy(); |
517 } | 519 } |
518 | 520 |
519 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { | 521 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64_t object_id) { |
520 PP_Var var = { PP_VARTYPE_OBJECT }; | 522 PP_Var var = { PP_VARTYPE_OBJECT }; |
521 var.value.as_id = object_id; | 523 var.value.as_id = object_id; |
522 ppb_var_impl_->Release(var); | 524 ppb_var_impl_->Release(var); |
523 } | 525 } |
524 | 526 |
525 } // namespace proxy | 527 } // namespace proxy |
526 } // namespace ppapi | 528 } // namespace ppapi |
OLD | NEW |