Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 2867833002: NavigationThrottle: allow customization of net::Error when blocking
Patch Set: Add unit tests. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), 673 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(),
674 timestamp); 674 timestamp);
675 } 675 }
676 676
677 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 677 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
678 common_params_.url); 678 common_params_.url);
679 } 679 }
680 680
681 void NavigationRequest::OnStartChecksComplete( 681 void NavigationRequest::OnStartChecksComplete(
682 NavigationThrottle::ThrottleCheckResult result) { 682 NavigationThrottle::ThrottleCheckResult result) {
683 DCHECK(result != NavigationThrottle::DEFER); 683 DCHECK(result.action() != NavigationThrottle::DEFER);
684 DCHECK(result != NavigationThrottle::BLOCK_RESPONSE); 684 DCHECK(result.action() != NavigationThrottle::BLOCK_RESPONSE);
685 685
686 if (on_start_checks_complete_closure_) 686 if (on_start_checks_complete_closure_)
687 on_start_checks_complete_closure_.Run(); 687 on_start_checks_complete_closure_.Run();
688 688
689 // Abort the request if needed. This will destroy the NavigationRequest. 689 // Abort the request if needed. This will destroy the NavigationRequest.
690 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 690 if (result.action() == NavigationThrottle::CANCEL_AND_IGNORE ||
691 result == NavigationThrottle::CANCEL) { 691 result.action() == NavigationThrottle::CANCEL) {
692 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 692 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
693 DCHECK_EQ(net::ERR_ABORTED, result.net_error_code());
693 OnRequestFailed(false, net::ERR_ABORTED); 694 OnRequestFailed(false, net::ERR_ABORTED);
694 695
695 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 696 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
696 // destroyed the NavigationRequest. 697 // destroyed the NavigationRequest.
697 return; 698 return;
698 } 699 }
699 700
700 if (result == NavigationThrottle::BLOCK_REQUEST) { 701 if (result.action() == NavigationThrottle::BLOCK_REQUEST) {
701 OnRequestFailed(false, net::ERR_BLOCKED_BY_CLIENT); 702 DCHECK_NE(net::OK, result.net_error_code());
703 OnRequestFailed(false, result.net_error_code());
702 704
703 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 705 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
704 // destroyed the NavigationRequest. 706 // destroyed the NavigationRequest.
705 return; 707 return;
706 } 708 }
707 709
708 // Use the SiteInstance of the navigating RenderFrameHost to get access to 710 // Use the SiteInstance of the navigating RenderFrameHost to get access to
709 // the StoragePartition. Using the url of the navigation will result in a 711 // the StoragePartition. Using the url of the navigation will result in a
710 // wrong StoragePartition being picked when a WebView is navigating. 712 // wrong StoragePartition being picked when a WebView is navigating.
711 DCHECK_NE(AssociatedSiteInstanceType::NONE, associated_site_instance_type_); 713 DCHECK_NE(AssociatedSiteInstanceType::NONE, associated_site_instance_type_);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 IsSecureFrame(frame_tree_node_->parent()), 779 IsSecureFrame(frame_tree_node_->parent()),
778 frame_tree_node_->frame_tree_node_id(), is_for_guests_only, 780 frame_tree_node_->frame_tree_node_id(), is_for_guests_only,
779 report_raw_headers, navigating_frame_host->GetVisibilityState()), 781 report_raw_headers, navigating_frame_host->GetVisibilityState()),
780 std::move(navigation_ui_data), 782 std::move(navigation_ui_data),
781 navigation_handle_->service_worker_handle(), 783 navigation_handle_->service_worker_handle(),
782 navigation_handle_->appcache_handle(), this); 784 navigation_handle_->appcache_handle(), this);
783 } 785 }
784 786
785 void NavigationRequest::OnRedirectChecksComplete( 787 void NavigationRequest::OnRedirectChecksComplete(
786 NavigationThrottle::ThrottleCheckResult result) { 788 NavigationThrottle::ThrottleCheckResult result) {
787 DCHECK(result != NavigationThrottle::DEFER); 789 DCHECK(result.action() != NavigationThrottle::DEFER);
788 DCHECK(result != NavigationThrottle::BLOCK_RESPONSE); 790 DCHECK(result.action() != NavigationThrottle::BLOCK_RESPONSE);
789 791
790 // Abort the request if needed. This will destroy the NavigationRequest. 792 // Abort the request if needed. This will destroy the NavigationRequest.
791 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 793 if (result.action() == NavigationThrottle::CANCEL_AND_IGNORE ||
792 result == NavigationThrottle::CANCEL) { 794 result.action() == NavigationThrottle::CANCEL) {
793 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 795 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
794 OnRequestFailed(false, net::ERR_ABORTED); 796 OnRequestFailed(false, net::ERR_ABORTED);
795 797
796 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 798 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
797 // destroyed the NavigationRequest. 799 // destroyed the NavigationRequest.
798 return; 800 return;
799 } 801 }
800 802
801 if (result == NavigationThrottle::BLOCK_REQUEST) { 803 if (result.action() == NavigationThrottle::BLOCK_REQUEST) {
802 OnRequestFailed(false, net::ERR_BLOCKED_BY_CLIENT); 804 OnRequestFailed(false, net::ERR_BLOCKED_BY_CLIENT);
nasko 2017/05/11 00:09:54 Shouldn't we pass results.net_error_code() here? T
803 805
804 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 806 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
805 // destroyed the NavigationRequest. 807 // destroyed the NavigationRequest.
806 return; 808 return;
807 } 809 }
808 810
809 loader_->FollowRedirect(); 811 loader_->FollowRedirect();
810 } 812 }
811 813
812 void NavigationRequest::OnWillProcessResponseChecksComplete( 814 void NavigationRequest::OnWillProcessResponseChecksComplete(
813 NavigationThrottle::ThrottleCheckResult result) { 815 NavigationThrottle::ThrottleCheckResult result) {
814 DCHECK(result != NavigationThrottle::DEFER); 816 DCHECK(result.action() != NavigationThrottle::DEFER);
815 817
816 // If the NavigationThrottles allowed the navigation to continue, have the 818 // If the NavigationThrottles allowed the navigation to continue, have the
817 // processing of the response resume in the network stack. 819 // processing of the response resume in the network stack.
818 if (result == NavigationThrottle::PROCEED) 820
821 if (result.action() == NavigationThrottle::PROCEED)
819 loader_->ProceedWithResponse(); 822 loader_->ProceedWithResponse();
820 823
821 // Abort the request if needed. This includes requests that were blocked by 824 // Abort the request if needed. This includes requests that were blocked by
822 // NavigationThrottles and requests that should not commit (e.g. downloads, 825 // NavigationThrottles and requests that should not commit (e.g. downloads,
823 // 204/205s). This will destroy the NavigationRequest. 826 // 204/205s). This will destroy the NavigationRequest.
824 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 827 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
825 result == NavigationThrottle::CANCEL || !response_should_be_rendered_) { 828 result == NavigationThrottle::CANCEL || !response_should_be_rendered_) {
826 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 829 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
830 if (response_should_be_rendered_)
831 DCHECK_EQ(net::ERR_ABORTED, result.net_error_code());
827 OnRequestFailed(false, net::ERR_ABORTED); 832 OnRequestFailed(false, net::ERR_ABORTED);
828 833
829 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 834 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
830 // destroyed the NavigationRequest. 835 // destroyed the NavigationRequest.
831 return; 836 return;
832 } 837 }
833 838
834 if (result == NavigationThrottle::BLOCK_RESPONSE) { 839 if (result.action() == NavigationThrottle::BLOCK_RESPONSE) {
835 OnRequestFailed(false, net::ERR_BLOCKED_BY_RESPONSE); 840 DCHECK_NE(net::OK, result.net_error_code());
841 OnRequestFailed(false, result.net_error_code());
836 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 842 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
837 // destroyed the NavigationRequest. 843 // destroyed the NavigationRequest.
838 return; 844 return;
839 } 845 }
840 846
841 CommitNavigation(); 847 CommitNavigation();
842 848
843 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused 849 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused
844 // the destruction of the NavigationRequest. 850 // the destruction of the NavigationRequest.
845 } 851 }
(...skipping 16 matching lines...) Expand all
862 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 868 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
863 869
864 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 870 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
865 std::move(handle_), common_params_, 871 std::move(handle_), common_params_,
866 request_params_, is_view_source_); 872 request_params_, is_view_source_);
867 873
868 frame_tree_node_->ResetNavigationRequest(true, true); 874 frame_tree_node_->ResetNavigationRequest(true, true);
869 } 875 }
870 876
871 } // namespace content 877 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698