| 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/plugin_prefs.h" | 5 #include "chrome/browser/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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "base/version.h" | 19 #include "base/version.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/plugin_installer.h" |
| 21 #include "chrome/browser/plugin_prefs_factory.h" | 22 #include "chrome/browser/plugin_prefs_factory.h" |
| 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_keyed_service.h" | 25 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/common/chrome_content_client.h" | 27 #include "chrome/common/chrome_content_client.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 plugin_state_[plugins[j].path] = enabled; | 127 plugin_state_[plugins[j].path] = enabled; |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 | 130 |
| 130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 131 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 131 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); | 132 base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups)); |
| 132 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 133 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 133 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 134 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool PluginPrefs::CanEnablePlugin(bool enabled, const FilePath& path) { | 137 void PluginPrefs::CanEnablePlugin(bool enabled, const FilePath& path, |
| 137 webkit::npapi::PluginList* plugin_list = GetPluginList(); | 138 const base::Callback<void(bool)>& cb) { |
| 139 PluginFinder::Get(base::Bind(&PluginPrefs::CanEnablePluginCallback, |
| 140 this, enabled, path, cb)); |
| 141 } |
| 142 |
| 143 void PluginPrefs::CanEnablePluginCallback(bool enabled, const FilePath& path, |
| 144 const base::Callback<void(bool)>& cb, |
| 145 PluginFinder* finder) { |
| 138 webkit::WebPluginInfo plugin; | 146 webkit::WebPluginInfo plugin; |
| 147 bool can_enable = true; |
| 139 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { | 148 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { |
| 140 scoped_ptr<webkit::npapi::PluginGroup> group( | 149 PluginInstaller* installer = finder->GetPluginInstaller(plugin); |
| 141 plugin_list->GetPluginGroup(plugin)); | |
| 142 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); | 150 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); |
| 143 PolicyStatus group_status = PolicyStatusForPlugin(group->GetGroupName()); | 151 PolicyStatus group_status = PolicyStatusForPlugin(installer->name()); |
| 144 if (enabled) { | 152 if (enabled) { |
| 145 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) | 153 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) |
| 146 return false; | 154 can_enable = false; |
| 147 } else { | 155 } else { |
| 148 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) | 156 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) |
| 149 return false; | 157 can_enable = false; |
| 150 } | 158 } |
| 151 } else { | 159 } else { |
| 152 NOTREACHED(); | 160 NOTREACHED(); |
| 153 } | 161 } |
| 154 return true; | 162 |
| 163 cb.Run(can_enable); |
| 155 } | 164 } |
| 156 | 165 |
| 157 void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path, | 166 void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path, |
| 158 const base::Closure& callback) { | 167 const base::Closure& callback) { |
| 159 PluginService::GetInstance()->GetPluginGroups( | 168 PluginService::GetInstance()->GetPluginGroups( |
| 160 base::Bind(&PluginPrefs::EnablePluginInternal, this, | 169 base::Bind(&PluginPrefs::EnablePluginInternal, this, |
| 161 enabled, path, callback)); | 170 enabled, path, callback)); |
| 162 } | 171 } |
| 163 | 172 |
| 164 void PluginPrefs::EnablePluginInternal( | 173 void PluginPrefs::EnablePluginInternal( |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 576 } |
| 568 } | 577 } |
| 569 | 578 |
| 570 void PluginPrefs::NotifyPluginStatusChanged() { | 579 void PluginPrefs::NotifyPluginStatusChanged() { |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 572 content::NotificationService::current()->Notify( | 581 content::NotificationService::current()->Notify( |
| 573 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 582 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 574 content::Source<Profile>(profile_), | 583 content::Source<Profile>(profile_), |
| 575 content::NotificationService::NoDetails()); | 584 content::NotificationService::NoDetails()); |
| 576 } | 585 } |
| OLD | NEW |