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