| 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 273 } |
| 274 | 274 |
| 275 void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns, | 275 void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns, |
| 276 const std::string& pref_name) { | 276 const std::string& pref_name) { |
| 277 base::AutoLock auto_lock(lock_); | 277 base::AutoLock auto_lock(lock_); |
| 278 ListValueToStringSet(prefs_->GetList(pref_name.c_str()), patterns); | 278 ListValueToStringSet(prefs_->GetList(pref_name.c_str()), patterns); |
| 279 | 279 |
| 280 NotifyPluginStatusChanged(); | 280 NotifyPluginStatusChanged(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void PluginPrefs::EnableNpapi() { |
| 284 PluginService::GetInstance()->EnableNpapiPlugins(); |
| 285 NotifyPluginStatusChanged(); |
| 286 } |
| 287 |
| 283 /*static*/ | 288 /*static*/ |
| 284 bool PluginPrefs::IsStringMatchedInSet( | 289 bool PluginPrefs::IsStringMatchedInSet( |
| 285 const base::string16& name, | 290 const base::string16& name, |
| 286 const std::set<base::string16>& pattern_set) { | 291 const std::set<base::string16>& pattern_set) { |
| 287 std::set<base::string16>::const_iterator pattern(pattern_set.begin()); | 292 std::set<base::string16>::const_iterator pattern(pattern_set.begin()); |
| 288 while (pattern != pattern_set.end()) { | 293 while (pattern != pattern_set.end()) { |
| 289 if (MatchPattern(name, *pattern)) | 294 if (MatchPattern(name, *pattern)) |
| 290 return true; | 295 return true; |
| 291 ++pattern; | 296 ++pattern; |
| 292 } | 297 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 484 // Build the set of policy enabled/disabled plugin patterns once and cache it. |
| 480 // Don't do this in the constructor, there's no profile available there. | 485 // Don't do this in the constructor, there's no profile available there. |
| 481 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), | 486 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), |
| 482 &policy_disabled_plugin_patterns_); | 487 &policy_disabled_plugin_patterns_); |
| 483 ListValueToStringSet( | 488 ListValueToStringSet( |
| 484 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), | 489 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), |
| 485 &policy_disabled_plugin_exception_patterns_); | 490 &policy_disabled_plugin_exception_patterns_); |
| 486 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), | 491 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), |
| 487 &policy_enabled_plugin_patterns_); | 492 &policy_enabled_plugin_patterns_); |
| 488 | 493 |
| 494 if (prefs_->GetBoolean(prefs::kEnableNpapi)) |
| 495 EnableNpapi(); |
| 496 |
| 489 registrar_.Init(prefs_); | 497 registrar_.Init(prefs_); |
| 490 | 498 |
| 491 // Because pointers to our own members will remain unchanged for the | 499 // Because pointers to our own members will remain unchanged for the |
| 492 // lifetime of |registrar_| (which we also own), we can bind their | 500 // lifetime of |registrar_| (which we also own), we can bind their |
| 493 // pointer values directly in the callbacks to avoid string-based | 501 // pointer values directly in the callbacks to avoid string-based |
| 494 // lookups at notification time. | 502 // lookups at notification time. |
| 495 registrar_.Add(prefs::kPluginsDisabledPlugins, | 503 registrar_.Add(prefs::kPluginsDisabledPlugins, |
| 496 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, | 504 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, |
| 497 base::Unretained(this), | 505 base::Unretained(this), |
| 498 &policy_disabled_plugin_patterns_)); | 506 &policy_disabled_plugin_patterns_)); |
| 499 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, | 507 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, |
| 500 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, | 508 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, |
| 501 base::Unretained(this), | 509 base::Unretained(this), |
| 502 &policy_disabled_plugin_exception_patterns_)); | 510 &policy_disabled_plugin_exception_patterns_)); |
| 503 registrar_.Add(prefs::kPluginsEnabledPlugins, | 511 registrar_.Add(prefs::kPluginsEnabledPlugins, |
| 504 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, | 512 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, |
| 505 base::Unretained(this), | 513 base::Unretained(this), |
| 506 &policy_enabled_plugin_patterns_)); | 514 &policy_enabled_plugin_patterns_)); |
| 515 registrar_.Add(prefs::kEnableNpapi, |
| 516 base::Bind(&PluginPrefs::EnableNpapi, |
| 517 base::Unretained(this))); |
| 507 | 518 |
| 508 NotifyPluginStatusChanged(); | 519 NotifyPluginStatusChanged(); |
| 509 } | 520 } |
| 510 | 521 |
| 511 void PluginPrefs::ShutdownOnUIThread() { | 522 void PluginPrefs::ShutdownOnUIThread() { |
| 512 prefs_ = NULL; | 523 prefs_ = NULL; |
| 513 registrar_.RemoveAll(); | 524 registrar_.RemoveAll(); |
| 514 } | 525 } |
| 515 | 526 |
| 516 PluginPrefs::PluginPrefs() : profile_(NULL), | 527 PluginPrefs::PluginPrefs() : profile_(NULL), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 589 } |
| 579 } | 590 } |
| 580 | 591 |
| 581 void PluginPrefs::NotifyPluginStatusChanged() { | 592 void PluginPrefs::NotifyPluginStatusChanged() { |
| 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 583 content::NotificationService::current()->Notify( | 594 content::NotificationService::current()->Notify( |
| 584 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 595 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 585 content::Source<Profile>(profile_), | 596 content::Source<Profile>(profile_), |
| 586 content::NotificationService::NoDetails()); | 597 content::NotificationService::NoDetails()); |
| 587 } | 598 } |
| OLD | NEW |