OLD | NEW |
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 Loading... |
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 Loading... |
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 = "GET"; |
| 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 } |
| 264 |
| 265 WillStartRequest(method, resource_request_body, sanitized_referrer, |
254 has_user_gesture, transition, is_external_protocol, | 266 has_user_gesture, transition, is_external_protocol, |
255 base::Bind(&UpdateThrottleCheckResult, &result)); | 267 base::Bind(&UpdateThrottleCheckResult, &result)); |
256 | 268 |
257 // Reset the callback to ensure it will not be called later. | 269 // Reset the callback to ensure it will not be called later. |
258 complete_callback_.Reset(); | 270 complete_callback_.Reset(); |
259 return result; | 271 return result; |
260 } | 272 } |
261 | 273 |
262 NavigationThrottle::ThrottleCheckResult | 274 NavigationThrottle::ThrottleCheckResult |
263 NavigationHandleImpl::CallWillRedirectRequestForTesting( | 275 NavigationHandleImpl::CallWillRedirectRequestForTesting( |
(...skipping 18 matching lines...) Expand all Loading... |
282 | 294 |
283 void NavigationHandleImpl::InitServiceWorkerHandle( | 295 void NavigationHandleImpl::InitServiceWorkerHandle( |
284 ServiceWorkerContextWrapper* service_worker_context) { | 296 ServiceWorkerContextWrapper* service_worker_context) { |
285 DCHECK(IsBrowserSideNavigationEnabled()); | 297 DCHECK(IsBrowserSideNavigationEnabled()); |
286 service_worker_handle_.reset( | 298 service_worker_handle_.reset( |
287 new ServiceWorkerNavigationHandle(service_worker_context)); | 299 new ServiceWorkerNavigationHandle(service_worker_context)); |
288 } | 300 } |
289 | 301 |
290 void NavigationHandleImpl::WillStartRequest( | 302 void NavigationHandleImpl::WillStartRequest( |
291 const std::string& method, | 303 const std::string& method, |
| 304 const scoped_refptr<content::ResourceRequestBody>& resource_request_body, |
292 const Referrer& sanitized_referrer, | 305 const Referrer& sanitized_referrer, |
293 bool has_user_gesture, | 306 bool has_user_gesture, |
294 ui::PageTransition transition, | 307 ui::PageTransition transition, |
295 bool is_external_protocol, | 308 bool is_external_protocol, |
296 const ThrottleChecksFinishedCallback& callback) { | 309 const ThrottleChecksFinishedCallback& callback) { |
| 310 // |method != "POST"| should imply absence of |resource_request_body|. |
| 311 DCHECK(method == "POST" || !resource_request_body); |
| 312 |
297 // Update the navigation parameters. | 313 // Update the navigation parameters. |
298 method_ = method; | 314 method_ = method; |
| 315 resource_request_body_ = resource_request_body; |
299 sanitized_referrer_ = sanitized_referrer; | 316 sanitized_referrer_ = sanitized_referrer; |
300 has_user_gesture_ = has_user_gesture; | 317 has_user_gesture_ = has_user_gesture; |
301 transition_ = transition; | 318 transition_ = transition; |
302 is_external_protocol_ = is_external_protocol; | 319 is_external_protocol_ = is_external_protocol; |
303 | 320 |
304 state_ = WILL_SEND_REQUEST; | 321 state_ = WILL_SEND_REQUEST; |
305 complete_callback_ = callback; | 322 complete_callback_ = callback; |
306 | 323 |
307 // Register the navigation throttles. The ScopedVector returned by | 324 // Register the navigation throttles. The ScopedVector returned by |
308 // GetNavigationThrottles is not assigned to throttles_ directly because it | 325 // GetNavigationThrottles is not assigned to throttles_ directly because it |
(...skipping 23 matching lines...) Expand all Loading... |
332 scoped_refptr<net::HttpResponseHeaders> response_headers, | 349 scoped_refptr<net::HttpResponseHeaders> response_headers, |
333 const ThrottleChecksFinishedCallback& callback) { | 350 const ThrottleChecksFinishedCallback& callback) { |
334 // Update the navigation parameters. | 351 // Update the navigation parameters. |
335 url_ = new_url; | 352 url_ = new_url; |
336 method_ = new_method; | 353 method_ = new_method; |
337 sanitized_referrer_.url = new_referrer_url; | 354 sanitized_referrer_.url = new_referrer_url; |
338 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 355 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
339 is_external_protocol_ = new_is_external_protocol; | 356 is_external_protocol_ = new_is_external_protocol; |
340 response_headers_ = response_headers; | 357 response_headers_ = response_headers; |
341 was_redirected_ = true; | 358 was_redirected_ = true; |
| 359 if (new_method != "POST") |
| 360 resource_request_body_ = nullptr; |
342 | 361 |
343 state_ = WILL_REDIRECT_REQUEST; | 362 state_ = WILL_REDIRECT_REQUEST; |
344 complete_callback_ = callback; | 363 complete_callback_ = callback; |
345 | 364 |
346 // Notify each throttle of the request. | 365 // Notify each throttle of the request. |
347 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 366 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
348 | 367 |
349 // If the navigation is not deferred, run the callback. | 368 // If the navigation is not deferred, run the callback. |
350 if (result != NavigationThrottle::DEFER) | 369 if (result != NavigationThrottle::DEFER) |
351 RunCompleteCallback(result); | 370 RunCompleteCallback(result); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 complete_callback_.Reset(); | 524 complete_callback_.Reset(); |
506 | 525 |
507 if (!callback.is_null()) | 526 if (!callback.is_null()) |
508 callback.Run(result); | 527 callback.Run(result); |
509 | 528 |
510 // No code after running the callback, as it might have resulted in our | 529 // No code after running the callback, as it might have resulted in our |
511 // destruction. | 530 // destruction. |
512 } | 531 } |
513 | 532 |
514 } // namespace content | 533 } // namespace content |
OLD | NEW |