From cdb11b555f79840fc9f793d808af13bcaf9bd1f7 Mon Sep 17 00:00:00 2001 From: "jcampan@chromium.org" Date: Sat, 7 Mar 2009 07:47:52 +0000 Subject: Landing again the CL that adds security info to canceled requests (it was breaking NPAPI tests on Vista due to an erroneuous commented line). TBR=darin Review URL: http://codereview.chromium.org/39309 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11197 0039d316-1c4b-4281-b951-d872f2087c98 --- net/url_request/url_request.cc | 18 ++++++++++++++++-- net/url_request/url_request.h | 17 +++++++++++++---- net/url_request/url_request_job.h | 3 +++ 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'net/url_request') diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index fefd24c..3de8439 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -260,10 +260,23 @@ void URLRequest::Start() { } void URLRequest::Cancel() { - CancelWithError(net::ERR_ABORTED); + DoCancel(net::ERR_ABORTED, net::SSLInfo()); } -void URLRequest::CancelWithError(int os_error) { +void URLRequest::SimulateError(int os_error) { + DoCancel(os_error, net::SSLInfo()); +} + +void URLRequest::SimulateSSLError(int os_error, const net::SSLInfo& ssl_info) { + // This should only be called on a started request. + if (!is_pending_ || !job_ || job_->has_response_started()) { + NOTREACHED(); + return; + } + DoCancel(os_error, ssl_info); +} + +void URLRequest::DoCancel(int os_error, const net::SSLInfo& ssl_info) { DCHECK(os_error < 0); // If the URL request already has an error status, then canceling is a no-op. @@ -271,6 +284,7 @@ void URLRequest::CancelWithError(int os_error) { if (status_.is_success()) { status_.set_status(URLRequestStatus::CANCELED); status_.set_os_error(os_error); + response_info_.ssl_info = ssl_info; } // There's nothing to do if we are not waiting on a Job. diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index f4aee3a..4309689 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -354,10 +354,15 @@ class URLRequest { // no effect once the response has completed. void Cancel(); - // Similar to Cancel but sets the error to |os_error| (see net_error_list.h - // for values) instead of net::ERR_ABORTED. - // Used to attach a reason for canceling a request. - void CancelWithError(int os_error); + // Cancels the request and sets the error to |os_error| (see net_error_list.h + // for values). + void SimulateError(int os_error); + + // Cancels the request and sets the error to |os_error| (see net_error_list.h + // for values) and attaches |ssl_info| as the SSLInfo for that request. This + // is useful to attach a certificate and certificate error to a canceled + // request. + void SimulateSSLError(int os_error, const net::SSLInfo& ssl_info); // Read initiates an asynchronous read from the response, and must only // be called after the OnResponseStarted callback is received with a @@ -435,6 +440,10 @@ class URLRequest { // been orphaned. void OrphanJob(); + // Cancels the request and set the error and ssl info for this request to the + // passed values. + void DoCancel(int os_error, const net::SSLInfo& ssl_info); + // Discard headers which have meaning in POST (Content-Length, Content-Type, // Origin). static std::string StripPostSpecificHeaders(const std::string& headers); diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index fae5a1b..aac3768 100644 --- a/net/url_request/url_request_job.h +++ b/net/url_request/url_request_job.h @@ -192,6 +192,9 @@ class URLRequestJob : public base::RefCountedThreadSafe { expected_content_size_ = size; } + // Whether we have processed the response for that request yet. + bool has_response_started() const { return has_handled_response_; } + protected: // Notifies the job that headers have been received. void NotifyHeadersComplete(); -- cgit v1.1