| 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 "content/browser/ppapi_plugin_process_host.h" | 5 #include "content/browser/ppapi_plugin_process_host.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/browser/plugin_service.h" | 12 #include "content/browser/plugin_service.h" |
| 13 #include "content/browser/renderer_host/render_message_filter.h" | 13 #include "content/browser/renderer_host/render_message_filter.h" |
| 14 #include "content/common/child_process_host.h" | 14 #include "content/common/child_process_host_impl.h" |
| 15 #include "content/common/child_process_messages.h" | 15 #include "content/common/child_process_messages.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/common/pepper_plugin_info.h" | 17 #include "content/public/common/pepper_plugin_info.h" |
| 18 #include "content/public/common/process_type.h" | 18 #include "content/public/common/process_type.h" |
| 19 #include "ipc/ipc_switches.h" | 19 #include "ipc/ipc_switches.h" |
| 20 #include "net/base/network_change_notifier.h" | 20 #include "net/base/network_change_notifier.h" |
| 21 #include "ppapi/proxy/ppapi_messages.h" | 21 #include "ppapi/proxy/ppapi_messages.h" |
| 22 | 22 |
| 23 using content::ChildProcessHost; |
| 24 using content::ChildProcessHostImpl; |
| 25 |
| 23 class PpapiPluginProcessHost::PluginNetworkObserver | 26 class PpapiPluginProcessHost::PluginNetworkObserver |
| 24 : public net::NetworkChangeNotifier::IPAddressObserver, | 27 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 25 public net::NetworkChangeNotifier::OnlineStateObserver { | 28 public net::NetworkChangeNotifier::OnlineStateObserver { |
| 26 public: | 29 public: |
| 27 explicit PluginNetworkObserver(PpapiPluginProcessHost* process_host) | 30 explicit PluginNetworkObserver(PpapiPluginProcessHost* process_host) |
| 28 : process_host_(process_host) { | 31 : process_host_(process_host) { |
| 29 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 32 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 30 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 33 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 31 } | 34 } |
| 32 | 35 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 PpapiPluginProcessHost* plugin_host = | 81 PpapiPluginProcessHost* plugin_host = |
| 79 new PpapiPluginProcessHost(); | 82 new PpapiPluginProcessHost(); |
| 80 if(plugin_host->Init(info)) | 83 if(plugin_host->Init(info)) |
| 81 return plugin_host; | 84 return plugin_host; |
| 82 | 85 |
| 83 NOTREACHED(); // Init is not expected to fail. | 86 NOTREACHED(); // Init is not expected to fail. |
| 84 return NULL; | 87 return NULL; |
| 85 } | 88 } |
| 86 | 89 |
| 87 void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { | 90 void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { |
| 88 if (child_process_host()->opening_channel()) { | 91 if (child_process_host()->IsChannelOpening()) { |
| 89 // The channel is already in the process of being opened. Put | 92 // The channel is already in the process of being opened. Put |
| 90 // this "open channel" request into a queue of requests that will | 93 // this "open channel" request into a queue of requests that will |
| 91 // be run once the channel is open. | 94 // be run once the channel is open. |
| 92 pending_requests_.push_back(client); | 95 pending_requests_.push_back(client); |
| 93 return; | 96 return; |
| 94 } | 97 } |
| 95 | 98 |
| 96 // We already have an open channel, send a request right away to plugin. | 99 // We already have an open channel, send a request right away to plugin. |
| 97 RequestPluginChannel(client); | 100 RequestPluginChannel(client); |
| 98 } | 101 } |
| 99 | 102 |
| 100 PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) | 103 PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) |
| 101 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_PLUGIN), | 104 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_PLUGIN), |
| 102 filter_(new PepperMessageFilter(host_resolver)), | 105 filter_(new PepperMessageFilter(host_resolver)), |
| 103 network_observer_(new PluginNetworkObserver(this)), | 106 network_observer_(new PluginNetworkObserver(this)), |
| 104 is_broker_(false), | 107 is_broker_(false), |
| 105 process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) { | 108 process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { |
| 106 child_process_host()->AddFilter(filter_.get()); | 109 child_process_host()->AddFilter(filter_.get()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 PpapiPluginProcessHost::PpapiPluginProcessHost() | 112 PpapiPluginProcessHost::PpapiPluginProcessHost() |
| 110 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), | 113 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), |
| 111 is_broker_(true), | 114 is_broker_(true), |
| 112 process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) { | 115 process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { |
| 113 } | 116 } |
| 114 | 117 |
| 115 bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { | 118 bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { |
| 116 plugin_path_ = info.path; | 119 plugin_path_ = info.path; |
| 117 if (info.name.empty()) { | 120 if (info.name.empty()) { |
| 118 set_name(plugin_path_.BaseName().LossyDisplayName()); | 121 set_name(plugin_path_.BaseName().LossyDisplayName()); |
| 119 } else { | 122 } else { |
| 120 set_name(UTF8ToUTF16(info.name)); | 123 set_name(UTF8ToUTF16(info.name)); |
| 121 } | 124 } |
| 122 | 125 |
| 123 if (!child_process_host()->CreateChannel()) | 126 std::string channel_id = child_process_host()->CreateChannel(); |
| 127 if (channel_id.empty()) |
| 124 return false; | 128 return false; |
| 125 | 129 |
| 126 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 130 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 127 CommandLine::StringType plugin_launcher = | 131 CommandLine::StringType plugin_launcher = |
| 128 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); | 132 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
| 129 | 133 |
| 130 #if defined(OS_LINUX) | 134 #if defined(OS_LINUX) |
| 131 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 135 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
| 132 ChildProcessHost::CHILD_NORMAL; | 136 ChildProcessHost::CHILD_NORMAL; |
| 133 #else | 137 #else |
| 134 int flags = ChildProcessHost::CHILD_NORMAL; | 138 int flags = ChildProcessHost::CHILD_NORMAL; |
| 135 #endif | 139 #endif |
| 136 FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 140 FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
| 137 if (exe_path.empty()) | 141 if (exe_path.empty()) |
| 138 return false; | 142 return false; |
| 139 | 143 |
| 140 CommandLine* cmd_line = new CommandLine(exe_path); | 144 CommandLine* cmd_line = new CommandLine(exe_path); |
| 141 cmd_line->AppendSwitchASCII(switches::kProcessType, | 145 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 142 is_broker_ ? switches::kPpapiBrokerProcess | 146 is_broker_ ? switches::kPpapiBrokerProcess |
| 143 : switches::kPpapiPluginProcess); | 147 : switches::kPpapiPluginProcess); |
| 144 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, | 148 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 145 child_process_host()->channel_id()); | |
| 146 | 149 |
| 147 // These switches are forwarded to both plugin and broker pocesses. | 150 // These switches are forwarded to both plugin and broker pocesses. |
| 148 static const char* kCommonForwardSwitches[] = { | 151 static const char* kCommonForwardSwitches[] = { |
| 149 switches::kVModule | 152 switches::kVModule |
| 150 }; | 153 }; |
| 151 cmd_line->CopySwitchesFrom(browser_command_line, kCommonForwardSwitches, | 154 cmd_line->CopySwitchesFrom(browser_command_line, kCommonForwardSwitches, |
| 152 arraysize(kCommonForwardSwitches)); | 155 arraysize(kCommonForwardSwitches)); |
| 153 | 156 |
| 154 if (!is_broker_) { | 157 if (!is_broker_) { |
| 155 // TODO(vtl): Stop passing flash args in the command line, on windows is | 158 // TODO(vtl): Stop passing flash args in the command line, on windows is |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 ::DuplicateHandle(::GetCurrentProcess(), plugin_process, | 281 ::DuplicateHandle(::GetCurrentProcess(), plugin_process, |
| 279 renderer_process, &renderers_plugin_handle, | 282 renderer_process, &renderers_plugin_handle, |
| 280 0, FALSE, DUPLICATE_SAME_ACCESS); | 283 0, FALSE, DUPLICATE_SAME_ACCESS); |
| 281 #elif defined(OS_POSIX) | 284 #elif defined(OS_POSIX) |
| 282 // Don't need to duplicate anything on POSIX since it's just a PID. | 285 // Don't need to duplicate anything on POSIX since it's just a PID. |
| 283 base::ProcessHandle renderers_plugin_handle = plugin_process; | 286 base::ProcessHandle renderers_plugin_handle = plugin_process; |
| 284 #endif | 287 #endif |
| 285 | 288 |
| 286 client->OnChannelOpened(renderers_plugin_handle, channel_handle); | 289 client->OnChannelOpened(renderers_plugin_handle, channel_handle); |
| 287 } | 290 } |
| OLD | NEW |