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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/browser/frame_host/navigator.h" | 9 #include "content/browser/frame_host/navigator.h" |
10 #include "content/browser/frame_host/navigator_delegate.h" | 10 #include "content/browser/frame_host/navigator_delegate.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 complete_callback_ = callback; | 273 complete_callback_ = callback; |
274 | 274 |
275 // Notify each throttle of the request. | 275 // Notify each throttle of the request. |
276 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 276 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
277 | 277 |
278 // If the navigation is not deferred, run the callback. | 278 // If the navigation is not deferred, run the callback. |
279 if (result != NavigationThrottle::DEFER) | 279 if (result != NavigationThrottle::DEFER) |
280 RunCompleteCallback(result); | 280 RunCompleteCallback(result); |
281 } | 281 } |
282 | 282 |
283 void NavigationHandleImpl::WillProcessResponse( | |
284 RenderFrameHostImpl* render_frame_host, | |
285 scoped_refptr<net::HttpResponseHeaders> response_headers, | |
286 const ThrottleChecksFinishedCallback& callback) { | |
287 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | |
288 render_frame_host_ = render_frame_host; | |
289 response_headers_ = response_headers; | |
290 state_ = READY_TO_COMMIT; | |
291 | |
292 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | |
293 | |
294 if (result != NavigationThrottle::PROCEED) { | |
295 DCHECK(result == NavigationThrottle::CANCEL || | |
296 result == NavigationThrottle::CANCEL_AND_IGNORE); | |
297 complete_callback_ = callback; | |
298 RunCompleteCallback(result); | |
299 } else { | |
300 ReadyToCommitNavigation(render_frame_host, response_headers); | |
Mike West
2015/12/17 13:09:15
This feels a bit hacky. I'd appreciate suggestions
| |
301 } | |
302 } | |
303 | |
283 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 304 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
284 url_ = new_url; | 305 url_ = new_url; |
285 GetDelegate()->DidRedirectNavigation(this); | 306 GetDelegate()->DidRedirectNavigation(this); |
286 } | 307 } |
287 | 308 |
288 void NavigationHandleImpl::ReadyToCommitNavigation( | 309 void NavigationHandleImpl::ReadyToCommitNavigation( |
289 RenderFrameHostImpl* render_frame_host, | 310 RenderFrameHostImpl* render_frame_host, |
290 scoped_refptr<net::HttpResponseHeaders> response_headers) { | 311 scoped_refptr<net::HttpResponseHeaders> response_headers) { |
291 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 312 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
292 render_frame_host_ = render_frame_host; | 313 render_frame_host_ = render_frame_host; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 | 386 |
366 default: | 387 default: |
367 NOTREACHED(); | 388 NOTREACHED(); |
368 } | 389 } |
369 } | 390 } |
370 next_index_ = 0; | 391 next_index_ = 0; |
371 state_ = WILL_REDIRECT_REQUEST; | 392 state_ = WILL_REDIRECT_REQUEST; |
372 return NavigationThrottle::PROCEED; | 393 return NavigationThrottle::PROCEED; |
373 } | 394 } |
374 | 395 |
396 NavigationThrottle::ThrottleCheckResult | |
397 NavigationHandleImpl::CheckWillProcessResponse() { | |
398 DCHECK(state_ == READY_TO_COMMIT); | |
399 for (size_t i = next_index_; i < throttles_.size(); ++i) { | |
400 NavigationThrottle::ThrottleCheckResult result = | |
401 throttles_[i]->WillProcessResponse(); | |
402 switch (result) { | |
403 case NavigationThrottle::PROCEED: | |
404 continue; | |
405 | |
406 case NavigationThrottle::CANCEL: | |
407 case NavigationThrottle::CANCEL_AND_IGNORE: | |
408 state_ = CANCELING; | |
409 return result; | |
410 | |
411 case NavigationThrottle::DEFER: | |
412 default: | |
413 NOTREACHED(); | |
414 } | |
415 } | |
416 next_index_ = 0; | |
417 state_ = READY_TO_COMMIT; | |
418 return NavigationThrottle::PROCEED; | |
419 } | |
420 | |
375 void NavigationHandleImpl::RunCompleteCallback( | 421 void NavigationHandleImpl::RunCompleteCallback( |
376 NavigationThrottle::ThrottleCheckResult result) { | 422 NavigationThrottle::ThrottleCheckResult result) { |
377 DCHECK(result != NavigationThrottle::DEFER); | 423 DCHECK(result != NavigationThrottle::DEFER); |
378 if (!complete_callback_.is_null()) | 424 if (!complete_callback_.is_null()) |
379 complete_callback_.Run(result); | 425 complete_callback_.Run(result); |
380 | 426 |
381 complete_callback_.Reset(); | 427 complete_callback_.Reset(); |
382 } | 428 } |
383 | 429 |
384 } // namespace content | 430 } // namespace content |
OLD | NEW |