| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_ | 5 #ifndef PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_ |
| 6 #define PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_ | 6 #define PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "ppapi/shared_impl/resource.h" | 12 #include "ppapi/shared_impl/resource.h" |
| 12 #include "ppapi/shared_impl/tracked_callback.h" | 13 #include "ppapi/shared_impl/tracked_callback.h" |
| 13 #include "ppapi/thunk/ppb_tcp_socket_private_api.h" | 14 #include "ppapi/thunk/ppb_tcp_socket_private_api.h" |
| 14 | 15 |
| 15 namespace ppapi { | 16 namespace ppapi { |
| 16 | 17 |
| 18 class PPB_X509Certificate_Fields; |
| 19 class PPB_X509Certificate_Private_Shared; |
| 20 |
| 17 // This class provides the shared implementation of a | 21 // This class provides the shared implementation of a |
| 18 // PPB_TCPSocket_Private. The functions that actually send messages | 22 // PPB_TCPSocket_Private. The functions that actually send messages |
| 19 // to browser are implemented differently for the proxied and | 23 // to browser are implemented differently for the proxied and |
| 20 // non-proxied derived classes. | 24 // non-proxied derived classes. |
| 21 class PPAPI_SHARED_EXPORT TCPSocketPrivateImpl | 25 class PPAPI_SHARED_EXPORT TCPSocketPrivateImpl |
| 22 : public thunk::PPB_TCPSocket_Private_API, | 26 : public thunk::PPB_TCPSocket_Private_API, |
| 23 public Resource { | 27 public Resource { |
| 24 public: | 28 public: |
| 25 // C-tor used in Impl case. | 29 // C-tor used in Impl case. |
| 26 TCPSocketPrivateImpl(PP_Instance instance, uint32 socket_id); | 30 TCPSocketPrivateImpl(PP_Instance instance, uint32 socket_id); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 uint16_t port, | 48 uint16_t port, |
| 45 PP_CompletionCallback callback) OVERRIDE; | 49 PP_CompletionCallback callback) OVERRIDE; |
| 46 virtual int32_t ConnectWithNetAddress( | 50 virtual int32_t ConnectWithNetAddress( |
| 47 const PP_NetAddress_Private* addr, | 51 const PP_NetAddress_Private* addr, |
| 48 PP_CompletionCallback callback) OVERRIDE; | 52 PP_CompletionCallback callback) OVERRIDE; |
| 49 virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) OVERRIDE; | 53 virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) OVERRIDE; |
| 50 virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) OVERRIDE; | 54 virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) OVERRIDE; |
| 51 virtual int32_t SSLHandshake(const char* server_name, | 55 virtual int32_t SSLHandshake(const char* server_name, |
| 52 uint16_t server_port, | 56 uint16_t server_port, |
| 53 PP_CompletionCallback callback) OVERRIDE; | 57 PP_CompletionCallback callback) OVERRIDE; |
| 58 virtual PP_Resource GetServerCertificate() OVERRIDE; |
| 59 virtual PP_Bool AddChainBuildingCertificate(PP_Resource certificate, |
| 60 PP_Bool trusted) OVERRIDE; |
| 54 virtual int32_t Read(char* buffer, | 61 virtual int32_t Read(char* buffer, |
| 55 int32_t bytes_to_read, | 62 int32_t bytes_to_read, |
| 56 PP_CompletionCallback callback) OVERRIDE; | 63 PP_CompletionCallback callback) OVERRIDE; |
| 57 virtual int32_t Write(const char* buffer, | 64 virtual int32_t Write(const char* buffer, |
| 58 int32_t bytes_to_write, | 65 int32_t bytes_to_write, |
| 59 PP_CompletionCallback callback) OVERRIDE; | 66 PP_CompletionCallback callback) OVERRIDE; |
| 60 virtual void Disconnect() OVERRIDE; | 67 virtual void Disconnect() OVERRIDE; |
| 61 | 68 |
| 62 // Notifications on operations completion. | 69 // Notifications on operations completion. |
| 63 void OnConnectCompleted(bool succeeded, | 70 void OnConnectCompleted(bool succeeded, |
| 64 const PP_NetAddress_Private& local_addr, | 71 const PP_NetAddress_Private& local_addr, |
| 65 const PP_NetAddress_Private& remote_addr); | 72 const PP_NetAddress_Private& remote_addr); |
| 66 void OnSSLHandshakeCompleted(bool succeeded); | 73 void OnSSLHandshakeCompleted( |
| 74 bool succeeded, |
| 75 const PPB_X509Certificate_Fields& certificate_fields); |
| 67 void OnReadCompleted(bool succeeded, const std::string& data); | 76 void OnReadCompleted(bool succeeded, const std::string& data); |
| 68 void OnWriteCompleted(bool succeeded, int32_t bytes_written); | 77 void OnWriteCompleted(bool succeeded, int32_t bytes_written); |
| 69 | 78 |
| 70 // Send functions that need to be implemented differently for the | 79 // Send functions that need to be implemented differently for the |
| 71 // proxied and non-proxied derived classes. | 80 // proxied and non-proxied derived classes. |
| 72 virtual void SendConnect(const std::string& host, uint16_t port) = 0; | 81 virtual void SendConnect(const std::string& host, uint16_t port) = 0; |
| 73 virtual void SendConnectWithNetAddress(const PP_NetAddress_Private& addr) = 0; | 82 virtual void SendConnectWithNetAddress(const PP_NetAddress_Private& addr) = 0; |
| 74 virtual void SendSSLHandshake(const std::string& server_name, | 83 virtual void SendSSLHandshake( |
| 75 uint16_t server_port) = 0; | 84 const std::string& server_name, |
| 85 uint16_t server_port, |
| 86 const std::vector<std::vector<char> >& trusted_certs, |
| 87 const std::vector<std::vector<char> >& untrusted_certs) = 0; |
| 76 virtual void SendRead(int32_t bytes_to_read) = 0; | 88 virtual void SendRead(int32_t bytes_to_read) = 0; |
| 77 virtual void SendWrite(const std::string& buffer) = 0; | 89 virtual void SendWrite(const std::string& buffer) = 0; |
| 78 virtual void SendDisconnect() = 0; | 90 virtual void SendDisconnect() = 0; |
| 79 | 91 |
| 80 protected: | 92 protected: |
| 81 enum ConnectionState { | 93 enum ConnectionState { |
| 82 // Before a connection is successfully established (including a connect | 94 // Before a connection is successfully established (including a connect |
| 83 // request is pending or a previous connect request failed). | 95 // request is pending or a previous connect request failed). |
| 84 BEFORE_CONNECT, | 96 BEFORE_CONNECT, |
| 85 // A connection has been successfully established (including a request of | 97 // A connection has been successfully established (including a request of |
| 86 // initiating SSL is pending). | 98 // initiating SSL is pending). |
| 87 CONNECTED, | 99 CONNECTED, |
| 88 // An SSL connection has been successfully established. | 100 // An SSL connection has been successfully established. |
| 89 SSL_CONNECTED, | 101 SSL_CONNECTED, |
| 90 // The connection has been ended. | 102 // The connection has been ended. |
| 91 DISCONNECTED | 103 DISCONNECTED |
| 92 }; | 104 }; |
| 93 | 105 |
| 94 void Init(uint32 socket_id); | 106 void Init(uint32 socket_id); |
| 95 bool IsConnected() const; | 107 bool IsConnected() const; |
| 96 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); | 108 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); |
| 97 | 109 |
| 110 ResourceObjectType resource_type_; |
| 111 |
| 98 uint32 socket_id_; | 112 uint32 socket_id_; |
| 99 ConnectionState connection_state_; | 113 ConnectionState connection_state_; |
| 100 | 114 |
| 101 scoped_refptr<TrackedCallback> connect_callback_; | 115 scoped_refptr<TrackedCallback> connect_callback_; |
| 102 scoped_refptr<TrackedCallback> ssl_handshake_callback_; | 116 scoped_refptr<TrackedCallback> ssl_handshake_callback_; |
| 103 scoped_refptr<TrackedCallback> read_callback_; | 117 scoped_refptr<TrackedCallback> read_callback_; |
| 104 scoped_refptr<TrackedCallback> write_callback_; | 118 scoped_refptr<TrackedCallback> write_callback_; |
| 105 | 119 |
| 106 char* read_buffer_; | 120 char* read_buffer_; |
| 107 int32_t bytes_to_read_; | 121 int32_t bytes_to_read_; |
| 108 | 122 |
| 109 PP_NetAddress_Private local_addr_; | 123 PP_NetAddress_Private local_addr_; |
| 110 PP_NetAddress_Private remote_addr_; | 124 PP_NetAddress_Private remote_addr_; |
| 111 | 125 |
| 126 scoped_refptr<PPB_X509Certificate_Private_Shared> server_certificate_; |
| 127 |
| 128 std::vector<std::vector<char> > trusted_certificates_; |
| 129 std::vector<std::vector<char> > untrusted_certificates_; |
| 130 |
| 112 DISALLOW_COPY_AND_ASSIGN(TCPSocketPrivateImpl); | 131 DISALLOW_COPY_AND_ASSIGN(TCPSocketPrivateImpl); |
| 113 }; | 132 }; |
| 114 | 133 |
| 115 } // namespace ppapi | 134 } // namespace ppapi |
| 116 | 135 |
| 117 #endif // PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_ | 136 #endif // PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_ |
| OLD | NEW |