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/browser/ppapi_plugin_process_host.h" | 5 #include "content/browser/ppapi_plugin_process_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 | 201 |
202 void PpapiPluginProcessHost::RequestPluginChannel(Client* client) { | 202 void PpapiPluginProcessHost::RequestPluginChannel(Client* client) { |
203 base::ProcessHandle process_handle; | 203 base::ProcessHandle process_handle; |
204 int renderer_id; | 204 int renderer_id; |
205 client->GetPpapiChannelInfo(&process_handle, &renderer_id); | 205 client->GetPpapiChannelInfo(&process_handle, &renderer_id); |
206 | 206 |
207 // We can't send any sync messages from the browser because it might lead to | 207 // We can't send any sync messages from the browser because it might lead to |
208 // a hang. See the similar code in PluginProcessHost for more description. | 208 // a hang. See the similar code in PluginProcessHost for more description. |
209 PpapiMsg_CreateChannel* msg = new PpapiMsg_CreateChannel( | 209 PpapiMsg_CreateChannel* msg = new PpapiMsg_CreateChannel( |
210 process_handle, renderer_id, client->OffTheRecord()); | 210 renderer_id, client->OffTheRecord()); |
211 msg->set_unblock(true); | 211 msg->set_unblock(true); |
212 if (Send(msg)) { | 212 if (Send(msg)) { |
213 sent_requests_.push(client); | 213 sent_requests_.push(client); |
214 } else { | 214 } else { |
215 client->OnPpapiChannelOpened(base::kNullProcessHandle, | 215 client->OnPpapiChannelOpened(IPC::ChannelHandle(), 0); |
216 IPC::ChannelHandle(), 0); | |
217 } | 216 } |
218 } | 217 } |
219 | 218 |
220 void PpapiPluginProcessHost::OnProcessLaunched() { | 219 void PpapiPluginProcessHost::OnProcessLaunched() { |
221 } | 220 } |
222 | 221 |
223 bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 222 bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
224 bool handled = true; | 223 bool handled = true; |
225 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg) | 224 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg) |
226 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, | 225 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, |
(...skipping 26 matching lines...) Expand all Loading... |
253 // plugin since they have their own channels which will go into the error | 252 // plugin since they have their own channels which will go into the error |
254 // state at the same time. Instead, we just need to notify any renderers | 253 // state at the same time. Instead, we just need to notify any renderers |
255 // that have requested a connection but have not yet received one. | 254 // that have requested a connection but have not yet received one. |
256 CancelRequests(); | 255 CancelRequests(); |
257 } | 256 } |
258 | 257 |
259 void PpapiPluginProcessHost::CancelRequests() { | 258 void PpapiPluginProcessHost::CancelRequests() { |
260 DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "") | 259 DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "") |
261 << "CancelRequests()"; | 260 << "CancelRequests()"; |
262 for (size_t i = 0; i < pending_requests_.size(); i++) { | 261 for (size_t i = 0; i < pending_requests_.size(); i++) { |
263 pending_requests_[i]->OnPpapiChannelOpened(base::kNullProcessHandle, | 262 pending_requests_[i]->OnPpapiChannelOpened(IPC::ChannelHandle(), 0); |
264 IPC::ChannelHandle(), 0); | |
265 } | 263 } |
266 pending_requests_.clear(); | 264 pending_requests_.clear(); |
267 | 265 |
268 while (!sent_requests_.empty()) { | 266 while (!sent_requests_.empty()) { |
269 sent_requests_.front()->OnPpapiChannelOpened(base::kNullProcessHandle, | 267 sent_requests_.front()->OnPpapiChannelOpened(IPC::ChannelHandle(), 0); |
270 IPC::ChannelHandle(), 0); | |
271 sent_requests_.pop(); | 268 sent_requests_.pop(); |
272 } | 269 } |
273 } | 270 } |
274 | 271 |
275 // Called when a new plugin <--> renderer channel has been created. | 272 // Called when a new plugin <--> renderer channel has been created. |
276 void PpapiPluginProcessHost::OnRendererPluginChannelCreated( | 273 void PpapiPluginProcessHost::OnRendererPluginChannelCreated( |
277 const IPC::ChannelHandle& channel_handle) { | 274 const IPC::ChannelHandle& channel_handle) { |
278 if (sent_requests_.empty()) | 275 if (sent_requests_.empty()) |
279 return; | 276 return; |
280 | 277 |
281 // All requests should be processed FIFO, so the next item in the | 278 // All requests should be processed FIFO, so the next item in the |
282 // sent_requests_ queue should be the one that the plugin just created. | 279 // sent_requests_ queue should be the one that the plugin just created. |
283 Client* client = sent_requests_.front(); | 280 Client* client = sent_requests_.front(); |
284 sent_requests_.pop(); | 281 sent_requests_.pop(); |
285 | 282 |
286 // Prepare the handle to send to the renderer. | 283 client->OnPpapiChannelOpened(channel_handle, process_->GetData().id); |
287 base::ProcessHandle plugin_process = process_->GetHandle(); | |
288 #if defined(OS_WIN) | |
289 base::ProcessHandle renderer_process; | |
290 int renderer_id; | |
291 client->GetPpapiChannelInfo(&renderer_process, &renderer_id); | |
292 | |
293 base::ProcessHandle renderers_plugin_handle = NULL; | |
294 ::DuplicateHandle(::GetCurrentProcess(), plugin_process, | |
295 renderer_process, &renderers_plugin_handle, | |
296 0, FALSE, DUPLICATE_SAME_ACCESS); | |
297 #elif defined(OS_POSIX) | |
298 // Don't need to duplicate anything on POSIX since it's just a PID. | |
299 base::ProcessHandle renderers_plugin_handle = plugin_process; | |
300 #endif | |
301 | |
302 client->OnPpapiChannelOpened(renderers_plugin_handle, channel_handle, | |
303 process_->GetData().id); | |
304 } | 284 } |
OLD | NEW |