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