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.
5 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
7 #include "webkit/plugins/ppapi/host_globals.h"
8 #include "webkit/plugins/ppapi/plugin_delegate.h"
9 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
10 #include "webkit/plugins/ppapi/resource_helper.h"
15 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl(
16 PP_Instance instance
, uint32 socket_id
)
17 : ::ppapi::TCPSocketPrivateImpl(instance
, socket_id
) {
20 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() {
24 PP_Resource
PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance
) {
25 PluginDelegate
* plugin_delegate
= GetPluginDelegate(instance
);
29 uint32 socket_id
= plugin_delegate
->TCPSocketCreate();
33 return (new PPB_TCPSocket_Private_Impl(instance
, socket_id
))->GetReference();
36 PP_Resource
PPB_TCPSocket_Private_Impl::CreateConnectedSocket(
39 const PP_NetAddress_Private
& local_addr
,
40 const PP_NetAddress_Private
& remote_addr
) {
41 PluginDelegate
* plugin_delegate
= GetPluginDelegate(instance
);
45 PPB_TCPSocket_Private_Impl
* socket
=
46 new PPB_TCPSocket_Private_Impl(instance
, socket_id
);
48 socket
->connection_state_
= PPB_TCPSocket_Private_Impl::CONNECTED
;
49 socket
->local_addr_
= local_addr
;
50 socket
->remote_addr_
= remote_addr
;
52 plugin_delegate
->RegisterTCPSocket(socket
, socket_id
);
54 return socket
->GetReference();
57 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string
& host
,
59 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
63 plugin_delegate
->TCPSocketConnect(this, socket_id_
, host
, port
);
66 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress(
67 const PP_NetAddress_Private
& addr
) {
68 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
72 plugin_delegate
->TCPSocketConnectWithNetAddress(this, socket_id_
, addr
);
75 void PPB_TCPSocket_Private_Impl::SendSSLHandshake(
76 const std::string
& server_name
,
78 const std::vector
<std::vector
<char> >& trusted_certs
,
79 const std::vector
<std::vector
<char> >& untrusted_certs
) {
80 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
84 plugin_delegate
->TCPSocketSSLHandshake(socket_id_
, server_name
, server_port
,
85 trusted_certs
, untrusted_certs
);
88 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read
) {
89 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
93 plugin_delegate
->TCPSocketRead(socket_id_
, bytes_to_read
);
97 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string
& buffer
) {
98 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
102 plugin_delegate
->TCPSocketWrite(socket_id_
, buffer
);
105 void PPB_TCPSocket_Private_Impl::SendDisconnect() {
106 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
107 if (!plugin_delegate
)
110 plugin_delegate
->TCPSocketDisconnect(socket_id_
);
113 void PPB_TCPSocket_Private_Impl::SendSetBoolOption(
114 PP_TCPSocketOption_Private name
,
116 PluginDelegate
* plugin_delegate
= ResourceHelper::GetPluginDelegate(this);
117 if (!plugin_delegate
)
120 plugin_delegate
->TCPSocketSetBoolOption(socket_id_
, name
, value
);
123 PluginDelegate
* PPB_TCPSocket_Private_Impl::GetPluginDelegate(
124 PP_Instance instance
) {
125 PluginInstance
* plugin_instance
= HostGlobals::Get()->GetInstance(instance
);
126 if (!plugin_instance
)
128 return plugin_instance
->delegate();
132 } // namespace webkit