Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / plugins / plugin_finder.h
blob6a12911ef3e38c150d5352c192362525cec3efca
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 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_
6 #define CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_
8 #include <map>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h"
15 #include "base/strings/string16.h"
16 #include "base/synchronization/lock.h"
17 #include "content/public/common/webplugininfo.h"
19 namespace base {
20 class DictionaryValue;
23 class GURL;
24 class PluginMetadata;
25 class PrefRegistrySimple;
27 #if defined(ENABLE_PLUGIN_INSTALLATION)
28 class PluginInstaller;
29 #endif
31 // This class should be created and initialized by calling
32 // |GetInstance()| and |Init()| on the UI thread.
33 // After that it can be safely used on any other thread.
34 class PluginFinder {
35 public:
36 static void RegisterPrefs(PrefRegistrySimple* registry);
38 static PluginFinder* GetInstance();
40 // It should be called on the UI thread.
41 void Init();
43 void ReinitializePlugins(const base::DictionaryValue* json_metadata);
45 #if defined(ENABLE_PLUGIN_INSTALLATION)
46 // Finds a plugin for the given MIME type and language (specified as an IETF
47 // language tag, i.e. en-US). If found, sets |installer| to the
48 // corresponding PluginInstaller and |plugin_metadata| to a copy of the
49 // corresponding PluginMetadata.
50 bool FindPlugin(const std::string& mime_type,
51 const std::string& language,
52 PluginInstaller** installer,
53 scoped_ptr<PluginMetadata>* plugin_metadata);
55 // Finds the plugin with the given identifier. If found, sets |installer|
56 // to the corresponding PluginInstaller and |plugin_metadata| to a copy
57 // of the corresponding PluginMetadata. |installer| may be NULL.
58 bool FindPluginWithIdentifier(const std::string& identifier,
59 PluginInstaller** installer,
60 scoped_ptr<PluginMetadata>* plugin_metadata);
61 #endif
63 // Returns the plugin name with the given |identifier| or |identifier| if not
64 // found.
65 base::string16 FindPluginNameWithIdentifier(const std::string& identifier);
67 // Returns the plugin name with the given |mime_type| and |language| or
68 // |mime_type| if not found.
69 base::string16 FindPluginName(const std::string& mime_type,
70 const std::string& language);
72 // Gets plugin metadata using |plugin|.
73 scoped_ptr<PluginMetadata> GetPluginMetadata(
74 const content::WebPluginInfo& plugin);
76 private:
77 friend struct base::DefaultSingletonTraits<PluginFinder>;
78 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax);
79 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups);
81 PluginFinder();
82 ~PluginFinder();
84 // Loads the plugin information from the browser resources and parses it.
85 // Returns NULL if the plugin list couldn't be parsed.
86 static base::DictionaryValue* LoadBuiltInPluginList();
88 #if defined(ENABLE_PLUGIN_INSTALLATION)
89 std::map<std::string, PluginInstaller*> installers_;
90 #endif
92 std::map<std::string, PluginMetadata*> identifier_plugin_;
94 // Version of the metadata information. We use this to consolidate multiple
95 // sources (baked into resource and fetched from a URL), making sure that we
96 // don't overwrite newer versions with older ones.
97 int version_;
99 // Synchronization for the above member variables is
100 // required since multiple threads can be accessing them concurrently.
101 base::Lock mutex_;
103 DISALLOW_COPY_AND_ASSIGN(PluginFinder);
106 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_