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