1 // Copyright 2013 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 #include "ppapi/proxy/tcp_socket_private_resource.h" 6 7 #include "ppapi/proxy/ppapi_messages.h" 8 #include "ppapi/shared_impl/ppb_tcp_socket_shared.h" 9 10 namespace ppapi { 11 namespace proxy { 12 13 TCPSocketPrivateResource::TCPSocketPrivateResource(Connection connection, 14 PP_Instance instance) 15 : TCPSocketResourceBase(connection, instance, TCP_SOCKET_VERSION_PRIVATE) { 16 SendCreate(BROWSER, PpapiHostMsg_TCPSocket_CreatePrivate()); 17 } 18 19 TCPSocketPrivateResource::TCPSocketPrivateResource( 20 Connection connection, 21 PP_Instance instance, 22 int pending_resource_id, 23 const PP_NetAddress_Private& local_addr, 24 const PP_NetAddress_Private& remote_addr) 25 : TCPSocketResourceBase(connection, instance, TCP_SOCKET_VERSION_PRIVATE, 26 local_addr, remote_addr) { 27 AttachToPendingHost(BROWSER, pending_resource_id); 28 } 29 30 TCPSocketPrivateResource::~TCPSocketPrivateResource() { 31 } 32 33 thunk::PPB_TCPSocket_Private_API* 34 TCPSocketPrivateResource::AsPPB_TCPSocket_Private_API() { 35 return this; 36 } 37 38 int32_t TCPSocketPrivateResource::Connect( 39 const char* host, 40 uint16_t port, 41 scoped_refptr<TrackedCallback> callback) { 42 return ConnectImpl(host, port, callback); 43 } 44 45 int32_t TCPSocketPrivateResource::ConnectWithNetAddress( 46 const PP_NetAddress_Private* addr, 47 scoped_refptr<TrackedCallback> callback) { 48 return ConnectWithNetAddressImpl(addr, callback); 49 } 50 51 PP_Bool TCPSocketPrivateResource::GetLocalAddress( 52 PP_NetAddress_Private* local_addr) { 53 return GetLocalAddressImpl(local_addr); 54 } 55 56 PP_Bool TCPSocketPrivateResource::GetRemoteAddress( 57 PP_NetAddress_Private* remote_addr) { 58 return GetRemoteAddressImpl(remote_addr); 59 } 60 61 int32_t TCPSocketPrivateResource::SSLHandshake( 62 const char* server_name, 63 uint16_t server_port, 64 scoped_refptr<TrackedCallback> callback) { 65 return SSLHandshakeImpl(server_name, server_port, callback); 66 } 67 68 PP_Resource TCPSocketPrivateResource::GetServerCertificate() { 69 return GetServerCertificateImpl(); 70 } 71 72 PP_Bool TCPSocketPrivateResource::AddChainBuildingCertificate( 73 PP_Resource certificate, 74 PP_Bool trusted) { 75 return AddChainBuildingCertificateImpl(certificate, trusted); 76 } 77 78 int32_t TCPSocketPrivateResource::Read( 79 char* buffer, 80 int32_t bytes_to_read, 81 scoped_refptr<TrackedCallback> callback) { 82 return ReadImpl(buffer, bytes_to_read, callback); 83 } 84 85 int32_t TCPSocketPrivateResource::Write( 86 const char* buffer, 87 int32_t bytes_to_write, 88 scoped_refptr<TrackedCallback> callback) { 89 return WriteImpl(buffer, bytes_to_write, callback); 90 } 91 92 void TCPSocketPrivateResource::Disconnect() { 93 CloseImpl(); 94 } 95 96 int32_t TCPSocketPrivateResource::SetOption( 97 PP_TCPSocketOption_Private name, 98 const PP_Var& value, 99 scoped_refptr<TrackedCallback> callback) { 100 switch (name) { 101 case PP_TCPSOCKETOPTION_PRIVATE_INVALID: 102 return PP_ERROR_BADARGUMENT; 103 case PP_TCPSOCKETOPTION_PRIVATE_NO_DELAY: 104 return SetOptionImpl(PP_TCPSOCKET_OPTION_NO_DELAY, value, callback); 105 default: 106 NOTREACHED(); 107 return PP_ERROR_BADARGUMENT; 108 } 109 } 110 111 PP_Resource TCPSocketPrivateResource::CreateAcceptedSocket( 112 int /* pending_host_id */, 113 const PP_NetAddress_Private& /* local_addr */, 114 const PP_NetAddress_Private& /* remote_addr */) { 115 NOTREACHED(); 116 return 0; 117 } 118 119 } // namespace proxy 120 } // namespace ppapi 121