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/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 uint32_t result = 0; | 61 uint32_t result = 0; |
62 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( | 62 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( |
63 API_ID_PPB_TESTING, instance_id, &result)); | 63 API_ID_PPB_TESTING, instance_id, &result)); |
64 return result; | 64 return result; |
65 } | 65 } |
66 | 66 |
67 PP_Bool IsOutOfProcess() { | 67 PP_Bool IsOutOfProcess() { |
68 return PP_TRUE; | 68 return PP_TRUE; |
69 } | 69 } |
70 | 70 |
| 71 void GenerateKeyEvent( |
| 72 PP_Instance instance, |
| 73 PP_InputEvent_Type type, |
| 74 const PP_InputEvent_Key& key_event) { |
| 75 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 76 if (dispatcher) { |
| 77 dispatcher->Send(new PpapiHostMsg_PPBTesting_GenerateKeyEvent( |
| 78 API_ID_PPB_TESTING, instance, type, key_event)); |
| 79 } |
| 80 } |
| 81 |
| 82 void GenerateCharacterEvent( |
| 83 PP_Instance instance, |
| 84 const PP_InputEvent_Character& character_event) |
| 85 { |
| 86 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 87 if (dispatcher) { |
| 88 std::string text(character_event.text); |
| 89 dispatcher->Send(new PpapiHostMsg_PPBTesting_GenerateCharacterEvent( |
| 90 API_ID_PPB_TESTING, |
| 91 instance, |
| 92 static_cast<PP_InputEvent_Modifier>(character_event.modifier), |
| 93 text)); |
| 94 } |
| 95 } |
| 96 |
| 97 void GenerateMouseEvent( |
| 98 PP_Instance instance, |
| 99 PP_InputEvent_Type type, |
| 100 const PP_InputEvent_Mouse& mouse_event) |
| 101 { |
| 102 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 103 if (dispatcher) { |
| 104 dispatcher->Send(new PpapiHostMsg_PPBTesting_GenerateMouseEvent( |
| 105 API_ID_PPB_TESTING, instance, type, mouse_event)); |
| 106 } |
| 107 } |
| 108 |
| 109 void GenerateWheelEvent( |
| 110 PP_Instance instance, |
| 111 const PP_InputEvent_Wheel& wheel_event) |
| 112 { |
| 113 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 114 if (dispatcher) { |
| 115 dispatcher->Send(new PpapiHostMsg_PPBTesting_GenerateWheelEvent( |
| 116 API_ID_PPB_TESTING, instance, wheel_event)); |
| 117 } |
| 118 } |
| 119 |
71 const PPB_Testing_Dev testing_interface = { | 120 const PPB_Testing_Dev testing_interface = { |
72 &ReadImageData, | 121 &ReadImageData, |
73 &RunMessageLoop, | 122 &RunMessageLoop, |
74 &QuitMessageLoop, | 123 &QuitMessageLoop, |
75 &GetLiveObjectsForInstance, | 124 &GetLiveObjectsForInstance, |
76 &IsOutOfProcess | 125 &IsOutOfProcess, |
| 126 &GenerateKeyEvent, |
| 127 &GenerateCharacterEvent, |
| 128 &GenerateMouseEvent, |
| 129 &GenerateWheelEvent |
77 }; | 130 }; |
78 | 131 |
79 InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { | 132 InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { |
80 return new PPB_Testing_Proxy(dispatcher); | 133 return new PPB_Testing_Proxy(dispatcher); |
81 } | 134 } |
82 | 135 |
83 } // namespace | 136 } // namespace |
84 | 137 |
85 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) | 138 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) |
86 : InterfaceProxy(dispatcher), | 139 : InterfaceProxy(dispatcher), |
(...skipping 19 matching lines...) Expand all Loading... |
106 return &info; | 159 return &info; |
107 } | 160 } |
108 | 161 |
109 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { | 162 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
110 bool handled = true; | 163 bool handled = true; |
111 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) | 164 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, | 165 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
113 OnMsgReadImageData) | 166 OnMsgReadImageData) |
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, | 167 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, |
115 OnMsgGetLiveObjectsForInstance) | 168 OnMsgGetLiveObjectsForInstance) |
| 169 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GenerateKeyEvent, |
| 170 OnMsgGenerateKeyEvent) |
| 171 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GenerateCharacterEvent, |
| 172 OnMsgGenerateCharacterEvent) |
| 173 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GenerateMouseEvent, |
| 174 OnMsgGenerateMouseEvent) |
| 175 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GenerateWheelEvent, |
| 176 OnMsgGenerateWheelEvent) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 177 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 178 IPC_END_MESSAGE_MAP() |
118 return handled; | 179 return handled; |
119 } | 180 } |
120 | 181 |
121 void PPB_Testing_Proxy::OnMsgReadImageData( | 182 void PPB_Testing_Proxy::OnMsgReadImageData( |
122 const HostResource& device_context_2d, | 183 const HostResource& device_context_2d, |
123 const HostResource& image, | 184 const HostResource& image, |
124 const PP_Point& top_left, | 185 const PP_Point& top_left, |
125 PP_Bool* result) { | 186 PP_Bool* result) { |
126 *result = ppb_testing_impl_->ReadImageData( | 187 *result = ppb_testing_impl_->ReadImageData( |
127 device_context_2d.host_resource(), image.host_resource(), &top_left); | 188 device_context_2d.host_resource(), image.host_resource(), &top_left); |
128 } | 189 } |
129 | 190 |
130 void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { | 191 void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { |
131 ppb_testing_impl_->RunMessageLoop(instance); | 192 ppb_testing_impl_->RunMessageLoop(instance); |
132 } | 193 } |
133 | 194 |
134 void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { | 195 void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { |
135 ppb_testing_impl_->QuitMessageLoop(instance); | 196 ppb_testing_impl_->QuitMessageLoop(instance); |
136 } | 197 } |
137 | 198 |
138 void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, | 199 void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, |
139 uint32_t* result) { | 200 uint32_t* result) { |
140 *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance); | 201 *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance); |
141 } | 202 } |
142 | 203 |
| 204 void PPB_Testing_Proxy::OnMsgGenerateKeyEvent( |
| 205 PP_Instance instance, |
| 206 PP_InputEvent_Type type, |
| 207 const PP_InputEvent_Key& key_event) { |
| 208 ppb_testing_impl_->GenerateKeyEvent(instance, type, key_event); |
| 209 } |
| 210 |
| 211 void PPB_Testing_Proxy::OnMsgGenerateCharacterEvent( |
| 212 PP_Instance instance, |
| 213 const PP_InputEvent_Modifier modifier, |
| 214 const std::string& text) { |
| 215 PP_InputEvent_Character character_event; |
| 216 character_event.modifier = modifier; |
| 217 for (size_t i = 0; i < text.size() && i < 5; i++) |
| 218 character_event.text[i] = text[i]; |
| 219 ppb_testing_impl_->GenerateCharacterEvent(instance, character_event); |
| 220 } |
| 221 |
| 222 void PPB_Testing_Proxy::OnMsgGenerateMouseEvent( |
| 223 PP_Instance instance, |
| 224 PP_InputEvent_Type type, |
| 225 const PP_InputEvent_Mouse& mouse_event) { |
| 226 ppb_testing_impl_->GenerateMouseEvent(instance, type, mouse_event); |
| 227 } |
| 228 |
| 229 void PPB_Testing_Proxy::OnMsgGenerateWheelEvent( |
| 230 PP_Instance instance, |
| 231 const PP_InputEvent_Wheel& wheel_event) { |
| 232 ppb_testing_impl_->GenerateWheelEvent(instance, wheel_event); |
| 233 } |
| 234 |
143 } // namespace proxy | 235 } // namespace proxy |
144 } // namespace ppapi | 236 } // namespace ppapi |
OLD | NEW |