| Index: chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
|
| diff --git a/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc b/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
|
| index fbf02dc0a1e0561a3a3e7ed3c3f0399a2e7e4974..17304e65879528e811ca7e47ee568b292c0c194c 100644
|
| --- a/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
|
| +++ b/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
|
| @@ -5,10 +5,12 @@
|
| #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
|
|
|
| #include "chrome/browser/extensions/api/socket/tcp_socket.h"
|
| +#include "chrome/browser/extensions/api/socket/tls_socket.h"
|
| #include "chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h"
|
| #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h"
|
| #include "content/public/common/socket_permission_request.h"
|
| #include "net/base/net_errors.h"
|
| +#include "net/url_request/url_request_context_getter.h"
|
|
|
| using extensions::ResumableTCPSocket;
|
| using extensions::api::sockets_tcp::SocketInfo;
|
| @@ -18,6 +20,9 @@ namespace {
|
|
|
| const char kSocketNotFoundError[] = "Socket not found";
|
| const char kPermissionError[] = "Does not have permission";
|
| +const char kInvalidSocketStateError[] =
|
| + "Socket must be a connected client TCP socket.";
|
| +const char kSocketNotConnectedError[] = "Socket not connected";
|
|
|
| linked_ptr<SocketInfo> CreateSocketInfo(int socket_id,
|
| ResumableTCPSocket* socket) {
|
| @@ -259,6 +264,8 @@ void SocketsTcpConnectFunction::AsyncWorkStart() {
|
| return;
|
| }
|
|
|
| + socket->set_hostname(params_->peer_address);
|
| +
|
| content::SocketPermissionRequest param(
|
| SocketPermissionRequest::TCP_CONNECT,
|
| params_->peer_address,
|
| @@ -440,5 +447,82 @@ void SocketsTcpGetSocketsFunction::Work() {
|
| results_ = sockets_tcp::GetSockets::Results::Create(socket_infos);
|
| }
|
|
|
| +SocketsTcpSecureFunction::SocketsTcpSecureFunction() {}
|
| +SocketsTcpSecureFunction::~SocketsTcpSecureFunction() {}
|
| +
|
| +bool SocketsTcpSecureFunction::Prepare() {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| + params_ = api::socket::Secure::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| + url_request_getter_ = GetProfile()->GetRequestContext();
|
| + return true;
|
| +}
|
| +
|
| +// Override the regular implementation, which would call AsyncWorkCompleted
|
| +// immediately after Work().
|
| +void SocketsTcpSecureFunction::AsyncWorkStart() {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
| +
|
| + ResumableTCPSocket* socket(GetTcpSocket(params_->socket_id));
|
| + if (!socket) {
|
| + SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT));
|
| + error_ = kSocketNotFoundError;
|
| + AsyncWorkCompleted();
|
| + return;
|
| + }
|
| +
|
| + paused_ = socket->paused();
|
| + persistent_ = socket->persistent();
|
| +
|
| + // Make sure it's a connected TCP client socket. Error out if it's already
|
| + // secure()'d.
|
| + if (socket->GetSocketType() == Socket::TYPE_TLS ||
|
| + socket->ClientStream() == NULL) {
|
| + SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT));
|
| + error_ = kInvalidSocketStateError;
|
| + AsyncWorkCompleted();
|
| + return;
|
| + }
|
| +
|
| + if (!socket->IsConnected()) {
|
| + SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT));
|
| + error_ = kSocketNotConnectedError;
|
| + AsyncWorkCompleted();
|
| + return;
|
| + }
|
| +
|
| + Profile* profile = GetProfile();
|
| + DCHECK(profile);
|
| +
|
| + scoped_refptr<net::SSLConfigService> config_service(
|
| + profile->GetSSLConfigService());
|
| +
|
| + TLSSocket::UpgradeSocketToTLS(
|
| + socket,
|
| + config_service,
|
| + url_request_getter_,
|
| + extension_id(),
|
| + params_->options.get(),
|
| + base::Bind(&SocketsTcpSecureFunction::TlsConnectDone, this));
|
| +}
|
| +
|
| +void SocketsTcpSecureFunction::TlsConnectDone(scoped_ptr<TLSSocket> socket,
|
| + int result) {
|
| + // |socket| can only be non-null if |result| == net::OK.
|
| + DCHECK(result == net::OK || socket == NULL);
|
| +
|
| + if (socket && result == net::OK) {
|
| + socket->set_persistent(persistent_);
|
| + socket->set_paused(paused_);
|
| + ReplaceSocket(params_->socket_id, socket.release());
|
| + } else {
|
| + RemoveSocket(params_->socket_id);
|
| + error_ = net::ErrorToString(result);
|
| + }
|
| +
|
| + results_ = api::sockets_tcp::Secure::Results::Create(result);
|
| + AsyncWorkCompleted();
|
| +}
|
| +
|
| } // namespace api
|
| } // namespace extensions
|
|
|