summaryrefslogtreecommitdiff
path: root/chromium/components/guest_view/browser/guest_view_message_filter.h
blob: 1a24bf2cacdd29e52b76c47bf823c4d24c5bea6c (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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 COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MESSAGE_FILTER_H_
#define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MESSAGE_FILTER_H_

#include <stddef.h>
#include <stdint.h>

#include <string>

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

namespace base {
class DictionaryValue;
}

namespace content {
class BrowserContext;
}

namespace guest_view {
class GuestViewManager;

// This class filters out incoming GuestView-specific IPC messages from the
// renderer process. It is created on the UI thread. Messages may be handled on
// the IO thread or the UI thread.
class GuestViewMessageFilter : public content::BrowserMessageFilter {
 public:
  GuestViewMessageFilter(int render_process_id,
                         content::BrowserContext* context);

 protected:
  GuestViewMessageFilter(const uint32_t* message_classes_to_filter,
                         size_t num_message_classes_to_filter,
                         int render_process_id,
                         content::BrowserContext* context);

  ~GuestViewMessageFilter() override;

  // Returns the GuestViewManager for |browser_context_| if one already exists,
  // or creates and returns one for |browser_context_| otherwise.
  virtual GuestViewManager* GetOrCreateGuestViewManager();

  // content::BrowserMessageFilter implementation.
  void OverrideThreadForMessage(const IPC::Message& message,
                                content::BrowserThread::ID* thread) override;
  void OnDestruct() const override;
  bool OnMessageReceived(const IPC::Message& message) override;

  const int render_process_id_;

  // Should only be accessed on the UI thread.
  content::BrowserContext* const browser_context_;

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

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

  // Message handlers on the UI thread.
  void OnAttachGuest(int element_instance_id,
                     int guest_instance_id,
                     const base::DictionaryValue& attach_params);
  void OnAttachToEmbedderFrame(int embedder_local_render_frame_id,
                               int element_instance_id,
                               int guest_instance_id,
                               const base::DictionaryValue& params);
  void OnViewCreated(int view_instance_id, const std::string& view_type);
  void OnViewGarbageCollected(int view_instance_id);

  DISALLOW_COPY_AND_ASSIGN(GuestViewMessageFilter);
};

}  // namespace guest_view

#endif  // COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MESSAGE_FILTER_H_