File: plugin_message_filter.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (90 lines) | stat: -rw-r--r-- 3,331 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_
#define PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_

#include <set>
#include <vector>

#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "ipc/ipc_sender.h"
#include "ipc/message_filter.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/ppapi_proxy_export.h"
#include "ppapi/proxy/resource_message_filter.h"

namespace ppapi {
namespace proxy {

class ResourceMessageReplyParams;
class ResourceReplyThreadRegistrar;

// Listens for messages on the I/O thread of the plugin and handles some of
// them to avoid needing to block on the plugin.
//
// There is one instance of this class for each renderer channel (same as for
// the PluginDispatchers).
class PPAPI_PROXY_EXPORT PluginMessageFilter : public IPC::MessageFilter,
                                               public IPC::Sender {
 public:
  // |seen_instance_ids| is a pointer to a set that will be used to uniquify
  // PP_Instances across all renderer channels. The same pointer should be
  // passed to each MessageFilter to ensure uniqueness, and the value should
  // outlive this class. It could be NULL if this filter is for a browser
  // channel.
  // |thread_registrar| is used to look up handling threads for resource
  // reply messages. It shouldn't be NULL.
  PluginMessageFilter(
      std::set<PP_Instance>* seen_instance_ids,
      scoped_refptr<ResourceReplyThreadRegistrar> thread_registrar);
  ~PluginMessageFilter() override;

  // MessageFilter implementation.
  void OnFilterAdded(IPC::Channel* channel) override;
  void OnFilterRemoved() override;
  bool OnMessageReceived(const IPC::Message& message) override;

  // IPC::Sender implementation.
  bool Send(IPC::Message* msg) override;

  void AddResourceMessageFilter(
      const scoped_refptr<ResourceMessageFilter>& filter);

  // Simulates an incoming resource reply that is handled on the calling thread.
  // For testing only.
  static void DispatchResourceReplyForTest(
      const ResourceMessageReplyParams& reply_params,
      const IPC::Message& nested_msg);

 private:
  void OnMsgReserveInstanceId(PP_Instance instance, bool* usable);
  void OnMsgResourceReply(const ResourceMessageReplyParams& reply_params,
                          const IPC::Message& nested_msg);

  // Dispatches the given resource reply to the appropriate resource in the
  // plugin process.
  static void DispatchResourceReply(
      const ResourceMessageReplyParams& reply_params,
      const IPC::Message& nested_msg);

  // All instance IDs ever queried by any renderer on this plugin. This is used
  // to make sure that new instance IDs are unique. This is a non-owning
  // pointer. It is managed by PluginDispatcher::PluginDelegate.
  std::set<PP_Instance>* seen_instance_ids_;

  scoped_refptr<ResourceReplyThreadRegistrar> resource_reply_thread_registrar_;

  std::vector<scoped_refptr<ResourceMessageFilter>> resource_filters_;

  // The IPC sender to the renderer. May be NULL if we're not currently
  // attached as a filter.
  IPC::Sender* sender_;
};

}  // namespace proxy
}  // namespace ppapi

#endif  // PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_