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/browser_child_process_host.h" |
12 #include "content/browser/plugin_service_impl.h" | 13 #include "content/browser/plugin_service_impl.h" |
13 #include "content/browser/renderer_host/render_message_filter.h" | 14 #include "content/browser/renderer_host/render_message_filter.h" |
14 #include "content/common/child_process_host_impl.h" | 15 #include "content/common/child_process_host_impl.h" |
15 #include "content/common/child_process_messages.h" | 16 #include "content/common/child_process_messages.h" |
16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
17 #include "content/public/common/pepper_plugin_info.h" | 18 #include "content/public/common/pepper_plugin_info.h" |
18 #include "content/public/common/process_type.h" | 19 #include "content/public/common/process_type.h" |
19 #include "ipc/ipc_switches.h" | 20 #include "ipc/ipc_switches.h" |
20 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
21 #include "ppapi/proxy/ppapi_messages.h" | 22 #include "ppapi/proxy/ppapi_messages.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const content::PepperPluginInfo& info) { | 81 const content::PepperPluginInfo& info) { |
81 PpapiPluginProcessHost* plugin_host = | 82 PpapiPluginProcessHost* plugin_host = |
82 new PpapiPluginProcessHost(); | 83 new PpapiPluginProcessHost(); |
83 if(plugin_host->Init(info)) | 84 if(plugin_host->Init(info)) |
84 return plugin_host; | 85 return plugin_host; |
85 | 86 |
86 NOTREACHED(); // Init is not expected to fail. | 87 NOTREACHED(); // Init is not expected to fail. |
87 return NULL; | 88 return NULL; |
88 } | 89 } |
89 | 90 |
| 91 bool PpapiPluginProcessHost::Send(IPC::Message* message) { |
| 92 return process_->Send(message); |
| 93 } |
| 94 |
90 void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { | 95 void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { |
91 if (child_process_host()->IsChannelOpening()) { | 96 if (process_->GetHost()->IsChannelOpening()) { |
92 // The channel is already in the process of being opened. Put | 97 // The channel is already in the process of being opened. Put |
93 // this "open channel" request into a queue of requests that will | 98 // this "open channel" request into a queue of requests that will |
94 // be run once the channel is open. | 99 // be run once the channel is open. |
95 pending_requests_.push_back(client); | 100 pending_requests_.push_back(client); |
96 return; | 101 return; |
97 } | 102 } |
98 | 103 |
99 // We already have an open channel, send a request right away to plugin. | 104 // We already have an open channel, send a request right away to plugin. |
100 RequestPluginChannel(client); | 105 RequestPluginChannel(client); |
101 } | 106 } |
102 | 107 |
103 PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) | 108 PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) |
104 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_PLUGIN), | 109 : filter_(new PepperMessageFilter(host_resolver)), |
105 filter_(new PepperMessageFilter(host_resolver)), | |
106 network_observer_(new PluginNetworkObserver(this)), | 110 network_observer_(new PluginNetworkObserver(this)), |
107 is_broker_(false), | 111 is_broker_(false), |
108 process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { | 112 process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { |
109 child_process_host()->AddFilter(filter_.get()); | 113 process_.reset(new BrowserChildProcessHost( |
| 114 content::PROCESS_TYPE_PPAPI_PLUGIN, this)); |
| 115 process_->GetHost()->AddFilter(filter_.get()); |
110 } | 116 } |
111 | 117 |
112 PpapiPluginProcessHost::PpapiPluginProcessHost() | 118 PpapiPluginProcessHost::PpapiPluginProcessHost() |
113 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), | 119 : is_broker_(true), |
114 is_broker_(true), | |
115 process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { | 120 process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { |
| 121 process_.reset(new BrowserChildProcessHost( |
| 122 content::PROCESS_TYPE_PPAPI_BROKER, this)); |
116 } | 123 } |
117 | 124 |
118 bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { | 125 bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { |
119 plugin_path_ = info.path; | 126 plugin_path_ = info.path; |
120 if (info.name.empty()) { | 127 if (info.name.empty()) { |
121 SetName(plugin_path_.BaseName().LossyDisplayName()); | 128 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); |
122 } else { | 129 } else { |
123 SetName(UTF8ToUTF16(info.name)); | 130 process_->SetName(UTF8ToUTF16(info.name)); |
124 } | 131 } |
125 | 132 |
126 std::string channel_id = child_process_host()->CreateChannel(); | 133 std::string channel_id = process_->GetHost()->CreateChannel(); |
127 if (channel_id.empty()) | 134 if (channel_id.empty()) |
128 return false; | 135 return false; |
129 | 136 |
130 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 137 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
131 CommandLine::StringType plugin_launcher = | 138 CommandLine::StringType plugin_launcher = |
132 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); | 139 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
133 | 140 |
134 #if defined(OS_LINUX) | 141 #if defined(OS_LINUX) |
135 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 142 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
136 ChildProcessHost::CHILD_NORMAL; | 143 ChildProcessHost::CHILD_NORMAL; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (!plugin_launcher.empty()) | 176 if (!plugin_launcher.empty()) |
170 cmd_line->PrependWrapper(plugin_launcher); | 177 cmd_line->PrependWrapper(plugin_launcher); |
171 | 178 |
172 // On posix, never use the zygote for the broker. Also, only use the zygote if | 179 // On posix, never use the zygote for the broker. Also, only use the zygote if |
173 // the plugin is sandboxed, and we are not using a plugin launcher - having a | 180 // the plugin is sandboxed, and we are not using a plugin launcher - having a |
174 // plugin launcher means we need to use another process instead of just | 181 // plugin launcher means we need to use another process instead of just |
175 // forking the zygote. | 182 // forking the zygote. |
176 #if defined(OS_POSIX) | 183 #if defined(OS_POSIX) |
177 bool use_zygote = !is_broker_ && plugin_launcher.empty() && info.is_sandboxed; | 184 bool use_zygote = !is_broker_ && plugin_launcher.empty() && info.is_sandboxed; |
178 #endif // OS_POSIX | 185 #endif // OS_POSIX |
179 Launch( | 186 process_->Launch( |
180 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
181 FilePath(), | 188 FilePath(), |
182 #elif defined(OS_POSIX) | 189 #elif defined(OS_POSIX) |
183 use_zygote, | 190 use_zygote, |
184 base::environment_vector(), | 191 base::environment_vector(), |
185 #endif | 192 #endif |
186 cmd_line); | 193 cmd_line); |
187 return true; | 194 return true; |
188 } | 195 } |
189 | 196 |
(...skipping 22 matching lines...) Expand all Loading... |
212 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, | 219 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, |
213 OnRendererPluginChannelCreated) | 220 OnRendererPluginChannelCreated) |
214 IPC_MESSAGE_UNHANDLED(handled = false) | 221 IPC_MESSAGE_UNHANDLED(handled = false) |
215 IPC_END_MESSAGE_MAP() | 222 IPC_END_MESSAGE_MAP() |
216 DCHECK(handled); | 223 DCHECK(handled); |
217 return handled; | 224 return handled; |
218 } | 225 } |
219 | 226 |
220 // Called when the browser <--> plugin channel has been established. | 227 // Called when the browser <--> plugin channel has been established. |
221 void PpapiPluginProcessHost::OnChannelConnected(int32 peer_pid) { | 228 void PpapiPluginProcessHost::OnChannelConnected(int32 peer_pid) { |
222 BrowserChildProcessHost::OnChannelConnected(peer_pid); | |
223 // This will actually load the plugin. Errors will actually not be reported | 229 // This will actually load the plugin. Errors will actually not be reported |
224 // back at this point. Instead, the plugin will fail to establish the | 230 // back at this point. Instead, the plugin will fail to establish the |
225 // connections when we request them on behalf of the renderer(s). | 231 // connections when we request them on behalf of the renderer(s). |
226 Send(new PpapiMsg_LoadPlugin(plugin_path_)); | 232 Send(new PpapiMsg_LoadPlugin(plugin_path_)); |
227 | 233 |
228 // Process all pending channel requests from the renderers. | 234 // Process all pending channel requests from the renderers. |
229 for (size_t i = 0; i < pending_requests_.size(); i++) | 235 for (size_t i = 0; i < pending_requests_.size(); i++) |
230 RequestPluginChannel(pending_requests_[i]); | 236 RequestPluginChannel(pending_requests_[i]); |
231 pending_requests_.clear(); | 237 pending_requests_.clear(); |
232 } | 238 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 const IPC::ChannelHandle& channel_handle) { | 270 const IPC::ChannelHandle& channel_handle) { |
265 if (sent_requests_.empty()) | 271 if (sent_requests_.empty()) |
266 return; | 272 return; |
267 | 273 |
268 // All requests should be processed FIFO, so the next item in the | 274 // All requests should be processed FIFO, so the next item in the |
269 // sent_requests_ queue should be the one that the plugin just created. | 275 // sent_requests_ queue should be the one that the plugin just created. |
270 Client* client = sent_requests_.front(); | 276 Client* client = sent_requests_.front(); |
271 sent_requests_.pop(); | 277 sent_requests_.pop(); |
272 | 278 |
273 // Prepare the handle to send to the renderer. | 279 // Prepare the handle to send to the renderer. |
274 base::ProcessHandle plugin_process = GetChildProcessHandle(); | 280 base::ProcessHandle plugin_process = process_->GetHandle(); |
275 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
276 base::ProcessHandle renderer_process; | 282 base::ProcessHandle renderer_process; |
277 int renderer_id; | 283 int renderer_id; |
278 client->GetChannelInfo(&renderer_process, &renderer_id); | 284 client->GetChannelInfo(&renderer_process, &renderer_id); |
279 | 285 |
280 base::ProcessHandle renderers_plugin_handle = NULL; | 286 base::ProcessHandle renderers_plugin_handle = NULL; |
281 ::DuplicateHandle(::GetCurrentProcess(), plugin_process, | 287 ::DuplicateHandle(::GetCurrentProcess(), plugin_process, |
282 renderer_process, &renderers_plugin_handle, | 288 renderer_process, &renderers_plugin_handle, |
283 0, FALSE, DUPLICATE_SAME_ACCESS); | 289 0, FALSE, DUPLICATE_SAME_ACCESS); |
284 #elif defined(OS_POSIX) | 290 #elif defined(OS_POSIX) |
285 // Don't need to duplicate anything on POSIX since it's just a PID. | 291 // Don't need to duplicate anything on POSIX since it's just a PID. |
286 base::ProcessHandle renderers_plugin_handle = plugin_process; | 292 base::ProcessHandle renderers_plugin_handle = plugin_process; |
287 #endif | 293 #endif |
288 | 294 |
289 client->OnChannelOpened(renderers_plugin_handle, channel_handle); | 295 client->OnChannelOpened(renderers_plugin_handle, channel_handle); |
290 } | 296 } |
OLD | NEW |