1 // Copyright (c) 2011 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_PROXY_PLUGIN_MESSAGE_FILTER_H_
6 #define PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "ipc/ipc_channel_proxy.h"
13 #include "ipc/ipc_sender.h"
14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/proxy/ppapi_proxy_export.h"
20 class ResourceMessageReplyParams
;
21 class ResourceReplyThreadRegistrar
;
23 // Listens for messages on the I/O thread of the plugin and handles some of
24 // them to avoid needing to block on the plugin.
26 // There is one instance of this class for each renderer channel (same as for
27 // the PluginDispatchers).
28 class PPAPI_PROXY_EXPORT PluginMessageFilter
29 : public IPC::ChannelProxy::MessageFilter
,
32 // |seen_instance_ids| is a pointer to a set that will be used to uniquify
33 // PP_Instances across all renderer channels. The same pointer should be
34 // passed to each MessageFilter to ensure uniqueness, and the value should
35 // outlive this class. It could be NULL if this filter is for a browser
37 // |thread_registrar| is used to look up handling threads for resource
38 // reply messages. It shouldn't be NULL.
40 std::set
<PP_Instance
>* seen_instance_ids
,
41 scoped_refptr
<ResourceReplyThreadRegistrar
> thread_registrar
);
42 virtual ~PluginMessageFilter();
44 // MessageFilter implementation.
45 virtual void OnFilterAdded(IPC::Channel
* channel
) OVERRIDE
;
46 virtual void OnFilterRemoved() OVERRIDE
;
47 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
49 // IPC::Sender implementation.
50 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
52 // Simulates an incoming resource reply that is handled on the calling thread.
54 static void DispatchResourceReplyForTest(
55 const ResourceMessageReplyParams
& reply_params
,
56 const IPC::Message
& nested_msg
);
59 void OnMsgReserveInstanceId(PP_Instance instance
, bool* usable
);
60 void OnMsgResourceReply(const ResourceMessageReplyParams
& reply_params
,
61 const IPC::Message
& nested_msg
);
63 // Dispatches the given resource reply to the appropriate resource in the
65 static void DispatchResourceReply(
66 const ResourceMessageReplyParams
& reply_params
,
67 const IPC::Message
& nested_msg
);
69 // All instance IDs ever queried by any renderer on this plugin. This is used
70 // to make sure that new instance IDs are unique. This is a non-owning
71 // pointer. It is managed by PluginDispatcher::PluginDelegate.
72 std::set
<PP_Instance
>* seen_instance_ids_
;
74 scoped_refptr
<ResourceReplyThreadRegistrar
> resource_reply_thread_registrar_
;
76 // The IPC channel to the renderer. May be NULL if we're not currently
77 // attached as a filter.
78 IPC::Channel
* channel_
;
84 #endif // PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_