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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 ++it) { | 311 ++it) { |
309 new_contents->GetController().SetSessionStorageNamespace(it->first, | 312 new_contents->GetController().SetSessionStorageNamespace(it->first, |
310 it->second); | 313 it->second); |
311 } | 314 } |
312 | 315 |
313 new_contents->Init(browser_context, site_instance, routing_id, | 316 new_contents->Init(browser_context, site_instance, routing_id, |
314 static_cast<const WebContentsImpl*>(base_web_contents)); | 317 static_cast<const WebContentsImpl*>(base_web_contents)); |
315 return new_contents; | 318 return new_contents; |
316 } | 319 } |
317 | 320 |
| 321 WebContents* WebContents::CreateGuest(BrowserContext* browser_context, |
| 322 const std::string& host_url, |
| 323 int guest_instance_id) { |
| 324 // The SiteInstance of a given guest is based on the fact that it's a guest |
| 325 // in addition to which platform application the guest belongs to, rather |
| 326 // than the URL that the guest is being navigated to. |
| 327 GURL guest_site( |
| 328 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str())); |
| 329 SiteInstance* guest_site_instance = |
| 330 SiteInstance::CreateForURL(browser_context, guest_site); |
| 331 WebContents* new_contents = WebContents::Create( |
| 332 browser_context, |
| 333 guest_site_instance, |
| 334 MSG_ROUTING_NONE, |
| 335 NULL); // base WebContents |
| 336 WebContentsImpl* new_contents_impl = |
| 337 static_cast<WebContentsImpl*>(new_contents); |
| 338 |
| 339 // This makes |new_contents| to have a guest role. |
| 340 // For more info, see comment above class BrowserPluginGuest. |
| 341 new_contents_impl->browser_plugin_guest_.reset( |
| 342 content::BrowserPluginGuest::Create( |
| 343 guest_instance_id, |
| 344 new_contents_impl, |
| 345 new_contents_impl->GetRenderViewHost())); |
| 346 return new_contents; |
| 347 } |
| 348 |
318 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { | 349 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { |
319 return rvh->GetDelegate()->GetAsWebContents(); | 350 return rvh->GetDelegate()->GetAsWebContents(); |
320 } | 351 } |
321 | 352 |
322 } | 353 } |
323 | 354 |
324 // WebContentsImpl ------------------------------------------------------------- | 355 // WebContentsImpl ------------------------------------------------------------- |
325 | 356 |
326 WebContentsImpl::WebContentsImpl( | 357 WebContentsImpl::WebContentsImpl( |
327 content::BrowserContext* browser_context, | 358 content::BrowserContext* browser_context, |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | 716 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
686 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 717 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
687 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | 718 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
688 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | 719 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
689 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | 720 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
690 OnSetSelectedColorInColorChooser) | 721 OnSetSelectedColorInColorChooser) |
691 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) | 722 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
692 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 723 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
693 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 724 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
694 OnRequestPpapiBrokerPermission) | 725 OnRequestPpapiBrokerPermission) |
| 726 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, |
| 727 OnBrowserPluginNavigateGuest) |
695 IPC_MESSAGE_UNHANDLED(handled = false) | 728 IPC_MESSAGE_UNHANDLED(handled = false) |
696 IPC_END_MESSAGE_MAP_EX() | 729 IPC_END_MESSAGE_MAP_EX() |
697 message_source_ = NULL; | 730 message_source_ = NULL; |
698 | 731 |
699 if (!message_is_ok) { | 732 if (!message_is_ok) { |
700 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 733 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
701 GetRenderProcessHost()->ReceivedBadMessage(); | 734 GetRenderProcessHost()->ReceivedBadMessage(); |
702 } | 735 } |
703 | 736 |
704 return handled; | 737 return handled; |
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 } | 2329 } |
2297 | 2330 |
2298 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, | 2331 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, |
2299 bool result) { | 2332 bool result) { |
2300 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); | 2333 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
2301 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), | 2334 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), |
2302 request_id, | 2335 request_id, |
2303 result)); | 2336 result)); |
2304 } | 2337 } |
2305 | 2338 |
| 2339 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id, |
| 2340 int64 frame_id, |
| 2341 const std::string& src, |
| 2342 const gfx::Size& size) { |
| 2343 // This is the first 'navigate' to a browser plugin, before WebContents has/is |
| 2344 // an 'Embedder'; subsequent navigate messages for this WebContents will |
| 2345 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this |
| 2346 // also means any message from browser plugin renderer prior to NavigateGuest |
| 2347 // which is not NavigateGuest will be ignored). Therefore |
| 2348 // |browser_plugin_embedder_| should not be set. |
| 2349 // For more info, see comment above classes BrowserPluginEmbedder and |
| 2350 // BrowserPluginGuest. |
| 2351 CHECK(!browser_plugin_embedder_.get()); |
| 2352 |
| 2353 browser_plugin_embedder_.reset( |
| 2354 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost())); |
| 2355 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(), |
| 2356 instance_id, |
| 2357 frame_id, |
| 2358 src, |
| 2359 size); |
| 2360 } |
| 2361 |
2306 // Notifies the RenderWidgetHost instance about the fact that the page is | 2362 // Notifies the RenderWidgetHost instance about the fact that the page is |
2307 // loading, or done loading and calls the base implementation. | 2363 // loading, or done loading and calls the base implementation. |
2308 void WebContentsImpl::SetIsLoading(bool is_loading, | 2364 void WebContentsImpl::SetIsLoading(bool is_loading, |
2309 LoadNotificationDetails* details) { | 2365 LoadNotificationDetails* details) { |
2310 if (is_loading == is_loading_) | 2366 if (is_loading == is_loading_) |
2311 return; | 2367 return; |
2312 | 2368 |
2313 if (!is_loading) { | 2369 if (!is_loading) { |
2314 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); | 2370 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
2315 load_state_host_.clear(); | 2371 load_state_host_.clear(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2452 | 2508 |
2453 void WebContentsImpl::NotifySwapped() { | 2509 void WebContentsImpl::NotifySwapped() { |
2454 // After sending out a swap notification, we need to send a disconnect | 2510 // After sending out a swap notification, we need to send a disconnect |
2455 // notification so that clients that pick up a pointer to |this| can NULL the | 2511 // notification so that clients that pick up a pointer to |this| can NULL the |
2456 // pointer. See Bug 1230284. | 2512 // pointer. See Bug 1230284. |
2457 notify_disconnection_ = true; | 2513 notify_disconnection_ = true; |
2458 content::NotificationService::current()->Notify( | 2514 content::NotificationService::current()->Notify( |
2459 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 2515 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
2460 content::Source<WebContents>(this), | 2516 content::Source<WebContents>(this), |
2461 content::NotificationService::NoDetails()); | 2517 content::NotificationService::NoDetails()); |
| 2518 |
| 2519 // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 2520 // gets swapped, so we don't reuse the same embedder next time a |
| 2521 // RenderViewHost is attached to this WebContents (for security concerns). |
| 2522 RemoveSwappedOutBrowserPluginEmbedder(); |
2462 } | 2523 } |
2463 | 2524 |
2464 void WebContentsImpl::NotifyConnected() { | 2525 void WebContentsImpl::NotifyConnected() { |
2465 notify_disconnection_ = true; | 2526 notify_disconnection_ = true; |
2466 content::NotificationService::current()->Notify( | 2527 content::NotificationService::current()->Notify( |
2467 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 2528 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
2468 content::Source<WebContents>(this), | 2529 content::Source<WebContents>(this), |
2469 content::NotificationService::NoDetails()); | 2530 content::NotificationService::NoDetails()); |
2470 } | 2531 } |
2471 | 2532 |
(...skipping 25 matching lines...) Expand all Loading... |
2497 WebContents* WebContentsImpl::GetAsWebContents() { | 2558 WebContents* WebContentsImpl::GetAsWebContents() { |
2498 return this; | 2559 return this; |
2499 } | 2560 } |
2500 | 2561 |
2501 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 2562 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
2502 if (delegate_) | 2563 if (delegate_) |
2503 return delegate_->GetRootWindowResizerRect(); | 2564 return delegate_->GetRootWindowResizerRect(); |
2504 return gfx::Rect(); | 2565 return gfx::Rect(); |
2505 } | 2566 } |
2506 | 2567 |
| 2568 void WebContentsImpl::RemoveSwappedOutBrowserPluginEmbedder() { |
| 2569 if (browser_plugin_embedder_.get()) |
| 2570 browser_plugin_embedder_.reset(); |
| 2571 } |
| 2572 |
2507 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 2573 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
2508 // Don't send notifications if we are just creating a swapped-out RVH for | 2574 // Don't send notifications if we are just creating a swapped-out RVH for |
2509 // the opener chain. These won't be used for view-source or WebUI, so it's | 2575 // the opener chain. These won't be used for view-source or WebUI, so it's |
2510 // ok to return early. | 2576 // ok to return early. |
2511 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2577 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
2512 return; | 2578 return; |
2513 | 2579 |
2514 content::NotificationService::current()->Notify( | 2580 content::NotificationService::current()->Notify( |
2515 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2581 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2516 content::Source<WebContents>(this), | 2582 content::Source<WebContents>(this), |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 old_browser_plugin_host()->embedder_render_process_host(); | 3351 old_browser_plugin_host()->embedder_render_process_host(); |
3286 *embedder_container_id = old_browser_plugin_host()->instance_id(); | 3352 *embedder_container_id = old_browser_plugin_host()->instance_id(); |
3287 int embedder_process_id = | 3353 int embedder_process_id = |
3288 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; | 3354 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
3289 if (embedder_process_id != -1) { | 3355 if (embedder_process_id != -1) { |
3290 *embedder_channel_name = | 3356 *embedder_channel_name = |
3291 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), | 3357 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
3292 embedder_process_id); | 3358 embedder_process_id); |
3293 } | 3359 } |
3294 } | 3360 } |
| 3361 |
| 3362 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { |
| 3363 return browser_plugin_guest_.get(); |
| 3364 } |
| 3365 |
| 3366 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { |
| 3367 return browser_plugin_embedder_.get(); |
| 3368 } |
OLD | NEW |