Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/metrics/histogram_macros.h" | |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/pattern.h" | 19 #include "base/strings/pattern.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/values.h" | 23 #include "base/values.h" |
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 26 #include "chrome/browser/plugins/plugin_installer.h" | 28 #include "chrome/browser/plugins/plugin_installer.h" |
| 27 #include "chrome/browser/plugins/plugin_metadata.h" | 29 #include "chrome/browser/plugins/plugin_metadata.h" |
| 28 #include "chrome/browser/plugins/plugin_prefs_factory.h" | 30 #include "chrome/browser/plugins/plugin_prefs_factory.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_content_client.h" | 33 #include "chrome/common/chrome_content_client.h" |
| 32 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
| 33 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 38 #include "components/content_settings/core/common/content_settings.h" | |
| 39 #include "components/content_settings/core/common/pref_names.h" | |
| 35 #include "components/keyed_service/core/keyed_service.h" | 40 #include "components/keyed_service/core/keyed_service.h" |
| 36 #include "components/prefs/scoped_user_pref_update.h" | 41 #include "components/prefs/scoped_user_pref_update.h" |
| 37 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/plugin_service.h" | 44 #include "content/public/browser/plugin_service.h" |
| 45 #include "content/public/common/content_constants.h" | |
| 40 #include "content/public/common/webplugininfo.h" | 46 #include "content/public/common/webplugininfo.h" |
| 41 | 47 |
| 42 #if !defined(DISABLE_NACL) | 48 #if !defined(DISABLE_NACL) |
| 43 #include "components/nacl/common/nacl_constants.h" | 49 #include "components/nacl/common/nacl_constants.h" |
| 44 #endif | 50 #endif |
| 45 | 51 |
| 46 using content::BrowserThread; | 52 using content::BrowserThread; |
| 47 using content::PluginService; | 53 using content::PluginService; |
| 48 | 54 |
| 49 namespace { | 55 namespace { |
| 50 | 56 |
| 51 bool IsComponentUpdatedPepperFlash(const base::FilePath& plugin) { | 57 bool IsComponentUpdatedPepperFlash(const base::FilePath& plugin) { |
| 52 if (plugin.BaseName().value() == chrome::kPepperFlashPluginFilename) { | 58 if (plugin.BaseName().value() == chrome::kPepperFlashPluginFilename) { |
| 53 base::FilePath component_updated_pepper_flash_dir; | 59 base::FilePath component_updated_pepper_flash_dir; |
| 54 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | 60 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
| 55 &component_updated_pepper_flash_dir) && | 61 &component_updated_pepper_flash_dir) && |
| 56 component_updated_pepper_flash_dir.IsParent(plugin)) { | 62 component_updated_pepper_flash_dir.IsParent(plugin)) { |
| 57 return true; | 63 return true; |
| 58 } | 64 } |
| 59 } | 65 } |
| 60 | 66 |
| 61 return false; | 67 return false; |
| 62 } | 68 } |
| 63 | 69 |
| 64 bool IsPDFViewerPlugin(const base::string16& plugin_name) { | 70 bool IsPDFViewerPlugin(const base::string16& plugin_name) { |
| 65 return plugin_name == base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); | 71 return plugin_name == base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); |
| 66 } | 72 } |
| 67 | 73 |
| 74 bool IsAdobeFlashPlayerPlugin(const base::string16& plugin_name) { | |
| 75 return (plugin_name == base::ASCIIToUTF16(content::kFlashPluginName) || | |
| 76 plugin_name == base::ASCIIToUTF16("Adobe Flash Player")); | |
|
Bernhard Bauer
2016/11/11 12:15:24
Would it make sense to move this to a constant in
pastarmovj
2016/11/14 13:58:00
Done.
| |
| 77 } | |
| 78 | |
| 68 } // namespace | 79 } // namespace |
| 69 | 80 |
| 70 PluginPrefs::PluginState::PluginState() { | 81 PluginPrefs::PluginState::PluginState() { |
| 71 } | 82 } |
| 72 | 83 |
| 73 PluginPrefs::PluginState::~PluginState() { | 84 PluginPrefs::PluginState::~PluginState() { |
| 74 } | 85 } |
| 75 | 86 |
| 76 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, | 87 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, |
| 77 bool* enabled) const { | 88 bool* enabled) const { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 base::string16 plugin_name; | 343 base::string16 plugin_name; |
| 333 if ((*current)->GetAsString(&plugin_name)) { | 344 if ((*current)->GetAsString(&plugin_name)) { |
| 334 dest->insert(plugin_name); | 345 dest->insert(plugin_name); |
| 335 } | 346 } |
| 336 } | 347 } |
| 337 } | 348 } |
| 338 | 349 |
| 339 void PluginPrefs::SetPrefs(PrefService* prefs) { | 350 void PluginPrefs::SetPrefs(PrefService* prefs) { |
| 340 prefs_ = prefs; | 351 prefs_ = prefs; |
| 341 bool update_internal_dir = false; | 352 bool update_internal_dir = false; |
| 353 bool plugins_migrated = false; | |
| 342 base::FilePath last_internal_dir = | 354 base::FilePath last_internal_dir = |
| 343 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); | 355 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); |
| 344 base::FilePath cur_internal_dir; | 356 base::FilePath cur_internal_dir; |
| 345 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && | 357 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
| 346 cur_internal_dir != last_internal_dir) { | 358 cur_internal_dir != last_internal_dir) { |
| 347 update_internal_dir = true; | 359 update_internal_dir = true; |
| 348 prefs_->SetFilePath( | 360 prefs_->SetFilePath( |
| 349 prefs::kPluginsLastInternalDirectory, cur_internal_dir); | 361 prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
| 350 } | 362 } |
| 351 | 363 |
| 352 { // Scoped update of prefs::kPluginsPluginsList. | 364 { // Scoped update of prefs::kPluginsPluginsList. |
| 353 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 365 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
| 354 base::ListValue* saved_plugins_list = update.Get(); | 366 base::ListValue* saved_plugins_list = update.Get(); |
| 355 if (saved_plugins_list && !saved_plugins_list->empty()) { | 367 if (saved_plugins_list && !saved_plugins_list->empty()) { |
| 356 for (const auto& plugin_value : *saved_plugins_list) { | 368 for (const auto& plugin_value : *saved_plugins_list) { |
| 357 base::DictionaryValue* plugin; | 369 base::DictionaryValue* plugin; |
| 358 if (!plugin_value->GetAsDictionary(&plugin)) { | 370 if (!plugin_value->GetAsDictionary(&plugin)) { |
| 359 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 371 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 360 continue; // Oops, don't know what to do with this item. | 372 continue; // Oops, don't know what to do with this item. |
| 361 } | 373 } |
| 362 | 374 |
| 363 base::string16 group_name; | 375 base::string16 name; |
| 376 if (!plugin->GetString("name", &name)) { | |
| 377 // This should not happen in the post NPAPI world. I remember that my | |
| 378 // initial assumption was the same about NPAPI plugins back then and | |
| 379 // and then was bitterly surprised when my change hit the canary and | |
| 380 // not handling well the empty names became a top crasher. Not so bad | |
| 381 // this time but we'd rather not CHECK on that. | |
|
Bernhard Bauer
2016/11/11 12:15:24
Couple of things:
1) This explanation seems a bit
pastarmovj
2016/11/14 13:58:00
Restructued this code. It doesn't matter anymore j
| |
| 382 LOG(WARNING) << "Nameless plugin detected in the post-NPAPI world?!"; | |
| 383 } | |
| 384 | |
| 364 bool enabled; | 385 bool enabled; |
| 365 if (!plugin->GetBoolean("enabled", &enabled)) | 386 if (!plugin->GetBoolean("enabled", &enabled)) |
| 366 enabled = true; | 387 enabled = true; |
| 367 | 388 |
| 389 // Migrate disabled plugins and re-enabled them all internally. | |
| 390 // TODO(pastarmovj): crbug/662006: Remove migration eventually. | |
|
Bernhard Bauer
2016/11/11 12:15:24
Nit: For ideal clickability, use a full URL: https
pastarmovj
2016/11/14 13:58:00
Was trying to save a line :) changed.
Bernhard Bauer
2016/11/14 14:35:38
Gotcha. FWIW, TODO(https://crbug.com/662006) is al
| |
| 391 if (!enabled) { | |
| 392 if (IsPDFViewerPlugin(name)) | |
| 393 prefs->SetBoolean(prefs::kPluginsAlwaysOpenPdfExternally, true); | |
| 394 if (IsAdobeFlashPlayerPlugin(name)) { | |
| 395 HostContentSettingsMapFactory::GetForProfile(profile_) | |
| 396 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 397 CONTENT_SETTING_BLOCK); | |
| 398 } | |
| 399 // TODO(pastarmovj): crbug/662002: Remove the enabled flag completely. | |
| 400 enabled = true; | |
| 401 plugin->SetBoolean("enabled", true); | |
| 402 plugins_migrated = true; | |
|
Bernhard Bauer
2016/11/11 12:15:24
So, this would set the flag even if the migrated p
pastarmovj
2016/11/14 13:58:00
Yes. I want to know that any plugin was user-disab
| |
| 403 } | |
| 404 | |
| 368 base::FilePath::StringType path; | 405 base::FilePath::StringType path; |
| 369 // The plugin list constains all the plugin files in addition to the | 406 // The plugin list constains all the plugin files in addition to the |
| 370 // plugin groups. | 407 // plugin groups. |
| 371 if (plugin->GetString("path", &path)) { | 408 if (plugin->GetString("path", &path)) { |
| 372 // Files have a path attribute, groups don't. | 409 // Files have a path attribute, groups don't. |
| 373 base::FilePath plugin_path(path); | 410 base::FilePath plugin_path(path); |
| 374 | 411 |
| 375 // The path to the internal plugin directory changes everytime Chrome | 412 // The path to the internal plugin directory changes everytime Chrome |
| 376 // is auto-updated, since it contains the current version number. For | 413 // is auto-updated, since it contains the current version number. For |
| 377 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to | 414 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 404 | 441 |
| 405 // If |relative_path| is empty, |plugin_path| is not within | 442 // If |relative_path| is empty, |plugin_path| is not within |
| 406 // |last_internal_dir|. We don't need to update it. | 443 // |last_internal_dir|. We don't need to update it. |
| 407 if (!relative_path.empty()) { | 444 if (!relative_path.empty()) { |
| 408 plugin_path = cur_internal_dir.Append(relative_path); | 445 plugin_path = cur_internal_dir.Append(relative_path); |
| 409 path = plugin_path.value(); | 446 path = plugin_path.value(); |
| 410 plugin->SetString("path", path); | 447 plugin->SetString("path", path); |
| 411 } | 448 } |
| 412 } | 449 } |
| 413 | 450 |
| 414 plugin_state_.Set(plugin_path, enabled); | 451 plugin_state_.Set(plugin_path, enabled); |
|
Bernhard Bauer
2016/11/11 12:15:24
So, if we enable all plugins anyway, why do we eve
pastarmovj
2016/11/14 13:58:00
Not anymore but untangling this is going to make t
| |
| 415 } else if (!enabled && plugin->GetString("name", &group_name)) { | |
| 416 // Otherwise this is a list of groups. | |
| 417 plugin_group_state_[group_name] = false; | |
| 418 } | 452 } |
| 419 } | 453 } |
| 420 } else { | 454 } else { |
| 421 // If the saved plugin list is empty, then the call to UpdatePreferences() | 455 // If the saved plugin list is empty, then the call to UpdatePreferences() |
| 422 // below failed in an earlier run, possibly because the user closed the | 456 // below failed in an earlier run, possibly because the user closed the |
| 423 // browser too quickly. | 457 // browser too quickly. |
| 424 | 458 |
| 425 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 | 459 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 |
| 426 // for background. | 460 // for background. |
| 427 plugin_group_state_[base::ASCIIToUTF16( | 461 plugin_group_state_[base::ASCIIToUTF16( |
| 428 PluginMetadata::kAdobeReaderGroupName)] = false; | 462 PluginMetadata::kAdobeReaderGroupName)] = false; |
| 429 } | 463 } |
| 430 } // Scoped update of prefs::kPluginsPluginsList. | 464 } // Scoped update of prefs::kPluginsPluginsList. |
| 431 | 465 |
| 466 UMA_HISTOGRAM_BOOLEAN("Plugin.EnabledStatusMigrationDone", plugins_migrated); | |
| 467 | |
| 432 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 468 // Build the set of policy enabled/disabled plugin patterns once and cache it. |
| 433 // Don't do this in the constructor, there's no profile available there. | 469 // Don't do this in the constructor, there's no profile available there. |
| 470 // TODO(pastarmovj): crbug/662002: Remove the prefs completely. | |
| 434 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), | 471 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), |
| 435 &policy_disabled_plugin_patterns_); | 472 &policy_disabled_plugin_patterns_); |
| 436 ListValueToStringSet( | 473 ListValueToStringSet( |
| 437 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), | 474 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), |
| 438 &policy_disabled_plugin_exception_patterns_); | 475 &policy_disabled_plugin_exception_patterns_); |
| 439 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), | 476 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), |
| 440 &policy_enabled_plugin_patterns_); | 477 &policy_enabled_plugin_patterns_); |
| 441 always_open_pdf_externally_ = | 478 always_open_pdf_externally_ = |
| 442 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); | 479 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); |
| 443 | 480 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 } | 580 } |
| 544 } | 581 } |
| 545 | 582 |
| 546 void PluginPrefs::NotifyPluginStatusChanged() { | 583 void PluginPrefs::NotifyPluginStatusChanged() { |
| 547 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 584 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 548 content::NotificationService::current()->Notify( | 585 content::NotificationService::current()->Notify( |
| 549 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 586 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 550 content::Source<Profile>(profile_), | 587 content::Source<Profile>(profile_), |
| 551 content::NotificationService::NoDetails()); | 588 content::NotificationService::NoDetails()); |
| 552 } | 589 } |
| OLD | NEW |