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 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "content/common/browser_plugin/browser_plugin_constants.h"
9 #include "content/public/renderer/browser_plugin_delegate.h"
10 #include "content/public/renderer/render_thread.h"
11 #include "content/renderer/browser_plugin/browser_plugin.h"
16 BrowserPluginManager
* BrowserPluginManager::Create(
17 RenderViewImpl
* render_view
) {
18 return new BrowserPluginManager(render_view
);
21 BrowserPluginManager::BrowserPluginManager(RenderViewImpl
* render_view
)
22 : RenderViewObserver(render_view
),
23 current_instance_id_(browser_plugin::kInstanceIDNone
),
24 render_view_(render_view
->AsWeakPtr()) {
27 BrowserPluginManager::~BrowserPluginManager() {
30 void BrowserPluginManager::AddBrowserPlugin(
31 int browser_plugin_instance_id
,
32 BrowserPlugin
* browser_plugin
) {
33 instances_
.AddWithID(browser_plugin
, browser_plugin_instance_id
);
36 void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id
) {
37 instances_
.Remove(browser_plugin_instance_id
);
40 BrowserPlugin
* BrowserPluginManager::GetBrowserPlugin(
41 int browser_plugin_instance_id
) const {
42 return instances_
.Lookup(browser_plugin_instance_id
);
45 int BrowserPluginManager::GetNextInstanceID() {
46 return ++current_instance_id_
;
49 void BrowserPluginManager::UpdateDeviceScaleFactor() {
50 IDMap
<BrowserPlugin
>::iterator
iter(&instances_
);
51 while (!iter
.IsAtEnd()) {
52 iter
.GetCurrentValue()->UpdateDeviceScaleFactor();
57 void BrowserPluginManager::UpdateFocusState() {
58 IDMap
<BrowserPlugin
>::iterator
iter(&instances_
);
59 while (!iter
.IsAtEnd()) {
60 iter
.GetCurrentValue()->UpdateGuestFocusState();
65 void BrowserPluginManager::Attach(int browser_plugin_instance_id
) {
66 BrowserPlugin
* plugin
= GetBrowserPlugin(browser_plugin_instance_id
);
71 BrowserPlugin
* BrowserPluginManager::CreateBrowserPlugin(
72 RenderViewImpl
* render_view
,
73 blink::WebFrame
* frame
,
74 scoped_ptr
<BrowserPluginDelegate
> delegate
) {
75 return new BrowserPlugin(render_view
, frame
, delegate
.Pass());
78 void BrowserPluginManager::DidCommitCompositorFrame() {
79 IDMap
<BrowserPlugin
>::iterator
iter(&instances_
);
80 while (!iter
.IsAtEnd()) {
81 iter
.GetCurrentValue()->DidCommitCompositorFrame();
86 bool BrowserPluginManager::OnMessageReceived(
87 const IPC::Message
& message
) {
88 if (BrowserPlugin::ShouldForwardToBrowserPlugin(message
)) {
89 int browser_plugin_instance_id
= browser_plugin::kInstanceIDNone
;
90 // All allowed messages must have |browser_plugin_instance_id| as their
92 PickleIterator
iter(message
);
93 bool success
= iter
.ReadInt(&browser_plugin_instance_id
);
95 BrowserPlugin
* plugin
= GetBrowserPlugin(browser_plugin_instance_id
);
96 if (plugin
&& plugin
->OnMessageReceived(message
))
103 bool BrowserPluginManager::Send(IPC::Message
* msg
) {
104 return RenderThread::Get()->Send(msg
);
107 } // namespace content