summaryrefslogtreecommitdiffstats
path: root/extensions/browser/io_thread_extension_message_filter.h
blob: f6f41bb4835a4941ac8c827def0f9c2ff60b53a0 (plain)
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
// Copyright 2015 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 EXTENSIONS_BROWSER_IO_THREAD_EXTENSION_MESSAGE_FILTER_H_
#define EXTENSIONS_BROWSER_IO_THREAD_EXTENSION_MESSAGE_FILTER_H_

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/browser_message_filter.h"

struct ExtensionHostMsg_Request_Params;

namespace content {
class BrowserContext;
}

namespace extensions {

class InfoMap;

// This class filters out incoming extension-specific IPC messages from the
// renderer process. It is created on the UI thread, but handles messages on the
// IO thread and is destroyed there.
class IOThreadExtensionMessageFilter : public content::BrowserMessageFilter {
 public:
  IOThreadExtensionMessageFilter(int render_process_id,
                                 content::BrowserContext* context);

  int render_process_id() { return render_process_id_; }

 private:
  friend class base::DeleteHelper<IOThreadExtensionMessageFilter>;
  friend class content::BrowserThread;

  ~IOThreadExtensionMessageFilter() override;

  // content::BrowserMessageFilter implementation.
  void OnDestruct() const override;
  bool OnMessageReceived(const IPC::Message& message) override;

  // Message handlers on the IO thread.
  void OnAppWindowReady(int route_id);
  void OnExtensionGenerateUniqueID(int* unique_id);
  void OnExtensionRequestForIOThread(
      int routing_id,
      const ExtensionHostMsg_Request_Params& params);

  const int render_process_id_;

  // The browser context as a void pointer, for use as an identifier on the IO
  // thread.
  void* browser_context_id_;

  scoped_refptr<extensions::InfoMap> extension_info_map_;

  // Weak pointers produced by this factory are bound to the IO thread.
  base::WeakPtrFactory<IOThreadExtensionMessageFilter> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(IOThreadExtensionMessageFilter);
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_IO_THREAD_EXTENSION_MESSAGE_FILTER_H_