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" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 140 |
| 141 bool NavigationHandleImpl::HasCommitted() { | 141 bool NavigationHandleImpl::HasCommitted() { |
| 142 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; | 142 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool NavigationHandleImpl::IsErrorPage() { | 145 bool NavigationHandleImpl::IsErrorPage() { |
| 146 return state_ == DID_COMMIT_ERROR_PAGE; | 146 return state_ == DID_COMMIT_ERROR_PAGE; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void NavigationHandleImpl::Resume() { | 149 void NavigationHandleImpl::Resume() { |
| 150 if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT) | 150 if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT && |
| 151 state_ != DEFERRING_RESPONSE) { | |
| 151 return; | 152 return; |
| 153 } | |
| 152 | 154 |
| 153 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 155 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
| 154 if (state_ == DEFERRING_START) { | 156 if (state_ == DEFERRING_START) { |
| 155 result = CheckWillStartRequest(); | 157 result = CheckWillStartRequest(); |
| 158 } else if (state_ == DEFERRING_REDIRECT) { | |
| 159 result = CheckWillRedirectRequest(); | |
| 156 } else { | 160 } else { |
| 157 result = CheckWillRedirectRequest(); | 161 result = CheckWillProcessResponse(); |
| 158 } | 162 } |
| 159 | 163 |
| 160 if (result != NavigationThrottle::DEFER) | 164 if (result != NavigationThrottle::DEFER) |
| 161 RunCompleteCallback(result); | 165 RunCompleteCallback(result); |
| 162 } | 166 } |
| 163 | 167 |
| 164 void NavigationHandleImpl::CancelDeferredNavigation( | 168 void NavigationHandleImpl::CancelDeferredNavigation( |
| 165 NavigationThrottle::ThrottleCheckResult result) { | 169 NavigationThrottle::ThrottleCheckResult result) { |
| 166 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 170 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
| 167 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 171 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 complete_callback_ = callback; | 276 complete_callback_ = callback; |
| 273 | 277 |
| 274 // Notify each throttle of the request. | 278 // Notify each throttle of the request. |
| 275 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 279 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 276 | 280 |
| 277 // If the navigation is not deferred, run the callback. | 281 // If the navigation is not deferred, run the callback. |
| 278 if (result != NavigationThrottle::DEFER) | 282 if (result != NavigationThrottle::DEFER) |
| 279 RunCompleteCallback(result); | 283 RunCompleteCallback(result); |
| 280 } | 284 } |
| 281 | 285 |
| 286 void NavigationHandleImpl::WillProcessResponse( | |
| 287 scoped_refptr<net::HttpResponseHeaders> response_headers, | |
| 288 const ThrottleChecksFinishedCallback& callback) { | |
| 289 response_headers_ = response_headers; | |
| 290 state_ = WILL_PROCESS_RESPONSE; | |
| 291 complete_callback_ = callback; | |
| 292 | |
| 293 // Notify each throttle of the response. | |
| 294 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | |
| 295 | |
| 296 // If the navigation is not deferred, run the callback. | |
| 297 if (result != NavigationThrottle::DEFER) | |
| 298 RunCompleteCallback(result); | |
| 299 } | |
| 300 | |
| 282 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 301 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
| 283 url_ = new_url; | 302 url_ = new_url; |
| 284 GetDelegate()->DidRedirectNavigation(this); | 303 GetDelegate()->DidRedirectNavigation(this); |
| 285 } | 304 } |
| 286 | 305 |
| 287 void NavigationHandleImpl::ReadyToCommitNavigation( | 306 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 288 RenderFrameHostImpl* render_frame_host, | 307 RenderFrameHostImpl* render_frame_host, |
| 289 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 308 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
| 290 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 309 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| 291 render_frame_host_ = render_frame_host; | 310 render_frame_host_ = render_frame_host; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 | 381 |
| 363 default: | 382 default: |
| 364 NOTREACHED(); | 383 NOTREACHED(); |
| 365 } | 384 } |
| 366 } | 385 } |
| 367 next_index_ = 0; | 386 next_index_ = 0; |
| 368 state_ = WILL_REDIRECT_REQUEST; | 387 state_ = WILL_REDIRECT_REQUEST; |
| 369 return NavigationThrottle::PROCEED; | 388 return NavigationThrottle::PROCEED; |
| 370 } | 389 } |
| 371 | 390 |
| 391 NavigationThrottle::ThrottleCheckResult | |
| 392 NavigationHandleImpl::CheckWillProcessResponse() { | |
| 393 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | |
| 394 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | |
| 395 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | |
| 396 for (size_t i = next_index_; i < throttles_.size(); ++i) { | |
| 397 NavigationThrottle::ThrottleCheckResult result = | |
| 398 throttles_[i]->WillProcessResponse(); | |
| 399 switch (result) { | |
| 400 case NavigationThrottle::PROCEED: | |
| 401 continue; | |
| 402 | |
| 403 case NavigationThrottle::CANCEL: | |
| 404 case NavigationThrottle::CANCEL_AND_IGNORE: | |
| 405 state_ = CANCELING; | |
| 406 return result; | |
| 407 | |
| 408 case NavigationThrottle::DEFER: | |
| 409 state_ = DEFERRING_RESPONSE; | |
| 410 next_index_ = i + 1; | |
| 411 return result; | |
| 412 } | |
| 413 } | |
| 414 next_index_ = 0; | |
| 415 state_ = WILL_PROCESS_RESPONSE; | |
| 416 return NavigationThrottle::PROCEED; | |
| 417 } | |
| 418 | |
| 372 void NavigationHandleImpl::RunCompleteCallback( | 419 void NavigationHandleImpl::RunCompleteCallback( |
| 373 NavigationThrottle::ThrottleCheckResult result) { | 420 NavigationThrottle::ThrottleCheckResult result) { |
| 374 DCHECK(result != NavigationThrottle::DEFER); | 421 DCHECK(result != NavigationThrottle::DEFER); |
| 375 if (!complete_callback_.is_null()) | |
| 376 complete_callback_.Run(result); | |
| 377 | 422 |
| 423 ThrottleChecksFinishedCallback callback = complete_callback_; | |
| 378 complete_callback_.Reset(); | 424 complete_callback_.Reset(); |
| 425 | |
| 426 if (!callback.is_null()) | |
| 427 callback.Run(result); | |
| 428 | |
| 429 // No code after running the calback, as it might result in our destruction. | |
|
clamy
2016/01/26 14:08:55
nit: callback
Good find! :)
| |
| 379 } | 430 } |
| 380 | 431 |
| 381 } // namespace content | 432 } // namespace content |
| OLD | NEW |