plugin_finder.h 3.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_
#define CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_

#include <map>
#include <string>

#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
15
#include "base/strings/string16.h"
16
#include "base/synchronization/lock.h"
17
#include "content/public/common/webplugininfo.h"
18 19 20 21 22 23 24

namespace base {
class DictionaryValue;
}

class GURL;
class PluginMetadata;
25
class PrefRegistrySimple;
26 27 28 29 30 31 32 33 34 35

#if defined(ENABLE_PLUGIN_INSTALLATION)
class PluginInstaller;
#endif

// This class should be created and initialized by calling
// |GetInstance()| and |Init()| on the UI thread.
// After that it can be safely used on any other thread.
class PluginFinder {
 public:
36
  static void RegisterPrefs(PrefRegistrySimple* registry);
37 38 39 40 41 42

  static PluginFinder* GetInstance();

  // It should be called on the UI thread.
  void Init();

43
  void ReinitializePlugins(const base::DictionaryValue* json_metadata);
44

45
#if defined(ENABLE_PLUGIN_INSTALLATION)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  // Finds a plug-in for the given MIME type and language (specified as an IETF
  // language tag, i.e. en-US). If found, sets |installer| to the
  // corresponding PluginInstaller and |plugin_metadata| to a copy of the
  // corresponding PluginMetadata.
  bool FindPlugin(const std::string& mime_type,
                  const std::string& language,
                  PluginInstaller** installer,
                  scoped_ptr<PluginMetadata>* plugin_metadata);

  // Finds the plug-in with the given identifier. If found, sets |installer|
  // to the corresponding PluginInstaller and |plugin_metadata| to a copy
  // of the corresponding PluginMetadata. |installer| may be NULL.
  bool FindPluginWithIdentifier(const std::string& identifier,
                                PluginInstaller** installer,
                                scoped_ptr<PluginMetadata>* plugin_metadata);
#endif

  // Returns the plug-in name with the given identifier.
64
  base::string16 FindPluginNameWithIdentifier(const std::string& identifier);
65 66 67

  // Gets plug-in metadata using |plugin|.
  scoped_ptr<PluginMetadata> GetPluginMetadata(
68
      const content::WebPluginInfo& plugin);
69 70 71 72 73 74 75 76 77 78 79 80

 private:
  friend struct DefaultSingletonTraits<PluginFinder>;
  friend class Singleton<PluginFinder>;
  FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax);
  FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups);

  PluginFinder();
  ~PluginFinder();

  // Loads the plug-in information from the browser resources and parses it.
  // Returns NULL if the plug-in list couldn't be parsed.
81
  static base::DictionaryValue* LoadBuiltInPluginList();
82 83 84 85 86 87 88

#if defined(ENABLE_PLUGIN_INSTALLATION)
  std::map<std::string, PluginInstaller*> installers_;
#endif

  std::map<std::string, PluginMetadata*> identifier_plugin_;

89 90 91 92 93
  // Version of the metadata information. We use this to consolidate multiple
  // sources (baked into resource and fetched from a URL), making sure that we
  // don't overwrite newer versions with older ones.
  int version_;

94 95 96 97 98 99 100 101
  // Synchronization for the above member variables is
  // required since multiple threads can be accessing them concurrently.
  base::Lock mutex_;

  DISALLOW_COPY_AND_ASSIGN(PluginFinder);
};

#endif  // CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_