| Index: chrome/browser/extensions/api/socket/socket_api.cc
|
| diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
|
| index c870171ba80e7fc1b1b31d73517295fb88fafa4a..a3e5998f75bfc5d93ac4c7c01e562424f53d14b8 100644
|
| --- a/chrome/browser/extensions/api/socket/socket_api.cc
|
| +++ b/chrome/browser/extensions/api/socket/socket_api.cc
|
| @@ -9,6 +9,7 @@
|
| #include "chrome/browser/extensions/api/api_resource_controller.h"
|
| #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h"
|
| #include "chrome/browser/extensions/api/socket/socket.h"
|
| +#include "chrome/browser/extensions/api/socket/ssl_socket.h"
|
| #include "chrome/browser/extensions/api/socket/tcp_socket.h"
|
| #include "chrome/browser/extensions/api/socket/udp_socket.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| @@ -29,6 +30,7 @@ const char kResultCodeKey[] = "resultCode";
|
| const char kSocketIdKey[] = "socketId";
|
| const char kTCPOption[] = "tcp";
|
| const char kUDPOption[] = "udp";
|
| +const char kSSLOption[] = "ssl";
|
|
|
| const char kSocketNotFoundError[] = "Socket not found";
|
| const char kSocketTypeInvalidError[] = "Socket type is not supported";
|
| @@ -98,6 +100,8 @@ bool SocketCreateFunction::Prepare() {
|
| socket_type_ = kSocketTypeTCP;
|
| } else if (socket_type_string == kUDPOption) {
|
| socket_type_ = kSocketTypeUDP;
|
| + } else if (socket_type_string == kSSLOption) {
|
| + socket_type_ = kSocketTypeSSL;
|
| } else {
|
| error_ = kSocketTypeInvalidError;
|
| return false;
|
| @@ -113,8 +117,10 @@ void SocketCreateFunction::Work() {
|
| Socket* socket = NULL;
|
| if (socket_type_ == kSocketTypeTCP) {
|
| socket = new TCPSocket(event_notifier_);
|
| - } else if (socket_type_== kSocketTypeUDP) {
|
| + } else if (socket_type_ == kSocketTypeUDP) {
|
| socket = new UDPSocket(event_notifier_);
|
| + } else if (socket_type_ == kSocketTypeSSL) {
|
| + socket = new SSLSocket(event_notifier_);
|
| }
|
| DCHECK(socket);
|
|
|
| @@ -176,6 +182,31 @@ void SocketConnectFunction::OnConnect(int result) {
|
| AsyncWorkCompleted();
|
| }
|
|
|
| +bool SocketHandshakeFunction::Prepare() {
|
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_));
|
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &ssl_hostname_));
|
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &ssl_port_));
|
| + return true;
|
| +}
|
| +
|
| +void SocketHandshakeFunction::AsyncWorkStart() {
|
| + Socket* socket = controller()->GetSocket(socket_id_);
|
| + if (!socket) {
|
| + error_ = kSocketNotFoundError;
|
| + OnCompleted(-1);
|
| + return;
|
| + }
|
| + socket->PerformSSLHandshake(ssl_hostname_,
|
| + ssl_port_,
|
| + base::Bind(&SocketHandshakeFunction::OnCompleted,
|
| + this));
|
| +}
|
| +
|
| +void SocketHandshakeFunction::OnCompleted(int result) {
|
| + result_.reset(Value::CreateIntegerValue(result));
|
| + AsyncWorkCompleted();
|
| +}
|
| +
|
| bool SocketDisconnectFunction::Prepare() {
|
| EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_));
|
| return true;
|
|
|