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

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: Fixed compilation error 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/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"
11 #include "content/browser/frame_host/navigation_before_commit_info.h" 11 #include "content/browser/frame_host/navigation_before_commit_info.h"
12 #include "content/browser/frame_host/navigation_controller_impl.h" 12 #include "content/browser/frame_host/navigation_controller_impl.h"
13 #include "content/browser/frame_host/navigation_entry_impl.h" 13 #include "content/browser/frame_host/navigation_entry_impl.h"
14 #include "content/browser/frame_host/navigation_request.h"
14 #include "content/browser/frame_host/navigator_delegate.h" 15 #include "content/browser/frame_host/navigator_delegate.h"
15 #include "content/browser/frame_host/render_frame_host_impl.h" 16 #include "content/browser/frame_host/render_frame_host_impl.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h" 17 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/browser/site_instance_impl.h" 18 #include "content/browser/site_instance_impl.h"
18 #include "content/browser/webui/web_ui_controller_factory_registry.h" 19 #include "content/browser/webui/web_ui_controller_factory_registry.h"
19 #include "content/browser/webui/web_ui_impl.h" 20 #include "content/browser/webui/web_ui_impl.h"
20 #include "content/common/frame_messages.h" 21 #include "content/common/frame_messages.h"
22 #include "content/common/navigation_params.h"
21 #include "content/common/view_messages.h" 23 #include "content/common/view_messages.h"
22 #include "content/public/browser/browser_context.h" 24 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/content_browser_client.h" 25 #include "content/public/browser/content_browser_client.h"
24 #include "content/public/browser/global_request_id.h" 26 #include "content/public/browser/global_request_id.h"
25 #include "content/public/browser/invalidate_type.h" 27 #include "content/public/browser/invalidate_type.h"
26 #include "content/public/browser/navigation_controller.h" 28 #include "content/public/browser/navigation_controller.h"
27 #include "content/public/browser/navigation_details.h" 29 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/page_navigator.h" 30 #include "content/public/browser/page_navigator.h"
29 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
30 #include "content/public/common/bindings_policy.h" 32 #include "content/public/common/bindings_policy.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 66 }
65 67
66 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { 68 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) {
67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 69 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
68 switches::kSitePerProcess)) 70 switches::kSitePerProcess))
69 return rfh->frame_tree_node()->render_manager(); 71 return rfh->frame_tree_node()->render_manager();
70 72
71 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); 73 return rfh->frame_tree_node()->frame_tree()->root()->render_manager();
72 } 74 }
73 75
74 } // namespace 76 void MakeNavigateParams(const NavigationEntryImpl& entry,
77 NavigationControllerImpl* controller,
78 NavigationController::ReloadType reload_type,
79 base::TimeTicks navigation_start,
80 FrameMsg_Navigate_Params* params) {
81 params->common_params = CommonNavigationParams(
82 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(),
83 GetNavigationType(controller->GetBrowserContext(), entry, reload_type),
84 !entry.IsViewSourceMode());
85 params->request_params = RequestNavigationParams(
86 entry.GetHasPostData(),
87 entry.extra_headers(),
88 entry.GetBrowserInitiatedPostData());
89 params->commit_params = CommitNavigationParams(
90 entry.GetPageState(), entry.GetIsOverridingUserAgent(), navigation_start);
91 if (!entry.GetBaseURLForDataURL().is_empty()) {
92 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
93 params->history_url_for_data_url = entry.GetVirtualURL();
94 }
95 params->should_replace_current_entry = entry.should_replace_entry();
96 // This is used by the old performance infrastructure to set up DocumentState
97 // associated with the RenderView.
98 // TODO(ppi): make it go away.
99 params->request_time = base::Time::Now();
100 params->transferred_request_child_id =
101 entry.transferred_global_request_id().child_id;
102 params->transferred_request_request_id =
103 entry.transferred_global_request_id().request_id;
75 104
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,
87 const NavigationControllerImpl& controller,
88 NavigationController::ReloadType reload_type,
89 base::TimeTicks navigation_start,
90 FrameMsg_Navigate_Params* params) {
91 params->page_id = entry.GetPageID(); 105 params->page_id = entry.GetPageID();
92 params->should_clear_history_list = entry.should_clear_history_list(); 106 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()) { 107 if (entry.should_clear_history_list()) {
95 // Set the history list related parameters to the same values a 108 // Set the history list related parameters to the same values a
96 // NavigationController would return before its first navigation. This will 109 // NavigationController would return before its first navigation. This will
97 // fully clear the RenderView's view of the session history. 110 // fully clear the RenderView's view of the session history.
98 params->pending_history_list_offset = -1; 111 params->pending_history_list_offset = -1;
99 params->current_history_list_offset = -1; 112 params->current_history_list_offset = -1;
100 params->current_history_list_length = 0; 113 params->current_history_list_length = 0;
101 } else { 114 } else {
102 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); 115 params->pending_history_list_offset = controller->GetIndexOfEntry(&entry);
103 params->current_history_list_offset = 116 params->current_history_list_offset =
104 controller.GetLastCommittedEntryIndex(); 117 controller->GetLastCommittedEntryIndex();
105 params->current_history_list_length = controller.GetEntryCount(); 118 params->current_history_list_length = controller->GetEntryCount();
106 } 119 }
107 params->url = entry.GetURL();
108 if (!entry.GetBaseURLForDataURL().is_empty()) {
109 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
110 params->history_url_for_data_url = entry.GetVirtualURL();
111 }
112 params->referrer = entry.GetReferrer();
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
118 // associated with the RenderView.
119 // TODO(ppi): make it go away.
120 params->request_time = base::Time::Now();
121 params->extra_headers = entry.extra_headers();
122 params->transferred_request_child_id =
123 entry.transferred_global_request_id().child_id;
124 params->transferred_request_request_id =
125 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()) {
131 params->browser_initiated_post_data.assign(
132 entry.GetBrowserInitiatedPostData()->front(),
133 entry.GetBrowserInitiatedPostData()->front() +
134 entry.GetBrowserInitiatedPostData()->size());
135 }
136
137 // Set the redirect chain to the navigation's redirects, unless we are 120 // Set the redirect chain to the navigation's redirects, unless we are
138 // returning to a completed navigation (whose previous redirects don't apply). 121 // returning to a completed navigation (whose previous redirects don't apply).
139 if (ui::PageTransitionIsNewNavigation(params->transition)) { 122 if (ui::PageTransitionIsNewNavigation(params->common_params.transition)) {
140 params->redirects = entry.GetRedirectChain(); 123 params->redirects = entry.GetRedirectChain();
141 } else { 124 } else {
142 params->redirects.clear(); 125 params->redirects.clear();
143 } 126 }
144 127
145 params->can_load_local_resources = entry.GetCanLoadLocalResources(); 128 params->can_load_local_resources = entry.GetCanLoadLocalResources();
146 params->frame_to_navigate = entry.GetFrameToNavigate(); 129 params->frame_to_navigate = entry.GetFrameToNavigate();
147 params->browser_navigation_start = navigation_start; 130 }
131
132 } // namespace
133
134
135 NavigatorImpl::NavigatorImpl(
136 NavigationControllerImpl* navigation_controller,
137 NavigatorDelegate* delegate)
138 : controller_(navigation_controller),
139 delegate_(delegate) {
148 } 140 }
149 141
150 NavigationController* NavigatorImpl::GetController() { 142 NavigationController* NavigatorImpl::GetController() {
151 return controller_; 143 return controller_;
152 } 144 }
153 145
154 void NavigatorImpl::DidStartProvisionalLoad( 146 void NavigatorImpl::DidStartProvisionalLoad(
155 RenderFrameHostImpl* render_frame_host, 147 RenderFrameHostImpl* render_frame_host,
156 const GURL& url, 148 const GURL& url,
157 bool is_transition_navigation) { 149 bool is_transition_navigation) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 << " characters."; 298 << " characters.";
307 return false; 299 return false;
308 } 300 }
309 301
310 // This will be used to set the Navigation Timing API navigationStart 302 // This will be used to set the Navigation Timing API navigationStart
311 // parameter for browser navigations in new tabs (intents, tabs opened through 303 // parameter for browser navigations in new tabs (intents, tabs opened through
312 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to 304 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to
313 // capture the time needed for the RenderFrameHost initialization. 305 // capture the time needed for the RenderFrameHost initialization.
314 base::TimeTicks navigation_start = base::TimeTicks::Now(); 306 base::TimeTicks navigation_start = base::TimeTicks::Now();
315 307
316 FrameMsg_Navigate_Params navigate_params;
317 RenderFrameHostManager* manager = 308 RenderFrameHostManager* manager =
318 render_frame_host->frame_tree_node()->render_manager(); 309 render_frame_host->frame_tree_node()->render_manager();
319 310
320 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead 311 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. Instead
321 // the RenderFrameHostManager handles the navigation requests for that frame 312 // the RenderFrameHostManager handles the navigation requests for that frame
322 // node. 313 // node.
323 if (CommandLine::ForCurrentProcess()->HasSwitch( 314 if (CommandLine::ForCurrentProcess()->HasSwitch(
324 switches::kEnableBrowserSideNavigation)) { 315 switches::kEnableBrowserSideNavigation)) {
325 // Create the navigation parameters. 316 FrameMsg_Navigate_Type::Value navigation_type =
326 MakeNavigateParams( 317 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type);
327 entry, *controller_, reload_type, navigation_start, &navigate_params); 318 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
328 return manager->RequestNavigation(entry, navigate_params); 319 render_frame_host->frame_tree_node()->frame_tree_node_id(),
320 CommonNavigationParams(entry.GetURL(),
321 entry.GetReferrer(),
322 entry.GetTransitionType(),
323 navigation_type,
324 !entry.IsViewSourceMode()),
325 CommitNavigationParams(entry.GetPageState(),
326 entry.GetIsOverridingUserAgent(),
327 navigation_start)));
328 RequestNavigationParams request_params(entry.GetHasPostData(),
329 entry.extra_headers(),
330 entry.GetBrowserInitiatedPostData());
331 return manager->RequestNavigation(navigation_request.Pass(),
332 request_params);
329 } 333 }
330 334
331 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); 335 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry);
332 if (!dest_render_frame_host) 336 if (!dest_render_frame_host)
333 return false; // Unable to create the desired RenderFrameHost. 337 return false; // Unable to create the desired RenderFrameHost.
334 338
335 // Make sure no code called via RFHM::Navigate clears the pending entry. 339 // Make sure no code called via RFHM::Navigate clears the pending entry.
336 CHECK_EQ(controller_->GetPendingEntry(), &entry); 340 CHECK_EQ(controller_->GetPendingEntry(), &entry);
337 341
338 // For security, we should never send non-Web-UI URLs to a Web UI renderer. 342 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
339 // Double check that here. 343 // Double check that here.
340 CheckWebUIRendererDoesNotDisplayNormalURL( 344 CheckWebUIRendererDoesNotDisplayNormalURL(
341 dest_render_frame_host, entry.GetURL()); 345 dest_render_frame_host, entry.GetURL());
342 346
343 // Notify observers that we will navigate in this RenderFrame. 347 // Notify observers that we will navigate in this RenderFrame.
344 if (delegate_) 348 if (delegate_)
345 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); 349 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host);
346 350
347 // Create the navigation parameters. 351 // Create the navigation parameters.
348 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once 352 // TODO(vitalybuka): Move this before AboutToNavigateRenderFrame once
349 // http://crbug.com/408684 is fixed. 353 // http://crbug.com/408684 is fixed.
354 FrameMsg_Navigate_Params navigate_params;
350 MakeNavigateParams( 355 MakeNavigateParams(
351 entry, *controller_, reload_type, navigation_start, &navigate_params); 356 entry, controller_, reload_type, navigation_start, &navigate_params);
352 357
353 // Navigate in the desired RenderFrameHost. 358 // Navigate in the desired RenderFrameHost.
354 // We can skip this step in the rare case that this is a transfer navigation 359 // We can skip this step in the rare case that this is a transfer navigation
355 // which began in the chosen RenderFrameHost, since the request has already 360 // which began in the chosen RenderFrameHost, since the request has already
356 // been issued. In that case, simply resume the response. 361 // been issued. In that case, simply resume the response.
357 bool is_transfer_to_same = 362 bool is_transfer_to_same =
358 navigate_params.transferred_request_child_id != -1 && 363 navigate_params.transferred_request_child_id != -1 &&
359 navigate_params.transferred_request_child_id == 364 navigate_params.transferred_request_child_id ==
360 dest_render_frame_host->GetProcess()->GetID(); 365 dest_render_frame_host->GetProcess()->GetID();
361 if (!is_transfer_to_same) { 366 if (!is_transfer_to_same) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 // Navigations in Web UI pages count as browser-initiated navigations. 634 // Navigations in Web UI pages count as browser-initiated navigations.
630 params.is_renderer_initiated = false; 635 params.is_renderer_initiated = false;
631 } 636 }
632 637
633 if (delegate_) 638 if (delegate_)
634 delegate_->RequestOpenURL(render_frame_host, params); 639 delegate_->RequestOpenURL(render_frame_host, params);
635 } 640 }
636 641
637 void NavigatorImpl::CommitNavigation( 642 void NavigatorImpl::CommitNavigation(
638 RenderFrameHostImpl* render_frame_host, 643 RenderFrameHostImpl* render_frame_host,
639 const NavigationBeforeCommitInfo& info) { 644 const GURL& stream_url,
640 CheckWebUIRendererDoesNotDisplayNormalURL( 645 const CommonNavigationParams& common_params,
641 render_frame_host, info.navigation_url); 646 const CommitNavigationParams& commit_params) {
642 // TODO(clamy): the render_frame_host should now send a commit IPC to the 647 CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
643 // renderer. 648 common_params.url);
649 render_frame_host->CommitNavigation(stream_url, common_params, commit_params);
644 } 650 }
645 651
646 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( 652 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(
647 RenderFrameHostImpl* render_frame_host, 653 RenderFrameHostImpl* render_frame_host,
648 const GURL& url) { 654 const GURL& url) {
649 int enabled_bindings = 655 int enabled_bindings =
650 render_frame_host->render_view_host()->GetEnabledBindings(); 656 render_frame_host->render_view_host()->GetEnabledBindings();
651 bool is_allowed_in_web_ui_renderer = 657 bool is_allowed_in_web_ui_renderer =
652 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( 658 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
653 controller_->GetBrowserContext(), url); 659 controller_->GetBrowserContext(), url);
654 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && 660 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
655 !is_allowed_in_web_ui_renderer) { 661 !is_allowed_in_web_ui_renderer) {
656 // Log the URL to help us diagnose any future failures of this CHECK. 662 // Log the URL to help us diagnose any future failures of this CHECK.
657 GetContentClient()->SetActiveURL(url); 663 GetContentClient()->SetActiveURL(url);
658 CHECK(0); 664 CHECK(0);
659 } 665 }
660 } 666 }
661 667
662 } // namespace content 668 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698