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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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: |
|
nasko
2017/01/23 19:10:13
Let's see if we can just remove UNSPECIFIED and re
arthursonzogni
2017/01/24 15:17:04
Acknowledged.
| |
| 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 Loading... | |
| 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 // Only normal navigations to a different document or reloads are expected. |
| 258 // - Renderer-initiated fragment-navigations never take place in the browser, | |
| 259 // even with PlzNavigate. | |
| 260 // - Restore-navigations are always browser-initiated. | |
| 261 // - History-navigations use the browser-initiated path, event the ones that | |
| 262 // are initiated by a javascript script, please see the IPC message | |
| 263 // ViewHostMsg_GoToEntryAtOffset. | |
| 264 DCHECK(FrameMsg_Navigate_Type::IsReload(common_params.navigation_type) || | |
| 265 common_params.navigation_type == | |
| 266 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT); | |
| 267 | |
| 256 // TODO(clamy): See how we should handle override of the user agent when the | 268 // 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. | 269 // 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 | 270 // 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. | 271 // renderer and sent to the browser instead of being measured here. |
| 260 // TODO(clamy): The pending history list offset should be properly set. | 272 // TODO(clamy): The pending history list offset should be properly set. |
| 261 RequestNavigationParams request_params( | 273 RequestNavigationParams request_params( |
| 262 false, // is_overriding_user_agent | 274 false, // is_overriding_user_agent |
| 263 std::vector<GURL>(), // redirects | 275 std::vector<GURL>(), // redirects |
| 264 false, // can_load_local_resources | 276 false, // can_load_local_resources |
| 265 PageState(), // page_state | 277 PageState(), // page_state |
| 266 0, // nav_entry_id | 278 0, // nav_entry_id |
| 267 false, // is_same_document_history_load | 279 false, // is_history_navigation_in_new_child |
| 268 false, // is_history_navigation_in_new_child | 280 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(), | 281 frame_tree_node->has_committed_real_load(), |
| 271 false, // intended_as_new_entry | 282 false, // intended_as_new_entry |
| 272 -1, // pending_history_list_offset | 283 -1, // pending_history_list_offset |
| 273 current_history_list_offset, current_history_list_length, | 284 current_history_list_offset, current_history_list_length, |
| 274 false, // is_view_source | 285 false, // is_view_source |
| 275 false, // should_clear_history_list | 286 false, // should_clear_history_list |
| 276 begin_params.has_user_gesture); | 287 begin_params.has_user_gesture); |
| 277 std::unique_ptr<NavigationRequest> navigation_request( | 288 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
| 278 new NavigationRequest(frame_tree_node, common_params, begin_params, | 289 frame_tree_node, common_params, begin_params, request_params, |
| 279 request_params, | 290 false, // browser_initiated |
| 280 false, // browser_initiated | 291 false, // may_transfer |
| 281 false, // may_transfer | 292 nullptr, nullptr)); |
| 282 nullptr, nullptr)); | |
| 283 return navigation_request; | 293 return navigation_request; |
| 284 } | 294 } |
| 285 | 295 |
| 286 NavigationRequest::NavigationRequest( | 296 NavigationRequest::NavigationRequest( |
| 287 FrameTreeNode* frame_tree_node, | 297 FrameTreeNode* frame_tree_node, |
| 288 const CommonNavigationParams& common_params, | 298 const CommonNavigationParams& common_params, |
| 289 const BeginNavigationParams& begin_params, | 299 const BeginNavigationParams& begin_params, |
| 290 const RequestNavigationParams& request_params, | 300 const RequestNavigationParams& request_params, |
| 291 bool browser_initiated, | 301 bool browser_initiated, |
| 292 bool may_transfer, | 302 bool may_transfer, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 | 349 |
| 340 NavigationRequest::~NavigationRequest() { | 350 NavigationRequest::~NavigationRequest() { |
| 341 } | 351 } |
| 342 | 352 |
| 343 void NavigationRequest::BeginNavigation() { | 353 void NavigationRequest::BeginNavigation() { |
| 344 DCHECK(!loader_); | 354 DCHECK(!loader_); |
| 345 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 355 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
| 346 state_ = STARTED; | 356 state_ = STARTED; |
| 347 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 357 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); |
| 348 | 358 |
| 349 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 359 if (ShouldMakeNetworkRequestForURL(common_params_.url) && |
| 360 !navigation_handle_->IsSamePage()) { | |
| 350 // It's safe to use base::Unretained because this NavigationRequest owns | 361 // It's safe to use base::Unretained because this NavigationRequest owns |
| 351 // the NavigationHandle where the callback will be stored. | 362 // the NavigationHandle where the callback will be stored. |
| 352 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 363 // TODO(clamy): pass the real value for |is_external_protocol| if needed. |
| 353 // TODO(clamy): pass the method to the NavigationHandle instead of a | 364 // TODO(clamy): pass the method to the NavigationHandle instead of a |
| 354 // boolean. | 365 // boolean. |
| 355 navigation_handle_->WillStartRequest( | 366 navigation_handle_->WillStartRequest( |
| 356 common_params_.method, common_params_.post_data, | 367 common_params_.method, common_params_.post_data, |
| 357 Referrer::SanitizeForRequest(common_params_.url, | 368 Referrer::SanitizeForRequest(common_params_.url, |
| 358 common_params_.referrer), | 369 common_params_.referrer), |
| 359 begin_params_.has_user_gesture, common_params_.transition, false, | 370 begin_params_.has_user_gesture, common_params_.transition, false, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 375 common_params_.url); | 386 common_params_.url); |
| 376 | 387 |
| 377 // Inform the NavigationHandle that the navigation will commit. | 388 // Inform the NavigationHandle that the navigation will commit. |
| 378 navigation_handle_->ReadyToCommitNavigation(render_frame_host); | 389 navigation_handle_->ReadyToCommitNavigation(render_frame_host); |
| 379 | 390 |
| 380 CommitNavigation(); | 391 CommitNavigation(); |
| 381 } | 392 } |
| 382 | 393 |
| 383 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { | 394 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { |
| 384 DCHECK_EQ(frame_tree_node_->navigation_request(), this); | 395 DCHECK_EQ(frame_tree_node_->navigation_request(), this); |
| 385 // TODO(nasko): Update the NavigationHandle creation to ensure that the | |
| 386 // proper values are specified for is_same_page. | |
| 387 FrameTreeNode* frame_tree_node = frame_tree_node_; | 396 FrameTreeNode* frame_tree_node = frame_tree_node_; |
| 388 std::unique_ptr<NavigationHandleImpl> navigation_handle = | 397 std::unique_ptr<NavigationHandleImpl> navigation_handle = |
| 389 NavigationHandleImpl::Create( | 398 NavigationHandleImpl::Create( |
| 390 common_params_.url, frame_tree_node_, !browser_initiated_, | 399 common_params_.url, frame_tree_node_, !browser_initiated_, |
| 391 false, // is_same_page | 400 FrameMsg_Navigate_Type::IsSameDocument(common_params_.navigation_type), |
| 392 common_params_.navigation_start, pending_nav_entry_id, | 401 common_params_.navigation_start, pending_nav_entry_id, |
| 393 false); // started_in_context_menu | 402 false); // started_in_context_menu |
| 394 | 403 |
| 395 if (!frame_tree_node->navigation_request()) { | 404 if (!frame_tree_node->navigation_request()) { |
| 396 // A callback could have cancelled this request synchronously in which case | 405 // A callback could have cancelled this request synchronously in which case |
| 397 // |this| is deleted. | 406 // |this| is deleted. |
| 398 return; | 407 return; |
| 399 } | 408 } |
| 400 | 409 |
| 401 navigation_handle_ = std::move(navigation_handle); | 410 navigation_handle_ = std::move(navigation_handle); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 // Have the processing of the response resume in the network stack. | 710 // Have the processing of the response resume in the network stack. |
| 702 loader_->ProceedWithResponse(); | 711 loader_->ProceedWithResponse(); |
| 703 | 712 |
| 704 CommitNavigation(); | 713 CommitNavigation(); |
| 705 | 714 |
| 706 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused | 715 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused |
| 707 // the destruction of the NavigationRequest. | 716 // the destruction of the NavigationRequest. |
| 708 } | 717 } |
| 709 | 718 |
| 710 void NavigationRequest::CommitNavigation() { | 719 void NavigationRequest::CommitNavigation() { |
| 711 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url)); | 720 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url) || |
| 721 navigation_handle_->IsSamePage()); | |
| 712 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); | 722 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); |
| 713 | 723 |
| 714 // Retrieve the RenderFrameHost that needs to commit the navigation. | 724 // Retrieve the RenderFrameHost that needs to commit the navigation. |
| 715 RenderFrameHostImpl* render_frame_host = | 725 RenderFrameHostImpl* render_frame_host = |
| 716 navigation_handle_->GetRenderFrameHost(); | 726 navigation_handle_->GetRenderFrameHost(); |
| 717 DCHECK(render_frame_host == | 727 DCHECK(render_frame_host == |
| 718 frame_tree_node_->render_manager()->current_frame_host() || | 728 frame_tree_node_->render_manager()->current_frame_host() || |
| 719 render_frame_host == | 729 render_frame_host == |
| 720 frame_tree_node_->render_manager()->speculative_frame_host()); | 730 frame_tree_node_->render_manager()->speculative_frame_host()); |
| 721 | 731 |
| 722 TransferNavigationHandleOwnership(render_frame_host); | 732 TransferNavigationHandleOwnership(render_frame_host); |
| 723 | 733 |
| 724 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 734 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); |
| 725 | 735 |
| 726 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 736 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
| 727 common_params_, request_params_, | 737 common_params_, request_params_, |
| 728 is_view_source_); | 738 is_view_source_); |
| 729 | 739 |
| 730 frame_tree_node_->ResetNavigationRequest(true); | 740 frame_tree_node_->ResetNavigationRequest(true); |
| 731 } | 741 } |
| 732 | 742 |
| 733 } // namespace content | 743 } // namespace content |
| OLD | NEW |