| 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/enter_proxy.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/serialized_var.h" |
| 12 #include "ppapi/shared_impl/ppapi_globals.h" | 13 #include "ppapi/shared_impl/ppapi_globals.h" |
| 13 #include "ppapi/shared_impl/resource.h" | 14 #include "ppapi/shared_impl/resource.h" |
| 14 #include "ppapi/shared_impl/resource_tracker.h" | 15 #include "ppapi/shared_impl/resource_tracker.h" |
| 15 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
| 16 #include "ppapi/thunk/ppb_input_event_api.h" | 17 #include "ppapi/thunk/ppb_input_event_api.h" |
| 17 | 18 |
| 18 using ppapi::thunk::EnterResource; | 19 using ppapi::thunk::EnterResource; |
| 19 using ppapi::thunk::PPB_InputEvent_API; | 20 using ppapi::thunk::PPB_InputEvent_API; |
| 20 | 21 |
| 21 namespace ppapi { | 22 namespace ppapi { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return; | 81 return; |
| 81 EnterResource<PPB_InputEvent_API> enter(input_event, false); | 82 EnterResource<PPB_InputEvent_API> enter(input_event, false); |
| 82 if (enter.failed()) | 83 if (enter.failed()) |
| 83 return; | 84 return; |
| 84 | 85 |
| 85 const InputEventData& input_event_data = enter.object()->GetInputEventData(); | 86 const InputEventData& input_event_data = enter.object()->GetInputEventData(); |
| 86 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent( | 87 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent( |
| 87 API_ID_PPB_TESTING, instance_id, input_event_data)); | 88 API_ID_PPB_TESTING, instance_id, input_event_data)); |
| 88 } | 89 } |
| 89 | 90 |
| 91 PP_Var ExecuteScript(PP_Instance instance, |
| 92 PP_Var script, |
| 93 PP_Var* exception) { |
| 94 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 95 if (!dispatcher) |
| 96 return PP_MakeUndefined(); |
| 97 ReceiveSerializedException se(dispatcher, exception); |
| 98 if (se.IsThrown()) |
| 99 return PP_MakeUndefined(); |
| 100 |
| 101 ReceiveSerializedVarReturnValue result; |
| 102 dispatcher->Send(new PpapiHostMsg_PPBTesting_ExecuteScript( |
| 103 API_ID_PPB_TESTING, instance, |
| 104 SerializedVarSendInput(dispatcher, script), &se, &result)); |
| 105 return result.Return(dispatcher); |
| 106 } |
| 107 |
| 90 const PPB_Testing_Dev testing_interface = { | 108 const PPB_Testing_Dev testing_interface = { |
| 91 &ReadImageData, | 109 &ReadImageData, |
| 92 &RunMessageLoop, | 110 &RunMessageLoop, |
| 93 &QuitMessageLoop, | 111 &QuitMessageLoop, |
| 94 &GetLiveObjectsForInstance, | 112 &GetLiveObjectsForInstance, |
| 95 &IsOutOfProcess, | 113 &IsOutOfProcess, |
| 96 &SimulateInputEvent | 114 &SimulateInputEvent, |
| 115 &ExecuteScript |
| 97 }; | 116 }; |
| 98 | 117 |
| 99 InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { | 118 InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { |
| 100 return new PPB_Testing_Proxy(dispatcher); | 119 return new PPB_Testing_Proxy(dispatcher); |
| 101 } | 120 } |
| 102 | 121 |
| 103 } // namespace | 122 } // namespace |
| 104 | 123 |
| 105 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) | 124 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) |
| 106 : InterfaceProxy(dispatcher), | 125 : InterfaceProxy(dispatcher), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 &testing_interface, | 139 &testing_interface, |
| 121 PPB_TESTING_DEV_INTERFACE, | 140 PPB_TESTING_DEV_INTERFACE, |
| 122 API_ID_PPB_TESTING, | 141 API_ID_PPB_TESTING, |
| 123 false, | 142 false, |
| 124 &CreateTestingProxy, | 143 &CreateTestingProxy, |
| 125 }; | 144 }; |
| 126 return &info; | 145 return &info; |
| 127 } | 146 } |
| 128 | 147 |
| 129 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { | 148 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 149 // Prevent the dispatcher from going away during a call to ExecuteScript. |
| 150 // This must happen OUTSIDE of ExecuteScript since the SerializedVars use |
| 151 // the dispatcher upon return of the function (converting the |
| 152 // SerializedVarReturnValue/OutParam to a SerializedVar in the destructor). |
| 153 ScopedModuleReference death_grip(dispatcher()); |
| 154 |
| 130 bool handled = true; | 155 bool handled = true; |
| 131 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) | 156 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
| 132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, | 157 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
| 133 OnMsgReadImageData) | 158 OnMsgReadImageData) |
| 134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, | 159 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, |
| 135 OnMsgGetLiveObjectsForInstance) | 160 OnMsgGetLiveObjectsForInstance) |
| 136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_SimulateInputEvent, | 161 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_SimulateInputEvent, |
| 137 OnMsgSimulateInputEvent) | 162 OnMsgSimulateInputEvent) |
| 163 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ExecuteScript, |
| 164 OnMsgExecuteScript) |
| 138 IPC_MESSAGE_UNHANDLED(handled = false) | 165 IPC_MESSAGE_UNHANDLED(handled = false) |
| 139 IPC_END_MESSAGE_MAP() | 166 IPC_END_MESSAGE_MAP() |
| 140 return handled; | 167 return handled; |
| 141 } | 168 } |
| 142 | 169 |
| 143 void PPB_Testing_Proxy::OnMsgReadImageData( | 170 void PPB_Testing_Proxy::OnMsgReadImageData( |
| 144 const HostResource& device_context_2d, | 171 const HostResource& device_context_2d, |
| 145 const HostResource& image, | 172 const HostResource& image, |
| 146 const PP_Point& top_left, | 173 const PP_Point& top_left, |
| 147 PP_Bool* result) { | 174 PP_Bool* result) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 166 PP_Instance instance, | 193 PP_Instance instance, |
| 167 const InputEventData& input_event) { | 194 const InputEventData& input_event) { |
| 168 scoped_refptr<PPB_InputEvent_Shared> input_event_impl( | 195 scoped_refptr<PPB_InputEvent_Shared> input_event_impl( |
| 169 new PPB_InputEvent_Shared(PPB_InputEvent_Shared::InitAsProxy(), | 196 new PPB_InputEvent_Shared(PPB_InputEvent_Shared::InitAsProxy(), |
| 170 instance, | 197 instance, |
| 171 input_event)); | 198 input_event)); |
| 172 ppb_testing_impl_->SimulateInputEvent(instance, | 199 ppb_testing_impl_->SimulateInputEvent(instance, |
| 173 input_event_impl->pp_resource()); | 200 input_event_impl->pp_resource()); |
| 174 } | 201 } |
| 175 | 202 |
| 203 void PPB_Testing_Proxy::OnMsgExecuteScript( |
| 204 PP_Instance instance, |
| 205 SerializedVarReceiveInput script, |
| 206 SerializedVarOutParam out_exception, |
| 207 SerializedVarReturnValue result) { |
| 208 if (dispatcher()->IsPlugin()) |
| 209 NOTREACHED(); |
| 210 else |
| 211 static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy(); |
| 212 |
| 213 result.Return(dispatcher(), ppb_testing_impl_->ExecuteScript( |
| 214 instance, |
| 215 script.Get(dispatcher()), |
| 216 out_exception.OutParam(dispatcher()))); |
| 217 } |
| 218 |
| 176 } // namespace proxy | 219 } // namespace proxy |
| 177 } // namespace ppapi | 220 } // namespace ppapi |
| OLD | NEW |