| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 waiting_for_upload_progress_ack_(false), | 87 waiting_for_upload_progress_ack_(false), |
| 88 is_transferring_(false), | 88 is_transferring_(false), |
| 89 weak_ptr_factory_(this) { | 89 weak_ptr_factory_(this) { |
| 90 request_->set_delegate(this); | 90 request_->set_delegate(this); |
| 91 handler_->SetController(this); | 91 handler_->SetController(this); |
| 92 } | 92 } |
| 93 | 93 |
| 94 ResourceLoader::~ResourceLoader() { | 94 ResourceLoader::~ResourceLoader() { |
| 95 if (login_delegate_.get()) | 95 if (login_delegate_.get()) |
| 96 login_delegate_->OnRequestCancelled(); | 96 login_delegate_->OnRequestCancelled(); |
| 97 ssl_client_auth_handler_.reset(); | 97 if (ssl_client_auth_handler_.get()) |
| 98 ssl_client_auth_handler_->OnRequestCancelled(); |
| 98 | 99 |
| 99 // Run ResourceHandler destructor before we tear-down the rest of our state | 100 // Run ResourceHandler destructor before we tear-down the rest of our state |
| 100 // as the ResourceHandler may want to inspect the URLRequest and other state. | 101 // as the ResourceHandler may want to inspect the URLRequest and other state. |
| 101 handler_.reset(); | 102 handler_.reset(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void ResourceLoader::StartRequest() { | 105 void ResourceLoader::StartRequest() { |
| 105 if (delegate_->HandleExternalProtocol(this, request_->url())) { | 106 if (delegate_->HandleExternalProtocol(this, request_->url())) { |
| 106 CancelAndIgnore(); | 107 CancelAndIgnore(); |
| 107 return; | 108 return; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 187 } |
| 187 | 188 |
| 188 ResourceRequestInfoImpl* ResourceLoader::GetRequestInfo() { | 189 ResourceRequestInfoImpl* ResourceLoader::GetRequestInfo() { |
| 189 return ResourceRequestInfoImpl::ForRequest(request_.get()); | 190 return ResourceRequestInfoImpl::ForRequest(request_.get()); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void ResourceLoader::ClearLoginDelegate() { | 193 void ResourceLoader::ClearLoginDelegate() { |
| 193 login_delegate_ = NULL; | 194 login_delegate_ = NULL; |
| 194 } | 195 } |
| 195 | 196 |
| 197 void ResourceLoader::ClearSSLClientAuthHandler() { |
| 198 ssl_client_auth_handler_ = NULL; |
| 199 } |
| 200 |
| 196 void ResourceLoader::OnUploadProgressACK() { | 201 void ResourceLoader::OnUploadProgressACK() { |
| 197 waiting_for_upload_progress_ack_ = false; | 202 waiting_for_upload_progress_ack_ = false; |
| 198 } | 203 } |
| 199 | 204 |
| 200 void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, | 205 void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, |
| 201 const net::RedirectInfo& redirect_info, | 206 const net::RedirectInfo& redirect_info, |
| 202 bool* defer) { | 207 bool* defer) { |
| 203 DCHECK_EQ(request_.get(), unused); | 208 DCHECK_EQ(request_.get(), unused); |
| 204 | 209 |
| 205 VLOG(1) << "OnReceivedRedirect: " << request_->url().spec(); | 210 VLOG(1) << "OnReceivedRedirect: " << request_->url().spec(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 void ResourceLoader::OnCertificateRequested( | 263 void ResourceLoader::OnCertificateRequested( |
| 259 net::URLRequest* unused, | 264 net::URLRequest* unused, |
| 260 net::SSLCertRequestInfo* cert_info) { | 265 net::SSLCertRequestInfo* cert_info) { |
| 261 DCHECK_EQ(request_.get(), unused); | 266 DCHECK_EQ(request_.get(), unused); |
| 262 | 267 |
| 263 if (request_->load_flags() & net::LOAD_PREFETCH) { | 268 if (request_->load_flags() & net::LOAD_PREFETCH) { |
| 264 request_->Cancel(); | 269 request_->Cancel(); |
| 265 return; | 270 return; |
| 266 } | 271 } |
| 267 | 272 |
| 268 DCHECK(!ssl_client_auth_handler_) | 273 DCHECK(!ssl_client_auth_handler_.get()) |
| 269 << "OnCertificateRequested called with ssl_client_auth_handler pending"; | 274 << "OnCertificateRequested called with ssl_client_auth_handler pending"; |
| 270 ssl_client_auth_handler_.reset(new SSLClientAuthHandler( | 275 ssl_client_auth_handler_ = new SSLClientAuthHandler( |
| 271 GetRequestInfo()->GetContext()->CreateClientCertStore(), | 276 GetRequestInfo()->GetContext()->CreateClientCertStore(), |
| 272 request_.get(), | 277 request_.get(), |
| 273 cert_info, | 278 cert_info); |
| 274 base::Bind(&ResourceLoader::ContinueWithCertificate, | |
| 275 weak_ptr_factory_.GetWeakPtr()))); | |
| 276 ssl_client_auth_handler_->SelectCertificate(); | 279 ssl_client_auth_handler_->SelectCertificate(); |
| 277 } | 280 } |
| 278 | 281 |
| 279 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, | 282 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, |
| 280 const net::SSLInfo& ssl_info, | 283 const net::SSLInfo& ssl_info, |
| 281 bool fatal) { | 284 bool fatal) { |
| 282 ResourceRequestInfoImpl* info = GetRequestInfo(); | 285 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 283 | 286 |
| 284 int render_process_id; | 287 int render_process_id; |
| 285 int render_frame_id; | 288 int render_frame_id; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 } | 485 } |
| 483 | 486 |
| 484 // TODO(darin): Perhaps we should really be looking to see if the status is | 487 // TODO(darin): Perhaps we should really be looking to see if the status is |
| 485 // IO_PENDING? | 488 // IO_PENDING? |
| 486 bool was_pending = request_->is_pending(); | 489 bool was_pending = request_->is_pending(); |
| 487 | 490 |
| 488 if (login_delegate_.get()) { | 491 if (login_delegate_.get()) { |
| 489 login_delegate_->OnRequestCancelled(); | 492 login_delegate_->OnRequestCancelled(); |
| 490 login_delegate_ = NULL; | 493 login_delegate_ = NULL; |
| 491 } | 494 } |
| 492 ssl_client_auth_handler_.reset(); | 495 if (ssl_client_auth_handler_.get()) { |
| 496 ssl_client_auth_handler_->OnRequestCancelled(); |
| 497 ssl_client_auth_handler_ = NULL; |
| 498 } |
| 493 | 499 |
| 494 request_->CancelWithError(error); | 500 request_->CancelWithError(error); |
| 495 | 501 |
| 496 if (!was_pending) { | 502 if (!was_pending) { |
| 497 // If the request isn't in flight, then we won't get an asynchronous | 503 // If the request isn't in flight, then we won't get an asynchronous |
| 498 // notification from the request, so we have to signal ourselves to finish | 504 // notification from the request, so we have to signal ourselves to finish |
| 499 // this request. | 505 // this request. |
| 500 base::MessageLoop::current()->PostTask( | 506 base::MessageLoop::current()->PostTask( |
| 501 FROM_HERE, | 507 FROM_HERE, |
| 502 base::Bind(&ResourceLoader::ResponseCompleted, | 508 base::Bind(&ResourceLoader::ResponseCompleted, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 case net::URLRequestStatus::IO_PENDING: | 704 case net::URLRequestStatus::IO_PENDING: |
| 699 case net::URLRequestStatus::FAILED: | 705 case net::URLRequestStatus::FAILED: |
| 700 status = STATUS_UNDEFINED; | 706 status = STATUS_UNDEFINED; |
| 701 break; | 707 break; |
| 702 } | 708 } |
| 703 | 709 |
| 704 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 710 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
| 705 } | 711 } |
| 706 } | 712 } |
| 707 | 713 |
| 708 void ResourceLoader::ContinueWithCertificate(net::X509Certificate* cert) { | |
| 709 ssl_client_auth_handler_.reset(); | |
| 710 request_->ContinueWithCertificate(cert); | |
| 711 } | |
| 712 | |
| 713 } // namespace content | 714 } // namespace content |
| OLD | NEW |