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

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

Issue 10407105: Improve error messaging of webRequest API in case of conflicts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempt to fix windows compilation Created 8 years, 2 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"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "grit/chromium_strings.h" 60 #include "grit/chromium_strings.h"
61 #include "grit/generated_resources.h" 61 #include "grit/generated_resources.h"
62 #include "grit/theme_resources.h" 62 #include "grit/theme_resources.h"
63 #include "ui/base/l10n/l10n_util.h" 63 #include "ui/base/l10n/l10n_util.h"
64 #include "ui/base/resource/resource_bundle.h" 64 #include "ui/base/resource/resource_bundle.h"
65 65
66 using content::RenderViewHost; 66 using content::RenderViewHost;
67 using content::WebContents; 67 using content::WebContents;
68 using extensions::Extension; 68 using extensions::Extension;
69 using extensions::ExtensionUpdater; 69 using extensions::ExtensionUpdater;
70 using extensions::ExtensionWarning;
70 using extensions::ManagementPolicy; 71 using extensions::ManagementPolicy;
71 72
72 /////////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////////
73 // 74 //
74 // ExtensionSettingsHandler 75 // ExtensionSettingsHandler
75 // 76 //
76 /////////////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////////////
77 78
78 ExtensionSettingsHandler::ExtensionSettingsHandler() 79 ExtensionSettingsHandler::ExtensionSettingsHandler()
79 : extension_service_(NULL), 80 : extension_service_(NULL),
80 management_policy_(NULL), 81 management_policy_(NULL),
81 ignore_notifications_(false), 82 ignore_notifications_(false),
82 deleting_rvh_(NULL), 83 deleting_rvh_(NULL),
83 registered_for_notifications_(false) { 84 registered_for_notifications_(false) {
84 } 85 }
85 86
86 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 87 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
87 // There may be pending file dialogs, we need to tell them that we've gone 88 // There may be pending file dialogs, we need to tell them that we've gone
88 // away so they don't try and call back to us. 89 // away so they don't try and call back to us.
89 if (load_extension_dialog_) 90 if (load_extension_dialog_)
90 load_extension_dialog_->ListenerDestroyed(); 91 load_extension_dialog_->ListenerDestroyed();
91 92
92 registrar_.RemoveAll(); 93 registrar_.RemoveAll();
94
95 if (registered_for_notifications_) {
96 Profile* profile = Profile::FromWebUI(web_ui());
97 extensions::ExtensionWarningService* warning_service =
98 extensions::ExtensionSystem::Get(profile)->warning_service();
99 warning_service->RemoveObserver(this);
100 }
93 } 101 }
94 102
95 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, 103 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
96 ManagementPolicy* policy) 104 ManagementPolicy* policy)
97 : extension_service_(service), 105 : extension_service_(service),
98 management_policy_(policy), 106 management_policy_(policy),
99 ignore_notifications_(false), 107 ignore_notifications_(false),
100 deleting_rvh_(NULL), 108 deleting_rvh_(NULL),
101 registered_for_notifications_(false) { 109 registered_for_notifications_(false) {
102 } 110 }
103 111
104 // static 112 // static
105 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { 113 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) {
106 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, 114 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode,
107 false, 115 false,
108 PrefService::SYNCABLE_PREF); 116 PrefService::SYNCABLE_PREF);
109 } 117 }
110 118
111 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( 119 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
112 const Extension* extension, 120 const Extension* extension,
113 const std::vector<ExtensionPage>& pages, 121 const std::vector<ExtensionPage>& pages,
114 const ExtensionWarningSet* warnings_set) { 122 const extensions::ExtensionWarningService* warning_service) {
115 DictionaryValue* extension_data = new DictionaryValue(); 123 DictionaryValue* extension_data = new DictionaryValue();
116 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); 124 bool enabled = extension_service_->IsExtensionEnabled(extension->id());
117 extension->GetBasicInfo(enabled, extension_data); 125 extension->GetBasicInfo(enabled, extension_data);
118 126
119 extension_data->SetBoolean("userModifiable", 127 extension_data->SetBoolean("userModifiable",
120 management_policy_->UserMayModifySettings(extension, NULL)); 128 management_policy_->UserMayModifySettings(extension, NULL));
121 129
122 GURL icon = 130 GURL icon =
123 ExtensionIconSource::GetIconURL(extension, 131 ExtensionIconSource::GetIconURL(extension,
124 extension_misc::EXTENSION_ICON_MEDIUM, 132 extension_misc::EXTENSION_ICON_MEDIUM,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 184 }
177 extension_data->Set("views", views); 185 extension_data->Set("views", views);
178 extensions::ExtensionActionManager* extension_action_manager = 186 extensions::ExtensionActionManager* extension_action_manager =
179 extensions::ExtensionActionManager::Get(extension_service_->profile()); 187 extensions::ExtensionActionManager::Get(extension_service_->profile());
180 extension_data->SetBoolean( 188 extension_data->SetBoolean(
181 "hasPopupAction", 189 "hasPopupAction",
182 extension_action_manager->GetBrowserAction(*extension) || 190 extension_action_manager->GetBrowserAction(*extension) ||
183 extension_action_manager->GetPageAction(*extension)); 191 extension_action_manager->GetPageAction(*extension));
184 192
185 // Add warnings. 193 // Add warnings.
186 if (warnings_set) { 194 if (warning_service) {
187 std::set<ExtensionWarningSet::WarningType> warnings; 195 std::vector<std::string> warnings;
188 warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); 196 warning_service->GetWarningMessagesForExtension(extension->id(), &warnings);
189 197
190 if (!warnings.empty()) { 198 if (!warnings.empty()) {
191 ListValue* warnings_list = new ListValue; 199 ListValue* warnings_list = new ListValue;
192 for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = 200 for (std::vector<std::string>::const_iterator iter = warnings.begin();
193 warnings.begin(); 201 iter != warnings.end(); ++iter) {
194 iter != warnings.end(); 202 warnings_list->Append(Value::CreateStringValue(*iter));
195 ++iter) {
196 string16 warning_string(
197 ExtensionWarningSet::GetLocalizedWarning(*iter));
198 warnings_list->Append(Value::CreateStringValue(warning_string));
199 } 203 }
200 extension_data->Set("warnings", warnings_list); 204 extension_data->Set("warnings", warnings_list);
201 } 205 }
202 } 206 }
203 207
204 // Add install warnings (these are not the same as warnings!). 208 // Add install warnings (these are not the same as warnings!).
205 if (extension->location() == Extension::LOAD) { 209 if (extension->location() == Extension::LOAD) {
206 const Extension::InstallWarningVector& install_warnings = 210 const Extension::InstallWarningVector& install_warnings =
207 extension->install_warnings(); 211 extension->install_warnings();
208 if (!install_warnings.empty()) { 212 if (!install_warnings.empty()) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: 416 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED:
413 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: 417 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED:
414 source_profile = content::Source<Profile>(source).ptr(); 418 source_profile = content::Source<Profile>(source).ptr();
415 if (!profile->IsSameProfile(source_profile)) 419 if (!profile->IsSameProfile(source_profile))
416 return; 420 return;
417 MaybeUpdateAfterNotification(); 421 MaybeUpdateAfterNotification();
418 break; 422 break;
419 case chrome::NOTIFICATION_EXTENSION_LOADED: 423 case chrome::NOTIFICATION_EXTENSION_LOADED:
420 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 424 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
421 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: 425 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
422 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED:
423 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: 426 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED:
424 case chrome::NOTIFICATION_PREF_CHANGED: 427 case chrome::NOTIFICATION_PREF_CHANGED:
425 MaybeUpdateAfterNotification(); 428 MaybeUpdateAfterNotification();
426 break; 429 break;
427 default: 430 default:
428 NOTREACHED(); 431 NOTREACHED();
429 } 432 }
430 } 433 }
431 434
432 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { 435 void ExtensionSettingsHandler::ExtensionUninstallAccepted() {
(...skipping 21 matching lines...) Expand all
454 // There will be no EXTENSION_UNLOADED notification for terminated 457 // There will be no EXTENSION_UNLOADED notification for terminated
455 // extensions as they were already unloaded. 458 // extensions as they were already unloaded.
456 if (was_terminated) 459 if (was_terminated)
457 HandleRequestExtensionsData(NULL); 460 HandleRequestExtensionsData(NULL);
458 } 461 }
459 462
460 void ExtensionSettingsHandler::ExtensionUninstallCanceled() { 463 void ExtensionSettingsHandler::ExtensionUninstallCanceled() {
461 extension_id_prompting_ = ""; 464 extension_id_prompting_ = "";
462 } 465 }
463 466
467 void ExtensionSettingsHandler::ExtensionWarningsChanged() {
468 MaybeUpdateAfterNotification();
469 }
470
464 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { 471 void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
465 const ExtensionSet* extensions = extension_service_->extensions(); 472 const ExtensionSet* extensions = extension_service_->extensions();
466 std::vector<const Extension*> unpacked_extensions; 473 std::vector<const Extension*> unpacked_extensions;
467 for (ExtensionSet::const_iterator extension = extensions->begin(); 474 for (ExtensionSet::const_iterator extension = extensions->begin();
468 extension != extensions->end(); ++extension) { 475 extension != extensions->end(); ++extension) {
469 if ((*extension)->location() == Extension::LOAD) 476 if ((*extension)->location() == Extension::LOAD)
470 unpacked_extensions.push_back(*extension); 477 unpacked_extensions.push_back(*extension);
471 } 478 }
472 479
473 for (std::vector<const Extension*>::iterator iter = 480 for (std::vector<const Extension*>::iterator iter =
474 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { 481 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) {
475 extension_service_->ReloadExtension((*iter)->id()); 482 extension_service_->ReloadExtension((*iter)->id());
476 } 483 }
477 } 484 }
478 485
479 void ExtensionSettingsHandler::HandleRequestExtensionsData( 486 void ExtensionSettingsHandler::HandleRequestExtensionsData(
480 const ListValue* args) { 487 const ListValue* args) {
481 DictionaryValue results; 488 DictionaryValue results;
482 489
490 Profile* profile = Profile::FromWebUI(web_ui());
491
483 // Add the extensions to the results structure. 492 // Add the extensions to the results structure.
484 ListValue *extensions_list = new ListValue(); 493 ListValue *extensions_list = new ListValue();
485 494
486 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); 495 extensions::ExtensionWarningService* warnings =
496 extensions::ExtensionSystem::Get(profile)->warning_service();
487 497
488 const ExtensionSet* extensions = extension_service_->extensions(); 498 const ExtensionSet* extensions = extension_service_->extensions();
489 for (ExtensionSet::const_iterator extension = extensions->begin(); 499 for (ExtensionSet::const_iterator extension = extensions->begin();
490 extension != extensions->end(); ++extension) { 500 extension != extensions->end(); ++extension) {
491 if ((*extension)->ShouldDisplayInExtensionSettings()) { 501 if ((*extension)->ShouldDisplayInExtensionSettings()) {
492 extensions_list->Append(CreateExtensionDetailValue( 502 extensions_list->Append(CreateExtensionDetailValue(
493 *extension, 503 *extension,
494 GetInspectablePagesForExtension(*extension, true), 504 GetInspectablePagesForExtension(*extension, true),
495 warnings)); 505 warnings));
496 } 506 }
(...skipping 19 matching lines...) Expand all
516 warnings)); 526 warnings));
517 } 527 }
518 } 528 }
519 results.Set("extensions", extensions_list); 529 results.Set("extensions", extensions_list);
520 530
521 if (ManagedMode::IsInManagedMode()) { 531 if (ManagedMode::IsInManagedMode()) {
522 results.SetBoolean("managedMode", true); 532 results.SetBoolean("managedMode", true);
523 results.SetBoolean("developerMode", false); 533 results.SetBoolean("developerMode", false);
524 } else { 534 } else {
525 results.SetBoolean("managedMode", false); 535 results.SetBoolean("managedMode", false);
526 Profile* profile = Profile::FromWebUI(web_ui()); 536
527 bool developer_mode = 537 bool developer_mode =
528 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); 538 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
529 results.SetBoolean("developerMode", developer_mode); 539 results.SetBoolean("developerMode", developer_mode);
530 } 540 }
531 541
532 bool load_unpacked_disabled = 542 bool load_unpacked_disabled =
533 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); 543 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault();
534 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); 544 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled);
535 545
536 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", 546 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData",
537 results); 547 results);
538 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); 548 content::WebContentsObserver::Observe(web_ui()->GetWebContents());
539 549
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 registered_for_notifications_ = true; 790 registered_for_notifications_ = true;
781 Profile* profile = Profile::FromWebUI(web_ui()); 791 Profile* profile = Profile::FromWebUI(web_ui());
782 792
783 // Register for notifications that we need to reload the page. 793 // Register for notifications that we need to reload the page.
784 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 794 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
785 content::Source<Profile>(profile)); 795 content::Source<Profile>(profile));
786 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 796 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
787 content::Source<Profile>(profile)); 797 content::Source<Profile>(profile));
788 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 798 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
789 content::Source<Profile>(profile)); 799 content::Source<Profile>(profile));
790 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED,
791 content::Source<Profile>(profile));
792 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 800 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
793 content::NotificationService::AllBrowserContextsAndSources()); 801 content::NotificationService::AllBrowserContextsAndSources());
794 registrar_.Add(this, 802 registrar_.Add(this,
795 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, 803 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
796 content::NotificationService::AllBrowserContextsAndSources()); 804 content::NotificationService::AllBrowserContextsAndSources());
797 registrar_.Add(this, 805 registrar_.Add(this,
798 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, 806 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
799 content::NotificationService::AllBrowserContextsAndSources()); 807 content::NotificationService::AllBrowserContextsAndSources());
800 registrar_.Add(this, 808 registrar_.Add(this,
801 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 809 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
802 content::NotificationService::AllBrowserContextsAndSources()); 810 content::NotificationService::AllBrowserContextsAndSources());
803 registrar_.Add(this, 811 registrar_.Add(this,
804 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 812 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
805 content::NotificationService::AllBrowserContextsAndSources()); 813 content::NotificationService::AllBrowserContextsAndSources());
806 registrar_.Add( 814 registrar_.Add(
807 this, 815 this,
808 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 816 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
809 content::Source<extensions::ExtensionPrefs>( 817 content::Source<extensions::ExtensionPrefs>(
810 profile->GetExtensionService()->extension_prefs())); 818 profile->GetExtensionService()->extension_prefs()));
811 819
820 extensions::ExtensionWarningService* warning_service =
821 extensions::ExtensionSystem::Get(profile)->warning_service();
822 warning_service->AddObserver(this);
823
812 pref_registrar_.Init(profile->GetPrefs()); 824 pref_registrar_.Init(profile->GetPrefs());
813 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); 825 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this);
814 local_state_pref_registrar_.Init(g_browser_process->local_state()); 826 local_state_pref_registrar_.Init(g_browser_process->local_state());
815 local_state_pref_registrar_.Add(prefs::kInManagedMode, this); 827 local_state_pref_registrar_.Add(prefs::kInManagedMode, this);
816 } 828 }
817 829
818 std::vector<ExtensionPage> 830 std::vector<ExtensionPage>
819 ExtensionSettingsHandler::GetInspectablePagesForExtension( 831 ExtensionSettingsHandler::GetInspectablePagesForExtension(
820 const Extension* extension, bool extension_is_enabled) { 832 const Extension* extension, bool extension_is_enabled) {
821 std::vector<ExtensionPage> result; 833 std::vector<ExtensionPage> result;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 std::vector<std::string> requirement_errors) { 936 std::vector<std::string> requirement_errors) {
925 if (requirement_errors.empty()) { 937 if (requirement_errors.empty()) {
926 extension_service_->EnableExtension(extension_id); 938 extension_service_->EnableExtension(extension_id);
927 } else { 939 } else {
928 ExtensionErrorReporter::GetInstance()->ReportError( 940 ExtensionErrorReporter::GetInstance()->ReportError(
929 UTF8ToUTF16(JoinString(requirement_errors, ' ')), 941 UTF8ToUTF16(JoinString(requirement_errors, ' ')),
930 true /* be noisy */); 942 true /* be noisy */);
931 } 943 }
932 requirements_checker_.reset(); 944 requirements_checker_.reset();
933 } 945 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698