| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" | |
| 6 | |
| 7 #include "ppapi/shared_impl/socket_option_data.h" | |
| 8 #include "webkit/plugins/ppapi/host_globals.h" | |
| 9 #include "webkit/plugins/ppapi/plugin_delegate.h" | |
| 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" | |
| 11 #include "webkit/plugins/ppapi/resource_helper.h" | |
| 12 | |
| 13 namespace webkit { | |
| 14 namespace ppapi { | |
| 15 | |
| 16 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( | |
| 17 PP_Instance instance, uint32 socket_id) | |
| 18 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) { | |
| 19 } | |
| 20 | |
| 21 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { | |
| 22 Disconnect(); | |
| 23 } | |
| 24 | |
| 25 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { | |
| 26 PluginDelegate* plugin_delegate = GetPluginDelegate(instance); | |
| 27 if (!plugin_delegate) | |
| 28 return 0; | |
| 29 | |
| 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 PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket( | |
| 38 PP_Instance instance, | |
| 39 uint32 socket_id, | |
| 40 const PP_NetAddress_Private& local_addr, | |
| 41 const PP_NetAddress_Private& remote_addr) { | |
| 42 PluginDelegate* plugin_delegate = GetPluginDelegate(instance); | |
| 43 if (!plugin_delegate) | |
| 44 return 0; | |
| 45 | |
| 46 PPB_TCPSocket_Private_Impl* socket = | |
| 47 new PPB_TCPSocket_Private_Impl(instance, socket_id); | |
| 48 | |
| 49 socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED; | |
| 50 socket->local_addr_ = local_addr; | |
| 51 socket->remote_addr_ = remote_addr; | |
| 52 | |
| 53 plugin_delegate->RegisterTCPSocket(socket, socket_id); | |
| 54 | |
| 55 return socket->GetReference(); | |
| 56 } | |
| 57 | |
| 58 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, | |
| 59 uint16_t port) { | |
| 60 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 61 if (!plugin_delegate) | |
| 62 return; | |
| 63 | |
| 64 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port); | |
| 65 } | |
| 66 | |
| 67 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( | |
| 68 const PP_NetAddress_Private& addr) { | |
| 69 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 70 if (!plugin_delegate) | |
| 71 return; | |
| 72 | |
| 73 plugin_delegate->TCPSocketConnectWithNetAddress(this, socket_id_, addr); | |
| 74 } | |
| 75 | |
| 76 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( | |
| 77 const std::string& server_name, | |
| 78 uint16_t server_port, | |
| 79 const std::vector<std::vector<char> >& trusted_certs, | |
| 80 const std::vector<std::vector<char> >& untrusted_certs) { | |
| 81 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 82 if (!plugin_delegate) | |
| 83 return; | |
| 84 | |
| 85 plugin_delegate->TCPSocketSSLHandshake(socket_id_, server_name, server_port, | |
| 86 trusted_certs, untrusted_certs); | |
| 87 } | |
| 88 | |
| 89 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { | |
| 90 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 91 if (!plugin_delegate) | |
| 92 return; | |
| 93 | |
| 94 plugin_delegate->TCPSocketRead(socket_id_, bytes_to_read); | |
| 95 } | |
| 96 | |
| 97 | |
| 98 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { | |
| 99 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 100 if (!plugin_delegate) | |
| 101 return; | |
| 102 | |
| 103 plugin_delegate->TCPSocketWrite(socket_id_, buffer); | |
| 104 } | |
| 105 | |
| 106 void PPB_TCPSocket_Private_Impl::SendDisconnect() { | |
| 107 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 108 if (!plugin_delegate) | |
| 109 return; | |
| 110 | |
| 111 plugin_delegate->TCPSocketDisconnect(socket_id_); | |
| 112 } | |
| 113 | |
| 114 void PPB_TCPSocket_Private_Impl::SendSetOption( | |
| 115 PP_TCPSocket_Option name, | |
| 116 const ::ppapi::SocketOptionData& value) { | |
| 117 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 118 if (!plugin_delegate) | |
| 119 return; | |
| 120 | |
| 121 plugin_delegate->TCPSocketSetOption(socket_id_, name, value); | |
| 122 } | |
| 123 | |
| 124 PluginDelegate* PPB_TCPSocket_Private_Impl::GetPluginDelegate( | |
| 125 PP_Instance instance) { | |
| 126 PluginInstanceImpl* plugin_instance = | |
| 127 HostGlobals::Get()->GetInstance(instance); | |
| 128 if (!plugin_instance) | |
| 129 return NULL; | |
| 130 return plugin_instance->delegate(); | |
| 131 } | |
| 132 | |
| 133 } // namespace ppapi | |
| 134 } // namespace webkit | |
| OLD | NEW |