Chromium Code Reviews| 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 WillStartRequest(is_post ? "POST" : "GET", nullptr, sanitized_referrer, |
| 254 has_user_gesture, transition, is_external_protocol, | 255 has_user_gesture, transition, is_external_protocol, |
| 255 base::Bind(&UpdateThrottleCheckResult, &result)); | 256 base::Bind(&UpdateThrottleCheckResult, &result)); |
| 256 | 257 |
| 257 // Reset the callback to ensure it will not be called later. | 258 // Reset the callback to ensure it will not be called later. |
| 258 complete_callback_.Reset(); | 259 complete_callback_.Reset(); |
| 259 return result; | 260 return result; |
| 260 } | 261 } |
| 261 | 262 |
| 262 NavigationThrottle::ThrottleCheckResult | 263 NavigationThrottle::ThrottleCheckResult |
| 263 NavigationHandleImpl::CallWillRedirectRequestForTesting( | 264 NavigationHandleImpl::CallWillRedirectRequestForTesting( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 282 | 283 |
| 283 void NavigationHandleImpl::InitServiceWorkerHandle( | 284 void NavigationHandleImpl::InitServiceWorkerHandle( |
| 284 ServiceWorkerContextWrapper* service_worker_context) { | 285 ServiceWorkerContextWrapper* service_worker_context) { |
| 285 DCHECK(IsBrowserSideNavigationEnabled()); | 286 DCHECK(IsBrowserSideNavigationEnabled()); |
| 286 service_worker_handle_.reset( | 287 service_worker_handle_.reset( |
| 287 new ServiceWorkerNavigationHandle(service_worker_context)); | 288 new ServiceWorkerNavigationHandle(service_worker_context)); |
| 288 } | 289 } |
| 289 | 290 |
| 290 void NavigationHandleImpl::WillStartRequest( | 291 void NavigationHandleImpl::WillStartRequest( |
| 291 const std::string& method, | 292 const std::string& method, |
| 293 const scoped_refptr<content::ResourceRequestBody>& resource_request_body, | |
| 292 const Referrer& sanitized_referrer, | 294 const Referrer& sanitized_referrer, |
| 293 bool has_user_gesture, | 295 bool has_user_gesture, |
| 294 ui::PageTransition transition, | 296 ui::PageTransition transition, |
| 295 bool is_external_protocol, | 297 bool is_external_protocol, |
| 296 const ThrottleChecksFinishedCallback& callback) { | 298 const ThrottleChecksFinishedCallback& callback) { |
| 297 // Update the navigation parameters. | 299 // Update the navigation parameters. |
|
clamy
2016/05/26 15:35:23
Add a DCHECK that resource_request_body is null ou
Łukasz Anforowicz
2016/05/26 17:14:02
Done.
| |
| 298 method_ = method; | 300 method_ = method; |
| 301 resource_request_body_ = resource_request_body; | |
| 299 sanitized_referrer_ = sanitized_referrer; | 302 sanitized_referrer_ = sanitized_referrer; |
| 300 has_user_gesture_ = has_user_gesture; | 303 has_user_gesture_ = has_user_gesture; |
| 301 transition_ = transition; | 304 transition_ = transition; |
| 302 is_external_protocol_ = is_external_protocol; | 305 is_external_protocol_ = is_external_protocol; |
| 303 | 306 |
| 304 state_ = WILL_SEND_REQUEST; | 307 state_ = WILL_SEND_REQUEST; |
| 305 complete_callback_ = callback; | 308 complete_callback_ = callback; |
| 306 | 309 |
| 307 // Register the navigation throttles. The ScopedVector returned by | 310 // Register the navigation throttles. The ScopedVector returned by |
| 308 // GetNavigationThrottles is not assigned to throttles_ directly because it | 311 // GetNavigationThrottles is not assigned to throttles_ directly because it |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 332 scoped_refptr<net::HttpResponseHeaders> response_headers, | 335 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 333 const ThrottleChecksFinishedCallback& callback) { | 336 const ThrottleChecksFinishedCallback& callback) { |
| 334 // Update the navigation parameters. | 337 // Update the navigation parameters. |
| 335 url_ = new_url; | 338 url_ = new_url; |
| 336 method_ = new_method; | 339 method_ = new_method; |
| 337 sanitized_referrer_.url = new_referrer_url; | 340 sanitized_referrer_.url = new_referrer_url; |
| 338 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 341 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 339 is_external_protocol_ = new_is_external_protocol; | 342 is_external_protocol_ = new_is_external_protocol; |
| 340 response_headers_ = response_headers; | 343 response_headers_ = response_headers; |
| 341 was_redirected_ = true; | 344 was_redirected_ = true; |
| 345 if (new_method != "POST") | |
| 346 resource_request_body_ = nullptr; | |
| 342 | 347 |
| 343 state_ = WILL_REDIRECT_REQUEST; | 348 state_ = WILL_REDIRECT_REQUEST; |
| 344 complete_callback_ = callback; | 349 complete_callback_ = callback; |
| 345 | 350 |
| 346 // Notify each throttle of the request. | 351 // Notify each throttle of the request. |
| 347 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 352 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 348 | 353 |
| 349 // If the navigation is not deferred, run the callback. | 354 // If the navigation is not deferred, run the callback. |
| 350 if (result != NavigationThrottle::DEFER) | 355 if (result != NavigationThrottle::DEFER) |
| 351 RunCompleteCallback(result); | 356 RunCompleteCallback(result); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 complete_callback_.Reset(); | 510 complete_callback_.Reset(); |
| 506 | 511 |
| 507 if (!callback.is_null()) | 512 if (!callback.is_null()) |
| 508 callback.Run(result); | 513 callback.Run(result); |
| 509 | 514 |
| 510 // No code after running the callback, as it might have resulted in our | 515 // No code after running the callback, as it might have resulted in our |
| 511 // destruction. | 516 // destruction. |
| 512 } | 517 } |
| 513 | 518 |
| 514 } // namespace content | 519 } // namespace content |
| OLD | NEW |