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

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

Issue 10908119: Replace chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED message with observer pattern Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "base/version.h" 16 #include "base/version.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/debugger/devtools_window.h" 18 #include "chrome/browser/debugger/devtools_window.h"
19 #include "chrome/browser/extensions/crx_installer.h" 19 #include "chrome/browser/extensions/crx_installer.h"
20 #include "chrome/browser/extensions/extension_disabled_ui.h" 20 #include "chrome/browser/extensions/extension_disabled_ui.h"
21 #include "chrome/browser/extensions/extension_host.h" 21 #include "chrome/browser/extensions/extension_host.h"
22 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_system.h" 23 #include "chrome/browser/extensions/extension_system.h"
24 #include "chrome/browser/extensions/extension_warning_set.h"
25 #include "chrome/browser/extensions/lazy_background_task_queue.h" 24 #include "chrome/browser/extensions/lazy_background_task_queue.h"
26 #include "chrome/browser/extensions/unpacked_installer.h" 25 #include "chrome/browser/extensions/unpacked_installer.h"
27 #include "chrome/browser/extensions/updater/extension_updater.h" 26 #include "chrome/browser/extensions/updater/extension_updater.h"
28 #include "chrome/browser/google/google_util.h" 27 #include "chrome/browser/google/google_util.h"
29 #include "chrome/browser/managed_mode.h" 28 #include "chrome/browser/managed_mode.h"
30 #include "chrome/browser/prefs/pref_service.h" 29 #include "chrome/browser/prefs/pref_service.h"
31 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/tab_contents/background_contents.h" 31 #include "chrome/browser/tab_contents/background_contents.h"
33 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/chrome_select_file_policy.h" 33 #include "chrome/browser/ui/chrome_select_file_policy.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 registered_for_notifications_(false) { 78 registered_for_notifications_(false) {
80 } 79 }
81 80
82 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 81 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
83 // There may be pending file dialogs, we need to tell them that we've gone 82 // There may be pending file dialogs, we need to tell them that we've gone
84 // away so they don't try and call back to us. 83 // away so they don't try and call back to us.
85 if (load_extension_dialog_) 84 if (load_extension_dialog_)
86 load_extension_dialog_->ListenerDestroyed(); 85 load_extension_dialog_->ListenerDestroyed();
87 86
88 registrar_.RemoveAll(); 87 registrar_.RemoveAll();
88
89 if (registered_for_notifications_) {
90 Profile* profile = Profile::FromWebUI(web_ui());
91 extensions::ExtensionWarningService* warnings =
92 extensions::ExtensionSystem::Get(profile)->warning_service();
93 warnings->RemoveObserver(this);
94 }
89 } 95 }
90 96
91 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, 97 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
92 ManagementPolicy* policy) 98 ManagementPolicy* policy)
93 : extension_service_(service), 99 : extension_service_(service),
94 management_policy_(policy), 100 management_policy_(policy),
95 ignore_notifications_(false), 101 ignore_notifications_(false),
96 deleting_rvh_(NULL), 102 deleting_rvh_(NULL),
97 registered_for_notifications_(false) { 103 registered_for_notifications_(false) {
98 } 104 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: 409 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED:
404 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: 410 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED:
405 source_profile = content::Source<Profile>(source).ptr(); 411 source_profile = content::Source<Profile>(source).ptr();
406 if (!profile->IsSameProfile(source_profile)) 412 if (!profile->IsSameProfile(source_profile))
407 return; 413 return;
408 MaybeUpdateAfterNotification(); 414 MaybeUpdateAfterNotification();
409 break; 415 break;
410 case chrome::NOTIFICATION_EXTENSION_LOADED: 416 case chrome::NOTIFICATION_EXTENSION_LOADED:
411 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 417 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
412 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: 418 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
413 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED:
414 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: 419 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED:
415 case chrome::NOTIFICATION_PREF_CHANGED: 420 case chrome::NOTIFICATION_PREF_CHANGED:
416 MaybeUpdateAfterNotification(); 421 MaybeUpdateAfterNotification();
417 break; 422 break;
418 default: 423 default:
419 NOTREACHED(); 424 NOTREACHED();
420 } 425 }
421 } 426 }
422 427
423 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { 428 void ExtensionSettingsHandler::ExtensionUninstallAccepted() {
(...skipping 21 matching lines...) Expand all
445 // There will be no EXTENSION_UNLOADED notification for terminated 450 // There will be no EXTENSION_UNLOADED notification for terminated
446 // extensions as they were already unloaded. 451 // extensions as they were already unloaded.
447 if (was_terminated) 452 if (was_terminated)
448 HandleRequestExtensionsData(NULL); 453 HandleRequestExtensionsData(NULL);
449 } 454 }
450 455
451 void ExtensionSettingsHandler::ExtensionUninstallCanceled() { 456 void ExtensionSettingsHandler::ExtensionUninstallCanceled() {
452 extension_id_prompting_ = ""; 457 extension_id_prompting_ = "";
453 } 458 }
454 459
460 void ExtensionSettingsHandler::ExtensionWarningsChanged() {
461 MaybeUpdateAfterNotification();
462 }
463
455 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { 464 void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
456 const ExtensionSet* extensions = extension_service_->extensions(); 465 const ExtensionSet* extensions = extension_service_->extensions();
457 std::vector<const Extension*> unpacked_extensions; 466 std::vector<const Extension*> unpacked_extensions;
458 for (ExtensionSet::const_iterator extension = extensions->begin(); 467 for (ExtensionSet::const_iterator extension = extensions->begin();
459 extension != extensions->end(); ++extension) { 468 extension != extensions->end(); ++extension) {
460 if ((*extension)->location() == Extension::LOAD) 469 if ((*extension)->location() == Extension::LOAD)
461 unpacked_extensions.push_back(*extension); 470 unpacked_extensions.push_back(*extension);
462 } 471 }
463 472
464 for (std::vector<const Extension*>::iterator iter = 473 for (std::vector<const Extension*>::iterator iter =
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 registered_for_notifications_ = true; 784 registered_for_notifications_ = true;
776 Profile* profile = Profile::FromWebUI(web_ui()); 785 Profile* profile = Profile::FromWebUI(web_ui());
777 786
778 // Register for notifications that we need to reload the page. 787 // Register for notifications that we need to reload the page.
779 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 788 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
780 content::Source<Profile>(profile)); 789 content::Source<Profile>(profile));
781 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 790 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
782 content::Source<Profile>(profile)); 791 content::Source<Profile>(profile));
783 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 792 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
784 content::Source<Profile>(profile)); 793 content::Source<Profile>(profile));
785 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED,
786 content::Source<Profile>(profile));
787 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 794 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
788 content::NotificationService::AllBrowserContextsAndSources()); 795 content::NotificationService::AllBrowserContextsAndSources());
789 registrar_.Add(this, 796 registrar_.Add(this,
790 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, 797 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
791 content::NotificationService::AllBrowserContextsAndSources()); 798 content::NotificationService::AllBrowserContextsAndSources());
792 registrar_.Add(this, 799 registrar_.Add(this,
793 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, 800 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
794 content::NotificationService::AllBrowserContextsAndSources()); 801 content::NotificationService::AllBrowserContextsAndSources());
795 registrar_.Add(this, 802 registrar_.Add(this,
796 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 803 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
797 content::NotificationService::AllBrowserContextsAndSources()); 804 content::NotificationService::AllBrowserContextsAndSources());
798 registrar_.Add(this, 805 registrar_.Add(this,
799 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 806 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
800 content::NotificationService::AllBrowserContextsAndSources()); 807 content::NotificationService::AllBrowserContextsAndSources());
801 registrar_.Add( 808 registrar_.Add(
802 this, 809 this,
803 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 810 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
804 content::Source<extensions::ExtensionPrefs>( 811 content::Source<extensions::ExtensionPrefs>(
805 profile->GetExtensionService()->extension_prefs())); 812 profile->GetExtensionService()->extension_prefs()));
806 813
814 extensions::ExtensionWarningService* warnings =
815 extensions::ExtensionSystem::Get(profile)->warning_service();
816 warnings->AddObserver(this);
817
807 pref_registrar_.Init(profile->GetPrefs()); 818 pref_registrar_.Init(profile->GetPrefs());
808 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); 819 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this);
809 local_state_pref_registrar_.Init(g_browser_process->local_state()); 820 local_state_pref_registrar_.Init(g_browser_process->local_state());
810 local_state_pref_registrar_.Add(prefs::kInManagedMode, this); 821 local_state_pref_registrar_.Add(prefs::kInManagedMode, this);
811 } 822 }
812 823
813 std::vector<ExtensionPage> 824 std::vector<ExtensionPage>
814 ExtensionSettingsHandler::GetInspectablePagesForExtension( 825 ExtensionSettingsHandler::GetInspectablePagesForExtension(
815 const Extension* extension, bool extension_is_enabled) { 826 const Extension* extension, bool extension_is_enabled) {
816 std::vector<ExtensionPage> result; 827 std::vector<ExtensionPage> result;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 #else 894 #else
884 return NULL; 895 return NULL;
885 #endif // !defined(OS_ANDROID) 896 #endif // !defined(OS_ANDROID)
886 } 897 }
887 898
888 void ExtensionSettingsHandler::InspectExtensionHost( 899 void ExtensionSettingsHandler::InspectExtensionHost(
889 extensions::ExtensionHost* host) { 900 extensions::ExtensionHost* host) {
890 if (host) 901 if (host)
891 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); 902 DevToolsWindow::OpenDevToolsWindow(host->render_view_host());
892 } 903 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_settings_handler.h ('k') | chrome/common/chrome_notification_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698