| 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 "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 DoneWithRequest(FINISHED); | 260 DoneWithRequest(FINISHED); |
| 261 URLRequestJob::NotifyDone(status); | 261 URLRequestJob::NotifyDone(status); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void URLRequestHttpJob::DestroyTransaction() { | 264 void URLRequestHttpJob::DestroyTransaction() { |
| 265 DCHECK(transaction_.get()); | 265 DCHECK(transaction_.get()); |
| 266 | 266 |
| 267 DoneWithRequest(ABORTED); | 267 DoneWithRequest(ABORTED); |
| 268 transaction_.reset(); | 268 transaction_.reset(); |
| 269 response_info_ = NULL; | 269 response_info_ = NULL; |
| 270 context_ = NULL; | |
| 271 } | 270 } |
| 272 | 271 |
| 273 void URLRequestHttpJob::StartTransaction() { | 272 void URLRequestHttpJob::StartTransaction() { |
| 274 if (request_->context() && request_->context()->network_delegate()) { | 273 if (request_->context() && request_->context()->network_delegate()) { |
| 275 int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders( | 274 int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders( |
| 276 request_, notify_before_headers_sent_callback_, | 275 request_, notify_before_headers_sent_callback_, |
| 277 &request_info_.extra_headers); | 276 &request_info_.extra_headers); |
| 278 // If an extension blocks the request, we rely on the callback to | 277 // If an extension blocks the request, we rely on the callback to |
| 279 // StartTransactionInternal(). | 278 // StartTransactionInternal(). |
| 280 if (rv == ERR_IO_PENDING) { | 279 if (rv == ERR_IO_PENDING) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 !manager->enforce_throttling() || | 334 !manager->enforce_throttling() || |
| 336 request_->first_party_for_cookies().scheme() != "chrome-extension" || | 335 request_->first_party_for_cookies().scheme() != "chrome-extension" || |
| 337 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { | 336 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { |
| 338 rv = transaction_->Start( | 337 rv = transaction_->Start( |
| 339 &request_info_, start_callback_, request_->net_log()); | 338 &request_info_, start_callback_, request_->net_log()); |
| 340 start_time_ = base::TimeTicks::Now(); | 339 start_time_ = base::TimeTicks::Now(); |
| 341 } else { | 340 } else { |
| 342 // Special error code for the exponential back-off module. | 341 // Special error code for the exponential back-off module. |
| 343 rv = ERR_TEMPORARILY_THROTTLED; | 342 rv = ERR_TEMPORARILY_THROTTLED; |
| 344 } | 343 } |
| 345 // Make sure the context is alive for the duration of the | |
| 346 // transaction. | |
| 347 context_ = request_->context(); | |
| 348 } | 344 } |
| 349 } | 345 } |
| 350 | 346 |
| 351 if (rv == ERR_IO_PENDING) | 347 if (rv == ERR_IO_PENDING) |
| 352 return; | 348 return; |
| 353 | 349 |
| 354 // The transaction started synchronously, but we need to notify the | 350 // The transaction started synchronously, but we need to notify the |
| 355 // URLRequest delegate via the message loop. | 351 // URLRequest delegate via the message loop. |
| 356 MessageLoop::current()->PostTask( | 352 MessageLoop::current()->PostTask( |
| 357 FROM_HERE, | 353 FROM_HERE, |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 return; | 667 return; |
| 672 | 668 |
| 673 // If the transaction was destroyed, then the job was cancelled, and | 669 // If the transaction was destroyed, then the job was cancelled, and |
| 674 // we can just ignore this notification. | 670 // we can just ignore this notification. |
| 675 if (!transaction_.get()) | 671 if (!transaction_.get()) |
| 676 return; | 672 return; |
| 677 | 673 |
| 678 // Clear the IO_PENDING status | 674 // Clear the IO_PENDING status |
| 679 SetStatus(URLRequestStatus()); | 675 SetStatus(URLRequestStatus()); |
| 680 | 676 |
| 677 const URLRequestContext* context = request_->context(); |
| 678 |
| 681 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && | 679 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && |
| 682 transaction_->GetResponseInfo() != NULL) { | 680 transaction_->GetResponseInfo() != NULL) { |
| 683 FraudulentCertificateReporter* reporter = | 681 FraudulentCertificateReporter* reporter = |
| 684 context_->fraudulent_certificate_reporter(); | 682 context->fraudulent_certificate_reporter(); |
| 685 if (reporter != NULL) { | 683 if (reporter != NULL) { |
| 686 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; | 684 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; |
| 687 bool sni_available = SSLConfigService::IsSNIAvailable( | 685 bool sni_available = SSLConfigService::IsSNIAvailable( |
| 688 context_->ssl_config_service()); | 686 context->ssl_config_service()); |
| 689 const std::string& host = request_->url().host(); | 687 const std::string& host = request_->url().host(); |
| 690 | 688 |
| 691 reporter->SendReport(host, ssl_info, sni_available); | 689 reporter->SendReport(host, ssl_info, sni_available); |
| 692 } | 690 } |
| 693 } | 691 } |
| 694 | 692 |
| 695 if (result == OK) { | 693 if (result == OK) { |
| 696 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); | 694 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
| 697 if (request_->context() && request_->context()->network_delegate()) { | 695 if (context && context->network_delegate()) { |
| 698 // Note that |this| may not be deleted until | 696 // Note that |this| may not be deleted until |
| 699 // |on_headers_received_callback_| or | 697 // |on_headers_received_callback_| or |
| 700 // |NetworkDelegate::URLRequestDestroyed()| has been called. | 698 // |NetworkDelegate::URLRequestDestroyed()| has been called. |
| 701 int error = request_->context()->network_delegate()-> | 699 int error = context->network_delegate()-> |
| 702 NotifyHeadersReceived(request_, on_headers_received_callback_, | 700 NotifyHeadersReceived(request_, on_headers_received_callback_, |
| 703 headers, &override_response_headers_); | 701 headers, &override_response_headers_); |
| 704 if (error != net::OK) { | 702 if (error != net::OK) { |
| 705 if (error == net::ERR_IO_PENDING) { | 703 if (error == net::ERR_IO_PENDING) { |
| 706 awaiting_callback_ = true; | 704 awaiting_callback_ = true; |
| 707 request_->net_log().BeginEvent( | 705 request_->net_log().BeginEvent( |
| 708 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 706 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 709 } else { | 707 } else { |
| 710 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, | 708 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
| 711 make_scoped_refptr( | 709 make_scoped_refptr( |
| 712 new NetLogStringParameter("source", "delegate"))); | 710 new NetLogStringParameter("source", "delegate"))); |
| 713 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); | 711 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); |
| 714 } | 712 } |
| 715 return; | 713 return; |
| 716 } | 714 } |
| 717 } | 715 } |
| 718 | 716 |
| 719 SaveCookiesAndNotifyHeadersComplete(net::OK); | 717 SaveCookiesAndNotifyHeadersComplete(net::OK); |
| 720 } else if (IsCertificateError(result)) { | 718 } else if (IsCertificateError(result)) { |
| 721 // We encountered an SSL certificate error. Ask our delegate to decide | 719 // We encountered an SSL certificate error. Ask our delegate to decide |
| 722 // what we should do. | 720 // what we should do. |
| 723 | 721 |
| 724 TransportSecurityState::DomainState domain_state; | 722 TransportSecurityState::DomainState domain_state; |
| 723 const URLRequestContext* context = request_->context(); |
| 725 const bool fatal = | 724 const bool fatal = |
| 726 context_->transport_security_state() && | 725 context->transport_security_state() && |
| 727 context_->transport_security_state()->GetDomainState( | 726 context->transport_security_state()->GetDomainState( |
| 728 request_info_.url.host(), | 727 request_info_.url.host(), |
| 729 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), | 728 SSLConfigService::IsSNIAvailable(context->ssl_config_service()), |
| 730 &domain_state); | 729 &domain_state); |
| 731 NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal); | 730 NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal); |
| 732 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 731 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 733 NotifyCertificateRequested( | 732 NotifyCertificateRequested( |
| 734 transaction_->GetResponseInfo()->cert_request_info); | 733 transaction_->GetResponseInfo()->cert_request_info); |
| 735 } else { | 734 } else { |
| 736 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 735 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 737 } | 736 } |
| 738 } | 737 } |
| 739 | 738 |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 return override_response_headers_.get() ? | 1412 return override_response_headers_.get() ? |
| 1414 override_response_headers_ : | 1413 override_response_headers_ : |
| 1415 transaction_->GetResponseInfo()->headers; | 1414 transaction_->GetResponseInfo()->headers; |
| 1416 } | 1415 } |
| 1417 | 1416 |
| 1418 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1417 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1419 awaiting_callback_ = false; | 1418 awaiting_callback_ = false; |
| 1420 } | 1419 } |
| 1421 | 1420 |
| 1422 } // namespace net | 1421 } // namespace net |
| OLD | NEW |