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

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: Addressed Evan's comments Created 8 years, 1 month 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "grit/chromium_strings.h" 61 #include "grit/chromium_strings.h"
62 #include "grit/generated_resources.h" 62 #include "grit/generated_resources.h"
63 #include "grit/theme_resources.h" 63 #include "grit/theme_resources.h"
64 #include "ui/base/l10n/l10n_util.h" 64 #include "ui/base/l10n/l10n_util.h"
65 #include "ui/base/resource/resource_bundle.h" 65 #include "ui/base/resource/resource_bundle.h"
66 66
67 using content::RenderViewHost; 67 using content::RenderViewHost;
68 using content::WebContents; 68 using content::WebContents;
69 using extensions::Extension; 69 using extensions::Extension;
70 using extensions::ExtensionUpdater; 70 using extensions::ExtensionUpdater;
71 using extensions::ExtensionWarning;
71 using extensions::ManagementPolicy; 72 using extensions::ManagementPolicy;
72 73
73 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
74 // 75 //
75 // ExtensionSettingsHandler 76 // ExtensionSettingsHandler
76 // 77 //
77 /////////////////////////////////////////////////////////////////////////////// 78 ///////////////////////////////////////////////////////////////////////////////
78 79
79 ExtensionSettingsHandler::ExtensionSettingsHandler() 80 ExtensionSettingsHandler::ExtensionSettingsHandler()
80 : extension_service_(NULL), 81 : extension_service_(NULL),
81 management_policy_(NULL), 82 management_policy_(NULL),
82 ignore_notifications_(false), 83 ignore_notifications_(false),
83 deleting_rvh_(NULL), 84 deleting_rvh_(NULL),
84 registered_for_notifications_(false) { 85 registered_for_notifications_(false),
86 ALLOW_THIS_IN_INITIALIZER_LIST(warning_service_observer_(this)) {
85 } 87 }
86 88
87 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 89 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
88 // There may be pending file dialogs, we need to tell them that we've gone 90 // There may be pending file dialogs, we need to tell them that we've gone
89 // away so they don't try and call back to us. 91 // away so they don't try and call back to us.
90 if (load_extension_dialog_) 92 if (load_extension_dialog_)
91 load_extension_dialog_->ListenerDestroyed(); 93 load_extension_dialog_->ListenerDestroyed();
92
93 registrar_.RemoveAll();
94 } 94 }
95 95
96 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, 96 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
97 ManagementPolicy* policy) 97 ManagementPolicy* policy)
98 : extension_service_(service), 98 : extension_service_(service),
99 management_policy_(policy), 99 management_policy_(policy),
100 ignore_notifications_(false), 100 ignore_notifications_(false),
101 deleting_rvh_(NULL), 101 deleting_rvh_(NULL),
102 registered_for_notifications_(false) { 102 registered_for_notifications_(false),
103 ALLOW_THIS_IN_INITIALIZER_LIST(warning_service_observer_(this)) {
103 } 104 }
104 105
105 // static 106 // static
106 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { 107 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) {
107 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, 108 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode,
108 false, 109 false,
109 PrefService::SYNCABLE_PREF); 110 PrefService::SYNCABLE_PREF);
110 } 111 }
111 112
112 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( 113 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
113 const Extension* extension, 114 const Extension* extension,
114 const std::vector<ExtensionPage>& pages, 115 const std::vector<ExtensionPage>& pages,
115 const ExtensionWarningSet* warnings_set) { 116 const extensions::ExtensionWarningService* warning_service) {
116 DictionaryValue* extension_data = new DictionaryValue(); 117 DictionaryValue* extension_data = new DictionaryValue();
117 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); 118 bool enabled = extension_service_->IsExtensionEnabled(extension->id());
118 extension->GetBasicInfo(enabled, extension_data); 119 extension->GetBasicInfo(enabled, extension_data);
119 120
120 extension_data->SetBoolean("userModifiable", 121 extension_data->SetBoolean("userModifiable",
121 management_policy_->UserMayModifySettings(extension, NULL)); 122 management_policy_->UserMayModifySettings(extension, NULL));
122 123
123 GURL icon = 124 GURL icon =
124 ExtensionIconSource::GetIconURL(extension, 125 ExtensionIconSource::GetIconURL(extension,
125 extension_misc::EXTENSION_ICON_MEDIUM, 126 extension_misc::EXTENSION_ICON_MEDIUM,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 198 }
198 extension_data->Set("views", views); 199 extension_data->Set("views", views);
199 extensions::ExtensionActionManager* extension_action_manager = 200 extensions::ExtensionActionManager* extension_action_manager =
200 extensions::ExtensionActionManager::Get(extension_service_->profile()); 201 extensions::ExtensionActionManager::Get(extension_service_->profile());
201 extension_data->SetBoolean( 202 extension_data->SetBoolean(
202 "hasPopupAction", 203 "hasPopupAction",
203 extension_action_manager->GetBrowserAction(*extension) || 204 extension_action_manager->GetBrowserAction(*extension) ||
204 extension_action_manager->GetPageAction(*extension)); 205 extension_action_manager->GetPageAction(*extension));
205 206
206 // Add warnings. 207 // Add warnings.
207 if (warnings_set) { 208 if (warning_service) {
208 std::set<ExtensionWarningSet::WarningType> warnings; 209 std::vector<std::string> warnings =
209 warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); 210 warning_service->GetWarningMessagesForExtension(extension->id());
210 211
211 if (!warnings.empty()) { 212 if (!warnings.empty()) {
212 ListValue* warnings_list = new ListValue; 213 ListValue* warnings_list = new ListValue;
213 for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = 214 for (std::vector<std::string>::const_iterator iter = warnings.begin();
214 warnings.begin(); 215 iter != warnings.end(); ++iter) {
215 iter != warnings.end(); 216 warnings_list->Append(Value::CreateStringValue(*iter));
216 ++iter) {
217 string16 warning_string(
218 ExtensionWarningSet::GetLocalizedWarning(*iter));
219 warnings_list->Append(Value::CreateStringValue(warning_string));
220 } 217 }
221 extension_data->Set("warnings", warnings_list); 218 extension_data->Set("warnings", warnings_list);
222 } 219 }
223 } 220 }
224 221
225 // Add install warnings (these are not the same as warnings!). 222 // Add install warnings (these are not the same as warnings!).
226 if (extension->location() == Extension::LOAD) { 223 if (extension->location() == Extension::LOAD) {
227 const Extension::InstallWarningVector& install_warnings = 224 const Extension::InstallWarningVector& install_warnings =
228 extension->install_warnings(); 225 extension->install_warnings();
229 if (!install_warnings.empty()) { 226 if (!install_warnings.empty()) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: 432 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED:
436 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: 433 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED:
437 source_profile = content::Source<Profile>(source).ptr(); 434 source_profile = content::Source<Profile>(source).ptr();
438 if (!profile->IsSameProfile(source_profile)) 435 if (!profile->IsSameProfile(source_profile))
439 return; 436 return;
440 MaybeUpdateAfterNotification(); 437 MaybeUpdateAfterNotification();
441 break; 438 break;
442 case chrome::NOTIFICATION_EXTENSION_LOADED: 439 case chrome::NOTIFICATION_EXTENSION_LOADED:
443 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 440 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
444 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: 441 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
445 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED:
446 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: 442 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED:
447 MaybeUpdateAfterNotification(); 443 MaybeUpdateAfterNotification();
448 break; 444 break;
449 default: 445 default:
450 NOTREACHED(); 446 NOTREACHED();
451 } 447 }
452 } 448 }
453 449
454 void ExtensionSettingsHandler::OnPreferenceChanged( 450 void ExtensionSettingsHandler::OnPreferenceChanged(
455 PrefServiceBase* service, 451 PrefServiceBase* service,
(...skipping 26 matching lines...) Expand all
482 // There will be no EXTENSION_UNLOADED notification for terminated 478 // There will be no EXTENSION_UNLOADED notification for terminated
483 // extensions as they were already unloaded. 479 // extensions as they were already unloaded.
484 if (was_terminated) 480 if (was_terminated)
485 HandleRequestExtensionsData(NULL); 481 HandleRequestExtensionsData(NULL);
486 } 482 }
487 483
488 void ExtensionSettingsHandler::ExtensionUninstallCanceled() { 484 void ExtensionSettingsHandler::ExtensionUninstallCanceled() {
489 extension_id_prompting_ = ""; 485 extension_id_prompting_ = "";
490 } 486 }
491 487
488 void ExtensionSettingsHandler::ExtensionWarningsChanged() {
489 MaybeUpdateAfterNotification();
490 }
491
492 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { 492 void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
493 const ExtensionSet* extensions = extension_service_->extensions(); 493 const ExtensionSet* extensions = extension_service_->extensions();
494 std::vector<const Extension*> unpacked_extensions; 494 std::vector<const Extension*> unpacked_extensions;
495 for (ExtensionSet::const_iterator extension = extensions->begin(); 495 for (ExtensionSet::const_iterator extension = extensions->begin();
496 extension != extensions->end(); ++extension) { 496 extension != extensions->end(); ++extension) {
497 if ((*extension)->location() == Extension::LOAD) 497 if ((*extension)->location() == Extension::LOAD)
498 unpacked_extensions.push_back(*extension); 498 unpacked_extensions.push_back(*extension);
499 } 499 }
500 500
501 for (std::vector<const Extension*>::iterator iter = 501 for (std::vector<const Extension*>::iterator iter =
502 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { 502 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) {
503 extension_service_->ReloadExtension((*iter)->id()); 503 extension_service_->ReloadExtension((*iter)->id());
504 } 504 }
505 } 505 }
506 506
507 void ExtensionSettingsHandler::HandleRequestExtensionsData( 507 void ExtensionSettingsHandler::HandleRequestExtensionsData(
508 const ListValue* args) { 508 const ListValue* args) {
509 DictionaryValue results; 509 DictionaryValue results;
510 510
511 Profile* profile = Profile::FromWebUI(web_ui());
512
511 // Add the extensions to the results structure. 513 // Add the extensions to the results structure.
512 ListValue *extensions_list = new ListValue(); 514 ListValue *extensions_list = new ListValue();
513 515
514 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); 516 extensions::ExtensionWarningService* warnings =
517 extensions::ExtensionSystem::Get(profile)->warning_service();
515 518
516 const ExtensionSet* extensions = extension_service_->extensions(); 519 const ExtensionSet* extensions = extension_service_->extensions();
517 for (ExtensionSet::const_iterator extension = extensions->begin(); 520 for (ExtensionSet::const_iterator extension = extensions->begin();
518 extension != extensions->end(); ++extension) { 521 extension != extensions->end(); ++extension) {
519 if ((*extension)->ShouldDisplayInExtensionSettings()) { 522 if ((*extension)->ShouldDisplayInExtensionSettings()) {
520 extensions_list->Append(CreateExtensionDetailValue( 523 extensions_list->Append(CreateExtensionDetailValue(
521 *extension, 524 *extension,
522 GetInspectablePagesForExtension(*extension, true), 525 GetInspectablePagesForExtension(*extension, true),
523 warnings)); 526 warnings));
524 } 527 }
(...skipping 19 matching lines...) Expand all
544 warnings)); 547 warnings));
545 } 548 }
546 } 549 }
547 results.Set("extensions", extensions_list); 550 results.Set("extensions", extensions_list);
548 551
549 if (ManagedMode::IsInManagedMode()) { 552 if (ManagedMode::IsInManagedMode()) {
550 results.SetBoolean("managedMode", true); 553 results.SetBoolean("managedMode", true);
551 results.SetBoolean("developerMode", false); 554 results.SetBoolean("developerMode", false);
552 } else { 555 } else {
553 results.SetBoolean("managedMode", false); 556 results.SetBoolean("managedMode", false);
554 Profile* profile = Profile::FromWebUI(web_ui()); 557
555 bool developer_mode = 558 bool developer_mode =
556 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); 559 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
557 results.SetBoolean("developerMode", developer_mode); 560 results.SetBoolean("developerMode", developer_mode);
558 } 561 }
559 562
560 // Check to see if we have any wiped out extensions. 563 // Check to see if we have any wiped out extensions.
561 Profile* profile = Profile::FromWebUI(web_ui());
562 ExtensionService* extension_service = 564 ExtensionService* extension_service =
563 extensions::ExtensionSystem::Get(profile)->extension_service(); 565 extensions::ExtensionSystem::Get(profile)->extension_service();
564 scoped_ptr<const ExtensionSet> wiped_out( 566 scoped_ptr<const ExtensionSet> wiped_out(
565 extension_service->GetWipedOutExtensions()); 567 extension_service->GetWipedOutExtensions());
566 results.SetBoolean("showDisabledExtensionsWarning", wiped_out->size() > 0); 568 results.SetBoolean("showDisabledExtensionsWarning", wiped_out->size() > 0);
567 569
568 bool load_unpacked_disabled = 570 bool load_unpacked_disabled =
569 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); 571 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault();
570 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); 572 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled);
571 573
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 registered_for_notifications_ = true; 819 registered_for_notifications_ = true;
818 Profile* profile = Profile::FromWebUI(web_ui()); 820 Profile* profile = Profile::FromWebUI(web_ui());
819 821
820 // Register for notifications that we need to reload the page. 822 // Register for notifications that we need to reload the page.
821 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 823 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
822 content::Source<Profile>(profile)); 824 content::Source<Profile>(profile));
823 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 825 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
824 content::Source<Profile>(profile)); 826 content::Source<Profile>(profile));
825 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 827 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
826 content::Source<Profile>(profile)); 828 content::Source<Profile>(profile));
827 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED,
828 content::Source<Profile>(profile));
829 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 829 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
830 content::NotificationService::AllBrowserContextsAndSources()); 830 content::NotificationService::AllBrowserContextsAndSources());
831 registrar_.Add(this, 831 registrar_.Add(this,
832 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, 832 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
833 content::NotificationService::AllBrowserContextsAndSources()); 833 content::NotificationService::AllBrowserContextsAndSources());
834 registrar_.Add(this, 834 registrar_.Add(this,
835 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, 835 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
836 content::NotificationService::AllBrowserContextsAndSources()); 836 content::NotificationService::AllBrowserContextsAndSources());
837 registrar_.Add(this, 837 registrar_.Add(this,
838 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 838 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
839 content::NotificationService::AllBrowserContextsAndSources()); 839 content::NotificationService::AllBrowserContextsAndSources());
840 registrar_.Add(this, 840 registrar_.Add(this,
841 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 841 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
842 content::NotificationService::AllBrowserContextsAndSources()); 842 content::NotificationService::AllBrowserContextsAndSources());
843 registrar_.Add( 843 registrar_.Add(
844 this, 844 this,
845 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 845 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
846 content::Source<extensions::ExtensionPrefs>( 846 content::Source<extensions::ExtensionPrefs>(
847 profile->GetExtensionService()->extension_prefs())); 847 profile->GetExtensionService()->extension_prefs()));
848 848
849 warning_service_observer_.Add(
850 extensions::ExtensionSystem::Get(profile)->warning_service());
851
849 pref_registrar_.Init(profile->GetPrefs()); 852 pref_registrar_.Init(profile->GetPrefs());
850 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); 853 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this);
851 local_state_pref_registrar_.Init(g_browser_process->local_state()); 854 local_state_pref_registrar_.Init(g_browser_process->local_state());
852 local_state_pref_registrar_.Add(prefs::kInManagedMode, this); 855 local_state_pref_registrar_.Add(prefs::kInManagedMode, this);
853 } 856 }
854 857
855 std::vector<ExtensionPage> 858 std::vector<ExtensionPage>
856 ExtensionSettingsHandler::GetInspectablePagesForExtension( 859 ExtensionSettingsHandler::GetInspectablePagesForExtension(
857 const Extension* extension, bool extension_is_enabled) { 860 const Extension* extension, bool extension_is_enabled) {
858 std::vector<ExtensionPage> result; 861 std::vector<ExtensionPage> result;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 std::vector<std::string> requirement_errors) { 965 std::vector<std::string> requirement_errors) {
963 if (requirement_errors.empty()) { 966 if (requirement_errors.empty()) {
964 extension_service_->EnableExtension(extension_id); 967 extension_service_->EnableExtension(extension_id);
965 } else { 968 } else {
966 ExtensionErrorReporter::GetInstance()->ReportError( 969 ExtensionErrorReporter::GetInstance()->ReportError(
967 UTF8ToUTF16(JoinString(requirement_errors, ' ')), 970 UTF8ToUTF16(JoinString(requirement_errors, ' ')),
968 true /* be noisy */); 971 true /* be noisy */);
969 } 972 }
970 requirements_checker_.reset(); 973 requirements_checker_.reset();
971 } 974 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698