 Chromium Code Reviews
 Chromium Code Reviews Issue 2584513003:
  PlzNavigate: identify same-page browser-initiated navigation.  (Closed)
    
  
    Issue 2584513003:
  PlzNavigate: identify same-page browser-initiated navigation.  (Closed) 
  | OLD | NEW | 
|---|---|
| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 base::Optional<url::Origin> initiator = | 215 base::Optional<url::Origin> initiator = | 
| 216 frame_tree_node->IsMainFrame() | 216 frame_tree_node->IsMainFrame() | 
| 217 ? base::Optional<url::Origin>() | 217 ? base::Optional<url::Origin>() | 
| 218 : base::Optional<url::Origin>( | 218 : base::Optional<url::Origin>( | 
| 219 frame_tree_node->frame_tree()->root()->current_origin()); | 219 frame_tree_node->frame_tree()->root()->current_origin()); | 
| 220 | 220 | 
| 221 // While the navigation was started via the LoadURL path it may have come from | 221 // While the navigation was started via the LoadURL path it may have come from | 
| 222 // the renderer in the first place as part of OpenURL. | 222 // the renderer in the first place as part of OpenURL. | 
| 223 bool browser_initiated = !entry.is_renderer_initiated(); | 223 bool browser_initiated = !entry.is_renderer_initiated(); | 
| 224 | 224 | 
| 225 bool is_history_navigation = frame_entry.page_state().IsValid(); | |
| 226 bool is_same_document_fragment_change = | |
| 227 net::AreURLsInPageNavigation(frame_tree_node->current_url(), dest_url) && | |
| 228 !is_history_navigation; | |
| 
nasko
2017/01/13 02:51:10
Can you put a comment why is_history_navigation ne
 
arthursonzogni
2017/01/13 15:18:37
Yes, it is more than useful.
Done.
 | |
| 229 | |
| 225 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 230 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 
| 226 frame_tree_node, entry.ConstructCommonNavigationParams( | 231 frame_tree_node, | 
| 227 frame_entry, request_body, dest_url, dest_referrer, | 232 entry.ConstructCommonNavigationParams(frame_entry, request_body, dest_url, | 
| 228 navigation_type, lofi_state, navigation_start), | 233 dest_referrer, navigation_type, | 
| 234 lofi_state, navigation_start), | |
| 229 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, | 235 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, | 
| 230 false, // has_user_gestures | 236 false, // has_user_gestures | 
| 231 false, // skip_service_worker | 237 false, // skip_service_worker | 
| 232 REQUEST_CONTEXT_TYPE_LOCATION, | 238 REQUEST_CONTEXT_TYPE_LOCATION, | 
| 233 blink::WebMixedContentContextType::Blockable, | 239 blink::WebMixedContentContextType::Blockable, | 
| 234 initiator), | 240 initiator), | 
| 235 entry.ConstructRequestNavigationParams( | 241 entry.ConstructRequestNavigationParams( | 
| 236 frame_entry, is_same_document_history_load, | 242 frame_entry, is_same_document_fragment_change, | 
| 237 is_history_navigation_in_new_child, | 243 is_same_document_history_load, is_history_navigation_in_new_child, | 
| 238 entry.GetSubframeUniqueNames(frame_tree_node), | 244 entry.GetSubframeUniqueNames(frame_tree_node), | 
| 239 frame_tree_node->has_committed_real_load(), | 245 frame_tree_node->has_committed_real_load(), | 
| 240 controller->GetPendingEntryIndex() == -1, | 246 controller->GetPendingEntryIndex() == -1, | 
| 241 controller->GetIndexOfEntry(&entry), | 247 controller->GetIndexOfEntry(&entry), | 
| 242 controller->GetLastCommittedEntryIndex(), | 248 controller->GetLastCommittedEntryIndex(), | 
| 243 controller->GetEntryCount()), | 249 controller->GetEntryCount()), | 
| 244 browser_initiated, | 250 browser_initiated, | 
| 245 true, // may_transfer | 251 true, // may_transfer | 
| 246 &frame_entry, &entry)); | 252 &frame_entry, &entry)); | 
| 247 return navigation_request; | 253 return navigation_request; | 
| 248 } | 254 } | 
| 249 | 255 | 
| 250 // static | 256 // static | 
| 251 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( | 257 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( | 
| 252 FrameTreeNode* frame_tree_node, | 258 FrameTreeNode* frame_tree_node, | 
| 253 const CommonNavigationParams& common_params, | 259 const CommonNavigationParams& common_params, | 
| 254 const BeginNavigationParams& begin_params, | 260 const BeginNavigationParams& begin_params, | 
| 255 int current_history_list_offset, | 261 int current_history_list_offset, | 
| 256 int current_history_list_length) { | 262 int current_history_list_length) { | 
| 263 bool is_same_document_fragment_change = net::AreURLsInPageNavigation( | |
| 264 frame_tree_node->current_url(), common_params.url); | |
| 265 | |
| 257 // TODO(clamy): Check if some PageState should be provided here. | 266 // TODO(clamy): Check if some PageState should be provided here. | 
| 
arthursonzogni
2017/01/13 15:18:37
Do we know now? Does history navigations could cal
 | |
| 258 // TODO(clamy): See how we should handle override of the user agent when the | 267 // TODO(clamy): See how we should handle override of the user agent when the | 
| 259 // navigation may start in a renderer and commit in another one. | 268 // navigation may start in a renderer and commit in another one. | 
| 260 // TODO(clamy): See if the navigation start time should be measured in the | 269 // TODO(clamy): See if the navigation start time should be measured in the | 
| 261 // renderer and sent to the browser instead of being measured here. | 270 // renderer and sent to the browser instead of being measured here. | 
| 262 // TODO(clamy): The pending history list offset should be properly set. | 271 // TODO(clamy): The pending history list offset should be properly set. | 
| 263 RequestNavigationParams request_params( | 272 RequestNavigationParams request_params( | 
| 264 false, // is_overriding_user_agent | 273 false, // is_overriding_user_agent | 
| 265 std::vector<GURL>(), // redirects | 274 std::vector<GURL>(), // redirects | 
| 266 false, // can_load_local_resources | 275 false, // can_load_local_resources | 
| 267 PageState(), // page_state | 276 PageState(), // page_state | 
| 268 0, // nav_entry_id | 277 0, // nav_entry_id | 
| 269 false, // is_same_document_history_load | 278 is_same_document_fragment_change, // is_same_document_fragment_change | 
| 270 false, // is_history_navigation_in_new_child | 279 false, // is_same_document_history_load | 
| 271 std::map<std::string, bool>(), // subframe_unique_names | 280 false, // is_history_navigation_in_new_child | 
| 281 std::map<std::string, bool>(), // subframe_unique_names | |
| 272 frame_tree_node->has_committed_real_load(), | 282 frame_tree_node->has_committed_real_load(), | 
| 273 false, // intended_as_new_entry | 283 false, // intended_as_new_entry | 
| 274 -1, // pending_history_list_offset | 284 -1, // pending_history_list_offset | 
| 275 current_history_list_offset, current_history_list_length, | 285 current_history_list_offset, current_history_list_length, | 
| 276 false, // is_view_source | 286 false, // is_view_source | 
| 277 false, // should_clear_history_list | 287 false, // should_clear_history_list | 
| 278 begin_params.has_user_gesture); | 288 begin_params.has_user_gesture); | 
| 279 std::unique_ptr<NavigationRequest> navigation_request( | 289 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 
| 280 new NavigationRequest(frame_tree_node, common_params, begin_params, | 290 frame_tree_node, common_params, begin_params, request_params, | 
| 281 request_params, | 291 false, // browser_initiated | 
| 282 false, // browser_initiated | 292 false, // may_transfer | 
| 283 false, // may_transfer | 293 nullptr, nullptr)); | 
| 284 nullptr, nullptr)); | |
| 285 return navigation_request; | 294 return navigation_request; | 
| 286 } | 295 } | 
| 287 | 296 | 
| 288 NavigationRequest::NavigationRequest( | 297 NavigationRequest::NavigationRequest( | 
| 289 FrameTreeNode* frame_tree_node, | 298 FrameTreeNode* frame_tree_node, | 
| 290 const CommonNavigationParams& common_params, | 299 const CommonNavigationParams& common_params, | 
| 291 const BeginNavigationParams& begin_params, | 300 const BeginNavigationParams& begin_params, | 
| 292 const RequestNavigationParams& request_params, | 301 const RequestNavigationParams& request_params, | 
| 293 bool browser_initiated, | 302 bool browser_initiated, | 
| 294 bool may_transfer, | 303 bool may_transfer, | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 | 350 | 
| 342 NavigationRequest::~NavigationRequest() { | 351 NavigationRequest::~NavigationRequest() { | 
| 343 } | 352 } | 
| 344 | 353 | 
| 345 void NavigationRequest::BeginNavigation() { | 354 void NavigationRequest::BeginNavigation() { | 
| 346 DCHECK(!loader_); | 355 DCHECK(!loader_); | 
| 347 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 356 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 
| 348 state_ = STARTED; | 357 state_ = STARTED; | 
| 349 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 358 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 
| 350 | 359 | 
| 351 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 360 if (ShouldMakeNetworkRequestForURL(common_params_.url) && | 
| 361 !navigation_handle_->IsSamePage()) { | |
| 352 // It's safe to use base::Unretained because this NavigationRequest owns | 362 // It's safe to use base::Unretained because this NavigationRequest owns | 
| 353 // the NavigationHandle where the callback will be stored. | 363 // the NavigationHandle where the callback will be stored. | 
| 354 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 364 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 
| 355 // TODO(clamy): pass the method to the NavigationHandle instead of a | 365 // TODO(clamy): pass the method to the NavigationHandle instead of a | 
| 356 // boolean. | 366 // boolean. | 
| 357 navigation_handle_->WillStartRequest( | 367 navigation_handle_->WillStartRequest( | 
| 358 common_params_.method, common_params_.post_data, | 368 common_params_.method, common_params_.post_data, | 
| 359 Referrer::SanitizeForRequest(common_params_.url, | 369 Referrer::SanitizeForRequest(common_params_.url, | 
| 360 common_params_.referrer), | 370 common_params_.referrer), | 
| 361 begin_params_.has_user_gesture, common_params_.transition, false, | 371 begin_params_.has_user_gesture, common_params_.transition, false, | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 376 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, | 386 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, | 
| 377 common_params_.url); | 387 common_params_.url); | 
| 378 | 388 | 
| 379 // Inform the NavigationHandle that the navigation will commit. | 389 // Inform the NavigationHandle that the navigation will commit. | 
| 380 navigation_handle_->ReadyToCommitNavigation(render_frame_host); | 390 navigation_handle_->ReadyToCommitNavigation(render_frame_host); | 
| 381 | 391 | 
| 382 CommitNavigation(); | 392 CommitNavigation(); | 
| 383 } | 393 } | 
| 384 | 394 | 
| 385 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { | 395 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { | 
| 386 // TODO(nasko): Update the NavigationHandle creation to ensure that the | 396 bool is_same_page = request_params_.is_same_document_fragment_change || | 
| 387 // proper values are specified for is_same_page. | 397 request_params_.is_same_document_history_load; | 
| 398 | |
| 388 navigation_handle_ = NavigationHandleImpl::Create( | 399 navigation_handle_ = NavigationHandleImpl::Create( | 
| 389 common_params_.url, frame_tree_node_, !browser_initiated_, | 400 common_params_.url, frame_tree_node_, !browser_initiated_, is_same_page, | 
| 390 false, // is_same_page | |
| 391 common_params_.navigation_start, pending_nav_entry_id, | 401 common_params_.navigation_start, pending_nav_entry_id, | 
| 392 false); // started_in_context_menu | 402 false); // started_in_context_menu | 
| 393 | 403 | 
| 394 if (!begin_params_.searchable_form_url.is_empty()) { | 404 if (!begin_params_.searchable_form_url.is_empty()) { | 
| 395 navigation_handle_->set_searchable_form_url( | 405 navigation_handle_->set_searchable_form_url( | 
| 396 begin_params_.searchable_form_url); | 406 begin_params_.searchable_form_url); | 
| 397 navigation_handle_->set_searchable_form_encoding( | 407 navigation_handle_->set_searchable_form_encoding( | 
| 398 begin_params_.searchable_form_encoding); | 408 begin_params_.searchable_form_encoding); | 
| 399 } | 409 } | 
| 400 } | 410 } | 
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 // Have the processing of the response resume in the network stack. | 705 // Have the processing of the response resume in the network stack. | 
| 696 loader_->ProceedWithResponse(); | 706 loader_->ProceedWithResponse(); | 
| 697 | 707 | 
| 698 CommitNavigation(); | 708 CommitNavigation(); | 
| 699 | 709 | 
| 700 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused | 710 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused | 
| 701 // the destruction of the NavigationRequest. | 711 // the destruction of the NavigationRequest. | 
| 702 } | 712 } | 
| 703 | 713 | 
| 704 void NavigationRequest::CommitNavigation() { | 714 void NavigationRequest::CommitNavigation() { | 
| 705 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url)); | 715 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url) || | 
| 716 navigation_handle_->IsSamePage()); | |
| 706 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); | 717 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); | 
| 707 | 718 | 
| 708 // Retrieve the RenderFrameHost that needs to commit the navigation. | 719 // Retrieve the RenderFrameHost that needs to commit the navigation. | 
| 709 RenderFrameHostImpl* render_frame_host = | 720 RenderFrameHostImpl* render_frame_host = | 
| 710 navigation_handle_->GetRenderFrameHost(); | 721 navigation_handle_->GetRenderFrameHost(); | 
| 711 DCHECK(render_frame_host == | 722 DCHECK(render_frame_host == | 
| 712 frame_tree_node_->render_manager()->current_frame_host() || | 723 frame_tree_node_->render_manager()->current_frame_host() || | 
| 713 render_frame_host == | 724 render_frame_host == | 
| 714 frame_tree_node_->render_manager()->speculative_frame_host()); | 725 frame_tree_node_->render_manager()->speculative_frame_host()); | 
| 715 | 726 | 
| 716 TransferNavigationHandleOwnership(render_frame_host); | 727 TransferNavigationHandleOwnership(render_frame_host); | 
| 717 | 728 | 
| 718 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 729 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 
| 719 | 730 | 
| 720 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 731 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 
| 721 common_params_, request_params_, | 732 common_params_, request_params_, | 
| 722 is_view_source_); | 733 is_view_source_); | 
| 723 | 734 | 
| 724 frame_tree_node_->ResetNavigationRequest(true); | 735 frame_tree_node_->ResetNavigationRequest(true); | 
| 725 } | 736 } | 
| 726 | 737 | 
| 727 } // namespace content | 738 } // namespace content | 
| OLD | NEW |