Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: ppapi/proxy/dispatcher.h

Issue 4229002: Core PPAPI proxy files. This includes the dispatcher which is the control poi... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
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
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/linked_ptr.h"
13 #include "base/scoped_ptr.h"
14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_handle.h"
16 #include "ipc/ipc_message.h"
17 #include "ppapi/c/pp_module.h"
18 #include "ppapi/proxy/callback_tracker.h"
19 #include "ppapi/proxy/interface_id.h"
20 #include "ppapi/proxy/plugin_resource_tracker.h"
21 #include "ppapi/proxy/plugin_var_tracker.h"
22
23 class MessageLoop;
24 struct PPB_Var_Deprecated;
25
26 namespace base {
27 class WaitableEvent;
28 }
29
30 namespace IPC {
31 class SyncChannel;
32 }
33
34 namespace pp {
35 namespace proxy {
36
37 class InterfaceProxy;
38 class VarSerialization;
39
40 // An interface proxy can represent either end of a cross-process interface
41 // call. The "source" side is where the call is invoked, and the "target" side
42 // is where the call ends up being executed.
43 //
44 // Plugin side | Browser side
45 // -------------------------------------|--------------------------------------
46 // |
47 // "Source" | "Target"
48 // InterfaceProxy ----------------------> InterfaceProxy
49 // |
50 // |
51 // "Target" | "Source"
52 // InterfaceProxy <---------------------- InterfaceProxy
53 // |
54 class Dispatcher : public IPC::Channel::Listener,
55 public IPC::Message::Sender {
56 public:
57 typedef const void* (*GetInterfaceFunc)(const char*);
58 typedef const int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc);
59 typedef const void (*ShutdownModuleFunc)();
60
61 ~Dispatcher();
62
63 bool InitWithChannel(MessageLoop* ipc_message_loop,
64 const std::string& channel_name,
65 bool is_client,
66 base::WaitableEvent* shutdown_event);
67
68 // Returns true if the dispatcher is on the plugin side, or false if it's the
69 // browser side.
70 virtual bool IsPlugin() const = 0;
71
72 VarSerialization* serialization() const { return serialization_.get(); }
73 PP_Module pp_module() const { return pp_module_; }
74
75 // Wrapper for calling the local GetInterface function.
76 const void* GetLocalInterface(const char* interface);
77
78 // Implements PPP_GetInterface and PPB_GetInterface on the "source" side. It
79 // will check if the remote side supports this interface as a target, and
80 // create a proxy if it does. A local implementation of that interface backed
81 // by the proxy will be returned on success. If the interface is unproxyable
82 // or not supported by the remote side, returns NULL.
83 const void* GetProxiedInterface(const std::string& interface);
84
85 // Called if the remote side is declaring to us which interfaces it supports
86 // so we don't have to query for each one. We'll pre-create proxies for
87 // each of the given interfaces.
88
89 // Returns the proxy corresponding to the given ID for sending commands to
90 // the remote process.
91 //InterfaceProxy* GetSourceProxyForInterfaceID(InterfaceID id);
92
93 // IPC::Message::Sender implementation.
94 virtual bool Send(IPC::Message* msg);
95
96 // IPC::Channel::Listener implementation.
97 virtual void OnMessageReceived(const IPC::Message& msg);
98
99 IPC::SyncChannel* channel() const {
100 return channel_.get();
101 }
102
103 CallbackTracker& callback_tracker() {
104 return callback_tracker_;
105 }
106
107 protected:
108 Dispatcher(GetInterfaceFunc local_get_interface);
109
110 // Setter for the derived classes to set the appropriate var serialization.
111 // Takes ownership of the given pointer, which must be on the heap.
112 void SetSerialization(VarSerialization* var_serialization);
113
114 void set_pp_module(PP_Module module) {
115 pp_module_ = module;
116 }
117
118 // Allows the PluginDispatcher to add a magic proxy for PPP_Class, bypassing
119 // the normal "do you support this proxy" stuff and the big lookup of
120 // name to proxy object. Takes ownership of the pointer.
121 void InjectProxy(InterfaceID id,
122 const std::string& name,
123 InterfaceProxy* proxy);
124
125 private:
126 typedef std::map< std::string, linked_ptr<InterfaceProxy> > ProxyMap;
127
128 // Message handlers
129 void OnMsgSupportsInterface(const std::string& interface_name, bool* result);
130 void OnMsgDeclareInterfaces(const std::vector<std::string>& interfaces);
131
132 // Allocates a new proxy on the heap corresponding to the given interface
133 // name, or returns NULL if that interface name isn't known proxyable. The
134 // caller owns the returned pointer.
135 //
136 // The interface_functions gives the pointer to the local interfece when this
137 // is a target proxy. When creating a source proxy, set this to NULL.
138 InterfaceProxy* CreateProxyForInterface(
139 const std::string& interface_name,
140 const void* interface_functions);
141
142 // Returns true if the remote side supports the given interface as the
143 // target of an IPC call.
144 bool RemoteSupportsTargetInterface(const std::string& interface);
145
146 // Sets up a proxy as the target for the given interface, if it is supported.
147 // Returns true if this process implements the given interface and it is
148 // proxyable.
149 bool SetupProxyForTargetInterface(const std::string& interface);
150
151 bool IsInterfaceTrusted(const std::string& interface);
152
153 // Set by the derived classed to indicate the module ID corresponding to
154 // this dispatcher.
155 PP_Module pp_module_;
156
157 scoped_ptr<IPC::SyncChannel> channel_;
158
159 bool disallow_trusted_interfaces_;
160
161 GetInterfaceFunc local_get_interface_;
162
163 ProxyMap proxies_;
164 InterfaceProxy* id_to_proxy_[INTERFACE_ID_COUNT];
165
166 // True if the remote side has declared which interfaces it supports in
167 // advance. When set, it means if we don't already have a source proxy for
168 // the requested interface, that the remote side doesn't support it and
169 // we don't need to query.
170 //
171 // This is just an optimization. The browser has a fixed set of interfaces
172 // it supports, and the many plugins will end up querying many of them. By
173 // having the browser just send all of those interfaces in one message, we
174 // can avoid a bunch of IPC chatter to set up each interface.
175 bool declared_supported_remote_interfaces_;
176
177 CallbackTracker callback_tracker_;
178
179 scoped_ptr<VarSerialization> serialization_;
180
181 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
182 };
183
184 } // namespace proxy
185 } // namespace pp
186
187 #endif // PPAPI_PROXY_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698