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