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

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

Issue 615633005: PlzNavigate: Move the navigation logic to NavigatorImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@commit-nav
Patch Set: Addressed comments + moved unittests Created 6 years, 2 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" 18 #include "content/browser/frame_host/navigation_before_commit_info.h"
19 #include "content/browser/frame_host/navigation_controller_impl.h" 19 #include "content/browser/frame_host/navigation_controller_impl.h"
20 #include "content/browser/frame_host/navigation_entry_impl.h" 20 #include "content/browser/frame_host/navigation_entry_impl.h"
21 #include "content/browser/frame_host/navigation_request.h"
22 #include "content/browser/frame_host/navigation_request_info.h"
23 #include "content/browser/frame_host/navigator.h" 21 #include "content/browser/frame_host/navigator.h"
24 #include "content/browser/frame_host/render_frame_host_factory.h" 22 #include "content/browser/frame_host/render_frame_host_factory.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 23 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/browser/frame_host/render_frame_proxy_host.h" 24 #include "content/browser/frame_host/render_frame_proxy_host.h"
27 #include "content/browser/renderer_host/render_process_host_impl.h" 25 #include "content/browser/renderer_host/render_process_host_impl.h"
28 #include "content/browser/renderer_host/render_view_host_factory.h" 26 #include "content/browser/renderer_host/render_view_host_factory.h"
29 #include "content/browser/renderer_host/render_view_host_impl.h" 27 #include "content/browser/renderer_host/render_view_host_impl.h"
30 #include "content/browser/site_instance_impl.h" 28 #include "content/browser/site_instance_impl.h"
31 #include "content/browser/webui/web_ui_controller_factory_registry.h" 29 #include "content/browser/webui/web_ui_controller_factory_registry.h"
32 #include "content/browser/webui/web_ui_impl.h" 30 #include "content/browser/webui/web_ui_impl.h"
33 #include "content/common/navigation_params.h" 31 #include "content/common/frame_messages.h"
34 #include "content/common/view_messages.h" 32 #include "content/common/view_messages.h"
35 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
36 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_types.h" 35 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/render_widget_host_iterator.h" 36 #include "content/public/browser/render_widget_host_iterator.h"
39 #include "content/public/browser/render_widget_host_view.h" 37 #include "content/public/browser/render_widget_host_view.h"
40 #include "content/public/browser/user_metrics.h" 38 #include "content/public/browser/user_metrics.h"
41 #include "content/public/browser/web_ui_controller.h" 39 #include "content/public/browser/web_ui_controller.h"
42 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
43 #include "content/public/common/referrer.h" 41 #include "content/public/common/referrer.h"
44 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
45 #include "net/base/load_flags.h"
46 43
47 namespace content { 44 namespace content {
48 45
49 // PlzNavigate
50 // Returns the net load flags to use based on the navigation type.
51 // TODO(clamy): unify the code with what is happening on the renderer side.
52 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) {
53 int load_flags = net::LOAD_NORMAL;
54 switch (navigation_type) {
55 case FrameMsg_Navigate_Type::RELOAD:
56 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
57 load_flags |= net::LOAD_VALIDATE_CACHE;
58 break;
59 case FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE:
60 load_flags |= net::LOAD_BYPASS_CACHE;
61 break;
62 case FrameMsg_Navigate_Type::RESTORE:
63 load_flags |= net::LOAD_PREFERRING_CACHE;
64 break;
65 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
66 load_flags |= net::LOAD_ONLY_FROM_CACHE;
67 break;
68 case FrameMsg_Navigate_Type::NORMAL:
69 default:
70 break;
71 }
72 return load_flags;
73 }
74
75 // PlzNavigate
76 // Generates a default FrameHostMsg_BeginNavigation_Params to be used when there
77 // is no live renderer.
78 FrameHostMsg_BeginNavigation_Params MakeDefaultBeginNavigation(
79 const RequestNavigationParams& request_params,
80 FrameMsg_Navigate_Type::Value navigation_type) {
81 FrameHostMsg_BeginNavigation_Params begin_navigation_params;
82 begin_navigation_params.method = request_params.is_post ? "POST" : "GET";
83 begin_navigation_params.load_flags =
84 LoadFlagFromNavigationType(navigation_type);
85
86 // TODO(clamy): Post data from the browser should be put in the request body.
87 // Headers should be filled in as well.
88
89 begin_navigation_params.has_user_gesture = false;
90 return begin_navigation_params;
91 }
92
93 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { 46 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) {
94 node->render_manager()->pending_delete_hosts_.clear(); 47 node->render_manager()->pending_delete_hosts_.clear();
95 return true; 48 return true;
96 } 49 }
97 50
98 RenderFrameHostManager::RenderFrameHostManager( 51 RenderFrameHostManager::RenderFrameHostManager(
99 FrameTreeNode* frame_tree_node, 52 FrameTreeNode* frame_tree_node,
100 RenderFrameHostDelegate* render_frame_delegate, 53 RenderFrameHostDelegate* render_frame_delegate,
101 RenderViewHostDelegate* render_view_delegate, 54 RenderViewHostDelegate* render_view_delegate,
102 RenderWidgetHostDelegate* render_widget_delegate, 55 RenderWidgetHostDelegate* render_widget_delegate,
(...skipping 11 matching lines...) Expand all
114 67
115 RenderFrameHostManager::~RenderFrameHostManager() { 68 RenderFrameHostManager::~RenderFrameHostManager() {
116 if (pending_render_frame_host_) 69 if (pending_render_frame_host_)
117 CancelPending(); 70 CancelPending();
118 71
119 // We should always have a current RenderFrameHost except in some tests. 72 // We should always have a current RenderFrameHost except in some tests.
120 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); 73 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>());
121 74
122 // Delete any swapped out RenderFrameHosts. 75 // Delete any swapped out RenderFrameHosts.
123 STLDeleteValues(&proxy_hosts_); 76 STLDeleteValues(&proxy_hosts_);
124
125 // PlzNavigate
126 // There is an active navigation request for this RFHM so it needs to be
127 // canceled.
128 if (CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kEnableBrowserSideNavigation)) {
130 if (navigation_request_.get())
131 navigation_request_->CancelNavigation();
132 }
133
134 } 77 }
135 78
136 void RenderFrameHostManager::Init(BrowserContext* browser_context, 79 void RenderFrameHostManager::Init(BrowserContext* browser_context,
137 SiteInstance* site_instance, 80 SiteInstance* site_instance,
138 int view_routing_id, 81 int view_routing_id,
139 int frame_routing_id) { 82 int frame_routing_id) {
140 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It 83 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It
141 // is important to immediately give this SiteInstance to a RenderViewHost so 84 // is important to immediately give this SiteInstance to a RenderViewHost so
142 // that the SiteInstance is ref counted. 85 // that the SiteInstance is ref counted.
143 if (!site_instance) 86 if (!site_instance)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ->render_manager() 129 ->render_manager()
187 ->current_frame_host() 130 ->current_frame_host()
188 ->GetSiteInstance() 131 ->GetSiteInstance()
189 ->GetId()); 132 ->GetId());
190 if (iter == proxy_hosts_.end()) 133 if (iter == proxy_hosts_.end())
191 return NULL; 134 return NULL;
192 135
193 return iter->second; 136 return iter->second;
194 } 137 }
195 138
196 void RenderFrameHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) { 139 void RenderFrameHostManager::SetPendingWebUI(const GURL& url,
140 int bindings) {
197 pending_web_ui_.reset( 141 pending_web_ui_.reset(
198 delegate_->CreateWebUIForRenderManager(entry.GetURL())); 142 delegate_->CreateWebUIForRenderManager(url));
199 pending_and_current_web_ui_.reset(); 143 pending_and_current_web_ui_.reset();
200 144
201 // If we have assigned (zero or more) bindings to this NavigationEntry in the 145 // If we have assigned (zero or more) bindings to this NavigationEntry in the
202 // past, make sure we're not granting it different bindings than it had 146 // past, make sure we're not granting it different bindings than it had
203 // before. If so, note it and don't give it any bindings, to avoid a 147 // before. If so, note it and don't give it any bindings, to avoid a
204 // potential privilege escalation. 148 // potential privilege escalation.
205 if (pending_web_ui_.get() && 149 if (pending_web_ui_.get() &&
206 entry.bindings() != NavigationEntryImpl::kInvalidBindings && 150 bindings != NavigationEntryImpl::kInvalidBindings &&
207 pending_web_ui_->GetBindings() != entry.bindings()) { 151 pending_web_ui_->GetBindings() != bindings) {
208 RecordAction( 152 RecordAction(
209 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); 153 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
210 pending_web_ui_.reset(); 154 pending_web_ui_.reset();
211 } 155 }
212 } 156 }
213 157
214 RenderFrameHostImpl* RenderFrameHostManager::Navigate( 158 RenderFrameHostImpl* RenderFrameHostManager::Navigate(
215 const NavigationEntryImpl& entry) { 159 const NavigationEntryImpl& entry) {
216 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate", 160 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate",
217 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); 161 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id());
218 // Create a pending RenderFrameHost to use for the navigation. 162 // Create a pending RenderFrameHost to use for the navigation.
219 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate(entry); 163 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate(
164 entry.GetURL(),
165 entry.site_instance(),
166 entry.GetTransitionType(),
167 entry.restore_type() != NavigationEntryImpl::RESTORE_NONE,
168 entry.IsViewSourceMode(),
169 entry.transferred_global_request_id(),
170 entry.bindings());
220 if (!dest_render_frame_host) 171 if (!dest_render_frame_host)
221 return NULL; // We weren't able to create a pending render frame host. 172 return NULL; // We weren't able to create a pending render frame host.
222 173
223 // If the current render_frame_host_ isn't live, we should create it so 174 // If the current render_frame_host_ isn't live, we should create it so
224 // that we don't show a sad tab while the dest_render_frame_host fetches 175 // that we don't show a sad tab while the dest_render_frame_host fetches
225 // its first page. (Bug 1145340) 176 // its first page. (Bug 1145340)
226 if (dest_render_frame_host != render_frame_host_ && 177 if (dest_render_frame_host != render_frame_host_ &&
227 !render_frame_host_->IsRenderFrameLive()) { 178 !render_frame_host_->IsRenderFrameLive()) {
228 // Note: we don't call InitRenderView here because we are navigating away 179 // Note: we don't call InitRenderView here because we are navigating away
229 // soon anyway, and we don't have the NavigationEntry for this host. 180 // soon anyway, and we don't have the NavigationEntry for this host.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 static_cast<RenderProcessHostImpl*>(render_frame_host_->GetProcess()); 396 static_cast<RenderProcessHostImpl*>(render_frame_host_->GetProcess());
446 process->ResumeResponseDeferredAtStart(*response_started_id_); 397 process->ResumeResponseDeferredAtStart(*response_started_id_);
447 398
448 render_frame_host_->ClearPendingTransitionRequestData(); 399 render_frame_host_->ClearPendingTransitionRequestData();
449 400
450 response_started_id_.reset(); 401 response_started_id_.reset();
451 } 402 }
452 403
453 void RenderFrameHostManager::DidNavigateFrame( 404 void RenderFrameHostManager::DidNavigateFrame(
454 RenderFrameHostImpl* render_frame_host) { 405 RenderFrameHostImpl* render_frame_host) {
455 // PlzNavigate
456 // The navigation request has been committed so the browser process doesn't
457 // need to care about it anymore.
458 if (CommandLine::ForCurrentProcess()->HasSwitch(
459 switches::kEnableBrowserSideNavigation)) {
460 navigation_request_.reset();
461 }
462
463 if (!cross_navigation_pending_) { 406 if (!cross_navigation_pending_) {
464 DCHECK(!pending_render_frame_host_); 407 DCHECK(!pending_render_frame_host_);
465 408
466 // We should only hear this from our current renderer. 409 // We should only hear this from our current renderer.
467 DCHECK_EQ(render_frame_host_, render_frame_host); 410 DCHECK_EQ(render_frame_host_, render_frame_host);
468 411
469 // Even when there is no pending RVH, there may be a pending Web UI. 412 // Even when there is no pending RVH, there may be a pending Web UI.
470 if (pending_web_ui()) 413 if (pending_web_ui())
471 CommitPending(); 414 CommitPending();
472 return; 415 return;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 pending_delete_hosts_.find(site_instance_id); 515 pending_delete_hosts_.find(site_instance_id);
573 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh) 516 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh)
574 pending_delete_hosts_.erase(site_instance_id); 517 pending_delete_hosts_.erase(site_instance_id);
575 } 518 }
576 519
577 void RenderFrameHostManager::ResetProxyHosts() { 520 void RenderFrameHostManager::ResetProxyHosts() {
578 STLDeleteValues(&proxy_hosts_); 521 STLDeleteValues(&proxy_hosts_);
579 } 522 }
580 523
581 // PlzNavigate 524 // PlzNavigate
582 bool RenderFrameHostManager::RequestNavigation( 525 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation(
583 scoped_ptr<NavigationRequest> navigation_request, 526 const GURL& url,
584 const RequestNavigationParams& request_params) { 527 ui::PageTransition transition) {
585 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 528 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
586 switches::kEnableBrowserSideNavigation)); 529 switches::kEnableBrowserSideNavigation));
587 530 // TODO(clamy): When we handle renderer initiated navigations, make sure not
588 // TODO(clamy): Check if navigations are blocked and if so store the 531 // to use a different process for subframes if --site-per-process is not
589 // parameters. 532 // enabled.
590
591 // If there is an ongoing request it must be canceled.
592 if (navigation_request_.get())
593 navigation_request_->CancelNavigation();
594
595 navigation_request_ = navigation_request.Pass();
596
597 if (render_frame_host_->IsRenderFrameLive()) {
598 // TODO(clamy): send a RequestNavigation IPC.
599 return true;
600 }
601
602 // The navigation request is sent directly to the IO thread.
603 OnBeginNavigation(
604 MakeDefaultBeginNavigation(
605 request_params, navigation_request_->common_params().navigation_type),
606 navigation_request_->common_params());
607 return true;
608 }
609
610 // PlzNavigate
611 void RenderFrameHostManager::OnBeginNavigation(
612 const FrameHostMsg_BeginNavigation_Params& params,
613 const CommonNavigationParams& common_params) {
614 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
615 switches::kEnableBrowserSideNavigation));
616 // TODO(clamy): In case of a renderer initiated navigation create a new
617 // NavigationRequest.
618 DCHECK(navigation_request_.get());
619 // Update the referrer with the one received from the renderer.
620 navigation_request_->common_params().referrer = common_params.referrer;
621
622 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params));
623
624 info->first_party_for_cookies =
625 frame_tree_node_->IsMainFrame()
626 ? navigation_request_->common_params().url
627 : frame_tree_node_->frame_tree()->root()->current_url();
628 info->is_main_frame = frame_tree_node_->IsMainFrame();
629 info->parent_is_main_frame = !frame_tree_node_->parent() ?
630 false : frame_tree_node_->parent()->IsMainFrame();
631
632 // TODO(clamy): Check if the current RFH should be initialized (in case it has
633 // crashed) not to display a sad tab while navigating.
634 // TODO(clamy): Spawn a speculative renderer process if we do not have one to
635 // use for the navigation.
636
637 navigation_request_->BeginNavigation(info.Pass(), params.request_body);
638 }
639
640 // PlzNavigate
641 void RenderFrameHostManager::CommitNavigation(
642 const NavigationBeforeCommitInfo& info) {
643 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
644 switches::kEnableBrowserSideNavigation));
645 DCHECK(navigation_request_.get());
646 // Ignores navigation commits if the request ID doesn't match the current
647 // active request.
648 if (navigation_request_->navigation_request_id() !=
649 info.navigation_request_id) {
650 return;
651 }
652 533
653 // Pick the right RenderFrameHost to commit the navigation. 534 // Pick the right RenderFrameHost to commit the navigation.
654 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 535 // TODO(clamy): Replace the default values by the right ones.
655 // TODO(clamy): Replace the default values by the right ones. This may require 536 RenderFrameHostImpl* render_frame_host = UpdateStateForNavigate(
656 // some storing in RequestNavigation. 537 url, NULL, transition, false, false, GlobalRequestID(),
657 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( 538 NavigationEntryImpl::kInvalidBindings);
658 info.navigation_url,
659 NULL,
660 navigation_request_->common_params().transition,
661 false,
662 false);
663 DCHECK(!pending_render_frame_host_.get());
664
665 // TODO(clamy): Update how pending WebUI objects are handled.
666 if (current_instance != new_instance.get()) {
667 CreateRenderFrameHostForNewSiteInstance(
668 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame());
669 DCHECK(pending_render_frame_host_.get());
670 // TODO(clamy): Wait until the navigation has committed before swapping
671 // renderers.
672 scoped_ptr<RenderFrameHostImpl> old_render_frame_host =
673 SetRenderFrameHost(pending_render_frame_host_.Pass());
674 if (frame_tree_node_->IsMainFrame())
675 render_frame_host_->render_view_host()->AttachToFrameTree();
676 }
677 539
678 // If the renderer that needs to navigate is not live (it was just created or 540 // If the renderer that needs to navigate is not live (it was just created or
679 // it crashed), initialize it. 541 // it crashed), initialize it.
680 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { 542 if (!render_frame_host->render_view_host()->IsRenderViewLive()) {
681 // Recreate the opener chain. 543 // Recreate the opener chain.
682 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( 544 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager(
683 render_frame_host_->GetSiteInstance()); 545 render_frame_host->GetSiteInstance());
684 if (!InitRenderView(render_frame_host_->render_view_host(), 546 if (!InitRenderView(render_frame_host->render_view_host(),
685 opener_route_id, 547 opener_route_id,
686 MSG_ROUTING_NONE, 548 MSG_ROUTING_NONE,
687 frame_tree_node_->IsMainFrame())) { 549 frame_tree_node_->IsMainFrame())) {
688 return; 550 return NULL;
689 } 551 }
690 } 552 }
691 553 return render_frame_host;
692 frame_tree_node_->navigator()->CommitNavigation(
693 render_frame_host_.get(),
694 info.stream_url,
695 navigation_request_->common_params(),
696 navigation_request_->commit_params());
697 } 554 }
698 555
699 void RenderFrameHostManager::Observe( 556 void RenderFrameHostManager::Observe(
700 int type, 557 int type,
701 const NotificationSource& source, 558 const NotificationSource& source,
702 const NotificationDetails& details) { 559 const NotificationDetails& details) {
703 switch (type) { 560 switch (type) {
704 case NOTIFICATION_RENDERER_PROCESS_CLOSED: 561 case NOTIFICATION_RENDERER_PROCESS_CLOSED:
705 case NOTIFICATION_RENDERER_PROCESS_CLOSING: 562 case NOTIFICATION_RENDERER_PROCESS_CLOSING:
706 RendererProcessClosing( 563 RendererProcessClosing(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat 670 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat
814 // it as a new navigation). So require a BrowsingInstance switch. 671 // it as a new navigation). So require a BrowsingInstance switch.
815 if (current_is_view_source_mode != new_is_view_source_mode) 672 if (current_is_view_source_mode != new_is_view_source_mode)
816 return true; 673 return true;
817 674
818 return false; 675 return false;
819 } 676 }
820 677
821 bool RenderFrameHostManager::ShouldReuseWebUI( 678 bool RenderFrameHostManager::ShouldReuseWebUI(
822 const NavigationEntry* current_entry, 679 const NavigationEntry* current_entry,
823 const NavigationEntryImpl* new_entry) const { 680 const GURL& new_url) const {
824 NavigationControllerImpl& controller = 681 NavigationControllerImpl& controller =
825 delegate_->GetControllerForRenderManager(); 682 delegate_->GetControllerForRenderManager();
826 return current_entry && web_ui_.get() && 683 return current_entry && web_ui_.get() &&
827 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( 684 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
828 controller.GetBrowserContext(), current_entry->GetURL()) == 685 controller.GetBrowserContext(), current_entry->GetURL()) ==
829 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( 686 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
830 controller.GetBrowserContext(), new_entry->GetURL())); 687 controller.GetBrowserContext(), new_url));
831 } 688 }
832 689
833 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( 690 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation(
834 const GURL& dest_url, 691 const GURL& dest_url,
835 SiteInstance* dest_instance, 692 SiteInstance* dest_instance,
836 ui::PageTransition dest_transition, 693 ui::PageTransition dest_transition,
837 bool dest_is_restore, 694 bool dest_is_restore,
838 bool dest_is_view_source_mode) { 695 bool dest_is_view_source_mode) {
839 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 696 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
840 SiteInstance* new_instance = current_instance; 697 SiteInstance* new_instance = current_instance;
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 // |rvh| to Shutdown. 1342 // |rvh| to Shutdown.
1486 FrameTree* tree = rvh->GetDelegate()->GetFrameTree(); 1343 FrameTree* tree = rvh->GetDelegate()->GetFrameTree();
1487 tree->ForEach(base::Bind( 1344 tree->ForEach(base::Bind(
1488 &RenderFrameHostManager::ClearProxiesInSiteInstance, 1345 &RenderFrameHostManager::ClearProxiesInSiteInstance,
1489 site_instance_id)); 1346 site_instance_id));
1490 } 1347 }
1491 } 1348 }
1492 } 1349 }
1493 1350
1494 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate( 1351 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate(
1495 const NavigationEntryImpl& entry) { 1352 const GURL& url,
1353 SiteInstance* instance,
1354 ui::PageTransition transition,
1355 bool is_restore,
1356 bool is_view_source_mode,
1357 const GlobalRequestID& transferred_request_id,
1358 int bindings) {
1496 // If we are currently navigating cross-process, we want to get back to normal 1359 // If we are currently navigating cross-process, we want to get back to normal
1497 // and then navigate as usual. 1360 // and then navigate as usual.
1498 if (cross_navigation_pending_) { 1361 if (cross_navigation_pending_) {
1499 if (pending_render_frame_host_) 1362 if (pending_render_frame_host_)
1500 CancelPending(); 1363 CancelPending();
1501 cross_navigation_pending_ = false; 1364 cross_navigation_pending_ = false;
1502 } 1365 }
1503 1366
1504 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 1367 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
1505 scoped_refptr<SiteInstance> new_instance = 1368 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation(
1506 GetSiteInstanceForNavigation( 1369 url, instance, transition, is_restore, is_view_source_mode);
1507 entry.GetURL(),
1508 entry.site_instance(),
1509 entry.GetTransitionType(),
1510 entry.restore_type() != NavigationEntryImpl::RESTORE_NONE,
1511 entry.IsViewSourceMode());
1512 1370
1513 const NavigationEntry* current_entry = 1371 const NavigationEntry* current_entry =
1514 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 1372 delegate_->GetLastCommittedNavigationEntryForRenderManager();
1515 1373
1516 if (new_instance.get() != current_instance) { 1374 if (new_instance.get() != current_instance) {
1517 TRACE_EVENT_INSTANT2( 1375 TRACE_EVENT_INSTANT2(
1518 "navigation", 1376 "navigation",
1519 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", 1377 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance",
1520 TRACE_EVENT_SCOPE_THREAD, 1378 TRACE_EVENT_SCOPE_THREAD,
1521 "current_instance id", current_instance->GetId(), 1379 "current_instance id", current_instance->GetId(),
1522 "new_instance id", new_instance->GetId()); 1380 "new_instance id", new_instance->GetId());
1523 1381
1524 // New SiteInstance: create a pending RFH to navigate. 1382 // New SiteInstance: create a pending RFH to navigate.
1525 DCHECK(!cross_navigation_pending_); 1383 DCHECK(!cross_navigation_pending_);
1526 1384
1527 // This will possibly create (set to NULL) a Web UI object for the pending 1385 // This will possibly create (set to NULL) a Web UI object for the pending
1528 // page. We'll use this later to give the page special access. This must 1386 // page. We'll use this later to give the page special access. This must
1529 // happen before the new renderer is created below so it will get bindings. 1387 // happen before the new renderer is created below so it will get bindings.
1530 // It must also happen after the above conditional call to CancelPending(), 1388 // It must also happen after the above conditional call to CancelPending(),
1531 // otherwise CancelPending may clear the pending_web_ui_ and the page will 1389 // otherwise CancelPending may clear the pending_web_ui_ and the page will
1532 // not have its bindings set appropriately. 1390 // not have its bindings set appropriately.
1533 SetPendingWebUI(entry); 1391 SetPendingWebUI(url, bindings);
1534 CreateRenderFrameHostForNewSiteInstance( 1392 CreateRenderFrameHostForNewSiteInstance(
1535 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame()); 1393 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame());
1536 if (!pending_render_frame_host_.get()) { 1394 if (!pending_render_frame_host_.get()) {
1537 return NULL; 1395 return NULL;
1538 } 1396 }
1539 1397
1540 // Check if our current RFH is live before we set up a transition. 1398 // Check if our current RFH is live before we set up a transition.
1541 if (!render_frame_host_->IsRenderFrameLive()) { 1399 if (!render_frame_host_->IsRenderFrameLive()) {
1542 if (!cross_navigation_pending_) { 1400 if (!cross_navigation_pending_) {
1543 // The current RFH is not live. There's no reason to sit around with a 1401 // The current RFH is not live. There's no reason to sit around with a
1544 // sad tab or a newly created RFH while we wait for the pending RFH to 1402 // sad tab or a newly created RFH while we wait for the pending RFH to
1545 // navigate. Just switch to the pending RFH now and go back to non 1403 // navigate. Just switch to the pending RFH now and go back to non
1546 // cross-navigating (Note that we don't care about on{before}unload 1404 // cross-navigating (Note that we don't care about on{before}unload
1547 // handlers if the current RFH isn't live.) 1405 // handlers if the current RFH isn't live.)
1548 CommitPending(); 1406 CommitPending();
1549 return render_frame_host_.get(); 1407 return render_frame_host_.get();
1550 } else { 1408 } else {
1551 NOTREACHED(); 1409 NOTREACHED();
1552 return render_frame_host_.get(); 1410 return render_frame_host_.get();
1553 } 1411 }
1554 } 1412 }
1555 // Otherwise, it's safe to treat this as a pending cross-site transition. 1413 // Otherwise, it's safe to treat this as a pending cross-site transition.
1556 1414
1557 // We need to wait until the beforeunload handler has run, unless we are 1415 // We need to wait until the beforeunload handler has run, unless we are
1558 // transferring an existing request (in which case it has already run). 1416 // transferring an existing request (in which case it has already run).
1559 // Suspend the new render view (i.e., don't let it send the cross-site 1417 // Suspend the new render view (i.e., don't let it send the cross-site
1560 // Navigate message) until we hear back from the old renderer's 1418 // Navigate message) until we hear back from the old renderer's
1561 // beforeunload handler. If the handler returns false, we'll have to 1419 // beforeunload handler. If the handler returns false, we'll have to
1562 // cancel the request. 1420 // cancel the request.
1563 DCHECK(!pending_render_frame_host_->are_navigations_suspended()); 1421 //
1564 bool is_transfer = 1422 // PlzNavigate: There is no notion of transfer navigations, and the old
1565 entry.transferred_global_request_id() != GlobalRequestID(); 1423 // renderer before unload handler has already run at that point.
1566 if (is_transfer) { 1424 if (!CommandLine::ForCurrentProcess()->HasSwitch(
Charlie Reis 2014/10/01 23:28:50 This is a bit awkward to read. Maybe move the "We
clamy 2014/10/02 17:39:54 Done.
1567 // We don't need to stop the old renderer or run beforeunload/unload 1425 switches::kEnableBrowserSideNavigation)) {
1568 // handlers, because those have already been done. 1426 DCHECK(!pending_render_frame_host_->are_navigations_suspended());
1569 DCHECK(cross_site_transferring_request_->request_id() == 1427 bool is_transfer = transferred_request_id != GlobalRequestID();
1570 entry.transferred_global_request_id()); 1428 if (is_transfer) {
1571 } else { 1429 // We don't need to stop the old renderer or run beforeunload/unload
1572 // Also make sure the old render view stops, in case a load is in 1430 // handlers, because those have already been done.
1573 // progress. (We don't want to do this for transfers, since it will 1431 DCHECK(cross_site_transferring_request_->request_id() ==
1574 // interrupt the transfer with an unexpected DidStopLoading.) 1432 transferred_request_id);
1575 render_frame_host_->Send(new FrameMsg_Stop( 1433 } else {
1576 render_frame_host_->GetRoutingID())); 1434 // Also make sure the old render view stops, in case a load is in
1577 pending_render_frame_host_->SetNavigationsSuspended(true, 1435 // progress. (We don't want to do this for transfers, since it will
1578 base::TimeTicks()); 1436 // interrupt the transfer with an unexpected DidStopLoading.)
1437 render_frame_host_->Send(new FrameMsg_Stop(
1438 render_frame_host_->GetRoutingID()));
1439 pending_render_frame_host_->SetNavigationsSuspended(true,
1440 base::TimeTicks());
1441 // Unless we are transferring an existing request, we should now tell
1442 // the old render view to run its beforeunload handler, since it doesn't
1443 // otherwise know that the cross-site request is happening. This will
1444 // trigger a call to OnBeforeUnloadACK with the reply.
1445 render_frame_host_->DispatchBeforeUnload(true);
1446 }
1579 } 1447 }
1580 1448
1581 // We now have a pending RFH. 1449 // We now have a pending RFH.
1582 DCHECK(!cross_navigation_pending_); 1450 DCHECK(!cross_navigation_pending_);
1583 cross_navigation_pending_ = true; 1451 cross_navigation_pending_ = true;
1584 1452
1585 // Unless we are transferring an existing request, we should now
1586 // tell the old render view to run its beforeunload handler, since it
1587 // doesn't otherwise know that the cross-site request is happening. This
1588 // will trigger a call to OnBeforeUnloadACK with the reply.
1589 if (!is_transfer)
1590 render_frame_host_->DispatchBeforeUnload(true);
1591
1592 return pending_render_frame_host_.get(); 1453 return pending_render_frame_host_.get();
1593 } 1454 }
1594 1455
1595 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. 1456 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_.
1596 DCHECK(!cross_navigation_pending_); 1457 DCHECK(!cross_navigation_pending_);
1597 1458
1598 // It's possible to swap out the current RFH and then decide to navigate in it 1459 // It's possible to swap out the current RFH and then decide to navigate in it
1599 // anyway (e.g., a cross-process navigation that redirects back to the 1460 // anyway (e.g., a cross-process navigation that redirects back to the
1600 // original site). In that case, we have a proxy for the current RFH but 1461 // original site). In that case, we have a proxy for the current RFH but
1601 // haven't deleted it yet. The new navigation will swap it back in, so we can 1462 // haven't deleted it yet. The new navigation will swap it back in, so we can
1602 // delete the proxy. 1463 // delete the proxy.
1603 DeleteRenderFrameProxyHost(new_instance.get()); 1464 DeleteRenderFrameProxyHost(new_instance.get());
1604 1465
1605 if (ShouldReuseWebUI(current_entry, &entry)) { 1466 if (ShouldReuseWebUI(current_entry, url)) {
1606 pending_web_ui_.reset(); 1467 pending_web_ui_.reset();
1607 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); 1468 pending_and_current_web_ui_ = web_ui_->AsWeakPtr();
1608 } else { 1469 } else {
1609 SetPendingWebUI(entry); 1470 SetPendingWebUI(url, bindings);
1610
1611 // Make sure the new RenderViewHost has the right bindings. 1471 // Make sure the new RenderViewHost has the right bindings.
1612 if (pending_web_ui() && 1472 if (pending_web_ui() &&
1613 !render_frame_host_->GetProcess()->IsIsolatedGuest()) { 1473 !render_frame_host_->GetProcess()->IsIsolatedGuest()) {
1614 render_frame_host_->render_view_host()->AllowBindings( 1474 render_frame_host_->render_view_host()->AllowBindings(
1615 pending_web_ui()->GetBindings()); 1475 pending_web_ui()->GetBindings());
1616 } 1476 }
1617 } 1477 }
1618 1478
1619 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) { 1479 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) {
1620 pending_web_ui()->GetController()->RenderViewReused( 1480 pending_web_ui()->GetController()->RenderViewReused(
1621 render_frame_host_->render_view_host()); 1481 render_frame_host_->render_view_host());
1622 } 1482 }
1623 1483
1624 // The renderer can exit view source mode when any error or cancellation 1484 // The renderer can exit view source mode when any error or cancellation
1625 // happen. We must overwrite to recover the mode. 1485 // happen. We must overwrite to recover the mode.
1626 if (entry.IsViewSourceMode()) { 1486 if (is_view_source_mode) {
1627 render_frame_host_->render_view_host()->Send( 1487 render_frame_host_->render_view_host()->Send(
1628 new ViewMsg_EnableViewSourceMode( 1488 new ViewMsg_EnableViewSourceMode(
1629 render_frame_host_->render_view_host()->GetRoutingID())); 1489 render_frame_host_->render_view_host()->GetRoutingID()));
1630 } 1490 }
1631 1491
1632 return render_frame_host_.get(); 1492 return render_frame_host_.get();
1633 } 1493 }
1634 1494
1635 void RenderFrameHostManager::CancelPending() { 1495 void RenderFrameHostManager::CancelPending() {
1636 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending", 1496 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending",
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 1600 void RenderFrameHostManager::DeleteRenderFrameProxyHost(
1741 SiteInstance* instance) { 1601 SiteInstance* instance) {
1742 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 1602 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId());
1743 if (iter != proxy_hosts_.end()) { 1603 if (iter != proxy_hosts_.end()) {
1744 delete iter->second; 1604 delete iter->second;
1745 proxy_hosts_.erase(iter); 1605 proxy_hosts_.erase(iter);
1746 } 1606 }
1747 } 1607 }
1748 1608
1749 } // namespace content 1609 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698