OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/ppapi_plugin/ppapi_thread.h" | 5 #include "content/ppapi_plugin/ppapi_thread.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "content/common/child_process.h" | 14 #include "content/common/child_process.h" |
15 #include "content/common/child_process_messages.h" | 15 #include "content/common/child_process_messages.h" |
16 #include "content/ppapi_plugin/broker_process_dispatcher.h" | 16 #include "content/ppapi_plugin/broker_process_dispatcher.h" |
17 #include "content/ppapi_plugin/plugin_process_dispatcher.h" | 17 #include "content/ppapi_plugin/plugin_process_dispatcher.h" |
18 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" | 18 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" |
19 #include "content/public/common/sandbox_init.h" | 19 #include "content/public/common/sandbox_init.h" |
20 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_platform_file.h" | |
21 #include "ipc/ipc_sync_channel.h" | 22 #include "ipc/ipc_sync_channel.h" |
22 #include "ppapi/c/dev/ppp_network_state_dev.h" | 23 #include "ppapi/c/dev/ppp_network_state_dev.h" |
23 #include "ppapi/c/pp_errors.h" | 24 #include "ppapi/c/pp_errors.h" |
24 #include "ppapi/c/ppp.h" | 25 #include "ppapi/c/ppp.h" |
25 #include "ppapi/proxy/plugin_globals.h" | 26 #include "ppapi/proxy/plugin_globals.h" |
26 #include "ppapi/proxy/ppapi_messages.h" | 27 #include "ppapi/proxy/ppapi_messages.h" |
27 #include "ppapi/proxy/interface_list.h" | 28 #include "ppapi/proxy/interface_list.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
29 #include "webkit/plugins/plugin_switches.h" | 30 #include "webkit/plugins/plugin_switches.h" |
30 | 31 |
(...skipping 11 matching lines...) Expand all Loading... | |
42 | 43 |
43 typedef int32_t (*InitializeBrokerFunc) | 44 typedef int32_t (*InitializeBrokerFunc) |
44 (PP_ConnectInstance_Func* connect_instance_func); | 45 (PP_ConnectInstance_Func* connect_instance_func); |
45 | 46 |
46 PpapiThread::PpapiThread(const CommandLine& command_line, bool is_broker) | 47 PpapiThread::PpapiThread(const CommandLine& command_line, bool is_broker) |
47 : is_broker_(is_broker), | 48 : is_broker_(is_broker), |
48 get_plugin_interface_(NULL), | 49 get_plugin_interface_(NULL), |
49 connect_instance_func_(NULL), | 50 connect_instance_func_(NULL), |
50 local_pp_module_( | 51 local_pp_module_( |
51 base::RandInt(0, std::numeric_limits<PP_Module>::max())), | 52 base::RandInt(0, std::numeric_limits<PP_Module>::max())), |
52 next_plugin_dispatcher_id_(1) { | 53 next_plugin_dispatcher_id_(1), |
54 peer_handle_(base::kNullProcessHandle) { | |
53 ppapi::proxy::PluginGlobals* globals = ppapi::proxy::PluginGlobals::Get(); | 55 ppapi::proxy::PluginGlobals* globals = ppapi::proxy::PluginGlobals::Get(); |
54 globals->set_plugin_proxy_delegate(this); | 56 globals->set_plugin_proxy_delegate(this); |
55 globals->set_command_line( | 57 globals->set_command_line( |
56 command_line.GetSwitchValueASCII(switches::kPpapiFlashArgs)); | 58 command_line.GetSwitchValueASCII(switches::kPpapiFlashArgs)); |
57 | 59 |
58 webkit_platform_support_.reset(new PpapiWebKitPlatformSupportImpl); | 60 webkit_platform_support_.reset(new PpapiWebKitPlatformSupportImpl); |
59 WebKit::initialize(webkit_platform_support_.get()); | 61 WebKit::initialize(webkit_platform_support_.get()); |
60 } | 62 } |
61 | 63 |
62 PpapiThread::~PpapiThread() { | 64 PpapiThread::~PpapiThread() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTalk_GetPermissionACK, | 112 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTalk_GetPermissionACK, |
111 OnPluginDispatcherMessageReceived(msg)) | 113 OnPluginDispatcherMessageReceived(msg)) |
112 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBHostResolver_ResolveACK, | 114 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBHostResolver_ResolveACK, |
113 OnPluginDispatcherMessageReceived(msg)) | 115 OnPluginDispatcherMessageReceived(msg)) |
114 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBNetworkMonitor_NetworkList, | 116 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBNetworkMonitor_NetworkList, |
115 OnPluginDispatcherMessageReceived(msg)) | 117 OnPluginDispatcherMessageReceived(msg)) |
116 IPC_MESSAGE_HANDLER(PpapiMsg_SetNetworkState, OnMsgSetNetworkState) | 118 IPC_MESSAGE_HANDLER(PpapiMsg_SetNetworkState, OnMsgSetNetworkState) |
117 IPC_END_MESSAGE_MAP() | 119 IPC_END_MESSAGE_MAP() |
118 return true; | 120 return true; |
119 } | 121 } |
122 void PpapiThread::OnChannelConnected(int32 peer_pid) { | |
jschuh
2012/05/10 00:10:57
We cache a handle to the other end here, because i
| |
123 #if defined(OS_WIN) | |
124 if (is_broker_) | |
125 peer_handle_ = ::OpenProcess(PROCESS_DUP_HANDLE, FALSE, peer_pid); | |
cpu_(ooo_6.6-7.5)
2012/05/10 22:10:43
do we ever close the peer handle? base::ProcessHan
jschuh
2012/05/10 22:16:28
D'oh. I thought I'd made that a scoped handle. Fix
| |
126 #endif | |
127 } | |
120 | 128 |
121 base::MessageLoopProxy* PpapiThread::GetIPCMessageLoop() { | 129 base::MessageLoopProxy* PpapiThread::GetIPCMessageLoop() { |
122 return ChildProcess::current()->io_message_loop_proxy(); | 130 return ChildProcess::current()->io_message_loop_proxy(); |
123 } | 131 } |
124 | 132 |
125 base::WaitableEvent* PpapiThread::GetShutdownEvent() { | 133 base::WaitableEvent* PpapiThread::GetShutdownEvent() { |
126 return ChildProcess::current()->GetShutDownEvent(); | 134 return ChildProcess::current()->GetShutDownEvent(); |
127 } | 135 } |
128 | 136 |
137 IPC::PlatformFileForTransit PpapiThread::ShareHandleWithRemote( | |
jschuh
2012/05/10 00:10:57
Here's the handle duping logic.
| |
138 base::PlatformFile handle, | |
139 const IPC::SyncChannel& channel, | |
140 bool should_close_source) { | |
141 IPC::PlatformFileForTransit out_handle; | |
142 if (peer_handle_) { | |
143 DCHECK(is_broker_); | |
144 return IPC::GetFileHandleForProcess(handle, peer_handle_, | |
145 should_close_source); | |
146 } else { | |
147 DCHECK(!is_broker_); | |
148 return content::BrokerGetFileHandleForProcess(handle, channel.peer_pid(), | |
149 should_close_source); | |
150 } | |
151 return out_handle; | |
152 } | |
153 | |
129 std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { | 154 std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { |
130 return &globally_seen_instance_ids_; | 155 return &globally_seen_instance_ids_; |
131 } | 156 } |
132 | 157 |
133 bool PpapiThread::SendToBrowser(IPC::Message* msg) { | 158 bool PpapiThread::SendToBrowser(IPC::Message* msg) { |
134 return Send(msg); | 159 return Send(msg); |
135 } | 160 } |
136 | 161 |
137 void PpapiThread::PreCacheFont(const void* logfontw) { | 162 void PpapiThread::PreCacheFont(const void* logfontw) { |
138 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); | 265 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); |
241 if (init_error != PP_OK) { | 266 if (init_error != PP_OK) { |
242 LOG(WARNING) << "InitModule failed with error " << init_error; | 267 LOG(WARNING) << "InitModule failed with error " << init_error; |
243 return; | 268 return; |
244 } | 269 } |
245 } | 270 } |
246 | 271 |
247 library_.Reset(library.Release()); | 272 library_.Reset(library.Release()); |
248 } | 273 } |
249 | 274 |
250 void PpapiThread::OnMsgCreateChannel(base::ProcessHandle host_process_handle, | 275 void PpapiThread::OnMsgCreateChannel(int renderer_id, |
251 int renderer_id, | |
252 bool incognito) { | 276 bool incognito) { |
253 IPC::ChannelHandle channel_handle; | 277 IPC::ChannelHandle channel_handle; |
254 if (!library_.is_valid() || // Plugin couldn't be loaded. | 278 if (!library_.is_valid() || // Plugin couldn't be loaded. |
255 !SetupRendererChannel(host_process_handle, renderer_id, incognito, | 279 !SetupRendererChannel(renderer_id, incognito, &channel_handle)) { |
256 &channel_handle)) { | |
257 Send(new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle())); | 280 Send(new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle())); |
258 return; | 281 return; |
259 } | 282 } |
260 | 283 |
261 Send(new PpapiHostMsg_ChannelCreated(channel_handle)); | 284 Send(new PpapiHostMsg_ChannelCreated(channel_handle)); |
262 } | 285 } |
263 | 286 |
264 void PpapiThread::OnMsgSetNetworkState(bool online) { | 287 void PpapiThread::OnMsgSetNetworkState(bool online) { |
265 if (!get_plugin_interface_) | 288 if (!get_plugin_interface_) |
266 return; | 289 return; |
(...skipping 10 matching lines...) Expand all Loading... | |
277 if (!msg.ReadUInt32(&iter, &id)) { | 300 if (!msg.ReadUInt32(&iter, &id)) { |
278 NOTREACHED(); | 301 NOTREACHED(); |
279 return; | 302 return; |
280 } | 303 } |
281 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 304 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
282 plugin_dispatchers_.find(id); | 305 plugin_dispatchers_.find(id); |
283 if (dispatcher != plugin_dispatchers_.end()) | 306 if (dispatcher != plugin_dispatchers_.end()) |
284 dispatcher->second->OnMessageReceived(msg); | 307 dispatcher->second->OnMessageReceived(msg); |
285 } | 308 } |
286 | 309 |
287 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, | 310 bool PpapiThread::SetupRendererChannel(int renderer_id, |
288 int renderer_id, | |
289 bool incognito, | 311 bool incognito, |
290 IPC::ChannelHandle* handle) { | 312 IPC::ChannelHandle* handle) { |
291 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); | 313 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); |
292 IPC::ChannelHandle plugin_handle; | 314 IPC::ChannelHandle plugin_handle; |
293 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( | 315 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( |
294 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); | 316 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); |
295 | 317 |
296 ppapi::proxy::ProxyChannel* dispatcher = NULL; | 318 ppapi::proxy::ProxyChannel* dispatcher = NULL; |
297 bool init_result = false; | 319 bool init_result = false; |
298 if (is_broker_) { | 320 if (is_broker_) { |
299 BrokerProcessDispatcher* broker_dispatcher = | 321 BrokerProcessDispatcher* broker_dispatcher = |
300 new BrokerProcessDispatcher(host_process_handle, | 322 new BrokerProcessDispatcher(get_plugin_interface_, |
301 get_plugin_interface_, | |
302 connect_instance_func_); | 323 connect_instance_func_); |
303 init_result = broker_dispatcher->InitBrokerWithChannel(this, | 324 init_result = broker_dispatcher->InitBrokerWithChannel(this, |
304 plugin_handle, | 325 plugin_handle, |
305 false); | 326 false); |
306 dispatcher = broker_dispatcher; | 327 dispatcher = broker_dispatcher; |
307 } else { | 328 } else { |
308 PluginProcessDispatcher* plugin_dispatcher = | 329 PluginProcessDispatcher* plugin_dispatcher = |
309 new PluginProcessDispatcher(host_process_handle, get_plugin_interface_, | 330 new PluginProcessDispatcher(get_plugin_interface_, incognito); |
310 incognito); | |
311 init_result = plugin_dispatcher->InitPluginWithChannel(this, | 331 init_result = plugin_dispatcher->InitPluginWithChannel(this, |
312 plugin_handle, | 332 plugin_handle, |
313 false); | 333 false); |
314 dispatcher = plugin_dispatcher; | 334 dispatcher = plugin_dispatcher; |
315 } | 335 } |
316 | 336 |
317 if (!init_result) { | 337 if (!init_result) { |
318 delete dispatcher; | 338 delete dispatcher; |
319 return false; | 339 return false; |
320 } | 340 } |
(...skipping 10 matching lines...) Expand all Loading... | |
331 | 351 |
332 // From here, the dispatcher will manage its own lifetime according to the | 352 // From here, the dispatcher will manage its own lifetime according to the |
333 // lifetime of the attached channel. | 353 // lifetime of the attached channel. |
334 return true; | 354 return true; |
335 } | 355 } |
336 | 356 |
337 void PpapiThread::SavePluginName(const FilePath& path) { | 357 void PpapiThread::SavePluginName(const FilePath& path) { |
338 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( | 358 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( |
339 path.BaseName().AsUTF8Unsafe()); | 359 path.BaseName().AsUTF8Unsafe()); |
340 } | 360 } |
OLD | NEW |