Chromium Code Reviews| Index: chrome/browser/plugins/plugin_finder.cc |
| diff --git a/chrome/browser/plugins/plugin_finder.cc b/chrome/browser/plugins/plugin_finder.cc |
| index 91345d2340eb7e3d0694ca5dddb6333c817c7ca3..bbb56a509be5703e5fc2a067bcddea5c9cddd3b5 100644 |
| --- a/chrome/browser/plugins/plugin_finder.cc |
| +++ b/chrome/browser/plugins/plugin_finder.cc |
| @@ -31,6 +31,11 @@ using content::PluginService; |
| namespace { |
| +typedef std::map<std::string, PluginMetadata*> PluginMap; |
| + |
| +const char kMimeTypesListKey[] = "mime_types"; |
| +const char kMatchingMimeTypesListKey[] = "matching_mime_types"; |
| + |
| // Gets the base name of the file path as the identifier. |
| static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) { |
| #if defined(OS_POSIX) |
| @@ -54,6 +59,30 @@ static string16 GetGroupName(const webkit::WebPluginInfo& plugin) { |
| #endif |
| } |
| +void LoadMimeTypes(const std::string& mime_type_list_key, |
| + const DictionaryValue* plugin_dict, |
| + PluginMetadata* plugin) { |
| + const ListValue* mime_types = NULL; |
| + if (!plugin_dict->GetList(mime_type_list_key, &mime_types)) |
| + return; |
| + |
| + bool success = false; |
| + for (ListValue::const_iterator mime_type_it = mime_types->begin(); |
| + mime_type_it != mime_types->end(); ++mime_type_it) { |
| + std::string mime_type_str; |
| + success = (*mime_type_it)->GetAsString(&mime_type_str); |
| + DCHECK(success); |
| + if (mime_type_list_key == kMatchingMimeTypesListKey) { |
| + plugin->AddMatchingMimeType(mime_type_str); |
| + } else if (mime_type_list_key == kMimeTypesListKey) { |
| + plugin->AddMimeType(mime_type_str); |
| + } else { |
| + NOTREACHED(); |
| + return; |
| + } |
| + } |
| +} |
| + |
| PluginMetadata* CreatePluginMetadata( |
| const std::string& identifier, |
| const DictionaryValue* plugin_dict) { |
| @@ -69,13 +98,16 @@ PluginMetadata* CreatePluginMetadata( |
| string16 group_name_matcher; |
| success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); |
| DCHECK(success); |
| + std::string language_str; |
| + plugin_dict->GetString("lang", &language_str); |
| PluginMetadata* plugin = new PluginMetadata(identifier, |
| name, |
| display_url, |
| GURL(url), |
| GURL(help_url), |
| - group_name_matcher); |
| + group_name_matcher, |
| + language_str); |
| const ListValue* versions = NULL; |
| if (plugin_dict->GetList("versions", &versions)) { |
| for (ListValue::const_iterator it = versions->begin(); |
| @@ -99,6 +131,8 @@ PluginMetadata* CreatePluginMetadata( |
| } |
| } |
| + LoadMimeTypes(kMimeTypesListKey, plugin_dict, plugin); |
| + LoadMimeTypes(kMatchingMimeTypesListKey, plugin_dict, plugin); |
| return plugin; |
| } |
| @@ -169,38 +203,18 @@ bool PluginFinder::FindPlugin( |
| base::AutoLock lock(mutex_); |
| if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) |
| return false; |
| - for (DictionaryValue::Iterator plugin_it(*plugin_list_); |
| - plugin_it.HasNext(); plugin_it.Advance()) { |
| - const DictionaryValue* plugin = NULL; |
| - if (!plugin_it.value().GetAsDictionary(&plugin)) { |
| - NOTREACHED(); |
| - continue; |
| - } |
| - std::string language_str; |
| - bool success = plugin->GetString("lang", &language_str); |
| - if (language_str != language) |
| - continue; |
| - const ListValue* mime_types = NULL; |
| - if (plugin->GetList("mime_types", &mime_types)) { |
| - for (ListValue::const_iterator mime_type_it = mime_types->begin(); |
| - mime_type_it != mime_types->end(); ++mime_type_it) { |
| - std::string mime_type_str; |
| - success = (*mime_type_it)->GetAsString(&mime_type_str); |
| - DCHECK(success); |
| - if (mime_type_str == mime_type) { |
| - std::string identifier = plugin_it.key(); |
| - std::map<std::string, PluginMetadata*>::const_iterator metadata_it = |
| - identifier_plugin_.find(identifier); |
| - DCHECK(metadata_it != identifier_plugin_.end()); |
| - *plugin_metadata = metadata_it->second->Clone(); |
| - |
| - std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| - installers_.find(identifier); |
| - DCHECK(installer_it != installers_.end()); |
| - *installer = installer_it->second; |
| - return true; |
| - } |
| - } |
| + |
| + PluginMap::const_iterator metadata_it = identifier_plugin_.begin(); |
| + for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { |
| + if (language == metadata_it->second->language() && |
| + metadata_it->second->HasMimeType(mime_type)) { |
| + *plugin_metadata = metadata_it->second->Clone(); |
| + |
| + std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| + installers_.find(metadata_it->second->identifier()); |
| + DCHECK(installer_it != installers_.end()); |
| + *installer = installer_it->second; |
| + return true; |
| } |
| } |
| return false; |
| @@ -215,8 +229,7 @@ bool PluginFinder::FindPluginWithIdentifier( |
| installers_.find(identifier); |
| if (it != installers_.end()) { |
| *installer = it->second; |
| - std::map<std::string, PluginMetadata*>::const_iterator metadata_it = |
| - identifier_plugin_.find(identifier); |
| + PluginMap::const_iterator metadata_it = identifier_plugin_.find(identifier); |
| DCHECK(metadata_it != identifier_plugin_.end()); |
| *plugin_metadata = metadata_it->second->Clone(); |
| return true; |
| @@ -230,7 +243,6 @@ void PluginFinder::ReinitializePlugins( |
| base::AutoLock lock(mutex_); |
| STLDeleteValues(&identifier_plugin_); |
| identifier_plugin_.clear(); |
| - name_plugin_.clear(); |
| plugin_list_.reset(json_metadata.DeepCopy()); |
| InitInternal(); |
| @@ -240,8 +252,7 @@ void PluginFinder::ReinitializePlugins( |
| string16 PluginFinder::FindPluginNameWithIdentifier( |
| const std::string& identifier) { |
| base::AutoLock lock(mutex_); |
| - std::map<std::string, PluginMetadata*>::const_iterator it = |
| - identifier_plugin_.find(identifier); |
| + PluginMap::const_iterator it = identifier_plugin_.find(identifier); |
| string16 name; |
| if (it != identifier_plugin_.end()) |
| name = it->second->name(); |
| @@ -252,16 +263,12 @@ string16 PluginFinder::FindPluginNameWithIdentifier( |
| scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| const webkit::WebPluginInfo& plugin) { |
| base::AutoLock lock(mutex_); |
| - if (name_plugin_.find(plugin.name) != name_plugin_.end()) |
| - return name_plugin_[plugin.name]->Clone(); |
| - |
| - // Use the group name matcher to find the plug-in metadata we want. |
| - for (std::map<std::string, PluginMetadata*>::const_iterator it = |
| - identifier_plugin_.begin(); it != identifier_plugin_.end(); ++it) { |
| - if (!it->second->MatchesPlugin(plugin)) |
| + for (PluginMap::const_iterator it = identifier_plugin_.begin(); |
| + it != identifier_plugin_.end(); ++it) { |
| + string16 matching_name; |
|
Bernhard Bauer
2012/10/04 11:37:19
Ok, now you're not using |matching_name| anymore.
ibraaaa
2012/10/04 12:24:12
Done.
|
| + if (!it->second->MatchesPlugin(plugin, &matching_name)) |
| continue; |
| - name_plugin_[plugin.name] = it->second; |
| return it->second->Clone(); |
| } |
| @@ -271,9 +278,8 @@ scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| PluginMetadata* metadata = new PluginMetadata(identifier, |
| GetGroupName(plugin), |
| false, GURL(), GURL(), |
| - GetGroupName(plugin)); |
| - |
| - name_plugin_[plugin.name] = metadata; |
| + GetGroupName(plugin), |
| + ""); |
| identifier_plugin_[identifier] = metadata; |
| return metadata->Clone(); |
| } |