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

Unified Diff: content/browser/frame_host/navigation_request.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_request.cc
diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc
index df0f7a1e7b7128331b36debd5882b31dd4f37bd5..0aab9b7a5c3e6aa652869b9c43bfca3c77cf59da 100644
--- a/content/browser/frame_host/navigation_request.cc
+++ b/content/browser/frame_host/navigation_request.cc
@@ -259,8 +259,10 @@ void NavigationRequest::OnRequestRedirected(
void NavigationRequest::OnResponseStarted(
const scoped_refptr<ResourceResponse>& response,
scoped_ptr<StreamHandle> body) {
- DCHECK(state_ == STARTED);
+ DCHECK(state_ == STARTED && !response_ && !body_);
state_ = RESPONSE_STARTED;
+ response_ = response.get();
+ body_ = std::move(body);
// Update the service worker params of the request params.
request_params_.should_create_service_worker =
@@ -272,8 +274,10 @@ void NavigationRequest::OnResponseStarted(
->service_worker_provider_host_id();
}
- frame_tree_node_->navigator()->CommitNavigation(
- frame_tree_node_, response.get(), std::move(body));
+ navigation_handle_->WillProcessResponse(
+ response->head.headers,
+ base::Bind(&NavigationRequest::OnResponseChecksComplete,
+ base::Unretained(this)));
}
void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache,
@@ -330,6 +334,22 @@ void NavigationRequest::OnRedirectChecksComplete(
navigation_handle_->DidRedirectNavigation(common_params_.url);
}
+void NavigationRequest::OnResponseChecksComplete(
+ NavigationThrottle::ThrottleCheckResult result) {
+ CHECK(result != NavigationThrottle::DEFER);
+
+ // Abort the request if needed. This will destroy the NavigationRequest.
+ if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
+ result == NavigationThrottle::CANCEL) {
+ // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
+ frame_tree_node_->ResetNavigationRequest(false);
+ return;
+ }
+
+ frame_tree_node_->navigator()->CommitNavigation(
+ frame_tree_node_, response_.get(), std::move(body_));
+}
+
void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
// Only initialize the ServiceWorkerNavigationHandle if it can be created for
// this frame.

Powered by Google App Engine
This is Rietveld 408576698