| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h" | 5 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h" |
| 6 | 6 |
| 7 #include "content/common/pepper_messages.h" |
| 7 #include "content/renderer/pepper/host_globals.h" | 8 #include "content/renderer/pepper/host_globals.h" |
| 9 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 8 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 9 #include "content/renderer/pepper/plugin_delegate.h" | |
| 10 #include "content/renderer/pepper/resource_helper.h" | 11 #include "content/renderer/pepper/resource_helper.h" |
| 12 #include "content/renderer/render_thread_impl.h" |
| 13 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/shared_impl/socket_option_data.h" | 14 #include "ppapi/shared_impl/socket_option_data.h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( | 18 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( |
| 16 PP_Instance instance, uint32 socket_id) | 19 PP_Instance instance, uint32 socket_id) |
| 17 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) { | 20 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) { |
| 18 } | 21 } |
| 19 | 22 |
| 20 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { | 23 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { |
| 21 Disconnect(); | 24 Disconnect(); |
| 22 } | 25 } |
| 23 | 26 |
| 24 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { | 27 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { |
| 25 PluginDelegate* plugin_delegate = GetPluginDelegate(instance); | 28 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(instance); |
| 26 if (!plugin_delegate) | 29 if (!plugin_delegate) |
| 27 return 0; | 30 return 0; |
| 28 | 31 |
| 29 uint32 socket_id = plugin_delegate->TCPSocketCreate(); | 32 uint32 socket_id = 0; |
| 33 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_CreatePrivate( |
| 34 plugin_delegate->routing_id(), 0, &socket_id)); |
| 30 if (!socket_id) | 35 if (!socket_id) |
| 31 return 0; | 36 return 0; |
| 32 | 37 |
| 33 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); | 38 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); |
| 34 } | 39 } |
| 35 | 40 |
| 36 PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket( | 41 PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket( |
| 37 PP_Instance instance, | 42 PP_Instance instance, |
| 38 uint32 socket_id, | 43 uint32 socket_id, |
| 39 const PP_NetAddress_Private& local_addr, | 44 const PP_NetAddress_Private& local_addr, |
| 40 const PP_NetAddress_Private& remote_addr) { | 45 const PP_NetAddress_Private& remote_addr) { |
| 41 PluginDelegate* plugin_delegate = GetPluginDelegate(instance); | 46 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(instance); |
| 42 if (!plugin_delegate) | 47 if (!plugin_delegate) |
| 43 return 0; | 48 return 0; |
| 44 | 49 |
| 45 PPB_TCPSocket_Private_Impl* socket = | 50 PPB_TCPSocket_Private_Impl* socket = |
| 46 new PPB_TCPSocket_Private_Impl(instance, socket_id); | 51 new PPB_TCPSocket_Private_Impl(instance, socket_id); |
| 47 | 52 |
| 48 socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED; | 53 socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED; |
| 49 socket->local_addr_ = local_addr; | 54 socket->local_addr_ = local_addr; |
| 50 socket->remote_addr_ = remote_addr; | 55 socket->remote_addr_ = remote_addr; |
| 51 | 56 |
| 52 plugin_delegate->RegisterTCPSocket(socket, socket_id); | 57 plugin_delegate->RegisterTCPSocket(socket, socket_id); |
| 53 | 58 |
| 54 return socket->GetReference(); | 59 return socket->GetReference(); |
| 55 } | 60 } |
| 56 | 61 |
| 57 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, | 62 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, |
| 58 uint16_t port) { | 63 uint16_t port) { |
| 59 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 64 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 60 if (!plugin_delegate) | 65 if (!plugin_delegate) |
| 61 return; | 66 return; |
| 62 | 67 |
| 63 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port); | 68 plugin_delegate->RegisterTCPSocket(this, socket_id_); |
| 69 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_Connect( |
| 70 plugin_delegate->routing_id(), socket_id_, host, port)); |
| 64 } | 71 } |
| 65 | 72 |
| 66 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( | 73 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( |
| 67 const PP_NetAddress_Private& addr) { | 74 const PP_NetAddress_Private& addr) { |
| 68 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 75 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 69 if (!plugin_delegate) | 76 if (!plugin_delegate) |
| 70 return; | 77 return; |
| 71 | 78 |
| 72 plugin_delegate->TCPSocketConnectWithNetAddress(this, socket_id_, addr); | 79 plugin_delegate->RegisterTCPSocket(this, socket_id_); |
| 80 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress( |
| 81 plugin_delegate->routing_id(), socket_id_, addr)); |
| 73 } | 82 } |
| 74 | 83 |
| 75 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( | 84 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( |
| 76 const std::string& server_name, | 85 const std::string& server_name, |
| 77 uint16_t server_port, | 86 uint16_t server_port, |
| 78 const std::vector<std::vector<char> >& trusted_certs, | 87 const std::vector<std::vector<char> >& trusted_certs, |
| 79 const std::vector<std::vector<char> >& untrusted_certs) { | 88 const std::vector<std::vector<char> >& untrusted_certs) { |
| 80 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 89 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 81 if (!plugin_delegate) | 90 if (!plugin_delegate) |
| 82 return; | 91 return; |
| 83 | 92 |
| 84 plugin_delegate->TCPSocketSSLHandshake(socket_id_, server_name, server_port, | 93 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake( |
| 85 trusted_certs, untrusted_certs); | 94 socket_id_, server_name, server_port, trusted_certs, untrusted_certs)); |
| 86 } | 95 } |
| 87 | 96 |
| 88 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { | 97 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { |
| 89 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 98 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 90 if (!plugin_delegate) | 99 if (!plugin_delegate) |
| 91 return; | 100 return; |
| 92 | 101 |
| 93 plugin_delegate->TCPSocketRead(socket_id_, bytes_to_read); | 102 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_Read( |
| 103 socket_id_, bytes_to_read)); |
| 94 } | 104 } |
| 95 | 105 |
| 96 | 106 |
| 97 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { | 107 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { |
| 98 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 108 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 99 if (!plugin_delegate) | 109 if (!plugin_delegate) |
| 100 return; | 110 return; |
| 101 | 111 |
| 102 plugin_delegate->TCPSocketWrite(socket_id_, buffer); | 112 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_Write( |
| 113 socket_id_, buffer)); |
| 103 } | 114 } |
| 104 | 115 |
| 105 void PPB_TCPSocket_Private_Impl::SendDisconnect() { | 116 void PPB_TCPSocket_Private_Impl::SendDisconnect() { |
| 106 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 117 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 107 if (!plugin_delegate) | 118 if (!plugin_delegate) |
| 108 return; | 119 return; |
| 109 | 120 |
| 110 plugin_delegate->TCPSocketDisconnect(socket_id_); | 121 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id_)); |
| 111 } | 122 } |
| 112 | 123 |
| 113 void PPB_TCPSocket_Private_Impl::SendSetOption( | 124 void PPB_TCPSocket_Private_Impl::SendSetOption( |
| 114 PP_TCPSocket_Option name, | 125 PP_TCPSocket_Option name, |
| 115 const ::ppapi::SocketOptionData& value) { | 126 const ::ppapi::SocketOptionData& value) { |
| 116 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 127 PepperPluginDelegateImpl* plugin_delegate = GetPluginDelegate(pp_instance()); |
| 117 if (!plugin_delegate) | 128 if (!plugin_delegate) |
| 118 return; | 129 return; |
| 119 | 130 |
| 120 plugin_delegate->TCPSocketSetOption(socket_id_, name, value); | 131 plugin_delegate->Send(new PpapiHostMsg_PPBTCPSocket_SetOption( |
| 132 socket_id_, name, value)); |
| 121 } | 133 } |
| 122 | 134 |
| 123 PluginDelegate* PPB_TCPSocket_Private_Impl::GetPluginDelegate( | 135 PepperPluginDelegateImpl* PPB_TCPSocket_Private_Impl::GetPluginDelegate( |
| 124 PP_Instance instance) { | 136 PP_Instance instance) { |
| 125 PepperPluginInstanceImpl* plugin_instance = | 137 PepperPluginInstanceImpl* plugin_instance = |
| 126 HostGlobals::Get()->GetInstance(instance); | 138 HostGlobals::Get()->GetInstance(instance); |
| 127 if (!plugin_instance) | 139 if (!plugin_instance) |
| 128 return NULL; | 140 return NULL; |
| 129 return plugin_instance->delegate(); | 141 return static_cast<PepperPluginDelegateImpl*>(plugin_instance->delegate()); |
| 130 } | 142 } |
| 131 | 143 |
| 132 } // namespace content | 144 } // namespace content |
| OLD | NEW |