| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 request_params_(request_params), | 309 request_params_(request_params), |
| 310 browser_initiated_(browser_initiated), | 310 browser_initiated_(browser_initiated), |
| 311 state_(NOT_STARTED), | 311 state_(NOT_STARTED), |
| 312 restore_type_(RestoreType::NONE), | 312 restore_type_(RestoreType::NONE), |
| 313 is_view_source_(false), | 313 is_view_source_(false), |
| 314 bindings_(NavigationEntryImpl::kInvalidBindings), | 314 bindings_(NavigationEntryImpl::kInvalidBindings), |
| 315 response_should_be_rendered_(true), | 315 response_should_be_rendered_(true), |
| 316 associated_site_instance_type_(AssociatedSiteInstanceType::NONE), | 316 associated_site_instance_type_(AssociatedSiteInstanceType::NONE), |
| 317 may_transfer_(may_transfer) { | 317 may_transfer_(may_transfer) { |
| 318 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); | 318 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); |
| 319 TRACE_EVENT_ASYNC_BEGIN2("navigation", "NavigationRequest", this, |
| 320 "frame_tree_node", |
| 321 frame_tree_node_->frame_tree_node_id(), "url", |
| 322 common_params_.url.possibly_invalid_spec()); |
| 319 | 323 |
| 320 // Sanitize the referrer. | 324 // Sanitize the referrer. |
| 321 common_params_.referrer = | 325 common_params_.referrer = |
| 322 Referrer::SanitizeForRequest(common_params_.url, common_params_.referrer); | 326 Referrer::SanitizeForRequest(common_params_.url, common_params_.referrer); |
| 323 | 327 |
| 324 if (may_transfer) { | 328 if (may_transfer) { |
| 325 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); | 329 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
| 326 if (frame_entry) { | 330 if (frame_entry) { |
| 327 source_site_instance_ = frame_entry->source_site_instance(); | 331 source_site_instance_ = frame_entry->source_site_instance(); |
| 328 dest_site_instance_ = frame_entry->site_instance(); | 332 dest_site_instance_ = frame_entry->site_instance(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 353 net::HttpRequestHeaders headers; | 357 net::HttpRequestHeaders headers; |
| 354 headers.AddHeadersFromString(begin_params_.headers); | 358 headers.AddHeadersFromString(begin_params_.headers); |
| 355 AddAdditionalRequestHeaders( | 359 AddAdditionalRequestHeaders( |
| 356 &headers, common_params_.url, common_params_.navigation_type, | 360 &headers, common_params_.url, common_params_.navigation_type, |
| 357 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 361 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 358 common_params.method, user_agent_override, frame_tree_node); | 362 common_params.method, user_agent_override, frame_tree_node); |
| 359 begin_params_.headers = headers.ToString(); | 363 begin_params_.headers = headers.ToString(); |
| 360 } | 364 } |
| 361 | 365 |
| 362 NavigationRequest::~NavigationRequest() { | 366 NavigationRequest::~NavigationRequest() { |
| 367 TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this); |
| 363 } | 368 } |
| 364 | 369 |
| 365 void NavigationRequest::BeginNavigation() { | 370 void NavigationRequest::BeginNavigation() { |
| 366 DCHECK(!loader_); | 371 DCHECK(!loader_); |
| 367 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 372 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
| 373 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, |
| 374 "BeginNavigation"); |
| 368 state_ = STARTED; | 375 state_ = STARTED; |
| 369 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 376 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); |
| 370 | 377 |
| 371 if (ShouldMakeNetworkRequestForURL(common_params_.url) && | 378 if (ShouldMakeNetworkRequestForURL(common_params_.url) && |
| 372 !navigation_handle_->IsSameDocument()) { | 379 !navigation_handle_->IsSameDocument()) { |
| 373 // It's safe to use base::Unretained because this NavigationRequest owns | 380 // It's safe to use base::Unretained because this NavigationRequest owns |
| 374 // the NavigationHandle where the callback will be stored. | 381 // the NavigationHandle where the callback will be stored. |
| 375 // TODO(clamy): pass the method to the NavigationHandle instead of a | 382 // TODO(clamy): pass the method to the NavigationHandle instead of a |
| 376 // boolean. | 383 // boolean. |
| 377 bool is_external_protocol = | 384 bool is_external_protocol = |
| 378 !GetContentClient()->browser()->IsHandledURL(common_params_.url); | 385 !GetContentClient()->browser()->IsHandledURL(common_params_.url); |
| 379 navigation_handle_->WillStartRequest( | 386 navigation_handle_->WillStartRequest( |
| 380 common_params_.method, common_params_.post_data, | 387 common_params_.method, common_params_.post_data, |
| 381 Referrer::SanitizeForRequest(common_params_.url, | 388 Referrer::SanitizeForRequest(common_params_.url, |
| 382 common_params_.referrer), | 389 common_params_.referrer), |
| 383 begin_params_.has_user_gesture, common_params_.transition, | 390 begin_params_.has_user_gesture, common_params_.transition, |
| 384 is_external_protocol, begin_params_.request_context_type, | 391 is_external_protocol, begin_params_.request_context_type, |
| 385 begin_params_.mixed_content_context_type, | 392 begin_params_.mixed_content_context_type, |
| 386 base::Bind(&NavigationRequest::OnStartChecksComplete, | 393 base::Bind(&NavigationRequest::OnStartChecksComplete, |
| 387 base::Unretained(this))); | 394 base::Unretained(this))); |
| 388 return; | 395 return; |
| 389 } | 396 } |
| 390 | 397 |
| 391 // There is no need to make a network request for this navigation, so commit | 398 // There is no need to make a network request for this navigation, so commit |
| 392 // it immediately. | 399 // it immediately. |
| 400 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, |
| 401 "ResponseStarted"); |
| 393 state_ = RESPONSE_STARTED; | 402 state_ = RESPONSE_STARTED; |
| 394 | 403 |
| 395 // Select an appropriate RenderFrameHost. | 404 // Select an appropriate RenderFrameHost. |
| 396 RenderFrameHostImpl* render_frame_host = | 405 RenderFrameHostImpl* render_frame_host = |
| 397 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); | 406 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); |
| 398 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, | 407 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, |
| 399 common_params_.url); | 408 common_params_.url); |
| 400 | 409 |
| 401 // Inform the NavigationHandle that the navigation will commit. | 410 // Inform the NavigationHandle that the navigation will commit. |
| 402 navigation_handle_->ReadyToCommitNavigation(render_frame_host); | 411 navigation_handle_->ReadyToCommitNavigation(render_frame_host); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 const scoped_refptr<ResourceResponse>& response, | 518 const scoped_refptr<ResourceResponse>& response, |
| 510 std::unique_ptr<StreamHandle> body, | 519 std::unique_ptr<StreamHandle> body, |
| 511 mojo::ScopedDataPipeConsumerHandle consumer_handle, | 520 mojo::ScopedDataPipeConsumerHandle consumer_handle, |
| 512 const SSLStatus& ssl_status, | 521 const SSLStatus& ssl_status, |
| 513 std::unique_ptr<NavigationData> navigation_data, | 522 std::unique_ptr<NavigationData> navigation_data, |
| 514 const GlobalRequestID& request_id, | 523 const GlobalRequestID& request_id, |
| 515 bool is_download, | 524 bool is_download, |
| 516 bool is_stream) { | 525 bool is_stream) { |
| 517 DCHECK(state_ == STARTED); | 526 DCHECK(state_ == STARTED); |
| 518 DCHECK(response); | 527 DCHECK(response); |
| 528 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, |
| 529 "OnResponseStarted"); |
| 519 state_ = RESPONSE_STARTED; | 530 state_ = RESPONSE_STARTED; |
| 520 | 531 |
| 521 // Check if the response should be sent to a renderer. | 532 // Check if the response should be sent to a renderer. |
| 522 response_should_be_rendered_ = | 533 response_should_be_rendered_ = |
| 523 !is_download && (!response->head.headers.get() || | 534 !is_download && (!response->head.headers.get() || |
| 524 (response->head.headers->response_code() != 204 && | 535 (response->head.headers->response_code() != 204 && |
| 525 response->head.headers->response_code() != 205)); | 536 response->head.headers->response_code() != 205)); |
| 526 | 537 |
| 527 // Response that will not commit should be marked as aborted in the | 538 // Response that will not commit should be marked as aborted in the |
| 528 // NavigationHandle. | 539 // NavigationHandle. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 response->head.connection_info, ssl_status, request_id, | 600 response->head.connection_info, ssl_status, request_id, |
| 590 common_params_.should_replace_current_entry, is_download, is_stream, | 601 common_params_.should_replace_current_entry, is_download, is_stream, |
| 591 base::Closure(), | 602 base::Closure(), |
| 592 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete, | 603 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete, |
| 593 base::Unretained(this))); | 604 base::Unretained(this))); |
| 594 } | 605 } |
| 595 | 606 |
| 596 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 607 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
| 597 int net_error) { | 608 int net_error) { |
| 598 DCHECK(state_ == STARTED || state_ == RESPONSE_STARTED); | 609 DCHECK(state_ == STARTED || state_ == RESPONSE_STARTED); |
| 610 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationRequest", this, |
| 611 "OnRequestFailed", "error", net_error); |
| 599 state_ = FAILED; | 612 state_ = FAILED; |
| 600 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 613 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
| 601 | 614 |
| 602 // With PlzNavigate, debug URLs will give a failed navigation because the | 615 // With PlzNavigate, debug URLs will give a failed navigation because the |
| 603 // WebUI backend won't find a handler for them. They will be processed in the | 616 // WebUI backend won't find a handler for them. They will be processed in the |
| 604 // renderer, however do not discard the pending entry so that the URL bar | 617 // renderer, however do not discard the pending entry so that the URL bar |
| 605 // shows them correctly. | 618 // shows them correctly. |
| 606 if (!IsRendererDebugURL(common_params_.url)) { | 619 if (!IsRendererDebugURL(common_params_.url)) { |
| 607 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( | 620 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( |
| 608 navigation_handle_.get()); | 621 navigation_handle_.get()); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 853 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); |
| 841 | 854 |
| 842 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 855 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
| 843 std::move(handle_), common_params_, | 856 std::move(handle_), common_params_, |
| 844 request_params_, is_view_source_); | 857 request_params_, is_view_source_); |
| 845 | 858 |
| 846 frame_tree_node_->ResetNavigationRequest(true, true); | 859 frame_tree_node_->ResetNavigationRequest(true, true); |
| 847 } | 860 } |
| 848 | 861 |
| 849 } // namespace content | 862 } // namespace content |
| OLD | NEW |