Home | History | Annotate | Download | only in browser_plugin
      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 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
      6 
      7 #include "base/lazy_instance.h"
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/threading/thread_local.h"
     10 #include "base/values.h"
     11 #include "content/common/browser_plugin/browser_plugin_constants.h"
     12 #include "content/public/renderer/render_thread.h"
     13 #include "content/renderer/browser_plugin/browser_plugin.h"
     14 #include "content/renderer/browser_plugin/browser_plugin_manager_factory.h"
     15 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
     16 
     17 namespace content {
     18 
     19 // static
     20 BrowserPluginManagerFactory* BrowserPluginManager::factory_ = NULL;
     21 
     22 // static
     23 BrowserPluginManager* BrowserPluginManager::Create(
     24     RenderViewImpl* render_view) {
     25   if (factory_)
     26     return factory_->CreateBrowserPluginManager(render_view);
     27   return new BrowserPluginManagerImpl(render_view);
     28 }
     29 
     30 BrowserPluginManager::BrowserPluginManager(RenderViewImpl* render_view)
     31     : RenderViewObserver(render_view),
     32       current_instance_id_(browser_plugin::kInstanceIDNone),
     33       render_view_(render_view->AsWeakPtr()) {
     34 }
     35 
     36 BrowserPluginManager::~BrowserPluginManager() {
     37 }
     38 
     39 void BrowserPluginManager::AddBrowserPlugin(
     40     int browser_plugin_instance_id,
     41     BrowserPlugin* browser_plugin) {
     42   instances_.AddWithID(browser_plugin, browser_plugin_instance_id);
     43 }
     44 
     45 void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id) {
     46   instances_.Remove(browser_plugin_instance_id);
     47 }
     48 
     49 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin(
     50     int browser_plugin_instance_id) const {
     51   return instances_.Lookup(browser_plugin_instance_id);
     52 }
     53 
     54 int BrowserPluginManager::GetNextInstanceID() {
     55   return ++current_instance_id_;
     56 }
     57 
     58 void BrowserPluginManager::UpdateDeviceScaleFactor() {
     59   IDMap<BrowserPlugin>::iterator iter(&instances_);
     60   while (!iter.IsAtEnd()) {
     61     iter.GetCurrentValue()->UpdateDeviceScaleFactor();
     62     iter.Advance();
     63   }
     64 }
     65 
     66 void BrowserPluginManager::UpdateFocusState() {
     67   IDMap<BrowserPlugin>::iterator iter(&instances_);
     68   while (!iter.IsAtEnd()) {
     69     iter.GetCurrentValue()->UpdateGuestFocusState();
     70     iter.Advance();
     71   }
     72 }
     73 
     74 void BrowserPluginManager::Attach(int browser_plugin_instance_id) {
     75   BrowserPlugin* plugin = GetBrowserPlugin(browser_plugin_instance_id);
     76   if (plugin)
     77     plugin->Attach();
     78 }
     79 
     80 }  // namespace content
     81