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