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

Unified Diff: content/browser/loader/resource_loader.cc

Issue 2574063003: Move ResourceHandler deferred actions ahead of external protocol handling. (Closed)
Patch Set: Adds external protocol handling tests for sync and async cases. Created 4 years 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/loader/resource_loader.cc
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc
index bb77021ac8fa20c3d369154da1b6f0adcd0df945..e30970b991e525ca45aaf946afc12a8ecc6b6e99 100644
--- a/content/browser/loader/resource_loader.cc
+++ b/content/browser/loader/resource_loader.cc
@@ -157,11 +157,6 @@ ResourceLoader::~ResourceLoader() {
}
void ResourceLoader::StartRequest() {
- if (delegate_->HandleExternalProtocol(this, request_->url())) {
- CancelAndIgnore();
- return;
- }
-
// Give the handler a chance to delay the URLRequest from being started.
bool defer_start = false;
if (!handler_->OnWillStart(request_->url(), &defer_start)) {
@@ -273,12 +268,6 @@ void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused,
}
}
- if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) {
- // The request is complete so we can remove it.
- CancelAndIgnore();
- return;
- }
-
scoped_refptr<ResourceResponse> response = new ResourceResponse();
PopulateResourceResponse(info, request_.get(), response.get());
delegate_->DidReceiveRedirect(this, redirect_info.new_url, response.get());
@@ -286,6 +275,12 @@ void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused,
Cancel();
} else if (*defer) {
deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed.
+ DCHECK(deferred_redirect_url_.is_empty());
+ deferred_redirect_url_ = redirect_info.new_url;
+ } else if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) {
+ // The request is complete so we can remove it.
+ CancelAndIgnore();
+ return;
}
}
@@ -450,7 +445,7 @@ void ResourceLoader::Resume() {
StartRequestInternal();
break;
case DEFERRED_REDIRECT:
- request_->FollowDeferredRedirect();
+ FollowDeferredRedirectInternal();
break;
case DEFERRED_READ:
base::ThreadTaskRunnerHandle::Get()->PostTask(
@@ -478,10 +473,17 @@ void ResourceLoader::Cancel() {
void ResourceLoader::StartRequestInternal() {
DCHECK(!request_->is_pending());
+ // Note: at this point any possible deferred start actions are already over.
+
if (!request_->status().is_success()) {
return;
}
+ if (delegate_->HandleExternalProtocol(this, request_->url())) {
+ CancelAndIgnore();
+ return;
+ }
+
started_request_ = true;
request_->Start();
@@ -534,6 +536,17 @@ void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
}
}
+void ResourceLoader::FollowDeferredRedirectInternal() {
+ DCHECK(!deferred_redirect_url_.is_empty());
+ GURL redirect_url = deferred_redirect_url_;
+ deferred_redirect_url_ = GURL();
+ if (delegate_->HandleExternalProtocol(this, deferred_redirect_url_)) {
+ CancelAndIgnore();
+ } else {
+ request_->FollowDeferredRedirect();
+ }
+}
+
void ResourceLoader::CompleteResponseStarted() {
ResourceRequestInfoImpl* info = GetRequestInfo();
scoped_refptr<ResourceResponse> response = new ResourceResponse();

Powered by Google App Engine
This is Rietveld 408576698