Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1125)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 1616943003: Teach navigation throttles how to cancel requests in WillProcessResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fiddling. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 complete_callback_ = callback; 272 complete_callback_ = callback;
273 273
274 // Notify each throttle of the request. 274 // Notify each throttle of the request.
275 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); 275 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest();
276 276
277 // If the navigation is not deferred, run the callback. 277 // If the navigation is not deferred, run the callback.
278 if (result != NavigationThrottle::DEFER) 278 if (result != NavigationThrottle::DEFER)
279 RunCompleteCallback(result); 279 RunCompleteCallback(result);
280 } 280 }
281 281
282 void NavigationHandleImpl::WillProcessResponse(
283 scoped_refptr<net::HttpResponseHeaders> response_headers,
284 const ThrottleChecksFinishedCallback& callback) {
285 response_headers_ = response_headers;
286 state_ = WILL_PROCESS_RESPONSE;
287 complete_callback_ = callback;
288
289 // Notify each throttle of the response.
290 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse();
291
292 DCHECK(result != NavigationThrottle::DEFER);
clamy 2016/01/25 16:36:21 This should match the other checks: // If the navi
Mike West 2016/01/26 09:41:41 Done.
293 RunCompleteCallback(result);
294 }
295
282 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { 296 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) {
283 url_ = new_url; 297 url_ = new_url;
284 GetDelegate()->DidRedirectNavigation(this); 298 GetDelegate()->DidRedirectNavigation(this);
285 } 299 }
286 300
287 void NavigationHandleImpl::ReadyToCommitNavigation( 301 void NavigationHandleImpl::ReadyToCommitNavigation(
288 RenderFrameHostImpl* render_frame_host, 302 RenderFrameHostImpl* render_frame_host,
289 scoped_refptr<net::HttpResponseHeaders> response_headers) { 303 scoped_refptr<net::HttpResponseHeaders> response_headers) {
290 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); 304 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host);
291 render_frame_host_ = render_frame_host; 305 render_frame_host_ = render_frame_host;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 376
363 default: 377 default:
364 NOTREACHED(); 378 NOTREACHED();
365 } 379 }
366 } 380 }
367 next_index_ = 0; 381 next_index_ = 0;
368 state_ = WILL_REDIRECT_REQUEST; 382 state_ = WILL_REDIRECT_REQUEST;
369 return NavigationThrottle::PROCEED; 383 return NavigationThrottle::PROCEED;
370 } 384 }
371 385
386 NavigationThrottle::ThrottleCheckResult
387 NavigationHandleImpl::CheckWillProcessResponse() {
388 DCHECK(state_ == WILL_PROCESS_RESPONSE && next_index_ == 0);
389 for (size_t i = next_index_; i < throttles_.size(); ++i) {
390 NavigationThrottle::ThrottleCheckResult result =
391 throttles_[i]->WillProcessResponse();
392 switch (result) {
393 case NavigationThrottle::PROCEED:
394 continue;
395
396 case NavigationThrottle::CANCEL:
397 case NavigationThrottle::CANCEL_AND_IGNORE:
398 state_ = CANCELING;
399 return result;
400
401 case NavigationThrottle::DEFER:
clamy 2016/01/25 16:36:21 Since we're introducing it in the public API, we n
Mike West 2016/01/26 09:41:41 Done.
402 NOTREACHED();
403 }
404 }
405 state_ = WILL_PROCESS_RESPONSE;
406 return NavigationThrottle::PROCEED;
407 }
408
372 void NavigationHandleImpl::RunCompleteCallback( 409 void NavigationHandleImpl::RunCompleteCallback(
373 NavigationThrottle::ThrottleCheckResult result) { 410 NavigationThrottle::ThrottleCheckResult result) {
374 DCHECK(result != NavigationThrottle::DEFER); 411 DCHECK(result != NavigationThrottle::DEFER);
375 if (!complete_callback_.is_null())
376 complete_callback_.Run(result);
377 412
413 ThrottleChecksFinishedCallback callback = complete_callback_;
378 complete_callback_.Reset(); 414 complete_callback_.Reset();
415
416 if (!callback.is_null())
417 callback.Run(result);
418
419 // No code after running the calback, as it might result in our destruction.
379 } 420 }
380 421
381 } // namespace content 422 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698