• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TCPSocketPrivateResource(Connection connection,PP_Instance instance)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 
TCPSocketPrivateResource(Connection connection,PP_Instance instance,int pending_resource_id,const PP_NetAddress_Private & local_addr,const PP_NetAddress_Private & remote_addr)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 
~TCPSocketPrivateResource()30 TCPSocketPrivateResource::~TCPSocketPrivateResource() {
31 }
32 
33 thunk::PPB_TCPSocket_Private_API*
AsPPB_TCPSocket_Private_API()34 TCPSocketPrivateResource::AsPPB_TCPSocket_Private_API() {
35   return this;
36 }
37 
Connect(const char * host,uint16_t port,scoped_refptr<TrackedCallback> callback)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 
ConnectWithNetAddress(const PP_NetAddress_Private * addr,scoped_refptr<TrackedCallback> callback)45 int32_t TCPSocketPrivateResource::ConnectWithNetAddress(
46     const PP_NetAddress_Private* addr,
47     scoped_refptr<TrackedCallback> callback) {
48   return ConnectWithNetAddressImpl(addr, callback);
49 }
50 
GetLocalAddress(PP_NetAddress_Private * local_addr)51 PP_Bool TCPSocketPrivateResource::GetLocalAddress(
52     PP_NetAddress_Private* local_addr) {
53   return GetLocalAddressImpl(local_addr);
54 }
55 
GetRemoteAddress(PP_NetAddress_Private * remote_addr)56 PP_Bool TCPSocketPrivateResource::GetRemoteAddress(
57     PP_NetAddress_Private* remote_addr) {
58   return GetRemoteAddressImpl(remote_addr);
59 }
60 
SSLHandshake(const char * server_name,uint16_t server_port,scoped_refptr<TrackedCallback> callback)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 
GetServerCertificate()68 PP_Resource TCPSocketPrivateResource::GetServerCertificate() {
69   return GetServerCertificateImpl();
70 }
71 
AddChainBuildingCertificate(PP_Resource certificate,PP_Bool trusted)72 PP_Bool TCPSocketPrivateResource::AddChainBuildingCertificate(
73     PP_Resource certificate,
74     PP_Bool trusted) {
75   return AddChainBuildingCertificateImpl(certificate, trusted);
76 }
77 
Read(char * buffer,int32_t bytes_to_read,scoped_refptr<TrackedCallback> callback)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 
Write(const char * buffer,int32_t bytes_to_write,scoped_refptr<TrackedCallback> callback)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 
Disconnect()92 void TCPSocketPrivateResource::Disconnect() {
93   CloseImpl();
94 }
95 
SetOption(PP_TCPSocketOption_Private name,const PP_Var & value,scoped_refptr<TrackedCallback> callback)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 
CreateAcceptedSocket(int,const PP_NetAddress_Private &,const PP_NetAddress_Private &)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