summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/trusted/ppp_broker.h10
-rw-r--r--ppapi/proxy/broker_dispatcher.cc55
-rw-r--r--ppapi/proxy/broker_dispatcher.h16
-rw-r--r--ppapi/proxy/ppapi_messages.h6
4 files changed, 72 insertions, 15 deletions
diff --git a/ppapi/c/trusted/ppp_broker.h b/ppapi/c/trusted/ppp_broker.h
index 09cd570..923c1828 100644
--- a/ppapi/c/trusted/ppp_broker.h
+++ b/ppapi/c/trusted/ppp_broker.h
@@ -37,14 +37,16 @@ extern "C" {
/**
* PP_ConnectInstance_Func defines the signature that you implement to
- * receive notifications when a new instance connects to the broker.
+ * receive notifications when a plugin instance connects to the broker.
+ * The broker should listen on the socket before returning.
*
* @param[in] instance The plugin instance connecting to the broker.
- * @param[in] socket Handle to a socket the broker can use to communicate with
- * the instance.
+ * @param[in] handle Handle to a socket the broker can use to communicate with
+ * the plugin.
* @return PP_OK on success. Any other value on failure.
*/
-typedef int32_t (*PP_ConnectInstance_Func)(PP_Instance instance, int socket);
+typedef int32_t (*PP_ConnectInstance_Func)(PP_Instance instance,
+ int32_t handle);
/**
* @}
*/
diff --git a/ppapi/proxy/broker_dispatcher.cc b/ppapi/proxy/broker_dispatcher.cc
index f72f37a..ff86212 100644
--- a/ppapi/proxy/broker_dispatcher.cc
+++ b/ppapi/proxy/broker_dispatcher.cc
@@ -4,15 +4,31 @@
#include "ppapi/proxy/broker_dispatcher.h"
+#include "base/sync_socket.h"
+#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
namespace proxy {
+namespace {
+
+int32_t PlatformFileToInt(base::PlatformFile handle) {
+#if defined(OS_WIN)
+ return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle));
+#elif defined(OS_POSIX)
+ return handle;
+#else
+ #error Not implemented.
+#endif
+}
+
+} // namespace
+
BrokerDispatcher::BrokerDispatcher(base::ProcessHandle remote_process_handle,
PP_ConnectInstance_Func connect_instance)
- : ProxyChannel(remote_process_handle) {
- // TODO(ddorwin): Do something with connect_instance.
+ : ProxyChannel(remote_process_handle),
+ connect_instance_(connect_instance) {
}
BrokerDispatcher::~BrokerDispatcher() {
@@ -29,17 +45,44 @@ bool BrokerDispatcher::OnMessageReceived(const IPC::Message& msg) {
// Control messages.
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
bool handled = true;
- // TODO(ddorwin): Implement. Don't build empty block - fails on Windows.
-#if 0
IPC_BEGIN_MESSAGE_MAP(BrokerDispatcher, msg)
- // IPC_MESSAGE_FORWARD(PpapiMsg_ConnectToInstance)
+ IPC_MESSAGE_HANDLER(PpapiMsg_ConnectToPlugin, OnMsgConnectToPlugin)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
-#endif
return handled;
}
return false;
}
+// Transfers ownership of the handle to the broker module.
+void BrokerDispatcher::OnMsgConnectToPlugin(
+ PP_Instance instance,
+ IPC::PlatformFileForTransit handle) {
+ int32_t result = PP_OK;
+ if (handle == IPC::InvalidPlatformFileForTransit()) {
+ result = PP_ERROR_FAILED;
+ } else {
+ base::SyncSocket::Handle socket_handle =
+ IPC::PlatformFileForTransitToPlatformFile(handle);
+
+ if (connect_instance_) {
+ result = connect_instance_(instance, PlatformFileToInt(socket_handle));
+ } else {
+ result = PP_ERROR_FAILED;
+ // Close the handle since there is no other owner.
+ // The easiest way to clean it up is to just put it in an object
+ // and then close them. This failure case is not performance critical.
+ base::SyncSocket temp_socket(socket_handle);
+ }
+ }
+
+ // TODO(ddorwin): Report result via IPC.
+}
+
+BrokerHostDispatcher::BrokerHostDispatcher(
+ base::ProcessHandle remote_process_handle)
+ : BrokerDispatcher(remote_process_handle, NULL) {
+}
+
} // namespace proxy
} // namespace pp
diff --git a/ppapi/proxy/broker_dispatcher.h b/ppapi/proxy/broker_dispatcher.h
index 6b0673b..e451218 100644
--- a/ppapi/proxy/broker_dispatcher.h
+++ b/ppapi/proxy/broker_dispatcher.h
@@ -22,11 +22,6 @@ class BrokerDispatcher : public ProxyChannel {
const IPC::ChannelHandle& channel_handle,
bool is_client);
- // Returns true if the dispatcher is on the broker side, or false if it's the
- // browser side.
- // TODO(ddorwin): Implement.
- // virtual bool IsBroker() const = 0;
-
// IPC::Channel::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
@@ -35,10 +30,21 @@ class BrokerDispatcher : public ProxyChannel {
BrokerDispatcher(base::ProcessHandle remote_process_handle,
PP_ConnectInstance_Func connect_instance);
+ void OnMsgConnectToPlugin(PP_Instance instance,
+ IPC::PlatformFileForTransit handle);
+
+ PP_ConnectInstance_Func connect_instance_;
+
private:
DISALLOW_COPY_AND_ASSIGN(BrokerDispatcher);
};
+// A simple class for broker hosts.
+class BrokerHostDispatcher : public BrokerDispatcher {
+ public:
+ BrokerHostDispatcher(base::ProcessHandle remote_process_handle);
+};
+
} // namespace proxy
} // namespace pp
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 3749961..2870a4a 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -67,6 +67,12 @@ IPC_MESSAGE_CONTROL2(PpapiMsg_ExecuteCallback,
uint32 /* serialized_callback */,
int32 /* param */)
+// Broker Process.
+
+IPC_SYNC_MESSAGE_CONTROL2_0(PpapiMsg_ConnectToPlugin,
+ PP_Instance /* instance */,
+ IPC::PlatformFileForTransit /* handle */)
+
// PPB_Audio.
// Notifies the result of the audio stream create call. This is called in