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 "content/browser/frame_host/frame_tree_node.h" | 7 #include "content/browser/frame_host/frame_tree_node.h" |
| 8 #include "content/browser/frame_host/navigator.h" | 8 #include "content/browser/frame_host/navigator.h" |
| 9 #include "content/browser/frame_host/navigator_delegate.h" | 9 #include "content/browser/frame_host/navigator_delegate.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 has_user_gesture_ = has_user_gesture; | 225 has_user_gesture_ = has_user_gesture; |
| 226 transition_ = transition; | 226 transition_ = transition; |
| 227 is_external_protocol_ = is_external_protocol; | 227 is_external_protocol_ = is_external_protocol; |
| 228 | 228 |
| 229 state_ = WILL_SEND_REQUEST; | 229 state_ = WILL_SEND_REQUEST; |
| 230 complete_callback_ = callback; | 230 complete_callback_ = callback; |
| 231 | 231 |
| 232 // Register the navigation throttles. The ScopedVector returned by | 232 // Register the navigation throttles. The ScopedVector returned by |
| 233 // GetNavigationThrottles is not assigned to throttles_ directly because it | 233 // GetNavigationThrottles is not assigned to throttles_ directly because it |
| 234 // would overwrite any throttle previously added with | 234 // would overwrite any throttle previously added with |
| 235 // RegisterThrottleForTesting. | 235 // RegisterThrottleForTesting. |
|
clamy
2015/12/21 10:13:29
If you move the XFOThrottle to content/, you can j
| |
| 236 ScopedVector<NavigationThrottle> throttles_to_register = | 236 ScopedVector<NavigationThrottle> throttles_to_register = |
| 237 GetContentClient()->browser()->CreateThrottlesForNavigation(this); | 237 GetContentClient()->browser()->CreateThrottlesForNavigation(this); |
| 238 if (throttles_to_register.size() > 0) { | 238 if (throttles_to_register.size() > 0) { |
| 239 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | 239 throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| 240 throttles_to_register.end()); | 240 throttles_to_register.end()); |
| 241 throttles_to_register.weak_clear(); | 241 throttles_to_register.weak_clear(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 // Notify each throttle of the request. | 244 // Notify each throttle of the request. |
| 245 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 245 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 268 complete_callback_ = callback; | 268 complete_callback_ = callback; |
| 269 | 269 |
| 270 // Notify each throttle of the request. | 270 // Notify each throttle of the request. |
| 271 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 271 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 272 | 272 |
| 273 // If the navigation is not deferred, run the callback. | 273 // If the navigation is not deferred, run the callback. |
| 274 if (result != NavigationThrottle::DEFER) | 274 if (result != NavigationThrottle::DEFER) |
| 275 RunCompleteCallback(result); | 275 RunCompleteCallback(result); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void NavigationHandleImpl::WillProcessResponse( | |
| 279 RenderFrameHostImpl* render_frame_host, | |
| 280 scoped_refptr<net::HttpResponseHeaders> response_headers, | |
| 281 const ThrottleChecksFinishedCallback& callback) { | |
| 282 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | |
| 283 render_frame_host_ = render_frame_host; | |
| 284 response_headers_ = response_headers; | |
| 285 state_ = READY_TO_COMMIT; | |
| 286 | |
| 287 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | |
| 288 | |
| 289 if (result != NavigationThrottle::PROCEED) { | |
| 290 DCHECK(result == NavigationThrottle::CANCEL || | |
| 291 result == NavigationThrottle::CANCEL_AND_IGNORE); | |
| 292 complete_callback_ = callback; | |
| 293 RunCompleteCallback(result); | |
| 294 } else { | |
| 295 ReadyToCommitNavigation(render_frame_host, response_headers); | |
| 296 } | |
| 297 } | |
| 298 | |
| 278 void NavigationHandleImpl::ReadyToCommitNavigation( | 299 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 279 RenderFrameHostImpl* render_frame_host, | 300 RenderFrameHostImpl* render_frame_host, |
| 280 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 301 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
| 281 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 302 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| 282 render_frame_host_ = render_frame_host; | 303 render_frame_host_ = render_frame_host; |
| 283 response_headers_ = response_headers; | 304 response_headers_ = response_headers; |
| 284 state_ = READY_TO_COMMIT; | 305 state_ = READY_TO_COMMIT; |
| 285 | 306 |
| 286 // Only notify the WebContentsObservers when PlzNavigate is enabled, as | 307 // Only notify the WebContentsObservers when PlzNavigate is enabled, as |
| 287 // |render_frame_host_| may be wrong in the case of transfer navigations. | 308 // |render_frame_host_| may be wrong in the case of transfer navigations. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 } | 378 } |
| 358 next_index_ = 0; | 379 next_index_ = 0; |
| 359 state_ = WILL_REDIRECT_REQUEST; | 380 state_ = WILL_REDIRECT_REQUEST; |
| 360 | 381 |
| 361 // Notify the delegate that a redirect was encountered and will be followed. | 382 // Notify the delegate that a redirect was encountered and will be followed. |
| 362 GetDelegate()->DidRedirectNavigation(this); | 383 GetDelegate()->DidRedirectNavigation(this); |
| 363 | 384 |
| 364 return NavigationThrottle::PROCEED; | 385 return NavigationThrottle::PROCEED; |
| 365 } | 386 } |
| 366 | 387 |
| 388 NavigationThrottle::ThrottleCheckResult | |
| 389 NavigationHandleImpl::CheckWillProcessResponse() { | |
| 390 DCHECK(state_ == READY_TO_COMMIT); | |
| 391 for (size_t i = next_index_; i < throttles_.size(); ++i) { | |
| 392 NavigationThrottle::ThrottleCheckResult result = | |
| 393 throttles_[i]->WillProcessResponse(); | |
| 394 switch (result) { | |
| 395 case NavigationThrottle::PROCEED: | |
| 396 continue; | |
| 397 | |
| 398 case NavigationThrottle::CANCEL: | |
| 399 case NavigationThrottle::CANCEL_AND_IGNORE: | |
| 400 state_ = CANCELING; | |
| 401 return result; | |
| 402 | |
| 403 case NavigationThrottle::DEFER: | |
| 404 default: | |
| 405 NOTREACHED(); | |
| 406 } | |
| 407 } | |
| 408 next_index_ = 0; | |
| 409 state_ = READY_TO_COMMIT; | |
| 410 return NavigationThrottle::PROCEED; | |
| 411 } | |
| 412 | |
| 367 void NavigationHandleImpl::RunCompleteCallback( | 413 void NavigationHandleImpl::RunCompleteCallback( |
| 368 NavigationThrottle::ThrottleCheckResult result) { | 414 NavigationThrottle::ThrottleCheckResult result) { |
| 369 DCHECK(result != NavigationThrottle::DEFER); | 415 DCHECK(result != NavigationThrottle::DEFER); |
| 370 if (!complete_callback_.is_null()) | 416 if (!complete_callback_.is_null()) |
| 371 complete_callback_.Run(result); | 417 complete_callback_.Run(result); |
| 372 | 418 |
| 373 complete_callback_.Reset(); | 419 complete_callback_.Reset(); |
| 374 } | 420 } |
| 375 | 421 |
| 376 } // namespace content | 422 } // namespace content |
| OLD | NEW |