Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 14 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| 15 #include "content/browser/frame_host/cross_site_transferring_request.h" | 15 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 16 #include "content/browser/frame_host/debug_urls.h" | 16 #include "content/browser/frame_host/debug_urls.h" |
| 17 #include "content/browser/frame_host/interstitial_page_impl.h" | 17 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 18 #include "content/browser/frame_host/navigation_before_commit_info.h" | |
| 19 #include "content/browser/frame_host/navigation_controller_impl.h" | 18 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 20 #include "content/browser/frame_host/navigation_entry_impl.h" | 19 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 21 #include "content/browser/frame_host/navigation_request.h" | 20 #include "content/browser/frame_host/navigation_request.h" |
| 22 #include "content/browser/frame_host/navigation_request_info.h" | 21 #include "content/browser/frame_host/navigation_request_info.h" |
| 23 #include "content/browser/frame_host/navigator.h" | 22 #include "content/browser/frame_host/navigator.h" |
| 24 #include "content/browser/frame_host/render_frame_host_factory.h" | 23 #include "content/browser/frame_host/render_frame_host_factory.h" |
| 25 #include "content/browser/frame_host/render_frame_host_impl.h" | 24 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 26 #include "content/browser/frame_host/render_frame_proxy_host.h" | 25 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 27 #include "content/browser/renderer_host/render_process_host_impl.h" | 26 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 28 #include "content/browser/renderer_host/render_view_host_factory.h" | 27 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 29 #include "content/browser/renderer_host/render_view_host_impl.h" | 28 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 30 #include "content/browser/site_instance_impl.h" | 29 #include "content/browser/site_instance_impl.h" |
| 31 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 30 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 32 #include "content/browser/webui/web_ui_impl.h" | 31 #include "content/browser/webui/web_ui_impl.h" |
| 33 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
| 34 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
| 35 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 37 #include "content/public/browser/render_widget_host_iterator.h" | 36 #include "content/public/browser/render_widget_host_iterator.h" |
| 38 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 38 #include "content/public/browser/stream_handle.h" | |
| 39 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/browser/web_ui_controller.h" | 40 #include "content/public/browser/web_ui_controller.h" |
| 41 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
| 42 #include "content/public/common/referrer.h" | 42 #include "content/public/common/referrer.h" |
| 43 #include "content/public/common/url_constants.h" | 43 #include "content/public/common/url_constants.h" |
| 44 #include "net/base/load_flags.h" | 44 #include "net/base/load_flags.h" |
| 45 | 45 |
| 46 namespace content { | 46 namespace content { |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 99 |
| 100 RenderFrameHostManager::~RenderFrameHostManager() { | 100 RenderFrameHostManager::~RenderFrameHostManager() { |
| 101 if (pending_render_frame_host_) | 101 if (pending_render_frame_host_) |
| 102 CancelPending(); | 102 CancelPending(); |
| 103 | 103 |
| 104 // We should always have a current RenderFrameHost except in some tests. | 104 // We should always have a current RenderFrameHost except in some tests. |
| 105 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); | 105 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); |
| 106 | 106 |
| 107 // Delete any swapped out RenderFrameHosts. | 107 // Delete any swapped out RenderFrameHosts. |
| 108 STLDeleteValues(&proxy_hosts_); | 108 STLDeleteValues(&proxy_hosts_); |
| 109 | |
| 110 // PlzNavigate | |
| 111 // There is an active navigation request for this RFHM so it needs to be | |
| 112 // canceled. | |
| 113 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 114 switches::kEnableBrowserSideNavigation)) { | |
| 115 if (navigation_request_.get()) | |
| 116 navigation_request_->CancelNavigation(); | |
| 117 } | |
| 118 | |
| 119 } | 109 } |
| 120 | 110 |
| 121 void RenderFrameHostManager::Init(BrowserContext* browser_context, | 111 void RenderFrameHostManager::Init(BrowserContext* browser_context, |
| 122 SiteInstance* site_instance, | 112 SiteInstance* site_instance, |
| 123 int view_routing_id, | 113 int view_routing_id, |
| 124 int frame_routing_id) { | 114 int frame_routing_id) { |
| 125 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It | 115 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It |
| 126 // is important to immediately give this SiteInstance to a RenderViewHost so | 116 // is important to immediately give this SiteInstance to a RenderViewHost so |
| 127 // that the SiteInstance is ref counted. | 117 // that the SiteInstance is ref counted. |
| 128 if (!site_instance) | 118 if (!site_instance) |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 // TODO(clamy): Check if navigations are blocked and if so, return | 578 // TODO(clamy): Check if navigations are blocked and if so, return |
| 589 // immediately. | 579 // immediately. |
| 590 NavigationRequestInfo info(params); | 580 NavigationRequestInfo info(params); |
| 591 | 581 |
| 592 info.first_party_for_cookies = frame_tree_node_->IsMainFrame() ? | 582 info.first_party_for_cookies = frame_tree_node_->IsMainFrame() ? |
| 593 params.url : frame_tree_node_->frame_tree()->root()->current_url(); | 583 params.url : frame_tree_node_->frame_tree()->root()->current_url(); |
| 594 info.is_main_frame = frame_tree_node_->IsMainFrame(); | 584 info.is_main_frame = frame_tree_node_->IsMainFrame(); |
| 595 info.parent_is_main_frame = !frame_tree_node_->parent() ? | 585 info.parent_is_main_frame = !frame_tree_node_->parent() ? |
| 596 false : frame_tree_node_->parent()->IsMainFrame(); | 586 false : frame_tree_node_->parent()->IsMainFrame(); |
| 597 | 587 |
| 588 NavigationControllerImpl& controller = | |
| 589 delegate_->GetControllerForRenderManager(); | |
|
nasko
2014/09/24 21:15:34
nit: In general with out-of-process iframes we nee
davidben
2014/10/03 16:27:52
Acknowledged.
| |
| 590 BrowserContext* browser_context = controller.GetBrowserContext(); | |
| 591 | |
| 598 // TODO(clamy): Check if the current RFH should be initialized (in case it has | 592 // TODO(clamy): Check if the current RFH should be initialized (in case it has |
| 599 // crashed) not to display a sad tab while navigating. | 593 // crashed) not to display a sad tab while navigating. |
| 600 // TODO(clamy): Spawn a speculative renderer process if we do not have one to | 594 // TODO(clamy): Spawn a speculative renderer process if we do not have one to |
| 601 // use for the navigation. | 595 // use for the navigation. |
| 602 | 596 |
| 603 // If there is an ongoing request it must be canceled. | |
| 604 if (navigation_request_.get()) | |
| 605 navigation_request_->CancelNavigation(); | |
| 606 | |
| 607 navigation_request_.reset(new NavigationRequest( | 597 navigation_request_.reset(new NavigationRequest( |
| 608 info, frame_tree_node_->frame_tree_node_id())); | 598 info, browser_context, frame_tree_node_)); |
| 609 navigation_request_->BeginNavigation(params.request_body); | 599 navigation_request_->BeginNavigation(params.request_body); |
| 610 } | 600 } |
| 611 | 601 |
| 612 // PlzNavigate | 602 // PlzNavigate |
| 613 void RenderFrameHostManager::CommitNavigation( | 603 void RenderFrameHostManager::CommitNavigation(const GURL& url, |
| 614 const NavigationBeforeCommitInfo& info) { | 604 ResourceResponse* response, |
| 605 scoped_ptr<StreamHandle> body) { | |
| 615 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 606 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 616 switches::kEnableBrowserSideNavigation)); | 607 switches::kEnableBrowserSideNavigation)); |
| 617 DCHECK(navigation_request_.get()); | |
| 618 // Ignores navigation commits if the request ID doesn't match the current | |
| 619 // active request. | |
| 620 if (navigation_request_->navigation_request_id() != | |
| 621 info.navigation_request_id) { | |
| 622 return; | |
| 623 } | |
| 624 | 608 |
| 625 // Pick the right RenderFrameHost to commit the navigation. | 609 // Pick the right RenderFrameHost to commit the navigation. |
| 626 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 610 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
| 627 // TODO(clamy): Replace the default values by the right ones. This may require | 611 // TODO(clamy): Replace the default values by the right ones. This may require |
| 628 // some storing in RequestNavigation. | 612 // some storing in RequestNavigation. |
| 629 SiteInstance* new_instance = GetSiteInstanceForNavigation( | 613 SiteInstance* new_instance = GetSiteInstanceForNavigation( |
| 630 info.navigation_url, | 614 url, |
| 631 NULL, | 615 NULL, |
| 632 navigation_request_->info().navigation_params.transition_type, | 616 navigation_request_->info().navigation_params.transition_type, |
| 633 false, | 617 false, |
| 634 false); | 618 false); |
| 635 DCHECK(!pending_render_frame_host_.get()); | 619 DCHECK(!pending_render_frame_host_.get()); |
| 636 | 620 |
| 637 // TODO(clamy): Update how pending WebUI objects are handled. | 621 // TODO(clamy): Update how pending WebUI objects are handled. |
| 638 if (current_instance != new_instance) { | 622 if (current_instance != new_instance) { |
| 639 CreateRenderFrameHostForNewSiteInstance( | 623 CreateRenderFrameHostForNewSiteInstance( |
| 640 current_instance, new_instance, frame_tree_node_->IsMainFrame()); | 624 current_instance, new_instance, frame_tree_node_->IsMainFrame()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 655 render_frame_host_->GetSiteInstance()); | 639 render_frame_host_->GetSiteInstance()); |
| 656 if (!InitRenderView(render_frame_host_->render_view_host(), | 640 if (!InitRenderView(render_frame_host_->render_view_host(), |
| 657 opener_route_id, | 641 opener_route_id, |
| 658 MSG_ROUTING_NONE, | 642 MSG_ROUTING_NONE, |
| 659 frame_tree_node_->IsMainFrame())) { | 643 frame_tree_node_->IsMainFrame())) { |
| 660 return; | 644 return; |
| 661 } | 645 } |
| 662 } | 646 } |
| 663 | 647 |
| 664 frame_tree_node_->navigator()->CommitNavigation( | 648 frame_tree_node_->navigator()->CommitNavigation( |
| 665 render_frame_host_.get(), info); | 649 render_frame_host_.get(), url, response, body.Pass()); |
| 666 } | 650 } |
| 667 | 651 |
| 668 void RenderFrameHostManager::Observe( | 652 void RenderFrameHostManager::Observe( |
| 669 int type, | 653 int type, |
| 670 const NotificationSource& source, | 654 const NotificationSource& source, |
| 671 const NotificationDetails& details) { | 655 const NotificationDetails& details) { |
| 672 switch (type) { | 656 switch (type) { |
| 673 case NOTIFICATION_RENDERER_PROCESS_CLOSED: | 657 case NOTIFICATION_RENDERER_PROCESS_CLOSED: |
| 674 case NOTIFICATION_RENDERER_PROCESS_CLOSING: | 658 case NOTIFICATION_RENDERER_PROCESS_CLOSING: |
| 675 RendererProcessClosing( | 659 RendererProcessClosing( |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 1696 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
| 1713 SiteInstance* instance) { | 1697 SiteInstance* instance) { |
| 1714 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 1698 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
| 1715 if (iter != proxy_hosts_.end()) { | 1699 if (iter != proxy_hosts_.end()) { |
| 1716 delete iter->second; | 1700 delete iter->second; |
| 1717 proxy_hosts_.erase(iter); | 1701 proxy_hosts_.erase(iter); |
| 1718 } | 1702 } |
| 1719 } | 1703 } |
| 1720 | 1704 |
| 1721 } // namespace content | 1705 } // namespace content |
| OLD | NEW |