Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/plugins/plugin_prefs.cc

Issue 2474713003: Migrate enabled state of plugins into specialized Flash and PDF prefs. (Closed)
Patch Set: Address comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 PluginMetadata::kAdobeFlashPlayerGroupName));
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
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-enable them all internally.
381 // TODO(http://crbug.com/662006): Remove migration eventually.
382 if (!enabled) {
383 base::string16 name;
384 plugin->GetString("name", &name);
385 if (IsPDFViewerPlugin(name))
386 prefs->SetBoolean(prefs::kPluginsAlwaysOpenPdfExternally, true);
387 if (IsAdobeFlashPlayerPlugin(name)) {
388 HostContentSettingsMapFactory::GetForProfile(profile_)
389 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
390 CONTENT_SETTING_BLOCK);
391 }
392 // TODO(http://crbug.com/662002): Remove the enabled flag completely.
393 enabled = true;
394 plugin->SetBoolean("enabled", true);
395 plugins_migrated = true;
396 }
397
368 base::FilePath::StringType path; 398 base::FilePath::StringType path;
369 // The plugin list constains all the plugin files in addition to the 399 // The plugin list constains all the plugin files in addition to the
370 // plugin groups. 400 // plugin groups.
371 if (plugin->GetString("path", &path)) { 401 if (plugin->GetString("path", &path)) {
372 // Files have a path attribute, groups don't. 402 // Files have a path attribute, groups don't.
373 base::FilePath plugin_path(path); 403 base::FilePath plugin_path(path);
374 404
375 // The path to the internal plugin directory changes everytime Chrome 405 // The path to the internal plugin directory changes everytime Chrome
376 // is auto-updated, since it contains the current version number. For 406 // is auto-updated, since it contains the current version number. For
377 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to 407 // example, it changes from foobar\Chrome\Application\21.0.1180.83 to
(...skipping 27 matching lines...) Expand all
405 // If |relative_path| is empty, |plugin_path| is not within 435 // If |relative_path| is empty, |plugin_path| is not within
406 // |last_internal_dir|. We don't need to update it. 436 // |last_internal_dir|. We don't need to update it.
407 if (!relative_path.empty()) { 437 if (!relative_path.empty()) {
408 plugin_path = cur_internal_dir.Append(relative_path); 438 plugin_path = cur_internal_dir.Append(relative_path);
409 path = plugin_path.value(); 439 path = plugin_path.value();
410 plugin->SetString("path", path); 440 plugin->SetString("path", path);
411 } 441 }
412 } 442 }
413 443
414 plugin_state_.Set(plugin_path, enabled); 444 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 } 445 }
419 } 446 }
420 } else { 447 } else {
421 // If the saved plugin list is empty, then the call to UpdatePreferences() 448 // 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 449 // below failed in an earlier run, possibly because the user closed the
423 // browser too quickly. 450 // browser too quickly.
424 451
425 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105 452 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105
426 // for background. 453 // for background.
427 plugin_group_state_[base::ASCIIToUTF16( 454 plugin_group_state_[base::ASCIIToUTF16(
428 PluginMetadata::kAdobeReaderGroupName)] = false; 455 PluginMetadata::kAdobeReaderGroupName)] = false;
429 } 456 }
430 } // Scoped update of prefs::kPluginsPluginsList. 457 } // Scoped update of prefs::kPluginsPluginsList.
431 458
459 UMA_HISTOGRAM_BOOLEAN("Plugin.EnabledStatusMigrationDone", plugins_migrated);
460
432 // Build the set of policy enabled/disabled plugin patterns once and cache it. 461 // 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. 462 // Don't do this in the constructor, there's no profile available there.
463 // TODO(http://crbug.com/662002): : Remove the prefs completely.
434 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), 464 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins),
435 &policy_disabled_plugin_patterns_); 465 &policy_disabled_plugin_patterns_);
436 ListValueToStringSet( 466 ListValueToStringSet(
437 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), 467 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions),
438 &policy_disabled_plugin_exception_patterns_); 468 &policy_disabled_plugin_exception_patterns_);
439 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), 469 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins),
440 &policy_enabled_plugin_patterns_); 470 &policy_enabled_plugin_patterns_);
441 always_open_pdf_externally_ = 471 always_open_pdf_externally_ =
442 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); 472 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally);
443 473
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 573 }
544 } 574 }
545 575
546 void PluginPrefs::NotifyPluginStatusChanged() { 576 void PluginPrefs::NotifyPluginStatusChanged() {
547 DCHECK_CURRENTLY_ON(BrowserThread::UI); 577 DCHECK_CURRENTLY_ON(BrowserThread::UI);
548 content::NotificationService::current()->Notify( 578 content::NotificationService::current()->Notify(
549 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 579 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
550 content::Source<Profile>(profile_), 580 content::Source<Profile>(profile_),
551 content::NotificationService::NoDetails()); 581 content::NotificationService::NoDetails());
552 } 582 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_policy_handler.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698