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

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

Issue 2496293003: PlzNavigate: add origin header (Closed)
Patch Set: Addressed comments Created 4 years 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/FlagExpectations/enable-browser-side-navigation » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/appcache/appcache_navigation_handle.h" 9 #include "content/browser/appcache/appcache_navigation_handle.h"
10 #include "content/browser/appcache/chrome_appcache_service.h" 10 #include "content/browser/appcache/chrome_appcache_service.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // TODO(clamy): This should be function in FrameTreeNode. 103 // TODO(clamy): This should be function in FrameTreeNode.
104 bool IsSecureFrame(FrameTreeNode* frame) { 104 bool IsSecureFrame(FrameTreeNode* frame) {
105 while (frame) { 105 while (frame) {
106 if (!IsPotentiallyTrustworthyOrigin(frame->current_origin())) 106 if (!IsPotentiallyTrustworthyOrigin(frame->current_origin()))
107 return false; 107 return false;
108 frame = frame->parent(); 108 frame = frame->parent();
109 } 109 }
110 return true; 110 return true;
111 } 111 }
112 112
113 // This should match blink::ResourceRequest::needsHTTPOrigin.
114 bool NeedsHTTPOrigin(net::HttpRequestHeaders* headers,
115 const std::string& method) {
116 // Don't add an Origin header if it is already present.
117 if (headers->HasHeader(net::HttpRequestHeaders::kOrigin))
118 return false;
119
120 // Don't send an Origin header for GET or HEAD to avoid privacy issues.
121 // For example, if an intranet page has a hyperlink to an external web
122 // site, we don't want to include the Origin of the request because it
123 // will leak the internal host name. Similar privacy concerns have lead
124 // to the widespread suppression of the Referer header at the network
125 // layer.
126 if (method == "GET" || method == "HEAD")
127 return false;
128
129 // For non-GET and non-HEAD methods, always send an Origin header so the
130 // server knows we support this feature.
131 return true;
132 }
133
113 // TODO(clamy): This should match what's happening in 134 // TODO(clamy): This should match what's happening in
114 // blink::FrameFetchContext::addAdditionalRequestHeaders. 135 // blink::FrameFetchContext::addAdditionalRequestHeaders.
115 void AddAdditionalRequestHeaders(net::HttpRequestHeaders* headers, 136 void AddAdditionalRequestHeaders(net::HttpRequestHeaders* headers,
116 const GURL& url, 137 const GURL& url,
117 FrameMsg_Navigate_Type::Value navigation_type, 138 FrameMsg_Navigate_Type::Value navigation_type,
118 BrowserContext* browser_context) { 139 BrowserContext* browser_context,
140 const std::string& method,
141 FrameTreeNode* frame_tree_node) {
119 if (!url.SchemeIsHTTPOrHTTPS()) 142 if (!url.SchemeIsHTTPOrHTTPS())
120 return; 143 return;
121 144
122 bool is_reload = 145 bool is_reload =
123 navigation_type == FrameMsg_Navigate_Type::RELOAD || 146 navigation_type == FrameMsg_Navigate_Type::RELOAD ||
124 navigation_type == FrameMsg_Navigate_Type::RELOAD_MAIN_RESOURCE || 147 navigation_type == FrameMsg_Navigate_Type::RELOAD_MAIN_RESOURCE ||
125 navigation_type == FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE || 148 navigation_type == FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE ||
126 navigation_type == FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; 149 navigation_type == FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
127 if (is_reload) 150 if (is_reload)
128 headers->RemoveHeader("Save-Data"); 151 headers->RemoveHeader("Save-Data");
129 152
130 if (GetContentClient()->browser()->IsDataSaverEnabled(browser_context)) 153 if (GetContentClient()->browser()->IsDataSaverEnabled(browser_context))
131 headers->SetHeaderIfMissing("Save-Data", "on"); 154 headers->SetHeaderIfMissing("Save-Data", "on");
132 155
133 headers->SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, 156 headers->SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
134 GetContentClient()->GetUserAgent()); 157 GetContentClient()->GetUserAgent());
135 158
136 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational 159 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational
137 // requests, as described in 160 // requests, as described in
138 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect 161 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect
139 headers->AddHeaderFromString("Upgrade-Insecure-Requests: 1"); 162 headers->AddHeaderFromString("Upgrade-Insecure-Requests: 1");
163
164 // Next, set the HTTP Origin if needed.
165 if (!NeedsHTTPOrigin(headers, method))
166 return;
167
168 // Create a unique origin.
169 url::Origin origin;
170 if (frame_tree_node->IsMainFrame()) {
171 // For main frame, the origin is the url currently loading.
172 origin = url::Origin(url);
173 } else if ((frame_tree_node->effective_sandbox_flags() &
174 blink::WebSandboxFlags::Origin) == blink::WebSandboxFlags::None) {
175 // The origin should be the origin of the root, except for sandboxed
176 // frames which have a unique origin.
177 origin = frame_tree_node->frame_tree()->root()->current_origin();
178 }
179
180 headers->SetHeader(net::HttpRequestHeaders::kOrigin, origin.Serialize());
140 } 181 }
141 182
142 } // namespace 183 } // namespace
143 184
144 // static 185 // static
145 std::unique_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( 186 std::unique_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
146 FrameTreeNode* frame_tree_node, 187 FrameTreeNode* frame_tree_node,
147 const GURL& dest_url, 188 const GURL& dest_url,
148 const Referrer& dest_referrer, 189 const Referrer& dest_referrer,
149 const FrameNavigationEntry& frame_entry, 190 const FrameNavigationEntry& frame_entry,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Update the load flags with cache information. 293 // Update the load flags with cache information.
253 UpdateLoadFlagsWithCacheFlags(&begin_params_.load_flags, 294 UpdateLoadFlagsWithCacheFlags(&begin_params_.load_flags,
254 common_params_.navigation_type, 295 common_params_.navigation_type,
255 common_params_.method == "POST"); 296 common_params_.method == "POST");
256 297
257 // Add necessary headers that may not be present in the BeginNavigationParams. 298 // Add necessary headers that may not be present in the BeginNavigationParams.
258 net::HttpRequestHeaders headers; 299 net::HttpRequestHeaders headers;
259 headers.AddHeadersFromString(begin_params_.headers); 300 headers.AddHeadersFromString(begin_params_.headers);
260 AddAdditionalRequestHeaders( 301 AddAdditionalRequestHeaders(
261 &headers, common_params_.url, common_params_.navigation_type, 302 &headers, common_params_.url, common_params_.navigation_type,
262 frame_tree_node_->navigator()->GetController()->GetBrowserContext()); 303 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
304 common_params.method, frame_tree_node);
263 begin_params_.headers = headers.ToString(); 305 begin_params_.headers = headers.ToString();
264 } 306 }
265 307
266 NavigationRequest::~NavigationRequest() { 308 NavigationRequest::~NavigationRequest() {
267 } 309 }
268 310
269 void NavigationRequest::BeginNavigation() { 311 void NavigationRequest::BeginNavigation() {
270 DCHECK(!loader_); 312 DCHECK(!loader_);
271 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 313 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
272 state_ = STARTED; 314 state_ = STARTED;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 TransferNavigationHandleOwnership(render_frame_host); 655 TransferNavigationHandleOwnership(render_frame_host);
614 656
615 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 657 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
616 common_params_, request_params_, 658 common_params_, request_params_,
617 is_view_source_); 659 is_view_source_);
618 660
619 frame_tree_node_->ResetNavigationRequest(true); 661 frame_tree_node_->ResetNavigationRequest(true);
620 } 662 }
621 663
622 } // namespace content 664 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/FlagExpectations/enable-browser-side-navigation » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698