OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" | |
6 | |
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" | |
11 | |
12 namespace webkit { | |
13 namespace ppapi { | |
14 | |
15 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( | |
16 PP_Instance instance, uint32 socket_id) | |
17 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) { | |
18 } | |
19 | |
20 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { | |
21 Disconnect(); | |
22 } | |
23 | |
24 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { | |
25 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); | |
26 if (!plugin_instance) | |
27 return 0; | |
28 | |
29 PluginDelegate* plugin_delegate = plugin_instance->delegate(); | |
30 uint32 socket_id = plugin_delegate->TCPSocketCreate(); | |
31 if (!socket_id) | |
32 return 0; | |
33 | |
34 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); | |
35 } | |
36 | |
37 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, | |
38 uint16_t port) { | |
39 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
40 if (!plugin_delegate) | |
41 return; | |
42 | |
43 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port); | |
44 } | |
45 | |
46 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( | |
47 const PP_NetAddress_Private& addr) { | |
48 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
49 if (!plugin_delegate) | |
50 return; | |
51 | |
52 plugin_delegate->TCPSocketConnectWithNetAddress(this, socket_id_, addr); | |
53 } | |
54 | |
55 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( | |
56 const std::string& server_name, | |
57 uint16_t server_port) { | |
58 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
59 if (!plugin_delegate) | |
60 return; | |
61 | |
62 plugin_delegate->TCPSocketSSLHandshake(socket_id_, server_name, server_port); | |
63 } | |
64 | |
65 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { | |
66 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
67 if (!plugin_delegate) | |
68 return; | |
69 | |
70 plugin_delegate->TCPSocketRead(socket_id_, bytes_to_read); | |
71 } | |
72 | |
73 | |
74 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { | |
75 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
76 if (!plugin_delegate) | |
77 return; | |
78 | |
79 plugin_delegate->TCPSocketWrite(socket_id_, buffer); | |
80 } | |
81 | |
82 void PPB_TCPSocket_Private_Impl::SendDisconnect() { | |
83 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
84 if (!plugin_delegate) | |
85 return; | |
86 | |
87 plugin_delegate->TCPSocketDisconnect(socket_id_); | |
88 } | |
89 | |
90 } // namespace ppapi | |
91 } // namespace webkit | |
OLD | NEW |