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(); |
| 162 | |
| 163 // If the navigation is about to proceed after processing the response, then | |
| 164 // it's ready to commit. | |
| 165 if (result == NavigationThrottle::PROCEED) | |
| 166 ReadyToCommitNavigation(render_frame_host_, response_headers_); | |
|
Mike West
2016/01/29 07:38:38
This is a substantive change from the last patchse
| |
| 158 } | 167 } |
| 159 | 168 |
| 160 if (result != NavigationThrottle::DEFER) | 169 if (result != NavigationThrottle::DEFER) |
| 161 RunCompleteCallback(result); | 170 RunCompleteCallback(result); |
| 162 } | 171 } |
| 163 | 172 |
| 164 void NavigationHandleImpl::CancelDeferredNavigation( | 173 void NavigationHandleImpl::CancelDeferredNavigation( |
| 165 NavigationThrottle::ThrottleCheckResult result) { | 174 NavigationThrottle::ThrottleCheckResult result) { |
| 166 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 175 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
| 167 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 176 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 complete_callback_ = callback; | 281 complete_callback_ = callback; |
| 273 | 282 |
| 274 // Notify each throttle of the request. | 283 // Notify each throttle of the request. |
| 275 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 284 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 276 | 285 |
| 277 // If the navigation is not deferred, run the callback. | 286 // If the navigation is not deferred, run the callback. |
| 278 if (result != NavigationThrottle::DEFER) | 287 if (result != NavigationThrottle::DEFER) |
| 279 RunCompleteCallback(result); | 288 RunCompleteCallback(result); |
| 280 } | 289 } |
| 281 | 290 |
| 291 void NavigationHandleImpl::WillProcessResponse( | |
| 292 RenderFrameHostImpl* render_frame_host, | |
| 293 scoped_refptr<net::HttpResponseHeaders> response_headers, | |
| 294 const ThrottleChecksFinishedCallback& callback) { | |
| 295 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | |
| 296 render_frame_host_ = render_frame_host; | |
| 297 response_headers_ = response_headers; | |
| 298 state_ = WILL_PROCESS_RESPONSE; | |
| 299 complete_callback_ = callback; | |
| 300 | |
| 301 // Notify each throttle of the response. | |
| 302 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | |
| 303 | |
| 304 // If the navigation is about to proceed, then it's ready to commit. | |
| 305 if (result == NavigationThrottle::PROCEED) | |
| 306 ReadyToCommitNavigation(render_frame_host, response_headers); | |
| 307 | |
| 308 // If the navigation is not deferred, run the callback. | |
| 309 if (result != NavigationThrottle::DEFER) | |
| 310 RunCompleteCallback(result); | |
| 311 } | |
| 312 | |
| 282 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 313 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
| 283 url_ = new_url; | 314 url_ = new_url; |
| 284 GetDelegate()->DidRedirectNavigation(this); | 315 GetDelegate()->DidRedirectNavigation(this); |
| 285 } | 316 } |
| 286 | 317 |
| 287 void NavigationHandleImpl::ReadyToCommitNavigation( | 318 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 288 RenderFrameHostImpl* render_frame_host, | 319 RenderFrameHostImpl* render_frame_host, |
| 289 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 320 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
| 290 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 321 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| 291 render_frame_host_ = render_frame_host; | 322 render_frame_host_ = render_frame_host; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 | 393 |
| 363 default: | 394 default: |
| 364 NOTREACHED(); | 395 NOTREACHED(); |
| 365 } | 396 } |
| 366 } | 397 } |
| 367 next_index_ = 0; | 398 next_index_ = 0; |
| 368 state_ = WILL_REDIRECT_REQUEST; | 399 state_ = WILL_REDIRECT_REQUEST; |
| 369 return NavigationThrottle::PROCEED; | 400 return NavigationThrottle::PROCEED; |
| 370 } | 401 } |
| 371 | 402 |
| 403 NavigationThrottle::ThrottleCheckResult | |
| 404 NavigationHandleImpl::CheckWillProcessResponse() { | |
| 405 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | |
| 406 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | |
| 407 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | |
| 408 for (size_t i = next_index_; i < throttles_.size(); ++i) { | |
| 409 NavigationThrottle::ThrottleCheckResult result = | |
| 410 throttles_[i]->WillProcessResponse(); | |
| 411 switch (result) { | |
| 412 case NavigationThrottle::PROCEED: | |
| 413 continue; | |
| 414 | |
| 415 case NavigationThrottle::CANCEL: | |
| 416 case NavigationThrottle::CANCEL_AND_IGNORE: | |
| 417 state_ = CANCELING; | |
| 418 return result; | |
| 419 | |
| 420 case NavigationThrottle::DEFER: | |
| 421 state_ = DEFERRING_RESPONSE; | |
| 422 next_index_ = i + 1; | |
| 423 return result; | |
| 424 } | |
| 425 } | |
| 426 next_index_ = 0; | |
| 427 state_ = WILL_PROCESS_RESPONSE; | |
| 428 return NavigationThrottle::PROCEED; | |
| 429 } | |
| 430 | |
| 372 void NavigationHandleImpl::RunCompleteCallback( | 431 void NavigationHandleImpl::RunCompleteCallback( |
| 373 NavigationThrottle::ThrottleCheckResult result) { | 432 NavigationThrottle::ThrottleCheckResult result) { |
| 374 DCHECK(result != NavigationThrottle::DEFER); | 433 DCHECK(result != NavigationThrottle::DEFER); |
| 375 if (!complete_callback_.is_null()) | |
| 376 complete_callback_.Run(result); | |
| 377 | 434 |
| 435 ThrottleChecksFinishedCallback callback = complete_callback_; | |
| 378 complete_callback_.Reset(); | 436 complete_callback_.Reset(); |
| 437 | |
| 438 if (!callback.is_null()) | |
| 439 callback.Run(result); | |
| 440 | |
| 441 // No code after running the callback, as it might have resulted in our | |
| 442 // destruction. | |
| 379 } | 443 } |
| 380 | 444 |
| 381 } // namespace content | 445 } // namespace content |
| OLD | NEW |