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

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

Issue 2689653003: PlzNavigate: Enforce 'form-action' CSP on the browser-side. (Closed)
Patch Set: PlzNavigate: Enforce 'form-action' CSP on the browser-side. Created 3 years, 10 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/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/appcache/appcache_navigation_handle.h" 11 #include "content/browser/appcache/appcache_navigation_handle.h"
12 #include "content/browser/appcache/appcache_service_impl.h" 12 #include "content/browser/appcache/appcache_service_impl.h"
13 #include "content/browser/browsing_data/clear_site_data_throttle.h" 13 #include "content/browser/browsing_data/clear_site_data_throttle.h"
14 #include "content/browser/child_process_security_policy_impl.h" 14 #include "content/browser/child_process_security_policy_impl.h"
15 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 15 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
16 #include "content/browser/frame_host/ancestor_throttle.h" 16 #include "content/browser/frame_host/ancestor_throttle.h"
17 #include "content/browser/frame_host/debug_urls.h" 17 #include "content/browser/frame_host/debug_urls.h"
18 #include "content/browser/frame_host/form_submission_throttle.h"
18 #include "content/browser/frame_host/frame_tree_node.h" 19 #include "content/browser/frame_host/frame_tree_node.h"
19 #include "content/browser/frame_host/mixed_content_navigation_throttle.h" 20 #include "content/browser/frame_host/mixed_content_navigation_throttle.h"
20 #include "content/browser/frame_host/navigation_controller_impl.h" 21 #include "content/browser/frame_host/navigation_controller_impl.h"
21 #include "content/browser/frame_host/navigation_entry_impl.h" 22 #include "content/browser/frame_host/navigation_entry_impl.h"
22 #include "content/browser/frame_host/navigator.h" 23 #include "content/browser/frame_host/navigator.h"
23 #include "content/browser/frame_host/navigator_delegate.h" 24 #include "content/browser/frame_host/navigator_delegate.h"
24 #include "content/browser/loader/resource_dispatcher_host_impl.h" 25 #include "content/browser/loader/resource_dispatcher_host_impl.h"
25 #include "content/browser/service_worker/service_worker_context_wrapper.h" 26 #include "content/browser/service_worker/service_worker_context_wrapper.h"
26 #include "content/browser/service_worker/service_worker_navigation_handle.h" 27 #include "content/browser/service_worker/service_worker_navigation_handle.h"
27 #include "content/common/frame_messages.h" 28 #include "content/common/frame_messages.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // static 60 // static
60 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 61 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
61 const GURL& url, 62 const GURL& url,
62 const std::vector<GURL>& redirect_chain, 63 const std::vector<GURL>& redirect_chain,
63 FrameTreeNode* frame_tree_node, 64 FrameTreeNode* frame_tree_node,
64 bool is_renderer_initiated, 65 bool is_renderer_initiated,
65 bool is_same_page, 66 bool is_same_page,
66 const base::TimeTicks& navigation_start, 67 const base::TimeTicks& navigation_start,
67 int pending_nav_entry_id, 68 int pending_nav_entry_id,
68 bool started_from_context_menu, 69 bool started_from_context_menu,
69 bool should_bypass_main_world_csp) { 70 bool should_bypass_main_world_csp,
71 bool is_form_submission) {
70 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( 72 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl(
71 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page, 73 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page,
72 navigation_start, pending_nav_entry_id, started_from_context_menu, 74 navigation_start, pending_nav_entry_id, started_from_context_menu,
73 should_bypass_main_world_csp)); 75 should_bypass_main_world_csp, is_form_submission));
74 } 76 }
75 77
76 NavigationHandleImpl::NavigationHandleImpl( 78 NavigationHandleImpl::NavigationHandleImpl(
77 const GURL& url, 79 const GURL& url,
78 const std::vector<GURL>& redirect_chain, 80 const std::vector<GURL>& redirect_chain,
79 FrameTreeNode* frame_tree_node, 81 FrameTreeNode* frame_tree_node,
80 bool is_renderer_initiated, 82 bool is_renderer_initiated,
81 bool is_same_page, 83 bool is_same_page,
82 const base::TimeTicks& navigation_start, 84 const base::TimeTicks& navigation_start,
83 int pending_nav_entry_id, 85 int pending_nav_entry_id,
84 bool started_from_context_menu, 86 bool started_from_context_menu,
85 bool should_bypass_main_world_csp) 87 bool should_bypass_main_world_csp,
88 bool is_form_submission)
86 : url_(url), 89 : url_(url),
87 has_user_gesture_(false), 90 has_user_gesture_(false),
88 transition_(ui::PAGE_TRANSITION_LINK), 91 transition_(ui::PAGE_TRANSITION_LINK),
89 is_external_protocol_(false), 92 is_external_protocol_(false),
90 net_error_code_(net::OK), 93 net_error_code_(net::OK),
91 render_frame_host_(nullptr), 94 render_frame_host_(nullptr),
92 is_renderer_initiated_(is_renderer_initiated), 95 is_renderer_initiated_(is_renderer_initiated),
93 is_same_page_(is_same_page), 96 is_same_page_(is_same_page),
94 was_redirected_(false), 97 was_redirected_(false),
95 did_replace_entry_(false), 98 did_replace_entry_(false),
96 should_update_history_(false), 99 should_update_history_(false),
97 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), 100 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
98 original_url_(url), 101 original_url_(url),
99 state_(INITIAL), 102 state_(INITIAL),
100 is_transferring_(false), 103 is_transferring_(false),
101 frame_tree_node_(frame_tree_node), 104 frame_tree_node_(frame_tree_node),
102 next_index_(0), 105 next_index_(0),
103 navigation_start_(navigation_start), 106 navigation_start_(navigation_start),
104 pending_nav_entry_id_(pending_nav_entry_id), 107 pending_nav_entry_id_(pending_nav_entry_id),
105 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED), 108 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED),
106 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable), 109 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable),
107 should_replace_current_entry_(false), 110 should_replace_current_entry_(false),
108 redirect_chain_(redirect_chain), 111 redirect_chain_(redirect_chain),
109 is_download_(false), 112 is_download_(false),
110 is_stream_(false), 113 is_stream_(false),
111 started_from_context_menu_(started_from_context_menu), 114 started_from_context_menu_(started_from_context_menu),
112 reload_type_(ReloadType::NONE), 115 reload_type_(ReloadType::NONE),
113 navigation_type_(NAVIGATION_TYPE_UNKNOWN), 116 navigation_type_(NAVIGATION_TYPE_UNKNOWN),
114 should_bypass_main_world_csp_(should_bypass_main_world_csp), 117 should_bypass_main_world_csp_(should_bypass_main_world_csp),
118 is_form_submission_(is_form_submission),
115 weak_factory_(this) { 119 weak_factory_(this) {
116 DCHECK(!navigation_start.is_null()); 120 DCHECK(!navigation_start.is_null());
117 if (redirect_chain_.empty()) 121 if (redirect_chain_.empty())
118 redirect_chain_.push_back(url); 122 redirect_chain_.push_back(url);
119 123
120 starting_site_instance_ = 124 starting_site_instance_ =
121 frame_tree_node_->current_frame_host()->GetSiteInstance(); 125 frame_tree_node_->current_frame_host()->GetSiteInstance();
122 126
123 if (pending_nav_entry_id_) { 127 if (pending_nav_entry_id_) {
124 NavigationControllerImpl* nav_controller = 128 NavigationControllerImpl* nav_controller =
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 460 }
457 461
458 NavigationData* NavigationHandleImpl::GetNavigationData() { 462 NavigationData* NavigationHandleImpl::GetNavigationData() {
459 return navigation_data_.get(); 463 return navigation_data_.get();
460 } 464 }
461 465
462 bool NavigationHandleImpl::should_bypass_main_world_csp() const { 466 bool NavigationHandleImpl::should_bypass_main_world_csp() const {
463 return should_bypass_main_world_csp_; 467 return should_bypass_main_world_csp_;
464 } 468 }
465 469
470 bool NavigationHandleImpl::is_form_submission() const {
471 DCHECK(IsBrowserSideNavigationEnabled())
472 << "This method is implemented only with PlzNavigate";
473 return is_form_submission_;
474 }
475
466 const GlobalRequestID& NavigationHandleImpl::GetGlobalRequestID() { 476 const GlobalRequestID& NavigationHandleImpl::GetGlobalRequestID() {
467 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE || 477 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE ||
468 state_ == READY_TO_COMMIT); 478 state_ == READY_TO_COMMIT);
469 return request_id_; 479 return request_id_;
470 } 480 }
471 481
472 void NavigationHandleImpl::InitServiceWorkerHandle( 482 void NavigationHandleImpl::InitServiceWorkerHandle(
473 ServiceWorkerContextWrapper* service_worker_context) { 483 ServiceWorkerContextWrapper* service_worker_context) {
474 DCHECK(IsBrowserSideNavigationEnabled()); 484 DCHECK(IsBrowserSideNavigationEnabled());
475 service_worker_handle_.reset( 485 service_worker_handle_.reset(
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = 915 std::unique_ptr<NavigationThrottle> clear_site_data_throttle =
906 ClearSiteDataThrottle::CreateThrottleForNavigation(this); 916 ClearSiteDataThrottle::CreateThrottleForNavigation(this);
907 if (clear_site_data_throttle) 917 if (clear_site_data_throttle)
908 throttles_to_register.push_back(std::move(clear_site_data_throttle)); 918 throttles_to_register.push_back(std::move(clear_site_data_throttle));
909 919
910 std::unique_ptr<content::NavigationThrottle> ancestor_throttle = 920 std::unique_ptr<content::NavigationThrottle> ancestor_throttle =
911 content::AncestorThrottle::MaybeCreateThrottleFor(this); 921 content::AncestorThrottle::MaybeCreateThrottleFor(this);
912 if (ancestor_throttle) 922 if (ancestor_throttle)
913 throttles_.push_back(std::move(ancestor_throttle)); 923 throttles_.push_back(std::move(ancestor_throttle));
914 924
925 std::unique_ptr<content::NavigationThrottle> form_submission_throttle =
926 content::FormSubmissionThrottle::MaybeCreateThrottleFor(this);
927 if (form_submission_throttle)
928 throttles_.push_back(std::move(form_submission_throttle));
Mike West 2017/02/22 15:36:08 This needs to happen before the mixed content chec
arthursonzogni 2017/02/22 17:15:23 I would say the FIFO order, they are executed from
alexmos 2017/02/28 02:48:46 Mike would know these reasons much better, but one
arthursonzogni 2017/03/07 16:25:51 Done. Mike please confirm that it looks good to yo
929
915 throttles_.insert(throttles_.begin(), 930 throttles_.insert(throttles_.begin(),
916 std::make_move_iterator(throttles_to_register.begin()), 931 std::make_move_iterator(throttles_to_register.begin()),
917 std::make_move_iterator(throttles_to_register.end())); 932 std::make_move_iterator(throttles_to_register.end()));
918 } 933 }
919 934
920 bool NavigationHandleImpl::IsSelfReferentialURL() { 935 bool NavigationHandleImpl::IsSelfReferentialURL() {
921 // about: URLs should be exempted since they are reserved for other purposes 936 // about: URLs should be exempted since they are reserved for other purposes
922 // and cannot be the source of infinite recursion. See 937 // and cannot be the source of infinite recursion. See
923 // https://crbug.com/341858 . 938 // https://crbug.com/341858 .
924 if (url_.SchemeIs("about")) 939 if (url_.SchemeIs("about"))
(...skipping 11 matching lines...) Expand all
936 if (node->current_url().EqualsIgnoringRef(url_)) { 951 if (node->current_url().EqualsIgnoringRef(url_)) {
937 if (found_self_reference) 952 if (found_self_reference)
938 return true; 953 return true;
939 found_self_reference = true; 954 found_self_reference = true;
940 } 955 }
941 } 956 }
942 return false; 957 return false;
943 } 958 }
944 959
945 } // namespace content 960 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698