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

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

Issue 2574063003: Move ResourceHandler deferred actions ahead of external protocol handling. (Closed)
Patch Set: Reverts URLRequest changes; redirect bugfix; improved unit tests. 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..742d8fe999b2fa27cf75225f1aba5298b20d53fe 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(
@@ -476,8 +471,14 @@ void ResourceLoader::Cancel() {
}
void ResourceLoader::StartRequestInternal() {
+ // At this point any possible deferred start is already over.
mmenke 2016/12/16 16:19:36 I don't understand this comment, or what it has to
carlosk 2016/12/20 19:23:31 It was just meant to clarify that once this method
DCHECK(!request_->is_pending());
+ if (delegate_->HandleExternalProtocol(this, request_->url())) {
+ CancelAndIgnore();
+ return;
+ }
+
if (!request_->status().is_success()) {
mmenke 2016/12/16 16:19:36 Not quite sure what this is checking (Hrm...), but
carlosk 2016/12/20 19:23:31 Done. It was not the case before my change, but e
return;
}
@@ -534,6 +535,16 @@ void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
}
}
+void ResourceLoader::FollowDeferredRedirectInternal() {
+ DCHECK(!deferred_redirect_url_.is_empty());
+ if (delegate_->HandleExternalProtocol(this, deferred_redirect_url_)) {
+ CancelAndIgnore();
+ } else {
+ request_->FollowDeferredRedirect();
+ }
+ deferred_redirect_url_ = GURL();
mmenke 2016/12/16 16:19:36 Should clear this before calling FollowDeferredRed
carlosk 2016/12/20 19:23:31 Done.
+}
+
void ResourceLoader::CompleteResponseStarted() {
ResourceRequestInfoImpl* info = GetRequestInfo();
scoped_refptr<ResourceResponse> response = new ResourceResponse();

Powered by Google App Engine
This is Rietveld 408576698