summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-30 17:19:02 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-30 17:19:02 +0000
commit24498a8e674e456f5d778f3e192d886fa4573ec9 (patch)
tree3a01d312cd4fc1bc5b329b05e04f4e21acd380d2 /ppapi
parenta64ccdb0c5dbe674a3cdc368ab758fdde0b4a5d9 (diff)
downloadchromium_src-24498a8e674e456f5d778f3e192d886fa4573ec9.zip
chromium_src-24498a8e674e456f5d778f3e192d886fa4573ec9.tar.gz
chromium_src-24498a8e674e456f5d778f3e192d886fa4573ec9.tar.bz2
Define PPB_Flash_TCPSocket and PPB_Flash_SSLSocket.
TEST=None BUG=None Review URL: http://codereview.chromium.org/7191005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91150 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/private/ppb_flash_net_connector.h7
-rw-r--r--ppapi/c/private/ppb_flash_tcp_socket.h88
-rw-r--r--ppapi/cpp/private/flash_tcp_socket.cc102
-rw-r--r--ppapi/cpp/private/flash_tcp_socket.h48
-rw-r--r--ppapi/ppapi_cpp.gypi1
-rw-r--r--ppapi/ppapi_proxy.gypi2
-rw-r--r--ppapi/ppapi_shared.gypi2
-rw-r--r--ppapi/proxy/dispatcher.cc3
-rw-r--r--ppapi/proxy/interface_id.h1
-rw-r--r--ppapi/proxy/plugin_dispatcher.cc6
-rw-r--r--ppapi/proxy/plugin_dispatcher.h11
-rw-r--r--ppapi/proxy/ppapi_messages.h40
-rw-r--r--ppapi/proxy/ppapi_param_traits.cc35
-rw-r--r--ppapi/proxy/ppapi_param_traits.h9
-rw-r--r--ppapi/proxy/ppb_flash_tcp_socket_proxy.cc438
-rw-r--r--ppapi/proxy/ppb_flash_tcp_socket_proxy.h61
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc6
-rw-r--r--ppapi/proxy/resource_creation_proxy.h1
-rw-r--r--ppapi/shared_impl/resource_object_base.h1
-rw-r--r--ppapi/tests/all_c_includes.h1
-rw-r--r--ppapi/thunk/ppb_flash_tcp_socket_api.h38
-rw-r--r--ppapi/thunk/ppb_flash_tcp_socket_thunk.cc121
-rw-r--r--ppapi/thunk/resource_creation_api.h1
-rw-r--r--ppapi/thunk/thunk.h2
24 files changed, 1018 insertions, 7 deletions
diff --git a/ppapi/c/private/ppb_flash_net_connector.h b/ppapi/c/private/ppb_flash_net_connector.h
index 2cc25bb..188dbef 100644
--- a/ppapi/c/private/ppb_flash_net_connector.h
+++ b/ppapi/c/private/ppb_flash_net_connector.h
@@ -9,15 +9,10 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/private/ppb_flash_file.h" // For |PP_FileHandle|.
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
#define PPB_FLASH_NETCONNECTOR_INTERFACE "PPB_Flash_NetConnector;0.1"
-// This is an opaque type holding a network address.
-struct PP_Flash_NetAddress {
- uint32_t size;
- char data[128];
-};
-
struct PPB_Flash_NetConnector {
PP_Resource (*Create)(PP_Instance instance_id);
PP_Bool (*IsFlashNetConnector)(PP_Resource resource_id);
diff --git a/ppapi/c/private/ppb_flash_tcp_socket.h b/ppapi/c/private/ppb_flash_tcp_socket.h
new file mode 100644
index 0000000..6577631
--- /dev/null
+++ b/ppapi/c/private/ppb_flash_tcp_socket.h
@@ -0,0 +1,88 @@
+// Copyright (c) 2011 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 PPAPI_C_PRIVATE_PPB_FLASH_TCP_SOCKET_H_
+#define PPAPI_C_PRIVATE_PPB_FLASH_TCP_SOCKET_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_stdint.h"
+
+// This is an opaque type holding a network address.
+struct PP_Flash_NetAddress {
+ uint32_t size;
+ char data[128];
+};
+
+#define PPB_FLASH_TCPSOCKET_INTERFACE "PPB_Flash_TCPSocket;0.1"
+
+struct PPB_Flash_TCPSocket {
+ PP_Resource (*Create)(PP_Instance instance);
+
+ PP_Bool (*IsFlashTCPSocket)(PP_Resource resource);
+
+ // Connects to a TCP port given as a host-port pair.
+ int32_t (*Connect)(PP_Resource tcp_socket,
+ const char* host,
+ uint16_t port,
+ struct PP_CompletionCallback callback);
+
+ // Same as Connect(), but connecting to the address given by |addr|. A typical
+ // use-case would be for reconnections.
+ int32_t (*ConnectWithNetAddress)(PP_Resource tcp_socket,
+ const struct PP_Flash_NetAddress* addr,
+ struct PP_CompletionCallback callback);
+
+ // Gets the local address of the socket, if it has been connected.
+ // Returns PP_TRUE on success.
+ PP_Bool (*GetLocalAddress)(PP_Resource tcp_socket,
+ struct PP_Flash_NetAddress* local_addr);
+
+ // Gets the remote address of the socket, if it has been connected.
+ // Returns PP_TRUE on success.
+ PP_Bool (*GetRemoteAddress)(PP_Resource tcp_socket,
+ struct PP_Flash_NetAddress* remote_addr);
+
+ // Does SSL handshake and moves to sending and receiving encrypted data. The
+ // socket must have been successfully connected. |server_name| will be
+ // compared with the name(s) in the server's certificate during the SSL
+ // handshake.
+ int32_t (*InitiateSSL)(PP_Resource tcp_socket,
+ const char* server_name,
+ struct PP_CompletionCallback callback);
+
+ // Reads data from the socket. The size of |buffer| must be at least as large
+ // as |bytes_to_read|. May perform a partial read. Returns the number of bytes
+ // read or an error code. If the return value is 0, then it indicates that
+ // end-of-file was reached.
+ // This method won't return more than 1 megabyte, so if |bytes_to_read|
+ // exceeds 1 megabyte, it will always perform a partial read.
+ // Multiple outstanding read requests are not supported.
+ int32_t (*Read)(PP_Resource tcp_socket,
+ char* buffer,
+ int32_t bytes_to_read,
+ struct PP_CompletionCallback callback);
+
+ // Writes data to the socket. May perform a partial write. Returns the number
+ // of bytes written or an error code.
+ // This method won't write more than 1 megabyte, so if |bytes_to_write|
+ // exceeds 1 megabyte, it will always perform a partial write.
+ // Multiple outstanding write requests are not supported.
+ int32_t (*Write)(PP_Resource tcp_socket,
+ const char* buffer,
+ int32_t bytes_to_write,
+ struct PP_CompletionCallback callback);
+
+ // Cancels any IO that may be pending, and disconnects the socket. Any pending
+ // callbacks will still run, reporting PP_Error_Aborted if pending IO was
+ // interrupted. It is NOT valid to call Connect() again after a call to this
+ // method. Note: If the socket is destroyed when it is still connected, then
+ // it will be implicitly disconnected, so you are not required to call this
+ // method.
+ void (*Disconnect)(PP_Resource tcp_socket);
+};
+
+#endif // PPAPI_C_PRIVATE_PPB_FLASH_TCP_SOCKET_H_
diff --git a/ppapi/cpp/private/flash_tcp_socket.cc b/ppapi/cpp/private/flash_tcp_socket.cc
new file mode 100644
index 0000000..f5b4633
--- /dev/null
+++ b/ppapi/cpp/private/flash_tcp_socket.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2011 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.
+
+// TODO(yzshen): See the comment in corresponding .h file.
+
+#include "ppapi/cpp/private/flash_tcp_socket.h"
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/module_impl.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_Flash_TCPSocket>() {
+ return PPB_FLASH_TCPSOCKET_INTERFACE;
+}
+
+} // namespace
+
+namespace flash {
+
+TCPSocket::TCPSocket(Instance* instance) {
+ if (has_interface<PPB_Flash_TCPSocket>() && instance) {
+ PassRefFromConstructor(get_interface<PPB_Flash_TCPSocket>()->Create(
+ instance->pp_instance()));
+ }
+}
+
+int32_t TCPSocket::Connect(const char* host,
+ uint16_t port,
+ const CompletionCallback& callback) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Flash_TCPSocket>()->Connect(
+ pp_resource(), host, port, callback.pp_completion_callback());
+}
+
+int32_t TCPSocket::ConnectWithNetAddress(const PP_Flash_NetAddress* addr,
+ const CompletionCallback& callback) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Flash_TCPSocket>()->ConnectWithNetAddress(
+ pp_resource(), addr, callback.pp_completion_callback());
+}
+
+bool TCPSocket::GetLocalAddress(PP_Flash_NetAddress* local_addr) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return false;
+
+ PP_Bool result = get_interface<PPB_Flash_TCPSocket>()->GetLocalAddress(
+ pp_resource(), local_addr);
+ return PP_ToBool(result);
+}
+
+bool TCPSocket::GetRemoteAddress(PP_Flash_NetAddress* remote_addr) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return false;
+ PP_Bool result = get_interface<PPB_Flash_TCPSocket>()->GetRemoteAddress(
+ pp_resource(), remote_addr);
+ return PP_ToBool(result);
+}
+
+int32_t TCPSocket::InitiateSSL(const char* server_name,
+ const CompletionCallback& callback) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Flash_TCPSocket>()->InitiateSSL(
+ pp_resource(), server_name, callback.pp_completion_callback());
+}
+
+int32_t TCPSocket::Read(char* buffer,
+ int32_t bytes_to_read,
+ const CompletionCallback& callback) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Flash_TCPSocket>()->Read(
+ pp_resource(), buffer, bytes_to_read, callback.pp_completion_callback());
+}
+
+int32_t TCPSocket::Write(const char* buffer,
+ int32_t bytes_to_write,
+ const CompletionCallback& callback) {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Flash_TCPSocket>()->Write(
+ pp_resource(), buffer, bytes_to_write, callback.pp_completion_callback());
+}
+
+void TCPSocket::Disconnect() {
+ if (!has_interface<PPB_Flash_TCPSocket>())
+ return;
+ return get_interface<PPB_Flash_TCPSocket>()->Disconnect(pp_resource());
+}
+
+} // namespace flash
+} // namespace pp
diff --git a/ppapi/cpp/private/flash_tcp_socket.h b/ppapi/cpp/private/flash_tcp_socket.h
new file mode 100644
index 0000000..8998728
--- /dev/null
+++ b/ppapi/cpp/private/flash_tcp_socket.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2011 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.
+
+// TODO(yzshen): This (and the .cc file) contain C++ wrappers for things
+// in ppapi/c/private/ppb_flash_tcp_socket.h. This is currently not used in
+// (or even compiled with) Chromium.
+
+#ifndef PPAPI_CPP_PRIVATE_FLASH_TCP_SOCKET_H_
+#define PPAPI_CPP_PRIVATE_FLASH_TCP_SOCKET_H_
+
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
+#include "ppapi/cpp/resource.h"
+
+namespace pp {
+
+class CompletionCallback;
+class Instance;
+
+namespace flash {
+
+class TCPSocket : public Resource {
+ public:
+ explicit TCPSocket(Instance* instance);
+
+ int32_t Connect(const char* host,
+ uint16_t port,
+ const CompletionCallback& callback);
+ int32_t ConnectWithNetAddress(const PP_Flash_NetAddress* addr,
+ const CompletionCallback& callback);
+ bool GetLocalAddress(PP_Flash_NetAddress* local_addr);
+ bool GetRemoteAddress(PP_Flash_NetAddress* remote_addr);
+ int32_t InitiateSSL(const char* server_name,
+ const CompletionCallback& callback);
+ int32_t Read(char* buffer,
+ int32_t bytes_to_read,
+ const CompletionCallback& callback);
+ int32_t Write(const char* buffer,
+ int32_t bytes_to_write,
+ const CompletionCallback& callback);
+ void Disconnect();
+};
+
+} // namespace flash
+} // namespace pp
+
+#endif // PPAPI_CPP_PRIVATE_FLASH_TCP_SOCKET_H_
diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi
index 045af8b..315e71c 100644
--- a/ppapi/ppapi_cpp.gypi
+++ b/ppapi/ppapi_cpp.gypi
@@ -92,6 +92,7 @@
'c/private/ppb_flash_file.h',
'c/private/ppb_flash_menu.h',
'c/private/ppb_flash_net_connector.h',
+ 'c/private/ppb_flash_tcp_socket.h',
'c/private/ppb_instance_private.h',
'c/private/ppb_nacl_private.h',
'c/private/ppb_pdf.h',
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index 1d4ba98..5af875d 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -90,6 +90,8 @@
'proxy/ppb_flash_menu_proxy.h',
'proxy/ppb_flash_net_connector_proxy.cc',
'proxy/ppb_flash_net_connector_proxy.h',
+ 'proxy/ppb_flash_tcp_socket_proxy.cc',
+ 'proxy/ppb_flash_tcp_socket_proxy.h',
'proxy/ppb_font_proxy.cc',
'proxy/ppb_font_proxy.h',
'proxy/ppb_graphics_2d_proxy.cc',
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index 11440a1..9d0d734 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -87,6 +87,8 @@
'thunk/ppb_flash_menu_thunk.cc',
'thunk/ppb_flash_net_connector_api.h',
'thunk/ppb_flash_net_connector_thunk.cc',
+ 'thunk/ppb_flash_tcp_socket_api.h',
+ 'thunk/ppb_flash_tcp_socket_thunk.cc',
'thunk/ppb_font_api.h',
'thunk/ppb_font_thunk.cc',
'thunk/ppb_fullscreen_thunk.cc',
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index 3520752..b8db635 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -40,6 +40,7 @@
#include "ppapi/c/private/ppb_flash_file.h"
#include "ppapi/c/private/ppb_flash_menu.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
#include "ppapi/proxy/ppapi_messages.h"
@@ -61,6 +62,7 @@
#include "ppapi/proxy/ppb_flash_proxy.h"
#include "ppapi/proxy/ppb_flash_menu_proxy.h"
#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
+#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h"
#include "ppapi/proxy/ppb_font_proxy.h"
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
@@ -129,6 +131,7 @@ InterfaceList::InterfaceList() {
AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo());
AddPPB(PPB_Flash_Proxy::GetInfo());
AddPPB(PPB_Flash_Menu_Proxy::GetInfo());
+ AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo());
AddPPB(PPB_Font_Proxy::GetInfo());
AddPPB(PPB_Graphics2D_Proxy::GetInfo());
AddPPB(PPB_ImageData_Proxy::GetInfo());
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index 40554f5..8fccd1d 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -33,6 +33,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
INTERFACE_ID_PPB_FLASH_MENU,
INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
+ INTERFACE_ID_PPB_FLASH_TCPSOCKET,
INTERFACE_ID_PPB_FONT,
INTERFACE_ID_PPB_GRAPHICS_2D,
INTERFACE_ID_PPB_IMAGE_DATA,
diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc
index ac0a072..6e13b8f 100644
--- a/ppapi/proxy/plugin_dispatcher.cc
+++ b/ppapi/proxy/plugin_dispatcher.cc
@@ -44,7 +44,8 @@ PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle,
GetInterfaceFunc get_interface)
: Dispatcher(remote_process_handle, get_interface),
plugin_delegate_(NULL),
- received_preferences_(false) {
+ received_preferences_(false),
+ plugin_dispatcher_id_(0) {
SetSerializationRules(new PluginVarSerializationRules);
// As a plugin, we always support the PPP_Class interface. There's no
@@ -56,6 +57,8 @@ PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle,
}
PluginDispatcher::~PluginDispatcher() {
+ if (plugin_delegate_)
+ plugin_delegate_->Unregister(plugin_dispatcher_id_);
}
// static
@@ -86,6 +89,7 @@ bool PluginDispatcher::InitPluginWithChannel(
if (!Dispatcher::InitWithChannel(delegate, channel_handle, is_client))
return false;
plugin_delegate_ = delegate;
+ plugin_dispatcher_id_ = plugin_delegate_->Register(this);
// The message filter will intercept and process certain messages directly
// on the I/O thread.
diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h
index 1964d94..ae6da60 100644
--- a/ppapi/proxy/plugin_dispatcher.h
+++ b/ppapi/proxy/plugin_dispatcher.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/basictypes.h"
#include "base/hash_tables.h"
#include "base/memory/scoped_ptr.h"
#include "base/process.h"
@@ -60,6 +61,12 @@ class PluginDispatcher : public Dispatcher {
// Sends the given message to the browser. Identical semantics to
// IPC::Message::Sender interface.
virtual bool SendToBrowser(IPC::Message* msg) = 0;
+
+ // Registers the plugin dispatcher and returns an ID.
+ // Plugin dispatcher IDs will be used to dispatch messages from the browser.
+ // Each call to Register() has to be matched with a call to Unregister().
+ virtual uint32 Register(PluginDispatcher* plugin_dispatcher) = 0;
+ virtual void Unregister(uint32 plugin_dispatcher_id) = 0;
};
// Constructor for the plugin side. The init and shutdown functions will be
@@ -123,6 +130,8 @@ class PluginDispatcher : public Dispatcher {
ppapi::FunctionGroupBase* GetFunctionAPI(
pp::proxy::InterfaceID id);
+ uint32 plugin_dispatcher_id() const { return plugin_dispatcher_id_; }
+
private:
friend class PluginDispatcherTest;
@@ -154,6 +163,8 @@ class PluginDispatcher : public Dispatcher {
bool received_preferences_;
ppapi::Preferences preferences_;
+ uint32 plugin_dispatcher_id_;
+
DISALLOW_COPY_AND_ASSIGN(PluginDispatcher);
};
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 9b29993..75f79ac 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -26,6 +26,7 @@
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_size.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
#include "ppapi/proxy/ppapi_param_traits.h"
#include "ppapi/proxy/serialized_flash_menu.h"
#include "ppapi/proxy/serialized_structs.h"
@@ -149,6 +150,24 @@ IPC_MESSAGE_ROUTED5(PpapiMsg_PPBFlashNetConnector_ConnectACK,
std::string /* local_addr_as_string */,
std::string /* remote_addr_as_string */)
+// PPB_Flash_TCPSocket.
+IPC_MESSAGE_ROUTED5(PpapiMsg_PPBFlashTCPSocket_ConnectACK,
+ uint32 /* plugin_dispatcher_id */,
+ uint32 /* socket_id */,
+ bool /* succeeded */,
+ PP_Flash_NetAddress /* local_addr */,
+ PP_Flash_NetAddress /* remote_addr */)
+IPC_MESSAGE_ROUTED4(PpapiMsg_PPBFlashTCPSocket_ReadACK,
+ uint32 /* plugin_dispatcher_id */,
+ uint32 /* socket_id */,
+ bool /* succeeded */,
+ std::string /* data */)
+IPC_MESSAGE_ROUTED4(PpapiMsg_PPBFlashTCPSocket_WriteACK,
+ uint32 /* plugin_dispatcher_id */,
+ uint32 /* socket_id */,
+ bool /* succeeded */,
+ int32_t /* bytes_written */)
+
// PPB_Graphics2D.
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics2D_FlushACK,
pp::proxy::HostResource /* graphics_2d */,
@@ -536,6 +555,27 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress,
pp::proxy::HostResource /* connector */,
std::string /* net_address_as_string */)
+// PPB_Flash_TCPSocket.
+IPC_SYNC_MESSAGE_CONTROL2_1(PpapiHostMsg_PPBFlashTCPSocket_Create,
+ int32 /* routing_id */,
+ uint32 /* plugin_dispatcher_id */,
+ uint32 /* socket_id */)
+IPC_MESSAGE_CONTROL3(PpapiHostMsg_PPBFlashTCPSocket_Connect,
+ uint32 /* socket_id */,
+ std::string /* host */,
+ uint16_t /* port */)
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBFlashTCPSocket_ConnectWithNetAddress,
+ uint32 /* socket_id */,
+ PP_Flash_NetAddress /* net_addr */)
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBFlashTCPSocket_Read,
+ uint32 /* socket_id */,
+ int32_t /* bytes_to_read */)
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBFlashTCPSocket_Write,
+ uint32 /* socket_id */,
+ std::string /* data */)
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBFlashTCPSocket_Disconnect,
+ uint32 /* socket_id */)
+
// PPB_Font.
IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies,
std::string /* result */)
diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc
index 20a00c8..aa21dc1 100644
--- a/ppapi/proxy/ppapi_param_traits.cc
+++ b/ppapi/proxy/ppapi_param_traits.cc
@@ -8,6 +8,7 @@
#include "ppapi/c/dev/pp_file_info_dev.h"
#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
#include "ppapi/proxy/host_resource.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/ppapi_messages.h"
@@ -136,6 +137,40 @@ bool ParamTraits<PP_FileInfo_Dev>::Read(const Message* m, void** iter,
void ParamTraits<PP_FileInfo_Dev>::Log(const param_type& p, std::string* l) {
}
+// PP_Flash_NetAddress ---------------------------------------------------------
+
+// static
+void ParamTraits<PP_Flash_NetAddress>::Write(Message* m, const param_type& p) {
+ WriteParam(m, p.size);
+ m->WriteBytes(p.data, static_cast<int>(p.size));
+}
+
+// static
+bool ParamTraits<PP_Flash_NetAddress>::Read(const Message* m,
+ void** iter,
+ param_type* p) {
+ uint16 size;
+ if (!ReadParam(m, iter, &size))
+ return false;
+ if (size > sizeof(p->data))
+ return false;
+ p->size = size;
+
+ const char* data;
+ if (!m->ReadBytes(iter, &data, size))
+ return false;
+ memcpy(p->data, data, size);
+ return true;
+}
+
+// static
+void ParamTraits<PP_Flash_NetAddress>::Log(const param_type& p,
+ std::string* l) {
+ l->append("<PP_Flash_NetAddress (");
+ LogParam(p.size, l);
+ l->append(" bytes)>");
+}
+
// PP_InputEvent ---------------------------------------------------------------
// static
diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h
index 3d6d57f..62f807b 100644
--- a/ppapi/proxy/ppapi_param_traits.h
+++ b/ppapi/proxy/ppapi_param_traits.h
@@ -15,6 +15,7 @@
struct PP_FileInfo_Dev;
struct PP_ObjectProperty;
struct PP_Flash_Menu;
+struct PP_Flash_NetAddress;
namespace pp {
namespace proxy {
@@ -49,6 +50,14 @@ struct ParamTraits<PP_FileInfo_Dev> {
static void Log(const param_type& p, std::string* l);
};
+template <>
+struct ParamTraits<PP_Flash_NetAddress> {
+ typedef PP_Flash_NetAddress param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* p);
+ static void Log(const param_type& p, std::string* l);
+};
+
template<>
struct ParamTraits<PP_InputEvent> {
typedef PP_InputEvent param_type;
diff --git a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc
new file mode 100644
index 0000000..d8968d8
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc
@@ -0,0 +1,438 @@
+// Copyright (c) 2011 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 "ppapi/proxy/ppb_flash_tcp_socket_proxy.h"
+
+#include <algorithm>
+#include <cstring>
+#include <map>
+
+#include "base/logging.h"
+#include "base/memory/linked_ptr.h"
+#include "base/message_loop.h"
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/thunk/ppb_flash_tcp_socket_api.h"
+#include "ppapi/thunk/thunk.h"
+
+using ppapi::thunk::PPB_Flash_TCPSocket_API;
+
+namespace pp {
+namespace proxy {
+
+const int32_t kFlashTCPSocketMaxReadSize = 1024 * 1024;
+const int32_t kFlashTCPSocketMaxWriteSize = 1024 * 1024;
+
+class FlashTCPSocket;
+
+namespace {
+
+typedef std::map<uint32, FlashTCPSocket*> IDToSocketMap;
+IDToSocketMap* g_id_to_socket = NULL;
+
+class AbortCallbackTask : public Task {
+ public:
+ explicit AbortCallbackTask(PP_CompletionCallback callback)
+ : callback_(callback) {}
+ virtual ~AbortCallbackTask() {}
+ virtual void Run() {
+ if (callback_.func)
+ PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
+ }
+
+ private:
+ PP_CompletionCallback callback_;
+};
+
+InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_Flash_TCPSocket_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+class FlashTCPSocket : public PPB_Flash_TCPSocket_API,
+ public PluginResource {
+ public:
+ FlashTCPSocket(const HostResource& resource, uint32 socket_id);
+ virtual ~FlashTCPSocket();
+
+ // ResourceObjectBase overrides.
+ virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE;
+
+ // PPB_Flash_TCPSocket_API implementation.
+ virtual int32_t Connect(const char* host,
+ uint16_t port,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t ConnectWithNetAddress(
+ const PP_Flash_NetAddress* addr,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) OVERRIDE;
+ virtual PP_Bool GetRemoteAddress(PP_Flash_NetAddress* remote_addr) OVERRIDE;
+ virtual int32_t InitiateSSL(const char* server_name,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Read(char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Write(const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual void Disconnect() OVERRIDE;
+
+ // Notifications from the proxy.
+ void OnConnectCompleted(bool succeeded,
+ const PP_Flash_NetAddress& local_addr,
+ const PP_Flash_NetAddress& remote_addr);
+ void OnReadCompleted(bool succeeded, const std::string& data);
+ void OnWriteCompleted(bool succeeded, int32_t bytes_written);
+
+ private:
+ enum ConnectionState {
+ // Before a connection is successfully established (including a connect
+ // request is pending or a previous connect request failed).
+ BEFORE_CONNECT,
+ CONNECTED,
+ DISCONNECTED
+ };
+
+ // Backend for both Connect() and ConnectWithNetAddress(). To keep things
+ // generic, the message is passed in (on error, it's deleted).
+ int32_t ConnectWithMessage(IPC::Message* msg,
+ PP_CompletionCallback callback);
+
+ void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback);
+
+ uint32 socket_id_;
+ ConnectionState connection_state_;
+
+ PP_CompletionCallback connect_callback_;
+ PP_CompletionCallback read_callback_;
+ PP_CompletionCallback write_callback_;
+
+ char* read_buffer_;
+ int32_t bytes_to_read_;
+
+ PP_Flash_NetAddress local_addr_;
+ PP_Flash_NetAddress remote_addr_;
+
+ DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket);
+};
+
+FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id)
+ : PluginResource(resource),
+ socket_id_(socket_id),
+ connection_state_(BEFORE_CONNECT),
+ connect_callback_(PP_BlockUntilComplete()),
+ read_callback_(PP_BlockUntilComplete()),
+ write_callback_(PP_BlockUntilComplete()),
+ read_buffer_(NULL),
+ bytes_to_read_(-1) {
+ DCHECK(socket_id != 0);
+
+ local_addr_.size = 0;
+ memset(local_addr_.data, 0, sizeof(local_addr_.data));
+ remote_addr_.size = 0;
+ memset(remote_addr_.data, 0, sizeof(remote_addr_.data));
+
+ if (!g_id_to_socket)
+ g_id_to_socket = new IDToSocketMap();
+ DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end());
+ (*g_id_to_socket)[socket_id] = this;
+}
+
+FlashTCPSocket::~FlashTCPSocket() {
+ Disconnect();
+}
+
+PPB_Flash_TCPSocket_API* FlashTCPSocket::AsPPB_Flash_TCPSocket_API() {
+ return this;
+}
+
+int32_t FlashTCPSocket::Connect(const char* host,
+ uint16_t port,
+ PP_CompletionCallback callback) {
+ if (!host)
+ return PP_ERROR_BADARGUMENT;
+
+ return ConnectWithMessage(
+ new PpapiHostMsg_PPBFlashTCPSocket_Connect(socket_id_, host, port),
+ callback);
+}
+
+int32_t FlashTCPSocket::ConnectWithNetAddress(
+ const PP_Flash_NetAddress* addr,
+ PP_CompletionCallback callback) {
+ if (!addr)
+ return PP_ERROR_BADARGUMENT;
+
+ return ConnectWithMessage(
+ new PpapiHostMsg_PPBFlashTCPSocket_ConnectWithNetAddress(
+ socket_id_, *addr),
+ callback);
+}
+
+PP_Bool FlashTCPSocket::GetLocalAddress(PP_Flash_NetAddress* local_addr) {
+ if (connection_state_ != CONNECTED || !local_addr)
+ return PP_FALSE;
+
+ *local_addr = local_addr_;
+ return PP_TRUE;
+}
+
+PP_Bool FlashTCPSocket::GetRemoteAddress(PP_Flash_NetAddress* remote_addr) {
+ if (connection_state_ != CONNECTED || !remote_addr)
+ return PP_FALSE;
+
+ *remote_addr = remote_addr_;
+ return PP_TRUE;
+}
+
+int32_t FlashTCPSocket::InitiateSSL(const char* server_name,
+ PP_CompletionCallback callback) {
+ // TODO(yzshen): add it.
+ return PP_ERROR_FAILED;
+}
+
+int32_t FlashTCPSocket::Read(char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) {
+ if (!buffer || bytes_to_read <= 0 || !callback.func)
+ return PP_ERROR_BADARGUMENT;
+
+ if (connection_state_ != CONNECTED)
+ return PP_ERROR_FAILED;
+ if (read_callback_.func)
+ return PP_ERROR_INPROGRESS;
+
+ read_buffer_ = buffer;
+ bytes_to_read_ = std::min(bytes_to_read, kFlashTCPSocketMaxReadSize);
+ read_callback_ = callback;
+
+ // Send the request, the browser will call us back via ReadACK.
+ GetDispatcher()->SendToBrowser(
+ new PpapiHostMsg_PPBFlashTCPSocket_Read(socket_id_, bytes_to_read_));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t FlashTCPSocket::Write(const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) {
+ if (!buffer || bytes_to_write <= 0 || !callback.func)
+ return PP_ERROR_BADARGUMENT;
+
+ if (connection_state_ != CONNECTED)
+ return PP_ERROR_FAILED;
+ if (write_callback_.func)
+ return PP_ERROR_INPROGRESS;
+
+ if (bytes_to_write > kFlashTCPSocketMaxWriteSize)
+ bytes_to_write = kFlashTCPSocketMaxWriteSize;
+
+ write_callback_ = callback;
+
+ // Send the request, the browser will call us back via WriteACK.
+ GetDispatcher()->SendToBrowser(
+ new PpapiHostMsg_PPBFlashTCPSocket_Write(
+ socket_id_, std::string(buffer, bytes_to_write)));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void FlashTCPSocket::Disconnect() {
+ if (connection_state_ == DISCONNECTED)
+ return;
+
+ connection_state_ = DISCONNECTED;
+ // After removed from the mapping, this object won't receive any notfications
+ // from the proxy.
+ DCHECK(g_id_to_socket->find(socket_id_) != g_id_to_socket->end());
+ g_id_to_socket->erase(socket_id_);
+
+ GetDispatcher()->SendToBrowser(
+ new PpapiHostMsg_PPBFlashTCPSocket_Disconnect(socket_id_));
+ socket_id_ = 0;
+
+ PostAbortAndClearIfNecessary(&connect_callback_);
+ PostAbortAndClearIfNecessary(&read_callback_);
+ PostAbortAndClearIfNecessary(&write_callback_);
+ read_buffer_ = NULL;
+ bytes_to_read_ = -1;
+}
+
+void FlashTCPSocket::OnConnectCompleted(
+ bool succeeded,
+ const PP_Flash_NetAddress& local_addr,
+ const PP_Flash_NetAddress& remote_addr) {
+ if (connection_state_ != BEFORE_CONNECT || !connect_callback_.func) {
+ NOTREACHED();
+ return;
+ }
+
+ if (succeeded) {
+ local_addr_ = local_addr;
+ remote_addr_ = remote_addr;
+ connection_state_ = CONNECTED;
+ }
+ PP_RunAndClearCompletionCallback(&connect_callback_,
+ succeeded ? PP_OK : PP_ERROR_FAILED);
+}
+
+void FlashTCPSocket::OnReadCompleted(bool succeeded, const std::string& data) {
+ if (!read_callback_.func || !read_buffer_) {
+ NOTREACHED();
+ return;
+ }
+
+ if (succeeded) {
+ CHECK_LE(static_cast<int32_t>(data.size()), bytes_to_read_);
+ if (!data.empty())
+ memcpy(read_buffer_, data.c_str(), data.size());
+ }
+ read_buffer_ = NULL;
+ bytes_to_read_ = -1;
+
+ PP_RunAndClearCompletionCallback(
+ &read_callback_,
+ succeeded ? data.size() : static_cast<int32_t>(PP_ERROR_FAILED));
+}
+
+void FlashTCPSocket::OnWriteCompleted(bool succeeded, int32_t bytes_written) {
+ if (!write_callback_.func || (succeeded && bytes_written < 0)) {
+ NOTREACHED();
+ return;
+ }
+
+ PP_RunAndClearCompletionCallback(
+ &write_callback_,
+ succeeded ? bytes_written : static_cast<int32_t>(PP_ERROR_FAILED));
+}
+
+int32_t FlashTCPSocket::ConnectWithMessage(IPC::Message* msg,
+ PP_CompletionCallback callback) {
+ scoped_ptr<IPC::Message> msg_deletor(msg);
+ if (!callback.func)
+ return PP_ERROR_BADARGUMENT;
+ if (connection_state_ != BEFORE_CONNECT)
+ return PP_ERROR_FAILED;
+ if (connect_callback_.func)
+ return PP_ERROR_INPROGRESS; // Can only have one pending request.
+
+ connect_callback_ = callback;
+ // Send the request, the browser will call us back via ConnectACK.
+ GetDispatcher()->SendToBrowser(msg_deletor.release());
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void FlashTCPSocket::PostAbortAndClearIfNecessary(
+ PP_CompletionCallback* callback) {
+ DCHECK(callback);
+
+ if (callback->func) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ new AbortCallbackTask(*callback));
+ *callback = PP_BlockUntilComplete();
+ }
+}
+
+PPB_Flash_TCPSocket_Proxy::PPB_Flash_TCPSocket_Proxy(
+ Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Flash_TCPSocket_Proxy::~PPB_Flash_TCPSocket_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPB_Flash_TCPSocket_Proxy::GetInfo() {
+ static const Info info = {
+ ::ppapi::thunk::GetPPB_Flash_TCPSocket_Thunk(),
+ PPB_FLASH_TCPSOCKET_INTERFACE,
+ INTERFACE_ID_PPB_FLASH_TCPSOCKET,
+ false,
+ &CreateFlashTCPSocketProxy,
+ };
+ return &info;
+}
+
+// static
+PP_Resource PPB_Flash_TCPSocket_Proxy::CreateProxyResource(
+ PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+
+ uint32 socket_id = 0;
+ dispatcher->SendToBrowser(new PpapiHostMsg_PPBFlashTCPSocket_Create(
+ INTERFACE_ID_PPB_FLASH_TCPSOCKET, dispatcher->plugin_dispatcher_id(),
+ &socket_id));
+ if (socket_id == 0)
+ return 0;
+
+ linked_ptr<FlashTCPSocket> object(new FlashTCPSocket(
+ HostResource::MakeInstanceOnly(instance), socket_id));
+ return PluginResourceTracker::GetInstance()->AddResource(object);
+}
+
+bool PPB_Flash_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_Flash_TCPSocket_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ConnectACK, OnMsgConnectACK)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ReadACK, OnMsgReadACK)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_Flash_TCPSocket_Proxy::OnMsgConnectACK(
+ uint32 /* plugin_dispatcher_id */,
+ uint32 socket_id,
+ bool succeeded,
+ const PP_Flash_NetAddress& local_addr,
+ const PP_Flash_NetAddress& remote_addr) {
+ if (!g_id_to_socket) {
+ NOTREACHED();
+ return;
+ }
+ IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
+ if (iter == g_id_to_socket->end())
+ return;
+ iter->second->OnConnectCompleted(succeeded, local_addr, remote_addr);
+}
+
+void PPB_Flash_TCPSocket_Proxy::OnMsgReadACK(uint32 /* plugin_dispatcher_id */,
+ uint32 socket_id,
+ bool succeeded,
+ const std::string& data) {
+ if (!g_id_to_socket) {
+ NOTREACHED();
+ return;
+ }
+ IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
+ if (iter == g_id_to_socket->end())
+ return;
+ iter->second->OnReadCompleted(succeeded, data);
+}
+
+void PPB_Flash_TCPSocket_Proxy::OnMsgWriteACK(uint32 /* plugin_dispatcher_id */,
+ uint32 socket_id,
+ bool succeeded,
+ int32_t bytes_written) {
+ if (!g_id_to_socket) {
+ NOTREACHED();
+ return;
+ }
+ IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
+ if (iter == g_id_to_socket->end())
+ return;
+ iter->second->OnWriteCompleted(succeeded, bytes_written);
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_flash_tcp_socket_proxy.h b/ppapi/proxy/ppb_flash_tcp_socket_proxy.h
new file mode 100644
index 0000000..aac9bbd
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_tcp_socket_proxy.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2011 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 PPAPI_PROXY_PPB_FLASH_TCP_SOCKET_PROXY_H_
+#define PPAPI_PROXY_PPB_FLASH_TCP_SOCKET_PROXY_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+namespace pp {
+namespace proxy {
+
+// The maximum number of bytes that each PpapiHostMsg_PPBFlashTCPSocket_Read
+// message is allowed to request.
+extern const int32_t kFlashTCPSocketMaxReadSize;
+// The maximum number of bytes that each PpapiHostMsg_PPBFlashTCPSocket_Write
+// message is allowed to carry.
+extern const int32_t kFlashTCPSocketMaxWriteSize;
+
+class PPB_Flash_TCPSocket_Proxy : public InterfaceProxy {
+ public:
+ PPB_Flash_TCPSocket_Proxy(Dispatcher* dispatcher,
+ const void* target_interface);
+ virtual ~PPB_Flash_TCPSocket_Proxy();
+
+ static const Info* GetInfo();
+
+ static PP_Resource CreateProxyResource(PP_Instance instance);
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Browser->plugin message handlers.
+ void OnMsgConnectACK(uint32 plugin_dispatcher_id,
+ uint32 socket_id,
+ bool succeeded,
+ const PP_Flash_NetAddress& local_addr,
+ const PP_Flash_NetAddress& remote_addr);
+ void OnMsgReadACK(uint32 plugin_dispatcher_id,
+ uint32 socket_id,
+ bool succeeded,
+ const std::string& data);
+ void OnMsgWriteACK(uint32 plugin_dispatcher_id,
+ uint32 socket_id,
+ bool succeeded,
+ int32_t bytes_written);
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_Flash_TCPSocket_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_FLASH_TCP_SOCKET_PROXY_H_
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index 095efb0..07d6248 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -22,6 +22,7 @@
#include "ppapi/proxy/ppb_file_system_proxy.h"
#include "ppapi/proxy/ppb_flash_menu_proxy.h"
#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
+#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h"
#include "ppapi/proxy/ppb_font_proxy.h"
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
@@ -138,6 +139,11 @@ PP_Resource ResourceCreationProxy::CreateFlashNetConnector(
return PPB_Flash_NetConnector_Proxy::CreateProxyResource(instance);
}
+PP_Resource ResourceCreationProxy::CreateFlashTCPSocket(
+ PP_Instance instance) {
+ return PPB_Flash_TCPSocket_Proxy::CreateProxyResource(instance);
+}
+
PP_Resource ResourceCreationProxy::CreateFontObject(
PP_Instance instance,
const PP_FontDescription_Dev* description) {
diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h
index 107ac3c..218607b 100644
--- a/ppapi/proxy/resource_creation_proxy.h
+++ b/ppapi/proxy/resource_creation_proxy.h
@@ -63,6 +63,7 @@ class ResourceCreationProxy : public ::ppapi::FunctionGroupBase,
virtual PP_Resource CreateFlashMenu(PP_Instance instance,
const PP_Flash_Menu* menu_data) OVERRIDE;
virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) OVERRIDE;
+ virtual PP_Resource CreateFlashTCPSocket(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateFontObject(
PP_Instance instance,
const PP_FontDescription_Dev* description) OVERRIDE;
diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h
index d61e55b..77f6dd16 100644
--- a/ppapi/shared_impl/resource_object_base.h
+++ b/ppapi/shared_impl/resource_object_base.h
@@ -23,6 +23,7 @@
F(PPB_Find_API) \
F(PPB_Flash_Menu_API) \
F(PPB_Flash_NetConnector_API) \
+ F(PPB_Flash_TCPSocket_API) \
F(PPB_Font_API) \
F(PPB_Graphics2D_API) \
F(PPB_Graphics3D_API) \
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h
index 7dd0960..d4f510d 100644
--- a/ppapi/tests/all_c_includes.h
+++ b/ppapi/tests/all_c_includes.h
@@ -82,6 +82,7 @@
#include "ppapi/c/ppp_messaging.h"
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/c/private/ppb_flash_menu.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
#include "ppapi/c/private/ppb_instance_private.h"
#include "ppapi/c/private/ppb_nacl_private.h"
#include "ppapi/c/private/ppb_pdf.h"
diff --git a/ppapi/thunk/ppb_flash_tcp_socket_api.h b/ppapi/thunk/ppb_flash_tcp_socket_api.h
new file mode 100644
index 0000000..d18eb6e
--- /dev/null
+++ b/ppapi/thunk/ppb_flash_tcp_socket_api.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2011 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 PPAPI_THUNK_PPB_FLASH_TCP_SOCKET_API_H_
+#define PPAPI_THUNK_PPB_FLASH_TCP_SOCKET_API_H_
+
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
+
+namespace ppapi {
+namespace thunk {
+
+class PPB_Flash_TCPSocket_API {
+ public:
+ virtual ~PPB_Flash_TCPSocket_API() {}
+
+ virtual int32_t Connect(const char* host,
+ uint16_t port,
+ PP_CompletionCallback callback) = 0;
+ virtual int32_t ConnectWithNetAddress(const PP_Flash_NetAddress* addr,
+ PP_CompletionCallback callback) = 0;
+ virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) = 0;
+ virtual PP_Bool GetRemoteAddress(PP_Flash_NetAddress* remote_addr) = 0;
+ virtual int32_t InitiateSSL(const char* server_name,
+ PP_CompletionCallback callback) = 0;
+ virtual int32_t Read(char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) = 0;
+ virtual int32_t Write(const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) = 0;
+ virtual void Disconnect() = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_PPB_FLASH_TCP_SOCKET_API_H_
diff --git a/ppapi/thunk/ppb_flash_tcp_socket_thunk.cc b/ppapi/thunk/ppb_flash_tcp_socket_thunk.cc
new file mode 100644
index 0000000..815dd53
--- /dev/null
+++ b/ppapi/thunk/ppb_flash_tcp_socket_thunk.cc
@@ -0,0 +1,121 @@
+// Copyright (c) 2011 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 "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/private/ppb_flash_tcp_socket.h"
+#include "ppapi/thunk/thunk.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_flash_tcp_socket_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+PP_Resource Create(PP_Instance instance) {
+ EnterFunction<ResourceCreationAPI> enter(instance, true);
+ if (enter.failed())
+ return 0;
+ return enter.functions()->CreateFlashTCPSocket(instance);
+}
+
+PP_Bool IsFlashTCPSocket(PP_Resource resource) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(resource, false);
+ return PP_FromBool(enter.succeeded());
+}
+
+int32_t Connect(PP_Resource tcp_socket,
+ const char* host,
+ uint16_t port,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+ return enter.object()->Connect(host, port, callback);
+}
+
+int32_t ConnectWithNetAddress(PP_Resource tcp_socket,
+ const PP_Flash_NetAddress* addr,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+ return enter.object()->ConnectWithNetAddress(addr, callback);
+}
+
+PP_Bool GetLocalAddress(PP_Resource tcp_socket,
+ PP_Flash_NetAddress* local_addr) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_FALSE;
+ return enter.object()->GetLocalAddress(local_addr);
+}
+
+PP_Bool GetRemoteAddress(PP_Resource tcp_socket,
+ PP_Flash_NetAddress* remote_addr) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_FALSE;
+ return enter.object()->GetRemoteAddress(remote_addr);
+}
+
+int32_t InitiateSSL(PP_Resource tcp_socket,
+ const char* server_name,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+ return enter.object()->InitiateSSL(server_name, callback);
+}
+
+int32_t Read(PP_Resource tcp_socket,
+ char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+ return enter.object()->Read(buffer, bytes_to_read, callback);
+}
+
+int32_t Write(PP_Resource tcp_socket,
+ const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+ return enter.object()->Write(buffer, bytes_to_write, callback);
+}
+
+void Disconnect(PP_Resource tcp_socket) {
+ EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true);
+ if (enter.succeeded())
+ enter.object()->Disconnect();
+}
+
+const PPB_Flash_TCPSocket g_ppb_flash_tcp_socket_thunk = {
+ &Create,
+ &IsFlashTCPSocket,
+ &Connect,
+ &ConnectWithNetAddress,
+ &GetLocalAddress,
+ &GetRemoteAddress,
+ &InitiateSSL,
+ &Read,
+ &Write,
+ &Disconnect
+};
+
+} // namespace
+
+const PPB_Flash_TCPSocket* GetPPB_Flash_TCPSocket_Thunk() {
+ return &g_ppb_flash_tcp_socket_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
+
diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h
index c998b56..e2e5ba1 100644
--- a/ppapi/thunk/resource_creation_api.h
+++ b/ppapi/thunk/resource_creation_api.h
@@ -63,6 +63,7 @@ class ResourceCreationAPI {
virtual PP_Resource CreateFlashMenu(PP_Instance instance,
const PP_Flash_Menu* menu_data) = 0;
virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) = 0;
+ virtual PP_Resource CreateFlashTCPSocket(PP_Instance instace) = 0;
// Note: can't be called CreateFont due to Windows #defines.
virtual PP_Resource CreateFontObject(
PP_Instance instance,
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index 645c5c6..9fb84b3 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -24,6 +24,7 @@ struct PPB_FileSystem_Dev;
struct PPB_Find_Dev;
struct PPB_Flash_Menu;
struct PPB_Flash_NetConnector;
+struct PPB_Flash_TCPSocket;
struct PPB_Font_Dev;
struct PPB_Fullscreen_Dev;
struct PPB_GLESChromiumTextureMapping_Dev;
@@ -75,6 +76,7 @@ const PPB_FileSystem_Dev* GetPPB_FileSystem_Thunk();
const PPB_Find_Dev* GetPPB_Find_Thunk();
const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk();
const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_Thunk();
+const PPB_Flash_TCPSocket* GetPPB_Flash_TCPSocket_Thunk();
const PPB_Font_Dev* GetPPB_Font_Thunk();
const PPB_Fullscreen_Dev* GetPPB_Fullscreen_Thunk();
const PPB_GLESChromiumTextureMapping_Dev*