Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: content/ppapi_plugin/ppapi_thread.cc

Issue 10378057: Broker out PPAPI handle duplication (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/ppapi_plugin/ppapi_thread.h ('k') | content/public/common/sandbox_init.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTalk_GetPermissionACK, 111 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTalk_GetPermissionACK,
111 OnPluginDispatcherMessageReceived(msg)) 112 OnPluginDispatcherMessageReceived(msg))
112 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBHostResolver_ResolveACK, 113 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBHostResolver_ResolveACK,
113 OnPluginDispatcherMessageReceived(msg)) 114 OnPluginDispatcherMessageReceived(msg))
114 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBNetworkMonitor_NetworkList, 115 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBNetworkMonitor_NetworkList,
115 OnPluginDispatcherMessageReceived(msg)) 116 OnPluginDispatcherMessageReceived(msg))
116 IPC_MESSAGE_HANDLER(PpapiMsg_SetNetworkState, OnMsgSetNetworkState) 117 IPC_MESSAGE_HANDLER(PpapiMsg_SetNetworkState, OnMsgSetNetworkState)
117 IPC_END_MESSAGE_MAP() 118 IPC_END_MESSAGE_MAP()
118 return true; 119 return true;
119 } 120 }
121 void PpapiThread::OnChannelConnected(int32 peer_pid) {
122 #if defined(OS_WIN)
123 if (is_broker_)
124 peer_handle_.Set(::OpenProcess(PROCESS_DUP_HANDLE, FALSE, peer_pid));
125 #endif
126 }
120 127
121 base::MessageLoopProxy* PpapiThread::GetIPCMessageLoop() { 128 base::MessageLoopProxy* PpapiThread::GetIPCMessageLoop() {
122 return ChildProcess::current()->io_message_loop_proxy(); 129 return ChildProcess::current()->io_message_loop_proxy();
123 } 130 }
124 131
125 base::WaitableEvent* PpapiThread::GetShutdownEvent() { 132 base::WaitableEvent* PpapiThread::GetShutdownEvent() {
126 return ChildProcess::current()->GetShutDownEvent(); 133 return ChildProcess::current()->GetShutDownEvent();
127 } 134 }
128 135
136 IPC::PlatformFileForTransit PpapiThread::ShareHandleWithRemote(
137 base::PlatformFile handle,
138 const IPC::SyncChannel& channel,
139 bool should_close_source) {
140 #if defined(OS_WIN)
141 if (peer_handle_.IsValid()) {
142 DCHECK(is_broker_);
143 return IPC::GetFileHandleForProcess(handle, peer_handle_,
144 should_close_source);
145 }
146 #endif
147
148 return content::BrokerGetFileHandleForProcess(handle, channel.peer_pid(),
149 should_close_source);
150 }
151
129 std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { 152 std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() {
130 return &globally_seen_instance_ids_; 153 return &globally_seen_instance_ids_;
131 } 154 }
132 155
133 bool PpapiThread::SendToBrowser(IPC::Message* msg) { 156 bool PpapiThread::SendToBrowser(IPC::Message* msg) {
134 return Send(msg); 157 return Send(msg);
135 } 158 }
136 159
137 void PpapiThread::PreCacheFont(const void* logfontw) { 160 void PpapiThread::PreCacheFont(const void* logfontw) {
138 #if defined(OS_WIN) 161 #if defined(OS_WIN)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); 263 &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
241 if (init_error != PP_OK) { 264 if (init_error != PP_OK) {
242 LOG(WARNING) << "InitModule failed with error " << init_error; 265 LOG(WARNING) << "InitModule failed with error " << init_error;
243 return; 266 return;
244 } 267 }
245 } 268 }
246 269
247 library_.Reset(library.Release()); 270 library_.Reset(library.Release());
248 } 271 }
249 272
250 void PpapiThread::OnMsgCreateChannel(base::ProcessHandle host_process_handle, 273 void PpapiThread::OnMsgCreateChannel(int renderer_id,
251 int renderer_id,
252 bool incognito) { 274 bool incognito) {
253 IPC::ChannelHandle channel_handle; 275 IPC::ChannelHandle channel_handle;
254 if (!library_.is_valid() || // Plugin couldn't be loaded. 276 if (!library_.is_valid() || // Plugin couldn't be loaded.
255 !SetupRendererChannel(host_process_handle, renderer_id, incognito, 277 !SetupRendererChannel(renderer_id, incognito, &channel_handle)) {
256 &channel_handle)) {
257 Send(new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle())); 278 Send(new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle()));
258 return; 279 return;
259 } 280 }
260 281
261 Send(new PpapiHostMsg_ChannelCreated(channel_handle)); 282 Send(new PpapiHostMsg_ChannelCreated(channel_handle));
262 } 283 }
263 284
264 void PpapiThread::OnMsgSetNetworkState(bool online) { 285 void PpapiThread::OnMsgSetNetworkState(bool online) {
265 if (!get_plugin_interface_) 286 if (!get_plugin_interface_)
266 return; 287 return;
(...skipping 10 matching lines...) Expand all
277 if (!msg.ReadUInt32(&iter, &id)) { 298 if (!msg.ReadUInt32(&iter, &id)) {
278 NOTREACHED(); 299 NOTREACHED();
279 return; 300 return;
280 } 301 }
281 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = 302 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher =
282 plugin_dispatchers_.find(id); 303 plugin_dispatchers_.find(id);
283 if (dispatcher != plugin_dispatchers_.end()) 304 if (dispatcher != plugin_dispatchers_.end())
284 dispatcher->second->OnMessageReceived(msg); 305 dispatcher->second->OnMessageReceived(msg);
285 } 306 }
286 307
287 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, 308 bool PpapiThread::SetupRendererChannel(int renderer_id,
288 int renderer_id,
289 bool incognito, 309 bool incognito,
290 IPC::ChannelHandle* handle) { 310 IPC::ChannelHandle* handle) {
291 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); 311 DCHECK(is_broker_ == (connect_instance_func_ != NULL));
292 IPC::ChannelHandle plugin_handle; 312 IPC::ChannelHandle plugin_handle;
293 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( 313 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID(
294 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); 314 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id));
295 315
296 ppapi::proxy::ProxyChannel* dispatcher = NULL; 316 ppapi::proxy::ProxyChannel* dispatcher = NULL;
297 bool init_result = false; 317 bool init_result = false;
298 if (is_broker_) { 318 if (is_broker_) {
299 BrokerProcessDispatcher* broker_dispatcher = 319 BrokerProcessDispatcher* broker_dispatcher =
300 new BrokerProcessDispatcher(host_process_handle, 320 new BrokerProcessDispatcher(get_plugin_interface_,
301 get_plugin_interface_,
302 connect_instance_func_); 321 connect_instance_func_);
303 init_result = broker_dispatcher->InitBrokerWithChannel(this, 322 init_result = broker_dispatcher->InitBrokerWithChannel(this,
304 plugin_handle, 323 plugin_handle,
305 false); 324 false);
306 dispatcher = broker_dispatcher; 325 dispatcher = broker_dispatcher;
307 } else { 326 } else {
308 PluginProcessDispatcher* plugin_dispatcher = 327 PluginProcessDispatcher* plugin_dispatcher =
309 new PluginProcessDispatcher(host_process_handle, get_plugin_interface_, 328 new PluginProcessDispatcher(get_plugin_interface_, incognito);
310 incognito);
311 init_result = plugin_dispatcher->InitPluginWithChannel(this, 329 init_result = plugin_dispatcher->InitPluginWithChannel(this,
312 plugin_handle, 330 plugin_handle,
313 false); 331 false);
314 dispatcher = plugin_dispatcher; 332 dispatcher = plugin_dispatcher;
315 } 333 }
316 334
317 if (!init_result) { 335 if (!init_result) {
318 delete dispatcher; 336 delete dispatcher;
319 return false; 337 return false;
320 } 338 }
(...skipping 10 matching lines...) Expand all
331 349
332 // From here, the dispatcher will manage its own lifetime according to the 350 // From here, the dispatcher will manage its own lifetime according to the
333 // lifetime of the attached channel. 351 // lifetime of the attached channel.
334 return true; 352 return true;
335 } 353 }
336 354
337 void PpapiThread::SavePluginName(const FilePath& path) { 355 void PpapiThread::SavePluginName(const FilePath& path) {
338 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( 356 ppapi::proxy::PluginGlobals::Get()->set_plugin_name(
339 path.BaseName().AsUTF8Unsafe()); 357 path.BaseName().AsUTF8Unsafe());
340 } 358 }
OLDNEW
« no previous file with comments | « content/ppapi_plugin/ppapi_thread.h ('k') | content/public/common/sandbox_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698