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/ui/webui/extensions/extension_settings_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/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 "chrome/browser/background/background_contents.h" | 20 #include "chrome/browser/background/background_contents.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/extensions/error_console/error_console.h" | |
24 #include "chrome/browser/extensions/extension_management.h" | 23 #include "chrome/browser/extensions/extension_management.h" |
25 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
26 #include "chrome/browser/extensions/extension_tab_util.h" | 25 #include "chrome/browser/extensions/extension_tab_util.h" |
27 #include "chrome/browser/extensions/extension_ui_util.h" | 26 #include "chrome/browser/extensions/extension_ui_util.h" |
28 #include "chrome/browser/extensions/install_verifier.h" | 27 #include "chrome/browser/extensions/install_verifier.h" |
29 #include "chrome/browser/extensions/updater/extension_updater.h" | 28 #include "chrome/browser/extensions/updater/extension_updater.h" |
30 #include "chrome/browser/extensions/webstore_reinstaller.h" | 29 #include "chrome/browser/extensions/webstore_reinstaller.h" |
31 #include "chrome/browser/platform_util.h" | 30 #include "chrome/browser/platform_util.h" |
32 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 31 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
33 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 /////////////////////////////////////////////////////////////////////////////// | 91 /////////////////////////////////////////////////////////////////////////////// |
93 | 92 |
94 ExtensionSettingsHandler::ExtensionSettingsHandler() | 93 ExtensionSettingsHandler::ExtensionSettingsHandler() |
95 : extension_service_(NULL), | 94 : extension_service_(NULL), |
96 ignore_notifications_(false), | 95 ignore_notifications_(false), |
97 deleting_rvh_(NULL), | 96 deleting_rvh_(NULL), |
98 deleting_rwh_id_(-1), | 97 deleting_rwh_id_(-1), |
99 deleting_rph_id_(-1), | 98 deleting_rph_id_(-1), |
100 registered_for_notifications_(false), | 99 registered_for_notifications_(false), |
101 warning_service_observer_(this), | 100 warning_service_observer_(this), |
102 error_console_observer_(this), | |
103 extension_prefs_observer_(this), | 101 extension_prefs_observer_(this), |
104 extension_registry_observer_(this), | 102 extension_management_observer_(this) { |
105 extension_management_observer_(this), | |
106 should_do_verification_check_(false) { | |
107 } | 103 } |
108 | 104 |
109 ExtensionSettingsHandler::~ExtensionSettingsHandler() { | 105 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
110 } | 106 } |
111 | 107 |
112 // static | 108 // static |
113 void ExtensionSettingsHandler::RegisterProfilePrefs( | 109 void ExtensionSettingsHandler::RegisterProfilePrefs( |
114 user_prefs::PrefRegistrySyncable* registry) { | 110 user_prefs::PrefRegistrySyncable* registry) { |
115 registry->RegisterBooleanPref( | 111 registry->RegisterBooleanPref( |
116 prefs::kExtensionsUIDeveloperMode, | 112 prefs::kExtensionsUIDeveloperMode, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, | 357 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, |
362 AsWeakPtr())); | 358 AsWeakPtr())); |
363 web_ui()->RegisterMessageCallback("extensionSettingsDismissADTPromo", | 359 web_ui()->RegisterMessageCallback("extensionSettingsDismissADTPromo", |
364 base::Bind(&ExtensionSettingsHandler::HandleDismissADTPromoMessage, | 360 base::Bind(&ExtensionSettingsHandler::HandleDismissADTPromoMessage, |
365 AsWeakPtr())); | 361 AsWeakPtr())); |
366 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", | 362 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", |
367 base::Bind(&ExtensionSettingsHandler::HandleShowPath, | 363 base::Bind(&ExtensionSettingsHandler::HandleShowPath, |
368 AsWeakPtr())); | 364 AsWeakPtr())); |
369 } | 365 } |
370 | 366 |
371 void ExtensionSettingsHandler::OnErrorAdded(const ExtensionError* error) { | |
372 MaybeUpdateAfterNotification(); | |
373 } | |
374 | |
375 void ExtensionSettingsHandler::Observe( | 367 void ExtensionSettingsHandler::Observe( |
376 int type, | 368 int type, |
377 const content::NotificationSource& source, | 369 const content::NotificationSource& source, |
378 const content::NotificationDetails& details) { | 370 const content::NotificationDetails& details) { |
379 Profile* profile = Profile::FromWebUI(web_ui()); | 371 Profile* profile = Profile::FromWebUI(web_ui()); |
380 Profile* source_profile = NULL; | 372 Profile* source_profile = NULL; |
381 switch (type) { | 373 switch (type) { |
382 // We listen for notifications that will result in the page being | 374 // We listen for notifications that will result in the page being |
383 // repopulated with data twice for the same event in certain cases. | 375 // repopulated with data twice for the same event in certain cases. |
384 // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because | 376 // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 base::MessageLoop::current()->PostTask( | 410 base::MessageLoop::current()->PostTask( |
419 FROM_HERE, | 411 FROM_HERE, |
420 base::Bind(&ExtensionSettingsHandler::MaybeUpdateAfterNotification, | 412 base::Bind(&ExtensionSettingsHandler::MaybeUpdateAfterNotification, |
421 AsWeakPtr())); | 413 AsWeakPtr())); |
422 break; | 414 break; |
423 default: | 415 default: |
424 NOTREACHED(); | 416 NOTREACHED(); |
425 } | 417 } |
426 } | 418 } |
427 | 419 |
428 void ExtensionSettingsHandler::OnExtensionLoaded( | |
429 content::BrowserContext* browser_context, | |
430 const Extension* extension) { | |
431 MaybeUpdateAfterNotification(); | |
432 } | |
433 | |
434 void ExtensionSettingsHandler::OnExtensionUnloaded( | |
435 content::BrowserContext* browser_context, | |
436 const Extension* extension, | |
437 UnloadedExtensionInfo::Reason reason) { | |
438 MaybeUpdateAfterNotification(); | |
439 } | |
440 | |
441 void ExtensionSettingsHandler::OnExtensionUninstalled( | |
442 content::BrowserContext* browser_context, | |
443 const Extension* extension, | |
444 extensions::UninstallReason reason) { | |
445 MaybeUpdateAfterNotification(); | |
446 } | |
447 | |
448 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( | 420 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( |
449 const std::string& extension_id, int disable_reasons) { | 421 const std::string& extension_id, int disable_reasons) { |
450 MaybeUpdateAfterNotification(); | 422 MaybeUpdateAfterNotification(); |
451 } | 423 } |
452 | 424 |
453 void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() { | 425 void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() { |
454 MaybeUpdateAfterNotification(); | 426 MaybeUpdateAfterNotification(); |
455 } | 427 } |
456 | 428 |
457 void ExtensionSettingsHandler::ExtensionWarningsChanged() { | 429 void ExtensionSettingsHandler::ExtensionWarningsChanged() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 bool developer_mode = | 463 bool developer_mode = |
492 !is_supervised && | 464 !is_supervised && |
493 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 465 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
494 results.SetBoolean("profileIsSupervised", is_supervised); | 466 results.SetBoolean("profileIsSupervised", is_supervised); |
495 results.SetBoolean("incognitoAvailable", incognito_available); | 467 results.SetBoolean("incognitoAvailable", incognito_available); |
496 results.SetBoolean("developerMode", developer_mode); | 468 results.SetBoolean("developerMode", developer_mode); |
497 results.SetBoolean("enableAppInfoDialog", CanShowAppInfoDialog()); | 469 results.SetBoolean("enableAppInfoDialog", CanShowAppInfoDialog()); |
498 | 470 |
499 // Promote the Chrome Apps & Extensions Developer Tools if they are not | 471 // Promote the Chrome Apps & Extensions Developer Tools if they are not |
500 // installed and the user has not previously dismissed the warning. | 472 // installed and the user has not previously dismissed the warning. |
| 473 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
501 bool promote_apps_dev_tools = false; | 474 bool promote_apps_dev_tools = false; |
502 if (!ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))-> | 475 if (!registry->GetExtensionById(kAppsDeveloperToolsExtensionId, |
503 GetExtensionById(kAppsDeveloperToolsExtensionId, | 476 ExtensionRegistry::EVERYTHING) && |
504 ExtensionRegistry::EVERYTHING) && | |
505 !profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDismissedADTPromo)) { | 477 !profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDismissedADTPromo)) { |
506 promote_apps_dev_tools = true; | 478 promote_apps_dev_tools = true; |
507 } | 479 } |
508 results.SetBoolean("promoteAppsDevTools", promote_apps_dev_tools); | 480 results.SetBoolean("promoteAppsDevTools", promote_apps_dev_tools); |
509 | 481 |
510 const bool load_unpacked_disabled = | 482 const bool load_unpacked_disabled = |
511 ExtensionManagementFactory::GetForBrowserContext(profile) | 483 ExtensionManagementFactory::GetForBrowserContext(profile) |
512 ->BlacklistedByDefault(); | 484 ->BlacklistedByDefault(); |
513 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); | 485 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); |
514 | 486 |
515 web_ui()->CallJavascriptFunction( | 487 web_ui()->CallJavascriptFunction( |
516 "extensions.ExtensionSettings.returnExtensionsData", results); | 488 "extensions.ExtensionSettings.returnExtensionsData", results); |
517 | 489 |
518 MaybeRegisterForNotifications(); | 490 MaybeRegisterForNotifications(); |
| 491 |
| 492 scoped_ptr<ExtensionSet> extensions = |
| 493 registry->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED | |
| 494 ExtensionRegistry::DISABLED | |
| 495 ExtensionRegistry::TERMINATED); |
| 496 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); |
| 497 bool should_do_verification_check = false; |
| 498 for (const scoped_refptr<const Extension>& extension : *extensions) { |
| 499 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), profile) && |
| 500 ((prefs->GetDisableReasons(extension->id()) & |
| 501 Extension::DISABLE_NOT_VERIFIED) != 0)) { |
| 502 should_do_verification_check = true; |
| 503 break; |
| 504 } |
| 505 } |
| 506 |
519 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", | 507 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", |
520 should_do_verification_check_); | 508 should_do_verification_check); |
521 if (should_do_verification_check_) { | 509 if (should_do_verification_check) |
522 should_do_verification_check_ = false; | 510 ExtensionSystem::Get(profile)->install_verifier()->VerifyAllExtensions(); |
523 ExtensionSystem::Get(Profile::FromWebUI(web_ui())) | |
524 ->install_verifier() | |
525 ->VerifyAllExtensions(); | |
526 } | |
527 } | 511 } |
528 | 512 |
529 void ExtensionSettingsHandler::HandleToggleDeveloperMode( | 513 void ExtensionSettingsHandler::HandleToggleDeveloperMode( |
530 const base::ListValue* args) { | 514 const base::ListValue* args) { |
531 Profile* profile = Profile::FromWebUI(web_ui()); | 515 Profile* profile = Profile::FromWebUI(web_ui()); |
532 if (profile->IsSupervised()) | 516 if (profile->IsSupervised()) |
533 return; | 517 return; |
534 | 518 |
535 bool developer_mode_on; | 519 bool developer_mode_on; |
536 CHECK(args->GetBoolean(0, &developer_mode_on)); | 520 CHECK(args->GetBoolean(0, &developer_mode_on)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 this, | 627 this, |
644 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 628 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
645 content::Source<ExtensionPrefs>(ExtensionPrefs::Get(profile))); | 629 content::Source<ExtensionPrefs>(ExtensionPrefs::Get(profile))); |
646 registrar_.Add(this, | 630 registrar_.Add(this, |
647 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 631 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
648 content::NotificationService::AllBrowserContextsAndSources()); | 632 content::NotificationService::AllBrowserContextsAndSources()); |
649 registrar_.Add(this, | 633 registrar_.Add(this, |
650 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 634 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
651 content::NotificationService::AllBrowserContextsAndSources()); | 635 content::NotificationService::AllBrowserContextsAndSources()); |
652 | 636 |
653 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); | |
654 | |
655 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); | 637 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); |
656 | 638 |
657 warning_service_observer_.Add(WarningService::Get(profile)); | 639 warning_service_observer_.Add(WarningService::Get(profile)); |
658 | 640 |
659 error_console_observer_.Add(ErrorConsole::Get(profile)); | |
660 | |
661 extension_management_observer_.Add( | 641 extension_management_observer_.Add( |
662 ExtensionManagementFactory::GetForBrowserContext(profile)); | 642 ExtensionManagementFactory::GetForBrowserContext(profile)); |
663 } | 643 } |
664 | 644 |
665 void ExtensionSettingsHandler::OnReinstallComplete( | 645 void ExtensionSettingsHandler::OnReinstallComplete( |
666 bool success, | 646 bool success, |
667 const std::string& error, | 647 const std::string& error, |
668 webstore_install::Result result) { | 648 webstore_install::Result result) { |
669 MaybeUpdateAfterNotification(); | 649 MaybeUpdateAfterNotification(); |
670 } | 650 } |
671 | 651 |
672 } // namespace extensions | 652 } // namespace extensions |
OLD | NEW |