diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 19:14:12 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 19:14:12 +0000 |
commit | 4c76d7cc78ca3eef79535a3c2a4d934f436c6797 (patch) | |
tree | 4f879d4e9ee0eddfe5b4e2ae59017a49d86fd950 /net/url_request/url_request.cc | |
parent | 21e09ce274981dc8c5b12f923969020333c09931 (diff) | |
download | chromium_src-4c76d7cc78ca3eef79535a3c2a4d934f436c6797.zip chromium_src-4c76d7cc78ca3eef79535a3c2a4d934f436c6797.tar.gz chromium_src-4c76d7cc78ca3eef79535a3c2a4d934f436c6797.tar.bz2 |
Allow extensions to redirect requests in onBeforeRequest.
BUG=60101
TEST=no
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=81479
Review URL: http://codereview.chromium.org/6677148
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81782 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request.cc')
-rw-r--r-- | net/url_request/url_request.cc | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 5c437c2..3d60137 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -23,6 +23,7 @@ #include "net/url_request/url_request_job.h" #include "net/url_request/url_request_job_manager.h" #include "net/url_request/url_request_netlog_params.h" +#include "net/url_request/url_request_redirect_job.h" using base::Time; using std::string; @@ -120,7 +121,9 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate) redirect_limit_(kMaxRedirects), final_upload_progress_(0), priority_(LOWEST), - identifier_(GenerateURLRequestIdentifier()) { + identifier_(GenerateURLRequestIdentifier()), + ALLOW_THIS_IN_INITIALIZER_LIST( + before_request_callback_(this, &URLRequest::BeforeRequestComplete)) { SIMPLE_STATS_COUNTER("URLRequestCount"); // Sanity check out environment. @@ -134,9 +137,6 @@ URLRequest::~URLRequest() { if (context_ && context_->network_delegate()) context_->network_delegate()->NotifyURLRequestDestroyed(this); - if (before_request_callback_) - before_request_callback_->Cancel(); - Cancel(); if (job_) @@ -362,22 +362,41 @@ GURL URLRequest::GetSanitizedReferrer() const { void URLRequest::Start() { response_info_.request_time = Time::Now(); + // Only notify the delegate for the initial request. if (context_ && context_->network_delegate()) { - before_request_callback_ = new CancelableCompletionCallback<URLRequest>( - this, &URLRequest::BeforeRequestComplete); if (context_->network_delegate()->NotifyBeforeURLRequest( - this, before_request_callback_) == net::ERR_IO_PENDING) { - before_request_callback_->AddRef(); // balanced in BeforeRequestComplete + this, &before_request_callback_, &delegate_redirect_url_) == + net::ERR_IO_PENDING) { net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); return; // paused } } - StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); + StartInternal(); } /////////////////////////////////////////////////////////////////////////////// +void URLRequest::BeforeRequestComplete(int error) { + DCHECK(!job_); + DCHECK_NE(ERR_IO_PENDING, error); + + net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); + if (error != OK) { + StartJob(new URLRequestErrorJob(this, error)); + } else if (!delegate_redirect_url_.is_empty()) { + GURL new_url; + new_url.Swap(&delegate_redirect_url_); + StartJob(new URLRequestRedirectJob(this, new_url)); + } else { + StartInternal(); + } +} + +void URLRequest::StartInternal() { + StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); +} + void URLRequest::StartJob(URLRequestJob* job) { DCHECK(!is_pending_); DCHECK(!job_); @@ -404,18 +423,6 @@ void URLRequest::StartJob(URLRequestJob* job) { job_->Start(); } -void URLRequest::BeforeRequestComplete(int error) { - DCHECK(!job_); - - net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); - before_request_callback_->Release(); // balanced in Start - if (error != OK) { - StartJob(new URLRequestErrorJob(this, error)); - } else { - StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); - } -} - void URLRequest::Restart() { // Should only be called if the original job didn't make any progress. DCHECK(job_ && !job_->has_response_started()); @@ -628,7 +635,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { final_upload_progress_ = job_->GetUploadProgress(); PrepareToRestart(); - Start(); + StartInternal(); return OK; } |