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

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

Issue 8176001: Warn user in case extension delays network traffic too much. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed Glen's comments Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/options/extension_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 base::Unretained(this))); 135 base::Unretained(this)));
136 } 136 }
137 137
138 void ExtensionSettingsHandler::HandleRequestExtensionsData( 138 void ExtensionSettingsHandler::HandleRequestExtensionsData(
139 const ListValue* args) { 139 const ListValue* args) {
140 DictionaryValue results; 140 DictionaryValue results;
141 141
142 // Add the extensions to the results structure. 142 // Add the extensions to the results structure.
143 ListValue *extensions_list = new ListValue(); 143 ListValue *extensions_list = new ListValue();
144 144
145 ExtensionService::ExtensionWarningsType warnings =
146 extension_service_->GetWarnings();
147
145 const ExtensionList* extensions = extension_service_->extensions(); 148 const ExtensionList* extensions = extension_service_->extensions();
146 for (ExtensionList::const_iterator extension = extensions->begin(); 149 for (ExtensionList::const_iterator extension = extensions->begin();
147 extension != extensions->end(); ++extension) { 150 extension != extensions->end(); ++extension) {
148 if (ShouldShowExtension(*extension)) { 151 if (ShouldShowExtension(*extension)) {
149 extensions_list->Append(CreateExtensionDetailValue( 152 extensions_list->Append(CreateExtensionDetailValue(
150 extension_service_, 153 extension_service_,
151 *extension, 154 *extension,
152 GetActivePagesForExtension(*extension), 155 GetActivePagesForExtension(*extension),
156 warnings,
153 true, false)); // enabled, terminated 157 true, false)); // enabled, terminated
154 } 158 }
155 } 159 }
156 extensions = extension_service_->disabled_extensions(); 160 extensions = extension_service_->disabled_extensions();
157 for (ExtensionList::const_iterator extension = extensions->begin(); 161 for (ExtensionList::const_iterator extension = extensions->begin();
158 extension != extensions->end(); ++extension) { 162 extension != extensions->end(); ++extension) {
159 if (ShouldShowExtension(*extension)) { 163 if (ShouldShowExtension(*extension)) {
160 extensions_list->Append(CreateExtensionDetailValue( 164 extensions_list->Append(CreateExtensionDetailValue(
161 extension_service_, 165 extension_service_,
162 *extension, 166 *extension,
163 GetActivePagesForExtension(*extension), 167 GetActivePagesForExtension(*extension),
168 warnings,
164 false, false)); // enabled, terminated 169 false, false)); // enabled, terminated
165 } 170 }
166 } 171 }
167 extensions = extension_service_->terminated_extensions(); 172 extensions = extension_service_->terminated_extensions();
168 std::vector<ExtensionPage> empty_pages; 173 std::vector<ExtensionPage> empty_pages;
169 for (ExtensionList::const_iterator extension = extensions->begin(); 174 for (ExtensionList::const_iterator extension = extensions->begin();
170 extension != extensions->end(); ++extension) { 175 extension != extensions->end(); ++extension) {
171 if (ShouldShowExtension(*extension)) { 176 if (ShouldShowExtension(*extension)) {
172 extensions_list->Append(CreateExtensionDetailValue( 177 extensions_list->Append(CreateExtensionDetailValue(
173 extension_service_, 178 extension_service_,
174 *extension, 179 *extension,
175 empty_pages, // Terminated process has no active pages. 180 empty_pages, // Terminated process has no active pages.
181 warnings,
176 false, true)); // enabled, terminated 182 false, true)); // enabled, terminated
177 } 183 }
178 } 184 }
179 results.Set("extensions", extensions_list); 185 results.Set("extensions", extensions_list);
180 186
181 Profile* profile = Profile::FromWebUI(web_ui_); 187 Profile* profile = Profile::FromWebUI(web_ui_);
182 bool developer_mode = 188 bool developer_mode =
183 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); 189 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
184 results.SetBoolean("developerMode", developer_mode); 190 results.SetBoolean("developerMode", developer_mode);
185 191
(...skipping 11 matching lines...) Expand all
197 203
198 // Register for notifications that we need to reload the page. 204 // Register for notifications that we need to reload the page.
199 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
200 NotificationService::AllSources()); 206 NotificationService::AllSources());
201 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, 207 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED,
202 NotificationService::AllSources()); 208 NotificationService::AllSources());
203 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 209 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
204 NotificationService::AllSources()); 210 NotificationService::AllSources());
205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 211 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
206 NotificationService::AllSources()); 212 NotificationService::AllSources());
213 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING,
214 NotificationService::AllSources());
207 registrar_.Add(this, 215 registrar_.Add(this,
208 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 216 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
209 NotificationService::AllSources()); 217 NotificationService::AllSources());
210 registrar_.Add(this, 218 registrar_.Add(this,
211 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, 219 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
212 NotificationService::AllSources()); 220 NotificationService::AllSources());
213 registrar_.Add(this, 221 registrar_.Add(this,
214 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, 222 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
215 NotificationService::AllSources()); 223 NotificationService::AllSources());
216 registrar_.Add(this, 224 registrar_.Add(this,
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 localized_strings->SetString("extensionSettingsLoadUnpackedButton", 555 localized_strings->SetString("extensionSettingsLoadUnpackedButton",
548 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); 556 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON));
549 localized_strings->SetString("extensionSettingsPackButton", 557 localized_strings->SetString("extensionSettingsPackButton",
550 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); 558 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON));
551 localized_strings->SetString("extensionSettingsUpdateButton", 559 localized_strings->SetString("extensionSettingsUpdateButton",
552 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); 560 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON));
553 localized_strings->SetString("extensionSettingsCrashMessage", 561 localized_strings->SetString("extensionSettingsCrashMessage",
554 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); 562 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION));
555 localized_strings->SetString("extensionSettingsInDevelopment", 563 localized_strings->SetString("extensionSettingsInDevelopment",
556 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); 564 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT));
565 localized_strings->SetString("extensionSettingsWarningsTitle",
566 l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE));
557 } 567 }
558 568
559 void ExtensionSettingsHandler::Initialize() { 569 void ExtensionSettingsHandler::Initialize() {
560 } 570 }
561 571
562 WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) { 572 WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) {
563 // Call through to superclass. 573 // Call through to superclass.
564 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); 574 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui);
565 575
566 extension_service_ = Profile::FromWebUI(web_ui_) 576 extension_service_ = Profile::FromWebUI(web_ui_)
(...skipping 26 matching lines...) Expand all
593 MaybeUpdateAfterNotification(); 603 MaybeUpdateAfterNotification();
594 break; 604 break;
595 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: 605 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED:
596 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); 606 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host();
597 MaybeUpdateAfterNotification(); 607 MaybeUpdateAfterNotification();
598 break; 608 break;
599 case chrome::NOTIFICATION_EXTENSION_LOADED: 609 case chrome::NOTIFICATION_EXTENSION_LOADED:
600 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: 610 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED:
601 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 611 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
602 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: 612 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
613 case chrome::NOTIFICATION_EXTENSION_WARNING:
603 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: 614 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED:
604 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: 615 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
605 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: 616 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED:
606 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: 617 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED:
607 MaybeUpdateAfterNotification(); 618 MaybeUpdateAfterNotification();
608 break; 619 break;
609 default: 620 default:
610 NOTREACHED(); 621 NOTREACHED();
611 } 622 }
612 } 623 }
613 624
614 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { 625 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) {
615 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); 626 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args));
616 CHECK(!extension_id.empty()); 627 CHECK(!extension_id.empty());
617 return extension_service_->GetExtensionById(extension_id, true); 628 return extension_service_->GetExtensionById(extension_id, true);
618 } 629 }
619 630
620 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { 631 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() {
621 TabContents* contents = web_ui_->tab_contents(); 632 TabContents* contents = web_ui_->tab_contents();
622 if (!ignore_notifications_ && contents && contents->render_view_host()) 633 if (!ignore_notifications_ && contents && contents->render_view_host())
623 HandleRequestExtensionsData(NULL); 634 HandleRequestExtensionsData(NULL);
624 deleting_rvh_ = NULL; 635 deleting_rvh_ = NULL;
625 } 636 }
626 637
627 // Static 638 // Static
639 string16 ExtensionSettingsHandler::GetLocalizedWarning(
640 const ExtensionServiceWarning& warning) {
641 switch (warning.warning_type()) {
642 case ExtensionServiceWarning::kInvalid:
643 case ExtensionServiceWarning::kMaxWarningType:
644 NOTREACHED();
645 return string16();
646 case ExtensionServiceWarning::kNetworkDelay:
647 return l10n_util::GetStringFUTF16(
648 IDS_EXTENSION_WARNINGS_NETWORK_DELAY,
649 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
650 }
651 return string16();
652 }
653
654 // Static
628 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( 655 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
629 ExtensionService* service, const Extension* extension, 656 ExtensionService* service, const Extension* extension,
630 const std::vector<ExtensionPage>& pages, bool enabled, bool terminated) { 657 const std::vector<ExtensionPage>& pages,
658 const ExtensionService::ExtensionWarningsType& warnings,
659 bool enabled, bool terminated) {
631 DictionaryValue* extension_data = new DictionaryValue(); 660 DictionaryValue* extension_data = new DictionaryValue();
632 GURL icon = 661 GURL icon =
633 ExtensionIconSource::GetIconURL(extension, 662 ExtensionIconSource::GetIconURL(extension,
634 Extension::EXTENSION_ICON_MEDIUM, 663 Extension::EXTENSION_ICON_MEDIUM,
635 ExtensionIconSet::MATCH_BIGGER, 664 ExtensionIconSet::MATCH_BIGGER,
636 !enabled, NULL); 665 !enabled, NULL);
637 extension_data->SetString("id", extension->id()); 666 extension_data->SetString("id", extension->id());
638 extension_data->SetString("name", extension->name()); 667 extension_data->SetString("name", extension->name());
639 extension_data->SetString("description", extension->description()); 668 extension_data->SetString("description", extension->description());
640 if (extension->location() == Extension::LOAD) 669 if (extension->location() == Extension::LOAD)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 view_value->SetInteger("renderViewId", iter->render_view_id); 713 view_value->SetInteger("renderViewId", iter->render_view_id);
685 view_value->SetInteger("renderProcessId", iter->render_process_id); 714 view_value->SetInteger("renderProcessId", iter->render_process_id);
686 view_value->SetBoolean("incognito", iter->incognito); 715 view_value->SetBoolean("incognito", iter->incognito);
687 views->Append(view_value); 716 views->Append(view_value);
688 } 717 }
689 extension_data->Set("views", views); 718 extension_data->Set("views", views);
690 extension_data->SetBoolean("hasPopupAction", 719 extension_data->SetBoolean("hasPopupAction",
691 extension->browser_action() || extension->page_action()); 720 extension->browser_action() || extension->page_action());
692 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); 721 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec());
693 722
723 // Add warnings.
724 ListValue* warnings_list = new ListValue;
725 for (ExtensionService::ExtensionWarningsType::const_iterator iter =
726 warnings.begin();
727 iter != warnings.end();
728 ++iter) {
729 if (iter->second.AffectsExtension(extension->id())) {
730 warnings_list->Append(
731 Value::CreateStringValue(GetLocalizedWarning(iter->second)));
732 }
733 }
734 extension_data->Set("warnings", warnings_list);
735
694 return extension_data; 736 return extension_data;
695 } 737 }
696 738
697 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( 739 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension(
698 const Extension* extension) { 740 const Extension* extension) {
699 std::vector<ExtensionPage> result; 741 std::vector<ExtensionPage> result;
700 742
701 // Get the extension process's active views. 743 // Get the extension process's active views.
702 ExtensionProcessManager* process_manager = 744 ExtensionProcessManager* process_manager =
703 extension_service_->profile()->GetExtensionProcessManager(); 745 extension_service_->profile()->GetExtensionProcessManager();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 continue; 788 continue;
747 } else if (!extension->web_extent().MatchesURL(url)) { 789 } else if (!extension->web_extent().MatchesURL(url)) {
748 continue; 790 continue;
749 } 791 }
750 792
751 result->push_back( 793 result->push_back(
752 ExtensionPage(url, process->id(), host->routing_id(), 794 ExtensionPage(url, process->id(), host->routing_id(),
753 process->browser_context()->IsOffTheRecord())); 795 process->browser_context()->IsOffTheRecord()));
754 } 796 }
755 } 797 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698