Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.cc

Issue 519533002: Initial PlzNavigate RDH-side logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 // TODO(clamy): Check if navigations are blocked and if so, return 579 // TODO(clamy): Check if navigations are blocked and if so, return
590 // immediately. 580 // immediately.
591 NavigationRequestInfo info(params); 581 NavigationRequestInfo info(params);
592 582
593 info.first_party_for_cookies = frame_tree_node_->IsMainFrame() ? 583 info.first_party_for_cookies = frame_tree_node_->IsMainFrame() ?
594 params.url : frame_tree_node_->frame_tree()->root()->current_url(); 584 params.url : frame_tree_node_->frame_tree()->root()->current_url();
595 info.is_main_frame = frame_tree_node_->IsMainFrame(); 585 info.is_main_frame = frame_tree_node_->IsMainFrame();
596 info.parent_is_main_frame = !frame_tree_node_->parent() ? 586 info.parent_is_main_frame = !frame_tree_node_->parent() ?
597 false : frame_tree_node_->parent()->IsMainFrame(); 587 false : frame_tree_node_->parent()->IsMainFrame();
598 588
589 NavigationControllerImpl& controller =
590 delegate_->GetControllerForRenderManager();
591 BrowserContext* browser_context = controller.GetBrowserContext();
592
599 // TODO(clamy): Check if the current RFH should be initialized (in case it has 593 // TODO(clamy): Check if the current RFH should be initialized (in case it has
600 // crashed) not to display a sad tab while navigating. 594 // crashed) not to display a sad tab while navigating.
601 // TODO(clamy): Spawn a speculative renderer process if we do not have one to 595 // TODO(clamy): Spawn a speculative renderer process if we do not have one to
602 // use for the navigation. 596 // use for the navigation.
603 597
604 // If there is an ongoing request it must be canceled.
605 if (navigation_request_.get())
606 navigation_request_->CancelNavigation();
607
608 navigation_request_.reset(new NavigationRequest( 598 navigation_request_.reset(new NavigationRequest(
609 info, frame_tree_node_->frame_tree_node_id())); 599 info, browser_context, frame_tree_node_));
610 navigation_request_->BeginNavigation(params.request_body); 600 navigation_request_->BeginNavigation(params.request_body);
611 } 601 }
612 602
613 // PlzNavigate 603 // PlzNavigate
614 void RenderFrameHostManager::CommitNavigation( 604 void RenderFrameHostManager::CommitNavigation(const GURL& url,
615 const NavigationBeforeCommitInfo& info) { 605 ResourceResponse* response,
606 scoped_ptr<StreamHandle> body) {
616 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 607 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
617 switches::kEnableBrowserSideNavigation)); 608 switches::kEnableBrowserSideNavigation));
618 DCHECK(navigation_request_.get());
619 // Ignores navigation commits if the request ID doesn't match the current
620 // active request.
621 if (navigation_request_->navigation_request_id() !=
622 info.navigation_request_id) {
623 return;
624 }
625 609
626 // Pick the right RenderFrameHost to commit the navigation. 610 // Pick the right RenderFrameHost to commit the navigation.
627 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 611 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
628 // TODO(clamy): Replace the default values by the right ones. This may require 612 // TODO(clamy): Replace the default values by the right ones. This may require
629 // some storing in RequestNavigation. 613 // some storing in RequestNavigation.
630 SiteInstance* new_instance = GetSiteInstanceForNavigation( 614 SiteInstance* new_instance = GetSiteInstanceForNavigation(
631 info.navigation_url, 615 url,
632 NULL, 616 NULL,
633 navigation_request_->info().navigation_params.transition_type, 617 navigation_request_->info().navigation_params.transition_type,
634 false, 618 false,
635 false); 619 false);
636 DCHECK(!pending_render_frame_host_.get()); 620 DCHECK(!pending_render_frame_host_.get());
637 621
638 // TODO(clamy): Update how pending WebUI objects are handled. 622 // TODO(clamy): Update how pending WebUI objects are handled.
639 if (current_instance != new_instance) { 623 if (current_instance != new_instance) {
640 CreateRenderFrameHostForNewSiteInstance( 624 CreateRenderFrameHostForNewSiteInstance(
641 current_instance, new_instance, frame_tree_node_->IsMainFrame()); 625 current_instance, new_instance, frame_tree_node_->IsMainFrame());
(...skipping 14 matching lines...) Expand all
656 render_frame_host_->GetSiteInstance()); 640 render_frame_host_->GetSiteInstance());
657 if (!InitRenderView(render_frame_host_->render_view_host(), 641 if (!InitRenderView(render_frame_host_->render_view_host(),
658 opener_route_id, 642 opener_route_id,
659 MSG_ROUTING_NONE, 643 MSG_ROUTING_NONE,
660 frame_tree_node_->IsMainFrame())) { 644 frame_tree_node_->IsMainFrame())) {
661 return; 645 return;
662 } 646 }
663 } 647 }
664 648
665 frame_tree_node_->navigator()->CommitNavigation( 649 frame_tree_node_->navigator()->CommitNavigation(
666 render_frame_host_.get(), info); 650 render_frame_host_.get(), url, response, body.Pass());
667 } 651 }
668 652
669 void RenderFrameHostManager::Observe( 653 void RenderFrameHostManager::Observe(
670 int type, 654 int type,
671 const NotificationSource& source, 655 const NotificationSource& source,
672 const NotificationDetails& details) { 656 const NotificationDetails& details) {
673 switch (type) { 657 switch (type) {
674 case NOTIFICATION_RENDERER_PROCESS_CLOSED: 658 case NOTIFICATION_RENDERER_PROCESS_CLOSED:
675 case NOTIFICATION_RENDERER_PROCESS_CLOSING: 659 case NOTIFICATION_RENDERER_PROCESS_CLOSING:
676 RendererProcessClosing( 660 RendererProcessClosing(
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 1701 void RenderFrameHostManager::DeleteRenderFrameProxyHost(
1718 SiteInstance* instance) { 1702 SiteInstance* instance) {
1719 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 1703 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId());
1720 if (iter != proxy_hosts_.end()) { 1704 if (iter != proxy_hosts_.end()) {
1721 delete iter->second; 1705 delete iter->second;
1722 proxy_hosts_.erase(iter); 1706 proxy_hosts_.erase(iter);
1723 } 1707 }
1724 } 1708 }
1725 1709
1726 } // namespace content 1710 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698