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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | |
19 #include "content/browser/browser_plugin/browser_plugin_guest.h" | |
18 #include "content/browser/browser_plugin/old/old_browser_plugin_host.h" | 20 #include "content/browser/browser_plugin/old/old_browser_plugin_host.h" |
19 #include "content/browser/child_process_security_policy_impl.h" | 21 #include "content/browser/child_process_security_policy_impl.h" |
20 #include "content/browser/debugger/devtools_manager_impl.h" | 22 #include "content/browser/debugger/devtools_manager_impl.h" |
21 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 23 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
22 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
23 #include "content/browser/download/download_stats.h" | 25 #include "content/browser/download/download_stats.h" |
24 #include "content/browser/download/mhtml_generation_manager.h" | 26 #include "content/browser/download/mhtml_generation_manager.h" |
25 #include "content/browser/download/save_package.h" | 27 #include "content/browser/download/save_package.h" |
26 #include "content/browser/gpu/gpu_data_manager_impl.h" | 28 #include "content/browser/gpu/gpu_data_manager_impl.h" |
27 #include "content/browser/gpu/gpu_process_host.h" | 29 #include "content/browser/gpu/gpu_process_host.h" |
28 #include "content/browser/host_zoom_map_impl.h" | 30 #include "content/browser/host_zoom_map_impl.h" |
29 #include "content/browser/intents/web_intents_dispatcher_impl.h" | 31 #include "content/browser/intents/web_intents_dispatcher_impl.h" |
30 #include "content/browser/renderer_host/render_process_host_impl.h" | 32 #include "content/browser/renderer_host/render_process_host_impl.h" |
31 #include "content/browser/renderer_host/render_view_host_impl.h" | 33 #include "content/browser/renderer_host/render_view_host_impl.h" |
32 #include "content/browser/renderer_host/render_widget_host_impl.h" | 34 #include "content/browser/renderer_host/render_widget_host_impl.h" |
33 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 35 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
34 #include "content/browser/site_instance_impl.h" | 36 #include "content/browser/site_instance_impl.h" |
35 #include "content/browser/web_contents/interstitial_page_impl.h" | 37 #include "content/browser/web_contents/interstitial_page_impl.h" |
36 #include "content/browser/web_contents/navigation_entry_impl.h" | 38 #include "content/browser/web_contents/navigation_entry_impl.h" |
37 #include "content/browser/webui/web_ui_impl.h" | 39 #include "content/browser/webui/web_ui_impl.h" |
40 #include "content/common/browser_plugin_messages.h" | |
38 #include "content/common/intents_messages.h" | 41 #include "content/common/intents_messages.h" |
39 #include "content/common/ssl_status_serialization.h" | 42 #include "content/common/ssl_status_serialization.h" |
40 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
41 #include "content/port/browser/render_view_host_delegate_view.h" | 44 #include "content/port/browser/render_view_host_delegate_view.h" |
42 #include "content/port/browser/render_widget_host_view_port.h" | 45 #include "content/port/browser/render_widget_host_view_port.h" |
43 #include "content/public/browser/browser_context.h" | 46 #include "content/public/browser/browser_context.h" |
44 #include "content/public/browser/color_chooser.h" | 47 #include "content/public/browser/color_chooser.h" |
45 #include "content/public/browser/content_browser_client.h" | 48 #include "content/public/browser/content_browser_client.h" |
46 #include "content/public/browser/devtools_agent_host_registry.h" | 49 #include "content/public/browser/devtools_agent_host_registry.h" |
47 #include "content/public/browser/download_manager.h" | 50 #include "content/public/browser/download_manager.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 int routing_id, | 419 int routing_id, |
417 const WebContentsImpl* base_web_contents, | 420 const WebContentsImpl* base_web_contents, |
418 WebContentsImpl* opener) { | 421 WebContentsImpl* opener) { |
419 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener); | 422 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener); |
420 | 423 |
421 new_contents->Init(browser_context, site_instance, routing_id, | 424 new_contents->Init(browser_context, site_instance, routing_id, |
422 static_cast<const WebContentsImpl*>(base_web_contents)); | 425 static_cast<const WebContentsImpl*>(base_web_contents)); |
423 return new_contents; | 426 return new_contents; |
424 } | 427 } |
425 | 428 |
429 WebContentsImpl* WebContentsImpl::CreateGuest(BrowserContext* browser_context, | |
430 const std::string& host_url, | |
431 int guest_instance_id) { | |
432 // The SiteInstance of a given guest is based on the fact that it's a guest | |
433 // in addition to which platform application the guest belongs to, rather | |
434 // than the URL that the guest is being navigated to. | |
435 GURL guest_site( | |
436 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str())); | |
437 SiteInstance* guest_site_instance = | |
438 SiteInstance::CreateForURL(browser_context, guest_site); | |
439 WebContentsImpl* new_contents = WebContentsImpl::Create( | |
440 browser_context, | |
441 guest_site_instance, | |
442 MSG_ROUTING_NONE, | |
443 NULL); // base WebContents | |
444 WebContentsImpl* new_contents_impl = | |
445 static_cast<WebContentsImpl*>(new_contents); | |
446 | |
447 // This makes |new_contents| to have a guest role. | |
Charlie Reis
2012/09/13 00:51:44
nit: This makes |new_contents| act as a guest.
lazyboy
2012/09/13 15:56:24
Done.
| |
448 // For more info, see comment above class BrowserPluginGuest. | |
449 new_contents_impl->browser_plugin_guest_.reset( | |
450 content::BrowserPluginGuest::Create( | |
451 guest_instance_id, | |
452 new_contents_impl, | |
453 new_contents_impl->GetRenderViewHost())); | |
454 return new_contents; | |
455 } | |
456 | |
426 WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, | 457 WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, |
427 const GURL& url) { | 458 const GURL& url) { |
428 WebPreferences prefs; | 459 WebPreferences prefs; |
429 | 460 |
430 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 461 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
431 | 462 |
432 prefs.developer_extras_enabled = true; | 463 prefs.developer_extras_enabled = true; |
433 prefs.javascript_enabled = | 464 prefs.javascript_enabled = |
434 !command_line.HasSwitch(switches::kDisableJavaScript); | 465 !command_line.HasSwitch(switches::kDisableJavaScript); |
435 prefs.web_security_enabled = | 466 prefs.web_security_enabled = |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | 718 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
688 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 719 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
689 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | 720 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
690 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | 721 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
691 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | 722 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
692 OnSetSelectedColorInColorChooser) | 723 OnSetSelectedColorInColorChooser) |
693 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) | 724 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
694 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 725 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
695 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 726 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
696 OnRequestPpapiBrokerPermission) | 727 OnRequestPpapiBrokerPermission) |
728 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, | |
729 OnBrowserPluginNavigateGuest) | |
697 IPC_MESSAGE_UNHANDLED(handled = false) | 730 IPC_MESSAGE_UNHANDLED(handled = false) |
698 IPC_END_MESSAGE_MAP_EX() | 731 IPC_END_MESSAGE_MAP_EX() |
699 message_source_ = NULL; | 732 message_source_ = NULL; |
700 | 733 |
701 if (!message_is_ok) { | 734 if (!message_is_ok) { |
702 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 735 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
703 GetRenderProcessHost()->ReceivedBadMessage(); | 736 GetRenderProcessHost()->ReceivedBadMessage(); |
704 } | 737 } |
705 | 738 |
706 return handled; | 739 return handled; |
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2295 } | 2328 } |
2296 | 2329 |
2297 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, | 2330 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, |
2298 bool result) { | 2331 bool result) { |
2299 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); | 2332 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
2300 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), | 2333 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), |
2301 request_id, | 2334 request_id, |
2302 result)); | 2335 result)); |
2303 } | 2336 } |
2304 | 2337 |
2338 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id, | |
2339 int64 frame_id, | |
2340 const std::string& src, | |
2341 const gfx::Size& size) { | |
2342 // This is the first 'navigate' to a browser plugin, before WebContents has/is | |
2343 // an 'Embedder'; subsequent navigate messages for this WebContents will | |
2344 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this | |
2345 // also means any message from browser plugin renderer prior to NavigateGuest | |
2346 // which is not NavigateGuest will be ignored). Therefore | |
2347 // |browser_plugin_embedder_| should not be set. | |
2348 // For more info, see comment above classes BrowserPluginEmbedder and | |
2349 // BrowserPluginGuest. | |
2350 CHECK(!browser_plugin_embedder_.get()); | |
2351 | |
2352 browser_plugin_embedder_.reset( | |
2353 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost())); | |
2354 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(), | |
2355 instance_id, | |
2356 frame_id, | |
2357 src, | |
2358 size); | |
2359 } | |
2360 | |
2305 // Notifies the RenderWidgetHost instance about the fact that the page is | 2361 // Notifies the RenderWidgetHost instance about the fact that the page is |
2306 // loading, or done loading and calls the base implementation. | 2362 // loading, or done loading and calls the base implementation. |
2307 void WebContentsImpl::SetIsLoading(bool is_loading, | 2363 void WebContentsImpl::SetIsLoading(bool is_loading, |
2308 LoadNotificationDetails* details) { | 2364 LoadNotificationDetails* details) { |
2309 if (is_loading == is_loading_) | 2365 if (is_loading == is_loading_) |
2310 return; | 2366 return; |
2311 | 2367 |
2312 if (!is_loading) { | 2368 if (!is_loading) { |
2313 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); | 2369 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
2314 load_state_host_.clear(); | 2370 load_state_host_.clear(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2451 | 2507 |
2452 void WebContentsImpl::NotifySwapped() { | 2508 void WebContentsImpl::NotifySwapped() { |
2453 // After sending out a swap notification, we need to send a disconnect | 2509 // After sending out a swap notification, we need to send a disconnect |
2454 // notification so that clients that pick up a pointer to |this| can NULL the | 2510 // notification so that clients that pick up a pointer to |this| can NULL the |
2455 // pointer. See Bug 1230284. | 2511 // pointer. See Bug 1230284. |
2456 notify_disconnection_ = true; | 2512 notify_disconnection_ = true; |
2457 content::NotificationService::current()->Notify( | 2513 content::NotificationService::current()->Notify( |
2458 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 2514 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
2459 content::Source<WebContents>(this), | 2515 content::Source<WebContents>(this), |
2460 content::NotificationService::NoDetails()); | 2516 content::NotificationService::NoDetails()); |
2517 | |
2518 // Ensure that the associated embedder gets cleared after a RenderViewHost | |
2519 // gets swapped, so we don't reuse the same embedder next time a | |
2520 // RenderViewHost is attached to this WebContents (for security concerns). | |
Charlie Reis
2012/09/13 00:51:44
What security concerns? I suggest dropping that p
lazyboy
2012/09/13 15:56:24
Remove the security concerns part from the comment
| |
2521 RemoveSwappedOutBrowserPluginEmbedder(); | |
2461 } | 2522 } |
2462 | 2523 |
2463 void WebContentsImpl::NotifyConnected() { | 2524 void WebContentsImpl::NotifyConnected() { |
2464 notify_disconnection_ = true; | 2525 notify_disconnection_ = true; |
2465 content::NotificationService::current()->Notify( | 2526 content::NotificationService::current()->Notify( |
2466 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 2527 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
2467 content::Source<WebContents>(this), | 2528 content::Source<WebContents>(this), |
2468 content::NotificationService::NoDetails()); | 2529 content::NotificationService::NoDetails()); |
2469 } | 2530 } |
2470 | 2531 |
(...skipping 25 matching lines...) Expand all Loading... | |
2496 WebContents* WebContentsImpl::GetAsWebContents() { | 2557 WebContents* WebContentsImpl::GetAsWebContents() { |
2497 return this; | 2558 return this; |
2498 } | 2559 } |
2499 | 2560 |
2500 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 2561 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
2501 if (delegate_) | 2562 if (delegate_) |
2502 return delegate_->GetRootWindowResizerRect(); | 2563 return delegate_->GetRootWindowResizerRect(); |
2503 return gfx::Rect(); | 2564 return gfx::Rect(); |
2504 } | 2565 } |
2505 | 2566 |
2567 void WebContentsImpl::RemoveSwappedOutBrowserPluginEmbedder() { | |
2568 if (browser_plugin_embedder_.get()) | |
2569 browser_plugin_embedder_.reset(); | |
2570 } | |
2571 | |
2506 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 2572 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
2507 // Don't send notifications if we are just creating a swapped-out RVH for | 2573 // Don't send notifications if we are just creating a swapped-out RVH for |
2508 // the opener chain. These won't be used for view-source or WebUI, so it's | 2574 // the opener chain. These won't be used for view-source or WebUI, so it's |
2509 // ok to return early. | 2575 // ok to return early. |
2510 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2576 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
2511 return; | 2577 return; |
2512 | 2578 |
2513 content::NotificationService::current()->Notify( | 2579 content::NotificationService::current()->Notify( |
2514 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2580 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2515 content::Source<WebContents>(this), | 2581 content::Source<WebContents>(this), |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3284 old_browser_plugin_host()->embedder_render_process_host(); | 3350 old_browser_plugin_host()->embedder_render_process_host(); |
3285 *embedder_container_id = old_browser_plugin_host()->instance_id(); | 3351 *embedder_container_id = old_browser_plugin_host()->instance_id(); |
3286 int embedder_process_id = | 3352 int embedder_process_id = |
3287 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; | 3353 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
3288 if (embedder_process_id != -1) { | 3354 if (embedder_process_id != -1) { |
3289 *embedder_channel_name = | 3355 *embedder_channel_name = |
3290 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), | 3356 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
3291 embedder_process_id); | 3357 embedder_process_id); |
3292 } | 3358 } |
3293 } | 3359 } |
3360 | |
3361 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { | |
3362 return browser_plugin_guest_.get(); | |
3363 } | |
3364 | |
3365 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { | |
3366 return browser_plugin_embedder_.get(); | |
3367 } | |
OLD | NEW |