summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/host_dispatcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/proxy/host_dispatcher.cc')
-rw-r--r--ppapi/proxy/host_dispatcher.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/ppapi/proxy/host_dispatcher.cc b/ppapi/proxy/host_dispatcher.cc
index c196c14..7978786 100644
--- a/ppapi/proxy/host_dispatcher.cc
+++ b/ppapi/proxy/host_dispatcher.cc
@@ -30,6 +30,9 @@ HostDispatcher::HostDispatcher(base::ProcessHandle remote_process_handle,
static_cast<const PPB_Var_Deprecated*>(
local_get_interface(PPB_VAR_DEPRECATED_INTERFACE));
SetSerializationRules(new HostVarSerializationRules(var_interface, module));
+
+ memset(plugin_interface_support_, 0,
+ sizeof(PluginInterfaceSupport) * INTERFACE_ID_COUNT);
}
HostDispatcher::~HostDispatcher() {
@@ -76,6 +79,68 @@ bool HostDispatcher::IsPlugin() const {
return false;
}
+bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) {
+ // Handle common control messages.
+ if (Dispatcher::OnMessageReceived(msg))
+ return true;
+
+ if (msg.routing_id() <= 0 && msg.routing_id() >= INTERFACE_ID_COUNT) {
+ NOTREACHED();
+ // TODO(brettw): kill the plugin if it starts sending invalid messages?
+ return true;
+ }
+
+ InterfaceProxy* proxy = target_proxies_[msg.routing_id()].get();
+ if (!proxy) {
+ // Autocreate any proxy objects to handle requests from the plugin. Since
+ // we always support all known PPB_* interfaces (modulo the trusted bit),
+ // there's very little checking necessary.
+ const InterfaceProxy::Info* info = GetPPBInterfaceInfo(
+ static_cast<InterfaceID>(msg.routing_id()));
+ if (!info ||
+ (info->is_trusted && disallow_trusted_interfaces()))
+ return true;
+
+ const void* local_interface = GetLocalInterface(info->name);
+ if (!local_interface) {
+ // This should always succeed since the browser should support the stuff
+ // the proxy does. If this happens, something is out of sync.
+ NOTREACHED();
+ return true;
+ }
+
+ proxy = info->create_proxy(this, local_interface);
+ target_proxies_[info->id].reset(proxy);
+ }
+
+ return proxy->OnMessageReceived(msg);
+}
+
+const void* HostDispatcher::GetProxiedInterface(const std::string& interface) {
+ // First see if we even have a proxy for this interface.
+ const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface);
+ if (!info)
+ return NULL;
+
+ if (plugin_interface_support_[static_cast<int>(info->id)] !=
+ INTERFACE_UNQUERIED) {
+ // Already queried the plugin if it supports this interface.
+ if (plugin_interface_support_[info->id] == INTERFACE_SUPPORTED)
+ return info->interface;
+ return NULL;
+ }
+
+ // Need to re-query. Cache the result so we only do this once.
+ bool supported = false;
+ Send(new PpapiMsg_SupportsInterface(interface, &supported));
+ plugin_interface_support_[static_cast<int>(info->id)] =
+ supported ? INTERFACE_SUPPORTED : INTERFACE_UNSUPPORTED;
+
+ if (supported)
+ return info->interface;
+ return NULL;
+}
+
} // namespace proxy
} // namespace pp