| 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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/app_restore_service.h" | 8 #include "apps/app_restore_service.h" |
| 9 #include "apps/app_window.h" | 9 #include "apps/app_window.h" |
| 10 #include "apps/app_window_registry.h" | 10 #include "apps/app_window_registry.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 : extension_service_(NULL), | 158 : extension_service_(NULL), |
| 159 management_policy_(NULL), | 159 management_policy_(NULL), |
| 160 ignore_notifications_(false), | 160 ignore_notifications_(false), |
| 161 deleting_rvh_(NULL), | 161 deleting_rvh_(NULL), |
| 162 deleting_rwh_id_(-1), | 162 deleting_rwh_id_(-1), |
| 163 deleting_rph_id_(-1), | 163 deleting_rph_id_(-1), |
| 164 registered_for_notifications_(false), | 164 registered_for_notifications_(false), |
| 165 warning_service_observer_(this), | 165 warning_service_observer_(this), |
| 166 error_console_observer_(this), | 166 error_console_observer_(this), |
| 167 extension_prefs_observer_(this), | 167 extension_prefs_observer_(this), |
| 168 extension_registry_observer_(this), |
| 168 should_do_verification_check_(false) { | 169 should_do_verification_check_(false) { |
| 169 } | 170 } |
| 170 | 171 |
| 171 ExtensionSettingsHandler::~ExtensionSettingsHandler() { | 172 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
| 172 } | 173 } |
| 173 | 174 |
| 174 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, | 175 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, |
| 175 ManagementPolicy* policy) | 176 ManagementPolicy* policy) |
| 176 : extension_service_(service), | 177 : extension_service_(service), |
| 177 management_policy_(policy), | 178 management_policy_(policy), |
| 178 ignore_notifications_(false), | 179 ignore_notifications_(false), |
| 179 deleting_rvh_(NULL), | 180 deleting_rvh_(NULL), |
| 180 deleting_rwh_id_(-1), | 181 deleting_rwh_id_(-1), |
| 181 deleting_rph_id_(-1), | 182 deleting_rph_id_(-1), |
| 182 registered_for_notifications_(false), | 183 registered_for_notifications_(false), |
| 183 warning_service_observer_(this), | 184 warning_service_observer_(this), |
| 184 error_console_observer_(this), | 185 error_console_observer_(this), |
| 185 extension_prefs_observer_(this), | 186 extension_prefs_observer_(this), |
| 187 extension_registry_observer_(this), |
| 186 should_do_verification_check_(false) { | 188 should_do_verification_check_(false) { |
| 187 } | 189 } |
| 188 | 190 |
| 189 // static | 191 // static |
| 190 void ExtensionSettingsHandler::RegisterProfilePrefs( | 192 void ExtensionSettingsHandler::RegisterProfilePrefs( |
| 191 user_prefs::PrefRegistrySyncable* registry) { | 193 user_prefs::PrefRegistrySyncable* registry) { |
| 192 registry->RegisterBooleanPref( | 194 registry->RegisterBooleanPref( |
| 193 prefs::kExtensionsUIDeveloperMode, | 195 prefs::kExtensionsUIDeveloperMode, |
| 194 false, | 196 false, |
| 195 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 197 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 MaybeUpdateAfterNotification(); | 646 MaybeUpdateAfterNotification(); |
| 645 break; | 647 break; |
| 646 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { | 648 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 647 content::RenderWidgetHost* rwh = | 649 content::RenderWidgetHost* rwh = |
| 648 content::Source<content::RenderWidgetHost>(source).ptr(); | 650 content::Source<content::RenderWidgetHost>(source).ptr(); |
| 649 deleting_rwh_id_ = rwh->GetRoutingID(); | 651 deleting_rwh_id_ = rwh->GetRoutingID(); |
| 650 deleting_rph_id_ = rwh->GetProcess()->GetID(); | 652 deleting_rph_id_ = rwh->GetProcess()->GetID(); |
| 651 MaybeUpdateAfterNotification(); | 653 MaybeUpdateAfterNotification(); |
| 652 break; | 654 break; |
| 653 } | 655 } |
| 654 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: | |
| 655 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | |
| 656 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: | |
| 657 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 656 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 658 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 657 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 659 MaybeUpdateAfterNotification(); | 658 MaybeUpdateAfterNotification(); |
| 660 break; | 659 break; |
| 661 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: | 660 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: |
| 662 // This notification is sent when the extension host destruction begins, | 661 // This notification is sent when the extension host destruction begins, |
| 663 // not when it finishes. We use PostTask to delay the update until after | 662 // not when it finishes. We use PostTask to delay the update until after |
| 664 // the destruction finishes. | 663 // the destruction finishes. |
| 665 base::MessageLoop::current()->PostTask( | 664 base::MessageLoop::current()->PostTask( |
| 666 FROM_HERE, | 665 FROM_HERE, |
| 667 base::Bind(&ExtensionSettingsHandler::MaybeUpdateAfterNotification, | 666 base::Bind(&ExtensionSettingsHandler::MaybeUpdateAfterNotification, |
| 668 AsWeakPtr())); | 667 AsWeakPtr())); |
| 669 break; | 668 break; |
| 670 default: | 669 default: |
| 671 NOTREACHED(); | 670 NOTREACHED(); |
| 672 } | 671 } |
| 673 } | 672 } |
| 674 | 673 |
| 674 void ExtensionSettingsHandler::OnExtensionLoaded( |
| 675 content::BrowserContext* browser_context, |
| 676 const Extension* extension) { |
| 677 MaybeUpdateAfterNotification(); |
| 678 } |
| 679 |
| 680 void ExtensionSettingsHandler::OnExtensionUnloaded( |
| 681 content::BrowserContext* browser_context, |
| 682 const Extension* extension, |
| 683 UnloadedExtensionInfo::Reason reason) { |
| 684 MaybeUpdateAfterNotification(); |
| 685 } |
| 686 |
| 687 void ExtensionSettingsHandler::OnExtensionUninstalled( |
| 688 content::BrowserContext* browser_context, |
| 689 const Extension* extension) { |
| 690 MaybeUpdateAfterNotification(); |
| 691 } |
| 692 |
| 675 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( | 693 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( |
| 676 const std::string& extension_id, int disable_reasons) { | 694 const std::string& extension_id, int disable_reasons) { |
| 677 MaybeUpdateAfterNotification(); | 695 MaybeUpdateAfterNotification(); |
| 678 } | 696 } |
| 679 | 697 |
| 680 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { | 698 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| 681 DCHECK(!extension_id_prompting_.empty()); | 699 DCHECK(!extension_id_prompting_.empty()); |
| 682 | 700 |
| 683 bool was_terminated = false; | 701 bool was_terminated = false; |
| 684 | 702 |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 } | 1147 } |
| 1130 | 1148 |
| 1131 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { | 1149 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { |
| 1132 if (registered_for_notifications_) | 1150 if (registered_for_notifications_) |
| 1133 return; | 1151 return; |
| 1134 | 1152 |
| 1135 registered_for_notifications_ = true; | 1153 registered_for_notifications_ = true; |
| 1136 Profile* profile = Profile::FromWebUI(web_ui()); | 1154 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1137 | 1155 |
| 1138 // Register for notifications that we need to reload the page. | 1156 // Register for notifications that we need to reload the page. |
| 1139 registrar_.Add(this, | |
| 1140 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
| 1141 content::Source<Profile>(profile)); | |
| 1142 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 1143 content::Source<Profile>(profile)); | |
| 1144 registrar_.Add(this, | |
| 1145 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | |
| 1146 content::Source<Profile>(profile)); | |
| 1147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 1157 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 1148 content::Source<Profile>(profile)); | 1158 content::Source<Profile>(profile)); |
| 1149 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 1159 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 1150 content::NotificationService::AllBrowserContextsAndSources()); | 1160 content::NotificationService::AllBrowserContextsAndSources()); |
| 1151 registrar_.Add(this, | 1161 registrar_.Add(this, |
| 1152 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 1162 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 1153 content::NotificationService::AllBrowserContextsAndSources()); | 1163 content::NotificationService::AllBrowserContextsAndSources()); |
| 1154 registrar_.Add(this, | 1164 registrar_.Add(this, |
| 1155 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 1165 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 1156 content::NotificationService::AllBrowserContextsAndSources()); | 1166 content::NotificationService::AllBrowserContextsAndSources()); |
| 1157 registrar_.Add( | 1167 registrar_.Add( |
| 1158 this, | 1168 this, |
| 1159 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 1169 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 1160 content::Source<ExtensionPrefs>(ExtensionPrefs::Get(profile))); | 1170 content::Source<ExtensionPrefs>(ExtensionPrefs::Get(profile))); |
| 1161 registrar_.Add(this, | 1171 registrar_.Add(this, |
| 1162 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 1172 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 1163 content::NotificationService::AllBrowserContextsAndSources()); | 1173 content::NotificationService::AllBrowserContextsAndSources()); |
| 1164 | |
| 1165 registrar_.Add(this, | 1174 registrar_.Add(this, |
| 1166 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1175 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1167 content::NotificationService::AllBrowserContextsAndSources()); | 1176 content::NotificationService::AllBrowserContextsAndSources()); |
| 1168 | 1177 |
| 1178 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); |
| 1179 |
| 1169 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); | 1180 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); |
| 1170 | 1181 |
| 1171 warning_service_observer_.Add( | 1182 warning_service_observer_.Add( |
| 1172 ExtensionSystem::Get(profile)->warning_service()); | 1183 ExtensionSystem::Get(profile)->warning_service()); |
| 1173 | 1184 |
| 1174 error_console_observer_.Add(ErrorConsole::Get(profile)); | 1185 error_console_observer_.Add(ErrorConsole::Get(profile)); |
| 1175 | 1186 |
| 1176 base::Closure callback = base::Bind( | 1187 base::Closure callback = base::Bind( |
| 1177 &ExtensionSettingsHandler::MaybeUpdateAfterNotification, | 1188 &ExtensionSettingsHandler::MaybeUpdateAfterNotification, |
| 1178 AsWeakPtr()); | 1189 AsWeakPtr()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 extension_service_->EnableExtension(extension_id); | 1332 extension_service_->EnableExtension(extension_id); |
| 1322 } else { | 1333 } else { |
| 1323 ExtensionErrorReporter::GetInstance()->ReportError( | 1334 ExtensionErrorReporter::GetInstance()->ReportError( |
| 1324 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')), | 1335 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')), |
| 1325 true); // Be noisy. | 1336 true); // Be noisy. |
| 1326 } | 1337 } |
| 1327 requirements_checker_.reset(); | 1338 requirements_checker_.reset(); |
| 1328 } | 1339 } |
| 1329 | 1340 |
| 1330 } // namespace extensions | 1341 } // namespace extensions |
| OLD | NEW |