Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / browser_plugin / browser_plugin_manager.h
blobbb9962cf37507af52bced34f80aa7d1a720c0d25
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"
15 namespace base {
16 class DictionaryValue;
19 namespace blink {
20 class WebFrame;
21 class WebNode;
22 struct WebPluginParams;
25 namespace content {
27 class BrowserPlugin;
28 class BrowserPluginManagerFactory;
29 class RenderViewImpl;
31 // BrowserPluginManager manages the routing of messages to the appropriate
32 // BrowserPlugin object based on its instance ID.
33 class CONTENT_EXPORT BrowserPluginManager
34 : public RenderViewObserver,
35 public base::RefCounted<BrowserPluginManager> {
36 public:
37 // Returns the one BrowserPluginManager for this process.
38 static BrowserPluginManager* Create(RenderViewImpl* render_view);
40 // Overrides factory for testing. Default (NULL) value indicates regular
41 // (non-test) environment.
42 static void set_factory_for_testing(BrowserPluginManagerFactory* factory) {
43 BrowserPluginManager::factory_ = factory;
46 explicit BrowserPluginManager(RenderViewImpl* render_view);
48 // Creates a new BrowserPlugin object.
49 // BrowserPlugin is responsible for associating itself with the
50 // BrowserPluginManager via AddBrowserPlugin. When it is destroyed, it is
51 // responsible for removing its association via RemoveBrowserPlugin.
52 virtual BrowserPlugin* CreateBrowserPlugin(
53 RenderViewImpl* render_view,
54 blink::WebFrame* frame,
55 bool auto_navigate) = 0;
57 void Attach(int browser_plugin_instance_id);
59 void AddBrowserPlugin(int browser_plugin_instance_id,
60 BrowserPlugin* browser_plugin);
61 void RemoveBrowserPlugin(int browser_plugin_instance_id);
62 BrowserPlugin* GetBrowserPlugin(int browser_plugin_instance_id) const;
64 void UpdateDeviceScaleFactor(float device_scale_factor);
65 void UpdateFocusState();
66 RenderViewImpl* render_view() const { return render_view_.get(); }
67 int GetNextInstanceID();
69 // RenderViewObserver implementation.
71 // BrowserPluginManager must override the default Send behavior.
72 virtual bool Send(IPC::Message* msg) OVERRIDE = 0;
74 // Don't destroy the BrowserPluginManager when the RenderViewImpl goes away.
75 // BrowserPluginManager's lifetime is managed by a reference count. Once
76 // the host RenderViewImpl and all BrowserPlugins release their references,
77 // then the BrowserPluginManager will be destroyed.
78 virtual void OnDestruct() OVERRIDE {}
80 protected:
81 // Friend RefCounted so that the dtor can be non-public.
82 friend class base::RefCounted<BrowserPluginManager>;
84 // Static factory instance (always NULL for non-test).
85 static BrowserPluginManagerFactory* factory_;
87 virtual ~BrowserPluginManager();
88 // This map is keyed by guest instance IDs.
89 IDMap<BrowserPlugin> instances_;
90 int current_instance_id_;
91 base::WeakPtr<RenderViewImpl> render_view_;
93 DISALLOW_COPY_AND_ASSIGN(BrowserPluginManager);
96 } // namespace content
98 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_