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/plugin_process_host.h" | 5 #include "content/browser/plugin_process_host.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
10 #include <utility> // for pair<> | 10 #include <utility> // for pair<> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/base_switches.h" | 15 #include "base/base_switches.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "content/browser/browser_child_process_host_impl.h" | 24 #include "content/browser/browser_child_process_host_impl.h" |
| 25 #include "content/browser/loader/resource_message_filter.h" |
25 #include "content/browser/gpu/gpu_data_manager_impl.h" | 26 #include "content/browser/gpu/gpu_data_manager_impl.h" |
26 #include "content/browser/plugin_service_impl.h" | 27 #include "content/browser/plugin_service_impl.h" |
27 #include "content/common/child_process_host_impl.h" | 28 #include "content/common/child_process_host_impl.h" |
28 #include "content/common/plugin_process_messages.h" | 29 #include "content/common/plugin_process_messages.h" |
29 #include "content/common/resource_messages.h" | 30 #include "content/common/resource_messages.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
32 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
33 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
| 35 #include "content/public/browser/resource_context.h" |
34 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/process_type.h" | 37 #include "content/public/common/process_type.h" |
36 #include "ipc/ipc_switches.h" | 38 #include "ipc/ipc_switches.h" |
| 39 #include "net/url_request/url_request_context_getter.h" |
37 #include "ui/base/ui_base_switches.h" | 40 #include "ui/base/ui_base_switches.h" |
38 #include "ui/gfx/native_widget_types.h" | 41 #include "ui/gfx/native_widget_types.h" |
39 #include "ui/gl/gl_switches.h" | 42 #include "ui/gl/gl_switches.h" |
40 | 43 |
41 #if defined(USE_X11) | 44 #if defined(USE_X11) |
42 #include "ui/gfx/gtk_native_view_id_manager.h" | 45 #include "ui/gfx/gtk_native_view_id_manager.h" |
43 #endif | 46 #endif |
44 | 47 |
45 #if defined(OS_MACOSX) | 48 #if defined(OS_MACOSX) |
46 #include "base/mac/mac_util.h" | 49 #include "base/mac/mac_util.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 env, | 249 env, |
247 #endif | 250 #endif |
248 cmd_line); | 251 cmd_line); |
249 | 252 |
250 // The plugin needs to be shutdown gracefully, i.e. NP_Shutdown needs to be | 253 // The plugin needs to be shutdown gracefully, i.e. NP_Shutdown needs to be |
251 // called on the plugin. The plugin process exits when it receives the | 254 // called on the plugin. The plugin process exits when it receives the |
252 // OnChannelError notification indicating that the browser plugin channel has | 255 // OnChannelError notification indicating that the browser plugin channel has |
253 // been destroyed. | 256 // been destroyed. |
254 process_->SetTerminateChildOnShutdown(false); | 257 process_->SetTerminateChildOnShutdown(false); |
255 | 258 |
| 259 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
| 260 base::Bind(&PluginProcessHost::GetContexts, |
| 261 base::Unretained(this))); |
| 262 |
| 263 // TODO(jam): right now we're passing NULL for appcache, blob storage, and |
| 264 // file system. If NPAPI plugins actually use this, we'll have to plumb them. |
| 265 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( |
| 266 process_->GetData().id, PROCESS_TYPE_PLUGIN, NULL, NULL, NULL, |
| 267 get_contexts_callback); |
| 268 process_->GetHost()->AddFilter(resource_message_filter); |
256 return true; | 269 return true; |
257 } | 270 } |
258 | 271 |
259 void PluginProcessHost::ForceShutdown() { | 272 void PluginProcessHost::ForceShutdown() { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
261 Send(new PluginProcessMsg_NotifyRenderersOfPendingShutdown()); | 274 Send(new PluginProcessMsg_NotifyRenderersOfPendingShutdown()); |
262 process_->ForceShutdown(); | 275 process_->ForceShutdown(); |
263 } | 276 } |
264 | 277 |
265 void PluginProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { | 278 void PluginProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
266 process_->GetHost()->AddFilter(filter); | 279 process_->GetHost()->AddFilter(filter); |
267 } | 280 } |
268 | 281 |
269 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 282 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
270 bool handled = true; | 283 bool handled = true; |
271 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) | 284 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) |
272 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) | 285 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) |
| 286 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelDestroyed, |
| 287 OnChannelDestroyed) |
273 #if defined(OS_WIN) | 288 #if defined(OS_WIN) |
274 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, | 289 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, |
275 OnPluginWindowDestroyed) | 290 OnPluginWindowDestroyed) |
276 #endif | 291 #endif |
277 #if defined(TOOLKIT_GTK) | 292 #if defined(TOOLKIT_GTK) |
278 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, | 293 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, |
279 OnMapNativeViewId) | 294 OnMapNativeViewId) |
280 #endif | 295 #endif |
281 #if defined(OS_MACOSX) | 296 #if defined(OS_MACOSX) |
282 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, | 297 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, |
283 OnPluginSelectWindow) | 298 OnPluginSelectWindow) |
284 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow, | 299 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow, |
285 OnPluginShowWindow) | 300 OnPluginShowWindow) |
286 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginHideWindow, | 301 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginHideWindow, |
287 OnPluginHideWindow) | 302 OnPluginHideWindow) |
288 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSetCursorVisibility, | 303 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSetCursorVisibility, |
289 OnPluginSetCursorVisibility) | 304 OnPluginSetCursorVisibility) |
290 #endif | 305 #endif |
291 IPC_MESSAGE_UNHANDLED(handled = false) | 306 IPC_MESSAGE_UNHANDLED(handled = false) |
292 IPC_END_MESSAGE_MAP() | 307 IPC_END_MESSAGE_MAP() |
293 | 308 |
294 DCHECK(handled); | |
295 return handled; | 309 return handled; |
296 } | 310 } |
297 | 311 |
298 void PluginProcessHost::OnChannelConnected(int32 peer_pid) { | 312 void PluginProcessHost::OnChannelConnected(int32 peer_pid) { |
299 for (size_t i = 0; i < pending_requests_.size(); ++i) { | 313 for (size_t i = 0; i < pending_requests_.size(); ++i) { |
300 RequestPluginChannel(pending_requests_[i]); | 314 RequestPluginChannel(pending_requests_[i]); |
301 } | 315 } |
302 | 316 |
303 pending_requests_.clear(); | 317 pending_requests_.clear(); |
304 } | 318 } |
(...skipping 16 matching lines...) Expand all Loading... |
321 pending_requests_.clear(); | 335 pending_requests_.clear(); |
322 | 336 |
323 while (!sent_requests_.empty()) { | 337 while (!sent_requests_.empty()) { |
324 Client* client = sent_requests_.front(); | 338 Client* client = sent_requests_.front(); |
325 if (client) | 339 if (client) |
326 client->OnError(); | 340 client->OnError(); |
327 sent_requests_.pop_front(); | 341 sent_requests_.pop_front(); |
328 } | 342 } |
329 } | 343 } |
330 | 344 |
331 // static | |
332 void PluginProcessHost::CancelPendingRequestsForResourceContext( | |
333 ResourceContext* context) { | |
334 for (PluginProcessHostIterator host_it; !host_it.Done(); ++host_it) { | |
335 PluginProcessHost* host = *host_it; | |
336 for (size_t i = 0; i < host->pending_requests_.size(); ++i) { | |
337 if (host->pending_requests_[i]->GetResourceContext() == context) { | |
338 host->pending_requests_[i]->OnError(); | |
339 host->pending_requests_.erase(host->pending_requests_.begin() + i); | |
340 --i; | |
341 } | |
342 } | |
343 } | |
344 } | |
345 | |
346 void PluginProcessHost::OpenChannelToPlugin(Client* client) { | 345 void PluginProcessHost::OpenChannelToPlugin(Client* client) { |
347 BrowserThread::PostTask( | 346 BrowserThread::PostTask( |
348 BrowserThread::UI, FROM_HERE, | 347 BrowserThread::UI, FROM_HERE, |
349 base::Bind(&BrowserChildProcessHostImpl::NotifyProcessInstanceCreated, | 348 base::Bind(&BrowserChildProcessHostImpl::NotifyProcessInstanceCreated, |
350 process_->GetData())); | 349 process_->GetData())); |
351 client->SetPluginInfo(info_); | 350 client->SetPluginInfo(info_); |
352 if (process_->GetHost()->IsChannelOpening()) { | 351 if (process_->GetHost()->IsChannelOpening()) { |
353 // The channel is already in the process of being opened. Put | 352 // The channel is already in the process of being opened. Put |
354 // this "open channel" request into a queue of requests that will | 353 // this "open channel" request into a queue of requests that will |
355 // be run once the channel is open. | 354 // be run once the channel is open. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 client->OnSentPluginChannelRequest(); | 400 client->OnSentPluginChannelRequest(); |
402 } else { | 401 } else { |
403 client->OnError(); | 402 client->OnError(); |
404 } | 403 } |
405 } | 404 } |
406 | 405 |
407 void PluginProcessHost::OnChannelCreated( | 406 void PluginProcessHost::OnChannelCreated( |
408 const IPC::ChannelHandle& channel_handle) { | 407 const IPC::ChannelHandle& channel_handle) { |
409 Client* client = sent_requests_.front(); | 408 Client* client = sent_requests_.front(); |
410 | 409 |
411 if (client) | 410 if (client) { |
| 411 resource_context_map_[client->ID()] = client->GetResourceContext(); |
412 client->OnChannelOpened(channel_handle); | 412 client->OnChannelOpened(channel_handle); |
| 413 } |
413 sent_requests_.pop_front(); | 414 sent_requests_.pop_front(); |
414 } | 415 } |
415 | 416 |
| 417 void PluginProcessHost::OnChannelDestroyed(int renderer_id) { |
| 418 resource_context_map_.erase(renderer_id); |
| 419 } |
| 420 |
| 421 void PluginProcessHost::GetContexts(const ResourceHostMsg_Request& request, |
| 422 ResourceContext** resource_context, |
| 423 net::URLRequestContext** request_context) { |
| 424 *resource_context = resource_context_map_[request.origin_pid]; |
| 425 *request_context = (*resource_context)->GetRequestContext(); |
| 426 } |
| 427 |
416 } // namespace content | 428 } // namespace content |
OLD | NEW |