| 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 "content/renderer/pepper/ppb_tcp_socket_private_impl.h" | |
| 6 | |
| 7 #include "content/common/pepper_messages.h" | |
| 8 #include "content/renderer/pepper/host_globals.h" | |
| 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | |
| 10 #include "content/renderer/render_thread_impl.h" | |
| 11 #include "ppapi/proxy/ppapi_messages.h" | |
| 12 #include "ppapi/shared_impl/socket_option_data.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( | |
| 17 PP_Instance instance, | |
| 18 uint32 socket_id, | |
| 19 int routing_id) | |
| 20 : ppapi::TCPSocketPrivateImpl(instance, socket_id), | |
| 21 routing_id_(routing_id) { | |
| 22 ChildThread::current()->AddRoute(routing_id, this); | |
| 23 } | |
| 24 | |
| 25 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { | |
| 26 ChildThread::current()->RemoveRoute(routing_id_); | |
| 27 Disconnect(); | |
| 28 } | |
| 29 | |
| 30 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { | |
| 31 int routing_id = RenderThreadImpl::current()->GenerateRoutingID(); | |
| 32 uint32 socket_id = 0; | |
| 33 RenderThreadImpl::current()->Send(new PpapiHostMsg_PPBTCPSocket_CreatePrivate( | |
| 34 routing_id, 0, &socket_id)); | |
| 35 if (!socket_id) | |
| 36 return 0; | |
| 37 | |
| 38 return (new PPB_TCPSocket_Private_Impl( | |
| 39 instance, socket_id, routing_id))->GetReference(); | |
| 40 } | |
| 41 | |
| 42 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, | |
| 43 uint16_t port) { | |
| 44 RenderThreadImpl::current()->Send(new PpapiHostMsg_PPBTCPSocket_Connect( | |
| 45 routing_id_, socket_id_, host, port)); | |
| 46 } | |
| 47 | |
| 48 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( | |
| 49 const PP_NetAddress_Private& addr) { | |
| 50 RenderThreadImpl::current()->Send( | |
| 51 new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress( | |
| 52 routing_id_, socket_id_, addr)); | |
| 53 } | |
| 54 | |
| 55 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( | |
| 56 const std::string& server_name, | |
| 57 uint16_t server_port, | |
| 58 const std::vector<std::vector<char> >& trusted_certs, | |
| 59 const std::vector<std::vector<char> >& untrusted_certs) { | |
| 60 RenderThreadImpl::current()->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake( | |
| 61 socket_id_, server_name, server_port, trusted_certs, untrusted_certs)); | |
| 62 } | |
| 63 | |
| 64 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { | |
| 65 RenderThreadImpl::current()->Send(new PpapiHostMsg_PPBTCPSocket_Read( | |
| 66 socket_id_, bytes_to_read)); | |
| 67 } | |
| 68 | |
| 69 | |
| 70 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { | |
| 71 RenderThreadImpl::current()->Send( | |
| 72 new PpapiHostMsg_PPBTCPSocket_Write(socket_id_, buffer)); | |
| 73 } | |
| 74 | |
| 75 void PPB_TCPSocket_Private_Impl::SendDisconnect() { | |
| 76 RenderThreadImpl::current()->Send( | |
| 77 new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id_)); | |
| 78 } | |
| 79 | |
| 80 void PPB_TCPSocket_Private_Impl::SendSetOption( | |
| 81 PP_TCPSocket_Option name, | |
| 82 const ppapi::SocketOptionData& value) { | |
| 83 RenderThreadImpl::current()->Send( | |
| 84 new PpapiHostMsg_PPBTCPSocket_SetOption(socket_id_, name, value)); | |
| 85 } | |
| 86 | |
| 87 bool PPB_TCPSocket_Private_Impl::OnMessageReceived( | |
| 88 const IPC::Message& message) { | |
| 89 bool handled = true; | |
| 90 IPC_BEGIN_MESSAGE_MAP(PPB_TCPSocket_Private_Impl, message) | |
| 91 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, OnTCPSocketConnectACK) | |
| 92 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, | |
| 93 OnTCPSocketSSLHandshakeACK) | |
| 94 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK) | |
| 95 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK) | |
| 96 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SetOptionACK, | |
| 97 OnTCPSocketSetOptionACK) | |
| 98 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 99 IPC_END_MESSAGE_MAP() | |
| 100 return handled; | |
| 101 } | |
| 102 | |
| 103 void PPB_TCPSocket_Private_Impl::OnTCPSocketConnectACK( | |
| 104 uint32 plugin_dispatcher_id, | |
| 105 uint32 socket_id, | |
| 106 int32_t result, | |
| 107 const PP_NetAddress_Private& local_addr, | |
| 108 const PP_NetAddress_Private& remote_addr) { | |
| 109 OnConnectCompleted(result, local_addr, remote_addr); | |
| 110 } | |
| 111 | |
| 112 void PPB_TCPSocket_Private_Impl::OnTCPSocketSSLHandshakeACK( | |
| 113 uint32 plugin_dispatcher_id, | |
| 114 uint32 socket_id, | |
| 115 bool succeeded, | |
| 116 const ppapi::PPB_X509Certificate_Fields& certificate_fields) { | |
| 117 OnSSLHandshakeCompleted(succeeded, certificate_fields); | |
| 118 } | |
| 119 | |
| 120 void PPB_TCPSocket_Private_Impl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id, | |
| 121 uint32 socket_id, | |
| 122 int32_t result, | |
| 123 const std::string& data) { | |
| 124 OnReadCompleted(result, data); | |
| 125 } | |
| 126 | |
| 127 void PPB_TCPSocket_Private_Impl::OnTCPSocketWriteACK( | |
| 128 uint32 plugin_dispatcher_id, | |
| 129 uint32 socket_id, | |
| 130 int32_t result) { | |
| 131 OnWriteCompleted(result); | |
| 132 } | |
| 133 | |
| 134 void PPB_TCPSocket_Private_Impl::OnTCPSocketSetOptionACK( | |
| 135 uint32 plugin_dispatcher_id, | |
| 136 uint32 socket_id, | |
| 137 int32_t result) { | |
| 138 OnSetOptionCompleted(result); | |
| 139 } | |
| 140 | |
| 141 } // namespace content | |
| OLD | NEW |