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

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

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Adding a DCHECK to probably make a lot of tests fail. 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 base::Optional<url::Origin> initiator = 213 base::Optional<url::Origin> initiator =
214 frame_tree_node->IsMainFrame() 214 frame_tree_node->IsMainFrame()
215 ? base::Optional<url::Origin>() 215 ? base::Optional<url::Origin>()
216 : base::Optional<url::Origin>( 216 : base::Optional<url::Origin>(
217 frame_tree_node->frame_tree()->root()->current_origin()); 217 frame_tree_node->frame_tree()->root()->current_origin());
218 218
219 // While the navigation was started via the LoadURL path it may have come from 219 // While the navigation was started via the LoadURL path it may have come from
220 // the renderer in the first place as part of OpenURL. 220 // the renderer in the first place as part of OpenURL.
221 bool browser_initiated = !entry.is_renderer_initiated(); 221 bool browser_initiated = !entry.is_renderer_initiated();
222 222
223 bool is_history_navigation = frame_entry.page_state().IsValid();
224
225 // A same-document fragment-navigation happens when the only part of the url
226 // that is modified is after the '#' character.
227 // Be careful not to consider history navigations. For instance, if the
228 // history is: 'A#bar' -> 'B' -> 'A#foo'. Then an history navigation from
229 // 'A#foo' to 'A#bar' is not a same-document navigation, but a
230 // different-document one! The two FrameNavigationEntry doesn't share the same
231 // document_sequence_number.
232 bool is_same_document_fragment_change =
233 net::IsFragmentAddedOrUpdated(frame_tree_node->current_url(), dest_url) &&
234 !is_history_navigation;
nasko 2017/01/13 19:36:57 Thanks for the comment! I was discussing this logi
arthursonzogni 2017/01/17 15:24:47 Thanks for shouldPerformFragmentNavigation. I will
235
223 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( 236 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
224 frame_tree_node, entry.ConstructCommonNavigationParams( 237 frame_tree_node, entry.ConstructCommonNavigationParams(
225 frame_entry, request_body, dest_url, dest_referrer, 238 frame_entry, request_body, dest_url, dest_referrer,
226 navigation_type, previews_state, navigation_start), 239 navigation_type, previews_state, navigation_start),
227 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, 240 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL,
228 false, // has_user_gestures 241 false, // has_user_gestures
229 false, // skip_service_worker 242 false, // skip_service_worker
230 REQUEST_CONTEXT_TYPE_LOCATION, 243 REQUEST_CONTEXT_TYPE_LOCATION,
231 blink::WebMixedContentContextType::Blockable, 244 blink::WebMixedContentContextType::Blockable,
232 initiator), 245 initiator),
233 entry.ConstructRequestNavigationParams( 246 entry.ConstructRequestNavigationParams(
234 frame_entry, is_same_document_history_load, 247 frame_entry, is_same_document_fragment_change,
235 is_history_navigation_in_new_child, 248 is_same_document_history_load, is_history_navigation_in_new_child,
236 entry.GetSubframeUniqueNames(frame_tree_node), 249 entry.GetSubframeUniqueNames(frame_tree_node),
237 frame_tree_node->has_committed_real_load(), 250 frame_tree_node->has_committed_real_load(),
238 controller->GetPendingEntryIndex() == -1, 251 controller->GetPendingEntryIndex() == -1,
239 controller->GetIndexOfEntry(&entry), 252 controller->GetIndexOfEntry(&entry),
240 controller->GetLastCommittedEntryIndex(), 253 controller->GetLastCommittedEntryIndex(),
241 controller->GetEntryCount()), 254 controller->GetEntryCount()),
242 browser_initiated, 255 browser_initiated,
243 true, // may_transfer 256 true, // may_transfer
244 &frame_entry, &entry)); 257 &frame_entry, &entry));
245 return navigation_request; 258 return navigation_request;
246 } 259 }
247 260
248 // static 261 // static
249 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 262 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
250 FrameTreeNode* frame_tree_node, 263 FrameTreeNode* frame_tree_node,
251 const CommonNavigationParams& common_params, 264 const CommonNavigationParams& common_params,
252 const BeginNavigationParams& begin_params, 265 const BeginNavigationParams& begin_params,
253 int current_history_list_offset, 266 int current_history_list_offset,
254 int current_history_list_length) { 267 int current_history_list_length) {
255 // TODO(clamy): Check if some PageState should be provided here. 268
269 // No renderer-initiated same-document navigation are using this method. The
270 // navigation takes place in the renderer without asking the browser to
271 // navigate.
272 DCHECK(net::IsFragmentAddedOrUpdated(frame_tree_node->current_url(),
273 common_params.url));
274
275 // Please note that no history-navigation uses this method as well.
nasko 2017/01/13 19:36:57 nit: Put the comments together before the DCHECK.
276
256 // TODO(clamy): See how we should handle override of the user agent when the 277 // 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. 278 // 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 279 // 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. 280 // renderer and sent to the browser instead of being measured here.
260 // TODO(clamy): The pending history list offset should be properly set. 281 // TODO(clamy): The pending history list offset should be properly set.
261 RequestNavigationParams request_params( 282 RequestNavigationParams request_params(
262 false, // is_overriding_user_agent 283 false, // is_overriding_user_agent
263 std::vector<GURL>(), // redirects 284 std::vector<GURL>(), // redirects
264 false, // can_load_local_resources 285 false, // can_load_local_resources
265 PageState(), // page_state 286 PageState(), // page_state
266 0, // nav_entry_id 287 0, // nav_entry_id
267 false, // is_same_document_history_load 288 false, // is_same_document_fragment_change
268 false, // is_history_navigation_in_new_child 289 false, // is_same_document_history_load
269 std::map<std::string, bool>(), // subframe_unique_names 290 false, // is_history_navigation_in_new_child
291 std::map<std::string, bool>(), // subframe_unique_names
270 frame_tree_node->has_committed_real_load(), 292 frame_tree_node->has_committed_real_load(),
271 false, // intended_as_new_entry 293 false, // intended_as_new_entry
272 -1, // pending_history_list_offset 294 -1, // pending_history_list_offset
273 current_history_list_offset, current_history_list_length, 295 current_history_list_offset, current_history_list_length,
274 false, // is_view_source 296 false, // is_view_source
275 false, // should_clear_history_list 297 false, // should_clear_history_list
276 begin_params.has_user_gesture); 298 begin_params.has_user_gesture);
277 std::unique_ptr<NavigationRequest> navigation_request( 299 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
278 new NavigationRequest(frame_tree_node, common_params, begin_params, 300 frame_tree_node, common_params, begin_params, request_params,
279 request_params, 301 false, // browser_initiated
280 false, // browser_initiated 302 false, // may_transfer
281 false, // may_transfer 303 nullptr, nullptr));
282 nullptr, nullptr));
283 return navigation_request; 304 return navigation_request;
284 } 305 }
285 306
286 NavigationRequest::NavigationRequest( 307 NavigationRequest::NavigationRequest(
287 FrameTreeNode* frame_tree_node, 308 FrameTreeNode* frame_tree_node,
288 const CommonNavigationParams& common_params, 309 const CommonNavigationParams& common_params,
289 const BeginNavigationParams& begin_params, 310 const BeginNavigationParams& begin_params,
290 const RequestNavigationParams& request_params, 311 const RequestNavigationParams& request_params,
291 bool browser_initiated, 312 bool browser_initiated,
292 bool may_transfer, 313 bool may_transfer,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 360
340 NavigationRequest::~NavigationRequest() { 361 NavigationRequest::~NavigationRequest() {
341 } 362 }
342 363
343 void NavigationRequest::BeginNavigation() { 364 void NavigationRequest::BeginNavigation() {
344 DCHECK(!loader_); 365 DCHECK(!loader_);
345 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 366 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
346 state_ = STARTED; 367 state_ = STARTED;
347 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 368 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
348 369
349 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { 370 if (ShouldMakeNetworkRequestForURL(common_params_.url) &&
371 !navigation_handle_->IsSamePage()) {
350 // It's safe to use base::Unretained because this NavigationRequest owns 372 // It's safe to use base::Unretained because this NavigationRequest owns
351 // the NavigationHandle where the callback will be stored. 373 // the NavigationHandle where the callback will be stored.
352 // TODO(clamy): pass the real value for |is_external_protocol| if needed. 374 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
353 // TODO(clamy): pass the method to the NavigationHandle instead of a 375 // TODO(clamy): pass the method to the NavigationHandle instead of a
354 // boolean. 376 // boolean.
355 navigation_handle_->WillStartRequest( 377 navigation_handle_->WillStartRequest(
356 common_params_.method, common_params_.post_data, 378 common_params_.method, common_params_.post_data,
357 Referrer::SanitizeForRequest(common_params_.url, 379 Referrer::SanitizeForRequest(common_params_.url,
358 common_params_.referrer), 380 common_params_.referrer),
359 begin_params_.has_user_gesture, common_params_.transition, false, 381 begin_params_.has_user_gesture, common_params_.transition, false,
(...skipping 14 matching lines...) Expand all
374 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 396 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
375 common_params_.url); 397 common_params_.url);
376 398
377 // Inform the NavigationHandle that the navigation will commit. 399 // Inform the NavigationHandle that the navigation will commit.
378 navigation_handle_->ReadyToCommitNavigation(render_frame_host); 400 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
379 401
380 CommitNavigation(); 402 CommitNavigation();
381 } 403 }
382 404
383 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 405 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
384 // TODO(nasko): Update the NavigationHandle creation to ensure that the 406 bool is_same_page = request_params_.is_same_document_fragment_change ||
385 // proper values are specified for is_same_page. 407 request_params_.is_same_document_history_load;
408
386 navigation_handle_ = NavigationHandleImpl::Create( 409 navigation_handle_ = NavigationHandleImpl::Create(
387 common_params_.url, frame_tree_node_, !browser_initiated_, 410 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, 411 common_params_.navigation_start, pending_nav_entry_id,
390 false); // started_in_context_menu 412 false); // started_in_context_menu
391 413
392 if (!begin_params_.searchable_form_url.is_empty()) { 414 if (!begin_params_.searchable_form_url.is_empty()) {
393 navigation_handle_->set_searchable_form_url( 415 navigation_handle_->set_searchable_form_url(
394 begin_params_.searchable_form_url); 416 begin_params_.searchable_form_url);
395 navigation_handle_->set_searchable_form_encoding( 417 navigation_handle_->set_searchable_form_encoding(
396 begin_params_.searchable_form_encoding); 418 begin_params_.searchable_form_encoding);
397 } 419 }
398 } 420 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 // Have the processing of the response resume in the network stack. 712 // Have the processing of the response resume in the network stack.
691 loader_->ProceedWithResponse(); 713 loader_->ProceedWithResponse();
692 714
693 CommitNavigation(); 715 CommitNavigation();
694 716
695 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused 717 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused
696 // the destruction of the NavigationRequest. 718 // the destruction of the NavigationRequest.
697 } 719 }
698 720
699 void NavigationRequest::CommitNavigation() { 721 void NavigationRequest::CommitNavigation() {
700 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url)); 722 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url) ||
723 navigation_handle_->IsSamePage());
701 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); 724 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme));
702 725
703 // Retrieve the RenderFrameHost that needs to commit the navigation. 726 // Retrieve the RenderFrameHost that needs to commit the navigation.
704 RenderFrameHostImpl* render_frame_host = 727 RenderFrameHostImpl* render_frame_host =
705 navigation_handle_->GetRenderFrameHost(); 728 navigation_handle_->GetRenderFrameHost();
706 DCHECK(render_frame_host == 729 DCHECK(render_frame_host ==
707 frame_tree_node_->render_manager()->current_frame_host() || 730 frame_tree_node_->render_manager()->current_frame_host() ||
708 render_frame_host == 731 render_frame_host ==
709 frame_tree_node_->render_manager()->speculative_frame_host()); 732 frame_tree_node_->render_manager()->speculative_frame_host());
710 733
711 TransferNavigationHandleOwnership(render_frame_host); 734 TransferNavigationHandleOwnership(render_frame_host);
712 735
713 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 736 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
714 737
715 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 738 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
716 common_params_, request_params_, 739 common_params_, request_params_,
717 is_view_source_); 740 is_view_source_);
718 741
719 frame_tree_node_->ResetNavigationRequest(true); 742 frame_tree_node_->ResetNavigationRequest(true);
720 } 743 }
721 744
722 } // namespace content 745 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698