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

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

Issue 2727633005: PlzNavigate: Enforce frame-src CSP on the browser. (Closed)
Patch Set: Addressed Alex's comments + trying to fix subframe swap issue Created 3 years, 9 months 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 <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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // static 58 // static
59 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 59 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
60 const GURL& url, 60 const GURL& url,
61 const std::vector<GURL>& redirect_chain, 61 const std::vector<GURL>& redirect_chain,
62 FrameTreeNode* frame_tree_node, 62 FrameTreeNode* frame_tree_node,
63 bool is_renderer_initiated, 63 bool is_renderer_initiated,
64 bool is_same_page, 64 bool is_same_page,
65 const base::TimeTicks& navigation_start, 65 const base::TimeTicks& navigation_start,
66 int pending_nav_entry_id, 66 int pending_nav_entry_id,
67 bool started_from_context_menu) { 67 bool started_from_context_menu,
68 bool should_bypass_main_world_csp) {
68 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( 69 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl(
69 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page, 70 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page,
70 navigation_start, pending_nav_entry_id, 71 navigation_start, pending_nav_entry_id, started_from_context_menu,
71 started_from_context_menu)); 72 should_bypass_main_world_csp));
72 } 73 }
73 74
74 NavigationHandleImpl::NavigationHandleImpl( 75 NavigationHandleImpl::NavigationHandleImpl(
75 const GURL& url, 76 const GURL& url,
76 const std::vector<GURL>& redirect_chain, 77 const std::vector<GURL>& redirect_chain,
77 FrameTreeNode* frame_tree_node, 78 FrameTreeNode* frame_tree_node,
78 bool is_renderer_initiated, 79 bool is_renderer_initiated,
79 bool is_same_page, 80 bool is_same_page,
80 const base::TimeTicks& navigation_start, 81 const base::TimeTicks& navigation_start,
81 int pending_nav_entry_id, 82 int pending_nav_entry_id,
82 bool started_from_context_menu) 83 bool started_from_context_menu,
84 bool should_bypass_main_world_csp)
83 : url_(url), 85 : url_(url),
84 has_user_gesture_(false), 86 has_user_gesture_(false),
85 transition_(ui::PAGE_TRANSITION_LINK), 87 transition_(ui::PAGE_TRANSITION_LINK),
86 is_external_protocol_(false), 88 is_external_protocol_(false),
87 net_error_code_(net::OK), 89 net_error_code_(net::OK),
88 render_frame_host_(nullptr), 90 render_frame_host_(nullptr),
89 is_renderer_initiated_(is_renderer_initiated), 91 is_renderer_initiated_(is_renderer_initiated),
90 is_same_page_(is_same_page), 92 is_same_page_(is_same_page),
91 was_redirected_(false), 93 was_redirected_(false),
92 did_replace_entry_(false), 94 did_replace_entry_(false),
93 should_update_history_(false), 95 should_update_history_(false),
94 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), 96 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
95 original_url_(url), 97 original_url_(url),
96 state_(INITIAL), 98 state_(INITIAL),
97 is_transferring_(false), 99 is_transferring_(false),
98 frame_tree_node_(frame_tree_node), 100 frame_tree_node_(frame_tree_node),
99 next_index_(0), 101 next_index_(0),
100 navigation_start_(navigation_start), 102 navigation_start_(navigation_start),
101 pending_nav_entry_id_(pending_nav_entry_id), 103 pending_nav_entry_id_(pending_nav_entry_id),
102 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED), 104 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED),
103 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable), 105 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable),
104 should_replace_current_entry_(false), 106 should_replace_current_entry_(false),
105 redirect_chain_(redirect_chain), 107 redirect_chain_(redirect_chain),
106 is_download_(false), 108 is_download_(false),
107 is_stream_(false), 109 is_stream_(false),
108 started_from_context_menu_(started_from_context_menu), 110 started_from_context_menu_(started_from_context_menu),
109 reload_type_(ReloadType::NONE), 111 reload_type_(ReloadType::NONE),
110 restore_type_(RestoreType::NONE), 112 restore_type_(RestoreType::NONE),
111 navigation_type_(NAVIGATION_TYPE_UNKNOWN), 113 navigation_type_(NAVIGATION_TYPE_UNKNOWN),
114 should_bypass_main_world_csp_(should_bypass_main_world_csp),
112 weak_factory_(this) { 115 weak_factory_(this) {
113 DCHECK(!navigation_start.is_null()); 116 DCHECK(!navigation_start.is_null());
114 if (redirect_chain_.empty()) 117 if (redirect_chain_.empty())
115 redirect_chain_.push_back(url); 118 redirect_chain_.push_back(url);
116 119
117 starting_site_instance_ = 120 starting_site_instance_ =
118 frame_tree_node_->current_frame_host()->GetSiteInstance(); 121 frame_tree_node_->current_frame_host()->GetSiteInstance();
119 122
120 if (pending_nav_entry_id_) { 123 if (pending_nav_entry_id_) {
121 NavigationControllerImpl* nav_controller = 124 NavigationControllerImpl* nav_controller =
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); 679 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START);
677 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); 680 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0);
678 DCHECK(state_ != DEFERRING_START || next_index_ != 0); 681 DCHECK(state_ != DEFERRING_START || next_index_ != 0);
679 for (size_t i = next_index_; i < throttles_.size(); ++i) { 682 for (size_t i = next_index_; i < throttles_.size(); ++i) {
680 NavigationThrottle::ThrottleCheckResult result = 683 NavigationThrottle::ThrottleCheckResult result =
681 throttles_[i]->WillStartRequest(); 684 throttles_[i]->WillStartRequest();
682 switch (result) { 685 switch (result) {
683 case NavigationThrottle::PROCEED: 686 case NavigationThrottle::PROCEED:
684 continue; 687 continue;
685 688
689 case NavigationThrottle::BLOCK_REQUEST:
686 case NavigationThrottle::CANCEL: 690 case NavigationThrottle::CANCEL:
687 case NavigationThrottle::CANCEL_AND_IGNORE: 691 case NavigationThrottle::CANCEL_AND_IGNORE:
688 case NavigationThrottle::BLOCK_REQUEST:
689 state_ = CANCELING; 692 state_ = CANCELING;
690 return result; 693 return result;
691 694
692 case NavigationThrottle::DEFER: 695 case NavigationThrottle::DEFER:
693 state_ = DEFERRING_START; 696 state_ = DEFERRING_START;
694 next_index_ = i + 1; 697 next_index_ = i + 1;
695 return result; 698 return result;
696 699
697 case NavigationThrottle::BLOCK_RESPONSE: 700 case NavigationThrottle::BLOCK_RESPONSE:
698 NOTREACHED(); 701 NOTREACHED();
699 } 702 }
700 } 703 }
701 next_index_ = 0; 704 next_index_ = 0;
702 state_ = WILL_SEND_REQUEST; 705 state_ = WILL_SEND_REQUEST;
703 return NavigationThrottle::PROCEED; 706 return NavigationThrottle::PROCEED;
704 } 707 }
705 708
706 NavigationThrottle::ThrottleCheckResult 709 NavigationThrottle::ThrottleCheckResult
707 NavigationHandleImpl::CheckWillRedirectRequest() { 710 NavigationHandleImpl::CheckWillRedirectRequest() {
708 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); 711 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT);
709 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); 712 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0);
710 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); 713 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0);
711 for (size_t i = next_index_; i < throttles_.size(); ++i) { 714 for (size_t i = next_index_; i < throttles_.size(); ++i) {
712 NavigationThrottle::ThrottleCheckResult result = 715 NavigationThrottle::ThrottleCheckResult result =
713 throttles_[i]->WillRedirectRequest(); 716 throttles_[i]->WillRedirectRequest();
714 switch (result) { 717 switch (result) {
715 case NavigationThrottle::PROCEED: 718 case NavigationThrottle::PROCEED:
716 continue; 719 continue;
717 720
721 case NavigationThrottle::BLOCK_REQUEST:
718 case NavigationThrottle::CANCEL: 722 case NavigationThrottle::CANCEL:
719 case NavigationThrottle::CANCEL_AND_IGNORE: 723 case NavigationThrottle::CANCEL_AND_IGNORE:
720 state_ = CANCELING; 724 state_ = CANCELING;
721 return result; 725 return result;
722 726
723 case NavigationThrottle::DEFER: 727 case NavigationThrottle::DEFER:
724 state_ = DEFERRING_REDIRECT; 728 state_ = DEFERRING_REDIRECT;
725 next_index_ = i + 1; 729 next_index_ = i + 1;
726 return result; 730 return result;
727 731
728 case NavigationThrottle::BLOCK_REQUEST:
729 case NavigationThrottle::BLOCK_RESPONSE: 732 case NavigationThrottle::BLOCK_RESPONSE:
730 NOTREACHED(); 733 NOTREACHED();
731 } 734 }
732 } 735 }
733 next_index_ = 0; 736 next_index_ = 0;
734 state_ = WILL_REDIRECT_REQUEST; 737 state_ = WILL_REDIRECT_REQUEST;
735 738
736 // Notify the delegate that a redirect was encountered and will be followed. 739 // Notify the delegate that a redirect was encountered and will be followed.
737 if (GetDelegate()) 740 if (GetDelegate())
738 GetDelegate()->DidRedirectNavigation(this); 741 GetDelegate()->DidRedirectNavigation(this);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 if (node->current_url().EqualsIgnoringRef(url_)) { 937 if (node->current_url().EqualsIgnoringRef(url_)) {
935 if (found_self_reference) 938 if (found_self_reference)
936 return true; 939 return true;
937 found_self_reference = true; 940 found_self_reference = true;
938 } 941 }
939 } 942 }
940 return false; 943 return false;
941 } 944 }
942 945
943 } // namespace content 946 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698