OLD | NEW |
1 // Copyright (c) 2012 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/plugin_dispatcher.h" | 5 #include "ppapi/proxy/plugin_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
13 #include "ipc/ipc_sync_channel.h" | 13 #include "ipc/ipc_sync_channel.h" |
14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/ppp_instance.h" | 16 #include "ppapi/c/ppp_instance.h" |
17 #include "ppapi/proxy/interface_list.h" | 17 #include "ppapi/proxy/interface_list.h" |
18 #include "ppapi/proxy/interface_proxy.h" | 18 #include "ppapi/proxy/interface_proxy.h" |
19 #include "ppapi/proxy/plugin_message_filter.h" | 19 #include "ppapi/proxy/plugin_message_filter.h" |
20 #include "ppapi/proxy/plugin_resource_tracker.h" | 20 #include "ppapi/proxy/plugin_resource_tracker.h" |
21 #include "ppapi/proxy/plugin_var_serialization_rules.h" | 21 #include "ppapi/proxy/plugin_var_serialization_rules.h" |
22 #include "ppapi/proxy/ppapi_messages.h" | 22 #include "ppapi/proxy/ppapi_messages.h" |
23 #include "ppapi/proxy/ppb_cursor_control_proxy.h" | 23 #include "ppapi/proxy/ppb_cursor_control_proxy.h" |
24 #include "ppapi/proxy/ppb_font_proxy.h" | 24 #include "ppapi/proxy/ppb_font_proxy.h" |
25 #include "ppapi/proxy/ppb_instance_proxy.h" | 25 #include "ppapi/proxy/ppb_instance_proxy.h" |
26 #include "ppapi/proxy/ppp_class_proxy.h" | 26 #include "ppapi/proxy/ppp_class_proxy.h" |
27 #include "ppapi/proxy/resource_creation_proxy.h" | 27 #include "ppapi/proxy/resource_creation_proxy.h" |
28 #include "ppapi/shared_impl/proxy_lock.h" | |
29 #include "ppapi/shared_impl/resource.h" | 28 #include "ppapi/shared_impl/resource.h" |
30 | 29 |
31 #if defined(OS_POSIX) | 30 #if defined(OS_POSIX) |
32 #include "base/eintr_wrapper.h" | 31 #include "base/eintr_wrapper.h" |
33 #include "ipc/ipc_channel_posix.h" | 32 #include "ipc/ipc_channel_posix.h" |
34 #endif | 33 #endif |
35 | 34 |
36 namespace ppapi { | 35 namespace ppapi { |
37 namespace proxy { | 36 namespace proxy { |
38 | 37 |
39 namespace { | 38 namespace { |
40 | 39 |
41 typedef std::map<PP_Instance, PluginDispatcher*> InstanceToDispatcherMap; | 40 typedef std::map<PP_Instance, PluginDispatcher*> InstanceToDispatcherMap; |
42 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; | 41 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; |
43 | 42 |
44 typedef std::set<PluginDispatcher*> DispatcherSet; | 43 typedef std::set<PluginDispatcher*> DispatcherSet; |
45 DispatcherSet* g_live_dispatchers = NULL; | 44 DispatcherSet* g_live_dispatchers = NULL; |
46 | 45 |
47 } // namespace | 46 } // namespace |
48 | 47 |
49 InstanceData::InstanceData() | 48 InstanceData::InstanceData() |
50 : flash_fullscreen(PP_FALSE), | 49 : flash_fullscreen(PP_FALSE), |
51 mouse_lock_callback(PP_BlockUntilComplete()) { | 50 mouse_lock_callback(PP_BlockUntilComplete()) { |
52 } | 51 } |
53 | 52 |
54 InstanceData::~InstanceData() { | 53 InstanceData::~InstanceData() { |
55 // Run any pending mouse lock callback to prevent leaks. | 54 // Run any pending mouse lock callback to prevent leaks. |
56 if (mouse_lock_callback.func) { | 55 if (mouse_lock_callback.func) |
57 CallWhileUnlocked(PP_RunAndClearCompletionCallback, | 56 PP_RunAndClearCompletionCallback(&mouse_lock_callback, PP_ERROR_ABORTED); |
58 &mouse_lock_callback, | |
59 static_cast<int32_t>(PP_ERROR_ABORTED)); | |
60 } | |
61 } | 57 } |
62 | 58 |
63 PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, | 59 PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, |
64 GetInterfaceFunc get_interface) | 60 GetInterfaceFunc get_interface) |
65 : Dispatcher(remote_process_handle, get_interface), | 61 : Dispatcher(remote_process_handle, get_interface), |
66 plugin_delegate_(NULL), | 62 plugin_delegate_(NULL), |
67 received_preferences_(false), | 63 received_preferences_(false), |
68 plugin_dispatcher_id_(0) { | 64 plugin_dispatcher_id_(0) { |
69 SetSerializationRules(new PluginVarSerializationRules); | 65 SetSerializationRules(new PluginVarSerializationRules); |
70 | 66 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 157 |
162 bool PluginDispatcher::IsPlugin() const { | 158 bool PluginDispatcher::IsPlugin() const { |
163 return true; | 159 return true; |
164 } | 160 } |
165 | 161 |
166 bool PluginDispatcher::Send(IPC::Message* msg) { | 162 bool PluginDispatcher::Send(IPC::Message* msg) { |
167 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::Send", | 163 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::Send", |
168 "Class", IPC_MESSAGE_ID_CLASS(msg->type()), | 164 "Class", IPC_MESSAGE_ID_CLASS(msg->type()), |
169 "Line", IPC_MESSAGE_ID_LINE(msg->type())); | 165 "Line", IPC_MESSAGE_ID_LINE(msg->type())); |
170 // We always want plugin->renderer messages to arrive in-order. If some sync | 166 // We always want plugin->renderer messages to arrive in-order. If some sync |
171 // and some async messages are sent in response to a synchronous | 167 // and some async messages are send in response to a synchronous |
172 // renderer->plugin call, the sync reply will be processed before the async | 168 // renderer->plugin call, the sync reply will be processed before the async |
173 // reply, and everything will be confused. | 169 // reply, and everything will be confused. |
174 // | 170 // |
175 // Allowing all async messages to unblock the renderer means more reentrancy | 171 // Allowing all async messages to unblock the renderer means more reentrancy |
176 // there but gives correct ordering. | 172 // there but gives correct ordering. |
177 msg->set_unblock(true); | 173 msg->set_unblock(true); |
178 if (msg->is_sync()) { | |
179 // Synchronous messages might be re-entrant, so we need to drop the lock. | |
180 ProxyAutoUnlock unlock; | |
181 return Dispatcher::Send(msg); | |
182 } | |
183 return Dispatcher::Send(msg); | 174 return Dispatcher::Send(msg); |
184 } | 175 } |
185 | 176 |
186 bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { | 177 bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { |
187 // We need to grab the proxy lock to ensure that we don't collide with the | |
188 // plugin making pepper calls on a different thread. | |
189 ProxyAutoLock lock; | |
190 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", | 178 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", |
191 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), | 179 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), |
192 "Line", IPC_MESSAGE_ID_LINE(msg.type())); | 180 "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
193 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 181 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
194 // Handle some plugin-specific control messages. | 182 // Handle some plugin-specific control messages. |
195 bool handled = true; | 183 bool handled = true; |
196 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) | 184 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) |
197 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) | 185 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) |
198 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) | 186 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) |
199 IPC_MESSAGE_UNHANDLED(handled = false); | 187 IPC_MESSAGE_UNHANDLED(handled = false); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // once they're set. The user will have to restart to get new font prefs | 277 // once they're set. The user will have to restart to get new font prefs |
290 // propogated to plugins. | 278 // propogated to plugins. |
291 if (!received_preferences_) { | 279 if (!received_preferences_) { |
292 received_preferences_ = true; | 280 received_preferences_ = true; |
293 preferences_ = prefs; | 281 preferences_ = prefs; |
294 } | 282 } |
295 } | 283 } |
296 | 284 |
297 } // namespace proxy | 285 } // namespace proxy |
298 } // namespace ppapi | 286 } // namespace ppapi |
OLD | NEW |