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 "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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" |
| 11 #include "base/task.h" |
10 #include "ppapi/c/dev/ppb_var_deprecated.h" | 12 #include "ppapi/c/dev/ppb_var_deprecated.h" |
11 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
13 #include "ppapi/proxy/host_dispatcher.h" | 15 #include "ppapi/proxy/host_dispatcher.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_var_tracker.h" | 17 #include "ppapi/proxy/plugin_var_tracker.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/proxy/ppp_class_proxy.h" | 19 #include "ppapi/proxy/ppp_class_proxy.h" |
18 #include "ppapi/proxy/serialized_var.h" | 20 #include "ppapi/proxy/serialized_var.h" |
19 | 21 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 InterfaceProxy* CreateVarDeprecatedProxy(Dispatcher* dispatcher, | 291 InterfaceProxy* CreateVarDeprecatedProxy(Dispatcher* dispatcher, |
290 const void* target_interface) { | 292 const void* target_interface) { |
291 return new PPB_Var_Deprecated_Proxy(dispatcher, target_interface); | 293 return new PPB_Var_Deprecated_Proxy(dispatcher, target_interface); |
292 } | 294 } |
293 | 295 |
294 } // namespace | 296 } // namespace |
295 | 297 |
296 PPB_Var_Deprecated_Proxy::PPB_Var_Deprecated_Proxy( | 298 PPB_Var_Deprecated_Proxy::PPB_Var_Deprecated_Proxy( |
297 Dispatcher* dispatcher, | 299 Dispatcher* dispatcher, |
298 const void* target_interface) | 300 const void* target_interface) |
299 : InterfaceProxy(dispatcher, target_interface) { | 301 : InterfaceProxy(dispatcher, target_interface), |
| 302 task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
300 } | 303 } |
301 | 304 |
302 PPB_Var_Deprecated_Proxy::~PPB_Var_Deprecated_Proxy() { | 305 PPB_Var_Deprecated_Proxy::~PPB_Var_Deprecated_Proxy() { |
303 } | 306 } |
304 | 307 |
305 // static | 308 // static |
306 const InterfaceProxy::Info* PPB_Var_Deprecated_Proxy::GetInfo() { | 309 const InterfaceProxy::Info* PPB_Var_Deprecated_Proxy::GetInfo() { |
307 static const Info info = { | 310 static const Info info = { |
308 &var_deprecated_interface, | 311 &var_deprecated_interface, |
309 PPB_VAR_DEPRECATED_INTERFACE, | 312 PPB_VAR_DEPRECATED_INTERFACE, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 357 |
355 void PPB_Var_Deprecated_Proxy::OnMsgAddRefObject(int64 object_id, | 358 void PPB_Var_Deprecated_Proxy::OnMsgAddRefObject(int64 object_id, |
356 int* /* unused */) { | 359 int* /* unused */) { |
357 PP_Var var; | 360 PP_Var var; |
358 var.type = PP_VARTYPE_OBJECT; | 361 var.type = PP_VARTYPE_OBJECT; |
359 var.value.as_id = object_id; | 362 var.value.as_id = object_id; |
360 ppb_var_target()->AddRef(var); | 363 ppb_var_target()->AddRef(var); |
361 } | 364 } |
362 | 365 |
363 void PPB_Var_Deprecated_Proxy::OnMsgReleaseObject(int64 object_id) { | 366 void PPB_Var_Deprecated_Proxy::OnMsgReleaseObject(int64 object_id) { |
364 PP_Var var; | 367 // Ok, so this is super subtle. |
365 var.type = PP_VARTYPE_OBJECT; | 368 // When the browser side sends a sync IPC message that returns a var, and the |
366 var.value.as_id = object_id; | 369 // plugin wants to give ownership of that var to the browser, dropping all |
367 ppb_var_target()->Release(var); | 370 // references, it may call ReleaseObject right after returning the result. |
| 371 // However, the IPC system doesn't enforce strict ordering of messages in that |
| 372 // case, where a message that is set to unblock (e.g. a sync message, or in |
| 373 // our case all messages coming from the plugin) that is sent *after* the |
| 374 // result may be dispatched on the browser side *before* the sync send |
| 375 // returned (see ipc_sync_channel.cc). In this case, that means it could |
| 376 // release the object before it is AddRef'ed on the browser side. |
| 377 // To work around this, we post a task here, that will not execute before |
| 378 // control goes back to the main message loop, that will ensure the sync send |
| 379 // has returned and the browser side can take its reference before we Release. |
| 380 // Note: if the instance is gone by the time the task is executed, then it |
| 381 // will Release the objects itself and this Release will be a NOOP (aside of a |
| 382 // spurious warning). |
| 383 // TODO(piman): See if we can fix the IPC code to enforce strict ordering, and |
| 384 // then remove this. |
| 385 MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
| 386 task_factory_.NewRunnableMethod( |
| 387 &PPB_Var_Deprecated_Proxy::DoReleaseObject, object_id)); |
368 } | 388 } |
369 | 389 |
370 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( | 390 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( |
371 SerializedVarReceiveInput var, | 391 SerializedVarReceiveInput var, |
372 SerializedVarReceiveInput name, | 392 SerializedVarReceiveInput name, |
373 SerializedVarOutParam exception, | 393 SerializedVarOutParam exception, |
374 PP_Bool* result) { | 394 PP_Bool* result) { |
375 SetAllowPluginReentrancy(); | 395 SetAllowPluginReentrancy(); |
376 *result = BoolToPPBool(ppb_var_target()->HasProperty( | 396 *result = BoolToPPBool(ppb_var_target()->HasProperty( |
377 var.Get(dispatcher()), | 397 var.Get(dispatcher()), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 ppb_var_target(), dispatcher(), instance, ppp_class, class_data)); | 505 ppb_var_target(), dispatcher(), instance, ppp_class, class_data)); |
486 } | 506 } |
487 | 507 |
488 void PPB_Var_Deprecated_Proxy::SetAllowPluginReentrancy() { | 508 void PPB_Var_Deprecated_Proxy::SetAllowPluginReentrancy() { |
489 if (dispatcher()->IsPlugin()) | 509 if (dispatcher()->IsPlugin()) |
490 NOTREACHED(); | 510 NOTREACHED(); |
491 else | 511 else |
492 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy(); | 512 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy(); |
493 } | 513 } |
494 | 514 |
| 515 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { |
| 516 PP_Var var; |
| 517 var.type = PP_VARTYPE_OBJECT; |
| 518 var.value.as_id = object_id; |
| 519 ppb_var_target()->Release(var); |
| 520 } |
| 521 |
495 } // namespace proxy | 522 } // namespace proxy |
496 } // namespace pp | 523 } // namespace pp |
OLD | NEW |