OLD | NEW |
| (Empty) |
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 #ifndef CHROME_BROWSER_PLUGIN_FINDER_H_ | |
6 #define CHROME_BROWSER_PLUGIN_FINDER_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/gtest_prod_util.h" | |
13 #include "base/hash_tables.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/singleton.h" | |
16 #include "base/string16.h" | |
17 #include "webkit/plugins/webplugininfo.h" | |
18 | |
19 namespace base { | |
20 class DictionaryValue; | |
21 } | |
22 | |
23 class GURL; | |
24 class PluginInstaller; | |
25 | |
26 class PluginFinder { | |
27 public: | |
28 typedef std::vector<webkit::WebPluginInfo> PluginVector; | |
29 typedef base::Callback<void(const PluginVector&, PluginFinder*)> | |
30 CombinedCallback; | |
31 // Gets PluginFinder and vector of Plugins asynchronously. It then | |
32 // calls |cb| once both are fetched. | |
33 static void GetPluginsAndPluginFinder(const CombinedCallback& cb); | |
34 | |
35 static void Get(const base::Callback<void(PluginFinder*)>& cb); | |
36 | |
37 // Finds a plug-in for the given MIME type and language (specified as an IETF | |
38 // language tag, i.e. en-US) and returns the PluginInstaller for the plug-in, | |
39 // or NULL if no plug-in is found. | |
40 PluginInstaller* FindPlugin(const std::string& mime_type, | |
41 const std::string& language); | |
42 | |
43 // Returns the plug-in with the given identifier. | |
44 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); | |
45 | |
46 // Gets a plug-in installer using |plugin|. | |
47 PluginInstaller* GetPluginInstaller(const webkit::WebPluginInfo& plugin); | |
48 | |
49 private: | |
50 friend struct DefaultSingletonTraits<PluginFinder>; | |
51 friend class Singleton<PluginFinder>; | |
52 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); | |
53 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); | |
54 | |
55 static PluginFinder* GetInstance(); | |
56 | |
57 PluginFinder(); | |
58 ~PluginFinder(); | |
59 | |
60 // Loads the plug-in information from the browser resources and parses it. | |
61 // Returns NULL if the plug-in list couldn't be parsed. | |
62 static base::DictionaryValue* LoadPluginList(); | |
63 | |
64 PluginInstaller* CreateInstaller(const std::string& identifier, | |
65 const base::DictionaryValue* plugin_dict); | |
66 | |
67 scoped_ptr<base::DictionaryValue> plugin_list_; | |
68 std::map<std::string, PluginInstaller*> installers_; | |
69 | |
70 // Note: Don't free memory for |name_insallers_| values | |
71 // since it holds pointers to same instances | |
72 // in |installers_| (Double De-allocation). | |
73 base::hash_map<string16, PluginInstaller*> name_installers_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(PluginFinder); | |
76 }; | |
77 | |
78 #endif // CHROME_BROWSER_PLUGIN_FINDER_H_ | |
OLD | NEW |