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(); | |
|
Charlie Reis
2017/03/09 17:39:03
Does this mean that if we're redirecting from A to
arthursonzogni
2017/03/10 11:55:28
Yes unfortunately.
| |
| 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 |
| 578 // Notify each throttle of the request. | |
| 579 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | |
| 566 if (IsSelfReferentialURL()) { | 580 if (IsSelfReferentialURL()) { |
| 567 state_ = CANCELING; | 581 state_ = CANCELING; |
| 568 RunCompleteCallback(NavigationThrottle::CANCEL); | 582 result = NavigationThrottle::CANCEL; |
| 569 return; | 583 } else { |
| 584 result = CheckWillRedirectRequest(); | |
| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); | 701 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); |
| 677 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); | 702 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); |
| 678 DCHECK(state_ != DEFERRING_START || next_index_ != 0); | 703 DCHECK(state_ != DEFERRING_START || next_index_ != 0); |
| 679 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 704 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 680 NavigationThrottle::ThrottleCheckResult result = | 705 NavigationThrottle::ThrottleCheckResult result = |
| 681 throttles_[i]->WillStartRequest(); | 706 throttles_[i]->WillStartRequest(); |
| 682 switch (result) { | 707 switch (result) { |
| 683 case NavigationThrottle::PROCEED: | 708 case NavigationThrottle::PROCEED: |
| 684 continue; | 709 continue; |
| 685 | 710 |
| 711 case NavigationThrottle::BLOCK_REQUEST: | |
| 686 case NavigationThrottle::CANCEL: | 712 case NavigationThrottle::CANCEL: |
| 687 case NavigationThrottle::CANCEL_AND_IGNORE: | 713 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 688 case NavigationThrottle::BLOCK_REQUEST: | |
| 689 state_ = CANCELING; | 714 state_ = CANCELING; |
| 690 return result; | 715 return result; |
| 691 | 716 |
| 692 case NavigationThrottle::DEFER: | 717 case NavigationThrottle::DEFER: |
| 693 state_ = DEFERRING_START; | 718 state_ = DEFERRING_START; |
| 694 next_index_ = i + 1; | 719 next_index_ = i + 1; |
| 695 return result; | 720 return result; |
| 696 | 721 |
| 697 case NavigationThrottle::BLOCK_RESPONSE: | 722 case NavigationThrottle::BLOCK_RESPONSE: |
| 698 NOTREACHED(); | 723 NOTREACHED(); |
| 699 } | 724 } |
| 700 } | 725 } |
| 701 next_index_ = 0; | 726 next_index_ = 0; |
| 702 state_ = WILL_SEND_REQUEST; | 727 state_ = WILL_SEND_REQUEST; |
| 703 return NavigationThrottle::PROCEED; | 728 return NavigationThrottle::PROCEED; |
| 704 } | 729 } |
| 705 | 730 |
| 706 NavigationThrottle::ThrottleCheckResult | 731 NavigationThrottle::ThrottleCheckResult |
| 707 NavigationHandleImpl::CheckWillRedirectRequest() { | 732 NavigationHandleImpl::CheckWillRedirectRequest() { |
| 708 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 733 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
| 709 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 734 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
| 710 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 735 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
| 711 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 736 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 712 NavigationThrottle::ThrottleCheckResult result = | 737 NavigationThrottle::ThrottleCheckResult result = |
| 713 throttles_[i]->WillRedirectRequest(); | 738 throttles_[i]->WillRedirectRequest(); |
| 714 switch (result) { | 739 switch (result) { |
| 715 case NavigationThrottle::PROCEED: | 740 case NavigationThrottle::PROCEED: |
| 716 continue; | 741 continue; |
| 717 | 742 |
| 743 case NavigationThrottle::BLOCK_REQUEST: | |
| 718 case NavigationThrottle::CANCEL: | 744 case NavigationThrottle::CANCEL: |
| 719 case NavigationThrottle::CANCEL_AND_IGNORE: | 745 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 720 state_ = CANCELING; | 746 state_ = CANCELING; |
| 721 return result; | 747 return result; |
| 722 | 748 |
| 723 case NavigationThrottle::DEFER: | 749 case NavigationThrottle::DEFER: |
| 724 state_ = DEFERRING_REDIRECT; | 750 state_ = DEFERRING_REDIRECT; |
| 725 next_index_ = i + 1; | 751 next_index_ = i + 1; |
| 726 return result; | 752 return result; |
| 727 | 753 |
| 728 case NavigationThrottle::BLOCK_REQUEST: | |
| 729 case NavigationThrottle::BLOCK_RESPONSE: | 754 case NavigationThrottle::BLOCK_RESPONSE: |
| 730 NOTREACHED(); | 755 NOTREACHED(); |
|
Charlie Reis
2017/03/09 17:39:03
Unrelated: NOTREACHED is compiled out of release b
arthursonzogni
2017/03/10 11:55:28
It is impossible to have NavigationThrottle::BLOCK
Charlie Reis
2017/03/13 20:48:02
My concern was that a poorly written NavigationThr
| |
| 731 } | 756 } |
| 732 } | 757 } |
| 733 next_index_ = 0; | 758 next_index_ = 0; |
| 734 state_ = WILL_REDIRECT_REQUEST; | 759 state_ = WILL_REDIRECT_REQUEST; |
| 735 | 760 |
| 736 // Notify the delegate that a redirect was encountered and will be followed. | 761 // Notify the delegate that a redirect was encountered and will be followed. |
| 737 if (GetDelegate()) | 762 if (GetDelegate()) |
| 738 GetDelegate()->DidRedirectNavigation(this); | 763 GetDelegate()->DidRedirectNavigation(this); |
| 739 | 764 |
| 740 return NavigationThrottle::PROCEED; | 765 return NavigationThrottle::PROCEED; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 if (node->current_url().EqualsIgnoringRef(url_)) { | 959 if (node->current_url().EqualsIgnoringRef(url_)) { |
| 935 if (found_self_reference) | 960 if (found_self_reference) |
| 936 return true; | 961 return true; |
| 937 found_self_reference = true; | 962 found_self_reference = true; |
| 938 } | 963 } |
| 939 } | 964 } |
| 940 return false; | 965 return false; |
| 941 } | 966 } |
| 942 | 967 |
| 943 } // namespace content | 968 } // namespace content |
| OLD | NEW |