| 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
| 6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
| 7 | 7 |
| 8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "net/dns/host_resolver.h" | 26 #include "net/dns/host_resolver.h" |
| 27 #include "net/http/http_auth_controller.h" | 27 #include "net/http/http_auth_controller.h" |
| 28 #include "net/http/http_network_session.h" | 28 #include "net/http/http_network_session.h" |
| 29 #include "net/http/http_request_headers.h" | 29 #include "net/http/http_request_headers.h" |
| 30 #include "net/http/http_request_info.h" | 30 #include "net/http/http_request_info.h" |
| 31 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_stream_factory.h" | 32 #include "net/http/http_stream_factory.h" |
| 33 #include "net/http/http_transaction_factory.h" | 33 #include "net/http/http_transaction_factory.h" |
| 34 #include "net/http/http_util.h" | 34 #include "net/http/http_util.h" |
| 35 #include "net/socket/client_socket_factory.h" | 35 #include "net/socket/client_socket_factory.h" |
| 36 #include "net/socket/client_socket_handle.h" |
| 36 #include "net/socket/socks5_client_socket.h" | 37 #include "net/socket/socks5_client_socket.h" |
| 37 #include "net/socket/socks_client_socket.h" | 38 #include "net/socket/socks_client_socket.h" |
| 38 #include "net/socket/ssl_client_socket.h" | 39 #include "net/socket/ssl_client_socket.h" |
| 39 #include "net/socket/tcp_client_socket.h" | 40 #include "net/socket/tcp_client_socket.h" |
| 40 #include "net/socket_stream/socket_stream_metrics.h" | 41 #include "net/socket_stream/socket_stream_metrics.h" |
| 41 #include "net/ssl/ssl_cert_request_info.h" | 42 #include "net/ssl/ssl_cert_request_info.h" |
| 42 #include "net/ssl/ssl_info.h" | 43 #include "net/ssl/ssl_info.h" |
| 43 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
| 44 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
| 45 | 46 |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 } | 947 } |
| 947 next_state_ = STATE_CLOSE; | 948 next_state_ = STATE_CLOSE; |
| 948 return ERR_TUNNEL_CONNECTION_FAILED; | 949 return ERR_TUNNEL_CONNECTION_FAILED; |
| 949 } | 950 } |
| 950 | 951 |
| 951 int SocketStream::DoSOCKSConnect() { | 952 int SocketStream::DoSOCKSConnect() { |
| 952 DCHECK_EQ(kSOCKSProxy, proxy_mode_); | 953 DCHECK_EQ(kSOCKSProxy, proxy_mode_); |
| 953 | 954 |
| 954 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 955 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 955 | 956 |
| 956 StreamSocket* s = socket_.release(); | |
| 957 HostResolver::RequestInfo req_info(HostPortPair::FromURL(url_)); | 957 HostResolver::RequestInfo req_info(HostPortPair::FromURL(url_)); |
| 958 | 958 |
| 959 DCHECK(!proxy_info_.is_empty()); | 959 DCHECK(!proxy_info_.is_empty()); |
| 960 if (proxy_info_.proxy_server().scheme() == ProxyServer::SCHEME_SOCKS5) | 960 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 961 s = new SOCKS5ClientSocket(s, req_info); | 961 connection->set_socket(socket_.release()); |
| 962 else | 962 if (proxy_info_.proxy_server().scheme() == ProxyServer::SCHEME_SOCKS5) { |
| 963 s = new SOCKSClientSocket(s, req_info, context_->host_resolver()); | 963 socket_.reset(new SOCKS5ClientSocket(connection.release(), req_info)); |
| 964 socket_.reset(s); | 964 } else { |
| 965 socket_.reset(new SOCKSClientSocket( |
| 966 connection.release(), req_info, context_->host_resolver())); |
| 967 } |
| 965 metrics_->OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); | 968 metrics_->OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); |
| 966 return socket_->Connect(io_callback_); | 969 return socket_->Connect(io_callback_); |
| 967 } | 970 } |
| 968 | 971 |
| 969 int SocketStream::DoSOCKSConnectComplete(int result) { | 972 int SocketStream::DoSOCKSConnectComplete(int result) { |
| 970 DCHECK_EQ(kSOCKSProxy, proxy_mode_); | 973 DCHECK_EQ(kSOCKSProxy, proxy_mode_); |
| 971 | 974 |
| 972 if (result == OK) { | 975 if (result == OK) { |
| 973 if (is_secure()) | 976 if (is_secure()) |
| 974 next_state_ = STATE_SSL_CONNECT; | 977 next_state_ = STATE_SSL_CONNECT; |
| 975 else | 978 else |
| 976 result = DidEstablishConnection(); | 979 result = DidEstablishConnection(); |
| 977 } else { | 980 } else { |
| 978 next_state_ = STATE_CLOSE; | 981 next_state_ = STATE_CLOSE; |
| 979 } | 982 } |
| 980 return result; | 983 return result; |
| 981 } | 984 } |
| 982 | 985 |
| 983 int SocketStream::DoSecureProxyConnect() { | 986 int SocketStream::DoSecureProxyConnect() { |
| 984 DCHECK(factory_); | 987 DCHECK(factory_); |
| 985 SSLClientSocketContext ssl_context; | 988 SSLClientSocketContext ssl_context; |
| 986 ssl_context.cert_verifier = context_->cert_verifier(); | 989 ssl_context.cert_verifier = context_->cert_verifier(); |
| 987 ssl_context.transport_security_state = context_->transport_security_state(); | 990 ssl_context.transport_security_state = context_->transport_security_state(); |
| 988 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); | 991 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); |
| 992 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 993 connection->set_socket(socket_.release()); |
| 989 socket_.reset(factory_->CreateSSLClientSocket( | 994 socket_.reset(factory_->CreateSSLClientSocket( |
| 990 socket_.release(), | 995 connection.release(), |
| 991 proxy_info_.proxy_server().host_port_pair(), | 996 proxy_info_.proxy_server().host_port_pair(), |
| 992 proxy_ssl_config_, | 997 proxy_ssl_config_, |
| 993 ssl_context)); | 998 ssl_context)); |
| 994 next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; | 999 next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; |
| 995 metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); | 1000 metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); |
| 996 return socket_->Connect(io_callback_); | 1001 return socket_->Connect(io_callback_); |
| 997 } | 1002 } |
| 998 | 1003 |
| 999 int SocketStream::DoSecureProxyConnectComplete(int result) { | 1004 int SocketStream::DoSecureProxyConnectComplete(int result) { |
| 1000 DCHECK_EQ(STATE_NONE, next_state_); | 1005 DCHECK_EQ(STATE_NONE, next_state_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 } | 1038 } |
| 1034 return result; | 1039 return result; |
| 1035 } | 1040 } |
| 1036 | 1041 |
| 1037 int SocketStream::DoSSLConnect() { | 1042 int SocketStream::DoSSLConnect() { |
| 1038 DCHECK(factory_); | 1043 DCHECK(factory_); |
| 1039 SSLClientSocketContext ssl_context; | 1044 SSLClientSocketContext ssl_context; |
| 1040 ssl_context.cert_verifier = context_->cert_verifier(); | 1045 ssl_context.cert_verifier = context_->cert_verifier(); |
| 1041 ssl_context.transport_security_state = context_->transport_security_state(); | 1046 ssl_context.transport_security_state = context_->transport_security_state(); |
| 1042 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); | 1047 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); |
| 1043 socket_.reset(factory_->CreateSSLClientSocket(socket_.release(), | 1048 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 1049 connection->set_socket(socket_.release()); |
| 1050 socket_.reset(factory_->CreateSSLClientSocket(connection.release(), |
| 1044 HostPortPair::FromURL(url_), | 1051 HostPortPair::FromURL(url_), |
| 1045 server_ssl_config_, | 1052 server_ssl_config_, |
| 1046 ssl_context)); | 1053 ssl_context)); |
| 1047 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 1054 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 1048 metrics_->OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); | 1055 metrics_->OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); |
| 1049 return socket_->Connect(io_callback_); | 1056 return socket_->Connect(io_callback_); |
| 1050 } | 1057 } |
| 1051 | 1058 |
| 1052 int SocketStream::DoSSLConnectComplete(int result) { | 1059 int SocketStream::DoSSLConnectComplete(int result) { |
| 1053 DCHECK_EQ(STATE_NONE, next_state_); | 1060 DCHECK_EQ(STATE_NONE, next_state_); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 context_->transport_security_state()->GetDomainState(url_.host(), | 1317 context_->transport_security_state()->GetDomainState(url_.host(), |
| 1311 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), | 1318 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), |
| 1312 &domain_state) && | 1319 &domain_state) && |
| 1313 domain_state.ShouldSSLErrorsBeFatal(); | 1320 domain_state.ShouldSSLErrorsBeFatal(); |
| 1314 | 1321 |
| 1315 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 1322 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
| 1316 return ERR_IO_PENDING; | 1323 return ERR_IO_PENDING; |
| 1317 } | 1324 } |
| 1318 | 1325 |
| 1319 } // namespace net | 1326 } // namespace net |
| OLD | NEW |