| 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/renderer_host/pepper/pepper_tcp_socket.h" | 5 #include "content/browser/renderer_host/pepper/pepper_tcp_socket.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 plugin_dispatcher_id_(plugin_dispatcher_id), | 59 plugin_dispatcher_id_(plugin_dispatcher_id), |
| 60 socket_id_(socket_id), | 60 socket_id_(socket_id), |
| 61 connection_state_(CONNECTED), | 61 connection_state_(CONNECTED), |
| 62 end_of_file_reached_(false), | 62 end_of_file_reached_(false), |
| 63 socket_(socket) { | 63 socket_(socket) { |
| 64 DCHECK(manager); | 64 DCHECK(manager); |
| 65 } | 65 } |
| 66 | 66 |
| 67 PepperTCPSocket::~PepperTCPSocket() { | 67 PepperTCPSocket::~PepperTCPSocket() { |
| 68 // Make sure no further callbacks from socket_. | 68 // Make sure no further callbacks from socket_. |
| 69 if (socket_.get()) | 69 if (socket_) |
| 70 socket_->Disconnect(); | 70 socket_->Disconnect(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void PepperTCPSocket::Connect(const std::string& host, uint16_t port) { | 73 void PepperTCPSocket::Connect(const std::string& host, uint16_t port) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 75 | 75 |
| 76 if (connection_state_ != BEFORE_CONNECT) { | 76 if (connection_state_ != BEFORE_CONNECT) { |
| 77 SendConnectACKError(); | 77 SendConnectACKError(); |
| 78 return; | 78 return; |
| 79 } | 79 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 net::ClientSocketHandle* handle = new net::ClientSocketHandle(); | 134 net::ClientSocketHandle* handle = new net::ClientSocketHandle(); |
| 135 handle->set_socket(socket_.release()); | 135 handle->set_socket(socket_.release()); |
| 136 net::ClientSocketFactory* factory = | 136 net::ClientSocketFactory* factory = |
| 137 net::ClientSocketFactory::GetDefaultFactory(); | 137 net::ClientSocketFactory::GetDefaultFactory(); |
| 138 net::HostPortPair host_port_pair(server_name, server_port); | 138 net::HostPortPair host_port_pair(server_name, server_port); |
| 139 net::SSLClientSocketContext ssl_context; | 139 net::SSLClientSocketContext ssl_context; |
| 140 ssl_context.cert_verifier = manager_->GetCertVerifier(); | 140 ssl_context.cert_verifier = manager_->GetCertVerifier(); |
| 141 socket_.reset(factory->CreateSSLClientSocket( | 141 socket_.reset(factory->CreateSSLClientSocket( |
| 142 handle, host_port_pair, manager_->ssl_config(), ssl_context)); | 142 handle, host_port_pair, manager_->ssl_config(), ssl_context)); |
| 143 if (!socket_.get()) { | 143 if (!socket_) { |
| 144 LOG(WARNING) << "Failed to create an SSL client socket."; | 144 LOG(WARNING) << "Failed to create an SSL client socket."; |
| 145 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED); | 145 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 int result = socket_->Connect( | 149 int result = socket_->Connect( |
| 150 base::Bind(&PepperTCPSocket::OnSSLHandshakeCompleted, | 150 base::Bind(&PepperTCPSocket::OnSSLHandshakeCompleted, |
| 151 base::Unretained(this))); | 151 base::Unretained(this))); |
| 152 if (result != net::ERR_IO_PENDING) | 152 if (result != net::ERR_IO_PENDING) |
| 153 OnSSLHandshakeCompleted(result); | 153 OnSSLHandshakeCompleted(result); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return true; | 284 return true; |
| 285 } | 285 } |
| 286 | 286 |
| 287 // static | 287 // static |
| 288 bool PepperTCPSocket::GetCertificateFields( | 288 bool PepperTCPSocket::GetCertificateFields( |
| 289 const char* der, | 289 const char* der, |
| 290 uint32_t length, | 290 uint32_t length, |
| 291 ppapi::PPB_X509Certificate_Fields* fields) { | 291 ppapi::PPB_X509Certificate_Fields* fields) { |
| 292 scoped_refptr<net::X509Certificate> cert = | 292 scoped_refptr<net::X509Certificate> cert = |
| 293 net::X509Certificate::CreateFromBytes(der, length); | 293 net::X509Certificate::CreateFromBytes(der, length); |
| 294 if (!cert.get()) | 294 if (!cert) |
| 295 return false; | 295 return false; |
| 296 return GetCertificateFields(*cert, fields); | 296 return GetCertificateFields(*cert, fields); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void PepperTCPSocket::SendReadACKError() { | 299 void PepperTCPSocket::SendReadACKError() { |
| 300 manager_->Send(new PpapiMsg_PPBTCPSocket_ReadACK( | 300 manager_->Send(new PpapiMsg_PPBTCPSocket_ReadACK( |
| 301 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string())); | 301 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string())); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void PepperTCPSocket::SendWriteACKError() { | 304 void PepperTCPSocket::SendWriteACKError() { |
| 305 manager_->Send(new PpapiMsg_PPBTCPSocket_WriteACK( | 305 manager_->Send(new PpapiMsg_PPBTCPSocket_WriteACK( |
| 306 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); | 306 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void PepperTCPSocket::SendSSLHandshakeACK(bool succeeded) { | 309 void PepperTCPSocket::SendSSLHandshakeACK(bool succeeded) { |
| 310 ppapi::PPB_X509Certificate_Fields certificate_fields; | 310 ppapi::PPB_X509Certificate_Fields certificate_fields; |
| 311 if (succeeded) { | 311 if (succeeded) { |
| 312 // Our socket is guaranteed to be an SSL socket if we get here. | 312 // Our socket is guaranteed to be an SSL socket if we get here. |
| 313 net::SSLClientSocket* ssl_socket = | 313 net::SSLClientSocket* ssl_socket = |
| 314 static_cast<net::SSLClientSocket*>(socket_.get()); | 314 static_cast<net::SSLClientSocket*>(socket_.get()); |
| 315 net::SSLInfo ssl_info; | 315 net::SSLInfo ssl_info; |
| 316 ssl_socket->GetSSLInfo(&ssl_info); | 316 ssl_socket->GetSSLInfo(&ssl_info); |
| 317 if (ssl_info.cert.get()) | 317 if (ssl_info.cert) |
| 318 GetCertificateFields(*ssl_info.cert, &certificate_fields); | 318 GetCertificateFields(*ssl_info.cert, &certificate_fields); |
| 319 } | 319 } |
| 320 manager_->Send(new PpapiMsg_PPBTCPSocket_SSLHandshakeACK( | 320 manager_->Send(new PpapiMsg_PPBTCPSocket_SSLHandshakeACK( |
| 321 routing_id_, | 321 routing_id_, |
| 322 plugin_dispatcher_id_, | 322 plugin_dispatcher_id_, |
| 323 socket_id_, | 323 socket_id_, |
| 324 succeeded, | 324 succeeded, |
| 325 certificate_fields)); | 325 certificate_fields)); |
| 326 } | 326 } |
| 327 | 327 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 DCHECK_GT(write_buffer_->BytesRemaining(), 0); | 444 DCHECK_GT(write_buffer_->BytesRemaining(), 0); |
| 445 | 445 |
| 446 int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(), | 446 int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(), |
| 447 base::Bind(&PepperTCPSocket::OnWriteCompleted, | 447 base::Bind(&PepperTCPSocket::OnWriteCompleted, |
| 448 base::Unretained(this))); | 448 base::Unretained(this))); |
| 449 if (result != net::ERR_IO_PENDING) | 449 if (result != net::ERR_IO_PENDING) |
| 450 OnWriteCompleted(result); | 450 OnWriteCompleted(result); |
| 451 } | 451 } |
| 452 | 452 |
| 453 } // namespace content | 453 } // namespace content |
| OLD | NEW |