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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 283 |
283 if (result != NavigationThrottle::DEFER) | 284 if (result != NavigationThrottle::DEFER) |
284 RunCompleteCallback(result); | 285 RunCompleteCallback(result); |
285 } | 286 } |
286 | 287 |
287 void NavigationHandleImpl::CancelDeferredNavigation( | 288 void NavigationHandleImpl::CancelDeferredNavigation( |
288 NavigationThrottle::ThrottleCheckResult result) { | 289 NavigationThrottle::ThrottleCheckResult result) { |
289 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 290 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
290 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 291 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
291 result == NavigationThrottle::CANCEL); | 292 result == NavigationThrottle::CANCEL); |
292 state_ = CANCELING; | 293 state_ = CANCELING_REQUEST; |
293 RunCompleteCallback(result); | 294 RunCompleteCallback(result); |
294 } | 295 } |
295 | 296 |
296 void NavigationHandleImpl::RegisterThrottleForTesting( | 297 void NavigationHandleImpl::RegisterThrottleForTesting( |
297 std::unique_ptr<NavigationThrottle> navigation_throttle) { | 298 std::unique_ptr<NavigationThrottle> navigation_throttle) { |
298 throttles_.push_back(std::move(navigation_throttle)); | 299 throttles_.push_back(std::move(navigation_throttle)); |
299 } | 300 } |
300 | 301 |
301 NavigationThrottle::ThrottleCheckResult | 302 NavigationThrottle::ThrottleCheckResult |
302 NavigationHandleImpl::CallWillStartRequestForTesting( | 303 NavigationHandleImpl::CallWillStartRequestForTesting( |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 DCHECK(state_ != DEFERRING_START || next_index_ != 0); | 577 DCHECK(state_ != DEFERRING_START || next_index_ != 0); |
577 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 578 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
578 NavigationThrottle::ThrottleCheckResult result = | 579 NavigationThrottle::ThrottleCheckResult result = |
579 throttles_[i]->WillStartRequest(); | 580 throttles_[i]->WillStartRequest(); |
580 switch (result) { | 581 switch (result) { |
581 case NavigationThrottle::PROCEED: | 582 case NavigationThrottle::PROCEED: |
582 continue; | 583 continue; |
583 | 584 |
584 case NavigationThrottle::CANCEL: | 585 case NavigationThrottle::CANCEL: |
585 case NavigationThrottle::CANCEL_AND_IGNORE: | 586 case NavigationThrottle::CANCEL_AND_IGNORE: |
587 state_ = CANCELING_REQUEST; | |
588 return result; | |
589 | |
586 case NavigationThrottle::BLOCK_REQUEST: | 590 case NavigationThrottle::BLOCK_REQUEST: |
587 state_ = CANCELING; | 591 state_ = CANCELING_RESPONSE; |
alexmos
2016/11/30 01:22:19
I know this is the same as in mkwst@'s original CL
arthursonzogni
2016/11/30 13:49:55
It looks suspicious to me. I think CANCELING_REQUE
| |
588 return result; | 592 return result; |
589 | 593 |
590 case NavigationThrottle::DEFER: | 594 case NavigationThrottle::DEFER: |
591 state_ = DEFERRING_START; | 595 state_ = DEFERRING_START; |
592 next_index_ = i + 1; | 596 next_index_ = i + 1; |
593 return result; | 597 return result; |
598 | |
599 case NavigationThrottle::BLOCK_RESPONSE: | |
600 NOTREACHED(); | |
594 } | 601 } |
595 } | 602 } |
596 next_index_ = 0; | 603 next_index_ = 0; |
597 state_ = WILL_SEND_REQUEST; | 604 state_ = WILL_SEND_REQUEST; |
598 return NavigationThrottle::PROCEED; | 605 return NavigationThrottle::PROCEED; |
599 } | 606 } |
600 | 607 |
601 NavigationThrottle::ThrottleCheckResult | 608 NavigationThrottle::ThrottleCheckResult |
602 NavigationHandleImpl::CheckWillRedirectRequest() { | 609 NavigationHandleImpl::CheckWillRedirectRequest() { |
603 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 610 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
604 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 611 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
605 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 612 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
606 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 613 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
607 NavigationThrottle::ThrottleCheckResult result = | 614 NavigationThrottle::ThrottleCheckResult result = |
608 throttles_[i]->WillRedirectRequest(); | 615 throttles_[i]->WillRedirectRequest(); |
609 switch (result) { | 616 switch (result) { |
610 case NavigationThrottle::PROCEED: | 617 case NavigationThrottle::PROCEED: |
611 continue; | 618 continue; |
612 | 619 |
613 case NavigationThrottle::CANCEL: | 620 case NavigationThrottle::CANCEL: |
614 case NavigationThrottle::CANCEL_AND_IGNORE: | 621 case NavigationThrottle::CANCEL_AND_IGNORE: |
615 state_ = CANCELING; | 622 state_ = CANCELING_REQUEST; |
616 return result; | 623 return result; |
617 | 624 |
618 case NavigationThrottle::DEFER: | 625 case NavigationThrottle::DEFER: |
619 state_ = DEFERRING_REDIRECT; | 626 state_ = DEFERRING_REDIRECT; |
620 next_index_ = i + 1; | 627 next_index_ = i + 1; |
621 return result; | 628 return result; |
622 | 629 |
623 case NavigationThrottle::BLOCK_REQUEST: | 630 case NavigationThrottle::BLOCK_REQUEST: |
631 case NavigationThrottle::BLOCK_RESPONSE: | |
624 NOTREACHED(); | 632 NOTREACHED(); |
625 } | 633 } |
626 } | 634 } |
627 next_index_ = 0; | 635 next_index_ = 0; |
628 state_ = WILL_REDIRECT_REQUEST; | 636 state_ = WILL_REDIRECT_REQUEST; |
629 | 637 |
630 // Notify the delegate that a redirect was encountered and will be followed. | 638 // Notify the delegate that a redirect was encountered and will be followed. |
631 if (GetDelegate()) | 639 if (GetDelegate()) |
632 GetDelegate()->DidRedirectNavigation(this); | 640 GetDelegate()->DidRedirectNavigation(this); |
633 | 641 |
634 return NavigationThrottle::PROCEED; | 642 return NavigationThrottle::PROCEED; |
635 } | 643 } |
636 | 644 |
637 NavigationThrottle::ThrottleCheckResult | 645 NavigationThrottle::ThrottleCheckResult |
638 NavigationHandleImpl::CheckWillProcessResponse() { | 646 NavigationHandleImpl::CheckWillProcessResponse() { |
639 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | 647 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); |
640 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | 648 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); |
641 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | 649 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); |
642 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 650 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
643 NavigationThrottle::ThrottleCheckResult result = | 651 NavigationThrottle::ThrottleCheckResult result = |
644 throttles_[i]->WillProcessResponse(); | 652 throttles_[i]->WillProcessResponse(); |
645 switch (result) { | 653 switch (result) { |
646 case NavigationThrottle::PROCEED: | 654 case NavigationThrottle::PROCEED: |
647 continue; | 655 continue; |
648 | 656 |
649 case NavigationThrottle::CANCEL: | 657 case NavigationThrottle::CANCEL: |
650 case NavigationThrottle::CANCEL_AND_IGNORE: | 658 case NavigationThrottle::CANCEL_AND_IGNORE: |
651 state_ = CANCELING; | 659 state_ = CANCELING_REQUEST; |
660 return result; | |
661 | |
662 case NavigationThrottle::BLOCK_RESPONSE: | |
663 state_ = CANCELING_RESPONSE; | |
652 return result; | 664 return result; |
653 | 665 |
654 case NavigationThrottle::DEFER: | 666 case NavigationThrottle::DEFER: |
655 state_ = DEFERRING_RESPONSE; | 667 state_ = DEFERRING_RESPONSE; |
656 next_index_ = i + 1; | 668 next_index_ = i + 1; |
657 return result; | 669 return result; |
658 | 670 |
659 case NavigationThrottle::BLOCK_REQUEST: | 671 case NavigationThrottle::BLOCK_REQUEST: |
660 NOTREACHED(); | 672 NOTREACHED(); |
661 } | 673 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 | 779 |
768 // No code after running the callback, as it might have resulted in our | 780 // No code after running the callback, as it might have resulted in our |
769 // destruction. | 781 // destruction. |
770 } | 782 } |
771 | 783 |
772 void NavigationHandleImpl::RegisterNavigationThrottles() { | 784 void NavigationHandleImpl::RegisterNavigationThrottles() { |
773 // Register the navigation throttles. The ScopedVector returned by | 785 // Register the navigation throttles. The ScopedVector returned by |
774 // GetNavigationThrottles is not assigned to throttles_ directly because it | 786 // GetNavigationThrottles is not assigned to throttles_ directly because it |
775 // would overwrite any throttle previously added with | 787 // would overwrite any throttle previously added with |
776 // RegisterThrottleForTesting. | 788 // RegisterThrottleForTesting. |
789 | |
777 ScopedVector<NavigationThrottle> throttles_to_register = | 790 ScopedVector<NavigationThrottle> throttles_to_register = |
778 GetDelegate()->CreateThrottlesForNavigation(this); | 791 GetDelegate()->CreateThrottlesForNavigation(this); |
779 std::unique_ptr<NavigationThrottle> devtools_throttle = | 792 std::unique_ptr<NavigationThrottle> devtools_throttle = |
780 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); | 793 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); |
781 if (devtools_throttle) | 794 if (devtools_throttle) |
782 throttles_to_register.push_back(std::move(devtools_throttle)); | 795 throttles_to_register.push_back(std::move(devtools_throttle)); |
783 | 796 |
784 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = | 797 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = |
785 ClearSiteDataThrottle::CreateThrottleForNavigation(this); | 798 ClearSiteDataThrottle::CreateThrottleForNavigation(this); |
786 if (clear_site_data_throttle) | 799 if (clear_site_data_throttle) |
787 throttles_to_register.push_back(std::move(clear_site_data_throttle)); | 800 throttles_to_register.push_back(std::move(clear_site_data_throttle)); |
788 | 801 |
802 std::unique_ptr<content::NavigationThrottle> ancestor_throttle = | |
803 content::AncestorThrottle::MaybeCreateThrottleFor(this); | |
804 if (ancestor_throttle) | |
805 throttles_.push_back(std::move(ancestor_throttle)); | |
806 | |
789 if (throttles_to_register.size() > 0) { | 807 if (throttles_to_register.size() > 0) { |
790 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), | 808 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), |
791 throttles_to_register.end()); | 809 throttles_to_register.end()); |
792 throttles_to_register.weak_clear(); | 810 throttles_to_register.weak_clear(); |
793 } | 811 } |
794 } | 812 } |
795 | 813 |
796 } // namespace content | 814 } // namespace content |
OLD | NEW |