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 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "base/values.h" |
9 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
10 #include "content/renderer/browser_plugin/browser_plugin.h" | 12 #include "content/renderer/browser_plugin/browser_plugin.h" |
11 #include "content/renderer/browser_plugin/browser_plugin_manager_factory.h" | 13 #include "content/renderer/browser_plugin/browser_plugin_manager_factory.h" |
12 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" | 14 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 // static | 18 // static |
17 BrowserPluginManagerFactory* BrowserPluginManager::factory_ = NULL; | 19 BrowserPluginManagerFactory* BrowserPluginManager::factory_ = NULL; |
18 | 20 |
19 BrowserPluginManager* BrowserPluginManager::Create( | 21 BrowserPluginManager* BrowserPluginManager::Create( |
20 RenderViewImpl* render_view) { | 22 RenderViewImpl* render_view) { |
21 if (factory_) | 23 if (factory_) |
22 return factory_->CreateBrowserPluginManager(render_view); | 24 return factory_->CreateBrowserPluginManager(render_view); |
23 return new BrowserPluginManagerImpl(render_view); | 25 return new BrowserPluginManagerImpl(render_view); |
24 } | 26 } |
25 | 27 |
26 BrowserPluginManager::BrowserPluginManager(RenderViewImpl* render_view) | 28 BrowserPluginManager::BrowserPluginManager(RenderViewImpl* render_view) |
27 : RenderViewObserver(render_view), | 29 : RenderViewObserver(render_view), |
| 30 // TODO(lazyboy): 10 is for testing only, change it to 1. |
| 31 next_instance_id_(10), |
28 render_view_(render_view->AsWeakPtr()) { | 32 render_view_(render_view->AsWeakPtr()) { |
29 } | 33 } |
30 | 34 |
31 BrowserPluginManager::~BrowserPluginManager() { | 35 BrowserPluginManager::~BrowserPluginManager() { |
32 } | 36 } |
33 | 37 |
34 void BrowserPluginManager::AddBrowserPlugin( | 38 void BrowserPluginManager::AddBrowserPlugin( |
35 int guest_instance_id, | 39 int guest_instance_id, |
36 BrowserPlugin* browser_plugin) { | 40 BrowserPlugin* browser_plugin) { |
37 instances_.AddWithID(browser_plugin, guest_instance_id); | 41 instances_.AddWithID(browser_plugin, guest_instance_id); |
38 } | 42 } |
39 | 43 |
40 void BrowserPluginManager::RemoveBrowserPlugin(int guest_instance_id) { | 44 void BrowserPluginManager::RemoveBrowserPlugin(int guest_instance_id) { |
41 instances_.Remove(guest_instance_id); | 45 instances_.Remove(guest_instance_id); |
42 } | 46 } |
43 | 47 |
44 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin( | 48 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin( |
45 int guest_instance_id) const { | 49 int guest_instance_id) const { |
46 return instances_.Lookup(guest_instance_id); | 50 return instances_.Lookup(guest_instance_id); |
47 } | 51 } |
48 | 52 |
| 53 void BrowserPluginManager::AddBrowserPluginInternal( |
| 54 int browser_plugin_instance_id, |
| 55 BrowserPlugin* browser_plugin) { |
| 56 instances_internal_.AddWithID(browser_plugin, browser_plugin_instance_id); |
| 57 } |
| 58 |
| 59 void BrowserPluginManager::RemoveBrowserPluginInternal( |
| 60 int browser_plugin_instance_id) { |
| 61 instances_internal_.Remove(browser_plugin_instance_id); |
| 62 } |
| 63 |
| 64 BrowserPlugin* BrowserPluginManager::GetBrowserPluginInternal( |
| 65 int browser_plugin_instance_id) const { |
| 66 return instances_internal_.Lookup(browser_plugin_instance_id); |
| 67 } |
| 68 |
| 69 int BrowserPluginManager::GetNextInstanceID() { |
| 70 return next_instance_id_++; |
| 71 } |
| 72 |
49 void BrowserPluginManager::UpdateDeviceScaleFactor(float device_scale_factor) { | 73 void BrowserPluginManager::UpdateDeviceScaleFactor(float device_scale_factor) { |
50 IDMap<BrowserPlugin>::iterator iter(&instances_); | 74 IDMap<BrowserPlugin>::iterator iter(&instances_); |
51 while (!iter.IsAtEnd()) { | 75 while (!iter.IsAtEnd()) { |
52 iter.GetCurrentValue()->UpdateDeviceScaleFactor(device_scale_factor); | 76 iter.GetCurrentValue()->UpdateDeviceScaleFactor(device_scale_factor); |
53 iter.Advance(); | 77 iter.Advance(); |
54 } | 78 } |
55 } | 79 } |
56 | 80 |
57 void BrowserPluginManager::UpdateFocusState() { | 81 void BrowserPluginManager::UpdateFocusState() { |
58 IDMap<BrowserPlugin>::iterator iter(&instances_); | 82 IDMap<BrowserPlugin>::iterator iter(&instances_); |
59 while (!iter.IsAtEnd()) { | 83 while (!iter.IsAtEnd()) { |
60 iter.GetCurrentValue()->UpdateGuestFocusState(); | 84 iter.GetCurrentValue()->UpdateGuestFocusState(); |
61 iter.Advance(); | 85 iter.Advance(); |
62 } | 86 } |
63 } | 87 } |
64 | 88 |
| 89 void BrowserPluginManager::AttachToBrowserPlugin( |
| 90 blink::WebNode& browser_plugin) { |
| 91 BrowserPlugin* plugin = BrowserPlugin::FromNode(browser_plugin); |
| 92 if (plugin) |
| 93 plugin->Attach(); |
| 94 } |
| 95 |
65 } // namespace content | 96 } // namespace content |
OLD | NEW |