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 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 #if defined(ENABLE_PLUGIN_INSTALLATION) | 25 #if defined(ENABLE_PLUGIN_INSTALLATION) |
26 #include "chrome/browser/plugins/plugin_installer.h" | 26 #include "chrome/browser/plugins/plugin_installer.h" |
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 const char kMimeTypesListKey[] = "mime_types"; | |
35 const char kMatchingMimeTypesListKey[] = "matching_mime_types"; | |
36 | |
34 // Gets the base name of the file path as the identifier. | 37 // Gets the base name of the file path as the identifier. |
35 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) { | 38 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) { |
36 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
37 return plugin.path.BaseName().value(); | 40 return plugin.path.BaseName().value(); |
38 #elif defined(OS_WIN) | 41 #elif defined(OS_WIN) |
39 return base::SysWideToUTF8(plugin.path.BaseName().value()); | 42 return base::SysWideToUTF8(plugin.path.BaseName().value()); |
40 #endif | 43 #endif |
41 } | 44 } |
42 | 45 |
43 // 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 |
44 // the filename without extension if the name is empty. | 47 // the filename without extension if the name is empty. |
45 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) { | 48 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) { |
46 if (!plugin.name.empty()) | 49 if (!plugin.name.empty()) |
47 return plugin.name; | 50 return plugin.name; |
48 | 51 |
49 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); | 52 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); |
50 #if defined(OS_POSIX) | 53 #if defined(OS_POSIX) |
51 return UTF8ToUTF16(path); | 54 return UTF8ToUTF16(path); |
52 #elif defined(OS_WIN) | 55 #elif defined(OS_WIN) |
53 return WideToUTF16(path); | 56 return WideToUTF16(path); |
54 #endif | 57 #endif |
55 } | 58 } |
56 | 59 |
60 void LoadMimeTypes(const std::string& mime_type_list_key, | |
61 const DictionaryValue* plugin_dict, | |
62 PluginMetadata* plugin) { | |
63 const ListValue* mime_types = NULL; | |
64 if (!plugin_dict->GetList(mime_type_list_key, &mime_types)) | |
65 return; | |
66 | |
67 bool success = false; | |
68 for (ListValue::const_iterator mime_type_it = mime_types->begin(); | |
69 mime_type_it != mime_types->end(); ++mime_type_it) { | |
70 std::string mime_type_str; | |
71 success = (*mime_type_it)->GetAsString(&mime_type_str); | |
72 DCHECK(success); | |
73 if (mime_type_list_key == kMatchingMimeTypesListKey) { | |
Bernhard Bauer
2012/10/02 14:40:13
This might be a bit simpler if you create a method
ibraaaa
2012/10/02 16:14:53
Well, if I send a boolean value (actually that is
Bernhard Bauer
2012/10/04 11:37:19
Right, it just seems a bit more awkward to pass in
ibraaaa
2012/10/04 12:24:12
Done.
| |
74 plugin->AddMatchingMimeType(mime_type_str); | |
75 } else if (mime_type_list_key == kMimeTypesListKey) { | |
76 plugin->AddMimeType(mime_type_str); | |
77 } else { | |
78 NOTREACHED(); | |
79 return; | |
80 } | |
81 } | |
82 } | |
83 | |
57 PluginMetadata* CreatePluginMetadata( | 84 PluginMetadata* CreatePluginMetadata( |
58 const std::string& identifier, | 85 const std::string& identifier, |
59 const DictionaryValue* plugin_dict) { | 86 const DictionaryValue* plugin_dict) { |
60 std::string url; | 87 std::string url; |
61 bool success = plugin_dict->GetString("url", &url); | 88 bool success = plugin_dict->GetString("url", &url); |
62 std::string help_url; | 89 std::string help_url; |
63 plugin_dict->GetString("help_url", &help_url); | 90 plugin_dict->GetString("help_url", &help_url); |
64 string16 name; | 91 string16 name; |
65 success = plugin_dict->GetString("name", &name); | 92 success = plugin_dict->GetString("name", &name); |
66 DCHECK(success); | 93 DCHECK(success); |
67 bool display_url = false; | 94 bool display_url = false; |
68 plugin_dict->GetBoolean("displayurl", &display_url); | 95 plugin_dict->GetBoolean("displayurl", &display_url); |
69 string16 group_name_matcher; | 96 string16 group_name_matcher; |
70 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); | 97 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); |
71 DCHECK(success); | 98 DCHECK(success); |
99 std::string language_str; | |
100 plugin_dict->GetString("lang", &language_str); | |
72 | 101 |
73 PluginMetadata* plugin = new PluginMetadata(identifier, | 102 PluginMetadata* plugin = new PluginMetadata(identifier, |
74 name, | 103 name, |
75 display_url, | 104 display_url, |
76 GURL(url), | 105 GURL(url), |
77 GURL(help_url), | 106 GURL(help_url), |
78 group_name_matcher); | 107 group_name_matcher, |
108 language_str); | |
79 const ListValue* versions = NULL; | 109 const ListValue* versions = NULL; |
80 if (plugin_dict->GetList("versions", &versions)) { | 110 if (plugin_dict->GetList("versions", &versions)) { |
81 for (ListValue::const_iterator it = versions->begin(); | 111 for (ListValue::const_iterator it = versions->begin(); |
82 it != versions->end(); ++it) { | 112 it != versions->end(); ++it) { |
83 DictionaryValue* version_dict = NULL; | 113 DictionaryValue* version_dict = NULL; |
84 if (!(*it)->GetAsDictionary(&version_dict)) { | 114 if (!(*it)->GetAsDictionary(&version_dict)) { |
85 NOTREACHED(); | 115 NOTREACHED(); |
86 continue; | 116 continue; |
87 } | 117 } |
88 std::string version; | 118 std::string version; |
89 success = version_dict->GetString("version", &version); | 119 success = version_dict->GetString("version", &version); |
90 DCHECK(success); | 120 DCHECK(success); |
91 std::string status_str; | 121 std::string status_str; |
92 success = version_dict->GetString("status", &status_str); | 122 success = version_dict->GetString("status", &status_str); |
93 DCHECK(success); | 123 DCHECK(success); |
94 PluginMetadata::SecurityStatus status = | 124 PluginMetadata::SecurityStatus status = |
95 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; | 125 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; |
96 success = PluginMetadata::ParseSecurityStatus(status_str, &status); | 126 success = PluginMetadata::ParseSecurityStatus(status_str, &status); |
97 DCHECK(success); | 127 DCHECK(success); |
98 plugin->AddVersion(Version(version), status); | 128 plugin->AddVersion(Version(version), status); |
99 } | 129 } |
100 } | 130 } |
101 | 131 |
132 LoadMimeTypes(kMimeTypesListKey, plugin_dict, plugin); | |
133 LoadMimeTypes(kMatchingMimeTypesListKey, plugin_dict, plugin); | |
102 return plugin; | 134 return plugin; |
103 } | 135 } |
104 | 136 |
105 } // namespace | 137 } // namespace |
106 | 138 |
107 // static | 139 // static |
108 PluginFinder* PluginFinder::GetInstance() { | 140 PluginFinder* PluginFinder::GetInstance() { |
109 // PluginFinder::GetInstance() is the only method that's allowed to call | 141 // PluginFinder::GetInstance() is the only method that's allowed to call |
110 // Singleton<PluginFinder>::get(). | 142 // Singleton<PluginFinder>::get(). |
111 return Singleton<PluginFinder>::get(); | 143 return Singleton<PluginFinder>::get(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 192 |
161 #if defined(ENABLE_PLUGIN_INSTALLATION) | 193 #if defined(ENABLE_PLUGIN_INSTALLATION) |
162 bool PluginFinder::FindPlugin( | 194 bool PluginFinder::FindPlugin( |
163 const std::string& mime_type, | 195 const std::string& mime_type, |
164 const std::string& language, | 196 const std::string& language, |
165 PluginInstaller** installer, | 197 PluginInstaller** installer, |
166 scoped_ptr<PluginMetadata>* plugin_metadata) { | 198 scoped_ptr<PluginMetadata>* plugin_metadata) { |
167 base::AutoLock lock(mutex_); | 199 base::AutoLock lock(mutex_); |
168 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) | 200 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) |
169 return false; | 201 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 | 202 |
196 std::map<std::string, PluginInstaller*>::const_iterator installer_it = | 203 std::map<std::string, PluginMetadata*>::const_iterator metadata_it = |
Bernhard Bauer
2012/10/02 14:40:13
You use this map type in a bunch of places. You co
ibraaaa
2012/10/02 16:14:53
Done.
| |
197 installers_.find(identifier); | 204 identifier_plugin_.begin(); |
198 DCHECK(installer_it != installers_.end()); | 205 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { |
199 *installer = installer_it->second; | 206 if (language == metadata_it->second->language() && |
200 return true; | 207 metadata_it->second->HasMimeType(mime_type)) { |
201 } | 208 *plugin_metadata = metadata_it->second->Clone(); |
209 | |
210 std::map<std::string, PluginInstaller*>::const_iterator installer_it = | |
211 installers_.find(metadata_it->second->identifier()); | |
212 DCHECK(installer_it != installers_.end()); | |
213 *installer = installer_it->second; | |
214 return true; | |
202 } | 215 } |
203 } | 216 } |
204 return false; | 217 return false; |
205 } | 218 } |
206 | 219 |
207 bool PluginFinder::FindPluginWithIdentifier( | 220 bool PluginFinder::FindPluginWithIdentifier( |
208 const std::string& identifier, | 221 const std::string& identifier, |
209 PluginInstaller** installer, | 222 PluginInstaller** installer, |
210 scoped_ptr<PluginMetadata>* plugin_metadata) { | 223 scoped_ptr<PluginMetadata>* plugin_metadata) { |
211 base::AutoLock lock(mutex_); | 224 base::AutoLock lock(mutex_); |
(...skipping 20 matching lines...) Expand all Loading... | |
232 string16 name; | 245 string16 name; |
233 if (it != identifier_plugin_.end()) | 246 if (it != identifier_plugin_.end()) |
234 name = it->second->name(); | 247 name = it->second->name(); |
235 | 248 |
236 return name.empty() ? UTF8ToUTF16(identifier) : name; | 249 return name.empty() ? UTF8ToUTF16(identifier) : name; |
237 } | 250 } |
238 | 251 |
239 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( | 252 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
240 const webkit::WebPluginInfo& plugin) { | 253 const webkit::WebPluginInfo& plugin) { |
241 base::AutoLock lock(mutex_); | 254 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. | |
246 for (std::map<std::string, PluginMetadata*>::const_iterator it = | 255 for (std::map<std::string, PluginMetadata*>::const_iterator it = |
247 identifier_plugin_.begin(); it != identifier_plugin_.end(); ++it) { | 256 identifier_plugin_.begin(); it != identifier_plugin_.end(); ++it) { |
248 if (!it->second->MatchesPlugin(plugin)) | 257 string16 matching_name; |
258 if (!it->second->MatchesPlugin(plugin, &matching_name)) | |
249 continue; | 259 continue; |
250 | 260 |
251 name_plugin_[plugin.name] = it->second; | 261 name_plugin_[matching_name] = it->second; |
Bernhard Bauer
2012/10/02 14:40:13
You're never reading from |name_plugin_| anymore.
ibraaaa
2012/10/02 16:14:53
Done.
| |
252 return it->second->Clone(); | 262 return it->second->Clone(); |
253 } | 263 } |
254 | 264 |
255 // The plug-in metadata was not found, create a dummy one holding | 265 // The plug-in metadata was not found, create a dummy one holding |
256 // the name, identifier and group name only. | 266 // the name, identifier and group name only. |
257 std::string identifier = GetIdentifier(plugin); | 267 std::string identifier = GetIdentifier(plugin); |
258 PluginMetadata* metadata = new PluginMetadata(identifier, | 268 PluginMetadata* metadata = new PluginMetadata(identifier, |
259 GetGroupName(plugin), | 269 GetGroupName(plugin), |
260 false, GURL(), GURL(), | 270 false, GURL(), GURL(), |
261 GetGroupName(plugin)); | 271 GetGroupName(plugin), |
262 | 272 ""); |
263 name_plugin_[plugin.name] = metadata; | 273 name_plugin_[plugin.name] = metadata; |
264 identifier_plugin_[identifier] = metadata; | 274 identifier_plugin_[identifier] = metadata; |
265 return metadata->Clone(); | 275 return metadata->Clone(); |
266 } | 276 } |
267 | 277 |
268 void PluginFinder::ReinitializePlugins( | 278 void PluginFinder::ReinitializePlugins( |
269 const base::DictionaryValue& json_metadata) { | 279 const base::DictionaryValue& json_metadata) { |
270 base::AutoLock lock(mutex_); | 280 base::AutoLock lock(mutex_); |
271 STLDeleteValues(&identifier_plugin_); | 281 STLDeleteValues(&identifier_plugin_); |
272 identifier_plugin_.clear(); | 282 identifier_plugin_.clear(); |
(...skipping 12 matching lines...) Expand all Loading... | |
285 DCHECK(!identifier_plugin_[identifier]); | 295 DCHECK(!identifier_plugin_[identifier]); |
286 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); | 296 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
287 | 297 |
288 #if defined(ENABLE_PLUGIN_INSTALLATION) | 298 #if defined(ENABLE_PLUGIN_INSTALLATION) |
289 if (installers_.find(identifier) == installers_.end()) | 299 if (installers_.find(identifier) == installers_.end()) |
290 installers_[identifier] = new PluginInstaller(); | 300 installers_[identifier] = new PluginInstaller(); |
291 #endif | 301 #endif |
292 } | 302 } |
293 } | 303 } |
294 } | 304 } |
OLD | NEW |