summaryrefslogtreecommitdiffstats
path: root/content/renderer/browser_plugin/browser_plugin_manager.h
blob: a762b889f035f010b3ebbba6f94d366d4a56ad87 (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
// Copyright (c) 2012 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 CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_
#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_

#include "base/id_map.h"
#include "base/memory/weak_ptr.h"
#include "content/public/renderer/render_process_observer.h"
#include "ipc/ipc_sender.h"

namespace blink {
class WebFrame;
}

namespace content {

class BrowserPlugin;
class BrowserPluginDelegate;
class RenderFrame;

// BrowserPluginManager manages the routing of messages to the appropriate
// BrowserPlugin object based on its instance ID. There is one BrowserPlugin
// for the RenderThread.
class CONTENT_EXPORT BrowserPluginManager : public RenderProcessObserver {
 public:
  static BrowserPluginManager* Get();

  BrowserPluginManager();
  ~BrowserPluginManager() override;

  // Creates a new BrowserPlugin object.
  // BrowserPlugin is responsible for associating itself with the
  // BrowserPluginManager via AddBrowserPlugin. When it is destroyed, it is
  // responsible for removing its association via RemoveBrowserPlugin.
  // The |delegate| is expected to manage its own lifetime.
  // Generally BrowserPlugin calls DidDestroyElement() on the delegate and
  // right now the delegate destroys itself once it hears that callback.
  BrowserPlugin* CreateBrowserPlugin(
      RenderFrame* render_frame,
      const base::WeakPtr<BrowserPluginDelegate>& delegate);

  void Attach(int browser_plugin_instance_id);

  void Detach(int browser_plugin_instance_id);

  void AddBrowserPlugin(int browser_plugin_instance_id,
                        BrowserPlugin* browser_plugin);
  void RemoveBrowserPlugin(int browser_plugin_instance_id);
  BrowserPlugin* GetBrowserPlugin(int browser_plugin_instance_id) const;

  void UpdateFocusState();

  // Returns a new instance ID to be used by BrowserPlugin. Instance IDs are
  // unique per process.
  int GetNextInstanceID();

  void DidCommitCompositorFrame(int render_frame_routing_id);
  bool Send(IPC::Message* msg);

  // RenderProcessObserver override.
  bool OnControlMessageReceived(const IPC::Message& message) override;

 private:
  // IPC message handlers.
  void OnCompositorFrameSwappedPluginUnavailable(const IPC::Message& message);

  // This map is keyed by guest instance IDs.
  IDMap<BrowserPlugin> instances_;

  DISALLOW_COPY_AND_ASSIGN(BrowserPluginManager);
};

}  // namespace content

#endif  // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_