| 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 #ifndef CHROME_BROWSER_PLUGIN_FINDER_H_ | 5 #ifndef CHROME_BROWSER_PLUGIN_FINDER_H_ |
| 6 #define CHROME_BROWSER_PLUGIN_FINDER_H_ | 6 #define CHROME_BROWSER_PLUGIN_FINDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "webkit/plugins/webplugininfo.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class DictionaryValue; | 19 class DictionaryValue; |
| 19 } | 20 } |
| 20 | 21 |
| 21 class GURL; | 22 class GURL; |
| 22 class PluginInstaller; | 23 class PluginInstaller; |
| 23 | 24 |
| 24 class PluginFinder { | 25 class PluginFinder { |
| 25 public: | 26 public: |
| 26 static void Get(const base::Callback<void(PluginFinder*)>& cb); | 27 static void Get(const base::Callback<void(PluginFinder*)>& cb); |
| 27 | 28 |
| 28 // Finds a plug-in for the given MIME type and language (specified as an IETF | 29 // Finds a plug-in for the given MIME type and language (specified as an IETF |
| 29 // language tag, i.e. en-US) and returns the PluginInstaller for the plug-in, | 30 // language tag, i.e. en-US) and returns the PluginInstaller for the plug-in, |
| 30 // or NULL if no plug-in is found. | 31 // or NULL if no plug-in is found. |
| 31 PluginInstaller* FindPlugin(const std::string& mime_type, | 32 PluginInstaller* FindPlugin(const std::string& mime_type, |
| 32 const std::string& language); | 33 const std::string& language); |
| 33 | 34 |
| 34 // Returns the plug-in with the given identifier. | 35 // Returns the plug-in with the given identifier. |
| 35 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); | 36 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); |
| 36 | 37 |
| 38 // Gets a plug-in installer using web plug-in info. |
| 39 PluginInstaller* GetPluginInstaller(const webkit::WebPluginInfo& plugin); |
| 40 |
| 37 private: | 41 private: |
| 38 friend struct DefaultSingletonTraits<PluginFinder>; | 42 friend struct DefaultSingletonTraits<PluginFinder>; |
| 39 friend class Singleton<PluginFinder>; | 43 friend class Singleton<PluginFinder>; |
| 40 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); | 44 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); |
| 41 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); | 45 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); |
| 42 | 46 |
| 43 static PluginFinder* GetInstance(); | 47 static PluginFinder* GetInstance(); |
| 44 | 48 |
| 45 PluginFinder(); | 49 PluginFinder(); |
| 46 ~PluginFinder(); | 50 ~PluginFinder(); |
| 47 | 51 |
| 48 // Loads the plug-in information from the browser resources and parses it. | 52 // Loads the plug-in information from the browser resources and parses it. |
| 49 // Returns NULL if the plug-in list couldn't be parsed. | 53 // Returns NULL if the plug-in list couldn't be parsed. |
| 50 static base::DictionaryValue* LoadPluginList(); | 54 static base::DictionaryValue* LoadPluginList(); |
| 51 | 55 |
| 52 PluginInstaller* CreateInstaller(const std::string& identifier, | 56 PluginInstaller* CreateInstaller(const std::string& identifier, |
| 53 const base::DictionaryValue* plugin_dict); | 57 const base::DictionaryValue* plugin_dict); |
| 54 | 58 |
| 59 // Gets the base name of the file path as the identifier. |
| 60 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin); |
| 61 |
| 62 // Gets the plug-in group name as the plug-in name if it is not empty or |
| 63 // the filename without extension if the name is empty. |
| 64 static string16 GetGroupName(const webkit::WebPluginInfo& plugin); |
| 65 |
| 55 scoped_ptr<base::DictionaryValue> plugin_list_; | 66 scoped_ptr<base::DictionaryValue> plugin_list_; |
| 56 std::map<std::string, PluginInstaller*> installers_; | 67 std::map<std::string, PluginInstaller*> installers_; |
| 57 | 68 |
| 58 DISALLOW_COPY_AND_ASSIGN(PluginFinder); | 69 DISALLOW_COPY_AND_ASSIGN(PluginFinder); |
| 59 }; | 70 }; |
| 60 | 71 |
| 61 #endif // CHROME_BROWSER_PLUGIN_FINDER_H_ | 72 #endif // CHROME_BROWSER_PLUGIN_FINDER_H_ |
| OLD | NEW |