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_prefs.h" | 5 #include "chrome/browser/plugins/plugin_prefs.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 while (pattern != pattern_set.end()) { | 283 while (pattern != pattern_set.end()) { |
284 if (MatchPattern(name, *pattern)) | 284 if (MatchPattern(name, *pattern)) |
285 return true; | 285 return true; |
286 ++pattern; | 286 ++pattern; |
287 } | 287 } |
288 | 288 |
289 return false; | 289 return false; |
290 } | 290 } |
291 | 291 |
292 /* static */ | 292 /* static */ |
293 void PluginPrefs::ListValueToStringSet(const ListValue* src, | 293 void PluginPrefs::ListValueToStringSet(const base::ListValue* src, |
294 std::set<base::string16>* dest) { | 294 std::set<base::string16>* dest) { |
295 DCHECK(src); | 295 DCHECK(src); |
296 DCHECK(dest); | 296 DCHECK(dest); |
297 dest->clear(); | 297 dest->clear(); |
298 ListValue::const_iterator end(src->end()); | 298 base::ListValue::const_iterator end(src->end()); |
299 for (ListValue::const_iterator current(src->begin()); | 299 for (base::ListValue::const_iterator current(src->begin()); |
300 current != end; ++current) { | 300 current != end; ++current) { |
301 base::string16 plugin_name; | 301 base::string16 plugin_name; |
302 if ((*current)->GetAsString(&plugin_name)) { | 302 if ((*current)->GetAsString(&plugin_name)) { |
303 dest->insert(plugin_name); | 303 dest->insert(plugin_name); |
304 } | 304 } |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 void PluginPrefs::SetPrefs(PrefService* prefs) { | 308 void PluginPrefs::SetPrefs(PrefService* prefs) { |
309 prefs_ = prefs; | 309 prefs_ = prefs; |
(...skipping 29 matching lines...) Expand all Loading... |
339 // code after it has been run once by most users. | 339 // code after it has been run once by most users. |
340 if (!prefs_->GetBoolean( | 340 if (!prefs_->GetBoolean( |
341 prefs::kPluginsRemovedOldComponentPepperFlashSettings)) { | 341 prefs::kPluginsRemovedOldComponentPepperFlashSettings)) { |
342 prefs_->SetBoolean(prefs::kPluginsRemovedOldComponentPepperFlashSettings, | 342 prefs_->SetBoolean(prefs::kPluginsRemovedOldComponentPepperFlashSettings, |
343 true); | 343 true); |
344 remove_component_pepper_flash_settings = true; | 344 remove_component_pepper_flash_settings = true; |
345 } | 345 } |
346 | 346 |
347 { // Scoped update of prefs::kPluginsPluginsList. | 347 { // Scoped update of prefs::kPluginsPluginsList. |
348 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 348 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
349 ListValue* saved_plugins_list = update.Get(); | 349 base::ListValue* saved_plugins_list = update.Get(); |
350 if (saved_plugins_list && !saved_plugins_list->empty()) { | 350 if (saved_plugins_list && !saved_plugins_list->empty()) { |
351 // The following four variables are only valid when | 351 // The following four variables are only valid when |
352 // |migrate_to_pepper_flash| is set to true. | 352 // |migrate_to_pepper_flash| is set to true. |
353 base::FilePath npapi_flash; | 353 base::FilePath npapi_flash; |
354 base::FilePath pepper_flash; | 354 base::FilePath pepper_flash; |
355 DictionaryValue* pepper_flash_node = NULL; | 355 base::DictionaryValue* pepper_flash_node = NULL; |
356 bool npapi_flash_enabled = false; | 356 bool npapi_flash_enabled = false; |
357 if (migrate_to_pepper_flash) { | 357 if (migrate_to_pepper_flash) { |
358 PathService::Get(chrome::FILE_FLASH_PLUGIN, &npapi_flash); | 358 PathService::Get(chrome::FILE_FLASH_PLUGIN, &npapi_flash); |
359 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &pepper_flash); | 359 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &pepper_flash); |
360 } | 360 } |
361 | 361 |
362 // Used when |remove_component_pepper_flash_settings| is set to true. | 362 // Used when |remove_component_pepper_flash_settings| is set to true. |
363 ListValue::iterator component_pepper_flash_node = | 363 base::ListValue::iterator component_pepper_flash_node = |
364 saved_plugins_list->end(); | 364 saved_plugins_list->end(); |
365 | 365 |
366 for (ListValue::iterator it = saved_plugins_list->begin(); | 366 for (base::ListValue::iterator it = saved_plugins_list->begin(); |
367 it != saved_plugins_list->end(); | 367 it != saved_plugins_list->end(); |
368 ++it) { | 368 ++it) { |
369 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { | 369 if (!(*it)->IsType(base::Value::TYPE_DICTIONARY)) { |
370 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 370 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
371 continue; // Oops, don't know what to do with this item. | 371 continue; // Oops, don't know what to do with this item. |
372 } | 372 } |
373 | 373 |
374 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it); | 374 base::DictionaryValue* plugin = |
| 375 static_cast<base::DictionaryValue*>(*it); |
375 base::string16 group_name; | 376 base::string16 group_name; |
376 bool enabled; | 377 bool enabled; |
377 if (!plugin->GetBoolean("enabled", &enabled)) | 378 if (!plugin->GetBoolean("enabled", &enabled)) |
378 enabled = true; | 379 enabled = true; |
379 | 380 |
380 base::FilePath::StringType path; | 381 base::FilePath::StringType path; |
381 // The plugin list constains all the plugin files in addition to the | 382 // The plugin list constains all the plugin files in addition to the |
382 // plugin groups. | 383 // plugin groups. |
383 if (plugin->GetString("path", &path)) { | 384 if (plugin->GetString("path", &path)) { |
384 // Files have a path attribute, groups don't. | 385 // Files have a path attribute, groups don't. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 policy_enabled_plugin_patterns_ = enabled_patterns; | 524 policy_enabled_plugin_patterns_ = enabled_patterns; |
524 } | 525 } |
525 | 526 |
526 void PluginPrefs::OnUpdatePreferences( | 527 void PluginPrefs::OnUpdatePreferences( |
527 const std::vector<content::WebPluginInfo>& plugins) { | 528 const std::vector<content::WebPluginInfo>& plugins) { |
528 if (!prefs_) | 529 if (!prefs_) |
529 return; | 530 return; |
530 | 531 |
531 PluginFinder* finder = PluginFinder::GetInstance(); | 532 PluginFinder* finder = PluginFinder::GetInstance(); |
532 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 533 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
533 ListValue* plugins_list = update.Get(); | 534 base::ListValue* plugins_list = update.Get(); |
534 plugins_list->Clear(); | 535 plugins_list->Clear(); |
535 | 536 |
536 base::FilePath internal_dir; | 537 base::FilePath internal_dir; |
537 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 538 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
538 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); | 539 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); |
539 | 540 |
540 base::AutoLock auto_lock(lock_); | 541 base::AutoLock auto_lock(lock_); |
541 | 542 |
542 // Add the plugin files. | 543 // Add the plugin files. |
543 std::set<base::string16> group_names; | 544 std::set<base::string16> group_names; |
544 for (size_t i = 0; i < plugins.size(); ++i) { | 545 for (size_t i = 0; i < plugins.size(); ++i) { |
545 DictionaryValue* summary = new DictionaryValue(); | 546 base::DictionaryValue* summary = new base::DictionaryValue(); |
546 summary->SetString("path", plugins[i].path.value()); | 547 summary->SetString("path", plugins[i].path.value()); |
547 summary->SetString("name", plugins[i].name); | 548 summary->SetString("name", plugins[i].name); |
548 summary->SetString("version", plugins[i].version); | 549 summary->SetString("version", plugins[i].version); |
549 bool enabled = true; | 550 bool enabled = true; |
550 plugin_state_.Get(plugins[i].path, &enabled); | 551 plugin_state_.Get(plugins[i].path, &enabled); |
551 summary->SetBoolean("enabled", enabled); | 552 summary->SetBoolean("enabled", enabled); |
552 plugins_list->Append(summary); | 553 plugins_list->Append(summary); |
553 | 554 |
554 scoped_ptr<PluginMetadata> plugin_metadata( | 555 scoped_ptr<PluginMetadata> plugin_metadata( |
555 finder->GetPluginMetadata(plugins[i])); | 556 finder->GetPluginMetadata(plugins[i])); |
556 // Insert into a set of all group names. | 557 // Insert into a set of all group names. |
557 group_names.insert(plugin_metadata->name()); | 558 group_names.insert(plugin_metadata->name()); |
558 } | 559 } |
559 | 560 |
560 // Add the plug-in groups. | 561 // Add the plug-in groups. |
561 for (std::set<base::string16>::const_iterator it = group_names.begin(); | 562 for (std::set<base::string16>::const_iterator it = group_names.begin(); |
562 it != group_names.end(); ++it) { | 563 it != group_names.end(); ++it) { |
563 DictionaryValue* summary = new DictionaryValue(); | 564 base::DictionaryValue* summary = new base::DictionaryValue(); |
564 summary->SetString("name", *it); | 565 summary->SetString("name", *it); |
565 bool enabled = true; | 566 bool enabled = true; |
566 std::map<base::string16, bool>::iterator gstate_it = | 567 std::map<base::string16, bool>::iterator gstate_it = |
567 plugin_group_state_.find(*it); | 568 plugin_group_state_.find(*it); |
568 if (gstate_it != plugin_group_state_.end()) | 569 if (gstate_it != plugin_group_state_.end()) |
569 enabled = gstate_it->second; | 570 enabled = gstate_it->second; |
570 summary->SetBoolean("enabled", enabled); | 571 summary->SetBoolean("enabled", enabled); |
571 plugins_list->Append(summary); | 572 plugins_list->Append(summary); |
572 } | 573 } |
573 } | 574 } |
574 | 575 |
575 void PluginPrefs::NotifyPluginStatusChanged() { | 576 void PluginPrefs::NotifyPluginStatusChanged() { |
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
577 content::NotificationService::current()->Notify( | 578 content::NotificationService::current()->Notify( |
578 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 579 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
579 content::Source<Profile>(profile_), | 580 content::Source<Profile>(profile_), |
580 content::NotificationService::NoDetails()); | 581 content::NotificationService::NoDetails()); |
581 } | 582 } |
OLD | NEW |