| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 base::string16 GetGroupName(const content::WebPluginInfo& plugin) { | 48 static base::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 return plugin.path.BaseName().RemoveExtension().AsUTF16Unsafe(); | 52 return plugin.path.BaseName().RemoveExtension().AsUTF16Unsafe(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void LoadMimeTypes(bool matching_mime_types, | 55 void LoadMimeTypes(bool matching_mime_types, |
| 56 const DictionaryValue* plugin_dict, | 56 const base::DictionaryValue* plugin_dict, |
| 57 PluginMetadata* plugin) { | 57 PluginMetadata* plugin) { |
| 58 const ListValue* mime_types = NULL; | 58 const base::ListValue* mime_types = NULL; |
| 59 std::string list_key = | 59 std::string list_key = |
| 60 matching_mime_types ? "matching_mime_types" : "mime_types"; | 60 matching_mime_types ? "matching_mime_types" : "mime_types"; |
| 61 if (!plugin_dict->GetList(list_key, &mime_types)) | 61 if (!plugin_dict->GetList(list_key, &mime_types)) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 bool success = false; | 64 bool success = false; |
| 65 for (ListValue::const_iterator mime_type_it = mime_types->begin(); | 65 for (base::ListValue::const_iterator mime_type_it = mime_types->begin(); |
| 66 mime_type_it != mime_types->end(); ++mime_type_it) { | 66 mime_type_it != mime_types->end(); ++mime_type_it) { |
| 67 std::string mime_type_str; | 67 std::string mime_type_str; |
| 68 success = (*mime_type_it)->GetAsString(&mime_type_str); | 68 success = (*mime_type_it)->GetAsString(&mime_type_str); |
| 69 DCHECK(success); | 69 DCHECK(success); |
| 70 if (matching_mime_types) { | 70 if (matching_mime_types) { |
| 71 plugin->AddMatchingMimeType(mime_type_str); | 71 plugin->AddMatchingMimeType(mime_type_str); |
| 72 } else { | 72 } else { |
| 73 plugin->AddMimeType(mime_type_str); | 73 plugin->AddMimeType(mime_type_str); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 PluginMetadata* CreatePluginMetadata( | 78 PluginMetadata* CreatePluginMetadata( |
| 79 const std::string& identifier, | 79 const std::string& identifier, |
| 80 const DictionaryValue* plugin_dict) { | 80 const base::DictionaryValue* plugin_dict) { |
| 81 std::string url; | 81 std::string url; |
| 82 bool success = plugin_dict->GetString("url", &url); | 82 bool success = plugin_dict->GetString("url", &url); |
| 83 std::string help_url; | 83 std::string help_url; |
| 84 plugin_dict->GetString("help_url", &help_url); | 84 plugin_dict->GetString("help_url", &help_url); |
| 85 base::string16 name; | 85 base::string16 name; |
| 86 success = plugin_dict->GetString("name", &name); | 86 success = plugin_dict->GetString("name", &name); |
| 87 DCHECK(success); | 87 DCHECK(success); |
| 88 bool display_url = false; | 88 bool display_url = false; |
| 89 plugin_dict->GetBoolean("displayurl", &display_url); | 89 plugin_dict->GetBoolean("displayurl", &display_url); |
| 90 base::string16 group_name_matcher; | 90 base::string16 group_name_matcher; |
| 91 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); | 91 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); |
| 92 DCHECK(success); | 92 DCHECK(success); |
| 93 std::string language_str; | 93 std::string language_str; |
| 94 plugin_dict->GetString("lang", &language_str); | 94 plugin_dict->GetString("lang", &language_str); |
| 95 | 95 |
| 96 PluginMetadata* plugin = new PluginMetadata(identifier, | 96 PluginMetadata* plugin = new PluginMetadata(identifier, |
| 97 name, | 97 name, |
| 98 display_url, | 98 display_url, |
| 99 GURL(url), | 99 GURL(url), |
| 100 GURL(help_url), | 100 GURL(help_url), |
| 101 group_name_matcher, | 101 group_name_matcher, |
| 102 language_str); | 102 language_str); |
| 103 const ListValue* versions = NULL; | 103 const base::ListValue* versions = NULL; |
| 104 if (plugin_dict->GetList("versions", &versions)) { | 104 if (plugin_dict->GetList("versions", &versions)) { |
| 105 for (ListValue::const_iterator it = versions->begin(); | 105 for (base::ListValue::const_iterator it = versions->begin(); |
| 106 it != versions->end(); ++it) { | 106 it != versions->end(); ++it) { |
| 107 DictionaryValue* version_dict = NULL; | 107 base::DictionaryValue* version_dict = NULL; |
| 108 if (!(*it)->GetAsDictionary(&version_dict)) { | 108 if (!(*it)->GetAsDictionary(&version_dict)) { |
| 109 NOTREACHED(); | 109 NOTREACHED(); |
| 110 continue; | 110 continue; |
| 111 } | 111 } |
| 112 std::string version; | 112 std::string version; |
| 113 success = version_dict->GetString("version", &version); | 113 success = version_dict->GetString("version", &version); |
| 114 DCHECK(success); | 114 DCHECK(success); |
| 115 std::string status_str; | 115 std::string status_str; |
| 116 success = version_dict->GetString("status", &status_str); | 116 success = version_dict->GetString("status", &status_str); |
| 117 DCHECK(success); | 117 DCHECK(success); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 PluginFinder::PluginFinder() : version_(-1) { | 145 PluginFinder::PluginFinder() : version_(-1) { |
| 146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void PluginFinder::Init() { | 149 void PluginFinder::Init() { |
| 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 151 // Load the built-in plug-in list first. If we have a newer version stored | 151 // Load the built-in plug-in list first. If we have a newer version stored |
| 152 // locally or download one, we will replace this one with it. | 152 // locally or download one, we will replace this one with it. |
| 153 scoped_ptr<DictionaryValue> plugin_list(LoadBuiltInPluginList()); | 153 scoped_ptr<base::DictionaryValue> plugin_list(LoadBuiltInPluginList()); |
| 154 DCHECK(plugin_list); | 154 DCHECK(plugin_list); |
| 155 ReinitializePlugins(plugin_list.get()); | 155 ReinitializePlugins(plugin_list.get()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // static | 158 // static |
| 159 DictionaryValue* PluginFinder::LoadBuiltInPluginList() { | 159 base::DictionaryValue* PluginFinder::LoadBuiltInPluginList() { |
| 160 base::StringPiece json_resource( | 160 base::StringPiece json_resource( |
| 161 ResourceBundle::GetSharedInstance().GetRawDataResource( | 161 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 162 IDR_PLUGIN_DB_JSON)); | 162 IDR_PLUGIN_DB_JSON)); |
| 163 std::string error_str; | 163 std::string error_str; |
| 164 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( | 164 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( |
| 165 json_resource, | 165 json_resource, |
| 166 base::JSON_PARSE_RFC, | 166 base::JSON_PARSE_RFC, |
| 167 NULL, | 167 NULL, |
| 168 &error_str)); | 168 &error_str)); |
| 169 if (!value.get()) { | 169 if (!value.get()) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 const char kVersionKey[] = "x-version"; | 236 const char kVersionKey[] = "x-version"; |
| 237 plugin_list->GetInteger(kVersionKey, &version); | 237 plugin_list->GetInteger(kVersionKey, &version); |
| 238 if (version <= version_) | 238 if (version <= version_) |
| 239 return; | 239 return; |
| 240 | 240 |
| 241 version_ = version; | 241 version_ = version; |
| 242 | 242 |
| 243 STLDeleteValues(&identifier_plugin_); | 243 STLDeleteValues(&identifier_plugin_); |
| 244 identifier_plugin_.clear(); | 244 identifier_plugin_.clear(); |
| 245 | 245 |
| 246 for (DictionaryValue::Iterator plugin_it(*plugin_list); | 246 for (base::DictionaryValue::Iterator plugin_it(*plugin_list); |
| 247 !plugin_it.IsAtEnd(); plugin_it.Advance()) { | 247 !plugin_it.IsAtEnd(); plugin_it.Advance()) { |
| 248 const DictionaryValue* plugin = NULL; | 248 const base::DictionaryValue* plugin = NULL; |
| 249 const std::string& identifier = plugin_it.key(); | 249 const std::string& identifier = plugin_it.key(); |
| 250 if (plugin_list->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { | 250 if (plugin_list->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { |
| 251 DCHECK(!identifier_plugin_[identifier]); | 251 DCHECK(!identifier_plugin_[identifier]); |
| 252 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); | 252 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
| 253 | 253 |
| 254 #if defined(ENABLE_PLUGIN_INSTALLATION) | 254 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 255 if (installers_.find(identifier) == installers_.end()) | 255 if (installers_.find(identifier) == installers_.end()) |
| 256 installers_[identifier] = new PluginInstaller(); | 256 installers_[identifier] = new PluginInstaller(); |
| 257 #endif | 257 #endif |
| 258 } | 258 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); | 295 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); |
| 296 | 296 |
| 297 DCHECK(metadata->MatchesPlugin(plugin)); | 297 DCHECK(metadata->MatchesPlugin(plugin)); |
| 298 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) | 298 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) |
| 299 identifier = GetLongIdentifier(plugin); | 299 identifier = GetLongIdentifier(plugin); |
| 300 | 300 |
| 301 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); | 301 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); |
| 302 identifier_plugin_[identifier] = metadata; | 302 identifier_plugin_[identifier] = metadata; |
| 303 return metadata->Clone(); | 303 return metadata->Clone(); |
| 304 } | 304 } |
| OLD | NEW |