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

Unified 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 side-by-side diff with in-line comments
Download patch
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..020005d22b256d77caecc15e19f630659103f238 100644
--- a/content/browser/frame_host/navigation_handle_impl.cc
+++ b/content/browser/frame_host/navigation_handle_impl.cc
@@ -279,6 +279,20 @@ void NavigationHandleImpl::WillRedirectRequest(
RunCompleteCallback(result);
}
+void NavigationHandleImpl::WillProcessResponse(
+ 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();
+
+ 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.
+ RunCompleteCallback(result);
+}
+
void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) {
url_ = new_url;
GetDelegate()->DidRedirectNavigation(this);
@@ -369,13 +383,40 @@ NavigationHandleImpl::CheckWillRedirectRequest() {
return NavigationThrottle::PROCEED;
}
+NavigationThrottle::ThrottleCheckResult
+NavigationHandleImpl::CheckWillProcessResponse() {
+ DCHECK(state_ == WILL_PROCESS_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:
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.
+ NOTREACHED();
+ }
+ }
+ 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.
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698