| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return static_cast<base::DictionaryValue*>(value.release()); | 245 return static_cast<base::DictionaryValue*>(value.release()); |
| 246 } | 246 } |
| 247 | 247 |
| 248 PluginFinder::~PluginFinder() { | 248 PluginFinder::~PluginFinder() { |
| 249 #if defined(ENABLE_PLUGIN_INSTALLATION) | 249 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 250 STLDeleteValues(&installers_); | 250 STLDeleteValues(&installers_); |
| 251 #endif | 251 #endif |
| 252 STLDeleteValues(&identifier_plugin_); | 252 STLDeleteValues(&identifier_plugin_); |
| 253 } | 253 } |
| 254 | 254 |
| 255 base::string16 PluginFinder::FindPluginName(const std::string& mime_type, | |
| 256 const std::string& language) { | |
| 257 base::AutoLock lock(mutex_); | |
| 258 | |
| 259 for (auto plugin : identifier_plugin_) { | |
| 260 if (language == plugin.second->language() && | |
| 261 plugin.second->HasMimeType(mime_type)) { | |
| 262 return plugin.second->name(); | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 return base::UTF8ToUTF16(mime_type); | |
| 267 } | |
| 268 | |
| 269 #if defined(ENABLE_PLUGIN_INSTALLATION) | 255 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 270 bool PluginFinder::FindPlugin( | 256 bool PluginFinder::FindPlugin( |
| 271 const std::string& mime_type, | 257 const std::string& mime_type, |
| 272 const std::string& language, | 258 const std::string& language, |
| 273 PluginInstaller** installer, | 259 PluginInstaller** installer, |
| 274 scoped_ptr<PluginMetadata>* plugin_metadata) { | 260 scoped_ptr<PluginMetadata>* plugin_metadata) { |
| 275 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) | 261 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) |
| 276 return false; | 262 return false; |
| 277 | 263 |
| 278 base::AutoLock lock(mutex_); | 264 base::AutoLock lock(mutex_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); | 321 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
| 336 | 322 |
| 337 #if defined(ENABLE_PLUGIN_INSTALLATION) | 323 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 338 if (installers_.find(identifier) == installers_.end()) | 324 if (installers_.find(identifier) == installers_.end()) |
| 339 installers_[identifier] = new PluginInstaller(); | 325 installers_[identifier] = new PluginInstaller(); |
| 340 #endif | 326 #endif |
| 341 } | 327 } |
| 342 } | 328 } |
| 343 } | 329 } |
| 344 | 330 |
| 345 base::string16 PluginFinder::FindPluginNameWithIdentifier( | |
| 346 const std::string& identifier) { | |
| 347 base::AutoLock lock(mutex_); | |
| 348 PluginMap::const_iterator it = identifier_plugin_.find(identifier); | |
| 349 base::string16 name; | |
| 350 if (it != identifier_plugin_.end()) | |
| 351 name = it->second->name(); | |
| 352 | |
| 353 return name.empty() ? base::UTF8ToUTF16(identifier) : name; | |
| 354 } | |
| 355 | |
| 356 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( | 331 scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| 357 const content::WebPluginInfo& plugin) { | 332 const content::WebPluginInfo& plugin) { |
| 358 base::AutoLock lock(mutex_); | 333 base::AutoLock lock(mutex_); |
| 359 for (PluginMap::const_iterator it = identifier_plugin_.begin(); | 334 for (PluginMap::const_iterator it = identifier_plugin_.begin(); |
| 360 it != identifier_plugin_.end(); ++it) { | 335 it != identifier_plugin_.end(); ++it) { |
| 361 if (!it->second->MatchesPlugin(plugin)) | 336 if (!it->second->MatchesPlugin(plugin)) |
| 362 continue; | 337 continue; |
| 363 | 338 |
| 364 return it->second->Clone(); | 339 return it->second->Clone(); |
| 365 } | 340 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 378 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); | 353 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); |
| 379 | 354 |
| 380 DCHECK(metadata->MatchesPlugin(plugin)); | 355 DCHECK(metadata->MatchesPlugin(plugin)); |
| 381 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) | 356 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) |
| 382 identifier = GetLongIdentifier(plugin); | 357 identifier = GetLongIdentifier(plugin); |
| 383 | 358 |
| 384 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); | 359 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); |
| 385 identifier_plugin_[identifier] = metadata; | 360 identifier_plugin_[identifier] = metadata; |
| 386 return metadata->Clone(); | 361 return metadata->Clone(); |
| 387 } | 362 } |
| OLD | NEW |