Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 2321503002: (Re-)introduce AncestorThrottle to handle 'X-Frame-Options'. (Closed)
Patch Set: Rebase after a month... Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/debug/dump_without_crashing.h" 9 #include "base/debug/dump_without_crashing.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "content/browser/browsing_data/clear_site_data_throttle.h" 11 #include "content/browser/browsing_data/clear_site_data_throttle.h"
12 #include "content/browser/child_process_security_policy_impl.h" 12 #include "content/browser/child_process_security_policy_impl.h"
13 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 13 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
14 #include "content/browser/frame_host/ancestor_throttle.h"
14 #include "content/browser/frame_host/frame_tree_node.h" 15 #include "content/browser/frame_host/frame_tree_node.h"
15 #include "content/browser/frame_host/navigator.h" 16 #include "content/browser/frame_host/navigator.h"
16 #include "content/browser/frame_host/navigator_delegate.h" 17 #include "content/browser/frame_host/navigator_delegate.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"
22 #include "content/public/browser/content_browser_client.h" 23 #include "content/public/browser/content_browser_client.h"
23 #include "content/public/browser/navigation_ui_data.h" 24 #include "content/public/browser/navigation_ui_data.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 268
268 if (result != NavigationThrottle::DEFER) 269 if (result != NavigationThrottle::DEFER)
269 RunCompleteCallback(result); 270 RunCompleteCallback(result);
270 } 271 }
271 272
272 void NavigationHandleImpl::CancelDeferredNavigation( 273 void NavigationHandleImpl::CancelDeferredNavigation(
273 NavigationThrottle::ThrottleCheckResult result) { 274 NavigationThrottle::ThrottleCheckResult result) {
274 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); 275 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT);
275 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || 276 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE ||
276 result == NavigationThrottle::CANCEL); 277 result == NavigationThrottle::CANCEL);
277 state_ = CANCELING; 278 state_ = CANCELING_REQUEST;
278 RunCompleteCallback(result); 279 RunCompleteCallback(result);
279 } 280 }
280 281
281 void NavigationHandleImpl::RegisterThrottleForTesting( 282 void NavigationHandleImpl::RegisterThrottleForTesting(
282 std::unique_ptr<NavigationThrottle> navigation_throttle) { 283 std::unique_ptr<NavigationThrottle> navigation_throttle) {
283 throttles_.push_back(std::move(navigation_throttle)); 284 throttles_.push_back(std::move(navigation_throttle));
284 } 285 }
285 286
286 NavigationThrottle::ThrottleCheckResult 287 NavigationThrottle::ThrottleCheckResult
287 NavigationHandleImpl::CallWillStartRequestForTesting( 288 NavigationHandleImpl::CallWillStartRequestForTesting(
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 DCHECK(state_ != DEFERRING_START || next_index_ != 0); 538 DCHECK(state_ != DEFERRING_START || next_index_ != 0);
538 for (size_t i = next_index_; i < throttles_.size(); ++i) { 539 for (size_t i = next_index_; i < throttles_.size(); ++i) {
539 NavigationThrottle::ThrottleCheckResult result = 540 NavigationThrottle::ThrottleCheckResult result =
540 throttles_[i]->WillStartRequest(); 541 throttles_[i]->WillStartRequest();
541 switch (result) { 542 switch (result) {
542 case NavigationThrottle::PROCEED: 543 case NavigationThrottle::PROCEED:
543 continue; 544 continue;
544 545
545 case NavigationThrottle::CANCEL: 546 case NavigationThrottle::CANCEL:
546 case NavigationThrottle::CANCEL_AND_IGNORE: 547 case NavigationThrottle::CANCEL_AND_IGNORE:
548 state_ = CANCELING_REQUEST;
549 return result;
550
547 case NavigationThrottle::BLOCK_REQUEST: 551 case NavigationThrottle::BLOCK_REQUEST:
548 state_ = CANCELING; 552 state_ = CANCELING_RESPONSE;
549 return result; 553 return result;
550 554
551 case NavigationThrottle::DEFER: 555 case NavigationThrottle::DEFER:
552 state_ = DEFERRING_START; 556 state_ = DEFERRING_START;
553 next_index_ = i + 1; 557 next_index_ = i + 1;
554 return result; 558 return result;
559
560 case NavigationThrottle::BLOCK_RESPONSE:
561 NOTREACHED();
555 } 562 }
556 } 563 }
557 next_index_ = 0; 564 next_index_ = 0;
558 state_ = WILL_SEND_REQUEST; 565 state_ = WILL_SEND_REQUEST;
559 return NavigationThrottle::PROCEED; 566 return NavigationThrottle::PROCEED;
560 } 567 }
561 568
562 NavigationThrottle::ThrottleCheckResult 569 NavigationThrottle::ThrottleCheckResult
563 NavigationHandleImpl::CheckWillRedirectRequest() { 570 NavigationHandleImpl::CheckWillRedirectRequest() {
564 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); 571 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT);
565 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); 572 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0);
566 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); 573 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0);
567 for (size_t i = next_index_; i < throttles_.size(); ++i) { 574 for (size_t i = next_index_; i < throttles_.size(); ++i) {
568 NavigationThrottle::ThrottleCheckResult result = 575 NavigationThrottle::ThrottleCheckResult result =
569 throttles_[i]->WillRedirectRequest(); 576 throttles_[i]->WillRedirectRequest();
570 switch (result) { 577 switch (result) {
571 case NavigationThrottle::PROCEED: 578 case NavigationThrottle::PROCEED:
572 continue; 579 continue;
573 580
574 case NavigationThrottle::CANCEL: 581 case NavigationThrottle::CANCEL:
575 case NavigationThrottle::CANCEL_AND_IGNORE: 582 case NavigationThrottle::CANCEL_AND_IGNORE:
576 state_ = CANCELING; 583 state_ = CANCELING_REQUEST;
577 return result; 584 return result;
578 585
579 case NavigationThrottle::DEFER: 586 case NavigationThrottle::DEFER:
580 state_ = DEFERRING_REDIRECT; 587 state_ = DEFERRING_REDIRECT;
581 next_index_ = i + 1; 588 next_index_ = i + 1;
582 return result; 589 return result;
583 590
584 case NavigationThrottle::BLOCK_REQUEST: 591 case NavigationThrottle::BLOCK_REQUEST:
592 case NavigationThrottle::BLOCK_RESPONSE:
585 NOTREACHED(); 593 NOTREACHED();
586 } 594 }
587 } 595 }
588 next_index_ = 0; 596 next_index_ = 0;
589 state_ = WILL_REDIRECT_REQUEST; 597 state_ = WILL_REDIRECT_REQUEST;
590 598
591 // Notify the delegate that a redirect was encountered and will be followed. 599 // Notify the delegate that a redirect was encountered and will be followed.
592 if (GetDelegate()) 600 if (GetDelegate())
593 GetDelegate()->DidRedirectNavigation(this); 601 GetDelegate()->DidRedirectNavigation(this);
594 602
595 return NavigationThrottle::PROCEED; 603 return NavigationThrottle::PROCEED;
596 } 604 }
597 605
598 NavigationThrottle::ThrottleCheckResult 606 NavigationThrottle::ThrottleCheckResult
599 NavigationHandleImpl::CheckWillProcessResponse() { 607 NavigationHandleImpl::CheckWillProcessResponse() {
600 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); 608 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE);
601 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); 609 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0);
602 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); 610 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0);
603 for (size_t i = next_index_; i < throttles_.size(); ++i) { 611 for (size_t i = next_index_; i < throttles_.size(); ++i) {
604 NavigationThrottle::ThrottleCheckResult result = 612 NavigationThrottle::ThrottleCheckResult result =
605 throttles_[i]->WillProcessResponse(); 613 throttles_[i]->WillProcessResponse();
606 switch (result) { 614 switch (result) {
607 case NavigationThrottle::PROCEED: 615 case NavigationThrottle::PROCEED:
608 continue; 616 continue;
609 617
610 case NavigationThrottle::CANCEL: 618 case NavigationThrottle::CANCEL:
611 case NavigationThrottle::CANCEL_AND_IGNORE: 619 case NavigationThrottle::CANCEL_AND_IGNORE:
612 state_ = CANCELING; 620 state_ = CANCELING_REQUEST;
621 return result;
622
623 case NavigationThrottle::BLOCK_RESPONSE:
624 state_ = CANCELING_RESPONSE;
613 return result; 625 return result;
614 626
615 case NavigationThrottle::DEFER: 627 case NavigationThrottle::DEFER:
616 state_ = DEFERRING_RESPONSE; 628 state_ = DEFERRING_RESPONSE;
617 next_index_ = i + 1; 629 next_index_ = i + 1;
618 return result; 630 return result;
619 631
620 case NavigationThrottle::BLOCK_REQUEST: 632 case NavigationThrottle::BLOCK_REQUEST:
621 NOTREACHED(); 633 NOTREACHED();
622 } 634 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 740
729 // No code after running the callback, as it might have resulted in our 741 // No code after running the callback, as it might have resulted in our
730 // destruction. 742 // destruction.
731 } 743 }
732 744
733 void NavigationHandleImpl::RegisterNavigationThrottles() { 745 void NavigationHandleImpl::RegisterNavigationThrottles() {
734 // Register the navigation throttles. The ScopedVector returned by 746 // Register the navigation throttles. The ScopedVector returned by
735 // GetNavigationThrottles is not assigned to throttles_ directly because it 747 // GetNavigationThrottles is not assigned to throttles_ directly because it
736 // would overwrite any throttle previously added with 748 // would overwrite any throttle previously added with
737 // RegisterThrottleForTesting. 749 // RegisterThrottleForTesting.
750
738 ScopedVector<NavigationThrottle> throttles_to_register = 751 ScopedVector<NavigationThrottle> throttles_to_register =
739 GetDelegate()->CreateThrottlesForNavigation(this); 752 GetDelegate()->CreateThrottlesForNavigation(this);
740 std::unique_ptr<NavigationThrottle> devtools_throttle = 753 std::unique_ptr<NavigationThrottle> devtools_throttle =
741 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); 754 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this);
742 if (devtools_throttle) 755 if (devtools_throttle)
743 throttles_to_register.push_back(std::move(devtools_throttle)); 756 throttles_to_register.push_back(std::move(devtools_throttle));
744 757
745 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = 758 std::unique_ptr<NavigationThrottle> clear_site_data_throttle =
746 ClearSiteDataThrottle::CreateThrottleForNavigation(this); 759 ClearSiteDataThrottle::CreateThrottleForNavigation(this);
747 if (clear_site_data_throttle) 760 if (clear_site_data_throttle)
748 throttles_to_register.push_back(std::move(clear_site_data_throttle)); 761 throttles_to_register.push_back(std::move(clear_site_data_throttle));
749 762
763 std::unique_ptr<content::NavigationThrottle> ancestor_throttle =
764 content::AncestorThrottle::MaybeCreateThrottleFor(this);
765 if (ancestor_throttle)
766 throttles_.push_back(std::move(ancestor_throttle));
767
750 if (throttles_to_register.size() > 0) { 768 if (throttles_to_register.size() > 0) {
751 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), 769 throttles_.insert(throttles_.begin(), throttles_to_register.begin(),
752 throttles_to_register.end()); 770 throttles_to_register.end());
753 throttles_to_register.weak_clear(); 771 throttles_to_register.weak_clear();
754 } 772 }
755 } 773 }
756 774
757 bool NavigationHandleImpl::WasStartedFromContextMenu() const { 775 bool NavigationHandleImpl::WasStartedFromContextMenu() const {
758 return started_from_context_menu_; 776 return started_from_context_menu_;
759 } 777 }
760 778
761 } // namespace content 779 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.h ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698