Chromium Code Reviews| 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( | |
| 966 new SOCKSClientSocket( | |
| 967 connection.release(), req_info, context_->host_resolver())); | |
|
Ryan Sleevi
2013/08/13 20:26:13
seems like this could be
socket_.reset(new SOCKSC
akalin
2013/08/13 20:51:28
Done.
| |
| 968 } | |
| 965 metrics_->OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); | 969 metrics_->OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); |
| 966 return socket_->Connect(io_callback_); | 970 return socket_->Connect(io_callback_); |
| 967 } | 971 } |
| 968 | 972 |
| 969 int SocketStream::DoSOCKSConnectComplete(int result) { | 973 int SocketStream::DoSOCKSConnectComplete(int result) { |
| 970 DCHECK_EQ(kSOCKSProxy, proxy_mode_); | 974 DCHECK_EQ(kSOCKSProxy, proxy_mode_); |
| 971 | 975 |
| 972 if (result == OK) { | 976 if (result == OK) { |
| 973 if (is_secure()) | 977 if (is_secure()) |
| 974 next_state_ = STATE_SSL_CONNECT; | 978 next_state_ = STATE_SSL_CONNECT; |
| 975 else | 979 else |
| 976 result = DidEstablishConnection(); | 980 result = DidEstablishConnection(); |
| 977 } else { | 981 } else { |
| 978 next_state_ = STATE_CLOSE; | 982 next_state_ = STATE_CLOSE; |
| 979 } | 983 } |
| 980 return result; | 984 return result; |
| 981 } | 985 } |
| 982 | 986 |
| 983 int SocketStream::DoSecureProxyConnect() { | 987 int SocketStream::DoSecureProxyConnect() { |
| 984 DCHECK(factory_); | 988 DCHECK(factory_); |
| 985 SSLClientSocketContext ssl_context; | 989 SSLClientSocketContext ssl_context; |
| 986 ssl_context.cert_verifier = context_->cert_verifier(); | 990 ssl_context.cert_verifier = context_->cert_verifier(); |
| 987 ssl_context.transport_security_state = context_->transport_security_state(); | 991 ssl_context.transport_security_state = context_->transport_security_state(); |
| 988 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); | 992 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); |
| 993 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
| 994 connection->set_socket(socket_.release()); | |
| 989 socket_.reset(factory_->CreateSSLClientSocket( | 995 socket_.reset(factory_->CreateSSLClientSocket( |
| 990 socket_.release(), | 996 connection.release(), |
| 991 proxy_info_.proxy_server().host_port_pair(), | 997 proxy_info_.proxy_server().host_port_pair(), |
| 992 proxy_ssl_config_, | 998 proxy_ssl_config_, |
| 993 ssl_context)); | 999 ssl_context)); |
| 994 next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; | 1000 next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; |
| 995 metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); | 1001 metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); |
| 996 return socket_->Connect(io_callback_); | 1002 return socket_->Connect(io_callback_); |
| 997 } | 1003 } |
| 998 | 1004 |
| 999 int SocketStream::DoSecureProxyConnectComplete(int result) { | 1005 int SocketStream::DoSecureProxyConnectComplete(int result) { |
| 1000 DCHECK_EQ(STATE_NONE, next_state_); | 1006 DCHECK_EQ(STATE_NONE, next_state_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 } | 1039 } |
| 1034 return result; | 1040 return result; |
| 1035 } | 1041 } |
| 1036 | 1042 |
| 1037 int SocketStream::DoSSLConnect() { | 1043 int SocketStream::DoSSLConnect() { |
| 1038 DCHECK(factory_); | 1044 DCHECK(factory_); |
| 1039 SSLClientSocketContext ssl_context; | 1045 SSLClientSocketContext ssl_context; |
| 1040 ssl_context.cert_verifier = context_->cert_verifier(); | 1046 ssl_context.cert_verifier = context_->cert_verifier(); |
| 1041 ssl_context.transport_security_state = context_->transport_security_state(); | 1047 ssl_context.transport_security_state = context_->transport_security_state(); |
| 1042 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); | 1048 ssl_context.server_bound_cert_service = context_->server_bound_cert_service(); |
| 1043 socket_.reset(factory_->CreateSSLClientSocket(socket_.release(), | 1049 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 1050 connection->set_socket(socket_.release()); | |
| 1051 socket_.reset(factory_->CreateSSLClientSocket(connection.release(), | |
| 1044 HostPortPair::FromURL(url_), | 1052 HostPortPair::FromURL(url_), |
| 1045 server_ssl_config_, | 1053 server_ssl_config_, |
| 1046 ssl_context)); | 1054 ssl_context)); |
| 1047 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 1055 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 1048 metrics_->OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); | 1056 metrics_->OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); |
| 1049 return socket_->Connect(io_callback_); | 1057 return socket_->Connect(io_callback_); |
| 1050 } | 1058 } |
| 1051 | 1059 |
| 1052 int SocketStream::DoSSLConnectComplete(int result) { | 1060 int SocketStream::DoSSLConnectComplete(int result) { |
| 1053 DCHECK_EQ(STATE_NONE, next_state_); | 1061 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(), | 1318 context_->transport_security_state()->GetDomainState(url_.host(), |
| 1311 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), | 1319 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), |
| 1312 &domain_state) && | 1320 &domain_state) && |
| 1313 domain_state.ShouldSSLErrorsBeFatal(); | 1321 domain_state.ShouldSSLErrorsBeFatal(); |
| 1314 | 1322 |
| 1315 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 1323 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
| 1316 return ERR_IO_PENDING; | 1324 return ERR_IO_PENDING; |
| 1317 } | 1325 } |
| 1318 | 1326 |
| 1319 } // namespace net | 1327 } // namespace net |
| OLD | NEW |