Added content browser test that checks gum callbacks are fired after an
[chromium-blink-merge.git] / ppapi / proxy / plugin_message_filter.h
blob2e239a2e40957cb64a20e0316143c395f27bbe98
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_
8 #include <set>
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "ipc/ipc_sender.h"
13 #include "ipc/message_filter.h"
14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/proxy/ppapi_proxy_export.h"
17 namespace ppapi {
18 namespace proxy {
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 : public IPC::MessageFilter,
29 public IPC::Sender {
30 public:
31 // |seen_instance_ids| is a pointer to a set that will be used to uniquify
32 // PP_Instances across all renderer channels. The same pointer should be
33 // passed to each MessageFilter to ensure uniqueness, and the value should
34 // outlive this class. It could be NULL if this filter is for a browser
35 // channel.
36 // |thread_registrar| is used to look up handling threads for resource
37 // reply messages. It shouldn't be NULL.
38 PluginMessageFilter(
39 std::set<PP_Instance>* seen_instance_ids,
40 scoped_refptr<ResourceReplyThreadRegistrar> thread_registrar);
41 virtual ~PluginMessageFilter();
43 // MessageFilter implementation.
44 virtual void OnFilterAdded(IPC::Sender* sender) override;
45 virtual void OnFilterRemoved() override;
46 virtual bool OnMessageReceived(const IPC::Message& message) override;
48 // IPC::Sender implementation.
49 virtual bool Send(IPC::Message* msg) override;
51 // Simulates an incoming resource reply that is handled on the calling thread.
52 // For testing only.
53 static void DispatchResourceReplyForTest(
54 const ResourceMessageReplyParams& reply_params,
55 const IPC::Message& nested_msg);
57 private:
58 void OnMsgReserveInstanceId(PP_Instance instance, bool* usable);
59 void OnMsgResourceReply(const ResourceMessageReplyParams& reply_params,
60 const IPC::Message& nested_msg);
62 // Dispatches the given resource reply to the appropriate resource in the
63 // plugin process.
64 static void DispatchResourceReply(
65 const ResourceMessageReplyParams& reply_params,
66 const IPC::Message& nested_msg);
68 // All instance IDs ever queried by any renderer on this plugin. This is used
69 // to make sure that new instance IDs are unique. This is a non-owning
70 // pointer. It is managed by PluginDispatcher::PluginDelegate.
71 std::set<PP_Instance>* seen_instance_ids_;
73 scoped_refptr<ResourceReplyThreadRegistrar> resource_reply_thread_registrar_;
75 // The IPC sender to the renderer. May be NULL if we're not currently
76 // attached as a filter.
77 IPC::Sender* sender_;
80 } // namespace proxy
81 } // namespace ppapi
83 #endif // PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_