blob: 348c91c29076669686c541ce30a59ea7da62b5d4 [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"
17#include "ppapi/proxy/callback_tracker.h"
[email protected]e2614c62011-04-16 22:12:4518#include "ppapi/proxy/proxy_channel.h"
[email protected]c2932f5e2010-11-03 03:22:3319#include "ppapi/proxy/interface_id.h"
[email protected]465faa22011-02-08 16:31:4620#include "ppapi/proxy/interface_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3321#include "ppapi/proxy/plugin_var_tracker.h"
22
[email protected]55cdf6052011-05-13 19:22:5323namespace ppapi {
[email protected]7a1f7c6f2011-05-10 21:17:4824class WebKitForwarding;
25}
26
[email protected]55cdf6052011-05-13 19:22:5327namespace pp {
[email protected]c2932f5e2010-11-03 03:22:3328namespace proxy {
29
[email protected]c2932f5e2010-11-03 03:22:3330class 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]e2614c62011-04-16 22:12:4546class Dispatcher : public ProxyChannel {
[email protected]c2932f5e2010-11-03 03:22:3347 public:
48 typedef const void* (*GetInterfaceFunc)(const char*);
[email protected]9c7baaef2010-11-10 05:42:4649 typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc);
[email protected]c2932f5e2010-11-03 03:22:3350
[email protected]4f15d2842011-02-15 17:36:3351 virtual ~Dispatcher();
[email protected]c2932f5e2010-11-03 03:22:3352
[email protected]c2932f5e2010-11-03 03:22:3353 // Returns true if the dispatcher is on the plugin side, or false if it's the
54 // browser side.
55 virtual bool IsPlugin() const = 0;
56
57 VarSerializationRules* serialization_rules() const {
58 return serialization_rules_.get();
59 }
[email protected]c2932f5e2010-11-03 03:22:3360
61 // Wrapper for calling the local GetInterface function.
[email protected]84396dbc2011-04-14 06:33:4262 const void* GetLocalInterface(const char* interface_name);
[email protected]c2932f5e2010-11-03 03:22:3363
[email protected]1609d0d2011-04-15 22:06:2164 // Returns the pointer to the IO thread for processing IPC messages.
65 // TODO(brettw) remove this. It's a hack to support the Flash
66 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this
67 // implementation detail should be hidden.
[email protected]92bf9062011-05-02 18:00:4968 base::MessageLoopProxy* GetIPCMessageLoop();
[email protected]1609d0d2011-04-15 22:06:2169
70 // Adds the given filter to the IO thread. Takes ownership of the pointer.
71 // TODO(brettw) remove this. It's a hack to support the Flash
72 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this
73 // implementation detail should be hidden.
74 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter);
75
[email protected]e2614c62011-04-16 22:12:4576 // TODO(brettw): What is this comment referring to?
[email protected]c2932f5e2010-11-03 03:22:3377 // Called if the remote side is declaring to us which interfaces it supports
78 // so we don't have to query for each one. We'll pre-create proxies for
79 // each of the given interfaces.
80
[email protected]c2932f5e2010-11-03 03:22:3381 // IPC::Channel::Listener implementation.
[email protected]a95986a82010-12-24 06:19:2882 virtual bool OnMessageReceived(const IPC::Message& msg);
[email protected]c2932f5e2010-11-03 03:22:3383
84 CallbackTracker& callback_tracker() {
85 return callback_tracker_;
86 }
87
[email protected]465faa22011-02-08 16:31:4688 // Retrieves the information associated with the given interface, identified
89 // either by name or ID. Each function searches either PPP or PPB interfaces.
90 static const InterfaceProxy::Info* GetPPBInterfaceInfo(
91 const std::string& name);
92 static const InterfaceProxy::Info* GetPPBInterfaceInfo(
93 InterfaceID id);
94 static const InterfaceProxy::Info* GetPPPInterfaceInfo(
95 const std::string& name);
[email protected]465faa22011-02-08 16:31:4696
[email protected]c2932f5e2010-11-03 03:22:3397 protected:
[email protected]5d84d012010-12-02 17:17:2198 Dispatcher(base::ProcessHandle remote_process_handle,
99 GetInterfaceFunc local_get_interface);
[email protected]c2932f5e2010-11-03 03:22:33100
[email protected]c2932f5e2010-11-03 03:22:33101 // Setter for the derived classes to set the appropriate var serialization.
102 // Takes ownership of the given pointer, which must be on the heap.
103 void SetSerializationRules(VarSerializationRules* var_serialization_rules);
104
[email protected]465faa22011-02-08 16:31:46105 bool disallow_trusted_interfaces() const {
106 return disallow_trusted_interfaces_;
107 }
[email protected]c2932f5e2010-11-03 03:22:33108
[email protected]c2932f5e2010-11-03 03:22:33109 private:
[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 CallbackTracker callback_tracker_;
115
116 scoped_ptr<VarSerializationRules> serialization_rules_;
117
118 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
119};
120
121} // namespace proxy
122} // namespace pp
123
124#endif // PPAPI_PROXY_DISPATCHER_H_