 Chromium Code Reviews
 Chromium Code Reviews Issue 1616943003:
  Teach navigation throttles how to cancel requests in WillProcessResponse.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1616943003:
  Teach navigation throttles how to cancel requests in WillProcessResponse.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: content/browser/frame_host/navigation_handle_impl.cc | 
| diff --git a/content/browser/frame_host/navigation_handle_impl.cc b/content/browser/frame_host/navigation_handle_impl.cc | 
| index a8d32e911e2311019cb8131cbb571d7f6da39a4e..a5a1997e0d44f6ac7c2eca6deac3c3ab5bc6e52c 100644 | 
| --- a/content/browser/frame_host/navigation_handle_impl.cc | 
| +++ b/content/browser/frame_host/navigation_handle_impl.cc | 
| @@ -147,14 +147,18 @@ bool NavigationHandleImpl::IsErrorPage() { | 
| } | 
| void NavigationHandleImpl::Resume() { | 
| - if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT) | 
| + if (state_ != DEFERRING_START && state_ != DEFERRING_REDIRECT && | 
| + state_ != DEFERRING_RESPONSE) { | 
| return; | 
| + } | 
| NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 
| if (state_ == DEFERRING_START) { | 
| result = CheckWillStartRequest(); | 
| - } else { | 
| + } else if (state_ == DEFERRING_REDIRECT) { | 
| result = CheckWillRedirectRequest(); | 
| + } else { | 
| + result = CheckWillProcessResponse(); | 
| } | 
| if (result != NavigationThrottle::DEFER) | 
| @@ -279,6 +283,26 @@ void NavigationHandleImpl::WillRedirectRequest( | 
| RunCompleteCallback(result); | 
| } | 
| +void NavigationHandleImpl::WillProcessResponse( | 
| + RenderFrameHostImpl* render_frame_host, | 
| + scoped_refptr<net::HttpResponseHeaders> response_headers, | 
| + const ThrottleChecksFinishedCallback& callback) { | 
| + response_headers_ = response_headers; | 
| + state_ = WILL_PROCESS_RESPONSE; | 
| + complete_callback_ = callback; | 
| + | 
| + // Notify each throttle of the response. | 
| + NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); | 
| + | 
| + // 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
 | 
| + if (result == NavigationThrottle::PROCEED) | 
| + ReadyToCommitNavigation(render_frame_host, response_headers); | 
| + | 
| + // If the navigation is not deferred, run the callback. | 
| + if (result != NavigationThrottle::DEFER) | 
| + RunCompleteCallback(result); | 
| +} | 
| + | 
| void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 
| url_ = new_url; | 
| GetDelegate()->DidRedirectNavigation(this); | 
| @@ -369,13 +393,45 @@ NavigationHandleImpl::CheckWillRedirectRequest() { | 
| return NavigationThrottle::PROCEED; | 
| } | 
| +NavigationThrottle::ThrottleCheckResult | 
| +NavigationHandleImpl::CheckWillProcessResponse() { | 
| + DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | 
| + DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | 
| + DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | 
| + for (size_t i = next_index_; i < throttles_.size(); ++i) { | 
| + NavigationThrottle::ThrottleCheckResult result = | 
| + throttles_[i]->WillProcessResponse(); | 
| + switch (result) { | 
| + case NavigationThrottle::PROCEED: | 
| + continue; | 
| + | 
| + case NavigationThrottle::CANCEL: | 
| + case NavigationThrottle::CANCEL_AND_IGNORE: | 
| + state_ = CANCELING; | 
| + return result; | 
| + | 
| + case NavigationThrottle::DEFER: | 
| + state_ = DEFERRING_RESPONSE; | 
| + next_index_ = i + 1; | 
| + return result; | 
| + } | 
| + } | 
| + next_index_ = 0; | 
| + state_ = WILL_PROCESS_RESPONSE; | 
| + return NavigationThrottle::PROCEED; | 
| +} | 
| + | 
| void NavigationHandleImpl::RunCompleteCallback( | 
| NavigationThrottle::ThrottleCheckResult result) { | 
| DCHECK(result != NavigationThrottle::DEFER); | 
| - if (!complete_callback_.is_null()) | 
| - complete_callback_.Run(result); | 
| + ThrottleChecksFinishedCallback callback = complete_callback_; | 
| complete_callback_.Reset(); | 
| + | 
| + if (!callback.is_null()) | 
| + callback.Run(result); | 
| + | 
| + // 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"?
 | 
| } | 
| } // namespace content |