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

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

Issue 483773002: PlzNavigate: implement CommitNavigation on the browser side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split the class into structs used by IPCs 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/navigator_impl.h" 5 #include "content/browser/frame_host/navigator_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/frame_tree_node.h" 10 #include "content/browser/frame_host/frame_tree_node.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { 66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) {
67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 67 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
68 switches::kSitePerProcess)) 68 switches::kSitePerProcess))
69 return rfh->frame_tree_node()->render_manager(); 69 return rfh->frame_tree_node()->render_manager();
70 70
71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); 71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager();
72 } 72 }
73 73
74 } // namespace 74 void InitializeNavigationParams(
75
76
77 NavigatorImpl::NavigatorImpl(
78 NavigationControllerImpl* navigation_controller,
79 NavigatorDelegate* delegate)
80 : controller_(navigation_controller),
81 delegate_(delegate) {
82 }
83
84 // static.
85 void NavigatorImpl::MakeNavigateParams(
86 const NavigationEntryImpl& entry, 75 const NavigationEntryImpl& entry,
87 const NavigationControllerImpl& controller, 76 NavigationControllerImpl* controller,
88 NavigationController::ReloadType reload_type, 77 NavigationController::ReloadType reload_type,
89 base::TimeTicks navigation_start, 78 base::TimeTicks navigation_start,
90 FrameMsg_Navigate_Params* params) { 79 NavigationParamsWithRequestAndCommitInfo* params) {
80 params->url = entry.GetURL();
81 params->referrer = entry.GetReferrer();
82 params->transition = entry.GetTransitionType();
91 params->page_id = entry.GetPageID(); 83 params->page_id = entry.GetPageID();
92 params->should_clear_history_list = entry.should_clear_history_list(); 84 params->should_clear_history_list = entry.should_clear_history_list();
93 params->should_replace_current_entry = entry.should_replace_entry();
94 if (entry.should_clear_history_list()) { 85 if (entry.should_clear_history_list()) {
95 // Set the history list related parameters to the same values a 86 // Set the history list related parameters to the same values a
96 // NavigationController would return before its first navigation. This will 87 // NavigationController would return before its first navigation. This will
97 // fully clear the RenderView's view of the session history. 88 // fully clear the RenderView's view of the session history.
98 params->pending_history_list_offset = -1; 89 params->pending_history_list_offset = -1;
99 params->current_history_list_offset = -1; 90 params->current_history_list_offset = -1;
100 params->current_history_list_length = 0; 91 params->current_history_list_length = 0;
101 } else { 92 } else {
102 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); 93 params->pending_history_list_offset =
94 controller->GetIndexOfEntry(&entry);
103 params->current_history_list_offset = 95 params->current_history_list_offset =
104 controller.GetLastCommittedEntryIndex(); 96 controller->GetLastCommittedEntryIndex();
105 params->current_history_list_length = controller.GetEntryCount(); 97 params->current_history_list_length =
98 controller->GetEntryCount();
106 } 99 }
107 params->url = entry.GetURL(); 100 params->page_state = entry.GetPageState();
101 params->navigation_type = GetNavigationType(
102 controller->GetBrowserContext(), entry, reload_type);
103 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
104 params->browser_navigation_start = navigation_start;
105 params->is_post = entry.GetHasPostData();
106 // Avoid downloading when in view-source mode.
107 params->allow_download = !entry.IsViewSourceMode();
108 }
109
110 void MakeNavigateParams(
111 const NavigationEntryImpl& entry,
112 NavigationControllerImpl* controller,
113 NavigationController::ReloadType reload_type,
114 base::TimeTicks navigation_start,
115 FrameMsg_Navigate_Params* params) {
116 InitializeNavigationParams(
117 entry,
118 controller,
119 reload_type,
120 navigation_start,
121 static_cast<NavigationParamsWithRequestAndCommitInfo*>(params));
108 if (!entry.GetBaseURLForDataURL().is_empty()) { 122 if (!entry.GetBaseURLForDataURL().is_empty()) {
109 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); 123 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
110 params->history_url_for_data_url = entry.GetVirtualURL(); 124 params->history_url_for_data_url = entry.GetVirtualURL();
111 } 125 }
112 params->referrer = entry.GetReferrer(); 126 params->should_replace_current_entry = entry.should_replace_entry();
113 params->transition = entry.GetTransitionType();
114 params->page_state = entry.GetPageState();
115 params->navigation_type =
116 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
117 // This is used by the old performance infrastructure to set up DocumentState 127 // This is used by the old performance infrastructure to set up DocumentState
118 // associated with the RenderView. 128 // associated with the RenderView.
119 // TODO(ppi): make it go away. 129 // TODO(ppi): make it go away.
120 params->request_time = base::Time::Now(); 130 params->request_time = base::Time::Now();
121 params->extra_headers = entry.extra_headers(); 131 params->extra_headers = entry.extra_headers();
122 params->transferred_request_child_id = 132 params->transferred_request_child_id =
123 entry.transferred_global_request_id().child_id; 133 entry.transferred_global_request_id().child_id;
124 params->transferred_request_request_id = 134 params->transferred_request_request_id =
125 entry.transferred_global_request_id().request_id; 135 entry.transferred_global_request_id().request_id;
126 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
127 // Avoid downloading when in view-source mode.
128 params->allow_download = !entry.IsViewSourceMode();
129 params->is_post = entry.GetHasPostData();
130 if (entry.GetBrowserInitiatedPostData()) { 136 if (entry.GetBrowserInitiatedPostData()) {
131 params->browser_initiated_post_data.assign( 137 params->browser_initiated_post_data.assign(
132 entry.GetBrowserInitiatedPostData()->front(), 138 entry.GetBrowserInitiatedPostData()->front(),
133 entry.GetBrowserInitiatedPostData()->front() + 139 entry.GetBrowserInitiatedPostData()->front() +
134 entry.GetBrowserInitiatedPostData()->size()); 140 entry.GetBrowserInitiatedPostData()->size());
135 } 141 }
136 142
137 // Set the redirect chain to the navigation's redirects, unless we are 143 // Set the redirect chain to the navigation's redirects, unless we are
138 // returning to a completed navigation (whose previous redirects don't apply). 144 // returning to a completed navigation (whose previous redirects don't apply).
139 if (PageTransitionIsNewNavigation(params->transition)) { 145 if (PageTransitionIsNewNavigation(params->transition)) {
140 params->redirects = entry.GetRedirectChain(); 146 params->redirects = entry.GetRedirectChain();
141 } else { 147 } else {
142 params->redirects.clear(); 148 params->redirects.clear();
143 } 149 }
144 150
145 params->can_load_local_resources = entry.GetCanLoadLocalResources(); 151 params->can_load_local_resources = entry.GetCanLoadLocalResources();
146 params->frame_to_navigate = entry.GetFrameToNavigate(); 152 params->frame_to_navigate = entry.GetFrameToNavigate();
147 params->browser_navigation_start = navigation_start; 153 }
154
155 } // namespace
156
157
158 NavigatorImpl::NavigatorImpl(
159 NavigationControllerImpl* navigation_controller,
160 NavigatorDelegate* delegate)
161 : controller_(navigation_controller),
162 delegate_(delegate) {
148 } 163 }
149 164
150 NavigationController* NavigatorImpl::GetController() { 165 NavigationController* NavigatorImpl::GetController() {
151 return controller_; 166 return controller_;
152 } 167 }
153 168
154 void NavigatorImpl::DidStartProvisionalLoad( 169 void NavigatorImpl::DidStartProvisionalLoad(
155 RenderFrameHostImpl* render_frame_host, 170 RenderFrameHostImpl* render_frame_host,
156 const GURL& url, 171 const GURL& url,
157 bool is_transition_navigation) { 172 bool is_transition_navigation) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to 356 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to
342 // capture the time needed for the RenderFrameHost initialization. 357 // capture the time needed for the RenderFrameHost initialization.
343 base::TimeTicks navigation_start = base::TimeTicks::Now(); 358 base::TimeTicks navigation_start = base::TimeTicks::Now();
344 359
345 // WebContents uses this to fill LoadNotificationDetails when the load 360 // WebContents uses this to fill LoadNotificationDetails when the load
346 // completes, so that PerformanceMonitor that listens to the notification can 361 // completes, so that PerformanceMonitor that listens to the notification can
347 // record the load time. PerformanceMonitor is no longer maintained. 362 // record the load time. PerformanceMonitor is no longer maintained.
348 // TODO(ppi): make this go away. 363 // TODO(ppi): make this go away.
349 current_load_start_ = base::TimeTicks::Now(); 364 current_load_start_ = base::TimeTicks::Now();
350 365
351 // Create the navigation parameters.
352 FrameMsg_Navigate_Params navigate_params;
353 MakeNavigateParams(
354 entry, *controller_, reload_type, navigation_start, &navigate_params);
355
356 RenderFrameHostManager* manager = 366 RenderFrameHostManager* manager =
357 render_frame_host->frame_tree_node()->render_manager(); 367 render_frame_host->frame_tree_node()->render_manager();
358 368
359 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead 369 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead
360 // the RenderFrameHostManager handles the navigation requests for that frame 370 // the RenderFrameHostManager handles the navigation requests for that frame
361 // node. 371 // node.
362 if (CommandLine::ForCurrentProcess()->HasSwitch( 372 if (CommandLine::ForCurrentProcess()->HasSwitch(
363 switches::kEnableBrowserSideNavigation)) { 373 switches::kEnableBrowserSideNavigation)) {
364 return manager->RequestNavigation(entry, navigate_params); 374 scoped_ptr<NavigationParamsWithRequestAndCommitInfo> navigation_params(
375 new NavigationParamsWithRequestAndCommitInfo());
376 InitializeNavigationParams(entry,
377 controller_,
378 reload_type,
379 current_load_start_,
380 navigation_params.get());
381 return manager->RequestNavigation(navigation_params.Pass());
365 } 382 }
366 383
367 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); 384 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry);
368 if (!dest_render_frame_host) 385 if (!dest_render_frame_host)
369 return false; // Unable to create the desired RenderFrameHost. 386 return false; // Unable to create the desired RenderFrameHost.
370 387
371 // Make sure no code called via RFHM::Navigate clears the pending entry. 388 // Make sure no code called via RFHM::Navigate clears the pending entry.
372 CHECK_EQ(controller_->GetPendingEntry(), &entry); 389 CHECK_EQ(controller_->GetPendingEntry(), &entry);
373 390
374 // For security, we should never send non-Web-UI URLs to a Web UI renderer. 391 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
375 // Double check that here. 392 // Double check that here.
376 CheckWebUIRendererDoesNotDisplayNormalURL( 393 CheckWebUIRendererDoesNotDisplayNormalURL(
377 dest_render_frame_host, entry.GetURL()); 394 dest_render_frame_host, entry.GetURL());
378 395
379 // Notify observers that we will navigate in this RenderFrame. 396 // Notify observers that we will navigate in this RenderFrame.
380 if (delegate_) 397 if (delegate_)
381 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); 398 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host);
382 399
400 // Create the navigation parameters.
401 FrameMsg_Navigate_Params navigate_params;
402 MakeNavigateParams(
403 entry, controller_, reload_type, navigation_start, &navigate_params);
404
383 // Navigate in the desired RenderFrameHost. 405 // Navigate in the desired RenderFrameHost.
384 // We can skip this step in the rare case that this is a transfer navigation 406 // We can skip this step in the rare case that this is a transfer navigation
385 // which began in the chosen RenderFrameHost, since the request has already 407 // which began in the chosen RenderFrameHost, since the request has already
386 // been issued. In that case, simply resume the response. 408 // been issued. In that case, simply resume the response.
387 bool is_transfer_to_same = 409 bool is_transfer_to_same =
388 navigate_params.transferred_request_child_id != -1 && 410 navigate_params.transferred_request_child_id != -1 &&
389 navigate_params.transferred_request_child_id == 411 navigate_params.transferred_request_child_id ==
390 dest_render_frame_host->GetProcess()->GetID(); 412 dest_render_frame_host->GetProcess()->GetID();
391 if (!is_transfer_to_same) { 413 if (!is_transfer_to_same) {
392 dest_render_frame_host->Navigate(navigate_params); 414 dest_render_frame_host->Navigate(navigate_params);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // Navigations in Web UI pages count as browser-initiated navigations. 679 // Navigations in Web UI pages count as browser-initiated navigations.
658 params.is_renderer_initiated = false; 680 params.is_renderer_initiated = false;
659 } 681 }
660 682
661 if (delegate_) 683 if (delegate_)
662 delegate_->RequestOpenURL(render_frame_host, params); 684 delegate_->RequestOpenURL(render_frame_host, params);
663 } 685 }
664 686
665 void NavigatorImpl::CommitNavigation( 687 void NavigatorImpl::CommitNavigation(
666 RenderFrameHostImpl* render_frame_host, 688 RenderFrameHostImpl* render_frame_host,
667 const NavigationBeforeCommitInfo& info) { 689 const FrameMsg_CommitNavigation_Params& commit_navigation_params) {
668 CheckWebUIRendererDoesNotDisplayNormalURL( 690 CheckWebUIRendererDoesNotDisplayNormalURL(
669 render_frame_host, info.navigation_url); 691 render_frame_host, commit_navigation_params.url);
670 // TODO(clamy): the render_frame_host should now send a commit IPC to the 692 render_frame_host->CommitNavigation(commit_navigation_params);
671 // renderer. 693 }
694
695 scoped_ptr<NavigationParamsWithRequestAndCommitInfo>
696 NavigatorImpl::MakeNavigationParamsForTest(
697 const NavigationEntryImpl& entry,
698 NavigationController::ReloadType reload_type) {
699 scoped_ptr<NavigationParamsWithRequestAndCommitInfo> navigation_params (
700 new NavigationParamsWithRequestAndCommitInfo());
701 InitializeNavigationParams(entry,
702 controller_,
703 reload_type,
704 base::TimeTicks::Now(),
705 navigation_params.get());
706 return navigation_params.Pass();
672 } 707 }
673 708
674 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( 709 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(
675 RenderFrameHostImpl* render_frame_host, 710 RenderFrameHostImpl* render_frame_host,
676 const GURL& url) { 711 const GURL& url) {
677 int enabled_bindings = 712 int enabled_bindings =
678 render_frame_host->render_view_host()->GetEnabledBindings(); 713 render_frame_host->render_view_host()->GetEnabledBindings();
679 bool is_allowed_in_web_ui_renderer = 714 bool is_allowed_in_web_ui_renderer =
680 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( 715 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
681 controller_->GetBrowserContext(), url); 716 controller_->GetBrowserContext(), url);
682 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && 717 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
683 !is_allowed_in_web_ui_renderer) { 718 !is_allowed_in_web_ui_renderer) {
684 // Log the URL to help us diagnose any future failures of this CHECK. 719 // Log the URL to help us diagnose any future failures of this CHECK.
685 GetContentClient()->SetActiveURL(url); 720 GetContentClient()->SetActiveURL(url);
686 CHECK(0); 721 CHECK(0);
687 } 722 }
688 } 723 }
689 724
690 } // namespace content 725 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698