| OLD | NEW |
| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "chrome/browser/debugger/devtools_window.h" | 16 #include "chrome/browser/debugger/devtools_window.h" |
| 17 #include "chrome/browser/extensions/crx_installer.h" | 17 #include "chrome/browser/extensions/crx_installer.h" |
| 18 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 18 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_updater.h" | 20 #include "chrome/browser/extensions/extension_updater.h" |
| 21 #include "chrome/browser/extensions/extension_warning_set.h" |
| 21 #include "chrome/browser/google/google_util.h" | 22 #include "chrome/browser/google/google_util.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/tab_contents/background_contents.h" | 24 #include "chrome/browser/tab_contents/background_contents.h" |
| 24 #include "chrome/browser/ui/webui/extension_icon_source.h" | 25 #include "chrome/browser/ui/webui/extension_icon_source.h" |
| 25 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/common/chrome_view_types.h" | 29 #include "chrome/common/chrome_view_types.h" |
| 29 #include "content/browser/browsing_instance.h" | 30 #include "content/browser/browsing_instance.h" |
| 30 #include "content/browser/renderer_host/render_process_host.h" | 31 #include "content/browser/renderer_host/render_process_host.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 base::Unretained(this))); | 137 base::Unretained(this))); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 140 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 140 const ListValue* args) { | 141 const ListValue* args) { |
| 141 DictionaryValue results; | 142 DictionaryValue results; |
| 142 | 143 |
| 143 // Add the extensions to the results structure. | 144 // Add the extensions to the results structure. |
| 144 ListValue *extensions_list = new ListValue(); | 145 ListValue *extensions_list = new ListValue(); |
| 145 | 146 |
| 147 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); |
| 148 |
| 146 const ExtensionList* extensions = extension_service_->extensions(); | 149 const ExtensionList* extensions = extension_service_->extensions(); |
| 147 for (ExtensionList::const_iterator extension = extensions->begin(); | 150 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 148 extension != extensions->end(); ++extension) { | 151 extension != extensions->end(); ++extension) { |
| 149 if (ShouldShowExtension(*extension)) { | 152 if (ShouldShowExtension(*extension)) { |
| 150 extensions_list->Append(CreateExtensionDetailValue( | 153 extensions_list->Append(CreateExtensionDetailValue( |
| 151 extension_service_, | 154 extension_service_, |
| 152 *extension, | 155 *extension, |
| 153 GetActivePagesForExtension(*extension), | 156 GetActivePagesForExtension(*extension), |
| 157 warnings, |
| 154 true, false)); // enabled, terminated | 158 true, false)); // enabled, terminated |
| 155 } | 159 } |
| 156 } | 160 } |
| 157 extensions = extension_service_->disabled_extensions(); | 161 extensions = extension_service_->disabled_extensions(); |
| 158 for (ExtensionList::const_iterator extension = extensions->begin(); | 162 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 159 extension != extensions->end(); ++extension) { | 163 extension != extensions->end(); ++extension) { |
| 160 if (ShouldShowExtension(*extension)) { | 164 if (ShouldShowExtension(*extension)) { |
| 161 extensions_list->Append(CreateExtensionDetailValue( | 165 extensions_list->Append(CreateExtensionDetailValue( |
| 162 extension_service_, | 166 extension_service_, |
| 163 *extension, | 167 *extension, |
| 164 GetActivePagesForExtension(*extension), | 168 GetActivePagesForExtension(*extension), |
| 169 warnings, |
| 165 false, false)); // enabled, terminated | 170 false, false)); // enabled, terminated |
| 166 } | 171 } |
| 167 } | 172 } |
| 168 extensions = extension_service_->terminated_extensions(); | 173 extensions = extension_service_->terminated_extensions(); |
| 169 std::vector<ExtensionPage> empty_pages; | 174 std::vector<ExtensionPage> empty_pages; |
| 170 for (ExtensionList::const_iterator extension = extensions->begin(); | 175 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 171 extension != extensions->end(); ++extension) { | 176 extension != extensions->end(); ++extension) { |
| 172 if (ShouldShowExtension(*extension)) { | 177 if (ShouldShowExtension(*extension)) { |
| 173 extensions_list->Append(CreateExtensionDetailValue( | 178 extensions_list->Append(CreateExtensionDetailValue( |
| 174 extension_service_, | 179 extension_service_, |
| 175 *extension, | 180 *extension, |
| 176 empty_pages, // Terminated process has no active pages. | 181 empty_pages, // Terminated process has no active pages. |
| 182 warnings, |
| 177 false, true)); // enabled, terminated | 183 false, true)); // enabled, terminated |
| 178 } | 184 } |
| 179 } | 185 } |
| 180 results.Set("extensions", extensions_list); | 186 results.Set("extensions", extensions_list); |
| 181 | 187 |
| 182 Profile* profile = Profile::FromWebUI(web_ui_); | 188 Profile* profile = Profile::FromWebUI(web_ui_); |
| 183 bool developer_mode = | 189 bool developer_mode = |
| 184 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 190 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 185 results.SetBoolean("developerMode", developer_mode); | 191 results.SetBoolean("developerMode", developer_mode); |
| 186 | 192 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 199 | 205 |
| 200 // Register for notifications that we need to reload the page. | 206 // Register for notifications that we need to reload the page. |
| 201 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 207 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 202 Source<Profile>(profile)); | 208 Source<Profile>(profile)); |
| 203 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, | 209 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
| 204 Source<Profile>(profile)); | 210 Source<Profile>(profile)); |
| 205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 211 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 206 Source<Profile>(profile)); | 212 Source<Profile>(profile)); |
| 207 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 213 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 208 Source<Profile>(profile)); | 214 Source<Profile>(profile)); |
| 215 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, |
| 216 Source<Profile>(profile)); |
| 209 registrar_.Add(this, | 217 registrar_.Add(this, |
| 210 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 218 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 211 NotificationService::AllBrowserContextsAndSources()); | 219 NotificationService::AllBrowserContextsAndSources()); |
| 212 registrar_.Add(this, | 220 registrar_.Add(this, |
| 213 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 221 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 214 NotificationService::AllBrowserContextsAndSources()); | 222 NotificationService::AllBrowserContextsAndSources()); |
| 215 registrar_.Add(this, | 223 registrar_.Add(this, |
| 216 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 224 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| 217 NotificationService::AllBrowserContextsAndSources()); | 225 NotificationService::AllBrowserContextsAndSources()); |
| 218 registrar_.Add(this, | 226 registrar_.Add(this, |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 localized_strings->SetString("extensionSettingsLoadUnpackedButton", | 559 localized_strings->SetString("extensionSettingsLoadUnpackedButton", |
| 552 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); | 560 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); |
| 553 localized_strings->SetString("extensionSettingsPackButton", | 561 localized_strings->SetString("extensionSettingsPackButton", |
| 554 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); | 562 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); |
| 555 localized_strings->SetString("extensionSettingsUpdateButton", | 563 localized_strings->SetString("extensionSettingsUpdateButton", |
| 556 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); | 564 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); |
| 557 localized_strings->SetString("extensionSettingsCrashMessage", | 565 localized_strings->SetString("extensionSettingsCrashMessage", |
| 558 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); | 566 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); |
| 559 localized_strings->SetString("extensionSettingsInDevelopment", | 567 localized_strings->SetString("extensionSettingsInDevelopment", |
| 560 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); | 568 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); |
| 569 localized_strings->SetString("extensionSettingsWarningsTitle", |
| 570 l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE)); |
| 561 } | 571 } |
| 562 | 572 |
| 563 void ExtensionSettingsHandler::Initialize() { | 573 void ExtensionSettingsHandler::Initialize() { |
| 564 } | 574 } |
| 565 | 575 |
| 566 WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) { | 576 WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) { |
| 567 // Call through to superclass. | 577 // Call through to superclass. |
| 568 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); | 578 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); |
| 569 | 579 |
| 570 extension_service_ = Profile::FromWebUI(web_ui_) | 580 extension_service_ = Profile::FromWebUI(web_ui_) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 source_profile = Profile::FromBrowserContext( | 628 source_profile = Profile::FromBrowserContext( |
| 619 Source<NavigationController>(source).ptr()->browser_context()); | 629 Source<NavigationController>(source).ptr()->browser_context()); |
| 620 if (!profile->IsSameProfile(source_profile)) | 630 if (!profile->IsSameProfile(source_profile)) |
| 621 return; | 631 return; |
| 622 MaybeUpdateAfterNotification(); | 632 MaybeUpdateAfterNotification(); |
| 623 break; | 633 break; |
| 624 case chrome::NOTIFICATION_EXTENSION_LOADED: | 634 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 625 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: | 635 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: |
| 626 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 636 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 627 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 637 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 638 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| 628 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 639 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 629 MaybeUpdateAfterNotification(); | 640 MaybeUpdateAfterNotification(); |
| 630 break; | 641 break; |
| 631 default: | 642 default: |
| 632 NOTREACHED(); | 643 NOTREACHED(); |
| 633 } | 644 } |
| 634 } | 645 } |
| 635 | 646 |
| 636 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { | 647 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
| 637 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 648 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| 638 CHECK(!extension_id.empty()); | 649 CHECK(!extension_id.empty()); |
| 639 return extension_service_->GetExtensionById(extension_id, true); | 650 return extension_service_->GetExtensionById(extension_id, true); |
| 640 } | 651 } |
| 641 | 652 |
| 642 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { | 653 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| 643 TabContents* contents = web_ui_->tab_contents(); | 654 TabContents* contents = web_ui_->tab_contents(); |
| 644 if (!ignore_notifications_ && contents && contents->render_view_host()) | 655 if (!ignore_notifications_ && contents && contents->render_view_host()) |
| 645 HandleRequestExtensionsData(NULL); | 656 HandleRequestExtensionsData(NULL); |
| 646 deleting_rvh_ = NULL; | 657 deleting_rvh_ = NULL; |
| 647 } | 658 } |
| 648 | 659 |
| 649 // Static | 660 // Static |
| 650 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 661 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| 651 ExtensionService* service, const Extension* extension, | 662 ExtensionService* service, const Extension* extension, |
| 652 const std::vector<ExtensionPage>& pages, bool enabled, bool terminated) { | 663 const std::vector<ExtensionPage>& pages, |
| 664 const ExtensionWarningSet* warnings_set, |
| 665 bool enabled, bool terminated) { |
| 653 DictionaryValue* extension_data = new DictionaryValue(); | 666 DictionaryValue* extension_data = new DictionaryValue(); |
| 654 GURL icon = | 667 GURL icon = |
| 655 ExtensionIconSource::GetIconURL(extension, | 668 ExtensionIconSource::GetIconURL(extension, |
| 656 Extension::EXTENSION_ICON_MEDIUM, | 669 Extension::EXTENSION_ICON_MEDIUM, |
| 657 ExtensionIconSet::MATCH_BIGGER, | 670 ExtensionIconSet::MATCH_BIGGER, |
| 658 !enabled, NULL); | 671 !enabled, NULL); |
| 659 extension_data->SetString("id", extension->id()); | 672 extension_data->SetString("id", extension->id()); |
| 660 extension_data->SetString("name", extension->name()); | 673 extension_data->SetString("name", extension->name()); |
| 661 extension_data->SetString("description", extension->description()); | 674 extension_data->SetString("description", extension->description()); |
| 662 if (extension->location() == Extension::LOAD) | 675 if (extension->location() == Extension::LOAD) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 view_value->SetInteger("renderViewId", iter->render_view_id); | 719 view_value->SetInteger("renderViewId", iter->render_view_id); |
| 707 view_value->SetInteger("renderProcessId", iter->render_process_id); | 720 view_value->SetInteger("renderProcessId", iter->render_process_id); |
| 708 view_value->SetBoolean("incognito", iter->incognito); | 721 view_value->SetBoolean("incognito", iter->incognito); |
| 709 views->Append(view_value); | 722 views->Append(view_value); |
| 710 } | 723 } |
| 711 extension_data->Set("views", views); | 724 extension_data->Set("views", views); |
| 712 extension_data->SetBoolean("hasPopupAction", | 725 extension_data->SetBoolean("hasPopupAction", |
| 713 extension->browser_action() || extension->page_action()); | 726 extension->browser_action() || extension->page_action()); |
| 714 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); | 727 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); |
| 715 | 728 |
| 729 // Add warnings. |
| 730 ListValue* warnings_list = new ListValue; |
| 731 if (warnings_set) { |
| 732 std::set<ExtensionWarningSet::WarningType> warnings; |
| 733 warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); |
| 734 |
| 735 for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = |
| 736 warnings.begin(); |
| 737 iter != warnings.end(); |
| 738 ++iter) { |
| 739 string16 warning_string(ExtensionWarningSet::GetLocalizedWarning(*iter)); |
| 740 warnings_list->Append(Value::CreateStringValue(warning_string)); |
| 741 } |
| 742 } |
| 743 extension_data->Set("warnings", warnings_list); |
| 744 |
| 716 return extension_data; | 745 return extension_data; |
| 717 } | 746 } |
| 718 | 747 |
| 719 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( | 748 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( |
| 720 const Extension* extension) { | 749 const Extension* extension) { |
| 721 std::vector<ExtensionPage> result; | 750 std::vector<ExtensionPage> result; |
| 722 | 751 |
| 723 // Get the extension process's active views. | 752 // Get the extension process's active views. |
| 724 ExtensionProcessManager* process_manager = | 753 ExtensionProcessManager* process_manager = |
| 725 extension_service_->profile()->GetExtensionProcessManager(); | 754 extension_service_->profile()->GetExtensionProcessManager(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 continue; | 797 continue; |
| 769 } else if (!extension->web_extent().MatchesURL(url)) { | 798 } else if (!extension->web_extent().MatchesURL(url)) { |
| 770 continue; | 799 continue; |
| 771 } | 800 } |
| 772 | 801 |
| 773 result->push_back( | 802 result->push_back( |
| 774 ExtensionPage(url, process->id(), host->routing_id(), | 803 ExtensionPage(url, process->id(), host->routing_id(), |
| 775 process->browser_context()->IsOffTheRecord())); | 804 process->browser_context()->IsOffTheRecord())); |
| 776 } | 805 } |
| 777 } | 806 } |
| OLD | NEW |