OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ppapi_plugin_process_host.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" |
| 9 #include "base/process_util.h" |
| 10 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/render_messages.h" |
| 13 #include "ipc/ipc_channel_handle.h" |
| 14 #include "ipc/ipc_switches.h" |
| 15 #include "third_party/ppapi/proxy/ppapi_messages.h" |
| 16 |
| 17 PpapiPluginProcessHost::PpapiPluginProcessHost(ResourceMessageFilter* filter) |
| 18 : BrowserChildProcessHost(ChildProcessInfo::PPAPI_PLUGIN_PROCESS, |
| 19 filter->resource_dispatcher_host()), |
| 20 filter_(filter) { |
| 21 } |
| 22 |
| 23 PpapiPluginProcessHost::~PpapiPluginProcessHost() { |
| 24 } |
| 25 |
| 26 void PpapiPluginProcessHost::Init(const FilePath& path, |
| 27 IPC::Message* reply_msg) { |
| 28 plugin_path_ = path; |
| 29 reply_msg_.reset(reply_msg); |
| 30 |
| 31 if (!CreateChannel()) { |
| 32 ReplyToRenderer(IPC::ChannelHandle()); |
| 33 return; |
| 34 } |
| 35 |
| 36 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 37 CommandLine::StringType plugin_launcher = |
| 38 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
| 39 |
| 40 FilePath exe_path = ChildProcessHost::GetChildPath(plugin_launcher.empty()); |
| 41 if (exe_path.empty()) { |
| 42 ReplyToRenderer(IPC::ChannelHandle()); |
| 43 return; |
| 44 } |
| 45 |
| 46 CommandLine* cmd_line = new CommandLine(exe_path); |
| 47 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 48 switches::kPpapiPluginProcess); |
| 49 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); |
| 50 |
| 51 if (!plugin_launcher.empty()) |
| 52 cmd_line->PrependWrapper(plugin_launcher); |
| 53 |
| 54 Launch( |
| 55 #if defined(OS_WIN) |
| 56 FilePath(), |
| 57 #elif defined(OS_POSIX) |
| 58 true, base::environment_vector(), |
| 59 #endif |
| 60 cmd_line); |
| 61 } |
| 62 |
| 63 void PpapiPluginProcessHost::OnProcessLaunched() { |
| 64 } |
| 65 |
| 66 URLRequestContext* PpapiPluginProcessHost::GetRequestContext( |
| 67 uint32 request_id, |
| 68 const ViewHostMsg_Resource_Request& request_data) { |
| 69 return NULL; |
| 70 } |
| 71 |
| 72 void PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| 73 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg) |
| 74 IPC_MESSAGE_HANDLER(PpapiHostMsg_PluginLoaded, OnPluginLoaded) |
| 75 IPC_MESSAGE_UNHANDLED_ERROR(); |
| 76 IPC_END_MESSAGE_MAP() |
| 77 } |
| 78 |
| 79 void PpapiPluginProcessHost::OnChannelConnected(int32 peer_pid) { |
| 80 PpapiMsg_LoadPlugin* msg = new PpapiMsg_LoadPlugin(plugin_path_, |
| 81 filter_->id()); |
| 82 if (!Send(msg)) // Just send an empty handle on failure. |
| 83 ReplyToRenderer(IPC::ChannelHandle()); |
| 84 // This function will result in OnChannelCreated getting called to finish. |
| 85 } |
| 86 |
| 87 void PpapiPluginProcessHost::OnChannelError() { |
| 88 if (reply_msg_.get()) |
| 89 ReplyToRenderer(IPC::ChannelHandle()); |
| 90 } |
| 91 |
| 92 void PpapiPluginProcessHost::OnPluginLoaded(const IPC::ChannelHandle& handle) { |
| 93 ReplyToRenderer(handle); |
| 94 } |
| 95 |
| 96 void PpapiPluginProcessHost::ReplyToRenderer(const IPC::ChannelHandle& handle) { |
| 97 DCHECK(reply_msg_.get()); |
| 98 ViewHostMsg_OpenChannelToPepperPlugin::WriteReplyParams(reply_msg_.get(), |
| 99 handle); |
| 100 filter_->Send(reply_msg_.release()); |
| 101 } |
OLD | NEW |