| 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" | |
| 20 #include "content/browser/browser_plugin/old/old_browser_plugin_host.h" | 18 #include "content/browser/browser_plugin/old/old_browser_plugin_host.h" |
| 21 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
| 22 #include "content/browser/debugger/devtools_manager_impl.h" | 20 #include "content/browser/debugger/devtools_manager_impl.h" |
| 23 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 21 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 22 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 25 #include "content/browser/download/download_stats.h" | 23 #include "content/browser/download/download_stats.h" |
| 26 #include "content/browser/download/mhtml_generation_manager.h" | 24 #include "content/browser/download/mhtml_generation_manager.h" |
| 27 #include "content/browser/download/save_package.h" | 25 #include "content/browser/download/save_package.h" |
| 28 #include "content/browser/gpu/gpu_data_manager_impl.h" | 26 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 29 #include "content/browser/gpu/gpu_process_host.h" | 27 #include "content/browser/gpu/gpu_process_host.h" |
| 30 #include "content/browser/host_zoom_map_impl.h" | 28 #include "content/browser/host_zoom_map_impl.h" |
| 31 #include "content/browser/intents/web_intents_dispatcher_impl.h" | 29 #include "content/browser/intents/web_intents_dispatcher_impl.h" |
| 32 #include "content/browser/renderer_host/render_process_host_impl.h" | 30 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 33 #include "content/browser/renderer_host/render_view_host_impl.h" | 31 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 34 #include "content/browser/renderer_host/render_widget_host_impl.h" | 32 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 35 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 33 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 36 #include "content/browser/site_instance_impl.h" | 34 #include "content/browser/site_instance_impl.h" |
| 37 #include "content/browser/web_contents/interstitial_page_impl.h" | 35 #include "content/browser/web_contents/interstitial_page_impl.h" |
| 38 #include "content/browser/web_contents/navigation_entry_impl.h" | 36 #include "content/browser/web_contents/navigation_entry_impl.h" |
| 39 #include "content/browser/webui/web_ui_impl.h" | 37 #include "content/browser/webui/web_ui_impl.h" |
| 40 #include "content/common/browser_plugin_messages.h" | |
| 41 #include "content/common/intents_messages.h" | 38 #include "content/common/intents_messages.h" |
| 42 #include "content/common/ssl_status_serialization.h" | 39 #include "content/common/ssl_status_serialization.h" |
| 43 #include "content/common/view_messages.h" | 40 #include "content/common/view_messages.h" |
| 44 #include "content/port/browser/render_view_host_delegate_view.h" | 41 #include "content/port/browser/render_view_host_delegate_view.h" |
| 45 #include "content/port/browser/render_widget_host_view_port.h" | 42 #include "content/port/browser/render_widget_host_view_port.h" |
| 46 #include "content/public/browser/browser_context.h" | 43 #include "content/public/browser/browser_context.h" |
| 47 #include "content/public/browser/color_chooser.h" | 44 #include "content/public/browser/color_chooser.h" |
| 48 #include "content/public/browser/content_browser_client.h" | 45 #include "content/public/browser/content_browser_client.h" |
| 49 #include "content/public/browser/devtools_agent_host_registry.h" | 46 #include "content/public/browser/devtools_agent_host_registry.h" |
| 50 #include "content/public/browser/download_manager.h" | 47 #include "content/public/browser/download_manager.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 int routing_id, | 416 int routing_id, |
| 420 const WebContentsImpl* base_web_contents, | 417 const WebContentsImpl* base_web_contents, |
| 421 WebContentsImpl* opener) { | 418 WebContentsImpl* opener) { |
| 422 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener); | 419 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener); |
| 423 | 420 |
| 424 new_contents->Init(browser_context, site_instance, routing_id, | 421 new_contents->Init(browser_context, site_instance, routing_id, |
| 425 static_cast<const WebContentsImpl*>(base_web_contents)); | 422 static_cast<const WebContentsImpl*>(base_web_contents)); |
| 426 return new_contents; | 423 return new_contents; |
| 427 } | 424 } |
| 428 | 425 |
| 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| act as a guest. | |
| 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 | |
| 457 WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, | 426 WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, |
| 458 const GURL& url) { | 427 const GURL& url) { |
| 459 WebPreferences prefs; | 428 WebPreferences prefs; |
| 460 | 429 |
| 461 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 430 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 462 | 431 |
| 463 prefs.developer_extras_enabled = true; | 432 prefs.developer_extras_enabled = true; |
| 464 prefs.javascript_enabled = | 433 prefs.javascript_enabled = |
| 465 !command_line.HasSwitch(switches::kDisableJavaScript); | 434 !command_line.HasSwitch(switches::kDisableJavaScript); |
| 466 prefs.web_security_enabled = | 435 prefs.web_security_enabled = |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | 692 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
| 724 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 693 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
| 725 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | 694 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 726 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | 695 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
| 727 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | 696 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
| 728 OnSetSelectedColorInColorChooser) | 697 OnSetSelectedColorInColorChooser) |
| 729 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) | 698 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
| 730 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 699 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
| 731 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 700 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 732 OnRequestPpapiBrokerPermission) | 701 OnRequestPpapiBrokerPermission) |
| 733 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, | |
| 734 OnBrowserPluginNavigateGuest) | |
| 735 IPC_MESSAGE_UNHANDLED(handled = false) | 702 IPC_MESSAGE_UNHANDLED(handled = false) |
| 736 IPC_END_MESSAGE_MAP_EX() | 703 IPC_END_MESSAGE_MAP_EX() |
| 737 message_source_ = NULL; | 704 message_source_ = NULL; |
| 738 | 705 |
| 739 if (!message_is_ok) { | 706 if (!message_is_ok) { |
| 740 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 707 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
| 741 GetRenderProcessHost()->ReceivedBadMessage(); | 708 GetRenderProcessHost()->ReceivedBadMessage(); |
| 742 } | 709 } |
| 743 | 710 |
| 744 return handled; | 711 return handled; |
| (...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2336 } | 2303 } |
| 2337 | 2304 |
| 2338 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, | 2305 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, |
| 2339 bool result) { | 2306 bool result) { |
| 2340 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); | 2307 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
| 2341 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), | 2308 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), |
| 2342 request_id, | 2309 request_id, |
| 2343 result)); | 2310 result)); |
| 2344 } | 2311 } |
| 2345 | 2312 |
| 2346 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id, | |
| 2347 int64 frame_id, | |
| 2348 const std::string& src, | |
| 2349 const gfx::Size& size) { | |
| 2350 // This is the first 'navigate' to a browser plugin, before WebContents has/is | |
| 2351 // an 'Embedder'; subsequent navigate messages for this WebContents will | |
| 2352 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this | |
| 2353 // also means any message from browser plugin renderer prior to NavigateGuest | |
| 2354 // which is not NavigateGuest will be ignored). Therefore | |
| 2355 // |browser_plugin_embedder_| should not be set. | |
| 2356 // For more info, see comment above classes BrowserPluginEmbedder and | |
| 2357 // BrowserPluginGuest. | |
| 2358 CHECK(!browser_plugin_embedder_.get()); | |
| 2359 | |
| 2360 browser_plugin_embedder_.reset( | |
| 2361 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost())); | |
| 2362 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(), | |
| 2363 instance_id, | |
| 2364 frame_id, | |
| 2365 src, | |
| 2366 size); | |
| 2367 } | |
| 2368 | |
| 2369 // Notifies the RenderWidgetHost instance about the fact that the page is | 2313 // Notifies the RenderWidgetHost instance about the fact that the page is |
| 2370 // loading, or done loading and calls the base implementation. | 2314 // loading, or done loading and calls the base implementation. |
| 2371 void WebContentsImpl::SetIsLoading(bool is_loading, | 2315 void WebContentsImpl::SetIsLoading(bool is_loading, |
| 2372 LoadNotificationDetails* details) { | 2316 LoadNotificationDetails* details) { |
| 2373 if (is_loading == is_loading_) | 2317 if (is_loading == is_loading_) |
| 2374 return; | 2318 return; |
| 2375 | 2319 |
| 2376 if (!is_loading) { | 2320 if (!is_loading) { |
| 2377 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); | 2321 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
| 2378 load_state_host_.clear(); | 2322 load_state_host_.clear(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2515 | 2459 |
| 2516 void WebContentsImpl::NotifySwapped() { | 2460 void WebContentsImpl::NotifySwapped() { |
| 2517 // After sending out a swap notification, we need to send a disconnect | 2461 // After sending out a swap notification, we need to send a disconnect |
| 2518 // notification so that clients that pick up a pointer to |this| can NULL the | 2462 // notification so that clients that pick up a pointer to |this| can NULL the |
| 2519 // pointer. See Bug 1230284. | 2463 // pointer. See Bug 1230284. |
| 2520 notify_disconnection_ = true; | 2464 notify_disconnection_ = true; |
| 2521 content::NotificationService::current()->Notify( | 2465 content::NotificationService::current()->Notify( |
| 2522 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 2466 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 2523 content::Source<WebContents>(this), | 2467 content::Source<WebContents>(this), |
| 2524 content::NotificationService::NoDetails()); | 2468 content::NotificationService::NoDetails()); |
| 2525 | |
| 2526 // Ensure that the associated embedder gets cleared after a RenderViewHost | |
| 2527 // gets swapped, so we don't reuse the same embedder next time a | |
| 2528 // RenderViewHost is attached to this WebContents. | |
| 2529 RemoveBrowserPluginEmbedder(); | |
| 2530 } | 2469 } |
| 2531 | 2470 |
| 2532 void WebContentsImpl::NotifyConnected() { | 2471 void WebContentsImpl::NotifyConnected() { |
| 2533 notify_disconnection_ = true; | 2472 notify_disconnection_ = true; |
| 2534 content::NotificationService::current()->Notify( | 2473 content::NotificationService::current()->Notify( |
| 2535 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 2474 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 2536 content::Source<WebContents>(this), | 2475 content::Source<WebContents>(this), |
| 2537 content::NotificationService::NoDetails()); | 2476 content::NotificationService::NoDetails()); |
| 2538 } | 2477 } |
| 2539 | 2478 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2565 WebContents* WebContentsImpl::GetAsWebContents() { | 2504 WebContents* WebContentsImpl::GetAsWebContents() { |
| 2566 return this; | 2505 return this; |
| 2567 } | 2506 } |
| 2568 | 2507 |
| 2569 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 2508 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
| 2570 if (delegate_) | 2509 if (delegate_) |
| 2571 return delegate_->GetRootWindowResizerRect(); | 2510 return delegate_->GetRootWindowResizerRect(); |
| 2572 return gfx::Rect(); | 2511 return gfx::Rect(); |
| 2573 } | 2512 } |
| 2574 | 2513 |
| 2575 void WebContentsImpl::RemoveBrowserPluginEmbedder() { | |
| 2576 if (browser_plugin_embedder_.get()) | |
| 2577 browser_plugin_embedder_.reset(); | |
| 2578 } | |
| 2579 | |
| 2580 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 2514 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
| 2581 // Don't send notifications if we are just creating a swapped-out RVH for | 2515 // Don't send notifications if we are just creating a swapped-out RVH for |
| 2582 // the opener chain. These won't be used for view-source or WebUI, so it's | 2516 // the opener chain. These won't be used for view-source or WebUI, so it's |
| 2583 // ok to return early. | 2517 // ok to return early. |
| 2584 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2518 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
| 2585 return; | 2519 return; |
| 2586 | 2520 |
| 2587 content::NotificationService::current()->Notify( | 2521 content::NotificationService::current()->Notify( |
| 2588 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2522 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 2589 content::Source<WebContents>(this), | 2523 content::Source<WebContents>(this), |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3358 old_browser_plugin_host()->embedder_render_process_host(); | 3292 old_browser_plugin_host()->embedder_render_process_host(); |
| 3359 *embedder_container_id = old_browser_plugin_host()->instance_id(); | 3293 *embedder_container_id = old_browser_plugin_host()->instance_id(); |
| 3360 int embedder_process_id = | 3294 int embedder_process_id = |
| 3361 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; | 3295 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
| 3362 if (embedder_process_id != -1) { | 3296 if (embedder_process_id != -1) { |
| 3363 *embedder_channel_name = | 3297 *embedder_channel_name = |
| 3364 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), | 3298 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
| 3365 embedder_process_id); | 3299 embedder_process_id); |
| 3366 } | 3300 } |
| 3367 } | 3301 } |
| 3368 | |
| 3369 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { | |
| 3370 return browser_plugin_guest_.get(); | |
| 3371 } | |
| 3372 | |
| 3373 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { | |
| 3374 return browser_plugin_embedder_.get(); | |
| 3375 } | |
| OLD | NEW |