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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_settings_handler.cc

Issue 1049483003: [Extensions] Update extensions UI to observe events and add test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months 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/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
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),
105 extension_management_observer_(this) { 102 extension_management_observer_(this) {
106 } 103 }
107 104
108 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 105 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
109 } 106 }
110 107
111 // static 108 // static
112 void ExtensionSettingsHandler::RegisterProfilePrefs( 109 void ExtensionSettingsHandler::RegisterProfilePrefs(
113 user_prefs::PrefRegistrySyncable* registry) { 110 user_prefs::PrefRegistrySyncable* registry) {
114 registry->RegisterBooleanPref( 111 registry->RegisterBooleanPref(
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, 357 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage,
361 AsWeakPtr())); 358 AsWeakPtr()));
362 web_ui()->RegisterMessageCallback("extensionSettingsDismissADTPromo", 359 web_ui()->RegisterMessageCallback("extensionSettingsDismissADTPromo",
363 base::Bind(&ExtensionSettingsHandler::HandleDismissADTPromoMessage, 360 base::Bind(&ExtensionSettingsHandler::HandleDismissADTPromoMessage,
364 AsWeakPtr())); 361 AsWeakPtr()));
365 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", 362 web_ui()->RegisterMessageCallback("extensionSettingsShowPath",
366 base::Bind(&ExtensionSettingsHandler::HandleShowPath, 363 base::Bind(&ExtensionSettingsHandler::HandleShowPath,
367 AsWeakPtr())); 364 AsWeakPtr()));
368 } 365 }
369 366
370 void ExtensionSettingsHandler::OnErrorAdded(const ExtensionError* error) {
371 MaybeUpdateAfterNotification();
372 }
373
374 void ExtensionSettingsHandler::Observe( 367 void ExtensionSettingsHandler::Observe(
375 int type, 368 int type,
376 const content::NotificationSource& source, 369 const content::NotificationSource& source,
377 const content::NotificationDetails& details) { 370 const content::NotificationDetails& details) {
378 Profile* profile = Profile::FromWebUI(web_ui()); 371 Profile* profile = Profile::FromWebUI(web_ui());
379 Profile* source_profile = NULL; 372 Profile* source_profile = NULL;
380 switch (type) { 373 switch (type) {
381 // We listen for notifications that will result in the page being 374 // We listen for notifications that will result in the page being
382 // repopulated with data twice for the same event in certain cases. 375 // repopulated with data twice for the same event in certain cases.
383 // 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
417 base::MessageLoop::current()->PostTask( 410 base::MessageLoop::current()->PostTask(
418 FROM_HERE, 411 FROM_HERE,
419 base::Bind(&ExtensionSettingsHandler::MaybeUpdateAfterNotification, 412 base::Bind(&ExtensionSettingsHandler::MaybeUpdateAfterNotification,
420 AsWeakPtr())); 413 AsWeakPtr()));
421 break; 414 break;
422 default: 415 default:
423 NOTREACHED(); 416 NOTREACHED();
424 } 417 }
425 } 418 }
426 419
427 void ExtensionSettingsHandler::OnExtensionLoaded(
428 content::BrowserContext* browser_context,
429 const Extension* extension) {
430 MaybeUpdateAfterNotification();
431 }
432
433 void ExtensionSettingsHandler::OnExtensionUnloaded(
434 content::BrowserContext* browser_context,
435 const Extension* extension,
436 UnloadedExtensionInfo::Reason reason) {
437 MaybeUpdateAfterNotification();
438 }
439
440 void ExtensionSettingsHandler::OnExtensionUninstalled(
441 content::BrowserContext* browser_context,
442 const Extension* extension,
443 extensions::UninstallReason reason) {
444 MaybeUpdateAfterNotification();
445 }
446
447 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( 420 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged(
448 const std::string& extension_id, int disable_reasons) { 421 const std::string& extension_id, int disable_reasons) {
449 MaybeUpdateAfterNotification(); 422 MaybeUpdateAfterNotification();
450 } 423 }
451 424
452 void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() { 425 void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() {
453 MaybeUpdateAfterNotification(); 426 MaybeUpdateAfterNotification();
454 } 427 }
455 428
456 void ExtensionSettingsHandler::ExtensionWarningsChanged() { 429 void ExtensionSettingsHandler::ExtensionWarningsChanged() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 489
517 MaybeRegisterForNotifications(); 490 MaybeRegisterForNotifications();
518 491
519 scoped_ptr<ExtensionSet> extensions = 492 scoped_ptr<ExtensionSet> extensions =
520 registry->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED | 493 registry->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
521 ExtensionRegistry::DISABLED | 494 ExtensionRegistry::DISABLED |
522 ExtensionRegistry::TERMINATED); 495 ExtensionRegistry::TERMINATED);
523 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); 496 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile);
524 bool should_do_verification_check = false; 497 bool should_do_verification_check = false;
525 for (const scoped_refptr<const Extension>& extension : *extensions) { 498 for (const scoped_refptr<const Extension>& extension : *extensions) {
526 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), profile) && 499 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), profile)) {
527 ((prefs->GetDisableReasons(extension->id()) & 500 int disable_reasons = prefs->GetDisableReasons(extension->id());
528 Extension::DISABLE_NOT_VERIFIED) != 0)) { 501 if ((disable_reasons & Extension::DISABLE_NOT_VERIFIED) != 0) {
Dan Beam 2015/04/07 17:21:13 :(
Devlin 2015/04/07 21:14:50 Fixed.
529 should_do_verification_check = true; 502 should_do_verification_check = true;
530 break; 503 break;
504 }
531 } 505 }
532 } 506 }
533 507
534 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", 508 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck",
535 should_do_verification_check); 509 should_do_verification_check);
536 if (should_do_verification_check) 510 if (should_do_verification_check)
537 ExtensionSystem::Get(profile)->install_verifier()->VerifyAllExtensions(); 511 ExtensionSystem::Get(profile)->install_verifier()->VerifyAllExtensions();
538 } 512 }
539 513
540 void ExtensionSettingsHandler::HandleToggleDeveloperMode( 514 void ExtensionSettingsHandler::HandleToggleDeveloperMode(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 this, 628 this,
655 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 629 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
656 content::Source<ExtensionPrefs>(ExtensionPrefs::Get(profile))); 630 content::Source<ExtensionPrefs>(ExtensionPrefs::Get(profile)));
657 registrar_.Add(this, 631 registrar_.Add(this,
658 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 632 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
659 content::NotificationService::AllBrowserContextsAndSources()); 633 content::NotificationService::AllBrowserContextsAndSources());
660 registrar_.Add(this, 634 registrar_.Add(this,
661 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 635 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
662 content::NotificationService::AllBrowserContextsAndSources()); 636 content::NotificationService::AllBrowserContextsAndSources());
663 637
664 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
665
666 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); 638 content::WebContentsObserver::Observe(web_ui()->GetWebContents());
667 639
668 warning_service_observer_.Add(WarningService::Get(profile)); 640 warning_service_observer_.Add(WarningService::Get(profile));
669 641
670 error_console_observer_.Add(ErrorConsole::Get(profile));
671
672 extension_management_observer_.Add( 642 extension_management_observer_.Add(
673 ExtensionManagementFactory::GetForBrowserContext(profile)); 643 ExtensionManagementFactory::GetForBrowserContext(profile));
674 } 644 }
675 645
676 void ExtensionSettingsHandler::OnReinstallComplete( 646 void ExtensionSettingsHandler::OnReinstallComplete(
677 bool success, 647 bool success,
678 const std::string& error, 648 const std::string& error,
679 webstore_install::Result result) { 649 webstore_install::Result result) {
680 MaybeUpdateAfterNotification(); 650 MaybeUpdateAfterNotification();
681 } 651 }
682 652
683 } // namespace extensions 653 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698