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

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

Issue 1956383003: Forwarding POST body into renderer after a cross-site transfer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Relaxed and simplified DCHECKs to only verify |method != "POST"| case. Created 4 years, 6 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 <utility> 7 #include <utility>
8 8
9 #include "content/browser/frame_host/frame_tree_node.h" 9 #include "content/browser/frame_host/frame_tree_node.h"
10 #include "content/browser/frame_host/navigator.h" 10 #include "content/browser/frame_host/navigator.h"
11 #include "content/browser/frame_host/navigator_delegate.h" 11 #include "content/browser/frame_host/navigator_delegate.h"
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" 12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
13 #include "content/browser/service_worker/service_worker_navigation_handle.h" 13 #include "content/browser/service_worker/service_worker_navigation_handle.h"
14 #include "content/common/frame_messages.h" 14 #include "content/common/frame_messages.h"
15 #include "content/common/resource_request_body.h"
15 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/common/browser_side_navigation_policy.h" 17 #include "content/public/common/browser_side_navigation_policy.h"
17 #include "content/public/common/content_client.h" 18 #include "content/public/common/content_client.h"
18 #include "net/url_request/redirect_info.h" 19 #include "net/url_request/redirect_info.h"
19 20
20 namespace content { 21 namespace content {
21 22
22 namespace { 23 namespace {
23 24
24 void UpdateThrottleCheckResult( 25 void UpdateThrottleCheckResult(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (frame_tree_node_->IsMainFrame()) 138 if (frame_tree_node_->IsMainFrame())
138 return FrameTreeNode::kFrameTreeNodeInvalidId; 139 return FrameTreeNode::kFrameTreeNodeInvalidId;
139 140
140 return frame_tree_node_->parent()->frame_tree_node_id(); 141 return frame_tree_node_->parent()->frame_tree_node_id();
141 } 142 }
142 143
143 const base::TimeTicks& NavigationHandleImpl::NavigationStart() { 144 const base::TimeTicks& NavigationHandleImpl::NavigationStart() {
144 return navigation_start_; 145 return navigation_start_;
145 } 146 }
146 147
147 bool NavigationHandleImpl::IsPost() { 148 const std::string& NavigationHandleImpl::GetMethod() {
148 CHECK_NE(INITIAL, state_) 149 CHECK_NE(INITIAL, state_)
149 << "This accessor should not be called before the request is started."; 150 << "This accessor should not be called before the request is started.";
150 return method_ == "POST"; 151 return method_;
151 } 152 }
152 153
153 const Referrer& NavigationHandleImpl::GetReferrer() { 154 const Referrer& NavigationHandleImpl::GetReferrer() {
154 CHECK_NE(INITIAL, state_) 155 CHECK_NE(INITIAL, state_)
155 << "This accessor should not be called before the request is started."; 156 << "This accessor should not be called before the request is started.";
156 return sanitized_referrer_; 157 return sanitized_referrer_;
157 } 158 }
158 159
159 bool NavigationHandleImpl::HasUserGesture() { 160 bool NavigationHandleImpl::HasUserGesture() {
160 CHECK_NE(INITIAL, state_) 161 CHECK_NE(INITIAL, state_)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 244 }
244 245
245 NavigationThrottle::ThrottleCheckResult 246 NavigationThrottle::ThrottleCheckResult
246 NavigationHandleImpl::CallWillStartRequestForTesting( 247 NavigationHandleImpl::CallWillStartRequestForTesting(
247 bool is_post, 248 bool is_post,
248 const Referrer& sanitized_referrer, 249 const Referrer& sanitized_referrer,
249 bool has_user_gesture, 250 bool has_user_gesture,
250 ui::PageTransition transition, 251 ui::PageTransition transition,
251 bool is_external_protocol) { 252 bool is_external_protocol) {
252 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; 253 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER;
253 WillStartRequest(is_post ? "POST" : "GET", sanitized_referrer, 254
255 scoped_refptr<ResourceRequestBody> resource_request_body;
256 std::string method;
257 if (is_post) {
258 method = "POST";
259
260 std::string body = "test=body";
261 resource_request_body = new ResourceRequestBody();
262 resource_request_body->AppendBytes(body.data(), body.size());
263 } else {
264 method = "GET";
Charlie Reis 2016/05/31 21:08:36 Maybe we can just initialize |method| to "GET" and
Łukasz Anforowicz 2016/05/31 22:40:55 Done.
265 resource_request_body = nullptr;
266 }
267
268 WillStartRequest(method, resource_request_body, sanitized_referrer,
254 has_user_gesture, transition, is_external_protocol, 269 has_user_gesture, transition, is_external_protocol,
255 base::Bind(&UpdateThrottleCheckResult, &result)); 270 base::Bind(&UpdateThrottleCheckResult, &result));
256 271
257 // Reset the callback to ensure it will not be called later. 272 // Reset the callback to ensure it will not be called later.
258 complete_callback_.Reset(); 273 complete_callback_.Reset();
259 return result; 274 return result;
260 } 275 }
261 276
262 NavigationThrottle::ThrottleCheckResult 277 NavigationThrottle::ThrottleCheckResult
263 NavigationHandleImpl::CallWillRedirectRequestForTesting( 278 NavigationHandleImpl::CallWillRedirectRequestForTesting(
(...skipping 18 matching lines...) Expand all
282 297
283 void NavigationHandleImpl::InitServiceWorkerHandle( 298 void NavigationHandleImpl::InitServiceWorkerHandle(
284 ServiceWorkerContextWrapper* service_worker_context) { 299 ServiceWorkerContextWrapper* service_worker_context) {
285 DCHECK(IsBrowserSideNavigationEnabled()); 300 DCHECK(IsBrowserSideNavigationEnabled());
286 service_worker_handle_.reset( 301 service_worker_handle_.reset(
287 new ServiceWorkerNavigationHandle(service_worker_context)); 302 new ServiceWorkerNavigationHandle(service_worker_context));
288 } 303 }
289 304
290 void NavigationHandleImpl::WillStartRequest( 305 void NavigationHandleImpl::WillStartRequest(
291 const std::string& method, 306 const std::string& method,
307 const scoped_refptr<content::ResourceRequestBody>& resource_request_body,
292 const Referrer& sanitized_referrer, 308 const Referrer& sanitized_referrer,
293 bool has_user_gesture, 309 bool has_user_gesture,
294 ui::PageTransition transition, 310 ui::PageTransition transition,
295 bool is_external_protocol, 311 bool is_external_protocol,
296 const ThrottleChecksFinishedCallback& callback) { 312 const ThrottleChecksFinishedCallback& callback) {
313 // |method != "POST"| should imply absence of |resource_request_body|.
314 DCHECK(method == "POST" || !resource_request_body);
Charlie Reis 2016/05/31 21:08:36 Maybe we should upgrade this to a CHECK? Seems li
Łukasz Anforowicz 2016/05/31 22:40:55 Maybe we should try this in a follow-up, smaller (
Charlie Reis 2016/06/01 23:46:32 Sure. Any CHECKs we add can happen in a separate,
Łukasz Anforowicz 2016/06/02 22:07:04 Ack.
315
297 // Update the navigation parameters. 316 // Update the navigation parameters.
298 method_ = method; 317 method_ = method;
318 resource_request_body_ = resource_request_body;
299 sanitized_referrer_ = sanitized_referrer; 319 sanitized_referrer_ = sanitized_referrer;
300 has_user_gesture_ = has_user_gesture; 320 has_user_gesture_ = has_user_gesture;
301 transition_ = transition; 321 transition_ = transition;
302 is_external_protocol_ = is_external_protocol; 322 is_external_protocol_ = is_external_protocol;
303 323
304 state_ = WILL_SEND_REQUEST; 324 state_ = WILL_SEND_REQUEST;
305 complete_callback_ = callback; 325 complete_callback_ = callback;
306 326
307 // Register the navigation throttles. The ScopedVector returned by 327 // Register the navigation throttles. The ScopedVector returned by
308 // GetNavigationThrottles is not assigned to throttles_ directly because it 328 // GetNavigationThrottles is not assigned to throttles_ directly because it
(...skipping 23 matching lines...) Expand all
332 scoped_refptr<net::HttpResponseHeaders> response_headers, 352 scoped_refptr<net::HttpResponseHeaders> response_headers,
333 const ThrottleChecksFinishedCallback& callback) { 353 const ThrottleChecksFinishedCallback& callback) {
334 // Update the navigation parameters. 354 // Update the navigation parameters.
335 url_ = new_url; 355 url_ = new_url;
336 method_ = new_method; 356 method_ = new_method;
337 sanitized_referrer_.url = new_referrer_url; 357 sanitized_referrer_.url = new_referrer_url;
338 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); 358 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_);
339 is_external_protocol_ = new_is_external_protocol; 359 is_external_protocol_ = new_is_external_protocol;
340 response_headers_ = response_headers; 360 response_headers_ = response_headers;
341 was_redirected_ = true; 361 was_redirected_ = true;
362 if (new_method != "POST")
363 resource_request_body_ = nullptr;
342 364
343 state_ = WILL_REDIRECT_REQUEST; 365 state_ = WILL_REDIRECT_REQUEST;
344 complete_callback_ = callback; 366 complete_callback_ = callback;
345 367
346 // Notify each throttle of the request. 368 // Notify each throttle of the request.
347 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); 369 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest();
348 370
349 // If the navigation is not deferred, run the callback. 371 // If the navigation is not deferred, run the callback.
350 if (result != NavigationThrottle::DEFER) 372 if (result != NavigationThrottle::DEFER)
351 RunCompleteCallback(result); 373 RunCompleteCallback(result);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 complete_callback_.Reset(); 527 complete_callback_.Reset();
506 528
507 if (!callback.is_null()) 529 if (!callback.is_null())
508 callback.Run(result); 530 callback.Run(result);
509 531
510 // No code after running the callback, as it might have resulted in our 532 // No code after running the callback, as it might have resulted in our
511 // destruction. 533 // destruction.
512 } 534 }
513 535
514 } // namespace content 536 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698