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_testing_proxy.h" | 5 #include "ppapi/proxy/ppb_testing_proxy.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "ppapi/c/dev/ppb_testing_dev.h" | 8 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 9 #include "ppapi/proxy/enter_proxy.h" |
9 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
11 #include "ppapi/shared_impl/ppapi_globals.h" | 12 #include "ppapi/shared_impl/ppapi_globals.h" |
12 #include "ppapi/shared_impl/resource.h" | 13 #include "ppapi/shared_impl/resource.h" |
13 #include "ppapi/shared_impl/resource_tracker.h" | 14 #include "ppapi/shared_impl/resource_tracker.h" |
| 15 #include "ppapi/thunk/enter.h" |
| 16 #include "ppapi/thunk/ppb_input_event_api.h" |
| 17 |
| 18 using ppapi::thunk::EnterResource; |
| 19 using ppapi::thunk::PPB_InputEvent_API; |
14 | 20 |
15 namespace ppapi { | 21 namespace ppapi { |
16 namespace proxy { | 22 namespace proxy { |
17 | 23 |
18 namespace { | 24 namespace { |
19 | 25 |
20 PP_Bool ReadImageData(PP_Resource graphics_2d, | 26 PP_Bool ReadImageData(PP_Resource graphics_2d, |
21 PP_Resource image, | 27 PP_Resource image, |
22 const PP_Point* top_left) { | 28 const PP_Point* top_left) { |
23 Resource* image_object = | 29 Resource* image_object = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 uint32_t result = 0; | 67 uint32_t result = 0; |
62 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( | 68 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( |
63 API_ID_PPB_TESTING, instance_id, &result)); | 69 API_ID_PPB_TESTING, instance_id, &result)); |
64 return result; | 70 return result; |
65 } | 71 } |
66 | 72 |
67 PP_Bool IsOutOfProcess() { | 73 PP_Bool IsOutOfProcess() { |
68 return PP_TRUE; | 74 return PP_TRUE; |
69 } | 75 } |
70 | 76 |
| 77 void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) { |
| 78 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 79 if (!dispatcher) |
| 80 return; |
| 81 EnterResource<PPB_InputEvent_API> enter(input_event, false); |
| 82 if (enter.failed()) { |
| 83 NOTREACHED(); |
| 84 return; |
| 85 } |
| 86 |
| 87 const InputEventData& input_event_data = enter.object()->GetInputEventData(); |
| 88 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent( |
| 89 API_ID_PPB_TESTING, instance_id, input_event_data)); |
| 90 } |
| 91 |
71 const PPB_Testing_Dev testing_interface = { | 92 const PPB_Testing_Dev testing_interface = { |
72 &ReadImageData, | 93 &ReadImageData, |
73 &RunMessageLoop, | 94 &RunMessageLoop, |
74 &QuitMessageLoop, | 95 &QuitMessageLoop, |
75 &GetLiveObjectsForInstance, | 96 &GetLiveObjectsForInstance, |
76 &IsOutOfProcess | 97 &IsOutOfProcess, |
| 98 &SimulateInputEvent |
77 }; | 99 }; |
78 | 100 |
79 InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { | 101 InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { |
80 return new PPB_Testing_Proxy(dispatcher); | 102 return new PPB_Testing_Proxy(dispatcher); |
81 } | 103 } |
82 | 104 |
83 } // namespace | 105 } // namespace |
84 | 106 |
85 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) | 107 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) |
86 : InterfaceProxy(dispatcher), | 108 : InterfaceProxy(dispatcher), |
(...skipping 19 matching lines...) Expand all Loading... |
106 return &info; | 128 return &info; |
107 } | 129 } |
108 | 130 |
109 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { | 131 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
110 bool handled = true; | 132 bool handled = true; |
111 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) | 133 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, | 134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
113 OnMsgReadImageData) | 135 OnMsgReadImageData) |
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, | 136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, |
115 OnMsgGetLiveObjectsForInstance) | 137 OnMsgGetLiveObjectsForInstance) |
| 138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_SimulateInputEvent, |
| 139 OnMsgSimulateInputEvent) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 140 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 141 IPC_END_MESSAGE_MAP() |
118 return handled; | 142 return handled; |
119 } | 143 } |
120 | 144 |
121 void PPB_Testing_Proxy::OnMsgReadImageData( | 145 void PPB_Testing_Proxy::OnMsgReadImageData( |
122 const HostResource& device_context_2d, | 146 const HostResource& device_context_2d, |
123 const HostResource& image, | 147 const HostResource& image, |
124 const PP_Point& top_left, | 148 const PP_Point& top_left, |
125 PP_Bool* result) { | 149 PP_Bool* result) { |
126 *result = ppb_testing_impl_->ReadImageData( | 150 *result = ppb_testing_impl_->ReadImageData( |
127 device_context_2d.host_resource(), image.host_resource(), &top_left); | 151 device_context_2d.host_resource(), image.host_resource(), &top_left); |
128 } | 152 } |
129 | 153 |
130 void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { | 154 void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { |
131 ppb_testing_impl_->RunMessageLoop(instance); | 155 ppb_testing_impl_->RunMessageLoop(instance); |
132 } | 156 } |
133 | 157 |
134 void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { | 158 void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { |
135 ppb_testing_impl_->QuitMessageLoop(instance); | 159 ppb_testing_impl_->QuitMessageLoop(instance); |
136 } | 160 } |
137 | 161 |
138 void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, | 162 void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, |
139 uint32_t* result) { | 163 uint32_t* result) { |
140 *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance); | 164 *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance); |
141 } | 165 } |
142 | 166 |
| 167 void PPB_Testing_Proxy::OnMsgSimulateInputEvent( |
| 168 PP_Instance instance, |
| 169 const InputEventData& input_event) { |
| 170 scoped_refptr<InputEventImpl> input_event_impl( |
| 171 new InputEventImpl(InputEventImpl::InitAsProxy(), |
| 172 instance, |
| 173 input_event)); |
| 174 ppb_testing_impl_->SimulateInputEvent(instance, |
| 175 input_event_impl->pp_resource()); |
| 176 } |
| 177 |
143 } // namespace proxy | 178 } // namespace proxy |
144 } // namespace ppapi | 179 } // namespace ppapi |
OLD | NEW |