summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-29 19:16:23 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-29 19:16:23 +0000
commit7d3782f9d79e1437b22a8c2908cb1aed813b9e52 (patch)
tree6371e4a0d63c2817669ec189c91e2452be8a2edc /ppapi/proxy
parentc8ee99efa1bdd2d47abb70fd96571f041add7983 (diff)
downloadchromium_src-7d3782f9d79e1437b22a8c2908cb1aed813b9e52.zip
chromium_src-7d3782f9d79e1437b22a8c2908cb1aed813b9e52.tar.gz
chromium_src-7d3782f9d79e1437b22a8c2908cb1aed813b9e52.tar.bz2
Implement proxy for PPB_Flash_NetConnector.
TEST=manual BUG=none Review URL: http://codereview.chromium.org/6698064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79718 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r--ppapi/proxy/dispatcher.cc6
-rw-r--r--ppapi/proxy/interface_id.h1
-rw-r--r--ppapi/proxy/plugin_resource.h1
-rw-r--r--ppapi/proxy/ppapi_messages.h19
-rw-r--r--ppapi/proxy/ppb_flash_net_connector_proxy.cc326
-rw-r--r--ppapi/proxy/ppb_flash_net_connector_proxy.h66
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.cc2
7 files changed, 420 insertions, 1 deletions
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index 9313094..c0b71c6 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -41,6 +41,7 @@
#include "ppapi/c/private/ppb_flash_clipboard.h"
#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_pdf.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
#include "ppapi/proxy/ppapi_messages.h"
@@ -59,6 +60,7 @@
#include "ppapi/proxy/ppb_flash_file_proxy.h"
#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_font_proxy.h"
#include "ppapi/proxy/ppb_fullscreen_proxy.h"
#include "ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h"
@@ -137,6 +139,10 @@ InterfaceList::InterfaceList() {
AddPPB(PPB_URLUtil_Proxy::GetInfo());
AddPPB(PPB_Var_Deprecated_Proxy::GetInfo());
+#ifdef ENABLE_FLAPPER_HACKS
+ AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo());
+#endif
+
// PPP (plugin) interfaces.
AddPPP(PPP_Instance_Proxy::GetInfo());
}
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index da8d859..6e8c6e3 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -29,6 +29,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_FLASH_FILE_FILEREF,
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
INTERFACE_ID_PPB_FLASH_MENU,
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
INTERFACE_ID_PPB_FONT,
INTERFACE_ID_PPB_FULLSCREEN,
INTERFACE_ID_PPB_GLES_CHROMIUM_TM,
diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h
index 0b4ef24..1a5e081 100644
--- a/ppapi/proxy/plugin_resource.h
+++ b/ppapi/proxy/plugin_resource.h
@@ -21,6 +21,7 @@
F(FileRef) \
F(FileSystem) \
F(FlashMenu) \
+ F(FlashNetConnector) \
F(Font) \
F(Graphics2D) \
F(ImageData) \
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 00668b1..d40c5a46 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -96,6 +96,14 @@ IPC_MESSAGE_ROUTED2(
pp::proxy::HostResource /* filesystem */,
int32_t /* result */)
+// PPB_Flash_NetConnector.
+IPC_MESSAGE_ROUTED5(PpapiMsg_PPBFlashNetConnector_ConnectACK,
+ pp::proxy::HostResource /* net_connector */,
+ int32_t /* result */,
+ IPC::PlatformFileForTransit /* handle */,
+ std::string /* local_addr_as_string */,
+ std::string /* remote_addr_as_string */)
+
// PPB_Graphics2D.
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics2D_FlushACK,
pp::proxy::HostResource /* graphics_2d */,
@@ -463,6 +471,17 @@ IPC_MESSAGE_ROUTED3(PpapiMsg_PPBFlashMenu_ShowACK,
int32_t /* selected_id */,
int32_t /* result */)
+// PPB_Flash_NetConnector.
+IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFlashNetConnector_Create,
+ PP_Instance /* instance_id */,
+ pp::proxy::HostResource /* result */)
+IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFlashNetConnector_ConnectTcp,
+ pp::proxy::HostResource /* connector */,
+ std::string /* host */,
+ uint16_t /* port */)
+IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress,
+ pp::proxy::HostResource /* connector */,
+ std::string /* net_address_as_string */)
// PPB_Font.
IPC_SYNC_MESSAGE_ROUTED2_3(
diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.cc b/ppapi/proxy/ppb_flash_net_connector_proxy.cc
new file mode 100644
index 0000000..3a3d620
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_net_connector_proxy.cc
@@ -0,0 +1,326 @@
+// 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_net_connector_proxy.h"
+
+#include <algorithm>
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/private/ppb_flash_net_connector.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/serialized_var.h"
+
+namespace pp {
+namespace proxy {
+
+std::string NetAddressToString(const PP_Flash_NetAddress& addr) {
+ return std::string(addr.data, std::min(static_cast<size_t>(addr.size),
+ sizeof(addr.data)));
+}
+
+void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) {
+ memcpy(addr->data, str.data(), std::min(str.size(), sizeof(addr->data)));
+}
+
+class FlashNetConnector : public PluginResource {
+ public:
+ FlashNetConnector(const HostResource& resource)
+ : PluginResource(resource),
+ callback_(PP_BlockUntilComplete()),
+ local_addr_out_(NULL),
+ remote_addr_out_(NULL) {
+ }
+ ~FlashNetConnector() {
+ if (callback_.func)
+ PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
+ }
+
+ // Resource overrides.
+ virtual FlashNetConnector* AsFlashNetConnector() {
+ return this;
+ }
+
+ bool HasCallback() const {
+ return callback_.func != NULL;
+ }
+
+ void SetCallback(const PP_CompletionCallback& callback,
+ PP_FileHandle* socket_out,
+ PP_Flash_NetAddress* local_addr_out,
+ PP_Flash_NetAddress* remote_addr_out) {
+ callback_ = callback;
+ socket_out_ = socket_out;
+ local_addr_out_ = local_addr_out;
+ remote_addr_out_ = remote_addr_out;
+ }
+
+ void ConnectComplete(int32_t result,
+ base::PlatformFile file,
+ const std::string& local_addr_as_string,
+ const std::string& remote_addr_as_string) {
+ if (!callback_.func) {
+ base::ClosePlatformFile(file);
+ return;
+ }
+
+ *socket_out_ = static_cast<PP_FileHandle>(file);
+ StringToNetAddress(local_addr_as_string, local_addr_out_);
+ StringToNetAddress(remote_addr_as_string, remote_addr_out_);
+
+ PP_CompletionCallback temp_callback = callback_;
+ callback_ = PP_BlockUntilComplete();
+ PP_RunCompletionCallback(&temp_callback, result);
+ }
+
+ private:
+ PP_CompletionCallback callback_;
+ PP_FileHandle* socket_out_;
+ PP_Flash_NetAddress* local_addr_out_;
+ PP_Flash_NetAddress* remote_addr_out_;
+};
+
+// Contains the data that the host interface will write to so we can send it
+// to the plugin. This is created when a request is initiated, and deleted in
+// the callback handler.
+struct PPB_Flash_NetConnector_Proxy::ConnectCallbackInfo {
+ ConnectCallbackInfo(const HostResource& r) : resource(r), handle(0) {
+ local_addr.size = 0;
+ remote_addr.size = 0;
+ }
+
+ HostResource resource;
+
+ PP_FileHandle handle;
+ PP_Flash_NetAddress local_addr;
+ PP_Flash_NetAddress remote_addr;
+};
+
+namespace {
+
+PP_Resource Create(PP_Instance instance_id) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return 0;
+
+ HostResource result;
+ dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create(
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance_id, &result));
+ if (result.is_null())
+ return 0;
+
+ linked_ptr<FlashNetConnector> object(new FlashNetConnector(result));
+ return PluginResourceTracker::GetInstance()->AddResource(object);
+}
+
+PP_Bool IsFlashNetConnector(PP_Resource resource_id) {
+ FlashNetConnector* object =
+ PluginResource::GetAs<FlashNetConnector>(resource_id);
+ return BoolToPPBool(!!object);
+}
+
+// Backend for both ConnectTcp and ConnectTcpAddress. To keep things generic,
+// the message is passed in (on error, it's deleted).
+int32_t ConnectWithMessage(FlashNetConnector* object,
+ IPC::Message* msg,
+ PP_FileHandle* socket_out,
+ struct PP_Flash_NetAddress* local_addr_out,
+ struct PP_Flash_NetAddress* remote_addr_out,
+ struct PP_CompletionCallback callback) {
+ scoped_ptr<IPC::Message> msg_deletor(msg);
+ if (object->HasCallback())
+ return PP_ERROR_INPROGRESS; // Can only have one pending request.
+
+ // Send the request, it will call us back via ConnectACK.
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+ dispatcher->Send(msg_deletor.release());
+
+ object->SetCallback(callback, socket_out, local_addr_out, remote_addr_out);
+ return PP_ERROR_WOULDBLOCK;
+}
+
+int32_t ConnectTcp(PP_Resource connector_id,
+ const char* host,
+ uint16_t port,
+ PP_FileHandle* socket_out,
+ struct PP_Flash_NetAddress* local_addr_out,
+ struct PP_Flash_NetAddress* remote_addr_out,
+ struct PP_CompletionCallback callback) {
+ FlashNetConnector* object =
+ PluginResource::GetAs<FlashNetConnector>(connector_id);
+ if (!object)
+ return PP_ERROR_BADARGUMENT;
+ return ConnectWithMessage(
+ object,
+ new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp(
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
+ object->host_resource(), host, port),
+ socket_out, local_addr_out, remote_addr_out, callback);
+}
+
+int32_t ConnectTcpAddress(PP_Resource connector_id,
+ const struct PP_Flash_NetAddress* addr,
+ PP_FileHandle* socket_out,
+ struct PP_Flash_NetAddress* local_addr_out,
+ struct PP_Flash_NetAddress* remote_addr_out,
+ struct PP_CompletionCallback callback) {
+ FlashNetConnector* object =
+ PluginResource::GetAs<FlashNetConnector>(connector_id);
+ if (!object)
+ return PP_ERROR_BADARGUMENT;
+ return ConnectWithMessage(
+ object,
+ new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress(
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
+ object->host_resource(), NetAddressToString(*addr)),
+ socket_out, local_addr_out, remote_addr_out, callback);
+}
+
+const PPB_Flash_NetConnector flash_netconnector_interface = {
+ &Create,
+ &IsFlashNetConnector,
+ &ConnectTcp,
+ &ConnectTcpAddress
+};
+
+InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_Flash_NetConnector_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPB_Flash_NetConnector_Proxy::PPB_Flash_NetConnector_Proxy(
+ Dispatcher* dispatcher, const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+}
+
+PPB_Flash_NetConnector_Proxy::~PPB_Flash_NetConnector_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPB_Flash_NetConnector_Proxy::GetInfo() {
+ static const Info info = {
+ &flash_netconnector_interface,
+ PPB_FLASH_NETCONNECTOR_INTERFACE,
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
+ false,
+ &CreateFlashNetConnectorProxy
+ };
+ return &info;
+}
+
+bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_Flash_NetConnector_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_Create,
+ OnMsgCreate)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcp,
+ OnMsgConnectTcp)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress,
+ OnMsgConnectTcpAddress)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashNetConnector_ConnectACK,
+ OnMsgConnectACK)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_Flash_NetConnector_Proxy::OnMsgCreate(PP_Instance instance_id,
+ HostResource* result) {
+ result->SetHostResource(
+ instance_id,
+ ppb_flash_net_connector_target()->Create(instance_id));
+}
+
+void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp(
+ const HostResource& resource,
+ const std::string& host,
+ uint16_t port) {
+ ConnectCallbackInfo* info = new ConnectCallbackInfo(resource);
+ CompletionCallback callback = callback_factory_.NewCallback(
+ &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info);
+
+ int32_t result = ppb_flash_net_connector_target()->ConnectTcp(
+ resource.host_resource(), host.c_str(), port,
+ &info->handle, &info->local_addr, &info->remote_addr,
+ callback.pp_completion_callback());
+ if (result != PP_ERROR_WOULDBLOCK)
+ OnCompleteCallbackInHost(result, info);
+}
+
+void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcpAddress(
+ const HostResource& resource,
+ const std::string& net_address_as_string) {
+ ConnectCallbackInfo* info = new ConnectCallbackInfo(resource);
+ CompletionCallback callback = callback_factory_.NewCallback(
+ &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info);
+
+ PP_Flash_NetAddress net_address;
+ StringToNetAddress(net_address_as_string, &net_address);
+
+ int32_t result = ppb_flash_net_connector_target()->ConnectTcpAddress(
+ resource.host_resource(), &net_address,
+ &info->handle, &info->local_addr, &info->remote_addr,
+ callback.pp_completion_callback());
+ if (result != PP_ERROR_WOULDBLOCK)
+ OnCompleteCallbackInHost(result, info);
+}
+
+void PPB_Flash_NetConnector_Proxy::OnMsgConnectACK(
+ const HostResource& host_resource,
+ int32_t result,
+ IPC::PlatformFileForTransit handle,
+ const std::string& load_addr_as_string,
+ const std::string& remote_addr_as_string) {
+ base::PlatformFile platform_file =
+ IPC::PlatformFileForTransitToPlatformFile(handle);
+
+ PP_Resource plugin_resource =
+ PluginResourceTracker::GetInstance()->PluginResourceForHostResource(
+ host_resource);
+ if (!plugin_resource) {
+ base::ClosePlatformFile(platform_file);
+ return;
+ }
+ FlashNetConnector* object =
+ PluginResource::GetAs<FlashNetConnector>(plugin_resource);
+ if (!object) {
+ base::ClosePlatformFile(platform_file);
+ return;
+ }
+
+ object->ConnectComplete(result, platform_file,
+ load_addr_as_string, remote_addr_as_string);
+}
+
+void PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost(
+ int32_t result,
+ ConnectCallbackInfo* info) {
+ // Callback must always delete the info.
+ scoped_ptr<ConnectCallbackInfo> info_deletor(info);
+
+ if (result == PP_OK) {
+ dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK(
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
+ info->resource, result,
+ dispatcher()->ShareHandleWithRemote(
+ static_cast<base::PlatformFile>(info->handle), true),
+ NetAddressToString(info->local_addr),
+ NetAddressToString(info->remote_addr)));
+ } else {
+ dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK(
+ INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
+ info->resource, result,
+ IPC::InvalidPlatformFileForTransit(), std::string(), std::string()));
+ }
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.h b/ppapi/proxy/ppb_flash_net_connector_proxy.h
new file mode 100644
index 0000000..aced8f8
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_net_connector_proxy.h
@@ -0,0 +1,66 @@
+// 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_NET_CONNECTOR_PROXY_H_
+#define PPAPI_PROXY_PPB_FLASH_NET_CONNECTOR_PROXY_H_
+
+#include "base/platform_file.h"
+#include "ipc/ipc_platform_file.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/proxy/interface_proxy.h"
+#include "ppapi/proxy/proxy_non_thread_safe_ref_count.h"
+
+struct PPB_Flash_NetConnector;
+
+namespace pp {
+namespace proxy {
+
+class HostResource;
+
+class PPB_Flash_NetConnector_Proxy : public InterfaceProxy {
+ public:
+ PPB_Flash_NetConnector_Proxy(Dispatcher* dispatcher,
+ const void* target_interface);
+ virtual ~PPB_Flash_NetConnector_Proxy();
+
+ static const Info* GetInfo();
+
+ const PPB_Flash_NetConnector* ppb_flash_net_connector_target() const {
+ return reinterpret_cast<const PPB_Flash_NetConnector*>(
+ target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ struct ConnectCallbackInfo;
+
+ // Plugin->host message handlers.
+ void OnMsgCreate(PP_Instance instance,
+ HostResource* result);
+ void OnMsgConnectTcp(const HostResource& resource,
+ const std::string& host,
+ uint16_t port);
+ void OnMsgConnectTcpAddress(const HostResource& resource_id,
+ const std::string& net_address_as_string);
+
+ // Host->plugin message handler.
+ void OnMsgConnectACK(const HostResource& host_resource,
+ int32_t result,
+ IPC::PlatformFileForTransit handle,
+ const std::string& load_addr_as_string,
+ const std::string& remote_addr_as_string);
+
+ void OnCompleteCallbackInHost(int32_t result, ConnectCallbackInfo* info);
+
+ CompletionCallbackFactory<PPB_Flash_NetConnector_Proxy,
+ ProxyNonThreadSafeRefCount> callback_factory_;
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_FLASH_NET_CONNECTOR_PROXY_H_
diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc
index a38b620..3a2f788 100644
--- a/ppapi/proxy/ppb_image_data_proxy.cc
+++ b/ppapi/proxy/ppb_image_data_proxy.cc
@@ -152,7 +152,7 @@ PP_Resource Create(PP_Instance instance,
PP_Bool init_to_zero) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
- return PP_ERROR_BADARGUMENT;
+ return 0;
HostResource result;
std::string image_data_desc;