mac: Fix DownloadItemController unit tests on Yosemite.
[chromium-blink-merge.git] / ppapi / host / ppapi_host.h
blob3f6e80dec7c1a48cef61154f5600e94257255f66
1 // Copyright (c) 2012 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.
5 #ifndef PPAPI_HOST_PPAPI_HOST_H_
6 #define PPAPI_HOST_PPAPI_HOST_H_
8 #include <map>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/observer_list.h"
16 #include "ipc/ipc_listener.h"
17 #include "ipc/ipc_sender.h"
18 #include "ppapi/c/pp_instance.h"
19 #include "ppapi/c/pp_resource.h"
20 #include "ppapi/host/ppapi_host_export.h"
21 #include "ppapi/shared_impl/ppapi_permissions.h"
23 namespace ppapi {
25 namespace proxy {
26 class ResourceMessageCallParams;
27 class ResourceMessageReplyParams;
28 class SerializedHandle;
31 namespace host {
33 class HostFactory;
34 struct HostMessageContext;
35 class InstanceMessageFilter;
36 struct ReplyMessageContext;
37 class ResourceHost;
39 // The host provides routing and tracking for resource message calls that
40 // come from the plugin to the host (browser or renderer), and the
41 // corresponding replies.
42 class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
43 public:
44 // The sender is the channel to the plugin for outgoing messages.
45 // Normally the creator will add filters for resource creation messages
46 // (AddHostFactoryFilter) and instance messages (AddInstanceMessageFilter)
47 // after construction.
48 PpapiHost(IPC::Sender* sender, const PpapiPermissions& perms);
49 virtual ~PpapiHost();
51 const PpapiPermissions& permissions() const { return permissions_; }
53 // Sender implementation. Forwards to the sender_.
54 virtual bool Send(IPC::Message* msg) override;
56 // Listener implementation.
57 virtual bool OnMessageReceived(const IPC::Message& msg) override;
59 // Sends the given reply message to the plugin.
60 void SendReply(const ReplyMessageContext& context,
61 const IPC::Message& msg);
63 // Sends the given unsolicited reply message to the plugin.
64 void SendUnsolicitedReply(PP_Resource resource, const IPC::Message& msg);
66 // Similar to |SendUnsolicitedReply()|, but also sends handles.
67 void SendUnsolicitedReplyWithHandles(
68 PP_Resource resource,
69 const IPC::Message& msg,
70 const std::vector<proxy::SerializedHandle>& handles);
72 // Create a ResourceHost with the given |nested_msg|.
73 scoped_ptr<ResourceHost> CreateResourceHost(PP_Resource resource,
74 PP_Instance instance,
75 const IPC::Message& nested_msg);
77 // Adds the given host resource as a pending one (with no corresponding
78 // PluginResource object and no PP_Resource ID yet). The pending resource ID
79 // is returned. See PpapiHostMsg_AttachToPendingHost.
80 int AddPendingResourceHost(scoped_ptr<ResourceHost> resource_host);
82 // Adds the given host factory filter to the host. The PpapiHost will take
83 // ownership of the pointer.
84 void AddHostFactoryFilter(scoped_ptr<HostFactory> filter);
86 // Adds the given message filter to the host. The PpapiHost will take
87 // ownership of the pointer.
88 void AddInstanceMessageFilter(scoped_ptr<InstanceMessageFilter> filter);
90 // Returns null if the resource doesn't exist.
91 host::ResourceHost* GetResourceHost(PP_Resource resource) const;
93 private:
94 friend class InstanceMessageFilter;
96 void HandleResourceCall(
97 const proxy::ResourceMessageCallParams& params,
98 const IPC::Message& nested_msg,
99 HostMessageContext* context);
101 // Message handlers.
102 void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params,
103 const IPC::Message& nested_msg);
104 void OnHostMsgInProcessResourceCall(
105 int routing_id,
106 const proxy::ResourceMessageCallParams& params,
107 const IPC::Message& nested_msg);
108 void OnHostMsgResourceSyncCall(
109 const proxy::ResourceMessageCallParams& params,
110 const IPC::Message& nested_msg,
111 IPC::Message* reply_msg);
112 void OnHostMsgResourceCreated(const proxy::ResourceMessageCallParams& param,
113 PP_Instance instance,
114 const IPC::Message& nested_msg);
115 void OnHostMsgAttachToPendingHost(PP_Resource resource, int pending_host_id);
116 void OnHostMsgResourceDestroyed(PP_Resource resource);
118 // Non-owning pointer.
119 IPC::Sender* sender_;
121 PpapiPermissions permissions_;
123 // Filters for resource creation messages. Note that since we don't support
124 // deleting these dynamically we don't need to worry about modifications
125 // during iteration. If we add that capability, this should be replaced with
126 // an ObserverList.
127 ScopedVector<HostFactory> host_factory_filters_;
129 // Filters for instance messages. Note that since we don't support deleting
130 // these dynamically we don't need to worry about modifications during
131 // iteration. If we add that capability, this should be replaced with an
132 // ObserverList.
133 ScopedVector<InstanceMessageFilter> instance_message_filters_;
135 typedef std::map<PP_Resource, linked_ptr<ResourceHost> > ResourceMap;
136 ResourceMap resources_;
138 // Resources that have been created in the host and have not yet had the
139 // corresponding PluginResource associated with them.
140 // See PpapiHostMsg_AttachToPendingHost.
141 typedef std::map<int, linked_ptr<ResourceHost> > PendingHostResourceMap;
142 PendingHostResourceMap pending_resource_hosts_;
143 int next_pending_resource_host_id_;
145 DISALLOW_COPY_AND_ASSIGN(PpapiHost);
148 } // namespace host
149 } // namespace ppapi
151 #endif // PPAPI_HOST_PPAPIE_HOST_H_