Chromium Code Reviews| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT && | 310 if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT && |
| 311 state_ != DEFERRING_RESPONSE) { | 311 state_ != DEFERRING_RESPONSE) { |
| 312 return; | 312 return; |
| 313 } | 313 } |
| 314 | 314 |
| 315 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 315 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
| 316 if (state_ == DEFERRING_START) { | 316 if (state_ == DEFERRING_START) { |
| 317 result = CheckWillStartRequest(); | 317 result = CheckWillStartRequest(); |
| 318 } else if (state_ == DEFERRING_REDIRECT) { | 318 } else if (state_ == DEFERRING_REDIRECT) { |
| 319 result = CheckWillRedirectRequest(); | 319 result = CheckWillRedirectRequest(); |
| 320 if (!IsBrowserSideNavigationEnabled() && | |
| 321 result != NavigationThrottle::PROCEED && | |
| 322 result != NavigationThrottle::DEFER) { | |
| 323 // The renderer will not be informed of the redirect, as the navigation | |
| 324 // will have been cancelled before sending the | |
| 325 // ResourceMsg_ReceivedRedirect IPC. Reset the URL of the NavigationHandle | |
| 326 // to the URL it had prior to the redirect, to match the commit of an | |
| 327 // error page. | |
| 328 redirect_chain_.pop_back(); | |
| 329 DCHECK(!redirect_chain_.empty()); | |
| 330 url_ = redirect_chain_.back(); | |
| 331 } | |
| 320 } else { | 332 } else { |
| 321 result = CheckWillProcessResponse(); | 333 result = CheckWillProcessResponse(); |
| 322 | 334 |
| 323 // If the navigation is about to proceed after having been deferred while | 335 // If the navigation is about to proceed after having been deferred while |
| 324 // processing the response, then it's ready to commit. Determine which | 336 // processing the response, then it's ready to commit. Determine which |
| 325 // RenderFrameHost should render the response, based on its site (after any | 337 // RenderFrameHost should render the response, based on its site (after any |
| 326 // redirects). | 338 // redirects). |
| 327 // Note: if MaybeTransferAndProceed returns false, this means that this | 339 // Note: if MaybeTransferAndProceed returns false, this means that this |
| 328 // NavigationHandle was deleted, so return immediately. | 340 // NavigationHandle was deleted, so return immediately. |
| 329 if (result == NavigationThrottle::PROCEED && !MaybeTransferAndProceed()) | 341 if (result == NavigationThrottle::PROCEED && !MaybeTransferAndProceed()) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 response_headers_ = response_headers; | 568 response_headers_ = response_headers; |
| 557 connection_info_ = connection_info; | 569 connection_info_ = connection_info; |
| 558 was_redirected_ = true; | 570 was_redirected_ = true; |
| 559 redirect_chain_.push_back(new_url); | 571 redirect_chain_.push_back(new_url); |
| 560 if (new_method != "POST") | 572 if (new_method != "POST") |
| 561 resource_request_body_ = nullptr; | 573 resource_request_body_ = nullptr; |
| 562 | 574 |
| 563 state_ = WILL_REDIRECT_REQUEST; | 575 state_ = WILL_REDIRECT_REQUEST; |
| 564 complete_callback_ = callback; | 576 complete_callback_ = callback; |
| 565 | 577 |
| 566 if (IsSelfReferentialURL()) { | 578 // Notify each throttle of the request. |
| 579 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | |
| 580 if (!IsSelfReferentialURL()) { | |
|
nasko
2017/03/01 18:12:43
nit: It is easier to read the positive statement,
clamy
2017/03/02 12:43:17
Done.
| |
| 581 result = CheckWillRedirectRequest(); | |
| 582 } else { | |
| 567 state_ = CANCELING; | 583 state_ = CANCELING; |
| 568 RunCompleteCallback(NavigationThrottle::CANCEL); | 584 result = NavigationThrottle::CANCEL; |
| 569 return; | |
| 570 } | 585 } |
| 571 | 586 |
| 572 // Notify each throttle of the request. | 587 if (!IsBrowserSideNavigationEnabled() && |
| 573 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 588 result != NavigationThrottle::PROCEED && |
| 589 result != NavigationThrottle::DEFER) { | |
| 590 // The renderer will not be informed of the redirect, as the navigation | |
| 591 // will have been cancelled before sending the | |
| 592 // ResourceMsg_ReceivedRedirect IPC. Reset the URL of the NavigationHandle | |
| 593 // to the URL it had prior to the redirect, to match the commit of an | |
| 594 // error page. | |
| 595 redirect_chain_.pop_back(); | |
| 596 DCHECK(!redirect_chain_.empty()); | |
| 597 url_ = redirect_chain_.back(); | |
| 598 } | |
| 574 | 599 |
| 575 // If the navigation is not deferred, run the callback. | 600 // If the navigation is not deferred, run the callback. |
| 576 if (result != NavigationThrottle::DEFER) | 601 if (result != NavigationThrottle::DEFER) |
| 577 RunCompleteCallback(result); | 602 RunCompleteCallback(result); |
| 578 } | 603 } |
| 579 | 604 |
| 580 void NavigationHandleImpl::WillProcessResponse( | 605 void NavigationHandleImpl::WillProcessResponse( |
| 581 RenderFrameHostImpl* render_frame_host, | 606 RenderFrameHostImpl* render_frame_host, |
| 582 scoped_refptr<net::HttpResponseHeaders> response_headers, | 607 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 583 net::HttpResponseInfo::ConnectionInfo connection_info, | 608 net::HttpResponseInfo::ConnectionInfo connection_info, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); | 699 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); |
| 675 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); | 700 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); |
| 676 DCHECK(state_ != DEFERRING_START || next_index_ != 0); | 701 DCHECK(state_ != DEFERRING_START || next_index_ != 0); |
| 677 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 702 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 678 NavigationThrottle::ThrottleCheckResult result = | 703 NavigationThrottle::ThrottleCheckResult result = |
| 679 throttles_[i]->WillStartRequest(); | 704 throttles_[i]->WillStartRequest(); |
| 680 switch (result) { | 705 switch (result) { |
| 681 case NavigationThrottle::PROCEED: | 706 case NavigationThrottle::PROCEED: |
| 682 continue; | 707 continue; |
| 683 | 708 |
| 709 case NavigationThrottle::BLOCK_REQUEST: | |
| 684 case NavigationThrottle::CANCEL: | 710 case NavigationThrottle::CANCEL: |
| 685 case NavigationThrottle::CANCEL_AND_IGNORE: | 711 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 686 case NavigationThrottle::BLOCK_REQUEST: | |
| 687 state_ = CANCELING; | 712 state_ = CANCELING; |
| 688 return result; | 713 return result; |
| 689 | 714 |
| 690 case NavigationThrottle::DEFER: | 715 case NavigationThrottle::DEFER: |
| 691 state_ = DEFERRING_START; | 716 state_ = DEFERRING_START; |
| 692 next_index_ = i + 1; | 717 next_index_ = i + 1; |
| 693 return result; | 718 return result; |
| 694 | 719 |
| 695 case NavigationThrottle::BLOCK_RESPONSE: | 720 case NavigationThrottle::BLOCK_RESPONSE: |
| 696 NOTREACHED(); | 721 NOTREACHED(); |
| 697 } | 722 } |
| 698 } | 723 } |
| 699 next_index_ = 0; | 724 next_index_ = 0; |
| 700 state_ = WILL_SEND_REQUEST; | 725 state_ = WILL_SEND_REQUEST; |
| 701 return NavigationThrottle::PROCEED; | 726 return NavigationThrottle::PROCEED; |
| 702 } | 727 } |
| 703 | 728 |
| 704 NavigationThrottle::ThrottleCheckResult | 729 NavigationThrottle::ThrottleCheckResult |
| 705 NavigationHandleImpl::CheckWillRedirectRequest() { | 730 NavigationHandleImpl::CheckWillRedirectRequest() { |
| 706 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 731 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
| 707 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 732 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
| 708 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 733 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
| 709 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 734 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 710 NavigationThrottle::ThrottleCheckResult result = | 735 NavigationThrottle::ThrottleCheckResult result = |
| 711 throttles_[i]->WillRedirectRequest(); | 736 throttles_[i]->WillRedirectRequest(); |
| 712 switch (result) { | 737 switch (result) { |
| 713 case NavigationThrottle::PROCEED: | 738 case NavigationThrottle::PROCEED: |
| 714 continue; | 739 continue; |
| 715 | 740 |
| 741 case NavigationThrottle::BLOCK_REQUEST: | |
| 716 case NavigationThrottle::CANCEL: | 742 case NavigationThrottle::CANCEL: |
| 717 case NavigationThrottle::CANCEL_AND_IGNORE: | 743 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 718 state_ = CANCELING; | 744 state_ = CANCELING; |
| 719 return result; | 745 return result; |
| 720 | 746 |
| 721 case NavigationThrottle::DEFER: | 747 case NavigationThrottle::DEFER: |
| 722 state_ = DEFERRING_REDIRECT; | 748 state_ = DEFERRING_REDIRECT; |
| 723 next_index_ = i + 1; | 749 next_index_ = i + 1; |
| 724 return result; | 750 return result; |
| 725 | 751 |
| 726 case NavigationThrottle::BLOCK_REQUEST: | |
| 727 case NavigationThrottle::BLOCK_RESPONSE: | 752 case NavigationThrottle::BLOCK_RESPONSE: |
| 728 NOTREACHED(); | 753 NOTREACHED(); |
| 729 } | 754 } |
| 730 } | 755 } |
| 731 next_index_ = 0; | 756 next_index_ = 0; |
| 732 state_ = WILL_REDIRECT_REQUEST; | 757 state_ = WILL_REDIRECT_REQUEST; |
| 733 | 758 |
| 734 // Notify the delegate that a redirect was encountered and will be followed. | 759 // Notify the delegate that a redirect was encountered and will be followed. |
| 735 if (GetDelegate()) | 760 if (GetDelegate()) |
| 736 GetDelegate()->DidRedirectNavigation(this); | 761 GetDelegate()->DidRedirectNavigation(this); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 if (node->current_url().EqualsIgnoringRef(url_)) { | 957 if (node->current_url().EqualsIgnoringRef(url_)) { |
| 933 if (found_self_reference) | 958 if (found_self_reference) |
| 934 return true; | 959 return true; |
| 935 found_self_reference = true; | 960 found_self_reference = true; |
| 936 } | 961 } |
| 937 } | 962 } |
| 938 return false; | 963 return false; |
| 939 } | 964 } |
| 940 | 965 |
| 941 } // namespace content | 966 } // namespace content |
| OLD | NEW |