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 #include "chrome/browser/plugins/plugin_finder.h" | 5 #include "chrome/browser/plugins/plugin_finder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #endif | 27 #endif |
28 | 28 |
29 using base::DictionaryValue; | 29 using base::DictionaryValue; |
30 using content::PluginService; | 30 using content::PluginService; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 typedef std::map<std::string, PluginMetadata*> PluginMap; | 34 typedef std::map<std::string, PluginMetadata*> PluginMap; |
35 | 35 |
36 // Gets the full path of the plug-in file as the identifier. | 36 // Gets the full path of the plug-in file as the identifier. |
37 std::string GetLongIdentifier(const webkit::WebPluginInfo& plugin) { | 37 std::string GetLongIdentifier(const content::WebPluginInfo& plugin) { |
38 return plugin.path.AsUTF8Unsafe(); | 38 return plugin.path.AsUTF8Unsafe(); |
39 } | 39 } |
40 | 40 |
41 // Gets the base name of the file path as the identifier. | 41 // Gets the base name of the file path as the identifier. |
42 std::string GetIdentifier(const webkit::WebPluginInfo& plugin) { | 42 std::string GetIdentifier(const content::WebPluginInfo& plugin) { |
43 return plugin.path.BaseName().AsUTF8Unsafe(); | 43 return plugin.path.BaseName().AsUTF8Unsafe(); |
44 } | 44 } |
45 | 45 |
46 // Gets the plug-in group name as the plug-in name if it is not empty or | 46 // Gets the plug-in group name as the plug-in name if it is not empty or |
47 // the filename without extension if the name is empty. | 47 // the filename without extension if the name is empty. |
48 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) { | 48 static string16 GetGroupName(const content::WebPluginInfo& plugin) { |
49 if (!plugin.name.empty()) | 49 if (!plugin.name.empty()) |
50 return plugin.name; | 50 return plugin.name; |
51 | 51 |
52 base::FilePath::StringType path = | 52 base::FilePath::StringType path = |
53 plugin.path.BaseName().RemoveExtension().value(); | 53 plugin.path.BaseName().RemoveExtension().value(); |
54 #if defined(OS_POSIX) | 54 #if defined(OS_POSIX) |
55 return UTF8ToUTF16(path); | 55 return UTF8ToUTF16(path); |
56 #elif defined(OS_WIN) | 56 #elif defined(OS_WIN) |
57 return WideToUTF16(path); | 57 return WideToUTF16(path); |
58 #endif | 58 #endif |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 base::AutoLock lock(mutex_); | 270 base::AutoLock lock(mutex_); |
271 PluginMap::const_iterator it = identifier_plugin_.find(identifier); | 271 PluginMap::const_iterator it = identifier_plugin_.find(identifier); |
272 string16 name; | 272 string16 name; |
273 if (it != identifier_plugin_.end()) | 273 if (it != identifier_plugin_.end()) |
274 name = it->second->name(); | 274 name = it->second->name(); |
275 | 275 |
276 return name.empty() ? UTF8ToUTF16(identifier) : name; | 276 return name.empty() ? UTF8ToUTF16(identifier) : name; |
277 } | 277 } |
278 | 278 |
279 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( | 279 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
280 const webkit::WebPluginInfo& plugin) { | 280 const content::WebPluginInfo& plugin) { |
281 base::AutoLock lock(mutex_); | 281 base::AutoLock lock(mutex_); |
282 for (PluginMap::const_iterator it = identifier_plugin_.begin(); | 282 for (PluginMap::const_iterator it = identifier_plugin_.begin(); |
283 it != identifier_plugin_.end(); ++it) { | 283 it != identifier_plugin_.end(); ++it) { |
284 if (!it->second->MatchesPlugin(plugin)) | 284 if (!it->second->MatchesPlugin(plugin)) |
285 continue; | 285 continue; |
286 | 286 |
287 return it->second->Clone(); | 287 return it->second->Clone(); |
288 } | 288 } |
289 | 289 |
290 // The plug-in metadata was not found, create a dummy one holding | 290 // The plug-in metadata was not found, create a dummy one holding |
(...skipping 10 matching lines...) Expand all Loading... |
301 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); | 301 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); |
302 | 302 |
303 DCHECK(metadata->MatchesPlugin(plugin)); | 303 DCHECK(metadata->MatchesPlugin(plugin)); |
304 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) | 304 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) |
305 identifier = GetLongIdentifier(plugin); | 305 identifier = GetLongIdentifier(plugin); |
306 | 306 |
307 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); | 307 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); |
308 identifier_plugin_[identifier] = metadata; | 308 identifier_plugin_[identifier] = metadata; |
309 return metadata->Clone(); | 309 return metadata->Clone(); |
310 } | 310 } |
OLD | NEW |