diff options
author | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-22 15:56:03 +0000 |
---|---|---|
committer | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-22 15:56:03 +0000 |
commit | 20e3112e65dd794b794bdabd53bc4542b767ad2d (patch) | |
tree | f84c170eab4600c7036af549039078eeb477a262 /webkit | |
parent | 11039d76fa14f1b007272144c0b300a19711532b (diff) | |
download | chromium_src-20e3112e65dd794b794bdabd53bc4542b767ad2d.zip chromium_src-20e3112e65dd794b794bdabd53bc4542b767ad2d.tar.gz chromium_src-20e3112e65dd794b794bdabd53bc4542b767ad2d.tar.bz2 |
Exposed Listen and Accept methods to in-process plugins.
BUG=108277
TEST=UI test TestTCPServerSocketPrivate
Review URL: http://codereview.chromium.org/9283022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123033 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 18 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 9 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc | 86 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h | 41 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc | 36 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h | 11 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.cc | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.h | 3 |
11 files changed, 222 insertions, 5 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 36cbcde..d294167 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -299,6 +299,8 @@ '../plugins/ppapi/ppb_proxy_impl.h', '../plugins/ppapi/ppb_scrollbar_impl.cc', '../plugins/ppapi/ppb_scrollbar_impl.h', + '../plugins/ppapi/ppb_tcp_server_socket_private_impl.cc', + '../plugins/ppapi/ppb_tcp_server_socket_private_impl.h', '../plugins/ppapi/ppb_tcp_socket_private_impl.cc', '../plugins/ppapi/ppb_tcp_socket_private_impl.h', '../plugins/ppapi/ppb_text_input_impl.cc', diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index ea6a9f2..c62f39e 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -275,6 +275,10 @@ void MockPluginDelegate::TCPSocketWrite(uint32 socket_id, void MockPluginDelegate::TCPSocketDisconnect(uint32 socket_id) { } +void MockPluginDelegate::RegisterTCPSocket(PPB_TCPSocket_Private_Impl* socket, + uint32 socket_id) { +} + uint32 MockPluginDelegate::UDPSocketCreate() { return 0; } @@ -296,6 +300,20 @@ void MockPluginDelegate::UDPSocketSendTo(uint32 socket_id, void MockPluginDelegate::UDPSocketClose(uint32 socket_id) { } +void MockPluginDelegate::TCPServerSocketListen( + PPB_TCPServerSocket_Private_Impl* socket, + uint32 temp_socket_id, + const PP_NetAddress_Private& addr, + int32_t backlog) { +} + +void MockPluginDelegate::TCPServerSocketAccept(uint32 real_socket_id) { +} + +void MockPluginDelegate::TCPServerSocketStopListening(uint32 real_socket_id, + uint32 temp_socket_id) { +} + int32_t MockPluginDelegate::ShowContextMenu( PluginInstance* instance, webkit::ppapi::PPB_Flash_Menu_Impl* menu, diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index cb40de7..8b35aff 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -122,6 +122,8 @@ class MockPluginDelegate : public PluginDelegate { virtual void TCPSocketRead(uint32 socket_id, int32_t bytes_to_read); virtual void TCPSocketWrite(uint32 socket_id, const std::string& buffer); virtual void TCPSocketDisconnect(uint32 socket_id); + virtual void RegisterTCPSocket(PPB_TCPSocket_Private_Impl* socket, + uint32 socket_id); virtual uint32 UDPSocketCreate(); virtual void UDPSocketBind(PPB_UDPSocket_Private_Impl* socket, uint32 socket_id, @@ -131,6 +133,13 @@ class MockPluginDelegate : public PluginDelegate { const std::string& buffer, const PP_NetAddress_Private& addr); virtual void UDPSocketClose(uint32 socket_id); + virtual void TCPServerSocketListen(PPB_TCPServerSocket_Private_Impl* socket, + uint32 temp_socket_id, + const PP_NetAddress_Private& addr, + int32_t backlog); + virtual void TCPServerSocketAccept(uint32 real_socket_id); + virtual void TCPServerSocketStopListening(uint32 real_socket_id, + uint32 temp_socket_id); virtual int32_t ShowContextMenu( PluginInstance* instance, webkit::ppapi::PPB_Flash_Menu_Impl* menu, diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index fe7d45d..973c6e4 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -82,6 +82,7 @@ class PluginModule; class PPB_Broker_Impl; class PPB_Flash_Menu_Impl; class PPB_Flash_NetConnector_Impl; +class PPB_TCPServerSocket_Private_Impl; class PPB_TCPSocket_Private_Impl; class PPB_UDPSocket_Private_Impl; @@ -452,6 +453,8 @@ class PluginDelegate { virtual void TCPSocketRead(uint32 socket_id, int32_t bytes_to_read) = 0; virtual void TCPSocketWrite(uint32 socket_id, const std::string& buffer) = 0; virtual void TCPSocketDisconnect(uint32 socket_id) = 0; + virtual void RegisterTCPSocket(PPB_TCPSocket_Private_Impl* socket, + uint32 socket_id) = 0; // For PPB_UDPSocket_Private. virtual uint32 UDPSocketCreate() = 0; @@ -464,6 +467,15 @@ class PluginDelegate { const PP_NetAddress_Private& addr) = 0; virtual void UDPSocketClose(uint32 socket_id) = 0; + // For PPB_TCPServerSocket_Private. + virtual void TCPServerSocketListen(PPB_TCPServerSocket_Private_Impl* socket, + uint32 temp_socket_id, + const PP_NetAddress_Private& addr, + int32_t backlog) = 0; + virtual void TCPServerSocketAccept(uint32 real_socket_id) = 0; + virtual void TCPServerSocketStopListening(uint32 real_socket_id, + uint32 temp_socket_id) = 0; + // Show the given context menu at the given position (in the plugin's // coordinates). virtual int32_t ShowContextMenu( diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 195046a..0a5d457 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -76,6 +76,7 @@ #include "ppapi/c/private/ppb_instance_private.h" #include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_proxy_private.h" +#include "ppapi/c/private/ppb_tcp_server_socket_private.h" #include "ppapi/c/private/ppb_tcp_socket_private.h" #include "ppapi/c/private/ppb_udp_socket_private.h" #include "ppapi/c/private/ppb_uma_private.h" @@ -343,6 +344,8 @@ const void* GetInterface(const char* name) { return ::ppapi::PPB_OpenGLES2_Shared::GetInterface(); if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) return PPB_Proxy_Impl::GetInterface(); + if (strcmp(name, PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE) == 0) + return ::ppapi::thunk::GetPPB_TCPServerSocket_Private_0_1_Thunk(); if (strcmp(name, PPB_UMA_PRIVATE_INTERFACE) == 0) return PPB_UMA_Private_Impl::GetInterface(); if (strcmp(name, PPB_URLLOADERTRUSTED_INTERFACE_0_3) == 0) diff --git a/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc b/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc new file mode 100644 index 0000000..213b4bf --- /dev/null +++ b/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" + +#include "base/logging.h" +#include "webkit/plugins/ppapi/host_globals.h" +#include "webkit/plugins/ppapi/plugin_delegate.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" + +namespace webkit { +namespace ppapi { + +PPB_TCPServerSocket_Private_Impl::PPB_TCPServerSocket_Private_Impl( + PP_Instance instance) + : ::ppapi::PPB_TCPServerSocket_Shared(instance) { +} + +PPB_TCPServerSocket_Private_Impl::~PPB_TCPServerSocket_Private_Impl() { + StopListening(); +} + +PP_Resource PPB_TCPServerSocket_Private_Impl::CreateResource( + PP_Instance instance) { + PPB_TCPServerSocket_Private_Impl* socket = + new PPB_TCPServerSocket_Private_Impl(instance); + return socket->GetReference(); +} + +void PPB_TCPServerSocket_Private_Impl::OnAcceptCompleted( + bool succeeded, + uint32 tcp_socket_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) { + if (!::ppapi::TrackedCallback::IsPending(accept_callback_) || + !tcp_socket_buffer_) { + NOTREACHED(); + return; + } + + if (succeeded) { + *tcp_socket_buffer_ = + PPB_TCPSocket_Private_Impl::CreateConnectedSocket(pp_instance(), + tcp_socket_id, + local_addr, + remote_addr); + } + tcp_socket_buffer_ = NULL; + + ::ppapi::TrackedCallback::ClearAndRun(&accept_callback_, + succeeded ? PP_OK : PP_ERROR_FAILED); +} + +void PPB_TCPServerSocket_Private_Impl::SendListen( + uint32 temp_socket_id, + const PP_NetAddress_Private& addr, + int32_t backlog) { + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return; + + plugin_delegate->TCPServerSocketListen(this, temp_socket_id, addr, backlog); +} + +void PPB_TCPServerSocket_Private_Impl::SendAccept() { + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return; + + plugin_delegate->TCPServerSocketAccept(real_socket_id_); +} + +void PPB_TCPServerSocket_Private_Impl::SendStopListening() { + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return; + + plugin_delegate->TCPServerSocketStopListening(real_socket_id_, + temp_socket_id_); +} + +} // namespace ppapi +} // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h b/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h new file mode 100644 index 0000000..6533e61 --- /dev/null +++ b/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h @@ -0,0 +1,41 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_PLUGINS_PPAPI_PPB_TCP_SERVER_SOCKET_PRIVATE_IMPL_H_ +#define WEBKIT_PLUGINS_PPAPI_PPB_TCP_SERVER_SOCKET_PRIVATE_IMPL_H_ + +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h" + +namespace webkit { +namespace ppapi { + +class PPB_TCPServerSocket_Private_Impl + : public ::ppapi::PPB_TCPServerSocket_Shared { + public: + static PP_Resource CreateResource(PP_Instance instance); + + virtual void OnAcceptCompleted( + bool succeeded, + uint32 tcp_socket_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) OVERRIDE; + + virtual void SendListen(uint32_t temp_socket_id, + const PP_NetAddress_Private& addr, + int32_t backlog) OVERRIDE; + virtual void SendAccept() OVERRIDE; + virtual void SendStopListening() OVERRIDE; + + private: + PPB_TCPServerSocket_Private_Impl(PP_Instance instance); + virtual ~PPB_TCPServerSocket_Private_Impl(); + + DISALLOW_COPY_AND_ASSIGN(PPB_TCPServerSocket_Private_Impl); +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_PPB_TCP_SERVER_SOCKET_PRIVATE_IMPL_H_ diff --git a/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc b/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc index 61fc83c..06489aa 100644 --- a/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc +++ b/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -22,11 +22,10 @@ PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { } PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { - PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); - if (!plugin_instance) + PluginDelegate* plugin_delegate = GetPluginDelegate(instance); + if (!plugin_delegate) return 0; - PluginDelegate* plugin_delegate = plugin_instance->delegate(); uint32 socket_id = plugin_delegate->TCPSocketCreate(); if (!socket_id) return 0; @@ -34,6 +33,27 @@ PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); } +PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket( + PP_Instance instance, + uint32 socket_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) { + PluginDelegate* plugin_delegate = GetPluginDelegate(instance); + if (!plugin_delegate) + return 0; + + PPB_TCPSocket_Private_Impl* socket = + new PPB_TCPSocket_Private_Impl(instance, socket_id); + + socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED; + socket->local_addr_ = local_addr; + socket->remote_addr_ = remote_addr; + + plugin_delegate->RegisterTCPSocket(socket, socket_id); + + return socket->GetReference(); +} + void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, uint16_t port) { PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); @@ -87,5 +107,13 @@ void PPB_TCPSocket_Private_Impl::SendDisconnect() { plugin_delegate->TCPSocketDisconnect(socket_id_); } +PluginDelegate* PPB_TCPSocket_Private_Impl::GetPluginDelegate( + PP_Instance instance) { + PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); + if (!plugin_instance) + return NULL; + return plugin_instance->delegate(); +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h b/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h index ba86518..fdc298c 100644 --- a/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h +++ b/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,9 +11,16 @@ namespace webkit { namespace ppapi { +class PluginDelegate; + class PPB_TCPSocket_Private_Impl : public ::ppapi::TCPSocketPrivateImpl { public: static PP_Resource CreateResource(PP_Instance instance); + static PP_Resource CreateConnectedSocket( + PP_Instance instance, + uint32 socket_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr); virtual void SendConnect(const std::string& host, uint16_t port) OVERRIDE; virtual void SendConnectWithNetAddress( @@ -28,6 +35,8 @@ class PPB_TCPSocket_Private_Impl : public ::ppapi::TCPSocketPrivateImpl { PPB_TCPSocket_Private_Impl(PP_Instance instance, uint32 socket_id); virtual ~PPB_TCPSocket_Private_Impl(); + static PluginDelegate* GetPluginDelegate(PP_Instance instance); + DISALLOW_COPY_AND_ASSIGN(PPB_TCPSocket_Private_Impl); }; diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 120c587..4ef430e 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -27,6 +27,7 @@ #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" +#include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" #include "webkit/plugins/ppapi/ppb_transport_impl.h" #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h" @@ -257,6 +258,11 @@ PP_Resource ResourceCreationImpl::CreateResourceArray( return object->GetReference(); } +PP_Resource ResourceCreationImpl::CreateTCPServerSocketPrivate( + PP_Instance instance) { + return PPB_TCPServerSocket_Private_Impl::CreateResource(instance); +} + PP_Resource ResourceCreationImpl::CreateTCPSocketPrivate(PP_Instance instance) { return PPB_TCPSocket_Private_Impl::CreateResource(instance); } diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index d4595ae..f7c2a70 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -93,7 +93,10 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, uint32_t size) OVERRIDE; virtual PP_Resource CreateScrollbar(PP_Instance instance, PP_Bool vertical) OVERRIDE; + virtual PP_Resource CreateTCPServerSocketPrivate( + PP_Instance instance) OVERRIDE; virtual PP_Resource CreateTCPSocketPrivate(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateTransport(PP_Instance instance, const char* name, PP_TransportType type) OVERRIDE; |