| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_updater.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 14 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 13 #include "base/values.h" |
| 16 #include "base/version.h" | 14 #include "base/version.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_dependency_manager.h" | |
| 21 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | |
| 23 #include "chrome/common/chrome_content_client.h" | 18 #include "chrome/common/chrome_content_client.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | |
| 27 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 28 #include "content/browser/browser_thread.h" | 22 #include "content/browser/browser_thread.h" |
| 29 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| 30 #include "webkit/plugins/npapi/plugin_list.h" | 24 #include "webkit/plugins/npapi/plugin_list.h" |
| 31 #include "webkit/plugins/npapi/webplugininfo.h" | 25 #include "webkit/plugins/npapi/webplugininfo.h" |
| 32 | 26 |
| 33 namespace { | |
| 34 | |
| 35 class PluginPrefsWrapper : public ProfileKeyedService { | |
| 36 public: | |
| 37 explicit PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs) | |
| 38 : plugin_prefs_(plugin_prefs) {} | |
| 39 virtual ~PluginPrefsWrapper() {} | |
| 40 | |
| 41 PluginPrefs* plugin_prefs() { return plugin_prefs_.get(); } | |
| 42 | |
| 43 private: | |
| 44 // ProfileKeyedService methods: | |
| 45 virtual void Shutdown() OVERRIDE { | |
| 46 plugin_prefs_->ShutdownOnUIThread(); | |
| 47 } | |
| 48 | |
| 49 scoped_refptr<PluginPrefs> plugin_prefs_; | |
| 50 }; | |
| 51 | |
| 52 } | |
| 53 | |
| 54 // How long to wait to save the plugin enabled information, which might need to | 27 // How long to wait to save the plugin enabled information, which might need to |
| 55 // go to disk. | 28 // go to disk. |
| 56 #define kPluginUpdateDelayMs (60 * 1000) | 29 #define kPluginUpdateDelayMs (60 * 1000) |
| 57 | 30 |
| 58 class PluginPrefs::Factory : public ProfileKeyedServiceFactory { | 31 PluginUpdater::PluginUpdater() |
| 59 public: | 32 : notify_pending_(false) { |
| 60 static Factory* GetInstance(); | |
| 61 | |
| 62 PluginPrefsWrapper* GetWrapperForProfile(Profile* profile); | |
| 63 | |
| 64 private: | |
| 65 friend struct DefaultSingletonTraits<Factory>; | |
| 66 | |
| 67 Factory(); | |
| 68 virtual ~Factory() {} | |
| 69 | |
| 70 // ProfileKeyedServiceFactory methods: | |
| 71 virtual ProfileKeyedService* BuildServiceInstanceFor( | |
| 72 Profile* profile) const OVERRIDE; | |
| 73 virtual bool ServiceRedirectedInIncognito() OVERRIDE { return true; } | |
| 74 virtual bool ServiceIsNULLWhileTesting() OVERRIDE { return true; } | |
| 75 }; | |
| 76 | |
| 77 // static | |
| 78 void PluginPrefs::Initialize() { | |
| 79 Factory::GetInstance(); | |
| 80 } | 33 } |
| 81 | 34 |
| 82 // static | 35 DictionaryValue* PluginUpdater::CreatePluginFileSummary( |
| 83 PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) { | |
| 84 PluginPrefs* plugin_prefs = | |
| 85 Factory::GetInstance()->GetWrapperForProfile(profile)->plugin_prefs(); | |
| 86 DCHECK(plugin_prefs); | |
| 87 return plugin_prefs; | |
| 88 } | |
| 89 | |
| 90 DictionaryValue* PluginPrefs::CreatePluginFileSummary( | |
| 91 const webkit::npapi::WebPluginInfo& plugin) { | 36 const webkit::npapi::WebPluginInfo& plugin) { |
| 92 DictionaryValue* data = new DictionaryValue(); | 37 DictionaryValue* data = new DictionaryValue(); |
| 93 data->SetString("path", plugin.path.value()); | 38 data->SetString("path", plugin.path.value()); |
| 94 data->SetString("name", plugin.name); | 39 data->SetString("name", plugin.name); |
| 95 data->SetString("version", plugin.version); | 40 data->SetString("version", plugin.version); |
| 96 data->SetBoolean("enabled", IsPluginEnabled(plugin)); | 41 data->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(plugin)); |
| 97 return data; | 42 return data; |
| 98 } | 43 } |
| 99 | 44 |
| 100 void PluginPrefs::EnablePluginGroup(bool enable, const string16& group_name) { | 45 // static |
| 46 ListValue* PluginUpdater::GetPluginGroupsData() { |
| 47 std::vector<webkit::npapi::PluginGroup> plugin_groups; |
| 48 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); |
| 49 |
| 50 // Construct DictionaryValues to return to the UI |
| 51 ListValue* plugin_groups_data = new ListValue(); |
| 52 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
| 53 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); |
| 54 } |
| 55 return plugin_groups_data; |
| 56 } |
| 57 |
| 58 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { |
| 101 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); | 59 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); |
| 102 NotifyPluginStatusChanged(); | 60 NotifyPluginStatusChanged(); |
| 103 } | 61 } |
| 104 | 62 |
| 105 void PluginPrefs::EnablePlugin(bool enable, const FilePath& path) { | 63 void PluginUpdater::EnablePlugin(bool enable, |
| 64 const FilePath::StringType& path) { |
| 65 FilePath file_path(path); |
| 106 if (enable) | 66 if (enable) |
| 107 webkit::npapi::PluginList::Singleton()->EnablePlugin(path); | 67 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); |
| 108 else | 68 else |
| 109 webkit::npapi::PluginList::Singleton()->DisablePlugin(path); | 69 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); |
| 110 | 70 |
| 111 NotifyPluginStatusChanged(); | 71 NotifyPluginStatusChanged(); |
| 112 } | 72 } |
| 113 | 73 |
| 114 bool PluginPrefs::IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin) { | 74 void PluginUpdater::Observe(int type, |
| 115 // If enabling NaCl, make sure the plugin is also enabled. See bug | |
| 116 // http://code.google.com/p/chromium/issues/detail?id=81010 for more | |
| 117 // information. | |
| 118 // TODO(dspringer): When NaCl is on by default, remove this code. | |
| 119 if ((plugin.name == | |
| 120 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName)) && | |
| 121 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) { | |
| 122 return true; | |
| 123 } | |
| 124 return webkit::npapi::IsPluginEnabled(plugin); | |
| 125 } | |
| 126 | |
| 127 void PluginPrefs::Observe(int type, | |
| 128 const NotificationSource& source, | 75 const NotificationSource& source, |
| 129 const NotificationDetails& details) { | 76 const NotificationDetails& details) { |
| 130 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); | 77 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); |
| 131 const std::string* pref_name = Details<std::string>(details).ptr(); | 78 const std::string* pref_name = Details<std::string>(details).ptr(); |
| 132 if (!pref_name) { | 79 if (!pref_name) { |
| 133 NOTREACHED(); | 80 NOTREACHED(); |
| 134 return; | 81 return; |
| 135 } | 82 } |
| 136 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | |
| 137 if (*pref_name == prefs::kPluginsDisabledPlugins || | 83 if (*pref_name == prefs::kPluginsDisabledPlugins || |
| 138 *pref_name == prefs::kPluginsDisabledPluginsExceptions || | 84 *pref_name == prefs::kPluginsDisabledPluginsExceptions || |
| 139 *pref_name == prefs::kPluginsEnabledPlugins) { | 85 *pref_name == prefs::kPluginsEnabledPlugins) { |
| 86 PrefService* pref_service = Source<PrefService>(source).ptr(); |
| 140 const ListValue* disabled_list = | 87 const ListValue* disabled_list = |
| 141 prefs_->GetList(prefs::kPluginsDisabledPlugins); | 88 pref_service->GetList(prefs::kPluginsDisabledPlugins); |
| 142 const ListValue* exceptions_list = | 89 const ListValue* exceptions_list = |
| 143 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); | 90 pref_service->GetList(prefs::kPluginsDisabledPluginsExceptions); |
| 144 const ListValue* enabled_list = | 91 const ListValue* enabled_list = |
| 145 prefs_->GetList(prefs::kPluginsEnabledPlugins); | 92 pref_service->GetList(prefs::kPluginsEnabledPlugins); |
| 146 UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list); | 93 UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list); |
| 147 } | 94 } |
| 148 } | 95 } |
| 149 | 96 |
| 150 void PluginPrefs::UpdatePluginsStateFromPolicy( | 97 void PluginUpdater::UpdatePluginsStateFromPolicy( |
| 151 const ListValue* disabled_list, | 98 const ListValue* disabled_list, |
| 152 const ListValue* exceptions_list, | 99 const ListValue* exceptions_list, |
| 153 const ListValue* enabled_list) { | 100 const ListValue* enabled_list) { |
| 154 std::set<string16> disabled_plugin_patterns; | 101 std::set<string16> disabled_plugin_patterns; |
| 155 std::set<string16> disabled_plugin_exception_patterns; | 102 std::set<string16> disabled_plugin_exception_patterns; |
| 156 std::set<string16> enabled_plugin_patterns; | 103 std::set<string16> enabled_plugin_patterns; |
| 157 | 104 |
| 158 ListValueToStringSet(disabled_list, &disabled_plugin_patterns); | 105 ListValueToStringSet(disabled_list, &disabled_plugin_patterns); |
| 159 ListValueToStringSet(exceptions_list, &disabled_plugin_exception_patterns); | 106 ListValueToStringSet(exceptions_list, &disabled_plugin_exception_patterns); |
| 160 ListValueToStringSet(enabled_list, &enabled_plugin_patterns); | 107 ListValueToStringSet(enabled_list, &enabled_plugin_patterns); |
| 161 | 108 |
| 162 webkit::npapi::PluginGroup::SetPolicyEnforcedPluginPatterns( | 109 webkit::npapi::PluginGroup::SetPolicyEnforcedPluginPatterns( |
| 163 disabled_plugin_patterns, | 110 disabled_plugin_patterns, |
| 164 disabled_plugin_exception_patterns, | 111 disabled_plugin_exception_patterns, |
| 165 enabled_plugin_patterns); | 112 enabled_plugin_patterns); |
| 166 | 113 |
| 167 NotifyPluginStatusChanged(); | 114 NotifyPluginStatusChanged(); |
| 168 } | 115 } |
| 169 | 116 |
| 170 void PluginPrefs::ListValueToStringSet(const ListValue* src, | 117 void PluginUpdater::ListValueToStringSet(const ListValue* src, |
| 171 std::set<string16>* dest) { | 118 std::set<string16>* dest) { |
| 172 DCHECK(src); | 119 DCHECK(src); |
| 173 DCHECK(dest); | 120 DCHECK(dest); |
| 174 ListValue::const_iterator end(src->end()); | 121 ListValue::const_iterator end(src->end()); |
| 175 for (ListValue::const_iterator current(src->begin()); | 122 for (ListValue::const_iterator current(src->begin()); |
| 176 current != end; ++current) { | 123 current != end; ++current) { |
| 177 string16 plugin_name; | 124 string16 plugin_name; |
| 178 if ((*current)->GetAsString(&plugin_name)) { | 125 if ((*current)->GetAsString(&plugin_name)) { |
| 179 dest->insert(plugin_name); | 126 dest->insert(plugin_name); |
| 180 } | 127 } |
| 181 } | 128 } |
| 182 } | 129 } |
| 183 | 130 |
| 184 void PluginPrefs::SetProfile(Profile* profile) { | 131 void PluginUpdater::SetProfile(Profile* profile) { |
| 185 prefs_ = profile->GetPrefs(); | |
| 186 bool update_internal_dir = false; | 132 bool update_internal_dir = false; |
| 187 FilePath last_internal_dir = | 133 FilePath last_internal_dir = |
| 188 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); | 134 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); |
| 189 FilePath cur_internal_dir; | 135 FilePath cur_internal_dir; |
| 190 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && | 136 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
| 191 cur_internal_dir != last_internal_dir) { | 137 cur_internal_dir != last_internal_dir) { |
| 192 update_internal_dir = true; | 138 update_internal_dir = true; |
| 193 prefs_->SetFilePath( | 139 profile->GetPrefs()->SetFilePath( |
| 194 prefs::kPluginsLastInternalDirectory, cur_internal_dir); | 140 prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
| 195 } | 141 } |
| 196 | 142 |
| 197 bool force_enable_internal_pdf = false; | 143 bool force_enable_internal_pdf = false; |
| 198 bool internal_pdf_enabled = false; | 144 bool internal_pdf_enabled = false; |
| 199 string16 pdf_group_name = | 145 string16 pdf_group_name = |
| 200 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); | 146 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); |
| 201 FilePath pdf_path; | 147 FilePath pdf_path; |
| 202 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 148 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 203 FilePath::StringType pdf_path_str = pdf_path.value(); | 149 FilePath::StringType pdf_path_str = pdf_path.value(); |
| 204 if (!prefs_->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { | 150 if (!profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { |
| 205 // We switched to the internal pdf plugin being on by default, and so we | 151 // We switched to the internal pdf plugin being on by default, and so we |
| 206 // need to force it to be enabled. We only want to do it this once though, | 152 // need to force it to be enabled. We only want to do it this once though, |
| 207 // i.e. we don't want to enable it again if the user disables it afterwards. | 153 // i.e. we don't want to enable it again if the user disables it afterwards. |
| 208 prefs_->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); | 154 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); |
| 209 force_enable_internal_pdf = true; | 155 force_enable_internal_pdf = true; |
| 210 } | 156 } |
| 211 | 157 |
| 212 { // Scoped update of prefs::kPluginsPluginsList. | 158 { // Scoped update of prefs::kPluginsPluginsList. |
| 213 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 159 ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); |
| 214 ListValue* saved_plugins_list = update.Get(); | 160 ListValue* saved_plugins_list = update.Get(); |
| 215 if (saved_plugins_list && !saved_plugins_list->empty()) { | 161 if (saved_plugins_list && !saved_plugins_list->empty()) { |
| 216 for (ListValue::const_iterator it = saved_plugins_list->begin(); | 162 for (ListValue::const_iterator it = saved_plugins_list->begin(); |
| 217 it != saved_plugins_list->end(); | 163 it != saved_plugins_list->end(); |
| 218 ++it) { | 164 ++it) { |
| 219 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { | 165 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { |
| 220 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 166 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 221 continue; // Oops, don't know what to do with this item. | 167 continue; // Oops, don't know what to do with this item. |
| 222 } | 168 } |
| 223 | 169 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // If the saved plugin list is empty, then the call to UpdatePreferences() | 214 // If the saved plugin list is empty, then the call to UpdatePreferences() |
| 269 // below failed in an earlier run, possibly because the user closed the | 215 // below failed in an earlier run, possibly because the user closed the |
| 270 // browser too quickly. Try to force enable the internal PDF plugin again. | 216 // browser too quickly. Try to force enable the internal PDF plugin again. |
| 271 force_enable_internal_pdf = true; | 217 force_enable_internal_pdf = true; |
| 272 } | 218 } |
| 273 } // Scoped update of prefs::kPluginsPluginsList. | 219 } // Scoped update of prefs::kPluginsPluginsList. |
| 274 | 220 |
| 275 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 221 // Build the set of policy enabled/disabled plugin patterns once and cache it. |
| 276 // Don't do this in the constructor, there's no profile available there. | 222 // Don't do this in the constructor, there's no profile available there. |
| 277 const ListValue* disabled_plugins = | 223 const ListValue* disabled_plugins = |
| 278 prefs_->GetList(prefs::kPluginsDisabledPlugins); | 224 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPlugins); |
| 279 const ListValue* disabled_exception_plugins = | 225 const ListValue* disabled_exception_plugins = |
| 280 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); | 226 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPluginsExceptions); |
| 281 const ListValue* enabled_plugins = | 227 const ListValue* enabled_plugins = |
| 282 prefs_->GetList(prefs::kPluginsEnabledPlugins); | 228 profile->GetPrefs()->GetList(prefs::kPluginsEnabledPlugins); |
| 283 UpdatePluginsStateFromPolicy(disabled_plugins, | 229 UpdatePluginsStateFromPolicy(disabled_plugins, |
| 284 disabled_exception_plugins, | 230 disabled_exception_plugins, |
| 285 enabled_plugins); | 231 enabled_plugins); |
| 286 | 232 |
| 287 registrar_.RemoveAll(); | 233 registrar_.RemoveAll(); |
| 288 registrar_.Init(prefs_); | 234 registrar_.Init(profile->GetPrefs()); |
| 289 registrar_.Add(prefs::kPluginsDisabledPlugins, this); | 235 registrar_.Add(prefs::kPluginsDisabledPlugins, this); |
| 290 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); | 236 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); |
| 291 registrar_.Add(prefs::kPluginsEnabledPlugins, this); | 237 registrar_.Add(prefs::kPluginsEnabledPlugins, this); |
| 292 | 238 |
| 293 if (force_enable_internal_pdf || internal_pdf_enabled) { | 239 if (force_enable_internal_pdf || internal_pdf_enabled) { |
| 294 // See http://crbug.com/50105 for background. | 240 // See http://crbug.com/50105 for background. |
| 295 EnablePluginGroup(false, ASCIIToUTF16( | 241 EnablePluginGroup(false, ASCIIToUTF16( |
| 296 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 242 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
| 297 } | 243 } |
| 298 | 244 |
| 299 if (force_enable_internal_pdf) { | 245 if (force_enable_internal_pdf) { |
| 300 // We want to save this, but doing so requires loading the list of plugins, | 246 // We want to save this, but doing so requires loading the list of plugins, |
| 301 // so do it after a minute as to not impact startup performance. Note that | 247 // so do it after a minute as to not impact startup performance. Note that |
| 302 // plugins are loaded after 30s by the metrics service. | 248 // plugins are loaded after 30s by the metrics service. |
| 303 UpdatePreferences(kPluginUpdateDelayMs); | 249 UpdatePreferences(profile, kPluginUpdateDelayMs); |
| 304 } | 250 } |
| 305 } | 251 } |
| 306 | 252 |
| 307 void PluginPrefs::ShutdownOnUIThread() { | 253 void PluginUpdater::Shutdown() { |
| 308 prefs_ = NULL; | |
| 309 registrar_.RemoveAll(); | 254 registrar_.RemoveAll(); |
| 310 } | 255 } |
| 311 | 256 |
| 312 // static | 257 void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { |
| 313 PluginPrefs::Factory* PluginPrefs::Factory::GetInstance() { | 258 BrowserThread::PostDelayedTask( |
| 314 return Singleton<PluginPrefs::Factory>::get(); | 259 BrowserThread::FILE, |
| 260 FROM_HERE, |
| 261 NewRunnableFunction( |
| 262 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); |
| 315 } | 263 } |
| 316 | 264 |
| 317 PluginPrefsWrapper* PluginPrefs::Factory::GetWrapperForProfile( | 265 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { |
| 318 Profile* profile) { | 266 std::vector<webkit::npapi::WebPluginInfo> plugins; |
| 319 return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true)); | 267 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); |
| 320 } | |
| 321 | 268 |
| 322 PluginPrefs::Factory::Factory() | 269 std::vector<webkit::npapi::PluginGroup> groups; |
| 323 : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { | 270 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); |
| 324 } | |
| 325 | 271 |
| 326 ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor( | 272 BrowserThread::PostTask( |
| 327 Profile* profile) const { | 273 BrowserThread::UI, |
| 328 scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs()); | 274 FROM_HERE, |
| 329 plugin_prefs->SetProfile(profile); | 275 NewRunnableFunction(&PluginUpdater::OnUpdatePreferences, |
| 330 return new PluginPrefsWrapper(plugin_prefs); | 276 static_cast<Profile*>(profile), |
| 331 } | |
| 332 | |
| 333 PluginPrefs::PluginPrefs() : notify_pending_(false) { | |
| 334 } | |
| 335 | |
| 336 PluginPrefs::~PluginPrefs() { | |
| 337 } | |
| 338 | |
| 339 void PluginPrefs::UpdatePreferences(int delay_ms) { | |
| 340 BrowserThread::PostDelayedTask( | |
| 341 BrowserThread::FILE, | |
| 342 FROM_HERE, | |
| 343 NewRunnableMethod(this, &PluginPrefs::GetPreferencesDataOnFileThread), | |
| 344 delay_ms); | |
| 345 } | |
| 346 | |
| 347 void PluginPrefs::GetPreferencesDataOnFileThread() { | |
| 348 std::vector<webkit::npapi::WebPluginInfo> plugins; | |
| 349 std::vector<webkit::npapi::PluginGroup> groups; | |
| 350 | |
| 351 webkit::npapi::PluginList* plugin_list = | |
| 352 webkit::npapi::PluginList::Singleton(); | |
| 353 plugin_list->GetPlugins(&plugins); | |
| 354 plugin_list->GetPluginGroups(false, &groups); | |
| 355 | |
| 356 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 357 NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, | |
| 358 plugins, groups)); | 277 plugins, groups)); |
| 359 } | 278 } |
| 360 | 279 |
| 361 void PluginPrefs::OnUpdatePreferences( | 280 void PluginUpdater::OnUpdatePreferences( |
| 362 std::vector<webkit::npapi::WebPluginInfo> plugins, | 281 Profile* profile, |
| 363 std::vector<webkit::npapi::PluginGroup> groups) { | 282 const std::vector<webkit::npapi::WebPluginInfo>& plugins, |
| 364 if (!prefs_) | 283 const std::vector<webkit::npapi::PluginGroup>& groups) { |
| 365 return; | 284 ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); |
| 366 | |
| 367 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | |
| 368 ListValue* plugins_list = update.Get(); | 285 ListValue* plugins_list = update.Get(); |
| 369 plugins_list->Clear(); | 286 plugins_list->Clear(); |
| 370 | 287 |
| 371 FilePath internal_dir; | 288 FilePath internal_dir; |
| 372 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 289 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
| 373 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); | 290 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, |
| 291 internal_dir); |
| 374 | 292 |
| 375 // Add the plugin files. | 293 // Add the plugin files. |
| 376 for (size_t i = 0; i < plugins.size(); ++i) { | 294 for (size_t i = 0; i < plugins.size(); ++i) { |
| 377 DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); | 295 DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); |
| 378 // If the plugin is managed by policy, store the user preferred state | 296 // If the plugin is managed by policy, store the user preferred state |
| 379 // instead. | 297 // instead. |
| 380 if (plugins[i].enabled & | 298 if (plugins[i].enabled & webkit::npapi::WebPluginInfo::MANAGED_MASK) { |
| 381 webkit::npapi::WebPluginInfo::MANAGED_MASK) { | |
| 382 bool user_enabled = | 299 bool user_enabled = |
| 383 (plugins[i].enabled & webkit::npapi::WebPluginInfo::USER_MASK) == | 300 (plugins[i].enabled & webkit::npapi::WebPluginInfo::USER_MASK) == |
| 384 webkit::npapi::WebPluginInfo::USER_ENABLED; | 301 webkit::npapi::WebPluginInfo::USER_ENABLED; |
| 385 summary->SetBoolean("enabled", user_enabled); | 302 summary->SetBoolean("enabled", user_enabled); |
| 386 } | 303 } |
| 387 plugins_list->Append(summary); | 304 plugins_list->Append(summary); |
| 388 } | 305 } |
| 389 | 306 |
| 390 // Add the groups as well. | 307 // Add the groups as well. |
| 391 for (size_t i = 0; i < groups.size(); ++i) { | 308 for (size_t i = 0; i < groups.size(); ++i) { |
| 392 DictionaryValue* summary = groups[i].GetSummary(); | 309 DictionaryValue* summary = groups[i].GetSummary(); |
| 393 // If the plugin is disabled only by policy don't store this state in the | 310 // If the plugin is disabled only by policy don't store this state in the |
| 394 // user pref store. | 311 // user pref store. |
| 395 if (!groups[i].Enabled() && | 312 if (!groups[i].Enabled() && |
| 396 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy( | 313 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy( |
| 397 groups[i].GetGroupName())) | 314 groups[i].GetGroupName())) |
| 398 summary->SetBoolean("enabled", true); | 315 summary->SetBoolean("enabled", true); |
| 399 plugins_list->Append(summary); | 316 plugins_list->Append(summary); |
| 400 } | 317 } |
| 401 } | 318 } |
| 402 | 319 |
| 403 void PluginPrefs::NotifyPluginStatusChanged() { | 320 void PluginUpdater::NotifyPluginStatusChanged() { |
| 404 if (notify_pending_) | 321 if (notify_pending_) |
| 405 return; | 322 return; |
| 406 notify_pending_ = true; | 323 notify_pending_ = true; |
| 407 MessageLoop::current()->PostTask( | 324 MessageLoop::current()->PostTask( |
| 408 FROM_HERE, | 325 FROM_HERE, |
| 409 NewRunnableMethod(this, &PluginPrefs::OnNotifyPluginStatusChanged)); | 326 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); |
| 410 } | 327 } |
| 411 | 328 |
| 412 void PluginPrefs::OnNotifyPluginStatusChanged() { | 329 void PluginUpdater::OnNotifyPluginStatusChanged() { |
| 413 notify_pending_ = false; | 330 GetInstance()->notify_pending_ = false; |
| 414 NotificationService::current()->Notify( | 331 NotificationService::current()->Notify( |
| 415 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 332 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 416 Source<PluginPrefs>(this), | 333 Source<PluginUpdater>(GetInstance()), |
| 417 NotificationService::NoDetails()); | 334 NotificationService::NoDetails()); |
| 418 } | 335 } |
| 419 | 336 |
| 420 /*static*/ | 337 /*static*/ |
| 421 void PluginPrefs::RegisterPrefs(PrefService* prefs) { | 338 PluginUpdater* PluginUpdater::GetInstance() { |
| 339 return Singleton<PluginUpdater>::get(); |
| 340 } |
| 341 |
| 342 /*static*/ |
| 343 void PluginUpdater::RegisterPrefs(PrefService* prefs) { |
| 422 FilePath internal_dir; | 344 FilePath internal_dir; |
| 423 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir); | 345 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir); |
| 424 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, | 346 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, |
| 425 internal_dir, | 347 internal_dir, |
| 426 PrefService::UNSYNCABLE_PREF); | 348 PrefService::UNSYNCABLE_PREF); |
| 427 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, | 349 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, |
| 428 PrefService::UNSYNCABLE_PREF); | 350 PrefService::UNSYNCABLE_PREF); |
| 429 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, | 351 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, |
| 430 PrefService::UNSYNCABLE_PREF); | 352 PrefService::UNSYNCABLE_PREF); |
| 431 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, | 353 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, |
| 432 PrefService::UNSYNCABLE_PREF); | 354 PrefService::UNSYNCABLE_PREF); |
| 433 } | 355 } |
| OLD | NEW |