Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/plugins/plugin_finder.cc

Issue 11016005: Using MIME types in addition to plugin name to differentiate between plugins. (Closed) Base URL: http://git.chromium.org/chromium/src.git@5_plugins_resource_service
Patch Set: infobarED Lightspark Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 typedef std::map<std::string, PluginMetadata*> PluginMap;
35
36 const char kMimeTypesListKey[] = "mime_types";
37 const char kMatchingMimeTypesListKey[] = "matching_mime_types";
38
34 // Gets the base name of the file path as the identifier. 39 // Gets the base name of the file path as the identifier.
35 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) { 40 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) {
36 #if defined(OS_POSIX) 41 #if defined(OS_POSIX)
37 return plugin.path.BaseName().value(); 42 return plugin.path.BaseName().value();
38 #elif defined(OS_WIN) 43 #elif defined(OS_WIN)
39 return base::SysWideToUTF8(plugin.path.BaseName().value()); 44 return base::SysWideToUTF8(plugin.path.BaseName().value());
40 #endif 45 #endif
41 } 46 }
42 47
43 // Gets the plug-in group name as the plug-in name if it is not empty or 48 // 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. 49 // the filename without extension if the name is empty.
45 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) { 50 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) {
46 if (!plugin.name.empty()) 51 if (!plugin.name.empty())
47 return plugin.name; 52 return plugin.name;
48 53
49 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); 54 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value();
50 #if defined(OS_POSIX) 55 #if defined(OS_POSIX)
51 return UTF8ToUTF16(path); 56 return UTF8ToUTF16(path);
52 #elif defined(OS_WIN) 57 #elif defined(OS_WIN)
53 return WideToUTF16(path); 58 return WideToUTF16(path);
54 #endif 59 #endif
55 } 60 }
56 61
62 void LoadMimeTypes(const std::string& mime_type_list_key,
63 const DictionaryValue* plugin_dict,
64 PluginMetadata* plugin) {
65 const ListValue* mime_types = NULL;
66 if (!plugin_dict->GetList(mime_type_list_key, &mime_types))
67 return;
68
69 bool success = false;
70 for (ListValue::const_iterator mime_type_it = mime_types->begin();
71 mime_type_it != mime_types->end(); ++mime_type_it) {
72 std::string mime_type_str;
73 success = (*mime_type_it)->GetAsString(&mime_type_str);
74 DCHECK(success);
75 if (mime_type_list_key == kMatchingMimeTypesListKey) {
76 plugin->AddMatchingMimeType(mime_type_str);
77 } else if (mime_type_list_key == kMimeTypesListKey) {
78 plugin->AddMimeType(mime_type_str);
79 } else {
80 NOTREACHED();
81 return;
82 }
83 }
84 }
85
57 PluginMetadata* CreatePluginMetadata( 86 PluginMetadata* CreatePluginMetadata(
58 const std::string& identifier, 87 const std::string& identifier,
59 const DictionaryValue* plugin_dict) { 88 const DictionaryValue* plugin_dict) {
60 std::string url; 89 std::string url;
61 bool success = plugin_dict->GetString("url", &url); 90 bool success = plugin_dict->GetString("url", &url);
62 std::string help_url; 91 std::string help_url;
63 plugin_dict->GetString("help_url", &help_url); 92 plugin_dict->GetString("help_url", &help_url);
64 string16 name; 93 string16 name;
65 success = plugin_dict->GetString("name", &name); 94 success = plugin_dict->GetString("name", &name);
66 DCHECK(success); 95 DCHECK(success);
67 bool display_url = false; 96 bool display_url = false;
68 plugin_dict->GetBoolean("displayurl", &display_url); 97 plugin_dict->GetBoolean("displayurl", &display_url);
69 string16 group_name_matcher; 98 string16 group_name_matcher;
70 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); 99 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher);
71 DCHECK(success); 100 DCHECK(success);
101 std::string language_str;
102 plugin_dict->GetString("lang", &language_str);
72 103
73 PluginMetadata* plugin = new PluginMetadata(identifier, 104 PluginMetadata* plugin = new PluginMetadata(identifier,
74 name, 105 name,
75 display_url, 106 display_url,
76 GURL(url), 107 GURL(url),
77 GURL(help_url), 108 GURL(help_url),
78 group_name_matcher); 109 group_name_matcher,
110 language_str);
79 const ListValue* versions = NULL; 111 const ListValue* versions = NULL;
80 if (plugin_dict->GetList("versions", &versions)) { 112 if (plugin_dict->GetList("versions", &versions)) {
81 for (ListValue::const_iterator it = versions->begin(); 113 for (ListValue::const_iterator it = versions->begin();
82 it != versions->end(); ++it) { 114 it != versions->end(); ++it) {
83 DictionaryValue* version_dict = NULL; 115 DictionaryValue* version_dict = NULL;
84 if (!(*it)->GetAsDictionary(&version_dict)) { 116 if (!(*it)->GetAsDictionary(&version_dict)) {
85 NOTREACHED(); 117 NOTREACHED();
86 continue; 118 continue;
87 } 119 }
88 std::string version; 120 std::string version;
89 success = version_dict->GetString("version", &version); 121 success = version_dict->GetString("version", &version);
90 DCHECK(success); 122 DCHECK(success);
91 std::string status_str; 123 std::string status_str;
92 success = version_dict->GetString("status", &status_str); 124 success = version_dict->GetString("status", &status_str);
93 DCHECK(success); 125 DCHECK(success);
94 PluginMetadata::SecurityStatus status = 126 PluginMetadata::SecurityStatus status =
95 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; 127 PluginMetadata::SECURITY_STATUS_UP_TO_DATE;
96 success = PluginMetadata::ParseSecurityStatus(status_str, &status); 128 success = PluginMetadata::ParseSecurityStatus(status_str, &status);
97 DCHECK(success); 129 DCHECK(success);
98 plugin->AddVersion(Version(version), status); 130 plugin->AddVersion(Version(version), status);
99 } 131 }
100 } 132 }
101 133
134 LoadMimeTypes(kMimeTypesListKey, plugin_dict, plugin);
135 LoadMimeTypes(kMatchingMimeTypesListKey, plugin_dict, plugin);
102 return plugin; 136 return plugin;
103 } 137 }
104 138
105 } // namespace 139 } // namespace
106 140
107 // static 141 // static
108 PluginFinder* PluginFinder::GetInstance() { 142 PluginFinder* PluginFinder::GetInstance() {
109 // PluginFinder::GetInstance() is the only method that's allowed to call 143 // PluginFinder::GetInstance() is the only method that's allowed to call
110 // Singleton<PluginFinder>::get(). 144 // Singleton<PluginFinder>::get().
111 return Singleton<PluginFinder>::get(); 145 return Singleton<PluginFinder>::get();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 196
163 #if defined(ENABLE_PLUGIN_INSTALLATION) 197 #if defined(ENABLE_PLUGIN_INSTALLATION)
164 bool PluginFinder::FindPlugin( 198 bool PluginFinder::FindPlugin(
165 const std::string& mime_type, 199 const std::string& mime_type,
166 const std::string& language, 200 const std::string& language,
167 PluginInstaller** installer, 201 PluginInstaller** installer,
168 scoped_ptr<PluginMetadata>* plugin_metadata) { 202 scoped_ptr<PluginMetadata>* plugin_metadata) {
169 base::AutoLock lock(mutex_); 203 base::AutoLock lock(mutex_);
170 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) 204 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder))
171 return false; 205 return false;
172 for (DictionaryValue::Iterator plugin_it(*plugin_list_);
173 plugin_it.HasNext(); plugin_it.Advance()) {
174 const DictionaryValue* plugin = NULL;
175 if (!plugin_it.value().GetAsDictionary(&plugin)) {
176 NOTREACHED();
177 continue;
178 }
179 std::string language_str;
180 bool success = plugin->GetString("lang", &language_str);
181 if (language_str != language)
182 continue;
183 const ListValue* mime_types = NULL;
184 if (plugin->GetList("mime_types", &mime_types)) {
185 for (ListValue::const_iterator mime_type_it = mime_types->begin();
186 mime_type_it != mime_types->end(); ++mime_type_it) {
187 std::string mime_type_str;
188 success = (*mime_type_it)->GetAsString(&mime_type_str);
189 DCHECK(success);
190 if (mime_type_str == mime_type) {
191 std::string identifier = plugin_it.key();
192 std::map<std::string, PluginMetadata*>::const_iterator metadata_it =
193 identifier_plugin_.find(identifier);
194 DCHECK(metadata_it != identifier_plugin_.end());
195 *plugin_metadata = metadata_it->second->Clone();
196 206
197 std::map<std::string, PluginInstaller*>::const_iterator installer_it = 207 PluginMap::const_iterator metadata_it = identifier_plugin_.begin();
198 installers_.find(identifier); 208 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) {
199 DCHECK(installer_it != installers_.end()); 209 if (language == metadata_it->second->language() &&
200 *installer = installer_it->second; 210 metadata_it->second->HasMimeType(mime_type)) {
201 return true; 211 *plugin_metadata = metadata_it->second->Clone();
202 } 212
203 } 213 std::map<std::string, PluginInstaller*>::const_iterator installer_it =
214 installers_.find(metadata_it->second->identifier());
215 DCHECK(installer_it != installers_.end());
216 *installer = installer_it->second;
217 return true;
204 } 218 }
205 } 219 }
206 return false; 220 return false;
207 } 221 }
208 222
209 bool PluginFinder::FindPluginWithIdentifier( 223 bool PluginFinder::FindPluginWithIdentifier(
210 const std::string& identifier, 224 const std::string& identifier,
211 PluginInstaller** installer, 225 PluginInstaller** installer,
212 scoped_ptr<PluginMetadata>* plugin_metadata) { 226 scoped_ptr<PluginMetadata>* plugin_metadata) {
213 base::AutoLock lock(mutex_); 227 base::AutoLock lock(mutex_);
214 std::map<std::string, PluginInstaller*>::const_iterator it = 228 std::map<std::string, PluginInstaller*>::const_iterator it =
215 installers_.find(identifier); 229 installers_.find(identifier);
216 if (it != installers_.end()) { 230 if (it != installers_.end()) {
217 *installer = it->second; 231 *installer = it->second;
218 std::map<std::string, PluginMetadata*>::const_iterator metadata_it = 232 PluginMap::const_iterator metadata_it = identifier_plugin_.find(identifier);
219 identifier_plugin_.find(identifier);
220 DCHECK(metadata_it != identifier_plugin_.end()); 233 DCHECK(metadata_it != identifier_plugin_.end());
221 *plugin_metadata = metadata_it->second->Clone(); 234 *plugin_metadata = metadata_it->second->Clone();
222 return true; 235 return true;
223 } 236 }
224 237
225 return false; 238 return false;
226 } 239 }
227 240
228 void PluginFinder::ReinitializePlugins( 241 void PluginFinder::ReinitializePlugins(
229 const base::DictionaryValue& json_metadata) { 242 const base::DictionaryValue& json_metadata) {
230 base::AutoLock lock(mutex_); 243 base::AutoLock lock(mutex_);
231 STLDeleteValues(&identifier_plugin_); 244 STLDeleteValues(&identifier_plugin_);
232 identifier_plugin_.clear(); 245 identifier_plugin_.clear();
233 name_plugin_.clear();
234 246
235 plugin_list_.reset(json_metadata.DeepCopy()); 247 plugin_list_.reset(json_metadata.DeepCopy());
236 InitInternal(); 248 InitInternal();
237 } 249 }
238 #endif 250 #endif
239 251
240 string16 PluginFinder::FindPluginNameWithIdentifier( 252 string16 PluginFinder::FindPluginNameWithIdentifier(
241 const std::string& identifier) { 253 const std::string& identifier) {
242 base::AutoLock lock(mutex_); 254 base::AutoLock lock(mutex_);
243 std::map<std::string, PluginMetadata*>::const_iterator it = 255 PluginMap::const_iterator it = identifier_plugin_.find(identifier);
244 identifier_plugin_.find(identifier);
245 string16 name; 256 string16 name;
246 if (it != identifier_plugin_.end()) 257 if (it != identifier_plugin_.end())
247 name = it->second->name(); 258 name = it->second->name();
248 259
249 return name.empty() ? UTF8ToUTF16(identifier) : name; 260 return name.empty() ? UTF8ToUTF16(identifier) : name;
250 } 261 }
251 262
252 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( 263 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata(
253 const webkit::WebPluginInfo& plugin) { 264 const webkit::WebPluginInfo& plugin) {
254 base::AutoLock lock(mutex_); 265 base::AutoLock lock(mutex_);
255 if (name_plugin_.find(plugin.name) != name_plugin_.end()) 266 for (PluginMap::const_iterator it = identifier_plugin_.begin();
256 return name_plugin_[plugin.name]->Clone(); 267 it != identifier_plugin_.end(); ++it) {
257 268 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.
258 // Use the group name matcher to find the plug-in metadata we want. 269 if (!it->second->MatchesPlugin(plugin, &matching_name))
259 for (std::map<std::string, PluginMetadata*>::const_iterator it =
260 identifier_plugin_.begin(); it != identifier_plugin_.end(); ++it) {
261 if (!it->second->MatchesPlugin(plugin))
262 continue; 270 continue;
263 271
264 name_plugin_[plugin.name] = it->second;
265 return it->second->Clone(); 272 return it->second->Clone();
266 } 273 }
267 274
268 // The plug-in metadata was not found, create a dummy one holding 275 // The plug-in metadata was not found, create a dummy one holding
269 // the name, identifier and group name only. 276 // the name, identifier and group name only.
270 std::string identifier = GetIdentifier(plugin); 277 std::string identifier = GetIdentifier(plugin);
271 PluginMetadata* metadata = new PluginMetadata(identifier, 278 PluginMetadata* metadata = new PluginMetadata(identifier,
272 GetGroupName(plugin), 279 GetGroupName(plugin),
273 false, GURL(), GURL(), 280 false, GURL(), GURL(),
274 GetGroupName(plugin)); 281 GetGroupName(plugin),
275 282 "");
276 name_plugin_[plugin.name] = metadata;
277 identifier_plugin_[identifier] = metadata; 283 identifier_plugin_[identifier] = metadata;
278 return metadata->Clone(); 284 return metadata->Clone();
279 } 285 }
280 286
281 void PluginFinder::InitInternal() { 287 void PluginFinder::InitInternal() {
282 for (DictionaryValue::Iterator plugin_it(*plugin_list_); 288 for (DictionaryValue::Iterator plugin_it(*plugin_list_);
283 plugin_it.HasNext(); plugin_it.Advance()) { 289 plugin_it.HasNext(); plugin_it.Advance()) {
284 DictionaryValue* plugin = NULL; 290 DictionaryValue* plugin = NULL;
285 const std::string& identifier = plugin_it.key(); 291 const std::string& identifier = plugin_it.key();
286 if (plugin_list_->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { 292 if (plugin_list_->GetDictionaryWithoutPathExpansion(identifier, &plugin)) {
287 DCHECK(!identifier_plugin_[identifier]); 293 DCHECK(!identifier_plugin_[identifier]);
288 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); 294 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin);
289 295
290 #if defined(ENABLE_PLUGIN_INSTALLATION) 296 #if defined(ENABLE_PLUGIN_INSTALLATION)
291 if (installers_.find(identifier) == installers_.end()) 297 if (installers_.find(identifier) == installers_.end())
292 installers_[identifier] = new PluginInstaller(); 298 installers_[identifier] = new PluginInstaller();
293 #endif 299 #endif
294 } 300 }
295 } 301 }
296 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698