[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] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 12 | #include "base/callback.h" |
| 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" |
| 17 | #include "ppapi/proxy/callback_tracker.h" |
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 18 | #include "ppapi/proxy/proxy_channel.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 19 | #include "ppapi/proxy/interface_id.h" |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 20 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 21 | #include "ppapi/proxy/plugin_var_tracker.h" |
| 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 | class WebKitForwarding; |
| 25 | } |
| 26 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame^] | 27 | namespace pp { |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 28 | namespace proxy { |
| 29 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 30 | class VarSerializationRules; |
| 31 | |
| 32 | // An interface proxy can represent either end of a cross-process interface |
| 33 | // call. The "source" side is where the call is invoked, and the "target" side |
| 34 | // is where the call ends up being executed. |
| 35 | // |
| 36 | // Plugin side | Browser side |
| 37 | // -------------------------------------|-------------------------------------- |
| 38 | // | |
| 39 | // "Source" | "Target" |
| 40 | // InterfaceProxy ----------------------> InterfaceProxy |
| 41 | // | |
| 42 | // | |
| 43 | // "Target" | "Source" |
| 44 | // InterfaceProxy <---------------------- InterfaceProxy |
| 45 | // | |
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 46 | class Dispatcher : public ProxyChannel { |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 47 | public: |
| 48 | typedef const void* (*GetInterfaceFunc)(const char*); |
[email protected] | 9c7baaef | 2010-11-10 05:42:46 | [diff] [blame] | 49 | typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 50 | |
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 51 | class Delegate : public ProxyChannel::Delegate { |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 52 | public: |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 53 | // Returns the set used for globally uniquifying PP_Instances. This same |
| 54 | // set must be returned for all channels. This is required only for the |
| 55 | // plugin side, for the host side, the return value may be NULL. |
| 56 | // |
| 57 | // DEREFERENCE ONLY ON THE I/O THREAD. |
| 58 | virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() = 0; |
[email protected] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 59 | |
| 60 | // Returns the WebKit forwarding object used to make calls into WebKit. |
| 61 | // Necessary only on the plugin side. The host side can return NULL. |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame^] | 62 | virtual ppapi::WebKitForwarding* GetWebKitForwarding() = 0; |
[email protected] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 63 | |
| 64 | // Posts the given task to the WebKit thread associated with this plugin |
| 65 | // process. For host processes, this will not be called and can do |
| 66 | // nothing. The WebKit thread should be lazily created if it does not |
| 67 | // exist yet. |
| 68 | virtual void PostToWebKitThread(const tracked_objects::Location& from_here, |
| 69 | const base::Closure& task) = 0; |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 70 | }; |
| 71 | |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 72 | virtual ~Dispatcher(); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 73 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 74 | // Returns true if the dispatcher is on the plugin side, or false if it's the |
| 75 | // browser side. |
| 76 | virtual bool IsPlugin() const = 0; |
| 77 | |
| 78 | VarSerializationRules* serialization_rules() const { |
| 79 | return serialization_rules_.get(); |
| 80 | } |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 81 | |
| 82 | // Wrapper for calling the local GetInterface function. |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 83 | const void* GetLocalInterface(const char* interface_name); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 84 | |
[email protected] | 1609d0d | 2011-04-15 22:06:21 | [diff] [blame] | 85 | // Returns the pointer to the IO thread for processing IPC messages. |
| 86 | // TODO(brettw) remove this. It's a hack to support the Flash |
| 87 | // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this |
| 88 | // implementation detail should be hidden. |
[email protected] | 92bf906 | 2011-05-02 18:00:49 | [diff] [blame] | 89 | base::MessageLoopProxy* GetIPCMessageLoop(); |
[email protected] | 1609d0d | 2011-04-15 22:06:21 | [diff] [blame] | 90 | |
| 91 | // Adds the given filter to the IO thread. Takes ownership of the pointer. |
| 92 | // TODO(brettw) remove this. It's a hack to support the Flash |
| 93 | // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this |
| 94 | // implementation detail should be hidden. |
| 95 | void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 96 | |
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 97 | // TODO(brettw): What is this comment referring to? |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 98 | // Called if the remote side is declaring to us which interfaces it supports |
| 99 | // so we don't have to query for each one. We'll pre-create proxies for |
| 100 | // each of the given interfaces. |
| 101 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 102 | // IPC::Channel::Listener implementation. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 103 | virtual bool OnMessageReceived(const IPC::Message& msg); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 104 | |
| 105 | CallbackTracker& callback_tracker() { |
| 106 | return callback_tracker_; |
| 107 | } |
| 108 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 109 | // Retrieves the information associated with the given interface, identified |
| 110 | // either by name or ID. Each function searches either PPP or PPB interfaces. |
| 111 | static const InterfaceProxy::Info* GetPPBInterfaceInfo( |
| 112 | const std::string& name); |
| 113 | static const InterfaceProxy::Info* GetPPBInterfaceInfo( |
| 114 | InterfaceID id); |
| 115 | static const InterfaceProxy::Info* GetPPPInterfaceInfo( |
| 116 | const std::string& name); |
| 117 | static const InterfaceProxy::Info* GetPPPInterfaceInfo( |
| 118 | InterfaceID id); |
| 119 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 120 | protected: |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 121 | Dispatcher(base::ProcessHandle remote_process_handle, |
| 122 | GetInterfaceFunc local_get_interface); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 123 | |
[email protected] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 124 | void SetDelegate(Delegate* delegate); |
| 125 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 126 | // Setter for the derived classes to set the appropriate var serialization. |
| 127 | // Takes ownership of the given pointer, which must be on the heap. |
| 128 | void SetSerializationRules(VarSerializationRules* var_serialization_rules); |
| 129 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 130 | bool disallow_trusted_interfaces() const { |
| 131 | return disallow_trusted_interfaces_; |
| 132 | } |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 133 | |
[email protected] | 7a1f7c6f | 2011-05-10 21:17:48 | [diff] [blame] | 134 | Delegate* dispatcher_delegate_; |
| 135 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 136 | private: |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 137 | bool disallow_trusted_interfaces_; |
| 138 | |
| 139 | GetInterfaceFunc local_get_interface_; |
| 140 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 141 | CallbackTracker callback_tracker_; |
| 142 | |
| 143 | scoped_ptr<VarSerializationRules> serialization_rules_; |
| 144 | |
| 145 | DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 146 | }; |
| 147 | |
| 148 | } // namespace proxy |
| 149 | } // namespace pp |
| 150 | |
| 151 | #endif // PPAPI_PROXY_DISPATCHER_H_ |