| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions/extensions_ui.h" | 5 #include "chrome/browser/extensions/extensions_ui.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.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/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/thread.h" | 15 #include "base/thread.h" |
| 16 #include "base/version.h" | 16 #include "base/version.h" |
| 17 #include "chrome/browser/browser.h" | 17 #include "chrome/browser/browser.h" |
| 18 #include "chrome/browser/browser_list.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/debugger/devtools_manager.h" | 20 #include "chrome/browser/debugger/devtools_manager.h" |
| 20 #include "chrome/browser/debugger/devtools_toggle_action.h" | 21 #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 21 #include "chrome/browser/extensions/crx_installer.h" | 22 #include "chrome/browser/extensions/crx_installer.h" |
| 22 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 23 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| 23 #include "chrome/browser/extensions/extension_error_reporter.h" | 24 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 24 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 25 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 25 #include "chrome/browser/extensions/extension_host.h" | 26 #include "chrome/browser/extensions/extension_host.h" |
| 26 #include "chrome/browser/extensions/extension_message_service.h" | 27 #include "chrome/browser/extensions/extension_message_service.h" |
| 27 #include "chrome/browser/extensions/extensions_service.h" | 28 #include "chrome/browser/extensions/extensions_service.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 localized_strings.SetString("getMoreExtensions", | 109 localized_strings.SetString("getMoreExtensions", |
| 109 ASCIIToUTF16("<a href='") + | 110 ASCIIToUTF16("<a href='") + |
| 110 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | 111 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| 111 GURL(Extension::ChromeStoreURL())).spec()) + ASCIIToUTF16("'>") + | 112 GURL(Extension::ChromeStoreURL())).spec()) + ASCIIToUTF16("'>") + |
| 112 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS) + | 113 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS) + |
| 113 ASCIIToUTF16("</a>")); | 114 ASCIIToUTF16("</a>")); |
| 114 localized_strings.SetString("extensionDisabled", | 115 localized_strings.SetString("extensionDisabled", |
| 115 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLED_EXTENSION)); | 116 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLED_EXTENSION)); |
| 116 localized_strings.SetString("inDevelopment", | 117 localized_strings.SetString("inDevelopment", |
| 117 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); | 118 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); |
| 119 localized_strings.SetString("viewIncognito", |
| 120 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); |
| 118 localized_strings.SetString("extensionId", | 121 localized_strings.SetString("extensionId", |
| 119 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); | 122 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); |
| 120 localized_strings.SetString("extensionVersion", | 123 localized_strings.SetString("extensionVersion", |
| 121 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VERSION)); | 124 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VERSION)); |
| 122 localized_strings.SetString("inspectViews", | 125 localized_strings.SetString("inspectViews", |
| 123 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); | 126 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); |
| 124 localized_strings.SetString("inspectPopupsInstructions", | 127 localized_strings.SetString("inspectPopupsInstructions", |
| 125 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_POPUPS_INSTRUCTIONS)); | 128 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_POPUPS_INSTRUCTIONS)); |
| 126 localized_strings.SetString("disable", | 129 localized_strings.SetString("disable", |
| 127 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE)); | 130 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE)); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 313 |
| 311 // Add the extensions to the results structure. | 314 // Add the extensions to the results structure. |
| 312 ListValue *extensions_list = new ListValue(); | 315 ListValue *extensions_list = new ListValue(); |
| 313 | 316 |
| 314 // Stores the icon resource for each of the extensions in extensions_list. We | 317 // Stores the icon resource for each of the extensions in extensions_list. We |
| 315 // build up a list of them here, then load them on the file thread in | 318 // build up a list of them here, then load them on the file thread in |
| 316 // ::LoadIcons(). | 319 // ::LoadIcons(). |
| 317 std::vector<ExtensionResource>* extension_icons = | 320 std::vector<ExtensionResource>* extension_icons = |
| 318 new std::vector<ExtensionResource>(); | 321 new std::vector<ExtensionResource>(); |
| 319 | 322 |
| 320 ExtensionProcessManager* process_manager = | |
| 321 extensions_service_->profile()->GetExtensionProcessManager(); | |
| 322 const ExtensionList* extensions = extensions_service_->extensions(); | 323 const ExtensionList* extensions = extensions_service_->extensions(); |
| 323 for (ExtensionList::const_iterator extension = extensions->begin(); | 324 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 324 extension != extensions->end(); ++extension) { | 325 extension != extensions->end(); ++extension) { |
| 325 if (ShouldShowExtension(*extension)) { | 326 if (ShouldShowExtension(*extension)) { |
| 326 RenderProcessHost* process = | |
| 327 process_manager->GetExtensionProcess((*extension)->url()); | |
| 328 extensions_list->Append(CreateExtensionDetailValue( | 327 extensions_list->Append(CreateExtensionDetailValue( |
| 329 extensions_service_.get(), | 328 extensions_service_.get(), |
| 330 *extension, | 329 *extension, |
| 331 GetActivePagesForExtension(process, *extension), | 330 GetActivePagesForExtension(*extension), |
| 332 true)); // enabled | 331 true)); // enabled |
| 333 extension_icons->push_back(PickExtensionIcon(*extension)); | 332 extension_icons->push_back(PickExtensionIcon(*extension)); |
| 334 } | 333 } |
| 335 } | 334 } |
| 336 extensions = extensions_service_->disabled_extensions(); | 335 extensions = extensions_service_->disabled_extensions(); |
| 337 for (ExtensionList::const_iterator extension = extensions->begin(); | 336 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 338 extension != extensions->end(); ++extension) { | 337 extension != extensions->end(); ++extension) { |
| 339 if (ShouldShowExtension(*extension)) { | 338 if (ShouldShowExtension(*extension)) { |
| 340 RenderProcessHost* process = | |
| 341 process_manager->GetExtensionProcess((*extension)->url()); | |
| 342 extensions_list->Append(CreateExtensionDetailValue( | 339 extensions_list->Append(CreateExtensionDetailValue( |
| 343 extensions_service_.get(), | 340 extensions_service_.get(), |
| 344 *extension, | 341 *extension, |
| 345 GetActivePagesForExtension(process, *extension), | 342 GetActivePagesForExtension(*extension), |
| 346 false)); // enabled | 343 false)); // enabled |
| 347 extension_icons->push_back(PickExtensionIcon(*extension)); | 344 extension_icons->push_back(PickExtensionIcon(*extension)); |
| 348 } | 345 } |
| 349 } | 346 } |
| 350 results->Set("extensions", extensions_list); | 347 results->Set("extensions", extensions_list); |
| 351 | 348 |
| 352 bool developer_mode = dom_ui_->GetProfile()->GetPrefs() | 349 bool developer_mode = dom_ui_->GetProfile()->GetPrefs() |
| 353 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 350 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 354 results->SetBoolean("developerMode", developer_mode); | 351 results->SetBoolean("developerMode", developer_mode); |
| 355 | 352 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 DictionaryValue* view_value = new DictionaryValue; | 826 DictionaryValue* view_value = new DictionaryValue; |
| 830 if (iter->url.scheme() == chrome::kExtensionScheme) { | 827 if (iter->url.scheme() == chrome::kExtensionScheme) { |
| 831 // No leading slash. | 828 // No leading slash. |
| 832 view_value->SetString("path", iter->url.path().substr(1)); | 829 view_value->SetString("path", iter->url.path().substr(1)); |
| 833 } else { | 830 } else { |
| 834 // For live pages, use the full URL. | 831 // For live pages, use the full URL. |
| 835 view_value->SetString("path", iter->url.spec()); | 832 view_value->SetString("path", iter->url.spec()); |
| 836 } | 833 } |
| 837 view_value->SetInteger("renderViewId", iter->render_view_id); | 834 view_value->SetInteger("renderViewId", iter->render_view_id); |
| 838 view_value->SetInteger("renderProcessId", iter->render_process_id); | 835 view_value->SetInteger("renderProcessId", iter->render_process_id); |
| 836 view_value->SetBoolean("incognito", iter->incognito); |
| 839 views->Append(view_value); | 837 views->Append(view_value); |
| 840 } | 838 } |
| 841 extension_data->Set("views", views); | 839 extension_data->Set("views", views); |
| 842 extension_data->SetBoolean("hasPopupAction", | 840 extension_data->SetBoolean("hasPopupAction", |
| 843 extension->browser_action() || extension->page_action()); | 841 extension->browser_action() || extension->page_action()); |
| 844 extension_data->SetString("galleryUrl", extension->GalleryUrl().spec()); | 842 extension_data->SetString("galleryUrl", extension->GalleryUrl().spec()); |
| 845 | 843 |
| 846 return extension_data; | 844 return extension_data; |
| 847 } | 845 } |
| 848 | 846 |
| 849 std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension( | 847 std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension( |
| 850 RenderProcessHost* process, | |
| 851 Extension* extension) { | 848 Extension* extension) { |
| 852 std::vector<ExtensionPage> result; | 849 std::vector<ExtensionPage> result; |
| 850 |
| 851 // Get the extension process's active views. |
| 852 ExtensionProcessManager* process_manager = |
| 853 extensions_service_->profile()->GetExtensionProcessManager(); |
| 854 GetActivePagesForExtensionProcess( |
| 855 process_manager->GetExtensionProcess(extension->url()), |
| 856 extension, &result); |
| 857 |
| 858 // Repeat for the incognito process, if applicable. |
| 859 if (extensions_service_->profile()->HasOffTheRecordProfile() && |
| 860 extension->incognito_split_mode()) { |
| 861 ExtensionProcessManager* process_manager = |
| 862 extensions_service_->profile()->GetOffTheRecordProfile()-> |
| 863 GetExtensionProcessManager(); |
| 864 GetActivePagesForExtensionProcess( |
| 865 process_manager->GetExtensionProcess(extension->url()), |
| 866 extension, &result); |
| 867 } |
| 868 |
| 869 return result; |
| 870 } |
| 871 |
| 872 void ExtensionsDOMHandler::GetActivePagesForExtensionProcess( |
| 873 RenderProcessHost* process, |
| 874 Extension* extension, |
| 875 std::vector<ExtensionPage> *result) { |
| 853 if (!process) | 876 if (!process) |
| 854 return result; | 877 return; |
| 855 | 878 |
| 856 RenderProcessHost::listeners_iterator iter = process->ListenersIterator(); | 879 RenderProcessHost::listeners_iterator iter = process->ListenersIterator(); |
| 857 for (; !iter.IsAtEnd(); iter.Advance()) { | 880 for (; !iter.IsAtEnd(); iter.Advance()) { |
| 858 const RenderWidgetHost* widget = | 881 const RenderWidgetHost* widget = |
| 859 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); | 882 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); |
| 860 DCHECK(widget); | 883 DCHECK(widget); |
| 861 if (!widget || !widget->IsRenderView()) | 884 if (!widget || !widget->IsRenderView()) |
| 862 continue; | 885 continue; |
| 863 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); | 886 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); |
| 864 if (host == deleting_rvh_ || | 887 if (host == deleting_rvh_ || |
| 865 ViewType::EXTENSION_POPUP == host->delegate()->GetRenderViewType()) | 888 ViewType::EXTENSION_POPUP == host->delegate()->GetRenderViewType()) |
| 866 continue; | 889 continue; |
| 867 | 890 |
| 868 GURL url = host->delegate()->GetURL(); | 891 GURL url = host->delegate()->GetURL(); |
| 869 if (url.SchemeIs(chrome::kExtensionScheme)) { | 892 if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 870 if (url.host() != extension->id()) | 893 if (url.host() != extension->id()) |
| 871 continue; | 894 continue; |
| 872 } else if (!extension->web_extent().ContainsURL(url)) { | 895 } else if (!extension->web_extent().ContainsURL(url)) { |
| 873 continue; | 896 continue; |
| 874 } | 897 } |
| 875 | 898 |
| 876 result.push_back(ExtensionPage(url, process->id(), host->routing_id())); | 899 result->push_back(ExtensionPage(url, process->id(), host->routing_id(), |
| 900 process->profile()->IsOffTheRecord())); |
| 877 } | 901 } |
| 878 | |
| 879 return result; | |
| 880 } | 902 } |
| 881 | 903 |
| 882 ExtensionsDOMHandler::~ExtensionsDOMHandler() { | 904 ExtensionsDOMHandler::~ExtensionsDOMHandler() { |
| 883 if (pack_job_.get()) | 905 if (pack_job_.get()) |
| 884 pack_job_->ClearClient(); | 906 pack_job_->ClearClient(); |
| 885 | 907 |
| 886 if (icon_loader_.get()) | 908 if (icon_loader_.get()) |
| 887 icon_loader_->Cancel(); | 909 icon_loader_->Cancel(); |
| 888 } | 910 } |
| 889 | 911 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 911 // static | 933 // static |
| 912 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() { | 934 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() { |
| 913 return ResourceBundle::GetSharedInstance(). | 935 return ResourceBundle::GetSharedInstance(). |
| 914 LoadDataResourceBytes(IDR_PLUGIN); | 936 LoadDataResourceBytes(IDR_PLUGIN); |
| 915 } | 937 } |
| 916 | 938 |
| 917 // static | 939 // static |
| 918 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { | 940 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { |
| 919 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, false); | 941 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, false); |
| 920 } | 942 } |
| OLD | NEW |