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 "base/debug/dump_without_crashing.h" | 7 #include "base/debug/dump_without_crashing.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/browsing_data/clear_site_data_throttle.h" | 9 #include "content/browser/browsing_data/clear_site_data_throttle.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
11 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 11 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
12 #include "content/browser/frame_host/ancestor_throttle.h" | |
12 #include "content/browser/frame_host/debug_urls.h" | 13 #include "content/browser/frame_host/debug_urls.h" |
13 #include "content/browser/frame_host/frame_tree_node.h" | 14 #include "content/browser/frame_host/frame_tree_node.h" |
14 #include "content/browser/frame_host/navigator.h" | 15 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/navigator_delegate.h" | 16 #include "content/browser/frame_host/navigator_delegate.h" |
16 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 19 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
19 #include "content/common/frame_messages.h" | 20 #include "content/common/frame_messages.h" |
20 #include "content/common/resource_request_body_impl.h" | 21 #include "content/common/resource_request_body_impl.h" |
21 #include "content/common/site_isolation_policy.h" | 22 #include "content/common/site_isolation_policy.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 | 284 |
284 if (result != NavigationThrottle::DEFER) | 285 if (result != NavigationThrottle::DEFER) |
285 RunCompleteCallback(result); | 286 RunCompleteCallback(result); |
286 } | 287 } |
287 | 288 |
288 void NavigationHandleImpl::CancelDeferredNavigation( | 289 void NavigationHandleImpl::CancelDeferredNavigation( |
289 NavigationThrottle::ThrottleCheckResult result) { | 290 NavigationThrottle::ThrottleCheckResult result) { |
290 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 291 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
291 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 292 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
292 result == NavigationThrottle::CANCEL); | 293 result == NavigationThrottle::CANCEL); |
293 state_ = CANCELING; | 294 state_ = CANCELING_REQUEST; |
clamy
2016/12/06 17:09:43
Note: technically the navigation could be cancelle
arthursonzogni
2016/12/07 16:25:02
I updated the DCHECK.
As I said above, I will merg
| |
294 RunCompleteCallback(result); | 295 RunCompleteCallback(result); |
295 } | 296 } |
296 | 297 |
297 void NavigationHandleImpl::RegisterThrottleForTesting( | 298 void NavigationHandleImpl::RegisterThrottleForTesting( |
298 std::unique_ptr<NavigationThrottle> navigation_throttle) { | 299 std::unique_ptr<NavigationThrottle> navigation_throttle) { |
299 throttles_.push_back(std::move(navigation_throttle)); | 300 throttles_.push_back(std::move(navigation_throttle)); |
300 } | 301 } |
301 | 302 |
302 NavigationThrottle::ThrottleCheckResult | 303 NavigationThrottle::ThrottleCheckResult |
303 NavigationHandleImpl::CallWillStartRequestForTesting( | 304 NavigationHandleImpl::CallWillStartRequestForTesting( |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 579 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
579 NavigationThrottle::ThrottleCheckResult result = | 580 NavigationThrottle::ThrottleCheckResult result = |
580 throttles_[i]->WillStartRequest(); | 581 throttles_[i]->WillStartRequest(); |
581 switch (result) { | 582 switch (result) { |
582 case NavigationThrottle::PROCEED: | 583 case NavigationThrottle::PROCEED: |
583 continue; | 584 continue; |
584 | 585 |
585 case NavigationThrottle::CANCEL: | 586 case NavigationThrottle::CANCEL: |
586 case NavigationThrottle::CANCEL_AND_IGNORE: | 587 case NavigationThrottle::CANCEL_AND_IGNORE: |
587 case NavigationThrottle::BLOCK_REQUEST: | 588 case NavigationThrottle::BLOCK_REQUEST: |
588 state_ = CANCELING; | 589 state_ = CANCELING_REQUEST; |
589 return result; | 590 return result; |
590 | 591 |
591 case NavigationThrottle::DEFER: | 592 case NavigationThrottle::DEFER: |
592 state_ = DEFERRING_START; | 593 state_ = DEFERRING_START; |
593 next_index_ = i + 1; | 594 next_index_ = i + 1; |
594 return result; | 595 return result; |
596 | |
597 case NavigationThrottle::BLOCK_RESPONSE: | |
598 NOTREACHED(); | |
595 } | 599 } |
596 } | 600 } |
597 next_index_ = 0; | 601 next_index_ = 0; |
598 state_ = WILL_SEND_REQUEST; | 602 state_ = WILL_SEND_REQUEST; |
599 return NavigationThrottle::PROCEED; | 603 return NavigationThrottle::PROCEED; |
600 } | 604 } |
601 | 605 |
602 NavigationThrottle::ThrottleCheckResult | 606 NavigationThrottle::ThrottleCheckResult |
603 NavigationHandleImpl::CheckWillRedirectRequest() { | 607 NavigationHandleImpl::CheckWillRedirectRequest() { |
604 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 608 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
605 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 609 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
606 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 610 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
607 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 611 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
608 NavigationThrottle::ThrottleCheckResult result = | 612 NavigationThrottle::ThrottleCheckResult result = |
609 throttles_[i]->WillRedirectRequest(); | 613 throttles_[i]->WillRedirectRequest(); |
610 switch (result) { | 614 switch (result) { |
611 case NavigationThrottle::PROCEED: | 615 case NavigationThrottle::PROCEED: |
612 continue; | 616 continue; |
613 | 617 |
614 case NavigationThrottle::CANCEL: | 618 case NavigationThrottle::CANCEL: |
615 case NavigationThrottle::CANCEL_AND_IGNORE: | 619 case NavigationThrottle::CANCEL_AND_IGNORE: |
616 state_ = CANCELING; | 620 state_ = CANCELING_REQUEST; |
617 return result; | 621 return result; |
618 | 622 |
619 case NavigationThrottle::DEFER: | 623 case NavigationThrottle::DEFER: |
620 state_ = DEFERRING_REDIRECT; | 624 state_ = DEFERRING_REDIRECT; |
621 next_index_ = i + 1; | 625 next_index_ = i + 1; |
622 return result; | 626 return result; |
623 | 627 |
624 case NavigationThrottle::BLOCK_REQUEST: | 628 case NavigationThrottle::BLOCK_REQUEST: |
629 case NavigationThrottle::BLOCK_RESPONSE: | |
625 NOTREACHED(); | 630 NOTREACHED(); |
626 } | 631 } |
627 } | 632 } |
628 next_index_ = 0; | 633 next_index_ = 0; |
629 state_ = WILL_REDIRECT_REQUEST; | 634 state_ = WILL_REDIRECT_REQUEST; |
630 | 635 |
631 // Notify the delegate that a redirect was encountered and will be followed. | 636 // Notify the delegate that a redirect was encountered and will be followed. |
632 if (GetDelegate()) | 637 if (GetDelegate()) |
633 GetDelegate()->DidRedirectNavigation(this); | 638 GetDelegate()->DidRedirectNavigation(this); |
634 | 639 |
635 return NavigationThrottle::PROCEED; | 640 return NavigationThrottle::PROCEED; |
636 } | 641 } |
637 | 642 |
638 NavigationThrottle::ThrottleCheckResult | 643 NavigationThrottle::ThrottleCheckResult |
639 NavigationHandleImpl::CheckWillProcessResponse() { | 644 NavigationHandleImpl::CheckWillProcessResponse() { |
640 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | 645 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); |
641 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | 646 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); |
642 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | 647 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); |
643 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 648 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
644 NavigationThrottle::ThrottleCheckResult result = | 649 NavigationThrottle::ThrottleCheckResult result = |
645 throttles_[i]->WillProcessResponse(); | 650 throttles_[i]->WillProcessResponse(); |
646 switch (result) { | 651 switch (result) { |
647 case NavigationThrottle::PROCEED: | 652 case NavigationThrottle::PROCEED: |
648 continue; | 653 continue; |
649 | 654 |
650 case NavigationThrottle::CANCEL: | 655 case NavigationThrottle::CANCEL: |
651 case NavigationThrottle::CANCEL_AND_IGNORE: | 656 case NavigationThrottle::CANCEL_AND_IGNORE: |
652 state_ = CANCELING; | 657 state_ = CANCELING_REQUEST; |
658 return result; | |
659 | |
660 case NavigationThrottle::BLOCK_RESPONSE: | |
661 state_ = CANCELING_RESPONSE; | |
653 return result; | 662 return result; |
654 | 663 |
655 case NavigationThrottle::DEFER: | 664 case NavigationThrottle::DEFER: |
656 state_ = DEFERRING_RESPONSE; | 665 state_ = DEFERRING_RESPONSE; |
657 next_index_ = i + 1; | 666 next_index_ = i + 1; |
658 return result; | 667 return result; |
659 | 668 |
660 case NavigationThrottle::BLOCK_REQUEST: | 669 case NavigationThrottle::BLOCK_REQUEST: |
661 NOTREACHED(); | 670 NOTREACHED(); |
662 } | 671 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 | 777 |
769 // No code after running the callback, as it might have resulted in our | 778 // No code after running the callback, as it might have resulted in our |
770 // destruction. | 779 // destruction. |
771 } | 780 } |
772 | 781 |
773 void NavigationHandleImpl::RegisterNavigationThrottles() { | 782 void NavigationHandleImpl::RegisterNavigationThrottles() { |
774 // Register the navigation throttles. The ScopedVector returned by | 783 // Register the navigation throttles. The ScopedVector returned by |
775 // GetNavigationThrottles is not assigned to throttles_ directly because it | 784 // GetNavigationThrottles is not assigned to throttles_ directly because it |
776 // would overwrite any throttle previously added with | 785 // would overwrite any throttle previously added with |
777 // RegisterThrottleForTesting. | 786 // RegisterThrottleForTesting. |
787 | |
778 ScopedVector<NavigationThrottle> throttles_to_register = | 788 ScopedVector<NavigationThrottle> throttles_to_register = |
779 GetDelegate()->CreateThrottlesForNavigation(this); | 789 GetDelegate()->CreateThrottlesForNavigation(this); |
780 std::unique_ptr<NavigationThrottle> devtools_throttle = | 790 std::unique_ptr<NavigationThrottle> devtools_throttle = |
781 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); | 791 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); |
782 if (devtools_throttle) | 792 if (devtools_throttle) |
783 throttles_to_register.push_back(std::move(devtools_throttle)); | 793 throttles_to_register.push_back(std::move(devtools_throttle)); |
784 | 794 |
785 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = | 795 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = |
786 ClearSiteDataThrottle::CreateThrottleForNavigation(this); | 796 ClearSiteDataThrottle::CreateThrottleForNavigation(this); |
787 if (clear_site_data_throttle) | 797 if (clear_site_data_throttle) |
788 throttles_to_register.push_back(std::move(clear_site_data_throttle)); | 798 throttles_to_register.push_back(std::move(clear_site_data_throttle)); |
789 | 799 |
800 std::unique_ptr<content::NavigationThrottle> ancestor_throttle = | |
801 content::AncestorThrottle::MaybeCreateThrottleFor(this); | |
802 if (ancestor_throttle) | |
803 throttles_.push_back(std::move(ancestor_throttle)); | |
804 | |
790 if (throttles_to_register.size() > 0) { | 805 if (throttles_to_register.size() > 0) { |
791 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), | 806 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), |
792 throttles_to_register.end()); | 807 throttles_to_register.end()); |
793 throttles_to_register.weak_clear(); | 808 throttles_to_register.weak_clear(); |
794 } | 809 } |
795 } | 810 } |
796 | 811 |
797 } // namespace content | 812 } // namespace content |
OLD | NEW |