OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" |
15 #include "net/base/cert_status_flags.h" | 16 #include "net/base/cert_status_flags.h" |
16 #include "net/base/cookie_policy.h" | 17 #include "net/base/cookie_policy.h" |
17 #include "net/base/cookie_store.h" | 18 #include "net/base/cookie_store.h" |
18 #include "net/base/filter.h" | 19 #include "net/base/filter.h" |
19 #include "net/base/transport_security_state.h" | 20 #include "net/base/transport_security_state.h" |
20 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
23 #include "net/base/sdch_manager.h" | 24 #include "net/base/sdch_manager.h" |
24 #include "net/base/ssl_cert_request_info.h" | 25 #include "net/base/ssl_cert_request_info.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return new URLRequestHttpJob(request); | 118 return new URLRequestHttpJob(request); |
118 } | 119 } |
119 | 120 |
120 | 121 |
121 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) | 122 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) |
122 : URLRequestJob(request), | 123 : URLRequestJob(request), |
123 response_info_(NULL), | 124 response_info_(NULL), |
124 response_cookies_save_index_(0), | 125 response_cookies_save_index_(0), |
125 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 126 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
126 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 127 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 128 tls_login_auth_data_(request->GetTLSLoginAuthData()), |
127 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( | 129 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( |
128 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), | 130 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), |
129 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( | 131 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( |
130 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), | 132 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), |
131 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 133 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
132 this, &URLRequestHttpJob::OnStartCompleted)), | 134 this, &URLRequestHttpJob::OnStartCompleted)), |
133 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 135 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( |
134 this, &URLRequestHttpJob::OnReadCompleted)), | 136 this, &URLRequestHttpJob::OnReadCompleted)), |
135 read_in_progress_(false), | 137 read_in_progress_(false), |
136 transaction_(NULL), | 138 transaction_(NULL), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 rv = transaction_->RestartWithAuth(username_, password_, &start_callback_); | 214 rv = transaction_->RestartWithAuth(username_, password_, &start_callback_); |
213 username_.clear(); | 215 username_.clear(); |
214 password_.clear(); | 216 password_.clear(); |
215 } else { | 217 } else { |
216 DCHECK(request_->context()); | 218 DCHECK(request_->context()); |
217 DCHECK(request_->context()->http_transaction_factory()); | 219 DCHECK(request_->context()->http_transaction_factory()); |
218 | 220 |
219 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 221 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
220 &transaction_); | 222 &transaction_); |
221 if (rv == OK) { | 223 if (rv == OK) { |
| 224 if (tls_login_auth_data_->state == AUTH_STATE_HAVE_AUTH) { |
| 225 transaction_->SetTLSLoginAuthData(tls_login_auth_data_); |
| 226 } |
| 227 |
222 rv = transaction_->Start( | 228 rv = transaction_->Start( |
223 &request_info_, &start_callback_, request_->net_log()); | 229 &request_info_, &start_callback_, request_->net_log()); |
224 // Make sure the context is alive for the duration of the | 230 // Make sure the context is alive for the duration of the |
225 // transaction. | 231 // transaction. |
226 context_ = request_->context(); | 232 context_ = request_->context(); |
227 } | 233 } |
228 } | 234 } |
229 | 235 |
230 if (rv == ERR_IO_PENDING) | 236 if (rv == ERR_IO_PENDING) |
231 return; | 237 return; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } else if (ShouldTreatAsCertificateError(result)) { | 566 } else if (ShouldTreatAsCertificateError(result)) { |
561 // We encountered an SSL certificate error. Ask our delegate to decide | 567 // We encountered an SSL certificate error. Ask our delegate to decide |
562 // what we should do. | 568 // what we should do. |
563 // TODO(wtc): also pass ssl_info.cert_status, or just pass the whole | 569 // TODO(wtc): also pass ssl_info.cert_status, or just pass the whole |
564 // ssl_info. | 570 // ssl_info. |
565 request_->delegate()->OnSSLCertificateError( | 571 request_->delegate()->OnSSLCertificateError( |
566 request_, result, transaction_->GetResponseInfo()->ssl_info.cert); | 572 request_, result, transaction_->GetResponseInfo()->ssl_info.cert); |
567 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 573 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
568 request_->delegate()->OnCertificateRequested( | 574 request_->delegate()->OnCertificateRequested( |
569 request_, transaction_->GetResponseInfo()->cert_request_info); | 575 request_, transaction_->GetResponseInfo()->cert_request_info); |
| 576 } else if (result == ERR_TLS_CLIENT_LOGIN_NEEDED || |
| 577 result == ERR_TLS_CLIENT_LOGIN_FAILED) { |
| 578 DCHECK(transaction_->GetResponseInfo()); |
| 579 DCHECK(transaction_->GetResponseInfo()->login_request_info.get()); |
| 580 request_->delegate()->OnTLSLoginRequired( |
| 581 request_, transaction_->GetResponseInfo()->login_request_info); |
570 } else { | 582 } else { |
571 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 583 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
572 } | 584 } |
573 } | 585 } |
574 | 586 |
575 void URLRequestHttpJob::OnReadCompleted(int result) { | 587 void URLRequestHttpJob::OnReadCompleted(int result) { |
576 read_in_progress_ = false; | 588 read_in_progress_ = false; |
577 | 589 |
578 if (result == 0) { | 590 if (result == 0) { |
579 NotifyDone(URLRequestStatus()); | 591 NotifyDone(URLRequestStatus()); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 // OnAuthRequired. | 859 // OnAuthRequired. |
848 // | 860 // |
849 // We have to do this via InvokeLater to avoid "recursing" the consumer. | 861 // We have to do this via InvokeLater to avoid "recursing" the consumer. |
850 // | 862 // |
851 MessageLoop::current()->PostTask( | 863 MessageLoop::current()->PostTask( |
852 FROM_HERE, | 864 FROM_HERE, |
853 method_factory_.NewRunnableMethod( | 865 method_factory_.NewRunnableMethod( |
854 &URLRequestHttpJob::OnStartCompleted, OK)); | 866 &URLRequestHttpJob::OnStartCompleted, OK)); |
855 } | 867 } |
856 | 868 |
| 869 void URLRequestHttpJob::CancelTLSLogin() { |
| 870 // These will be reset in OnStartCompleted. |
| 871 response_info_ = NULL; |
| 872 |
| 873 MessageLoop::current()->PostTask( |
| 874 FROM_HERE, |
| 875 method_factory_.NewRunnableMethod( |
| 876 &URLRequestHttpJob::OnStartCompleted, |
| 877 ERR_ABORTED)); |
| 878 } |
| 879 |
857 void URLRequestHttpJob::ContinueWithCertificate( | 880 void URLRequestHttpJob::ContinueWithCertificate( |
858 X509Certificate* client_cert) { | 881 X509Certificate* client_cert) { |
859 DCHECK(transaction_.get()); | 882 DCHECK(transaction_.get()); |
860 | 883 |
861 DCHECK(!response_info_) << "should not have a response yet"; | 884 DCHECK(!response_info_) << "should not have a response yet"; |
862 | 885 |
863 // No matter what, we want to report our status as IO pending since we will | 886 // No matter what, we want to report our status as IO pending since we will |
864 // be notifying our consumer asynchronously via OnStartCompleted. | 887 // be notifying our consumer asynchronously via OnStartCompleted. |
865 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 888 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
866 | 889 |
867 int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_); | 890 int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_); |
868 if (rv == ERR_IO_PENDING) | 891 if (rv == ERR_IO_PENDING) |
869 return; | 892 return; |
870 | 893 |
871 // The transaction started synchronously, but we need to notify the | 894 // The transaction started synchronously, but we need to notify the |
872 // URLRequest delegate via the message loop. | 895 // URLRequest delegate via the message loop. |
873 MessageLoop::current()->PostTask( | 896 MessageLoop::current()->PostTask( |
874 FROM_HERE, | 897 FROM_HERE, |
875 method_factory_.NewRunnableMethod( | 898 method_factory_.NewRunnableMethod( |
876 &URLRequestHttpJob::OnStartCompleted, rv)); | 899 &URLRequestHttpJob::OnStartCompleted, rv)); |
877 } | 900 } |
878 | 901 |
| 902 void URLRequestHttpJob::ContinueWithTLSLogin() { |
| 903 DCHECK(tls_login_auth_data_->state == AUTH_STATE_HAVE_AUTH); |
| 904 |
| 905 transaction_->SetTLSLoginAuthData(tls_login_auth_data_); |
| 906 |
| 907 DCHECK(transaction_.get()); |
| 908 |
| 909 DCHECK(!response_info_) << "should not have a response yet"; |
| 910 |
| 911 // No matter what, we want to report our status as IO pending since we will |
| 912 // be notifying our consumer asynchronously via OnStartCompleted. |
| 913 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 914 |
| 915 int rv = transaction_->RestartWithTLSLogin(&start_callback_); |
| 916 if (rv == ERR_IO_PENDING) |
| 917 return; |
| 918 |
| 919 // The transaction started synchronously, but we need to notify the |
| 920 // URLRequest delegate via the message loop. |
| 921 MessageLoop::current()->PostTask( |
| 922 FROM_HERE, |
| 923 method_factory_.NewRunnableMethod( |
| 924 &URLRequestHttpJob::OnStartCompleted, rv)); |
| 925 } |
| 926 |
879 void URLRequestHttpJob::ContinueDespiteLastError() { | 927 void URLRequestHttpJob::ContinueDespiteLastError() { |
880 // If the transaction was destroyed, then the job was cancelled. | 928 // If the transaction was destroyed, then the job was cancelled. |
881 if (!transaction_.get()) | 929 if (!transaction_.get()) |
882 return; | 930 return; |
883 | 931 |
884 DCHECK(!response_info_) << "should not have a response yet"; | 932 DCHECK(!response_info_) << "should not have a response yet"; |
885 | 933 |
886 // No matter what, we want to report our status as IO pending since we will | 934 // No matter what, we want to report our status as IO pending since we will |
887 // be notifying our consumer asynchronously via OnStartCompleted. | 935 // be notifying our consumer asynchronously via OnStartCompleted. |
888 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 936 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 // At shutdown time, care is taken to be sure that we don't delete this | 996 // At shutdown time, care is taken to be sure that we don't delete this |
949 // globally useful instance "too soon," so this check is just defensive | 997 // globally useful instance "too soon," so this check is just defensive |
950 // coding to assure that IF the system is shutting down, we don't have any | 998 // coding to assure that IF the system is shutting down, we don't have any |
951 // problem if the manager was deleted ahead of time. | 999 // problem if the manager was deleted ahead of time. |
952 if (manager) // Defensive programming. | 1000 if (manager) // Defensive programming. |
953 manager->FetchDictionary(request_info_.url, sdch_dictionary_url_); | 1001 manager->FetchDictionary(request_info_.url, sdch_dictionary_url_); |
954 } | 1002 } |
955 } | 1003 } |
956 | 1004 |
957 } // namespace net | 1005 } // namespace net |
OLD | NEW |