| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/appcache/appcache_navigation_handle.h" | 10 #include "content/browser/appcache/appcache_navigation_handle.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 result = CheckWillRedirectRequest(); | 347 result = CheckWillRedirectRequest(); |
| 348 } else { | 348 } else { |
| 349 result = CheckWillProcessResponse(); | 349 result = CheckWillProcessResponse(); |
| 350 | 350 |
| 351 // If the navigation is about to proceed after having been deferred while | 351 // If the navigation is about to proceed after having been deferred while |
| 352 // processing the response, then it's ready to commit. Determine which | 352 // processing the response, then it's ready to commit. Determine which |
| 353 // RenderFrameHost should render the response, based on its site (after any | 353 // RenderFrameHost should render the response, based on its site (after any |
| 354 // redirects). | 354 // redirects). |
| 355 // Note: if MaybeTransferAndProceed returns false, this means that this | 355 // Note: if MaybeTransferAndProceed returns false, this means that this |
| 356 // NavigationHandle was deleted, so return immediately. | 356 // NavigationHandle was deleted, so return immediately. |
| 357 if (result == NavigationThrottle::PROCEED && !MaybeTransferAndProceed()) | 357 if (result.action() == NavigationThrottle::PROCEED && |
| 358 !MaybeTransferAndProceed()) |
| 358 return; | 359 return; |
| 359 } | 360 } |
| 360 | 361 |
| 361 if (result != NavigationThrottle::DEFER) { | 362 if (result.action() != NavigationThrottle::DEFER) { |
| 362 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 363 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 363 "Resuming"); | 364 "Resuming"); |
| 364 RunCompleteCallback(result); | 365 RunCompleteCallback(result); |
| 365 } | 366 } |
| 366 } | 367 } |
| 367 | 368 |
| 368 void NavigationHandleImpl::CancelDeferredNavigation( | 369 void NavigationHandleImpl::CancelDeferredNavigation( |
| 369 NavigationThrottle::ThrottleCheckResult result) { | 370 NavigationThrottle::ThrottleCheckResult result) { |
| 370 DCHECK(state_ == DEFERRING_START || | 371 DCHECK(state_ == DEFERRING_START || |
| 371 state_ == DEFERRING_REDIRECT || | 372 state_ == DEFERRING_REDIRECT || |
| 372 state_ == DEFERRING_RESPONSE); | 373 state_ == DEFERRING_RESPONSE); |
| 373 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 374 DCHECK(result.action() == NavigationThrottle::CANCEL_AND_IGNORE || |
| 374 result == NavigationThrottle::CANCEL); | 375 result.action() == NavigationThrottle::CANCEL); |
| 375 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 376 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 376 "CancelDeferredNavigation"); | 377 "CancelDeferredNavigation"); |
| 377 state_ = CANCELING; | 378 state_ = CANCELING; |
| 378 RunCompleteCallback(result); | 379 RunCompleteCallback(result); |
| 379 } | 380 } |
| 380 | 381 |
| 381 void NavigationHandleImpl::RegisterThrottleForTesting( | 382 void NavigationHandleImpl::RegisterThrottleForTesting( |
| 382 std::unique_ptr<NavigationThrottle> navigation_throttle) { | 383 std::unique_ptr<NavigationThrottle> navigation_throttle) { |
| 383 throttles_.push_back(std::move(navigation_throttle)); | 384 throttles_.push_back(std::move(navigation_throttle)); |
| 384 } | 385 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 | 563 |
| 563 RegisterNavigationThrottles(); | 564 RegisterNavigationThrottles(); |
| 564 | 565 |
| 565 if (IsBrowserSideNavigationEnabled()) | 566 if (IsBrowserSideNavigationEnabled()) |
| 566 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); | 567 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); |
| 567 | 568 |
| 568 // Notify each throttle of the request. | 569 // Notify each throttle of the request. |
| 569 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 570 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| 570 | 571 |
| 571 // If the navigation is not deferred, run the callback. | 572 // If the navigation is not deferred, run the callback. |
| 572 if (result != NavigationThrottle::DEFER) { | 573 if (result.action() != NavigationThrottle::DEFER) { |
| 573 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, | 574 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, |
| 574 "StartRequest", "result", result); | 575 "StartRequest", "result", result.action()); |
| 575 RunCompleteCallback(result); | 576 RunCompleteCallback(result); |
| 576 } | 577 } |
| 577 } | 578 } |
| 578 | 579 |
| 579 void NavigationHandleImpl::WillRedirectRequest( | 580 void NavigationHandleImpl::WillRedirectRequest( |
| 580 const GURL& new_url, | 581 const GURL& new_url, |
| 581 const std::string& new_method, | 582 const std::string& new_method, |
| 582 const GURL& new_referrer_url, | 583 const GURL& new_referrer_url, |
| 583 bool new_is_external_protocol, | 584 bool new_is_external_protocol, |
| 584 scoped_refptr<net::HttpResponseHeaders> response_headers, | 585 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 612 if (IsSelfReferentialURL()) { | 613 if (IsSelfReferentialURL()) { |
| 613 state_ = CANCELING; | 614 state_ = CANCELING; |
| 614 RunCompleteCallback(NavigationThrottle::CANCEL); | 615 RunCompleteCallback(NavigationThrottle::CANCEL); |
| 615 return; | 616 return; |
| 616 } | 617 } |
| 617 | 618 |
| 618 // Notify each throttle of the request. | 619 // Notify each throttle of the request. |
| 619 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 620 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 620 | 621 |
| 621 // If the navigation is not deferred, run the callback. | 622 // If the navigation is not deferred, run the callback. |
| 622 if (result != NavigationThrottle::DEFER) { | 623 if (result.action() != NavigationThrottle::DEFER) { |
| 623 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, | 624 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, |
| 624 "RedirectRequest", "result", result); | 625 "RedirectRequest", "result", result.action()); |
| 625 RunCompleteCallback(result); | 626 RunCompleteCallback(result); |
| 626 } | 627 } |
| 627 } | 628 } |
| 628 | 629 |
| 629 void NavigationHandleImpl::WillProcessResponse( | 630 void NavigationHandleImpl::WillProcessResponse( |
| 630 RenderFrameHostImpl* render_frame_host, | 631 RenderFrameHostImpl* render_frame_host, |
| 631 scoped_refptr<net::HttpResponseHeaders> response_headers, | 632 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 632 net::HttpResponseInfo::ConnectionInfo connection_info, | 633 net::HttpResponseInfo::ConnectionInfo connection_info, |
| 633 const SSLStatus& ssl_status, | 634 const SSLStatus& ssl_status, |
| 634 const GlobalRequestID& request_id, | 635 const GlobalRequestID& request_id, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 654 transfer_callback_ = transfer_callback; | 655 transfer_callback_ = transfer_callback; |
| 655 | 656 |
| 656 // Notify each throttle of the response. | 657 // Notify each throttle of the response. |
| 657 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | 658 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); |
| 658 | 659 |
| 659 // If the navigation is done processing the response, then it's ready to | 660 // If the navigation is done processing the response, then it's ready to |
| 660 // commit. Determine which RenderFrameHost should render the response, based | 661 // commit. Determine which RenderFrameHost should render the response, based |
| 661 // on its site (after any redirects). | 662 // on its site (after any redirects). |
| 662 // Note: if MaybeTransferAndProceed returns false, this means that this | 663 // Note: if MaybeTransferAndProceed returns false, this means that this |
| 663 // NavigationHandle was deleted, so return immediately. | 664 // NavigationHandle was deleted, so return immediately. |
| 664 if (result == NavigationThrottle::PROCEED && !MaybeTransferAndProceed()) | 665 if (result.action() == NavigationThrottle::PROCEED && |
| 666 !MaybeTransferAndProceed()) |
| 665 return; | 667 return; |
| 666 | 668 |
| 667 // If the navigation is not deferred, run the callback. | 669 // If the navigation is not deferred, run the callback. |
| 668 if (result != NavigationThrottle::DEFER) { | 670 if (result.action() != NavigationThrottle::DEFER) { |
| 669 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, | 671 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, |
| 670 "ProcessResponse", "result", result); | 672 "ProcessResponse", "result", result.action()); |
| 671 RunCompleteCallback(result); | 673 RunCompleteCallback(result); |
| 672 } | 674 } |
| 673 } | 675 } |
| 674 | 676 |
| 675 void NavigationHandleImpl::ReadyToCommitNavigation( | 677 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 676 RenderFrameHostImpl* render_frame_host) { | 678 RenderFrameHostImpl* render_frame_host) { |
| 677 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 679 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 678 "ReadyToCommitNavigation"); | 680 "ReadyToCommitNavigation"); |
| 679 | 681 |
| 680 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 682 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 NavigationHandleImpl::CheckWillStartRequest() { | 745 NavigationHandleImpl::CheckWillStartRequest() { |
| 744 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); | 746 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); |
| 745 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); | 747 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); |
| 746 DCHECK(state_ != DEFERRING_START || next_index_ != 0); | 748 DCHECK(state_ != DEFERRING_START || next_index_ != 0); |
| 747 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 749 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 748 NavigationThrottle::ThrottleCheckResult result = | 750 NavigationThrottle::ThrottleCheckResult result = |
| 749 throttles_[i]->WillStartRequest(); | 751 throttles_[i]->WillStartRequest(); |
| 750 TRACE_EVENT_ASYNC_STEP_INTO0( | 752 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 751 "navigation", "NavigationHandle", this, | 753 "navigation", "NavigationHandle", this, |
| 752 base::StringPrintf("CheckWillStartRequest: %s: %d", | 754 base::StringPrintf("CheckWillStartRequest: %s: %d", |
| 753 throttles_[i]->GetNameForLogging(), result)); | 755 throttles_[i]->GetNameForLogging(), |
| 754 switch (result) { | 756 result.action())); |
| 757 switch (result.action()) { |
| 755 case NavigationThrottle::PROCEED: | 758 case NavigationThrottle::PROCEED: |
| 756 continue; | 759 continue; |
| 757 | 760 |
| 758 case NavigationThrottle::BLOCK_REQUEST: | 761 case NavigationThrottle::BLOCK_REQUEST: |
| 759 case NavigationThrottle::CANCEL: | 762 case NavigationThrottle::CANCEL: |
| 760 case NavigationThrottle::CANCEL_AND_IGNORE: | 763 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 761 state_ = CANCELING; | 764 state_ = CANCELING; |
| 762 return result; | 765 return result; |
| 763 | 766 |
| 764 case NavigationThrottle::DEFER: | 767 case NavigationThrottle::DEFER: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 781 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 784 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
| 782 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 785 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
| 783 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 786 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
| 784 | 787 |
| 785 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 788 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 786 NavigationThrottle::ThrottleCheckResult result = | 789 NavigationThrottle::ThrottleCheckResult result = |
| 787 throttles_[i]->WillRedirectRequest(); | 790 throttles_[i]->WillRedirectRequest(); |
| 788 TRACE_EVENT_ASYNC_STEP_INTO0( | 791 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 789 "navigation", "NavigationHandle", this, | 792 "navigation", "NavigationHandle", this, |
| 790 base::StringPrintf("CheckWillRedirectRequest: %s: %d", | 793 base::StringPrintf("CheckWillRedirectRequest: %s: %d", |
| 791 throttles_[i]->GetNameForLogging(), result)); | 794 throttles_[i]->GetNameForLogging(), |
| 792 switch (result) { | 795 result.action())); |
| 796 switch (result.action()) { |
| 793 case NavigationThrottle::PROCEED: | 797 case NavigationThrottle::PROCEED: |
| 794 continue; | 798 continue; |
| 795 | 799 |
| 796 case NavigationThrottle::BLOCK_REQUEST: | 800 case NavigationThrottle::BLOCK_REQUEST: |
| 797 CHECK(IsBrowserSideNavigationEnabled()) | 801 CHECK(IsBrowserSideNavigationEnabled()) |
| 798 << "BLOCK_REQUEST must not be used on redirect without PlzNavigate"; | 802 << "BLOCK_REQUEST must not be used on redirect without PlzNavigate"; |
| 799 case NavigationThrottle::CANCEL: | 803 case NavigationThrottle::CANCEL: |
| 800 case NavigationThrottle::CANCEL_AND_IGNORE: | 804 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 801 state_ = CANCELING; | 805 state_ = CANCELING; |
| 802 return result; | 806 return result; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 825 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | 829 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); |
| 826 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | 830 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); |
| 827 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | 831 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); |
| 828 | 832 |
| 829 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 833 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 830 NavigationThrottle::ThrottleCheckResult result = | 834 NavigationThrottle::ThrottleCheckResult result = |
| 831 throttles_[i]->WillProcessResponse(); | 835 throttles_[i]->WillProcessResponse(); |
| 832 TRACE_EVENT_ASYNC_STEP_INTO0( | 836 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 833 "navigation", "NavigationHandle", this, | 837 "navigation", "NavigationHandle", this, |
| 834 base::StringPrintf("CheckWillProcessResponse: %s: %d", | 838 base::StringPrintf("CheckWillProcessResponse: %s: %d", |
| 835 throttles_[i]->GetNameForLogging(), result)); | 839 throttles_[i]->GetNameForLogging(), |
| 836 switch (result) { | 840 result.action())); |
| 841 switch (result.action()) { |
| 837 case NavigationThrottle::PROCEED: | 842 case NavigationThrottle::PROCEED: |
| 838 continue; | 843 continue; |
| 839 | 844 |
| 840 case NavigationThrottle::CANCEL: | 845 case NavigationThrottle::CANCEL: |
| 841 case NavigationThrottle::CANCEL_AND_IGNORE: | 846 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 842 case NavigationThrottle::BLOCK_RESPONSE: | 847 case NavigationThrottle::BLOCK_RESPONSE: |
| 843 state_ = CANCELING; | 848 state_ = CANCELING; |
| 844 return result; | 849 return result; |
| 845 | 850 |
| 846 case NavigationThrottle::DEFER: | 851 case NavigationThrottle::DEFER: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 transition_, should_replace_current_entry_); | 951 transition_, should_replace_current_entry_); |
| 947 if (!weak_self) | 952 if (!weak_self) |
| 948 return false; | 953 return false; |
| 949 } | 954 } |
| 950 | 955 |
| 951 return true; | 956 return true; |
| 952 } | 957 } |
| 953 | 958 |
| 954 void NavigationHandleImpl::RunCompleteCallback( | 959 void NavigationHandleImpl::RunCompleteCallback( |
| 955 NavigationThrottle::ThrottleCheckResult result) { | 960 NavigationThrottle::ThrottleCheckResult result) { |
| 956 DCHECK(result != NavigationThrottle::DEFER); | 961 DCHECK(result.action() != NavigationThrottle::DEFER); |
| 957 | 962 |
| 958 ThrottleChecksFinishedCallback callback = complete_callback_; | 963 ThrottleChecksFinishedCallback callback = complete_callback_; |
| 959 complete_callback_.Reset(); | 964 complete_callback_.Reset(); |
| 960 | 965 |
| 961 if (!complete_callback_for_testing_.is_null()) { | 966 if (!complete_callback_for_testing_.is_null()) { |
| 962 complete_callback_for_testing_.Run(result); | 967 complete_callback_for_testing_.Run(result); |
| 963 complete_callback_for_testing_.Reset(); | 968 complete_callback_for_testing_.Reset(); |
| 964 } | 969 } |
| 965 | 970 |
| 966 if (!callback.is_null()) | 971 if (!callback.is_null()) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 if (node->current_url().EqualsIgnoringRef(url_)) { | 1052 if (node->current_url().EqualsIgnoringRef(url_)) { |
| 1048 if (found_self_reference) | 1053 if (found_self_reference) |
| 1049 return true; | 1054 return true; |
| 1050 found_self_reference = true; | 1055 found_self_reference = true; |
| 1051 } | 1056 } |
| 1052 } | 1057 } |
| 1053 return false; | 1058 return false; |
| 1054 } | 1059 } |
| 1055 | 1060 |
| 1056 } // namespace content | 1061 } // namespace content |
| OLD | NEW |