| 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 "content/browser/appcache/appcache_navigation_handle.h" | 9 #include "content/browser/appcache/appcache_navigation_handle.h" |
| 10 #include "content/browser/appcache/chrome_appcache_service.h" | 10 #include "content/browser/appcache/chrome_appcache_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/public/browser/navigation_data.h" | 31 #include "content/public/browser/navigation_data.h" |
| 32 #include "content/public/browser/navigation_ui_data.h" | 32 #include "content/public/browser/navigation_ui_data.h" |
| 33 #include "content/public/browser/storage_partition.h" | 33 #include "content/public/browser/storage_partition.h" |
| 34 #include "content/public/browser/stream_handle.h" | 34 #include "content/public/browser/stream_handle.h" |
| 35 #include "content/public/common/appcache_info.h" | 35 #include "content/public/common/appcache_info.h" |
| 36 #include "content/public/common/content_client.h" | 36 #include "content/public/common/content_client.h" |
| 37 #include "content/public/common/request_context_type.h" | 37 #include "content/public/common/request_context_type.h" |
| 38 #include "content/public/common/resource_response.h" | 38 #include "content/public/common/resource_response.h" |
| 39 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
| 40 #include "net/base/load_flags.h" | 40 #include "net/base/load_flags.h" |
| 41 #include "net/base/net_errors.h" |
| 41 #include "net/base/url_util.h" | 42 #include "net/base/url_util.h" |
| 42 #include "net/http/http_request_headers.h" | 43 #include "net/http/http_request_headers.h" |
| 43 #include "net/url_request/redirect_info.h" | 44 #include "net/url_request/redirect_info.h" |
| 44 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 45 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 45 | 46 |
| 46 namespace content { | 47 namespace content { |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 // Returns the net load flags to use based on the navigation type. | 51 // Returns the net load flags to use based on the navigation type. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 const NavigationEntryImpl* entry) | 292 const NavigationEntryImpl* entry) |
| 292 : frame_tree_node_(frame_tree_node), | 293 : frame_tree_node_(frame_tree_node), |
| 293 common_params_(common_params), | 294 common_params_(common_params), |
| 294 begin_params_(begin_params), | 295 begin_params_(begin_params), |
| 295 request_params_(request_params), | 296 request_params_(request_params), |
| 296 browser_initiated_(browser_initiated), | 297 browser_initiated_(browser_initiated), |
| 297 state_(NOT_STARTED), | 298 state_(NOT_STARTED), |
| 298 restore_type_(RestoreType::NONE), | 299 restore_type_(RestoreType::NONE), |
| 299 is_view_source_(false), | 300 is_view_source_(false), |
| 300 bindings_(NavigationEntryImpl::kInvalidBindings), | 301 bindings_(NavigationEntryImpl::kInvalidBindings), |
| 302 response_should_be_rendered_(true), |
| 301 associated_site_instance_type_(AssociatedSiteInstanceType::NONE), | 303 associated_site_instance_type_(AssociatedSiteInstanceType::NONE), |
| 302 may_transfer_(may_transfer) { | 304 may_transfer_(may_transfer) { |
| 303 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); | 305 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); |
| 304 if (may_transfer) { | 306 if (may_transfer) { |
| 305 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); | 307 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
| 306 if (frame_entry) { | 308 if (frame_entry) { |
| 307 source_site_instance_ = frame_entry->source_site_instance(); | 309 source_site_instance_ = frame_entry->source_site_instance(); |
| 308 dest_site_instance_ = frame_entry->site_instance(); | 310 dest_site_instance_ = frame_entry->site_instance(); |
| 309 } | 311 } |
| 310 | 312 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 447 |
| 446 void NavigationRequest::OnResponseStarted( | 448 void NavigationRequest::OnResponseStarted( |
| 447 const scoped_refptr<ResourceResponse>& response, | 449 const scoped_refptr<ResourceResponse>& response, |
| 448 std::unique_ptr<StreamHandle> body, | 450 std::unique_ptr<StreamHandle> body, |
| 449 const SSLStatus& ssl_status, | 451 const SSLStatus& ssl_status, |
| 450 std::unique_ptr<NavigationData> navigation_data, | 452 std::unique_ptr<NavigationData> navigation_data, |
| 451 const GlobalRequestID& request_id, | 453 const GlobalRequestID& request_id, |
| 452 bool is_download, | 454 bool is_download, |
| 453 bool is_stream) { | 455 bool is_stream) { |
| 454 DCHECK(state_ == STARTED); | 456 DCHECK(state_ == STARTED); |
| 457 DCHECK(response); |
| 455 state_ = RESPONSE_STARTED; | 458 state_ = RESPONSE_STARTED; |
| 456 | 459 |
| 457 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not | 460 // Check if the response should be sent to a renderer. |
| 458 // commit; they leave the frame showing the previous page. | 461 response_should_be_rendered_ = |
| 459 DCHECK(response); | 462 !is_download && (!response->head.headers.get() || |
| 460 if (response->head.headers.get() && | 463 (response->head.headers->response_code() != 204 && |
| 461 (response->head.headers->response_code() == 204 || | 464 response->head.headers->response_code() != 205)); |
| 462 response->head.headers->response_code() == 205)) { | 465 |
| 463 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( | 466 // Response that will not commit should be marked as aborted in the |
| 464 navigation_handle_.get()); | 467 // NavigationHandle. |
| 465 frame_tree_node_->ResetNavigationRequest(false); | 468 if (!response_should_be_rendered_) |
| 466 return; | 469 navigation_handle_->set_net_error_code(net::ERR_ABORTED); |
| 467 } | |
| 468 | 470 |
| 469 // Update the service worker params of the request params. | 471 // Update the service worker params of the request params. |
| 470 bool did_create_service_worker_host = | 472 bool did_create_service_worker_host = |
| 471 navigation_handle_->service_worker_handle() && | 473 navigation_handle_->service_worker_handle() && |
| 472 navigation_handle_->service_worker_handle() | 474 navigation_handle_->service_worker_handle() |
| 473 ->service_worker_provider_host_id() != | 475 ->service_worker_provider_host_id() != |
| 474 kInvalidServiceWorkerProviderId; | 476 kInvalidServiceWorkerProviderId; |
| 475 request_params_.service_worker_provider_id = | 477 request_params_.service_worker_provider_id = |
| 476 did_create_service_worker_host | 478 did_create_service_worker_host |
| 477 ? navigation_handle_->service_worker_handle() | 479 ? navigation_handle_->service_worker_handle() |
| 478 ->service_worker_provider_host_id() | 480 ->service_worker_provider_host_id() |
| 479 : kInvalidServiceWorkerProviderId; | 481 : kInvalidServiceWorkerProviderId; |
| 480 | 482 |
| 481 request_params_.appcache_host_id = | 483 request_params_.appcache_host_id = |
| 482 navigation_handle_->appcache_handle() | 484 navigation_handle_->appcache_handle() |
| 483 ? navigation_handle_->appcache_handle()->appcache_host_id() | 485 ? navigation_handle_->appcache_handle()->appcache_host_id() |
| 484 : kAppCacheNoHostId; | 486 : kAppCacheNoHostId; |
| 485 | 487 |
| 486 // Update the lofi state of the request. | 488 // Update the lofi state of the request. |
| 487 if (response->head.is_using_lofi) | 489 if (response->head.is_using_lofi) |
| 488 common_params_.lofi_state = LOFI_ON; | 490 common_params_.lofi_state = LOFI_ON; |
| 489 else | 491 else |
| 490 common_params_.lofi_state = LOFI_OFF; | 492 common_params_.lofi_state = LOFI_OFF; |
| 491 | 493 |
| 492 // Select an appropriate renderer to commit the navigation. | 494 // Select an appropriate renderer to commit the navigation. |
| 493 RenderFrameHostImpl* render_frame_host = | 495 RenderFrameHostImpl* render_frame_host = nullptr; |
| 494 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); | 496 if (response_should_be_rendered_) { |
| 495 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, | 497 render_frame_host = |
| 496 common_params_.url); | 498 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); |
| 499 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
| 500 render_frame_host, common_params_.url); |
| 501 } |
| 502 DCHECK(render_frame_host || !response_should_be_rendered_); |
| 497 | 503 |
| 498 // For renderer-initiated navigations that are set to commit in a different | 504 // For renderer-initiated navigations that are set to commit in a different |
| 499 // renderer, allow the embedder to cancel the transfer. | 505 // renderer, allow the embedder to cancel the transfer. |
| 500 if (!browser_initiated_ && | 506 if (!browser_initiated_ && render_frame_host && |
| 501 render_frame_host != frame_tree_node_->current_frame_host() && | 507 render_frame_host != frame_tree_node_->current_frame_host() && |
| 502 !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation( | 508 !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation( |
| 503 frame_tree_node_->IsMainFrame())) { | 509 frame_tree_node_->IsMainFrame())) { |
| 504 frame_tree_node_->ResetNavigationRequest(false); | 510 frame_tree_node_->ResetNavigationRequest(false); |
| 505 return; | 511 return; |
| 506 } | 512 } |
| 507 | 513 |
| 508 if (navigation_data) | 514 if (navigation_data) |
| 509 navigation_handle_->set_navigation_data(std::move(navigation_data)); | 515 navigation_handle_->set_navigation_data(std::move(navigation_data)); |
| 510 | 516 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 return; | 657 return; |
| 652 } | 658 } |
| 653 | 659 |
| 654 loader_->FollowRedirect(); | 660 loader_->FollowRedirect(); |
| 655 } | 661 } |
| 656 | 662 |
| 657 void NavigationRequest::OnWillProcessResponseChecksComplete( | 663 void NavigationRequest::OnWillProcessResponseChecksComplete( |
| 658 NavigationThrottle::ThrottleCheckResult result) { | 664 NavigationThrottle::ThrottleCheckResult result) { |
| 659 DCHECK(result != NavigationThrottle::DEFER); | 665 DCHECK(result != NavigationThrottle::DEFER); |
| 660 | 666 |
| 661 // Abort the request if needed. This will destroy the NavigationRequest. | 667 // Abort the request if needed. This includes requests that were blocked by |
| 668 // NavigationThrottles and requests that should not commit (e.g. downloads, |
| 669 // 204/205s). This will destroy the NavigationRequest. |
| 662 if (result == NavigationThrottle::CANCEL_AND_IGNORE || | 670 if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
| 663 result == NavigationThrottle::CANCEL) { | 671 result == NavigationThrottle::CANCEL || !response_should_be_rendered_) { |
| 664 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. | 672 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. |
| 673 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( |
| 674 navigation_handle_.get()); |
| 665 frame_tree_node_->ResetNavigationRequest(false); | 675 frame_tree_node_->ResetNavigationRequest(false); |
| 666 return; | 676 return; |
| 667 } | 677 } |
| 668 | 678 |
| 669 if (result == NavigationThrottle::BLOCK_RESPONSE) { | 679 if (result == NavigationThrottle::BLOCK_RESPONSE) { |
| 670 OnRequestFailed(false, net::ERR_BLOCKED_BY_RESPONSE); | 680 OnRequestFailed(false, net::ERR_BLOCKED_BY_RESPONSE); |
| 671 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has | 681 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has |
| 672 // destroyed the NavigationRequest. | 682 // destroyed the NavigationRequest. |
| 673 return; | 683 return; |
| 674 } | 684 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 699 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 709 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); |
| 700 | 710 |
| 701 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 711 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
| 702 common_params_, request_params_, | 712 common_params_, request_params_, |
| 703 is_view_source_); | 713 is_view_source_); |
| 704 | 714 |
| 705 frame_tree_node_->ResetNavigationRequest(true); | 715 frame_tree_node_->ResetNavigationRequest(true); |
| 706 } | 716 } |
| 707 | 717 |
| 708 } // namespace content | 718 } // namespace content |
| OLD | NEW |