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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | 683 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
681 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 684 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
682 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | 685 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
683 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | 686 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
684 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | 687 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
685 OnSetSelectedColorInColorChooser) | 688 OnSetSelectedColorInColorChooser) |
686 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) | 689 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
687 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 690 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
688 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 691 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
689 OnRequestPpapiBrokerPermission) | 692 OnRequestPpapiBrokerPermission) |
693 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, | |
694 OnBrowserPluginNavigateGuest) | |
690 IPC_MESSAGE_UNHANDLED(handled = false) | 695 IPC_MESSAGE_UNHANDLED(handled = false) |
691 IPC_END_MESSAGE_MAP_EX() | 696 IPC_END_MESSAGE_MAP_EX() |
692 message_source_ = NULL; | 697 message_source_ = NULL; |
693 | 698 |
694 if (!message_is_ok) { | 699 if (!message_is_ok) { |
695 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 700 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
696 GetRenderProcessHost()->ReceivedBadMessage(); | 701 GetRenderProcessHost()->ReceivedBadMessage(); |
697 } | 702 } |
698 | 703 |
699 return handled; | 704 return handled; |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2267 } | 2272 } |
2268 | 2273 |
2269 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, | 2274 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, |
2270 bool result) { | 2275 bool result) { |
2271 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); | 2276 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
2272 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), | 2277 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), |
2273 request_id, | 2278 request_id, |
2274 result)); | 2279 result)); |
2275 } | 2280 } |
2276 | 2281 |
2282 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id, | |
2283 int64 frame_id, | |
2284 const std::string& src, | |
2285 const gfx::Size& size) { | |
2286 // This is the first 'navigate' to a browser plugin, before WebContents has/is | |
2287 // an 'Embedder'; subsequent navigate messages for this WebContents will | |
2288 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this | |
2289 // also means any message from browser plugin renderer prior to NavigateGuest | |
2290 // which is not NavigateGuest will be ignored). Therefore | |
2291 // |browser_plugin_embedder_| should not be set. | |
2292 CHECK(!browser_plugin_embedder_.get()); | |
2293 | |
2294 browser_plugin_embedder_.reset( | |
2295 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost())); | |
2296 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(), | |
2297 instance_id, | |
2298 frame_id, | |
2299 src, | |
2300 size); | |
2301 } | |
2302 | |
2277 // Notifies the RenderWidgetHost instance about the fact that the page is | 2303 // Notifies the RenderWidgetHost instance about the fact that the page is |
2278 // loading, or done loading and calls the base implementation. | 2304 // loading, or done loading and calls the base implementation. |
2279 void WebContentsImpl::SetIsLoading(bool is_loading, | 2305 void WebContentsImpl::SetIsLoading(bool is_loading, |
2280 LoadNotificationDetails* details) { | 2306 LoadNotificationDetails* details) { |
2281 if (is_loading == is_loading_) | 2307 if (is_loading == is_loading_) |
2282 return; | 2308 return; |
2283 | 2309 |
2284 if (!is_loading) { | 2310 if (!is_loading) { |
2285 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); | 2311 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
2286 load_state_host_.clear(); | 2312 load_state_host_.clear(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2423 | 2449 |
2424 void WebContentsImpl::NotifySwapped() { | 2450 void WebContentsImpl::NotifySwapped() { |
2425 // After sending out a swap notification, we need to send a disconnect | 2451 // After sending out a swap notification, we need to send a disconnect |
2426 // notification so that clients that pick up a pointer to |this| can NULL the | 2452 // notification so that clients that pick up a pointer to |this| can NULL the |
2427 // pointer. See Bug 1230284. | 2453 // pointer. See Bug 1230284. |
2428 notify_disconnection_ = true; | 2454 notify_disconnection_ = true; |
2429 content::NotificationService::current()->Notify( | 2455 content::NotificationService::current()->Notify( |
2430 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 2456 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
2431 content::Source<WebContents>(this), | 2457 content::Source<WebContents>(this), |
2432 content::NotificationService::NoDetails()); | 2458 content::NotificationService::NoDetails()); |
2459 | |
2460 // Ensure that the associated embedder gets cleared after a RenderViewHost | |
2461 // gets swapped, so we don't reuse the same embedder next time a | |
2462 // RenderViewHost is attached to this WebContents (for security concerns). | |
2463 RemoveSwappedOutBrowserPluginEmbedder(); | |
awong
2012/09/06 19:55:26
Can we add a test asserting this behavior, both th
lazyboy
2012/09/07 19:33:19
Will this be a similar browsertest that we current
awong
2012/09/07 20:51:03
Yes, something like that. Is there already a test
lazyboy
2012/09/08 02:12:22
No there isn't. I'll be adding one soon.
On 2012/
| |
2433 } | 2464 } |
2434 | 2465 |
2435 void WebContentsImpl::NotifyConnected() { | 2466 void WebContentsImpl::NotifyConnected() { |
2436 notify_disconnection_ = true; | 2467 notify_disconnection_ = true; |
2437 content::NotificationService::current()->Notify( | 2468 content::NotificationService::current()->Notify( |
2438 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 2469 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
2439 content::Source<WebContents>(this), | 2470 content::Source<WebContents>(this), |
2440 content::NotificationService::NoDetails()); | 2471 content::NotificationService::NoDetails()); |
2441 } | 2472 } |
2442 | 2473 |
(...skipping 25 matching lines...) Expand all Loading... | |
2468 WebContents* WebContentsImpl::GetAsWebContents() { | 2499 WebContents* WebContentsImpl::GetAsWebContents() { |
2469 return this; | 2500 return this; |
2470 } | 2501 } |
2471 | 2502 |
2472 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 2503 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
2473 if (delegate_) | 2504 if (delegate_) |
2474 return delegate_->GetRootWindowResizerRect(); | 2505 return delegate_->GetRootWindowResizerRect(); |
2475 return gfx::Rect(); | 2506 return gfx::Rect(); |
2476 } | 2507 } |
2477 | 2508 |
2509 void WebContentsImpl::RemoveSwappedOutBrowserPluginEmbedder() { | |
2510 if (browser_plugin_embedder_.get() && | |
2511 !browser_plugin_embedder_->IsForRenderViewHost(GetRenderViewHost())) { | |
awong
2012/09/06 19:55:26
Is there a case where you get a swapped signal, ha
lazyboy
2012/09/07 19:33:19
This is unnecessary it seems (I had way less idea
| |
2512 browser_plugin_embedder_.reset(); | |
2513 } | |
2514 } | |
2515 | |
2478 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 2516 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
2479 // Don't send notifications if we are just creating a swapped-out RVH for | 2517 // Don't send notifications if we are just creating a swapped-out RVH for |
2480 // the opener chain. These won't be used for view-source or WebUI, so it's | 2518 // the opener chain. These won't be used for view-source or WebUI, so it's |
2481 // ok to return early. | 2519 // ok to return early. |
2482 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2520 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
2483 return; | 2521 return; |
2484 | 2522 |
2485 content::NotificationService::current()->Notify( | 2523 content::NotificationService::current()->Notify( |
2486 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2524 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2487 content::Source<WebContents>(this), | 2525 content::Source<WebContents>(this), |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3256 old_browser_plugin_host()->embedder_render_process_host(); | 3294 old_browser_plugin_host()->embedder_render_process_host(); |
3257 *embedder_container_id = old_browser_plugin_host()->instance_id(); | 3295 *embedder_container_id = old_browser_plugin_host()->instance_id(); |
3258 int embedder_process_id = | 3296 int embedder_process_id = |
3259 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; | 3297 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
3260 if (embedder_process_id != -1) { | 3298 if (embedder_process_id != -1) { |
3261 *embedder_channel_name = | 3299 *embedder_channel_name = |
3262 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), | 3300 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
3263 embedder_process_id); | 3301 embedder_process_id); |
3264 } | 3302 } |
3265 } | 3303 } |
3304 | |
3305 content::BrowserPluginGuest* WebContentsImpl::AssignBrowserPluginGuest( | |
3306 int instance_id) { | |
3307 browser_plugin_guest_.reset(content::BrowserPluginGuest::Create( | |
3308 instance_id, this, GetRenderViewHost())); | |
3309 return browser_plugin_guest_.get(); | |
3310 } | |
3311 | |
3312 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { | |
3313 return browser_plugin_guest_.get(); | |
3314 } | |
3315 | |
3316 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { | |
3317 return browser_plugin_embedder_.get(); | |
3318 } | |
OLD | NEW |