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

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

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Refactor with FrameMsg_Navigate_type (nits) Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/navigation_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "content/browser/appcache/appcache_navigation_handle.h" 10 #include "content/browser/appcache/appcache_navigation_handle.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: 65 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
66 *load_flags |= net::LOAD_BYPASS_CACHE; 66 *load_flags |= net::LOAD_BYPASS_CACHE;
67 break; 67 break;
68 case FrameMsg_Navigate_Type::RESTORE: 68 case FrameMsg_Navigate_Type::RESTORE:
69 *load_flags |= net::LOAD_SKIP_CACHE_VALIDATION; 69 *load_flags |= net::LOAD_SKIP_CACHE_VALIDATION;
70 break; 70 break;
71 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: 71 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
72 *load_flags |= 72 *load_flags |=
73 net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION; 73 net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION;
74 break; 74 break;
75 case FrameMsg_Navigate_Type::NORMAL: 75 case FrameMsg_Navigate_Type::SAME_DOCUMENT:
76 case FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT:
77 case FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT:
78 case FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT:
76 if (is_post) 79 if (is_post)
77 *load_flags |= net::LOAD_VALIDATE_CACHE; 80 *load_flags |= net::LOAD_VALIDATE_CACHE;
78 break; 81 break;
79 default: 82 case FrameMsg_Navigate_Type::UNSPECIFIED:
80 break; 83 NOTREACHED();
81 } 84 }
82 } 85 }
83 86
84 // This is based on SecurityOrigin::isPotentiallyTrustworthy. 87 // This is based on SecurityOrigin::isPotentiallyTrustworthy.
85 // TODO(clamy): This should be function in url::Origin. 88 // TODO(clamy): This should be function in url::Origin.
86 bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) { 89 bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) {
87 if (origin.unique()) 90 if (origin.unique())
88 return false; 91 return false;
89 92
90 if (origin.scheme() == url::kHttpsScheme || 93 if (origin.scheme() == url::kHttpsScheme ||
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 frame_tree_node, entry.ConstructCommonNavigationParams( 227 frame_tree_node, entry.ConstructCommonNavigationParams(
225 frame_entry, request_body, dest_url, dest_referrer, 228 frame_entry, request_body, dest_url, dest_referrer,
226 navigation_type, previews_state, navigation_start), 229 navigation_type, previews_state, navigation_start),
227 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, 230 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL,
228 false, // has_user_gestures 231 false, // has_user_gestures
229 false, // skip_service_worker 232 false, // skip_service_worker
230 REQUEST_CONTEXT_TYPE_LOCATION, 233 REQUEST_CONTEXT_TYPE_LOCATION,
231 blink::WebMixedContentContextType::Blockable, 234 blink::WebMixedContentContextType::Blockable,
232 initiator), 235 initiator),
233 entry.ConstructRequestNavigationParams( 236 entry.ConstructRequestNavigationParams(
234 frame_entry, is_same_document_history_load, 237 frame_entry, is_history_navigation_in_new_child,
235 is_history_navigation_in_new_child,
236 entry.GetSubframeUniqueNames(frame_tree_node), 238 entry.GetSubframeUniqueNames(frame_tree_node),
237 frame_tree_node->has_committed_real_load(), 239 frame_tree_node->has_committed_real_load(),
238 controller->GetPendingEntryIndex() == -1, 240 controller->GetPendingEntryIndex() == -1,
239 controller->GetIndexOfEntry(&entry), 241 controller->GetIndexOfEntry(&entry),
240 controller->GetLastCommittedEntryIndex(), 242 controller->GetLastCommittedEntryIndex(),
241 controller->GetEntryCount()), 243 controller->GetEntryCount()),
242 browser_initiated, 244 browser_initiated,
243 true, // may_transfer 245 true, // may_transfer
244 &frame_entry, &entry)); 246 &frame_entry, &entry));
245 return navigation_request; 247 return navigation_request;
246 } 248 }
247 249
248 // static 250 // static
249 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 251 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
250 FrameTreeNode* frame_tree_node, 252 FrameTreeNode* frame_tree_node,
251 const CommonNavigationParams& common_params, 253 const CommonNavigationParams& common_params,
252 const BeginNavigationParams& begin_params, 254 const BeginNavigationParams& begin_params,
253 int current_history_list_offset, 255 int current_history_list_offset,
254 int current_history_list_length) { 256 int current_history_list_length) {
255 // TODO(clamy): Check if some PageState should be provided here. 257 // No history-navigation uses this method.
nasko 2017/01/19 00:43:35 Why did this TODO disappear? Are we sure PageState
arthursonzogni 2017/01/19 17:49:21 Yes I believe that no PageState should be provided
258 DCHECK(!FrameMsg_Navigate_Type::IsHistory(common_params.navigation_type));
259 // No fragment-navigation uses this method because the navigation takes place
nasko 2017/01/19 00:43:35 nit: Empty line before the comment.
arthursonzogni 2017/01/19 17:49:21 Acknowledged.
260 // in the renderer without asking the browser to navigate.
261 DCHECK(common_params.navigation_type !=
262 FrameMsg_Navigate_Type::SAME_DOCUMENT);
263
256 // TODO(clamy): See how we should handle override of the user agent when the 264 // TODO(clamy): See how we should handle override of the user agent when the
257 // navigation may start in a renderer and commit in another one. 265 // navigation may start in a renderer and commit in another one.
258 // TODO(clamy): See if the navigation start time should be measured in the 266 // TODO(clamy): See if the navigation start time should be measured in the
259 // renderer and sent to the browser instead of being measured here. 267 // renderer and sent to the browser instead of being measured here.
260 // TODO(clamy): The pending history list offset should be properly set. 268 // TODO(clamy): The pending history list offset should be properly set.
261 RequestNavigationParams request_params( 269 RequestNavigationParams request_params(
262 false, // is_overriding_user_agent 270 false, // is_overriding_user_agent
263 std::vector<GURL>(), // redirects 271 std::vector<GURL>(), // redirects
264 false, // can_load_local_resources 272 false, // can_load_local_resources
265 PageState(), // page_state 273 PageState(), // page_state
266 0, // nav_entry_id 274 0, // nav_entry_id
267 false, // is_same_document_history_load 275 false, // is_history_navigation_in_new_child
268 false, // is_history_navigation_in_new_child 276 std::map<std::string, bool>(), // subframe_unique_names
269 std::map<std::string, bool>(), // subframe_unique_names
270 frame_tree_node->has_committed_real_load(), 277 frame_tree_node->has_committed_real_load(),
271 false, // intended_as_new_entry 278 false, // intended_as_new_entry
272 -1, // pending_history_list_offset 279 -1, // pending_history_list_offset
273 current_history_list_offset, current_history_list_length, 280 current_history_list_offset, current_history_list_length,
274 false, // is_view_source 281 false, // is_view_source
275 false, // should_clear_history_list 282 false, // should_clear_history_list
276 begin_params.has_user_gesture); 283 begin_params.has_user_gesture);
277 std::unique_ptr<NavigationRequest> navigation_request( 284 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
278 new NavigationRequest(frame_tree_node, common_params, begin_params, 285 frame_tree_node, common_params, begin_params, request_params,
279 request_params, 286 false, // browser_initiated
280 false, // browser_initiated 287 false, // may_transfer
281 false, // may_transfer 288 nullptr, nullptr));
282 nullptr, nullptr));
283 return navigation_request; 289 return navigation_request;
284 } 290 }
285 291
286 NavigationRequest::NavigationRequest( 292 NavigationRequest::NavigationRequest(
287 FrameTreeNode* frame_tree_node, 293 FrameTreeNode* frame_tree_node,
288 const CommonNavigationParams& common_params, 294 const CommonNavigationParams& common_params,
289 const BeginNavigationParams& begin_params, 295 const BeginNavigationParams& begin_params,
290 const RequestNavigationParams& request_params, 296 const RequestNavigationParams& request_params,
291 bool browser_initiated, 297 bool browser_initiated,
292 bool may_transfer, 298 bool may_transfer,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 345
340 NavigationRequest::~NavigationRequest() { 346 NavigationRequest::~NavigationRequest() {
341 } 347 }
342 348
343 void NavigationRequest::BeginNavigation() { 349 void NavigationRequest::BeginNavigation() {
344 DCHECK(!loader_); 350 DCHECK(!loader_);
345 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 351 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
346 state_ = STARTED; 352 state_ = STARTED;
347 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 353 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
348 354
349 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { 355 if (ShouldMakeNetworkRequestForURL(common_params_.url) &&
356 !navigation_handle_->IsSamePage()) {
350 // It's safe to use base::Unretained because this NavigationRequest owns 357 // It's safe to use base::Unretained because this NavigationRequest owns
351 // the NavigationHandle where the callback will be stored. 358 // the NavigationHandle where the callback will be stored.
352 // TODO(clamy): pass the real value for |is_external_protocol| if needed. 359 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
353 // TODO(clamy): pass the method to the NavigationHandle instead of a 360 // TODO(clamy): pass the method to the NavigationHandle instead of a
354 // boolean. 361 // boolean.
355 navigation_handle_->WillStartRequest( 362 navigation_handle_->WillStartRequest(
356 common_params_.method, common_params_.post_data, 363 common_params_.method, common_params_.post_data,
357 Referrer::SanitizeForRequest(common_params_.url, 364 Referrer::SanitizeForRequest(common_params_.url,
358 common_params_.referrer), 365 common_params_.referrer),
359 begin_params_.has_user_gesture, common_params_.transition, false, 366 begin_params_.has_user_gesture, common_params_.transition, false,
(...skipping 14 matching lines...) Expand all
374 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 381 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
375 common_params_.url); 382 common_params_.url);
376 383
377 // Inform the NavigationHandle that the navigation will commit. 384 // Inform the NavigationHandle that the navigation will commit.
378 navigation_handle_->ReadyToCommitNavigation(render_frame_host); 385 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
379 386
380 CommitNavigation(); 387 CommitNavigation();
381 } 388 }
382 389
383 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 390 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
384 // TODO(nasko): Update the NavigationHandle creation to ensure that the 391 bool is_same_page =
385 // proper values are specified for is_same_page. 392 FrameMsg_Navigate_Type::IsSameDocument(common_params_.navigation_type);
nasko 2017/01/19 00:43:35 Why not call the method as part of the parameter p
arthursonzogni 2017/01/19 17:49:21 What you suggest looks good. Done.
393
386 navigation_handle_ = NavigationHandleImpl::Create( 394 navigation_handle_ = NavigationHandleImpl::Create(
387 common_params_.url, frame_tree_node_, !browser_initiated_, 395 common_params_.url, frame_tree_node_, !browser_initiated_, is_same_page,
388 false, // is_same_page
389 common_params_.navigation_start, pending_nav_entry_id, 396 common_params_.navigation_start, pending_nav_entry_id,
390 false); // started_in_context_menu 397 false); // started_in_context_menu
391 398
392 if (!begin_params_.searchable_form_url.is_empty()) { 399 if (!begin_params_.searchable_form_url.is_empty()) {
393 navigation_handle_->set_searchable_form_url( 400 navigation_handle_->set_searchable_form_url(
394 begin_params_.searchable_form_url); 401 begin_params_.searchable_form_url);
395 navigation_handle_->set_searchable_form_encoding( 402 navigation_handle_->set_searchable_form_encoding(
396 begin_params_.searchable_form_encoding); 403 begin_params_.searchable_form_encoding);
397 } 404 }
398 } 405 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 // Have the processing of the response resume in the network stack. 697 // Have the processing of the response resume in the network stack.
691 loader_->ProceedWithResponse(); 698 loader_->ProceedWithResponse();
692 699
693 CommitNavigation(); 700 CommitNavigation();
694 701
695 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused 702 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused
696 // the destruction of the NavigationRequest. 703 // the destruction of the NavigationRequest.
697 } 704 }
698 705
699 void NavigationRequest::CommitNavigation() { 706 void NavigationRequest::CommitNavigation() {
700 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url)); 707 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url) ||
708 navigation_handle_->IsSamePage());
701 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); 709 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme));
702 710
703 // Retrieve the RenderFrameHost that needs to commit the navigation. 711 // Retrieve the RenderFrameHost that needs to commit the navigation.
704 RenderFrameHostImpl* render_frame_host = 712 RenderFrameHostImpl* render_frame_host =
705 navigation_handle_->GetRenderFrameHost(); 713 navigation_handle_->GetRenderFrameHost();
706 DCHECK(render_frame_host == 714 DCHECK(render_frame_host ==
707 frame_tree_node_->render_manager()->current_frame_host() || 715 frame_tree_node_->render_manager()->current_frame_host() ||
708 render_frame_host == 716 render_frame_host ==
709 frame_tree_node_->render_manager()->speculative_frame_host()); 717 frame_tree_node_->render_manager()->speculative_frame_host());
710 718
711 TransferNavigationHandleOwnership(render_frame_host); 719 TransferNavigationHandleOwnership(render_frame_host);
712 720
713 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 721 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
714 722
715 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 723 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
716 common_params_, request_params_, 724 common_params_, request_params_,
717 is_view_source_); 725 is_view_source_);
718 726
719 frame_tree_node_->ResetNavigationRequest(true); 727 frame_tree_node_->ResetNavigationRequest(true);
720 } 728 }
721 729
722 } // namespace content 730 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698