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_instance_proxy.h" | 5 #include "ppapi/proxy/ppb_instance_proxy.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 #include "ppapi/c/ppb_instance.h" | 9 #include "ppapi/c/ppb_instance.h" |
10 #include "ppapi/c/ppb_messaging.h" | 10 #include "ppapi/c/ppb_messaging.h" |
11 #include "ppapi/c/ppb_mouse_lock.h" | 11 #include "ppapi/c/ppb_mouse_lock.h" |
| 12 #include "ppapi/proxy/enter_proxy.h" |
12 #include "ppapi/proxy/host_dispatcher.h" | 13 #include "ppapi/proxy/host_dispatcher.h" |
13 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
14 #include "ppapi/proxy/plugin_resource_tracker.h" | 15 #include "ppapi/proxy/plugin_resource_tracker.h" |
15 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/proxy/serialized_var.h" | 17 #include "ppapi/proxy/serialized_var.h" |
17 #include "ppapi/shared_impl/url_util_impl.h" | 18 #include "ppapi/shared_impl/url_util_impl.h" |
18 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
19 #include "ppapi/thunk/thunk.h" | 20 #include "ppapi/thunk/thunk.h" |
20 | 21 |
21 // Windows headers interfere with this file. | 22 // Windows headers interfere with this file. |
(...skipping 12 matching lines...) Expand all Loading... |
34 | 35 |
35 typedef EnterFunctionNoLock<PPB_Instance_FunctionAPI> EnterInstanceNoLock; | 36 typedef EnterFunctionNoLock<PPB_Instance_FunctionAPI> EnterInstanceNoLock; |
36 | 37 |
37 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher) { | 38 InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher) { |
38 return new PPB_Instance_Proxy(dispatcher); | 39 return new PPB_Instance_Proxy(dispatcher); |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher) | 44 PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher) |
44 : InterfaceProxy(dispatcher) { | 45 : InterfaceProxy(dispatcher), |
| 46 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
45 } | 47 } |
46 | 48 |
47 PPB_Instance_Proxy::~PPB_Instance_Proxy() { | 49 PPB_Instance_Proxy::~PPB_Instance_Proxy() { |
48 } | 50 } |
49 | 51 |
50 // static | 52 // static |
51 const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoPrivate() { | 53 const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoPrivate() { |
52 static const Info info = { | 54 static const Info info = { |
53 ppapi::thunk::GetPPB_Instance_Private_Thunk(), | 55 ppapi::thunk::GetPPB_Instance_Private_Thunk(), |
54 PPB_INSTANCE_PRIVATE_INTERFACE, | 56 PPB_INSTANCE_PRIVATE_INTERFACE, |
55 INTERFACE_ID_NONE, // 1_0 is the canonical one. | 57 INTERFACE_ID_NONE, // 1_0 is the canonical one. |
56 false, | 58 false, |
57 &CreateInstanceProxy, | 59 &CreateInstanceProxy, |
58 }; | 60 }; |
59 return &info; | 61 return &info; |
60 } | 62 } |
61 | 63 |
62 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { | 64 bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { |
63 // Prevent the dispatcher from going away during a call to ExecuteScript. | 65 // Prevent the dispatcher from going away during a call to ExecuteScript. |
64 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use | 66 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use |
65 // the dispatcher upon return of the function (converting the | 67 // the dispatcher upon return of the function (converting the |
66 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor). | 68 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor). |
67 ScopedModuleReference death_grip(dispatcher()); | 69 ScopedModuleReference death_grip(dispatcher()); |
68 | 70 |
69 bool handled = true; | 71 bool handled = true; |
70 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg) | 72 IPC_BEGIN_MESSAGE_MAP(PPB_Instance_Proxy, msg) |
| 73 // Plugin -> Host messages. |
71 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject, | 74 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetWindowObject, |
72 OnMsgGetWindowObject) | 75 OnMsgGetWindowObject) |
73 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject, | 76 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetOwnerElementObject, |
74 OnMsgGetOwnerElementObject) | 77 OnMsgGetOwnerElementObject) |
75 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics, | 78 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_BindGraphics, |
76 OnMsgBindGraphics) | 79 OnMsgBindGraphics) |
77 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame, | 80 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_IsFullFrame, |
78 OnMsgIsFullFrame) | 81 OnMsgIsFullFrame) |
79 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript, | 82 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript, |
80 OnMsgExecuteScript) | 83 OnMsgExecuteScript) |
(...skipping 24 matching lines...) Expand all Loading... |
105 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument, | 108 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument, |
106 OnMsgResolveRelativeToDocument) | 109 OnMsgResolveRelativeToDocument) |
107 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest, | 110 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest, |
108 OnMsgDocumentCanRequest) | 111 OnMsgDocumentCanRequest) |
109 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument, | 112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument, |
110 OnMsgDocumentCanAccessDocument) | 113 OnMsgDocumentCanAccessDocument) |
111 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL, | 114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL, |
112 OnMsgGetDocumentURL) | 115 OnMsgGetDocumentURL) |
113 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL, | 116 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL, |
114 OnMsgGetPluginInstanceURL) | 117 OnMsgGetPluginInstanceURL) |
| 118 |
| 119 // Host -> Plugin messages. |
| 120 IPC_MESSAGE_HANDLER(PpapiMsg_PPBInstance_MouseLockComplete, |
| 121 OnMsgMouseLockComplete) |
| 122 |
115 IPC_MESSAGE_UNHANDLED(handled = false) | 123 IPC_MESSAGE_UNHANDLED(handled = false) |
116 IPC_END_MESSAGE_MAP() | 124 IPC_END_MESSAGE_MAP() |
117 return handled; | 125 return handled; |
118 } | 126 } |
119 | 127 |
120 PPB_Instance_FunctionAPI* PPB_Instance_Proxy::AsPPB_Instance_FunctionAPI() { | 128 PPB_Instance_FunctionAPI* PPB_Instance_Proxy::AsPPB_Instance_FunctionAPI() { |
121 return this; | 129 return this; |
122 } | 130 } |
123 | 131 |
124 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance, | 132 PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance, |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage( | 367 dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage( |
360 INTERFACE_ID_PPB_INSTANCE, | 368 INTERFACE_ID_PPB_INSTANCE, |
361 instance, SerializedVarSendInput(dispatcher(), message))); | 369 instance, SerializedVarSendInput(dispatcher(), message))); |
362 } | 370 } |
363 | 371 |
364 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance, | 372 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance, |
365 PP_CompletionCallback callback) { | 373 PP_CompletionCallback callback) { |
366 if (!callback.func) | 374 if (!callback.func) |
367 return PP_ERROR_BADARGUMENT; | 375 return PP_ERROR_BADARGUMENT; |
368 | 376 |
| 377 // Save the mouse callback on the instance data. |
| 378 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
| 379 GetInstanceData(instance); |
| 380 if (!data) |
| 381 return PP_ERROR_BADARGUMENT; |
| 382 if (data->mouse_lock_callback.func) |
| 383 return PP_ERROR_INPROGRESS; // Already have a pending callback. |
| 384 data->mouse_lock_callback = callback; |
| 385 |
369 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse( | 386 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse( |
370 INTERFACE_ID_PPB_INSTANCE, instance, SendCallback(callback))); | 387 INTERFACE_ID_PPB_INSTANCE, instance)); |
371 return PP_OK_COMPLETIONPENDING; | 388 return PP_OK_COMPLETIONPENDING; |
372 } | 389 } |
373 | 390 |
374 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) { | 391 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) { |
375 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse( | 392 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse( |
376 INTERFACE_ID_PPB_INSTANCE, instance)); | 393 INTERFACE_ID_PPB_INSTANCE, instance)); |
377 } | 394 } |
378 | 395 |
379 void PPB_Instance_Proxy::OnMsgGetWindowObject( | 396 void PPB_Instance_Proxy::OnMsgGetWindowObject( |
380 PP_Instance instance, | 397 PP_Instance instance, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 enter.functions()->ClearInputEventRequest(instance, event_classes); | 528 enter.functions()->ClearInputEventRequest(instance, event_classes); |
512 } | 529 } |
513 | 530 |
514 void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance, | 531 void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance, |
515 SerializedVarReceiveInput message) { | 532 SerializedVarReceiveInput message) { |
516 EnterInstanceNoLock enter(instance, false); | 533 EnterInstanceNoLock enter(instance, false); |
517 if (enter.succeeded()) | 534 if (enter.succeeded()) |
518 enter.functions()->PostMessage(instance, message.Get(dispatcher())); | 535 enter.functions()->PostMessage(instance, message.Get(dispatcher())); |
519 } | 536 } |
520 | 537 |
521 void PPB_Instance_Proxy::OnMsgLockMouse(PP_Instance instance, | 538 void PPB_Instance_Proxy::OnMsgLockMouse(PP_Instance instance) { |
522 uint32_t serialized_callback) { | 539 EnterHostFunctionForceCallback<PPB_Instance_FunctionAPI> enter( |
523 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); | 540 instance, callback_factory_, |
524 if (enter.failed()) | 541 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance); |
525 return; | 542 if (enter.succeeded()) |
526 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); | 543 enter.SetResult(enter.functions()->LockMouse(instance, enter.callback())); |
527 int32_t result = enter.functions()->LockMouse(instance, callback); | |
528 if (result != PP_OK_COMPLETIONPENDING) | |
529 PP_RunCompletionCallback(&callback, result); | |
530 } | 544 } |
531 | 545 |
532 void PPB_Instance_Proxy::OnMsgUnlockMouse(PP_Instance instance) { | 546 void PPB_Instance_Proxy::OnMsgUnlockMouse(PP_Instance instance) { |
533 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); | 547 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); |
534 if (enter.succeeded()) | 548 if (enter.succeeded()) |
535 enter.functions()->UnlockMouse(instance); | 549 enter.functions()->UnlockMouse(instance); |
536 } | 550 } |
537 | 551 |
538 void PPB_Instance_Proxy::OnMsgResolveRelativeToDocument( | 552 void PPB_Instance_Proxy::OnMsgResolveRelativeToDocument( |
539 PP_Instance instance, | 553 PP_Instance instance, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 void PPB_Instance_Proxy::OnMsgGetPluginInstanceURL( | 591 void PPB_Instance_Proxy::OnMsgGetPluginInstanceURL( |
578 PP_Instance instance, | 592 PP_Instance instance, |
579 SerializedVarReturnValue result) { | 593 SerializedVarReturnValue result) { |
580 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); | 594 EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); |
581 if (enter.succeeded()) { | 595 if (enter.succeeded()) { |
582 result.Return(dispatcher(), | 596 result.Return(dispatcher(), |
583 enter.functions()->GetPluginInstanceURL(instance, NULL)); | 597 enter.functions()->GetPluginInstanceURL(instance, NULL)); |
584 } | 598 } |
585 } | 599 } |
586 | 600 |
| 601 void PPB_Instance_Proxy::OnMsgMouseLockComplete(PP_Instance instance, |
| 602 int32_t result) { |
| 603 // Save the mouse callback on the instance data. |
| 604 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
| 605 GetInstanceData(instance); |
| 606 if (!data) |
| 607 return; // Instance was probably deleted. |
| 608 if (!data->mouse_lock_callback.func) { |
| 609 NOTREACHED(); |
| 610 return; |
| 611 } |
| 612 PP_RunAndClearCompletionCallback(&data->mouse_lock_callback, result); |
| 613 } |
| 614 |
| 615 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result, |
| 616 PP_Instance instance) { |
| 617 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete( |
| 618 INTERFACE_ID_PPB_INSTANCE, instance, result)); |
| 619 } |
| 620 |
587 } // namespace proxy | 621 } // namespace proxy |
588 } // namespace ppapi | 622 } // namespace ppapi |
OLD | NEW |