Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / content / renderer / browser_plugin / browser_plugin_manager.h
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.
4
5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_
7
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"
13
14 namespace blink {
15 class WebFrame;
16 }
17
18 namespace content {
19
20 class BrowserPlugin;
21 class BrowserPluginDelegate;
22 class RenderViewImpl;
23
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> {
29  public:
30   // Returns the one BrowserPluginManager for this process.
31   static BrowserPluginManager* Create(RenderViewImpl* render_view);
32
33   explicit BrowserPluginManager(RenderViewImpl* render_view);
34
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);
43
44   void Attach(int browser_plugin_instance_id);
45
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;
50
51   void UpdateDeviceScaleFactor();
52   void UpdateFocusState();
53   RenderViewImpl* render_view() const { return render_view_.get(); }
54   int GetNextInstanceID();
55
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;
60
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 {}
66
67  private:
68   // Friend RefCounted so that the dtor can be non-public.
69   friend class base::RefCounted<BrowserPluginManager>;
70
71   ~BrowserPluginManager() override;
72
73   // IPC message handlers.
74   void OnCompositorFrameSwappedPluginUnavailable(const IPC::Message& message);
75
76   // This map is keyed by guest instance IDs.
77   IDMap<BrowserPlugin> instances_;
78   int current_instance_id_;
79   base::WeakPtr<RenderViewImpl> render_view_;
80
81   DISALLOW_COPY_AND_ASSIGN(BrowserPluginManager);
82 };
83
84 }  // namespace content
85
86 #endif //  CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_MANAGER_H_