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.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 std::string help_url; | 62 std::string help_url; |
63 plugin_dict->GetString("help_url", &help_url); | 63 plugin_dict->GetString("help_url", &help_url); |
64 string16 name; | 64 string16 name; |
65 success = plugin_dict->GetString("name", &name); | 65 success = plugin_dict->GetString("name", &name); |
66 DCHECK(success); | 66 DCHECK(success); |
67 bool display_url = false; | 67 bool display_url = false; |
68 plugin_dict->GetBoolean("displayurl", &display_url); | 68 plugin_dict->GetBoolean("displayurl", &display_url); |
69 string16 group_name_matcher; | 69 string16 group_name_matcher; |
70 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); | 70 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); |
71 DCHECK(success); | 71 DCHECK(success); |
| 72 std::string language_str; |
| 73 plugin_dict->GetString("lang", &language_str); |
72 | 74 |
73 PluginMetadata* plugin = new PluginMetadata(identifier, | 75 PluginMetadata* plugin = new PluginMetadata(identifier, |
74 name, | 76 name, |
75 display_url, | 77 display_url, |
76 GURL(url), | 78 GURL(url), |
77 GURL(help_url), | 79 GURL(help_url), |
78 group_name_matcher); | 80 group_name_matcher, |
| 81 language_str); |
79 const ListValue* versions = NULL; | 82 const ListValue* versions = NULL; |
80 if (plugin_dict->GetList("versions", &versions)) { | 83 if (plugin_dict->GetList("versions", &versions)) { |
81 for (ListValue::const_iterator it = versions->begin(); | 84 for (ListValue::const_iterator it = versions->begin(); |
82 it != versions->end(); ++it) { | 85 it != versions->end(); ++it) { |
83 DictionaryValue* version_dict = NULL; | 86 DictionaryValue* version_dict = NULL; |
84 if (!(*it)->GetAsDictionary(&version_dict)) { | 87 if (!(*it)->GetAsDictionary(&version_dict)) { |
85 NOTREACHED(); | 88 NOTREACHED(); |
86 continue; | 89 continue; |
87 } | 90 } |
88 std::string version; | 91 std::string version; |
89 success = version_dict->GetString("version", &version); | 92 success = version_dict->GetString("version", &version); |
90 DCHECK(success); | 93 DCHECK(success); |
91 std::string status_str; | 94 std::string status_str; |
92 success = version_dict->GetString("status", &status_str); | 95 success = version_dict->GetString("status", &status_str); |
93 DCHECK(success); | 96 DCHECK(success); |
94 PluginMetadata::SecurityStatus status = | 97 PluginMetadata::SecurityStatus status = |
95 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; | 98 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; |
96 success = PluginMetadata::ParseSecurityStatus(status_str, &status); | 99 success = PluginMetadata::ParseSecurityStatus(status_str, &status); |
97 DCHECK(success); | 100 DCHECK(success); |
98 plugin->AddVersion(Version(version), status); | 101 plugin->AddVersion(Version(version), status); |
99 } | 102 } |
100 } | 103 } |
101 | 104 |
| 105 const ListValue* mime_types = NULL; |
| 106 if (plugin_dict->GetList("mime_types", &mime_types)) { |
| 107 for (ListValue::const_iterator mime_type_it = mime_types->begin(); |
| 108 mime_type_it != mime_types->end(); ++mime_type_it) { |
| 109 DictionaryValue* mime_types_dict = NULL; |
| 110 if (!(*mime_type_it)->GetAsDictionary(&mime_types_dict)) { |
| 111 NOTREACHED(); |
| 112 continue; |
| 113 } |
| 114 std::string mime_type; |
| 115 success = mime_types_dict->GetString("mime_type", &mime_type); |
| 116 DCHECK(success); |
| 117 bool used_in_matching = false; |
| 118 mime_types_dict->GetBoolean("used_in_matching", &used_in_matching); |
| 119 plugin->AddMimeType(mime_type, used_in_matching); |
| 120 } |
| 121 } |
102 return plugin; | 122 return plugin; |
103 } | 123 } |
104 | 124 |
105 } // namespace | 125 } // namespace |
106 | 126 |
107 // static | 127 // static |
108 PluginFinder* PluginFinder::GetInstance() { | 128 PluginFinder* PluginFinder::GetInstance() { |
109 // PluginFinder::GetInstance() is the only method that's allowed to call | 129 // PluginFinder::GetInstance() is the only method that's allowed to call |
110 // Singleton<PluginFinder>::get(). | 130 // Singleton<PluginFinder>::get(). |
111 return Singleton<PluginFinder>::get(); | 131 return Singleton<PluginFinder>::get(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 180 |
161 #if defined(ENABLE_PLUGIN_INSTALLATION) | 181 #if defined(ENABLE_PLUGIN_INSTALLATION) |
162 bool PluginFinder::FindPlugin( | 182 bool PluginFinder::FindPlugin( |
163 const std::string& mime_type, | 183 const std::string& mime_type, |
164 const std::string& language, | 184 const std::string& language, |
165 PluginInstaller** installer, | 185 PluginInstaller** installer, |
166 scoped_ptr<PluginMetadata>* plugin_metadata) { | 186 scoped_ptr<PluginMetadata>* plugin_metadata) { |
167 base::AutoLock lock(mutex_); | 187 base::AutoLock lock(mutex_); |
168 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) | 188 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) |
169 return false; | 189 return false; |
170 for (DictionaryValue::Iterator plugin_it(*plugin_list_); | |
171 plugin_it.HasNext(); plugin_it.Advance()) { | |
172 const DictionaryValue* plugin = NULL; | |
173 if (!plugin_it.value().GetAsDictionary(&plugin)) { | |
174 NOTREACHED(); | |
175 continue; | |
176 } | |
177 std::string language_str; | |
178 bool success = plugin->GetString("lang", &language_str); | |
179 if (language_str != language) | |
180 continue; | |
181 const ListValue* mime_types = NULL; | |
182 plugin->GetList("mime_types", &mime_types); | |
183 DCHECK(success); | |
184 for (ListValue::const_iterator mime_type_it = mime_types->begin(); | |
185 mime_type_it != mime_types->end(); ++mime_type_it) { | |
186 std::string mime_type_str; | |
187 success = (*mime_type_it)->GetAsString(&mime_type_str); | |
188 DCHECK(success); | |
189 if (mime_type_str == mime_type) { | |
190 std::string identifier = plugin_it.key(); | |
191 std::map<std::string, PluginMetadata*>::const_iterator metadata_it = | |
192 identifier_plugin_.find(identifier); | |
193 DCHECK(metadata_it != identifier_plugin_.end()); | |
194 *plugin_metadata = metadata_it->second->Clone(); | |
195 | 190 |
196 std::map<std::string, PluginInstaller*>::const_iterator installer_it = | 191 std::map<std::string, PluginMetadata*>::const_iterator metadata_it = |
197 installers_.find(identifier); | 192 identifier_plugin_.begin(); |
198 DCHECK(installer_it != installers_.end()); | 193 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { |
199 *installer = installer_it->second; | 194 if (language == metadata_it->second->language() && |
200 return true; | 195 metadata_it->second->HasMimeType(mime_type)) { |
201 } | 196 *plugin_metadata = metadata_it->second->Clone(); |
| 197 |
| 198 std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| 199 installers_.find(metadata_it->second->identifier()); |
| 200 DCHECK(installer_it != installers_.end()); |
| 201 *installer = installer_it->second; |
| 202 return true; |
202 } | 203 } |
203 } | 204 } |
204 return false; | 205 return false; |
205 } | 206 } |
206 | 207 |
207 bool PluginFinder::FindPluginWithIdentifier( | 208 bool PluginFinder::FindPluginWithIdentifier( |
208 const std::string& identifier, | 209 const std::string& identifier, |
209 PluginInstaller** installer, | 210 PluginInstaller** installer, |
210 scoped_ptr<PluginMetadata>* plugin_metadata) { | 211 scoped_ptr<PluginMetadata>* plugin_metadata) { |
211 base::AutoLock lock(mutex_); | 212 base::AutoLock lock(mutex_); |
(...skipping 20 matching lines...) Expand all Loading... |
232 string16 name; | 233 string16 name; |
233 if (it != identifier_plugin_.end()) | 234 if (it != identifier_plugin_.end()) |
234 name = it->second->name(); | 235 name = it->second->name(); |
235 | 236 |
236 return name.empty() ? UTF8ToUTF16(identifier) : name; | 237 return name.empty() ? UTF8ToUTF16(identifier) : name; |
237 } | 238 } |
238 | 239 |
239 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( | 240 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
240 const webkit::WebPluginInfo& plugin) { | 241 const webkit::WebPluginInfo& plugin) { |
241 base::AutoLock lock(mutex_); | 242 base::AutoLock lock(mutex_); |
242 if (name_plugin_.find(plugin.name) != name_plugin_.end()) | |
243 return name_plugin_[plugin.name]->Clone(); | |
244 | |
245 // Use the group name matcher to find the plug-in metadata we want. | 243 // Use the group name matcher to find the plug-in metadata we want. |
246 for (std::map<std::string, PluginMetadata*>::const_iterator it = | 244 for (std::map<std::string, PluginMetadata*>::const_iterator it = |
247 identifier_plugin_.begin(); it != identifier_plugin_.end(); ++it) { | 245 identifier_plugin_.begin(); it != identifier_plugin_.end(); ++it) { |
248 if (!it->second->MatchesPlugin(plugin)) | 246 string16 matching_name; |
| 247 if (!it->second->MatchesPlugin(plugin, &matching_name)) |
249 continue; | 248 continue; |
250 | 249 |
251 name_plugin_[plugin.name] = it->second; | 250 name_plugin_[matching_name] = it->second; |
252 return it->second->Clone(); | 251 return it->second->Clone(); |
253 } | 252 } |
254 | 253 |
255 // The plug-in metadata was not found, create a dummy one holding | 254 // The plug-in metadata was not found, create a dummy one holding |
256 // the name, identifier and group name only. | 255 // the name, identifier and group name only. |
257 std::string identifier = GetIdentifier(plugin); | 256 std::string identifier = GetIdentifier(plugin); |
258 PluginMetadata* metadata = new PluginMetadata(identifier, | 257 PluginMetadata* metadata = new PluginMetadata(identifier, |
259 GetGroupName(plugin), | 258 GetGroupName(plugin), |
260 false, GURL(), GURL(), | 259 false, GURL(), GURL(), |
261 GetGroupName(plugin)); | 260 GetGroupName(plugin), |
262 | 261 ""); |
263 name_plugin_[plugin.name] = metadata; | 262 name_plugin_[plugin.name] = metadata; |
264 identifier_plugin_[identifier] = metadata; | 263 identifier_plugin_[identifier] = metadata; |
265 return metadata->Clone(); | 264 return metadata->Clone(); |
266 } | 265 } |
267 | 266 |
268 void PluginFinder::ReinitializePlugins( | 267 void PluginFinder::ReinitializePlugins( |
269 const base::DictionaryValue& json_metadata) { | 268 const base::DictionaryValue& json_metadata) { |
270 base::AutoLock lock(mutex_); | 269 base::AutoLock lock(mutex_); |
271 STLDeleteValues(&identifier_plugin_); | 270 STLDeleteValues(&identifier_plugin_); |
272 identifier_plugin_.clear(); | 271 identifier_plugin_.clear(); |
(...skipping 12 matching lines...) Expand all Loading... |
285 DCHECK(!identifier_plugin_[identifier]); | 284 DCHECK(!identifier_plugin_[identifier]); |
286 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); | 285 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
287 | 286 |
288 #if defined(ENABLE_PLUGIN_INSTALLATION) | 287 #if defined(ENABLE_PLUGIN_INSTALLATION) |
289 if (installers_.find(identifier) == installers_.end()) | 288 if (installers_.find(identifier) == installers_.end()) |
290 installers_[identifier] = new PluginInstaller(); | 289 installers_[identifier] = new PluginInstaller(); |
291 #endif | 290 #endif |
292 } | 291 } |
293 } | 292 } |
294 } | 293 } |
OLD | NEW |