Index: chrome/browser/extensions/api/socket/tls_socket.h |
diff --git a/chrome/browser/extensions/api/socket/tls_socket.h b/chrome/browser/extensions/api/socket/tls_socket.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8661f02130c5c3e989babc677d2955116253550b |
--- /dev/null |
+++ b/chrome/browser/extensions/api/socket/tls_socket.h |
@@ -0,0 +1,99 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ |
+ |
+#include <string> |
+ |
+#include "chrome/browser/extensions/api/socket/socket.h" |
+#include "chrome/browser/extensions/api/socket/socket_api.h" |
+#include "chrome/browser/extensions/api/socket/tcp_socket.h" |
+ |
+namespace net { |
+class Socket; |
+} |
+ |
+namespace extensions { |
+typedef base::Callback<void(Socket*, int)> SecureCallback; |
rpaquay
2013/12/09 23:02:03
Should "Socket*" be "TLSSocket*"?
lally
2013/12/12 02:31:39
Done.
|
+ |
+// TLS Sockets from the chrome.socket API. A regular TCPSocket is converted |
+// to a TLSSocket via chrome.socket.secure() or chrome.sockets.tcp.secure(). |
+// The inheritance here is for interface API compatibility, not for |
+// implementation that comes with it. We override methods to prevent |
+// behavioral leakage from the underlying implementation. |
+class TLSSocket : public ResumableTCPSocket { |
+ public: |
+ TLSSocket(net::StreamSocket* tls_socket, |
+ const std::string& owner_extension_id); |
+ |
+ virtual ~TLSSocket(); |
+ |
+ // Most of these methods either fail or forward the method call on to the |
+ // inner net::StreamSocket. The remaining few do actual TLS work. |
+ |
+ // Fails. |
+ virtual void Connect(const std::string& address, |
+ int port, |
+ const CompletionCallback& callback) OVERRIDE; |
+ // Forwards. |
+ virtual void Disconnect() OVERRIDE; |
+ |
+ // The |callback| will be called with the number of bytes read into the |
+ // buffer, or a negative number if an error occurred. Does TLS work. |
+ virtual void Read(int count, |
+ const ReadCompletionCallback& callback) OVERRIDE; |
+ |
+ // Fails. This should have been called on the TCP socket before secure() was |
+ // invoked. |
+ virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; |
+ |
+ // Fails. This should have been called on the TCP socket before secure() was |
+ // invoked. |
+ virtual bool SetNoDelay(bool no_delay) OVERRIDE; |
+ |
+ // Fails. TLSSocket is only a client. |
+ virtual int Listen(const std::string& address, int port, int backlog, |
+ std::string* error_msg) OVERRIDE; |
+ // Fails. TLSSocket is only a client. |
+ virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE; |
+ |
+ // Forwards. |
+ virtual bool IsConnected() OVERRIDE; |
+ |
+ // Forwards. |
+ virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; |
+ // Forwards. |
+ virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; |
+ |
+ // Returns TYPE_TLS. |
+ virtual SocketType GetSocketType() const OVERRIDE; |
+ |
+ // Convert the given |socket| to a TLS socket. Works only for TCP sockets. |
+ // Must be invoked in the IO thread. Returns an error string upon error |
+ // (which also mutates |*result|), or NULL if the final result will come |
+ // from an invocation to |callback|. Note: |callback| may get invoked |
+ // before SecureTCPSocket returns. |
+ static const char* SecureTCPSocket( |
+ Socket* socket, |
+ Profile* profile, |
+ net::URLRequestContextGetter* url_request_getter, |
+ const std::string& extension_id, |
+ api::socket::SecureOptions* options, |
+ SecureCallback callback, |
+ base::Value** result); |
+ |
+ private: |
+ virtual int WriteImpl(net::IOBuffer* io_buffer, int io_buffer_size, |
+ const net::CompletionCallback& callback) OVERRIDE; |
+ void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); |
+ |
+ scoped_ptr<net::StreamSocket> tls_socket_; |
+ |
+ ReadCompletionCallback read_callback_; |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ |