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( | |
77 content::kAdobeFlashPlayerPluginName)); | |
78 } | |
79 | |
68 } // namespace | 80 } // namespace |
69 | 81 |
70 PluginPrefs::PluginState::PluginState() { | 82 PluginPrefs::PluginState::PluginState() { |
71 } | 83 } |
72 | 84 |
73 PluginPrefs::PluginState::~PluginState() { | 85 PluginPrefs::PluginState::~PluginState() { |
74 } | 86 } |
75 | 87 |
76 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, | 88 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, |
77 bool* enabled) const { | 89 bool* enabled) const { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 base::string16 plugin_name; | 344 base::string16 plugin_name; |
333 if ((*current)->GetAsString(&plugin_name)) { | 345 if ((*current)->GetAsString(&plugin_name)) { |
334 dest->insert(plugin_name); | 346 dest->insert(plugin_name); |
335 } | 347 } |
336 } | 348 } |
337 } | 349 } |
338 | 350 |
339 void PluginPrefs::SetPrefs(PrefService* prefs) { | 351 void PluginPrefs::SetPrefs(PrefService* prefs) { |
340 prefs_ = prefs; | 352 prefs_ = prefs; |
341 bool update_internal_dir = false; | 353 bool update_internal_dir = false; |
354 bool plugins_migrated = false; | |
342 base::FilePath last_internal_dir = | 355 base::FilePath last_internal_dir = |
343 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); | 356 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); |
344 base::FilePath cur_internal_dir; | 357 base::FilePath cur_internal_dir; |
345 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && | 358 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
346 cur_internal_dir != last_internal_dir) { | 359 cur_internal_dir != last_internal_dir) { |
347 update_internal_dir = true; | 360 update_internal_dir = true; |
348 prefs_->SetFilePath( | 361 prefs_->SetFilePath( |
349 prefs::kPluginsLastInternalDirectory, cur_internal_dir); | 362 prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
350 } | 363 } |
351 | 364 |
352 { // Scoped update of prefs::kPluginsPluginsList. | 365 { // Scoped update of prefs::kPluginsPluginsList. |
353 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 366 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
354 base::ListValue* saved_plugins_list = update.Get(); | 367 base::ListValue* saved_plugins_list = update.Get(); |
355 if (saved_plugins_list && !saved_plugins_list->empty()) { | 368 if (saved_plugins_list && !saved_plugins_list->empty()) { |
356 for (const auto& plugin_value : *saved_plugins_list) { | 369 for (const auto& plugin_value : *saved_plugins_list) { |
357 base::DictionaryValue* plugin; | 370 base::DictionaryValue* plugin; |
358 if (!plugin_value->GetAsDictionary(&plugin)) { | 371 if (!plugin_value->GetAsDictionary(&plugin)) { |
359 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 372 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
360 continue; // Oops, don't know what to do with this item. | 373 continue; // Oops, don't know what to do with this item. |
361 } | 374 } |
362 | 375 |
363 base::string16 group_name; | |
364 bool enabled; | 376 bool enabled; |
365 if (!plugin->GetBoolean("enabled", &enabled)) | 377 if (!plugin->GetBoolean("enabled", &enabled)) |
366 enabled = true; | 378 enabled = true; |
367 | 379 |
380 // Migrate disabled plugins and re-enabled them all internally. | |
Bernhard Bauer
2016/11/14 14:35:38
Nit: "re-enable".
pastarmovj
2016/11/15 10:09:18
Done.
| |
381 // TODO(pastarmovj): http://crbug.com/662006: Remove migration | |
382 // eventually. | |
383 if (!enabled) { | |
384 base::string16 name; | |
385 if (plugin->GetString("name", &name)) { | |
Bernhard Bauer
2016/11/14 14:35:38
The check is now probably unnecessary as well -- a
pastarmovj
2016/11/15 10:09:18
Done.
| |
386 if (IsPDFViewerPlugin(name)) | |
387 prefs->SetBoolean(prefs::kPluginsAlwaysOpenPdfExternally, true); | |
388 if (IsAdobeFlashPlayerPlugin(name)) { | |
389 HostContentSettingsMapFactory::GetForProfile(profile_) | |
390 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | |
391 CONTENT_SETTING_BLOCK); | |
392 } | |
393 } | |
394 // TODO(pastarmovj): http://crbug.com/662002: Remove the enabled flag | |
395 // completely. | |
396 enabled = true; | |
397 plugin->SetBoolean("enabled", true); | |
398 plugins_migrated = true; | |
399 } | |
400 | |
368 base::FilePath::StringType path; | 401 base::FilePath::StringType path; |
369 // The plugin list constains all the plugin files in addition to the | 402 // The plugin list constains all the plugin files in addition to the |
370 // plugin groups. | 403 // plugin groups. |
371 if (plugin->GetString("path", &path)) { | 404 if (plugin->GetString("path", &path)) { |
372 // Files have a path attribute, groups don't. | 405 // Files have a path attribute, groups don't. |
373 base::FilePath plugin_path(path); | 406 base::FilePath plugin_path(path); |
374 | 407 |
375 // The path to the internal plugin directory changes everytime Chrome | 408 // The path to the internal plugin directory changes everytime Chrome |
376 // is auto-updated, since it contains the current version number. For | 409 // is auto-updated, since it contains the current version number. For |
377 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to | 410 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to |
(...skipping 27 matching lines...) Expand all Loading... | |
405 // If |relative_path| is empty, |plugin_path| is not within | 438 // If |relative_path| is empty, |plugin_path| is not within |
406 // |last_internal_dir|. We don't need to update it. | 439 // |last_internal_dir|. We don't need to update it. |
407 if (!relative_path.empty()) { | 440 if (!relative_path.empty()) { |
408 plugin_path = cur_internal_dir.Append(relative_path); | 441 plugin_path = cur_internal_dir.Append(relative_path); |
409 path = plugin_path.value(); | 442 path = plugin_path.value(); |
410 plugin->SetString("path", path); | 443 plugin->SetString("path", path); |
411 } | 444 } |
412 } | 445 } |
413 | 446 |
414 plugin_state_.Set(plugin_path, enabled); | 447 plugin_state_.Set(plugin_path, enabled); |
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 } | 448 } |
419 } | 449 } |
420 } else { | 450 } else { |
421 // If the saved plugin list is empty, then the call to UpdatePreferences() | 451 // 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 | 452 // below failed in an earlier run, possibly because the user closed the |
423 // browser too quickly. | 453 // browser too quickly. |
424 | 454 |
425 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 | 455 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 |
426 // for background. | 456 // for background. |
427 plugin_group_state_[base::ASCIIToUTF16( | 457 plugin_group_state_[base::ASCIIToUTF16( |
428 PluginMetadata::kAdobeReaderGroupName)] = false; | 458 PluginMetadata::kAdobeReaderGroupName)] = false; |
429 } | 459 } |
430 } // Scoped update of prefs::kPluginsPluginsList. | 460 } // Scoped update of prefs::kPluginsPluginsList. |
431 | 461 |
462 UMA_HISTOGRAM_BOOLEAN("Plugin.EnabledStatusMigrationDone", plugins_migrated); | |
463 | |
432 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 464 // 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. | 465 // Don't do this in the constructor, there's no profile available there. |
466 // TODO(pastarmovj): crbug/662002: Remove the prefs completely. | |
434 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), | 467 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), |
435 &policy_disabled_plugin_patterns_); | 468 &policy_disabled_plugin_patterns_); |
436 ListValueToStringSet( | 469 ListValueToStringSet( |
437 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), | 470 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), |
438 &policy_disabled_plugin_exception_patterns_); | 471 &policy_disabled_plugin_exception_patterns_); |
439 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), | 472 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), |
440 &policy_enabled_plugin_patterns_); | 473 &policy_enabled_plugin_patterns_); |
441 always_open_pdf_externally_ = | 474 always_open_pdf_externally_ = |
442 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); | 475 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); |
443 | 476 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 } | 576 } |
544 } | 577 } |
545 | 578 |
546 void PluginPrefs::NotifyPluginStatusChanged() { | 579 void PluginPrefs::NotifyPluginStatusChanged() { |
547 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 580 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
548 content::NotificationService::current()->Notify( | 581 content::NotificationService::current()->Notify( |
549 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 582 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
550 content::Source<Profile>(profile_), | 583 content::Source<Profile>(profile_), |
551 content::NotificationService::NoDetails()); | 584 content::NotificationService::NoDetails()); |
552 } | 585 } |
OLD | NEW |