| 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 "base/logging.h" |
| 9 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
| 10 #include "content/browser/frame_host/navigator.h" | 11 #include "content/browser/frame_host/navigator.h" |
| 11 #include "content/browser/frame_host/navigator_delegate.h" | 12 #include "content/browser/frame_host/navigator_delegate.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 14 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
| 14 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
| 16 #include "content/common/resource_request_body.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/common/browser_side_navigation_policy.h" | 18 #include "content/public/common/browser_side_navigation_policy.h" |
| 17 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 18 #include "net/url_request/redirect_info.h" | 20 #include "net/url_request/redirect_info.h" |
| 21 #include "url/gurl.h" |
| 22 #include "url/url_constants.h" |
| 19 | 23 |
| 20 namespace content { | 24 namespace content { |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 void UpdateThrottleCheckResult( | 28 void UpdateThrottleCheckResult( |
| 25 NavigationThrottle::ThrottleCheckResult* to_update, | 29 NavigationThrottle::ThrottleCheckResult* to_update, |
| 26 NavigationThrottle::ThrottleCheckResult result) { | 30 NavigationThrottle::ThrottleCheckResult result) { |
| 27 *to_update = result; | 31 *to_update = result; |
| 28 } | 32 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 247 } |
| 244 | 248 |
| 245 NavigationThrottle::ThrottleCheckResult | 249 NavigationThrottle::ThrottleCheckResult |
| 246 NavigationHandleImpl::CallWillStartRequestForTesting( | 250 NavigationHandleImpl::CallWillStartRequestForTesting( |
| 247 bool is_post, | 251 bool is_post, |
| 248 const Referrer& sanitized_referrer, | 252 const Referrer& sanitized_referrer, |
| 249 bool has_user_gesture, | 253 bool has_user_gesture, |
| 250 ui::PageTransition transition, | 254 ui::PageTransition transition, |
| 251 bool is_external_protocol) { | 255 bool is_external_protocol) { |
| 252 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 256 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
| 253 WillStartRequest(is_post ? "POST" : "GET", sanitized_referrer, | 257 |
| 258 scoped_refptr<ResourceRequestBody> resource_request_body; |
| 259 std::string method = "GET"; |
| 260 if (is_post) { |
| 261 method = "POST"; |
| 262 |
| 263 std::string body = "test=body"; |
| 264 resource_request_body = new ResourceRequestBody(); |
| 265 resource_request_body->AppendBytes(body.data(), body.size()); |
| 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 Loading... |
| 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 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 if (method != "POST" && resource_request_body) { |
| 315 NOTREACHED(); |
| 316 resource_request_body = nullptr; |
| 317 } |
| 318 |
| 297 // Update the navigation parameters. | 319 // Update the navigation parameters. |
| 298 method_ = method; | 320 method_ = method; |
| 321 if (method_ == "POST") |
| 322 resource_request_body_ = resource_request_body; |
| 299 sanitized_referrer_ = sanitized_referrer; | 323 sanitized_referrer_ = sanitized_referrer; |
| 300 has_user_gesture_ = has_user_gesture; | 324 has_user_gesture_ = has_user_gesture; |
| 301 transition_ = transition; | 325 transition_ = transition; |
| 302 is_external_protocol_ = is_external_protocol; | 326 is_external_protocol_ = is_external_protocol; |
| 303 | 327 |
| 304 state_ = WILL_SEND_REQUEST; | 328 state_ = WILL_SEND_REQUEST; |
| 305 complete_callback_ = callback; | 329 complete_callback_ = callback; |
| 306 | 330 |
| 307 // Register the navigation throttles. The ScopedVector returned by | 331 // Register the navigation throttles. The ScopedVector returned by |
| 308 // GetNavigationThrottles is not assigned to throttles_ directly because it | 332 // GetNavigationThrottles is not assigned to throttles_ directly because it |
| (...skipping 23 matching lines...) Expand all Loading... |
| 332 scoped_refptr<net::HttpResponseHeaders> response_headers, | 356 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 333 const ThrottleChecksFinishedCallback& callback) { | 357 const ThrottleChecksFinishedCallback& callback) { |
| 334 // Update the navigation parameters. | 358 // Update the navigation parameters. |
| 335 url_ = new_url; | 359 url_ = new_url; |
| 336 method_ = new_method; | 360 method_ = new_method; |
| 337 sanitized_referrer_.url = new_referrer_url; | 361 sanitized_referrer_.url = new_referrer_url; |
| 338 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 362 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 339 is_external_protocol_ = new_is_external_protocol; | 363 is_external_protocol_ = new_is_external_protocol; |
| 340 response_headers_ = response_headers; | 364 response_headers_ = response_headers; |
| 341 was_redirected_ = true; | 365 was_redirected_ = true; |
| 366 if (new_method != "POST") |
| 367 resource_request_body_ = nullptr; |
| 342 | 368 |
| 343 state_ = WILL_REDIRECT_REQUEST; | 369 state_ = WILL_REDIRECT_REQUEST; |
| 344 complete_callback_ = callback; | 370 complete_callback_ = callback; |
| 345 | 371 |
| 346 // Notify each throttle of the request. | 372 // Notify each throttle of the request. |
| 347 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 373 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 348 | 374 |
| 349 // If the navigation is not deferred, run the callback. | 375 // If the navigation is not deferred, run the callback. |
| 350 if (result != NavigationThrottle::DEFER) | 376 if (result != NavigationThrottle::DEFER) |
| 351 RunCompleteCallback(result); | 377 RunCompleteCallback(result); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 complete_callback_.Reset(); | 531 complete_callback_.Reset(); |
| 506 | 532 |
| 507 if (!callback.is_null()) | 533 if (!callback.is_null()) |
| 508 callback.Run(result); | 534 callback.Run(result); |
| 509 | 535 |
| 510 // No code after running the callback, as it might have resulted in our | 536 // No code after running the callback, as it might have resulted in our |
| 511 // destruction. | 537 // destruction. |
| 512 } | 538 } |
| 513 | 539 |
| 514 } // namespace content | 540 } // namespace content |
| OLD | NEW |