1 // Copyright (c) 2012 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 CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_
8 #include "base/id_map.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/public/renderer/render_view_observer.h"
12 #include "ipc/ipc_sender.h"
21 class BrowserPluginDelegate;
24 // BrowserPluginManager manages the routing of messages to the appropriate
25 // BrowserPlugin object based on its instance ID.
26 class CONTENT_EXPORT BrowserPluginManager
27 : public RenderViewObserver,
28 public base::RefCounted<BrowserPluginManager> {
30 // Returns the one BrowserPluginManager for this process.
31 static BrowserPluginManager* Create(RenderViewImpl* render_view);
33 explicit BrowserPluginManager(RenderViewImpl* render_view);
35 // Creates a new BrowserPlugin object.
36 // BrowserPlugin is responsible for associating itself with the
37 // BrowserPluginManager via AddBrowserPlugin. When it is destroyed, it is
38 // responsible for removing its association via RemoveBrowserPlugin.
39 BrowserPlugin* CreateBrowserPlugin(
40 RenderViewImpl* render_view,
41 blink::WebFrame* frame,
42 scoped_ptr<BrowserPluginDelegate> delegate);
44 void Attach(int browser_plugin_instance_id);
46 void AddBrowserPlugin(int browser_plugin_instance_id,
47 BrowserPlugin* browser_plugin);
48 void RemoveBrowserPlugin(int browser_plugin_instance_id);
49 BrowserPlugin* GetBrowserPlugin(int browser_plugin_instance_id) const;
51 void UpdateDeviceScaleFactor();
52 void UpdateFocusState();
53 RenderViewImpl* render_view() const { return render_view_.get(); }
54 int GetNextInstanceID();
56 // RenderViewObserver override. Call on render thread.
57 void DidCommitCompositorFrame() override;
58 bool OnMessageReceived(const IPC::Message& message) override;
59 bool Send(IPC::Message* msg) override;
61 // Don't destroy the BrowserPluginManager when the RenderViewImpl goes away.
62 // BrowserPluginManager's lifetime is managed by a reference count. Once
63 // the host RenderViewImpl and all BrowserPlugins release their references,
64 // then the BrowserPluginManager will be destroyed.
65 void OnDestruct() override {}
68 // Friend RefCounted so that the dtor can be non-public.
69 friend class base::RefCounted<BrowserPluginManager>;
71 ~BrowserPluginManager() override;
73 // IPC message handlers.
74 void OnCompositorFrameSwappedPluginUnavailable(const IPC::Message& message);
76 // This map is keyed by guest instance IDs.
77 IDMap<BrowserPlugin> instances_;
78 int current_instance_id_;
79 base::WeakPtr<RenderViewImpl> render_view_;
81 DISALLOW_COPY_AND_ASSIGN(BrowserPluginManager);
84 } // namespace content
86 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_