[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 2 | // 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] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 8 | #include <set> |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 9 | #include <string> |
10 | #include <vector> | ||||
11 | |||||
[email protected] | 2c5c7e8 | 2011-11-29 14:35:28 | [diff] [blame] | 12 | #include "base/callback_forward.h" |
[email protected] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 13 | #include "base/tracked_objects.h" |
[email protected] | 1609d0d | 2011-04-15 22:06:21 | [diff] [blame] | 14 | #include "ipc/ipc_channel_proxy.h" |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 15 | #include "ppapi/c/pp_instance.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 16 | #include "ppapi/c/pp_module.h" |
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 17 | #include "ppapi/proxy/proxy_channel.h" |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 18 | #include "ppapi/proxy/interface_list.h" |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 19 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 20 | #include "ppapi/proxy/plugin_var_tracker.h" |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 21 | #include "ppapi/shared_impl/api_id.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 22 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 23 | namespace ppapi { |
[email protected] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 24 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 25 | namespace proxy { |
26 | |||||
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 27 | class VarSerializationRules; |
28 | |||||
29 | // An interface proxy can represent either end of a cross-process interface | ||||
30 | // call. The "source" side is where the call is invoked, and the "target" side | ||||
31 | // is where the call ends up being executed. | ||||
32 | // | ||||
33 | // Plugin side | Browser side | ||||
34 | // -------------------------------------|-------------------------------------- | ||||
35 | // | | ||||
36 | // "Source" | "Target" | ||||
37 | // InterfaceProxy ----------------------> InterfaceProxy | ||||
38 | // | | ||||
39 | // | | ||||
40 | // "Target" | "Source" | ||||
41 | // InterfaceProxy <---------------------- InterfaceProxy | ||||
42 | // | | ||||
[email protected] | f0a04c4 | 2011-08-26 22:43:20 | [diff] [blame] | 43 | class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel { |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 44 | public: |
45 | typedef const void* (*GetInterfaceFunc)(const char*); | ||||
[email protected] | 9c7baaef | 2010-11-10 05:42:46 | [diff] [blame] | 46 | typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 47 | |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 48 | virtual ~Dispatcher(); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 49 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 50 | // Returns true if the dispatcher is on the plugin side, or false if it's the |
51 | // browser side. | ||||
52 | virtual bool IsPlugin() const = 0; | ||||
53 | |||||
54 | VarSerializationRules* serialization_rules() const { | ||||
55 | return serialization_rules_.get(); | ||||
56 | } | ||||
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 57 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 58 | // Returns a non-owning pointer to the interface proxy for the given ID, or |
59 | // NULL if the ID isn't found. This will create the proxy if it hasn't been | ||||
60 | // created so far. | ||||
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 61 | InterfaceProxy* GetInterfaceProxy(ApiID id); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 62 | |
[email protected] | 1609d0d | 2011-04-15 22:06:21 | [diff] [blame] | 63 | // Returns the pointer to the IO thread for processing IPC messages. |
64 | // TODO(brettw) remove this. It's a hack to support the Flash | ||||
65 | // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this | ||||
66 | // implementation detail should be hidden. | ||||
[email protected] | 92bf906 | 2011-05-02 18:00:49 | [diff] [blame] | 67 | base::MessageLoopProxy* GetIPCMessageLoop(); |
[email protected] | 1609d0d | 2011-04-15 22:06:21 | [diff] [blame] | 68 | |
69 | // Adds the given filter to the IO thread. Takes ownership of the pointer. | ||||
70 | // TODO(brettw) remove this. It's a hack to support the Flash | ||||
71 | // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this | ||||
72 | // implementation detail should be hidden. | ||||
73 | void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter); | ||||
74 | |||||
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 75 | // TODO(brettw): What is this comment referring to? |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 76 | // Called if the remote side is declaring to us which interfaces it supports |
77 | // so we don't have to query for each one. We'll pre-create proxies for | ||||
78 | // each of the given interfaces. | ||||
79 | |||||
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 80 | // IPC::Channel::Listener implementation. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 81 | virtual bool OnMessageReceived(const IPC::Message& msg); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 82 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 83 | GetInterfaceFunc local_get_interface() const { return local_get_interface_; } |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 84 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 85 | protected: |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 86 | Dispatcher(base::ProcessHandle remote_process_handle, |
87 | GetInterfaceFunc local_get_interface); | ||||
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 88 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 89 | // Setter for the derived classes to set the appropriate var serialization. |
90 | // Takes ownership of the given pointer, which must be on the heap. | ||||
91 | void SetSerializationRules(VarSerializationRules* var_serialization_rules); | ||||
92 | |||||
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 93 | // Called when an invalid message is received from the remote site. The |
94 | // default implementation does nothing, derived classes can override. | ||||
95 | virtual void OnInvalidMessageReceived(); | ||||
96 | |||||
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 97 | bool disallow_trusted_interfaces() const { |
98 | return disallow_trusted_interfaces_; | ||||
99 | } | ||||
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 100 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 101 | private: |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 102 | friend class HostDispatcherTest; |
103 | friend class PluginDispatcherTest; | ||||
104 | |||||
105 | // Lists all lazily-created interface proxies. | ||||
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 106 | scoped_ptr<InterfaceProxy> proxies_[API_ID_COUNT]; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 107 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 108 | bool disallow_trusted_interfaces_; |
109 | |||||
110 | GetInterfaceFunc local_get_interface_; | ||||
111 | |||||
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 112 | scoped_ptr<VarSerializationRules> serialization_rules_; |
113 | |||||
114 | DISALLOW_COPY_AND_ASSIGN(Dispatcher); | ||||
115 | }; | ||||
116 | |||||
117 | } // namespace proxy | ||||
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 118 | } // namespace ppapi |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 119 | |
120 | #endif // PPAPI_PROXY_DISPATCHER_H_ |