OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_TCP_SOCKET_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_TCP_SOCKET_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "net/base/address_list.h" | |
15 #include "net/base/completion_callback.h" | |
16 #include "ppapi/c/pp_stdint.h" | |
17 | |
18 namespace ppapi { | |
19 class PPB_X509Certificate_Fields; | |
20 } | |
21 | |
22 class PepperMessageFilter; | |
23 struct PP_NetAddress_Private; | |
24 | |
25 namespace net { | |
26 class IOBuffer; | |
27 class SingleRequestHostResolver; | |
28 class StreamSocket; | |
29 class X509Certificate; | |
30 } | |
31 | |
32 // PepperTCPSocket is used by PepperMessageFilter to handle requests from | |
33 // the Pepper TCP socket API (PPB_TCPSocket_Private). | |
34 class PepperTCPSocket { | |
35 public: | |
36 PepperTCPSocket(PepperMessageFilter* manager, | |
37 int32 routing_id, | |
38 uint32 plugin_dispatcher_id, | |
39 uint32 socket_id); | |
40 | |
41 // Used for creation already connected sockets. Takes ownership of | |
42 // |socket|. | |
43 PepperTCPSocket(PepperMessageFilter* manager, | |
44 int32 routing_id, | |
45 uint32 plugin_dispatcher_id, | |
46 uint32 socket_id, | |
47 net::StreamSocket* socket); | |
48 ~PepperTCPSocket(); | |
49 | |
50 int routing_id() { return routing_id_; } | |
51 | |
52 void Connect(const std::string& host, uint16_t port); | |
53 void ConnectWithNetAddress(const PP_NetAddress_Private& net_addr); | |
54 void SSLHandshake( | |
55 const std::string& server_name, | |
56 uint16_t server_port, | |
57 const std::vector<std::vector<char> >& trusted_certs, | |
58 const std::vector<std::vector<char> >& untrusted_certs); | |
59 void Read(int32 bytes_to_read); | |
60 void Write(const std::string& data); | |
61 | |
62 void SendConnectACKError(); | |
63 | |
64 // Extracts the certificate field data from a |net::X509Certificate| into | |
65 // |PPB_X509Certificate_Fields|. | |
66 static bool GetCertificateFields(const net::X509Certificate& cert, | |
67 ppapi::PPB_X509Certificate_Fields* fields); | |
68 // Extracts the certificate field data from the DER representation of a | |
69 // certificate into |PPB_X509Certificate_Fields|. | |
70 static bool GetCertificateFields(const char* der, | |
71 uint32_t length, | |
72 ppapi::PPB_X509Certificate_Fields* fields); | |
73 | |
74 private: | |
75 enum ConnectionState { | |
76 // Before a connection is successfully established (including a previous | |
77 // connect request failed). | |
78 BEFORE_CONNECT, | |
79 // There is a connect request that is pending. | |
80 CONNECT_IN_PROGRESS, | |
81 // A connection has been successfully established. | |
82 CONNECTED, | |
83 // There is an SSL handshake request that is pending. | |
84 SSL_HANDSHAKE_IN_PROGRESS, | |
85 // An SSL connection has been successfully established. | |
86 SSL_CONNECTED, | |
87 // An SSL handshake has failed. | |
88 SSL_HANDSHAKE_FAILED | |
89 }; | |
90 | |
91 void StartConnect(const net::AddressList& addresses); | |
92 | |
93 void SendReadACKError(); | |
94 void SendWriteACKError(); | |
95 void SendSSLHandshakeACK(bool succeeded); | |
96 | |
97 void OnResolveCompleted(int result); | |
98 void OnConnectCompleted(int result); | |
99 void OnSSLHandshakeCompleted(int result); | |
100 void OnReadCompleted(int result); | |
101 void OnWriteCompleted(int result); | |
102 | |
103 bool IsConnected() const; | |
104 | |
105 PepperMessageFilter* manager_; | |
106 int32 routing_id_; | |
107 uint32 plugin_dispatcher_id_; | |
108 uint32 socket_id_; | |
109 | |
110 ConnectionState connection_state_; | |
111 bool end_of_file_reached_; | |
112 | |
113 scoped_ptr<net::SingleRequestHostResolver> resolver_; | |
114 net::AddressList address_list_; | |
115 | |
116 scoped_ptr<net::StreamSocket> socket_; | |
117 | |
118 scoped_refptr<net::IOBuffer> read_buffer_; | |
119 scoped_refptr<net::IOBuffer> write_buffer_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(PepperTCPSocket); | |
122 }; | |
123 | |
124 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_TCP_SOCKET_H_ | |
OLD | NEW |