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.
5 #include "ppapi/proxy/tcp_socket_private_resource.h"
7 #include "ppapi/proxy/ppapi_messages.h"
8 #include "ppapi/shared_impl/ppb_tcp_socket_shared.h"
13 TCPSocketPrivateResource::TCPSocketPrivateResource(Connection connection
,
15 : TCPSocketResourceBase(connection
, instance
, TCP_SOCKET_VERSION_PRIVATE
) {
16 SendCreate(BROWSER
, PpapiHostMsg_TCPSocket_CreatePrivate());
19 TCPSocketPrivateResource::TCPSocketPrivateResource(
20 Connection connection
,
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
);
30 TCPSocketPrivateResource::~TCPSocketPrivateResource() {
33 thunk::PPB_TCPSocket_Private_API
*
34 TCPSocketPrivateResource::AsPPB_TCPSocket_Private_API() {
38 int32_t TCPSocketPrivateResource::Connect(
41 scoped_refptr
<TrackedCallback
> callback
) {
42 return ConnectImpl(host
, port
, callback
);
45 int32_t TCPSocketPrivateResource::ConnectWithNetAddress(
46 const PP_NetAddress_Private
* addr
,
47 scoped_refptr
<TrackedCallback
> callback
) {
48 return ConnectWithNetAddressImpl(addr
, callback
);
51 PP_Bool
TCPSocketPrivateResource::GetLocalAddress(
52 PP_NetAddress_Private
* local_addr
) {
53 return GetLocalAddressImpl(local_addr
);
56 PP_Bool
TCPSocketPrivateResource::GetRemoteAddress(
57 PP_NetAddress_Private
* remote_addr
) {
58 return GetRemoteAddressImpl(remote_addr
);
61 int32_t TCPSocketPrivateResource::SSLHandshake(
62 const char* server_name
,
64 scoped_refptr
<TrackedCallback
> callback
) {
65 return SSLHandshakeImpl(server_name
, server_port
, callback
);
68 PP_Resource
TCPSocketPrivateResource::GetServerCertificate() {
69 return GetServerCertificateImpl();
72 PP_Bool
TCPSocketPrivateResource::AddChainBuildingCertificate(
73 PP_Resource certificate
,
75 return AddChainBuildingCertificateImpl(certificate
, trusted
);
78 int32_t TCPSocketPrivateResource::Read(
80 int32_t bytes_to_read
,
81 scoped_refptr
<TrackedCallback
> callback
) {
82 return ReadImpl(buffer
, bytes_to_read
, callback
);
85 int32_t TCPSocketPrivateResource::Write(
87 int32_t bytes_to_write
,
88 scoped_refptr
<TrackedCallback
> callback
) {
89 return WriteImpl(buffer
, bytes_to_write
, callback
);
92 void TCPSocketPrivateResource::Disconnect() {
96 int32_t TCPSocketPrivateResource::SetOption(
97 PP_TCPSocketOption_Private name
,
99 scoped_refptr
<TrackedCallback
> callback
) {
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
,
105 true, // Check connect() state.
109 return PP_ERROR_BADARGUMENT
;
113 PP_Resource
TCPSocketPrivateResource::CreateAcceptedSocket(
114 int /* pending_host_id */,
115 const PP_NetAddress_Private
& /* local_addr */,
116 const PP_NetAddress_Private
& /* remote_addr */) {