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 "base/observer_list.h"
12 #include "content/public/renderer/render_view_observer.h"
13 #include "ipc/ipc_sender.h"
16 class DictionaryValue;
22 struct WebPluginParams;
28 class BrowserPluginDelegate;
29 class BrowserPluginManagerFactory;
32 // BrowserPluginManager manages the routing of messages to the appropriate
33 // BrowserPlugin object based on its instance ID.
34 class CONTENT_EXPORT BrowserPluginManager
35 : public RenderViewObserver,
36 public base::RefCounted<BrowserPluginManager> {
38 // Returns the one BrowserPluginManager for this process.
39 static BrowserPluginManager* Create(RenderViewImpl* render_view);
41 // Overrides factory for testing. Default (NULL) value indicates regular
42 // (non-test) environment.
43 static void set_factory_for_testing(BrowserPluginManagerFactory* factory) {
44 BrowserPluginManager::factory_ = factory;
47 explicit BrowserPluginManager(RenderViewImpl* render_view);
49 // Creates a new BrowserPlugin object.
50 // BrowserPlugin is responsible for associating itself with the
51 // BrowserPluginManager via AddBrowserPlugin. When it is destroyed, it is
52 // responsible for removing its association via RemoveBrowserPlugin.
53 virtual BrowserPlugin* CreateBrowserPlugin(
54 RenderViewImpl* render_view,
55 blink::WebFrame* frame,
56 scoped_ptr<BrowserPluginDelegate> delegate) = 0;
58 void Attach(int browser_plugin_instance_id);
60 void AddBrowserPlugin(int browser_plugin_instance_id,
61 BrowserPlugin* browser_plugin);
62 void RemoveBrowserPlugin(int browser_plugin_instance_id);
63 BrowserPlugin* GetBrowserPlugin(int browser_plugin_instance_id) const;
65 void UpdateDeviceScaleFactor();
66 void UpdateFocusState();
67 RenderViewImpl* render_view() const { return render_view_.get(); }
68 int GetNextInstanceID();
70 // RenderViewObserver implementation.
72 // BrowserPluginManager must override the default Send behavior.
73 virtual bool Send(IPC::Message* msg) OVERRIDE = 0;
75 // Don't destroy the BrowserPluginManager when the RenderViewImpl goes away.
76 // BrowserPluginManager's lifetime is managed by a reference count. Once
77 // the host RenderViewImpl and all BrowserPlugins release their references,
78 // then the BrowserPluginManager will be destroyed.
79 virtual void OnDestruct() OVERRIDE {}
82 // Friend RefCounted so that the dtor can be non-public.
83 friend class base::RefCounted<BrowserPluginManager>;
85 // Static factory instance (always NULL for non-test).
86 static BrowserPluginManagerFactory* factory_;
88 virtual ~BrowserPluginManager();
89 // This map is keyed by guest instance IDs.
90 IDMap<BrowserPlugin> instances_;
91 int current_instance_id_;
92 base::WeakPtr<RenderViewImpl> render_view_;
94 DISALLOW_COPY_AND_ASSIGN(BrowserPluginManager);
97 } // namespace content
99 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_