blob: 988f53da8d088aeaccf839d7e8d8a34c19efa576 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]c2932f5e2010-11-03 03:22:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PPAPI_PROXY_DISPATCHER_H_
6#define PPAPI_PROXY_DISPATCHER_H_
7
[email protected]2cc062242011-03-10 21:16:348#include <set>
[email protected]c2932f5e2010-11-03 03:22:339#include <string>
10#include <vector>
11
[email protected]7a1f7c6f2011-05-10 21:17:4812#include "base/callback.h"
13#include "base/tracked_objects.h"
[email protected]1609d0d2011-04-15 22:06:2114#include "ipc/ipc_channel_proxy.h"
[email protected]2cc062242011-03-10 21:16:3415#include "ppapi/c/pp_instance.h"
[email protected]c2932f5e2010-11-03 03:22:3316#include "ppapi/c/pp_module.h"
[email protected]e2614c62011-04-16 22:12:4517#include "ppapi/proxy/proxy_channel.h"
[email protected]5c966022011-09-13 18:09:3718#include "ppapi/proxy/interface_list.h"
[email protected]465faa22011-02-08 16:31:4619#include "ppapi/proxy/interface_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3320#include "ppapi/proxy/plugin_var_tracker.h"
[email protected]ac4b54d2011-10-20 23:09:2821#include "ppapi/shared_impl/api_id.h"
[email protected]c2932f5e2010-11-03 03:22:3322
[email protected]55cdf6052011-05-13 19:22:5323namespace ppapi {
[email protected]7a1f7c6f2011-05-10 21:17:4824
[email protected]4d2efd22011-08-18 21:58:0225class WebKitForwarding;
26
[email protected]c2932f5e2010-11-03 03:22:3327namespace proxy {
28
[email protected]c2932f5e2010-11-03 03:22:3329class VarSerializationRules;
30
31// An interface proxy can represent either end of a cross-process interface
32// call. The "source" side is where the call is invoked, and the "target" side
33// is where the call ends up being executed.
34//
35// Plugin side | Browser side
36// -------------------------------------|--------------------------------------
37// |
38// "Source" | "Target"
39// InterfaceProxy ----------------------> InterfaceProxy
40// |
41// |
42// "Target" | "Source"
43// InterfaceProxy <---------------------- InterfaceProxy
44// |
[email protected]f0a04c42011-08-26 22:43:2045class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel {
[email protected]c2932f5e2010-11-03 03:22:3346 public:
47 typedef const void* (*GetInterfaceFunc)(const char*);
[email protected]9c7baaef2010-11-10 05:42:4648 typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc);
[email protected]c2932f5e2010-11-03 03:22:3349
[email protected]4f15d2842011-02-15 17:36:3350 virtual ~Dispatcher();
[email protected]c2932f5e2010-11-03 03:22:3351
[email protected]c2932f5e2010-11-03 03:22:3352 // Returns true if the dispatcher is on the plugin side, or false if it's the
53 // browser side.
54 virtual bool IsPlugin() const = 0;
55
56 VarSerializationRules* serialization_rules() const {
57 return serialization_rules_.get();
58 }
[email protected]c2932f5e2010-11-03 03:22:3359
[email protected]5c966022011-09-13 18:09:3760 // Returns a non-owning pointer to the interface proxy for the given ID, or
61 // NULL if the ID isn't found. This will create the proxy if it hasn't been
62 // created so far.
[email protected]ac4b54d2011-10-20 23:09:2863 InterfaceProxy* GetInterfaceProxy(ApiID id);
[email protected]c2932f5e2010-11-03 03:22:3364
[email protected]1609d0d2011-04-15 22:06:2165 // Returns the pointer to the IO thread for processing IPC messages.
66 // TODO(brettw) remove this. It's a hack to support the Flash
67 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this
68 // implementation detail should be hidden.
[email protected]92bf9062011-05-02 18:00:4969 base::MessageLoopProxy* GetIPCMessageLoop();
[email protected]1609d0d2011-04-15 22:06:2170
71 // Adds the given filter to the IO thread. Takes ownership of the pointer.
72 // TODO(brettw) remove this. It's a hack to support the Flash
73 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this
74 // implementation detail should be hidden.
75 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter);
76
[email protected]e2614c62011-04-16 22:12:4577 // TODO(brettw): What is this comment referring to?
[email protected]c2932f5e2010-11-03 03:22:3378 // Called if the remote side is declaring to us which interfaces it supports
79 // so we don't have to query for each one. We'll pre-create proxies for
80 // each of the given interfaces.
81
[email protected]c2932f5e2010-11-03 03:22:3382 // IPC::Channel::Listener implementation.
[email protected]a95986a82010-12-24 06:19:2883 virtual bool OnMessageReceived(const IPC::Message& msg);
[email protected]c2932f5e2010-11-03 03:22:3384
[email protected]5c966022011-09-13 18:09:3785 GetInterfaceFunc local_get_interface() const { return local_get_interface_; }
[email protected]465faa22011-02-08 16:31:4686
[email protected]c2932f5e2010-11-03 03:22:3387 protected:
[email protected]5d84d012010-12-02 17:17:2188 Dispatcher(base::ProcessHandle remote_process_handle,
89 GetInterfaceFunc local_get_interface);
[email protected]c2932f5e2010-11-03 03:22:3390
[email protected]c2932f5e2010-11-03 03:22:3391 // Setter for the derived classes to set the appropriate var serialization.
92 // Takes ownership of the given pointer, which must be on the heap.
93 void SetSerializationRules(VarSerializationRules* var_serialization_rules);
94
[email protected]5c966022011-09-13 18:09:3795 // Called when an invalid message is received from the remote site. The
96 // default implementation does nothing, derived classes can override.
97 virtual void OnInvalidMessageReceived();
98
[email protected]465faa22011-02-08 16:31:4699 bool disallow_trusted_interfaces() const {
100 return disallow_trusted_interfaces_;
101 }
[email protected]c2932f5e2010-11-03 03:22:33102
[email protected]c2932f5e2010-11-03 03:22:33103 private:
[email protected]5c966022011-09-13 18:09:37104 friend class HostDispatcherTest;
105 friend class PluginDispatcherTest;
106
107 // Lists all lazily-created interface proxies.
[email protected]ac4b54d2011-10-20 23:09:28108 scoped_ptr<InterfaceProxy> proxies_[API_ID_COUNT];
[email protected]5c966022011-09-13 18:09:37109
[email protected]c2932f5e2010-11-03 03:22:33110 bool disallow_trusted_interfaces_;
111
112 GetInterfaceFunc local_get_interface_;
113
[email protected]c2932f5e2010-11-03 03:22:33114 scoped_ptr<VarSerializationRules> serialization_rules_;
115
116 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
117};
118
119} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02120} // namespace ppapi
[email protected]c2932f5e2010-11-03 03:22:33121
122#endif // PPAPI_PROXY_DISPATCHER_H_