OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_ |
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_ | 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_ |
7 | 7 |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "base/threading/non_thread_safe.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "content/public/renderer/render_process_observer.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/observer_list.h" | |
12 #include "content/public/renderer/render_view_observer.h" | |
11 #include "ipc/ipc_sender.h" | 13 #include "ipc/ipc_sender.h" |
12 | 14 |
13 namespace WebKit { | 15 namespace WebKit { |
14 class WebFrame; | 16 class WebFrame; |
15 struct WebPluginParams; | 17 struct WebPluginParams; |
16 } | 18 } |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 | 21 |
20 class BrowserPlugin; | 22 class BrowserPlugin; |
23 class BrowserPluginManagerFactory; | |
21 class RenderViewImpl; | 24 class RenderViewImpl; |
22 | 25 |
23 // BrowserPluginManager manages the routing of messages to the appropriate | 26 // BrowserPluginManager manages the routing of messages to the appropriate |
24 // BrowserPlugin object based on its instance ID. There is only one | 27 // BrowserPlugin object based on its instance ID. |
25 // BrowserPluginManager per renderer process, and it should only be accessed | 28 class CONTENT_EXPORT BrowserPluginManager |
26 // by the render thread. | 29 : public RenderViewObserver, |
27 class CONTENT_EXPORT BrowserPluginManager : public IPC::Sender, | 30 public base::RefCounted<BrowserPluginManager> { |
28 public RenderProcessObserver, | |
29 public base::NonThreadSafe { | |
30 public: | 31 public: |
31 // Returns the one BrowserPluginManager for this process. | 32 // Returns the one BrowserPluginManager for this process. |
32 static BrowserPluginManager* Get(); | 33 static BrowserPluginManager* Create(RenderViewImpl* render_view); |
33 | 34 |
34 BrowserPluginManager(); | 35 // Overrides factory for testing. Default (NULL) value indicates regular |
35 virtual ~BrowserPluginManager(); | 36 // (non-test) environment. |
37 static void set_factory_for_testing(BrowserPluginManagerFactory* factory) { | |
38 BrowserPluginManager::factory_ = factory; | |
39 } | |
40 | |
41 BrowserPluginManager(RenderViewImpl* render_view); | |
36 | 42 |
37 // Creates a new BrowserPlugin object with a unique identifier. | 43 // Creates a new BrowserPlugin object with a unique identifier. |
38 // BrowserPlugin is responsible for associating itself with the | 44 // BrowserPlugin is responsible for associating itself with the |
39 // BrowserPluginManager via AddBrowserPlugin. When it is destroyed, it is | 45 // BrowserPluginManager via AddBrowserPlugin. When it is destroyed, it is |
40 // responsible for removing its association via RemoveBrowserPlugin. | 46 // responsible for removing its association via RemoveBrowserPlugin. |
41 virtual BrowserPlugin* CreateBrowserPlugin( | 47 virtual BrowserPlugin* CreateBrowserPlugin( |
42 RenderViewImpl* render_view, | 48 RenderViewImpl* render_view, |
43 WebKit::WebFrame* frame, | 49 WebKit::WebFrame* frame, |
44 const WebKit::WebPluginParams& params) = 0; | 50 const WebKit::WebPluginParams& params) = 0; |
45 | 51 |
46 void AddBrowserPlugin(int instance_id, BrowserPlugin* browser_plugin); | 52 void AddBrowserPlugin(int instance_id, BrowserPlugin* browser_plugin); |
47 void RemoveBrowserPlugin(int instance_id); | 53 void RemoveBrowserPlugin(int instance_id); |
48 BrowserPlugin* GetBrowserPlugin(int instance_id) const; | 54 BrowserPlugin* GetBrowserPlugin(int instance_id) const; |
49 void SetEmbedderFocus(const RenderViewImpl* embedder, bool focused); | 55 void SetEmbedderFocus(const RenderViewImpl* embedder, bool focused); |
56 RenderViewImpl* render_view() const { return render_view_; } | |
57 | |
58 // RenderViewObserver implementation. | |
59 | |
60 // BrowserPluginManager must override the default Send behavior. | |
61 virtual bool Send(IPC::Message* msg) OVERRIDE = 0; | |
62 // Don't destroy the BrowserPluginManager when the RenderViewImpl goes away. | |
Charlie Reis
2012/11/20 00:33:34
nit: Blank line before.
Fady Samuel
2012/11/20 02:04:15
Done.
| |
63 // BrowserPluginManager's lifetime is managed by a reference count. Once | |
64 // the host RenderViewImpl and all BrowserPlugins release their references, | |
65 // then the BrowserPluginManager will be destroyed. | |
66 virtual void OnDestruct() OVERRIDE {} | |
50 | 67 |
51 protected: | 68 protected: |
69 // Friend RefCounted so that the dtor can be non-public. | |
70 friend class base::RefCounted<BrowserPluginManager>; | |
71 | |
72 // Static factory instance (always NULL for non-test). | |
73 static BrowserPluginManagerFactory* factory_; | |
74 | |
75 virtual ~BrowserPluginManager(); | |
52 IDMap<BrowserPlugin> instances_; | 76 IDMap<BrowserPlugin> instances_; |
77 base::WeakPtr<RenderViewImpl> render_view_; | |
53 int browser_plugin_counter_; | 78 int browser_plugin_counter_; |
54 }; | 79 }; |
55 | 80 |
56 } // namespace content | 81 } // namespace content |
57 | 82 |
58 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_ | 83 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_ |
OLD | NEW |