| 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/plugin_prefs.h" | 5 #include "chrome/browser/plugin_prefs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "base/version.h" | 19 #include "base/version.h" |
| 20 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/plugin_installer.h" | 22 #include "chrome/browser/plugin_installer.h" |
| 22 #include "chrome/browser/plugin_prefs_factory.h" | 23 #include "chrome/browser/plugin_prefs_factory.h" |
| 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 24 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_keyed_service.h" | 26 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/common/chrome_content_client.h" | 28 #include "chrome/common/chrome_content_client.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 PathService::Get(chrome::FILE_NACL_PLUGIN, &nacl_path); | 400 PathService::Get(chrome::FILE_NACL_PLUGIN, &nacl_path); |
| 400 FilePath::StringType nacl_path_str = nacl_path.value(); | 401 FilePath::StringType nacl_path_str = nacl_path.value(); |
| 401 if (!prefs_->GetBoolean(prefs::kPluginsEnabledNaCl)) { | 402 if (!prefs_->GetBoolean(prefs::kPluginsEnabledNaCl)) { |
| 402 // We switched to the nacl plugin being on by default, and so we need to | 403 // We switched to the nacl plugin being on by default, and so we need to |
| 403 // force it to be enabled. We only want to do it this once though, i.e. | 404 // force it to be enabled. We only want to do it this once though, i.e. |
| 404 // we don't want to enable it again if the user disables it afterwards. | 405 // we don't want to enable it again if the user disables it afterwards. |
| 405 prefs_->SetBoolean(prefs::kPluginsEnabledNaCl, true); | 406 prefs_->SetBoolean(prefs::kPluginsEnabledNaCl, true); |
| 406 force_enable_nacl = true; | 407 force_enable_nacl = true; |
| 407 } | 408 } |
| 408 | 409 |
| 410 bool migrate_to_pepper_flash = false; |
| 411 #if defined(OS_WIN) |
| 412 // If bundled NPAPI Flash is enabled while Peppper Flash is disabled, we |
| 413 // would like to turn Pepper Flash on. And we only want to do it once. |
| 414 // TODO(yzshen): Remove all |migrate_to_pepper_flash|-related code after it |
| 415 // has been run once by most users. (Maybe Chrome 24 or Chrome 25.) |
| 416 if (!prefs_->GetBoolean(prefs::kPluginsMigratedToPepperFlash)) { |
| 417 prefs_->SetBoolean(prefs::kPluginsMigratedToPepperFlash, true); |
| 418 migrate_to_pepper_flash = true; |
| 419 } |
| 420 #endif |
| 421 |
| 409 { // Scoped update of prefs::kPluginsPluginsList. | 422 { // Scoped update of prefs::kPluginsPluginsList. |
| 410 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 423 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
| 411 ListValue* saved_plugins_list = update.Get(); | 424 ListValue* saved_plugins_list = update.Get(); |
| 412 if (saved_plugins_list && !saved_plugins_list->empty()) { | 425 if (saved_plugins_list && !saved_plugins_list->empty()) { |
| 426 // The following four variables are only valid when |
| 427 // |migrate_to_pepper_flash| is set to true. |
| 428 FilePath npapi_flash; |
| 429 FilePath pepper_flash; |
| 430 DictionaryValue* pepper_flash_node = NULL; |
| 431 bool npapi_flash_enabled = false; |
| 432 if (migrate_to_pepper_flash) { |
| 433 PathService::Get(chrome::FILE_FLASH_PLUGIN, &npapi_flash); |
| 434 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &pepper_flash); |
| 435 } |
| 436 |
| 413 for (ListValue::const_iterator it = saved_plugins_list->begin(); | 437 for (ListValue::const_iterator it = saved_plugins_list->begin(); |
| 414 it != saved_plugins_list->end(); | 438 it != saved_plugins_list->end(); |
| 415 ++it) { | 439 ++it) { |
| 416 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { | 440 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { |
| 417 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 441 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 418 continue; // Oops, don't know what to do with this item. | 442 continue; // Oops, don't know what to do with this item. |
| 419 } | 443 } |
| 420 | 444 |
| 421 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it); | 445 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it); |
| 422 string16 group_name; | 446 string16 group_name; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 445 enabled = true; | 469 enabled = true; |
| 446 plugin->SetBoolean("enabled", true); | 470 plugin->SetBoolean("enabled", true); |
| 447 } | 471 } |
| 448 | 472 |
| 449 internal_pdf_enabled = enabled; | 473 internal_pdf_enabled = enabled; |
| 450 } else if (FilePath::CompareIgnoreCase(path, nacl_path_str) == 0) { | 474 } else if (FilePath::CompareIgnoreCase(path, nacl_path_str) == 0) { |
| 451 if (!enabled && force_enable_nacl) { | 475 if (!enabled && force_enable_nacl) { |
| 452 enabled = true; | 476 enabled = true; |
| 453 plugin->SetBoolean("enabled", true); | 477 plugin->SetBoolean("enabled", true); |
| 454 } | 478 } |
| 479 } else if (migrate_to_pepper_flash && |
| 480 FilePath::CompareEqualIgnoreCase(path, npapi_flash.value())) { |
| 481 npapi_flash_enabled = enabled; |
| 482 } else if (migrate_to_pepper_flash && |
| 483 FilePath::CompareEqualIgnoreCase(path, pepper_flash.value())) { |
| 484 if (!enabled) |
| 485 pepper_flash_node = plugin; |
| 455 } | 486 } |
| 456 | 487 |
| 457 plugin_state_[plugin_path] = enabled; | 488 plugin_state_[plugin_path] = enabled; |
| 458 } else if (!enabled && plugin->GetString("name", &group_name)) { | 489 } else if (!enabled && plugin->GetString("name", &group_name)) { |
| 459 // Don't disable this group if it's for the pdf or nacl plugins and | 490 // Don't disable this group if it's for the pdf or nacl plugins and |
| 460 // we just forced it on. | 491 // we just forced it on. |
| 461 if (force_enable_internal_pdf && pdf_group_name == group_name) | 492 if (force_enable_internal_pdf && pdf_group_name == group_name) |
| 462 continue; | 493 continue; |
| 463 if (force_enable_nacl && (nacl_group_name == group_name || | 494 if (force_enable_nacl && (nacl_group_name == group_name || |
| 464 old_nacl_group_name == group_name)) | 495 old_nacl_group_name == group_name)) |
| 465 continue; | 496 continue; |
| 466 | 497 |
| 467 // Otherwise this is a list of groups. | 498 // Otherwise this is a list of groups. |
| 468 plugin_group_state_[group_name] = false; | 499 plugin_group_state_[group_name] = false; |
| 469 } | 500 } |
| 470 } | 501 } |
| 502 |
| 503 if (npapi_flash_enabled && pepper_flash_node) { |
| 504 DCHECK(migrate_to_pepper_flash); |
| 505 pepper_flash_node->SetBoolean("enabled", true); |
| 506 plugin_state_[pepper_flash] = true; |
| 507 } |
| 471 } else { | 508 } else { |
| 472 // If the saved plugin list is empty, then the call to UpdatePreferences() | 509 // If the saved plugin list is empty, then the call to UpdatePreferences() |
| 473 // below failed in an earlier run, possibly because the user closed the | 510 // below failed in an earlier run, possibly because the user closed the |
| 474 // browser too quickly. Try to force enable the internal PDF and nacl | 511 // browser too quickly. Try to force enable the internal PDF and nacl |
| 475 // plugins again. | 512 // plugins again. |
| 476 force_enable_internal_pdf = true; | 513 force_enable_internal_pdf = true; |
| 477 force_enable_nacl = true; | 514 force_enable_nacl = true; |
| 478 } | 515 } |
| 479 } // Scoped update of prefs::kPluginsPluginsList. | 516 } // Scoped update of prefs::kPluginsPluginsList. |
| 480 | 517 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 } | 645 } |
| 609 } | 646 } |
| 610 | 647 |
| 611 void PluginPrefs::NotifyPluginStatusChanged() { | 648 void PluginPrefs::NotifyPluginStatusChanged() { |
| 612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 613 content::NotificationService::current()->Notify( | 650 content::NotificationService::current()->Notify( |
| 614 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 651 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 615 content::Source<Profile>(profile_), | 652 content::Source<Profile>(profile_), |
| 616 content::NotificationService::NoDetails()); | 653 content::NotificationService::NoDetails()); |
| 617 } | 654 } |
| OLD | NEW |