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

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

Issue 23624002: Add UI for RuntimeErrors in the ErrorConsole (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_merge
Patch Set: Created 7 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
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 "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/saved_files_service.h" 9 #include "apps/saved_files_service.h"
10 #include "apps/shell_window.h" 10 #include "apps/shell_window.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 ExtensionSettingsHandler::ExtensionSettingsHandler() 112 ExtensionSettingsHandler::ExtensionSettingsHandler()
113 : extension_service_(NULL), 113 : extension_service_(NULL),
114 management_policy_(NULL), 114 management_policy_(NULL),
115 ignore_notifications_(false), 115 ignore_notifications_(false),
116 deleting_rvh_(NULL), 116 deleting_rvh_(NULL),
117 registered_for_notifications_(false), 117 registered_for_notifications_(false),
118 rvh_created_callback_( 118 rvh_created_callback_(
119 base::Bind(&ExtensionSettingsHandler::RenderViewHostCreated, 119 base::Bind(&ExtensionSettingsHandler::RenderViewHostCreated,
120 base::Unretained(this))), 120 base::Unretained(this))),
121 warning_service_observer_(this) { 121 warning_service_observer_(this),
122 error_console_observer_(this) {
122 } 123 }
123 124
124 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 125 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
125 content::RenderViewHost::RemoveCreatedCallback(rvh_created_callback_); 126 content::RenderViewHost::RemoveCreatedCallback(rvh_created_callback_);
126 127
127 // There may be pending file dialogs, we need to tell them that we've gone 128 // There may be pending file dialogs, we need to tell them that we've gone
128 // away so they don't try and call back to us. 129 // away so they don't try and call back to us.
129 if (load_extension_dialog_.get()) 130 if (load_extension_dialog_.get())
130 load_extension_dialog_->ListenerDestroyed(); 131 load_extension_dialog_->ListenerDestroyed();
131 } 132 }
132 133
133 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, 134 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
134 ManagementPolicy* policy) 135 ManagementPolicy* policy)
135 : extension_service_(service), 136 : extension_service_(service),
136 management_policy_(policy), 137 management_policy_(policy),
137 ignore_notifications_(false), 138 ignore_notifications_(false),
138 deleting_rvh_(NULL), 139 deleting_rvh_(NULL),
139 registered_for_notifications_(false), 140 registered_for_notifications_(false),
140 warning_service_observer_(this) { 141 warning_service_observer_(this),
142 error_console_observer_(this) {
141 } 143 }
142 144
143 // static 145 // static
144 void ExtensionSettingsHandler::RegisterProfilePrefs( 146 void ExtensionSettingsHandler::RegisterProfilePrefs(
145 user_prefs::PrefRegistrySyncable* registry) { 147 user_prefs::PrefRegistrySyncable* registry) {
146 registry->RegisterBooleanPref( 148 registry->RegisterBooleanPref(
147 prefs::kExtensionsUIDeveloperMode, 149 prefs::kExtensionsUIDeveloperMode,
148 false, 150 false,
149 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 151 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
150 } 152 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 260
259 // If the ErrorConsole is enabled, get the errors for the extension and add 261 // If the ErrorConsole is enabled, get the errors for the extension and add
260 // them to the list. Otherwise, use the install warnings (using both is 262 // them to the list. Otherwise, use the install warnings (using both is
261 // redundant). 263 // redundant).
262 ErrorConsole* error_console = 264 ErrorConsole* error_console =
263 ErrorConsole::Get(extension_service_->profile()); 265 ErrorConsole::Get(extension_service_->profile());
264 if (error_console->enabled()) { 266 if (error_console->enabled()) {
265 const ErrorConsole::ErrorList& errors = 267 const ErrorConsole::ErrorList& errors =
266 error_console->GetErrorsForExtension(extension->id()); 268 error_console->GetErrorsForExtension(extension->id());
267 if (!errors.empty()) { 269 if (!errors.empty()) {
268 scoped_ptr<ListValue> list(new ListValue); 270 scoped_ptr<ListValue> manifest_errors(new ListValue);
271 scoped_ptr<ListValue> runtime_errors(new ListValue);
269 for (ErrorConsole::ErrorList::const_iterator iter = errors.begin(); 272 for (ErrorConsole::ErrorList::const_iterator iter = errors.begin();
270 iter != errors.end(); ++iter) { 273 iter != errors.end(); ++iter) {
271 list->Append((*iter)->ToValue().release()); 274 if ((*iter)->type() == ExtensionError::MANIFEST_ERROR)
275 manifest_errors->Append((*iter)->ToValue().release());
276 else
277 runtime_errors->Append((*iter)->ToValue().release());
272 } 278 }
273 extension_data->Set("manifestErrors", list.release()); 279 if (!manifest_errors->empty())
280 extension_data->Set("manifestErrors", manifest_errors.release());
281 if (!runtime_errors->empty())
282 extension_data->Set("runtimeErrors", runtime_errors.release());
274 } 283 }
275 } else if (Manifest::IsUnpackedLocation(extension->location())) { 284 } else if (Manifest::IsUnpackedLocation(extension->location())) {
276 const std::vector<InstallWarning>& install_warnings = 285 const std::vector<InstallWarning>& install_warnings =
277 extension->install_warnings(); 286 extension->install_warnings();
278 if (!install_warnings.empty()) { 287 if (!install_warnings.empty()) {
279 scoped_ptr<base::ListValue> list(new base::ListValue()); 288 scoped_ptr<base::ListValue> list(new base::ListValue());
280 for (std::vector<InstallWarning>::const_iterator it = 289 for (std::vector<InstallWarning>::const_iterator it =
281 install_warnings.begin(); it != install_warnings.end(); ++it) { 290 install_warnings.begin(); it != install_warnings.end(); ++it) {
282 base::DictionaryValue* item = new base::DictionaryValue(); 291 base::DictionaryValue* item = new base::DictionaryValue();
283 item->SetString("message", it->message); 292 item->SetString("message", it->message);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 void* params) { 482 void* params) {
474 last_unpacked_directory_ = base::FilePath(path); 483 last_unpacked_directory_ = base::FilePath(path);
475 UnpackedInstaller::Create(extension_service_)->Load(path); 484 UnpackedInstaller::Create(extension_service_)->Load(path);
476 } 485 }
477 486
478 void ExtensionSettingsHandler::MultiFilesSelected( 487 void ExtensionSettingsHandler::MultiFilesSelected(
479 const std::vector<base::FilePath>& files, void* params) { 488 const std::vector<base::FilePath>& files, void* params) {
480 NOTREACHED(); 489 NOTREACHED();
481 } 490 }
482 491
492 void ExtensionSettingsHandler::FileSelectionCanceled(void* params) {
493 }
494
495 void ExtensionSettingsHandler::OnErrorAdded(const ExtensionError* error) {
496 MaybeUpdateAfterNotification();
497 }
498
483 void ExtensionSettingsHandler::Observe( 499 void ExtensionSettingsHandler::Observe(
484 int type, 500 int type,
485 const content::NotificationSource& source, 501 const content::NotificationSource& source,
486 const content::NotificationDetails& details) { 502 const content::NotificationDetails& details) {
487 Profile* profile = Profile::FromWebUI(web_ui()); 503 Profile* profile = Profile::FromWebUI(web_ui());
488 Profile* source_profile = NULL; 504 Profile* source_profile = NULL;
489 switch (type) { 505 switch (type) {
490 // We listen for notifications that will result in the page being 506 // We listen for notifications that will result in the page being
491 // repopulated with data twice for the same event in certain cases. 507 // repopulated with data twice for the same event in certain cases.
492 // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because 508 // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 1015 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
1000 content::NotificationService::AllBrowserContextsAndSources()); 1016 content::NotificationService::AllBrowserContextsAndSources());
1001 1017
1002 content::RenderViewHost::AddCreatedCallback(rvh_created_callback_); 1018 content::RenderViewHost::AddCreatedCallback(rvh_created_callback_);
1003 1019
1004 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); 1020 content::WebContentsObserver::Observe(web_ui()->GetWebContents());
1005 1021
1006 warning_service_observer_.Add( 1022 warning_service_observer_.Add(
1007 ExtensionSystem::Get(profile)->warning_service()); 1023 ExtensionSystem::Get(profile)->warning_service());
1008 1024
1025 error_console_observer_.Add(ErrorConsole::Get(profile));
1026
1009 base::Closure callback = base::Bind( 1027 base::Closure callback = base::Bind(
1010 &ExtensionSettingsHandler::MaybeUpdateAfterNotification, 1028 &ExtensionSettingsHandler::MaybeUpdateAfterNotification,
1011 base::Unretained(this)); 1029 base::Unretained(this));
1012 1030
1013 pref_registrar_.Init(profile->GetPrefs()); 1031 pref_registrar_.Init(profile->GetPrefs());
1014 pref_registrar_.Add(prefs::kExtensionInstallDenyList, callback); 1032 pref_registrar_.Add(prefs::kExtensionInstallDenyList, callback);
1015 } 1033 }
1016 1034
1017 std::vector<ExtensionPage> 1035 std::vector<ExtensionPage>
1018 ExtensionSettingsHandler::GetInspectablePagesForExtension( 1036 ExtensionSettingsHandler::GetInspectablePagesForExtension(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 extension_service_->EnableExtension(extension_id); 1169 extension_service_->EnableExtension(extension_id);
1152 } else { 1170 } else {
1153 ExtensionErrorReporter::GetInstance()->ReportError( 1171 ExtensionErrorReporter::GetInstance()->ReportError(
1154 UTF8ToUTF16(JoinString(requirement_errors, ' ')), 1172 UTF8ToUTF16(JoinString(requirement_errors, ' ')),
1155 true /* be noisy */); 1173 true /* be noisy */);
1156 } 1174 }
1157 requirements_checker_.reset(); 1175 requirements_checker_.reset();
1158 } 1176 }
1159 1177
1160 } // namespace extensions 1178 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698