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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 bool NavigationHandleImpl::HasCommitted() { | 142 bool NavigationHandleImpl::HasCommitted() { |
143 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; | 143 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; |
144 } | 144 } |
145 | 145 |
146 bool NavigationHandleImpl::IsErrorPage() { | 146 bool NavigationHandleImpl::IsErrorPage() { |
147 return state_ == DID_COMMIT_ERROR_PAGE; | 147 return state_ == DID_COMMIT_ERROR_PAGE; |
148 } | 148 } |
149 | 149 |
150 void NavigationHandleImpl::Resume() { | 150 void NavigationHandleImpl::Resume() { |
151 if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT) | 151 if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT && |
| 152 state_ != DEFERRING_RESPONSE) { |
152 return; | 153 return; |
| 154 } |
153 | 155 |
154 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 156 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
155 if (state_ == DEFERRING_START) { | 157 if (state_ == DEFERRING_START) { |
156 result = CheckWillStartRequest(); | 158 result = CheckWillStartRequest(); |
| 159 } else if (state_ == DEFERRING_REDIRECT) { |
| 160 result = CheckWillRedirectRequest(); |
157 } else { | 161 } else { |
158 result = CheckWillRedirectRequest(); | 162 result = CheckWillProcessResponse(); |
| 163 |
| 164 // If the navigation is about to proceed after processing the response, then |
| 165 // it's ready to commit. |
| 166 if (result == NavigationThrottle::PROCEED) |
| 167 ReadyToCommitNavigation(render_frame_host_, response_headers_); |
159 } | 168 } |
160 | 169 |
161 if (result != NavigationThrottle::DEFER) | 170 if (result != NavigationThrottle::DEFER) |
162 RunCompleteCallback(result); | 171 RunCompleteCallback(result); |
163 } | 172 } |
164 | 173 |
165 void NavigationHandleImpl::CancelDeferredNavigation( | 174 void NavigationHandleImpl::CancelDeferredNavigation( |
166 NavigationThrottle::ThrottleCheckResult result) { | 175 NavigationThrottle::ThrottleCheckResult result) { |
167 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 176 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
168 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 177 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 complete_callback_ = callback; | 282 complete_callback_ = callback; |
274 | 283 |
275 // Notify each throttle of the request. | 284 // Notify each throttle of the request. |
276 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 285 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
277 | 286 |
278 // If the navigation is not deferred, run the callback. | 287 // If the navigation is not deferred, run the callback. |
279 if (result != NavigationThrottle::DEFER) | 288 if (result != NavigationThrottle::DEFER) |
280 RunCompleteCallback(result); | 289 RunCompleteCallback(result); |
281 } | 290 } |
282 | 291 |
| 292 void NavigationHandleImpl::WillProcessResponse( |
| 293 RenderFrameHostImpl* render_frame_host, |
| 294 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 295 const ThrottleChecksFinishedCallback& callback) { |
| 296 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| 297 render_frame_host_ = render_frame_host; |
| 298 response_headers_ = response_headers; |
| 299 state_ = WILL_PROCESS_RESPONSE; |
| 300 complete_callback_ = callback; |
| 301 |
| 302 // Notify each throttle of the response. |
| 303 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); |
| 304 |
| 305 // If the navigation is about to proceed, then it's ready to commit. |
| 306 if (result == NavigationThrottle::PROCEED) |
| 307 ReadyToCommitNavigation(render_frame_host, response_headers); |
| 308 |
| 309 // If the navigation is not deferred, run the callback. |
| 310 if (result != NavigationThrottle::DEFER) |
| 311 RunCompleteCallback(result); |
| 312 } |
| 313 |
283 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 314 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
284 url_ = new_url; | 315 url_ = new_url; |
285 GetDelegate()->DidRedirectNavigation(this); | 316 GetDelegate()->DidRedirectNavigation(this); |
286 } | 317 } |
287 | 318 |
288 void NavigationHandleImpl::ReadyToCommitNavigation( | 319 void NavigationHandleImpl::ReadyToCommitNavigation( |
289 RenderFrameHostImpl* render_frame_host, | 320 RenderFrameHostImpl* render_frame_host, |
290 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 321 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
291 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 322 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
292 render_frame_host_ = render_frame_host; | 323 render_frame_host_ = render_frame_host; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 402 |
372 default: | 403 default: |
373 NOTREACHED(); | 404 NOTREACHED(); |
374 } | 405 } |
375 } | 406 } |
376 next_index_ = 0; | 407 next_index_ = 0; |
377 state_ = WILL_REDIRECT_REQUEST; | 408 state_ = WILL_REDIRECT_REQUEST; |
378 return NavigationThrottle::PROCEED; | 409 return NavigationThrottle::PROCEED; |
379 } | 410 } |
380 | 411 |
| 412 NavigationThrottle::ThrottleCheckResult |
| 413 NavigationHandleImpl::CheckWillProcessResponse() { |
| 414 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); |
| 415 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); |
| 416 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); |
| 417 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 418 NavigationThrottle::ThrottleCheckResult result = |
| 419 throttles_[i]->WillProcessResponse(); |
| 420 switch (result) { |
| 421 case NavigationThrottle::PROCEED: |
| 422 continue; |
| 423 |
| 424 case NavigationThrottle::CANCEL: |
| 425 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 426 state_ = CANCELING; |
| 427 return result; |
| 428 |
| 429 case NavigationThrottle::DEFER: |
| 430 state_ = DEFERRING_RESPONSE; |
| 431 next_index_ = i + 1; |
| 432 return result; |
| 433 } |
| 434 } |
| 435 next_index_ = 0; |
| 436 state_ = WILL_PROCESS_RESPONSE; |
| 437 return NavigationThrottle::PROCEED; |
| 438 } |
| 439 |
381 void NavigationHandleImpl::RunCompleteCallback( | 440 void NavigationHandleImpl::RunCompleteCallback( |
382 NavigationThrottle::ThrottleCheckResult result) { | 441 NavigationThrottle::ThrottleCheckResult result) { |
383 DCHECK(result != NavigationThrottle::DEFER); | 442 DCHECK(result != NavigationThrottle::DEFER); |
384 if (!complete_callback_.is_null()) | |
385 complete_callback_.Run(result); | |
386 | 443 |
| 444 ThrottleChecksFinishedCallback callback = complete_callback_; |
387 complete_callback_.Reset(); | 445 complete_callback_.Reset(); |
| 446 |
| 447 if (!callback.is_null()) |
| 448 callback.Run(result); |
| 449 |
| 450 // No code after running the callback, as it might have resulted in our |
| 451 // destruction. |
388 } | 452 } |
389 | 453 |
390 } // namespace content | 454 } // namespace content |
OLD | NEW |