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 RenderFrameHostImpl* render_frame_host, | |
288 scoped_refptr<net::HttpResponseHeaders> response_headers, | |
289 const ThrottleChecksFinishedCallback& callback) { | |
290 response_headers_ = response_headers; | |
291 state_ = WILL_PROCESS_RESPONSE; | |
292 complete_callback_ = callback; | |
293 | |
294 // Notify each throttle of the response. | |
295 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | |
296 | |
297 // If we're about to proceed, then we're ready to commit. | |
clamy
2016/01/27 14:13:21
nit: // A proceeding navigation is now about to co
| |
298 if (result == NavigationThrottle::PROCEED) | |
299 ReadyToCommitNavigation(render_frame_host, response_headers); | |
300 | |
301 // If the navigation is not deferred, run the callback. | |
302 if (result != NavigationThrottle::DEFER) | |
303 RunCompleteCallback(result); | |
304 } | |
305 | |
282 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 306 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
283 url_ = new_url; | 307 url_ = new_url; |
284 GetDelegate()->DidRedirectNavigation(this); | 308 GetDelegate()->DidRedirectNavigation(this); |
285 } | 309 } |
286 | 310 |
287 void NavigationHandleImpl::ReadyToCommitNavigation( | 311 void NavigationHandleImpl::ReadyToCommitNavigation( |
288 RenderFrameHostImpl* render_frame_host, | 312 RenderFrameHostImpl* render_frame_host, |
289 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 313 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
290 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 314 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
291 render_frame_host_ = render_frame_host; | 315 render_frame_host_ = render_frame_host; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 | 386 |
363 default: | 387 default: |
364 NOTREACHED(); | 388 NOTREACHED(); |
365 } | 389 } |
366 } | 390 } |
367 next_index_ = 0; | 391 next_index_ = 0; |
368 state_ = WILL_REDIRECT_REQUEST; | 392 state_ = WILL_REDIRECT_REQUEST; |
369 return NavigationThrottle::PROCEED; | 393 return NavigationThrottle::PROCEED; |
370 } | 394 } |
371 | 395 |
396 NavigationThrottle::ThrottleCheckResult | |
397 NavigationHandleImpl::CheckWillProcessResponse() { | |
398 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | |
399 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | |
400 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | |
401 for (size_t i = next_index_; i < throttles_.size(); ++i) { | |
402 NavigationThrottle::ThrottleCheckResult result = | |
403 throttles_[i]->WillProcessResponse(); | |
404 switch (result) { | |
405 case NavigationThrottle::PROCEED: | |
406 continue; | |
407 | |
408 case NavigationThrottle::CANCEL: | |
409 case NavigationThrottle::CANCEL_AND_IGNORE: | |
410 state_ = CANCELING; | |
411 return result; | |
412 | |
413 case NavigationThrottle::DEFER: | |
414 state_ = DEFERRING_RESPONSE; | |
415 next_index_ = i + 1; | |
416 return result; | |
417 } | |
418 } | |
419 next_index_ = 0; | |
420 state_ = WILL_PROCESS_RESPONSE; | |
421 return NavigationThrottle::PROCEED; | |
422 } | |
423 | |
372 void NavigationHandleImpl::RunCompleteCallback( | 424 void NavigationHandleImpl::RunCompleteCallback( |
373 NavigationThrottle::ThrottleCheckResult result) { | 425 NavigationThrottle::ThrottleCheckResult result) { |
374 DCHECK(result != NavigationThrottle::DEFER); | 426 DCHECK(result != NavigationThrottle::DEFER); |
375 if (!complete_callback_.is_null()) | |
376 complete_callback_.Run(result); | |
377 | 427 |
428 ThrottleChecksFinishedCallback callback = complete_callback_; | |
378 complete_callback_.Reset(); | 429 complete_callback_.Reset(); |
430 | |
431 if (!callback.is_null()) | |
432 callback.Run(result); | |
433 | |
434 // No code after running the calback, as it might result in our destruction. | |
clamy
2016/01/27 14:13:21
nit: s/calback/callback
nasko
2016/01/27 18:11:08
nit: "might have resulted"?
| |
379 } | 435 } |
380 | 436 |
381 } // namespace content | 437 } // namespace content |
OLD | NEW |