| 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_prefs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 203 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 204 FilePath::StringType pdf_path_str = pdf_path.value(); | 204 FilePath::StringType pdf_path_str = pdf_path.value(); |
| 205 if (!prefs_->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { | 205 if (!prefs_->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { |
| 206 // We switched to the internal pdf plugin being on by default, and so we | 206 // We switched to the internal pdf plugin being on by default, and so we |
| 207 // need to force it to be enabled. We only want to do it this once though, | 207 // need to force it to be enabled. We only want to do it this once though, |
| 208 // i.e. we don't want to enable it again if the user disables it afterwards. | 208 // i.e. we don't want to enable it again if the user disables it afterwards. |
| 209 prefs_->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); | 209 prefs_->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); |
| 210 force_enable_internal_pdf = true; | 210 force_enable_internal_pdf = true; |
| 211 } | 211 } |
| 212 | 212 |
| 213 bool force_enable_nacl = false; |
| 214 string16 nacl_group_name = |
| 215 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName); |
| 216 // Since the NaCl Plugin changed names between Chrome 13 and 14, we need to |
| 217 // check for both because either could be stored as the plugin group name. |
| 218 string16 old_nacl_group_name = |
| 219 ASCIIToUTF16(chrome::ChromeContentClient::kNaClOldPluginName); |
| 220 FilePath nacl_path; |
| 221 PathService::Get(chrome::FILE_NACL_PLUGIN, &nacl_path); |
| 222 FilePath::StringType nacl_path_str = nacl_path.value(); |
| 223 if (!prefs_->GetBoolean(prefs::kPluginsEnabledNaCl)) { |
| 224 // We switched to the nacl plugin being on by default, and so we need to |
| 225 // force it to be enabled. We only want to do it this once though, i.e. |
| 226 // we don't want to enable it again if the user disables it afterwards. |
| 227 prefs_->SetBoolean(prefs::kPluginsEnabledNaCl, true); |
| 228 force_enable_nacl = true; |
| 229 } |
| 230 |
| 213 { // Scoped update of prefs::kPluginsPluginsList. | 231 { // Scoped update of prefs::kPluginsPluginsList. |
| 214 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 232 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
| 215 ListValue* saved_plugins_list = update.Get(); | 233 ListValue* saved_plugins_list = update.Get(); |
| 216 if (saved_plugins_list && !saved_plugins_list->empty()) { | 234 if (saved_plugins_list && !saved_plugins_list->empty()) { |
| 217 for (ListValue::const_iterator it = saved_plugins_list->begin(); | 235 for (ListValue::const_iterator it = saved_plugins_list->begin(); |
| 218 it != saved_plugins_list->end(); | 236 it != saved_plugins_list->end(); |
| 219 ++it) { | 237 ++it) { |
| 220 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { | 238 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { |
| 221 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 239 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 222 continue; // Oops, don't know what to do with this item. | 240 continue; // Oops, don't know what to do with this item. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 244 plugin->SetString("path", path); | 262 plugin->SetString("path", path); |
| 245 } | 263 } |
| 246 | 264 |
| 247 if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) { | 265 if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) { |
| 248 if (!enabled && force_enable_internal_pdf) { | 266 if (!enabled && force_enable_internal_pdf) { |
| 249 enabled = true; | 267 enabled = true; |
| 250 plugin->SetBoolean("enabled", true); | 268 plugin->SetBoolean("enabled", true); |
| 251 } | 269 } |
| 252 | 270 |
| 253 internal_pdf_enabled = enabled; | 271 internal_pdf_enabled = enabled; |
| 272 } else if (FilePath::CompareIgnoreCase(path, nacl_path_str) == 0) { |
| 273 if (!enabled && force_enable_nacl) { |
| 274 enabled = true; |
| 275 plugin->SetBoolean("enabled", true); |
| 276 } |
| 254 } | 277 } |
| 255 | 278 |
| 256 if (!enabled) | 279 if (!enabled) |
| 257 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); | 280 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path); |
| 258 } else if (!enabled && plugin->GetString("name", &group_name)) { | 281 } else if (!enabled && plugin->GetString("name", &group_name)) { |
| 259 // Don't disable this group if it's for the pdf plugin and we just | 282 // Don't disable this group if it's for the pdf or nacl plugins and |
| 260 // forced it on. | 283 // we just forced it on. |
| 261 if (force_enable_internal_pdf && pdf_group_name == group_name) | 284 if (force_enable_internal_pdf && pdf_group_name == group_name) |
| 262 continue; | 285 continue; |
| 286 if (force_enable_nacl && (nacl_group_name == group_name || |
| 287 old_nacl_group_name == group_name)) |
| 288 continue; |
| 263 | 289 |
| 264 // Otherwise this is a list of groups. | 290 // Otherwise this is a list of groups. |
| 265 EnablePluginGroup(false, group_name); | 291 EnablePluginGroup(false, group_name); |
| 266 } | 292 } |
| 267 } | 293 } |
| 268 } else { | 294 } else { |
| 269 // If the saved plugin list is empty, then the call to UpdatePreferences() | 295 // If the saved plugin list is empty, then the call to UpdatePreferences() |
| 270 // below failed in an earlier run, possibly because the user closed the | 296 // below failed in an earlier run, possibly because the user closed the |
| 271 // browser too quickly. Try to force enable the internal PDF plugin again. | 297 // browser too quickly. Try to force enable the internal PDF and nacl |
| 298 // plugins again. |
| 272 force_enable_internal_pdf = true; | 299 force_enable_internal_pdf = true; |
| 300 force_enable_nacl = true; |
| 273 } | 301 } |
| 274 } // Scoped update of prefs::kPluginsPluginsList. | 302 } // Scoped update of prefs::kPluginsPluginsList. |
| 275 | 303 |
| 276 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 304 // Build the set of policy enabled/disabled plugin patterns once and cache it. |
| 277 // Don't do this in the constructor, there's no profile available there. | 305 // Don't do this in the constructor, there's no profile available there. |
| 278 const ListValue* disabled_plugins = | 306 const ListValue* disabled_plugins = |
| 279 prefs_->GetList(prefs::kPluginsDisabledPlugins); | 307 prefs_->GetList(prefs::kPluginsDisabledPlugins); |
| 280 const ListValue* disabled_exception_plugins = | 308 const ListValue* disabled_exception_plugins = |
| 281 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); | 309 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); |
| 282 const ListValue* enabled_plugins = | 310 const ListValue* enabled_plugins = |
| 283 prefs_->GetList(prefs::kPluginsEnabledPlugins); | 311 prefs_->GetList(prefs::kPluginsEnabledPlugins); |
| 284 UpdatePluginsStateFromPolicy(disabled_plugins, | 312 UpdatePluginsStateFromPolicy(disabled_plugins, |
| 285 disabled_exception_plugins, | 313 disabled_exception_plugins, |
| 286 enabled_plugins); | 314 enabled_plugins); |
| 287 | 315 |
| 288 registrar_.RemoveAll(); | 316 registrar_.RemoveAll(); |
| 289 registrar_.Init(prefs_); | 317 registrar_.Init(prefs_); |
| 290 registrar_.Add(prefs::kPluginsDisabledPlugins, this); | 318 registrar_.Add(prefs::kPluginsDisabledPlugins, this); |
| 291 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); | 319 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); |
| 292 registrar_.Add(prefs::kPluginsEnabledPlugins, this); | 320 registrar_.Add(prefs::kPluginsEnabledPlugins, this); |
| 293 | 321 |
| 294 if (force_enable_internal_pdf || internal_pdf_enabled) { | 322 if (force_enable_internal_pdf || internal_pdf_enabled) { |
| 295 // See http://crbug.com/50105 for background. | 323 // See http://crbug.com/50105 for background. |
| 296 EnablePluginGroup(false, ASCIIToUTF16( | 324 EnablePluginGroup(false, ASCIIToUTF16( |
| 297 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 325 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
| 298 } | 326 } |
| 299 | 327 |
| 300 if (force_enable_internal_pdf) { | 328 if (force_enable_internal_pdf || force_enable_nacl) { |
| 301 // We want to save this, but doing so requires loading the list of plugins, | 329 // We want to save this, but doing so requires loading the list of plugins, |
| 302 // so do it after a minute as to not impact startup performance. Note that | 330 // so do it after a minute as to not impact startup performance. Note that |
| 303 // plugins are loaded after 30s by the metrics service. | 331 // plugins are loaded after 30s by the metrics service. |
| 304 UpdatePreferences(kPluginUpdateDelayMs); | 332 UpdatePreferences(kPluginUpdateDelayMs); |
| 305 } | 333 } |
| 306 } | 334 } |
| 307 | 335 |
| 308 void PluginPrefs::ShutdownOnUIThread() { | 336 void PluginPrefs::ShutdownOnUIThread() { |
| 309 prefs_ = NULL; | 337 prefs_ = NULL; |
| 310 registrar_.RemoveAll(); | 338 registrar_.RemoveAll(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, | 452 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, |
| 425 internal_dir, | 453 internal_dir, |
| 426 PrefService::UNSYNCABLE_PREF); | 454 PrefService::UNSYNCABLE_PREF); |
| 427 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, | 455 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, |
| 428 PrefService::UNSYNCABLE_PREF); | 456 PrefService::UNSYNCABLE_PREF); |
| 429 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, | 457 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, |
| 430 PrefService::UNSYNCABLE_PREF); | 458 PrefService::UNSYNCABLE_PREF); |
| 431 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, | 459 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, |
| 432 PrefService::UNSYNCABLE_PREF); | 460 PrefService::UNSYNCABLE_PREF); |
| 433 } | 461 } |
| OLD | NEW |