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) { | |
152 return; | 151 return; |
153 } | |
154 | 152 |
155 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 153 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
156 if (state_ == DEFERRING_START) { | 154 if (state_ == DEFERRING_START) { |
157 result = CheckWillStartRequest(); | 155 result = CheckWillStartRequest(); |
158 } else if (state_ == DEFERRING_REDIRECT) { | 156 } else { |
159 result = CheckWillRedirectRequest(); | 157 result = CheckWillRedirectRequest(); |
160 } else { | |
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_); | |
167 } | 158 } |
168 | 159 |
169 if (result != NavigationThrottle::DEFER) | 160 if (result != NavigationThrottle::DEFER) |
170 RunCompleteCallback(result); | 161 RunCompleteCallback(result); |
171 } | 162 } |
172 | 163 |
173 void NavigationHandleImpl::CancelDeferredNavigation( | 164 void NavigationHandleImpl::CancelDeferredNavigation( |
174 NavigationThrottle::ThrottleCheckResult result) { | 165 NavigationThrottle::ThrottleCheckResult result) { |
175 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 166 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
176 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || | 167 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 complete_callback_ = callback; | 272 complete_callback_ = callback; |
282 | 273 |
283 // Notify each throttle of the request. | 274 // Notify each throttle of the request. |
284 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 275 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
285 | 276 |
286 // If the navigation is not deferred, run the callback. | 277 // If the navigation is not deferred, run the callback. |
287 if (result != NavigationThrottle::DEFER) | 278 if (result != NavigationThrottle::DEFER) |
288 RunCompleteCallback(result); | 279 RunCompleteCallback(result); |
289 } | 280 } |
290 | 281 |
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 | |
313 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 282 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
314 url_ = new_url; | 283 url_ = new_url; |
315 GetDelegate()->DidRedirectNavigation(this); | 284 GetDelegate()->DidRedirectNavigation(this); |
316 } | 285 } |
317 | 286 |
318 void NavigationHandleImpl::ReadyToCommitNavigation( | 287 void NavigationHandleImpl::ReadyToCommitNavigation( |
319 RenderFrameHostImpl* render_frame_host, | 288 RenderFrameHostImpl* render_frame_host, |
320 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 289 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
321 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 290 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
322 render_frame_host_ = render_frame_host; | 291 render_frame_host_ = render_frame_host; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 362 |
394 default: | 363 default: |
395 NOTREACHED(); | 364 NOTREACHED(); |
396 } | 365 } |
397 } | 366 } |
398 next_index_ = 0; | 367 next_index_ = 0; |
399 state_ = WILL_REDIRECT_REQUEST; | 368 state_ = WILL_REDIRECT_REQUEST; |
400 return NavigationThrottle::PROCEED; | 369 return NavigationThrottle::PROCEED; |
401 } | 370 } |
402 | 371 |
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 | |
431 void NavigationHandleImpl::RunCompleteCallback( | 372 void NavigationHandleImpl::RunCompleteCallback( |
432 NavigationThrottle::ThrottleCheckResult result) { | 373 NavigationThrottle::ThrottleCheckResult result) { |
433 DCHECK(result != NavigationThrottle::DEFER); | 374 DCHECK(result != NavigationThrottle::DEFER); |
| 375 if (!complete_callback_.is_null()) |
| 376 complete_callback_.Run(result); |
434 | 377 |
435 ThrottleChecksFinishedCallback callback = complete_callback_; | |
436 complete_callback_.Reset(); | 378 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. | |
443 } | 379 } |
444 | 380 |
445 } // namespace content | 381 } // namespace content |
OLD | NEW |