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

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

Issue 989813002: [Extensions] Make a chrome.developerPrivate.getExtensionsInfo function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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) 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 "apps/app_load_service.h" 7 #include "apps/app_load_service.h"
8 #include "apps/saved_files_service.h" 8 #include "apps/saved_files_service.h"
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/browser/profiles/profile.h" 45 #include "chrome/browser/profiles/profile.h"
46 #include "chrome/browser/ui/apps/app_info_dialog.h" 46 #include "chrome/browser/ui/apps/app_info_dialog.h"
47 #include "chrome/browser/ui/browser.h" 47 #include "chrome/browser/ui/browser.h"
48 #include "chrome/browser/ui/browser_finder.h" 48 #include "chrome/browser/ui/browser_finder.h"
49 #include "chrome/browser/ui/browser_window.h" 49 #include "chrome/browser/ui/browser_window.h"
50 #include "chrome/browser/ui/extensions/app_launch_params.h" 50 #include "chrome/browser/ui/extensions/app_launch_params.h"
51 #include "chrome/browser/ui/extensions/application_launch.h" 51 #include "chrome/browser/ui/extensions/application_launch.h"
52 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" 52 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
53 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 53 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
54 #include "chrome/common/chrome_version_info.h" 54 #include "chrome/common/chrome_version_info.h"
55 #include "chrome/common/extensions/api/developer_private.h"
55 #include "chrome/common/extensions/features/feature_channel.h" 56 #include "chrome/common/extensions/features/feature_channel.h"
56 #include "chrome/common/pref_names.h" 57 #include "chrome/common/pref_names.h"
57 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
58 #include "chrome/grit/chromium_strings.h" 59 #include "chrome/grit/chromium_strings.h"
59 #include "chrome/grit/generated_resources.h" 60 #include "chrome/grit/generated_resources.h"
60 #include "components/google/core/browser/google_util.h" 61 #include "components/google/core/browser/google_util.h"
61 #include "components/pref_registry/pref_registry_syncable.h" 62 #include "components/pref_registry/pref_registry_syncable.h"
62 #include "content/public/browser/notification_service.h" 63 #include "content/public/browser/notification_service.h"
63 #include "content/public/browser/notification_source.h" 64 #include "content/public/browser/notification_source.h"
64 #include "content/public/browser/notification_types.h" 65 #include "content/public/browser/notification_types.h"
65 #include "content/public/browser/render_process_host.h" 66 #include "content/public/browser/render_process_host.h"
66 #include "content/public/browser/render_view_host.h" 67 #include "content/public/browser/render_view_host.h"
67 #include "content/public/browser/site_instance.h" 68 #include "content/public/browser/site_instance.h"
68 #include "content/public/browser/web_contents.h" 69 #include "content/public/browser/web_contents.h"
69 #include "content/public/browser/web_ui.h" 70 #include "content/public/browser/web_ui.h"
70 #include "content/public/browser/web_ui_data_source.h" 71 #include "content/public/browser/web_ui_data_source.h"
71 #include "extensions/browser/api/device_permissions_manager.h" 72 #include "extensions/browser/api/device_permissions_manager.h"
72 #include "extensions/browser/app_window/app_window.h"
73 #include "extensions/browser/app_window/app_window_registry.h"
74 #include "extensions/browser/blacklist_state.h" 73 #include "extensions/browser/blacklist_state.h"
75 #include "extensions/browser/extension_error.h" 74 #include "extensions/browser/extension_error.h"
76 #include "extensions/browser/extension_host.h" 75 #include "extensions/browser/extension_host.h"
77 #include "extensions/browser/extension_registry.h" 76 #include "extensions/browser/extension_registry.h"
78 #include "extensions/browser/extension_system.h" 77 #include "extensions/browser/extension_system.h"
79 #include "extensions/browser/lazy_background_task_queue.h" 78 #include "extensions/browser/lazy_background_task_queue.h"
80 #include "extensions/browser/management_policy.h" 79 #include "extensions/browser/management_policy.h"
81 #include "extensions/browser/pref_names.h" 80 #include "extensions/browser/pref_names.h"
82 #include "extensions/browser/view_type_utils.h"
83 #include "extensions/browser/warning_set.h" 81 #include "extensions/browser/warning_set.h"
84 #include "extensions/common/constants.h" 82 #include "extensions/common/constants.h"
85 #include "extensions/common/extension.h" 83 #include "extensions/common/extension.h"
86 #include "extensions/common/extension_icon_set.h" 84 #include "extensions/common/extension_icon_set.h"
87 #include "extensions/common/extension_set.h" 85 #include "extensions/common/extension_set.h"
88 #include "extensions/common/extension_urls.h" 86 #include "extensions/common/extension_urls.h"
89 #include "extensions/common/feature_switch.h" 87 #include "extensions/common/feature_switch.h"
90 #include "extensions/common/manifest.h" 88 #include "extensions/common/manifest.h"
91 #include "extensions/common/manifest_handlers/background_info.h" 89 #include "extensions/common/manifest_handlers/background_info.h"
92 #include "extensions/common/manifest_handlers/incognito_info.h" 90 #include "extensions/common/manifest_handlers/incognito_info.h"
(...skipping 12 matching lines...) Expand all
105 103
106 namespace { 104 namespace {
107 105
108 const char kAppsDeveloperToolsExtensionId[] = 106 const char kAppsDeveloperToolsExtensionId[] =
109 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc"; 107 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc";
110 108
111 } // namespace 109 } // namespace
112 110
113 namespace extensions { 111 namespace extensions {
114 112
115 ExtensionPage::ExtensionPage(const GURL& url,
116 int render_process_id,
117 int render_view_id,
118 bool incognito,
119 bool generated_background_page)
120 : url(url),
121 render_process_id(render_process_id),
122 render_view_id(render_view_id),
123 incognito(incognito),
124 generated_background_page(generated_background_page) {
125 }
126
127 // The install prompt is not necessarily modal (e.g. Mac, Linux Unity). This 113 // The install prompt is not necessarily modal (e.g. Mac, Linux Unity). This
128 // means that the user can navigate while the dialog is up, causing the dialog 114 // means that the user can navigate while the dialog is up, causing the dialog
129 // handler to outlive the ExtensionSettingsHandler. That's a problem because the 115 // handler to outlive the ExtensionSettingsHandler. That's a problem because the
130 // dialog framework will try to contact us back once the dialog is closed, which 116 // dialog framework will try to contact us back once the dialog is closed, which
131 // causes a crash. This class is designed to broker the message between the two 117 // causes a crash. This class is designed to broker the message between the two
132 // objects, while managing its own lifetime so that it can outlive the 118 // objects, while managing its own lifetime so that it can outlive the
133 // ExtensionSettingsHandler and (when doing so) gracefully ignore the message 119 // ExtensionSettingsHandler and (when doing so) gracefully ignore the message
134 // from the dialog. 120 // from the dialog.
135 class BrokerDelegate : public ExtensionInstallPrompt::Delegate { 121 class BrokerDelegate : public ExtensionInstallPrompt::Delegate {
136 public: 122 public:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 false, 199 false,
214 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 200 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
215 registry->RegisterBooleanPref( 201 registry->RegisterBooleanPref(
216 prefs::kExtensionsUIDismissedADTPromo, 202 prefs::kExtensionsUIDismissedADTPromo,
217 false, 203 false,
218 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 204 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
219 } 205 }
220 206
221 base::DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( 207 base::DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
222 const Extension* extension, 208 const Extension* extension,
223 const std::vector<ExtensionPage>& pages, 209 const InspectableViewsFinder::ViewList& views,
224 const WarningService* warning_service) { 210 const WarningService* warning_service) {
225 // The items which are to be written into app_dict are also described in 211 // The items which are to be written into app_dict are also described in
226 // chrome/browser/resources/extensions/extension_list.js in @typedef for 212 // chrome/browser/resources/extensions/extension_list.js in @typedef for
227 // ExtensionData. Please update it whenever you add or remove any keys here. 213 // ExtensionData. Please update it whenever you add or remove any keys here.
228 base::DictionaryValue* extension_data = new base::DictionaryValue(); 214 base::DictionaryValue* extension_data = new base::DictionaryValue();
229 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); 215 bool enabled = extension_service_->IsExtensionEnabled(extension->id());
230 GetExtensionBasicInfo(extension, enabled, extension_data); 216 GetExtensionBasicInfo(extension, enabled, extension_data);
231 217
232 ExtensionPrefs* prefs = ExtensionPrefs::Get(extension_service_->profile()); 218 ExtensionPrefs* prefs = ExtensionPrefs::Get(extension_service_->profile());
233 int disable_reasons = prefs->GetDisableReasons(extension->id()); 219 int disable_reasons = prefs->GetDisableReasons(extension->id());
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 379
394 // Don't show the "show button" for the browser action if the toolbar 380 // Don't show the "show button" for the browser action if the toolbar
395 // redesign is enabled, because "hidden" buttons are now just hidden in the 381 // redesign is enabled, because "hidden" buttons are now just hidden in the
396 // wrench menu. 382 // wrench menu.
397 if (!ExtensionActionAPI::GetBrowserActionVisibility(prefs, extension->id()) && 383 if (!ExtensionActionAPI::GetBrowserActionVisibility(prefs, extension->id()) &&
398 !FeatureSwitch::extension_action_redesign()->IsEnabled()) { 384 !FeatureSwitch::extension_action_redesign()->IsEnabled()) {
399 extension_data->SetBoolean("enable_show_button", true); 385 extension_data->SetBoolean("enable_show_button", true);
400 } 386 }
401 387
402 // Add views 388 // Add views
403 base::ListValue* views = new base::ListValue; 389 base::ListValue* views_value = new base::ListValue;
404 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); 390 for (const InspectableViewsFinder::View& view : views)
405 iter != pages.end(); ++iter) { 391 views_value->Append(view->ToValue().release());
406 base::DictionaryValue* view_value = new base::DictionaryValue; 392 extension_data->Set("views", views_value);
407 if (iter->url.scheme() == kExtensionScheme) {
408 // No leading slash.
409 view_value->SetString("path", iter->url.path().substr(1));
410 } else {
411 // For live pages, use the full URL.
412 view_value->SetString("path", iter->url.spec());
413 }
414 view_value->SetInteger("renderViewId", iter->render_view_id);
415 view_value->SetInteger("renderProcessId", iter->render_process_id);
416 view_value->SetBoolean("incognito", iter->incognito);
417 view_value->SetBoolean("generatedBackgroundPage",
418 iter->generated_background_page);
419 views->Append(view_value);
420 }
421 extension_data->Set("views", views);
422 ExtensionActionManager* extension_action_manager = 393 ExtensionActionManager* extension_action_manager =
423 ExtensionActionManager::Get(extension_service_->profile()); 394 ExtensionActionManager::Get(extension_service_->profile());
424 extension_data->SetBoolean( 395 extension_data->SetBoolean(
425 "hasPopupAction", 396 "hasPopupAction",
426 extension_action_manager->GetBrowserAction(*extension) || 397 extension_action_manager->GetBrowserAction(*extension) ||
427 extension_action_manager->GetPageAction(*extension)); 398 extension_action_manager->GetPageAction(*extension));
428 399
429 // Add warnings. 400 // Add warnings.
430 if (warning_service) { 401 if (warning_service) {
431 std::vector<std::string> warnings = 402 std::vector<std::string> warnings =
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 840
870 Profile* profile = Profile::FromWebUI(web_ui()); 841 Profile* profile = Profile::FromWebUI(web_ui());
871 842
872 // Add the extensions to the results structure. 843 // Add the extensions to the results structure.
873 base::ListValue* extensions_list = new base::ListValue(); 844 base::ListValue* extensions_list = new base::ListValue();
874 845
875 WarningService* warnings = WarningService::Get(profile); 846 WarningService* warnings = WarningService::Get(profile);
876 847
877 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); 848 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
878 const ExtensionSet& enabled_set = registry->enabled_extensions(); 849 const ExtensionSet& enabled_set = registry->enabled_extensions();
850 InspectableViewsFinder views_finder(profile, deleting_rvh_);
879 for (ExtensionSet::const_iterator extension = enabled_set.begin(); 851 for (ExtensionSet::const_iterator extension = enabled_set.begin();
880 extension != enabled_set.end(); ++extension) { 852 extension != enabled_set.end(); ++extension) {
881 if (ui_util::ShouldDisplayInExtensionSettings(extension->get(), profile)) { 853 if (ui_util::ShouldDisplayInExtensionSettings(extension->get(), profile)) {
882 extensions_list->Append(CreateExtensionDetailValue( 854 extensions_list->Append(CreateExtensionDetailValue(
883 extension->get(), 855 extension->get(),
884 GetInspectablePagesForExtension(extension->get(), true), 856 views_finder.GetViewsForExtension(**extension, true),
885 warnings)); 857 warnings));
886 } 858 }
887 } 859 }
888 const ExtensionSet& disabled_set = registry->disabled_extensions(); 860 const ExtensionSet& disabled_set = registry->disabled_extensions();
889 for (ExtensionSet::const_iterator extension = disabled_set.begin(); 861 for (ExtensionSet::const_iterator extension = disabled_set.begin();
890 extension != disabled_set.end(); ++extension) { 862 extension != disabled_set.end(); ++extension) {
891 if (ui_util::ShouldDisplayInExtensionSettings(extension->get(), profile)) { 863 if (ui_util::ShouldDisplayInExtensionSettings(extension->get(), profile)) {
892 extensions_list->Append(CreateExtensionDetailValue( 864 extensions_list->Append(CreateExtensionDetailValue(
893 extension->get(), 865 extension->get(),
894 GetInspectablePagesForExtension(extension->get(), false), 866 views_finder.GetViewsForExtension(**extension, false),
895 warnings)); 867 warnings));
896 } 868 }
897 } 869 }
898 const ExtensionSet& terminated_set = registry->terminated_extensions(); 870 const ExtensionSet& terminated_set = registry->terminated_extensions();
899 std::vector<ExtensionPage> empty_pages;
900 for (ExtensionSet::const_iterator extension = terminated_set.begin(); 871 for (ExtensionSet::const_iterator extension = terminated_set.begin();
901 extension != terminated_set.end(); ++extension) { 872 extension != terminated_set.end(); ++extension) {
902 if (ui_util::ShouldDisplayInExtensionSettings(extension->get(), profile)) { 873 if (ui_util::ShouldDisplayInExtensionSettings(extension->get(), profile)) {
903 extensions_list->Append(CreateExtensionDetailValue( 874 extensions_list->Append(CreateExtensionDetailValue(
904 extension->get(), 875 extension->get(),
905 empty_pages, // Terminated process has no active pages. 876 InspectableViewsFinder::ViewList(), // No views for terminated.
906 warnings)); 877 warnings));
907 } 878 }
908 } 879 }
909 results.Set("extensions", extensions_list); 880 results.Set("extensions", extensions_list);
910 881
911 bool is_supervised = profile->IsSupervised(); 882 bool is_supervised = profile->IsSupervised();
912 bool incognito_available = 883 bool incognito_available =
913 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) != 884 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) !=
914 IncognitoModePrefs::DISABLED; 885 IncognitoModePrefs::DISABLED;
915 bool developer_mode = 886 bool developer_mode =
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); 1186 content::WebContentsObserver::Observe(web_ui()->GetWebContents());
1216 1187
1217 warning_service_observer_.Add(WarningService::Get(profile)); 1188 warning_service_observer_.Add(WarningService::Get(profile));
1218 1189
1219 error_console_observer_.Add(ErrorConsole::Get(profile)); 1190 error_console_observer_.Add(ErrorConsole::Get(profile));
1220 1191
1221 extension_management_observer_.Add( 1192 extension_management_observer_.Add(
1222 ExtensionManagementFactory::GetForBrowserContext(profile)); 1193 ExtensionManagementFactory::GetForBrowserContext(profile));
1223 } 1194 }
1224 1195
1225 std::vector<ExtensionPage>
1226 ExtensionSettingsHandler::GetInspectablePagesForExtension(
1227 const Extension* extension, bool extension_is_enabled) {
1228 std::vector<ExtensionPage> result;
1229
1230 // Get the extension process's active views.
1231 extensions::ProcessManager* process_manager =
1232 ProcessManager::Get(extension_service_->profile());
1233 GetInspectablePagesForExtensionProcess(
1234 extension,
1235 process_manager->GetRenderViewHostsForExtension(extension->id()),
1236 &result);
1237
1238 // Get app window views
1239 GetAppWindowPagesForExtensionProfile(
1240 extension, extension_service_->profile(), &result);
1241
1242 // Include a link to start the lazy background page, if applicable.
1243 if (BackgroundInfo::HasLazyBackgroundPage(extension) &&
1244 extension_is_enabled &&
1245 !process_manager->GetBackgroundHostForExtension(extension->id())) {
1246 result.push_back(ExtensionPage(
1247 BackgroundInfo::GetBackgroundURL(extension),
1248 -1,
1249 -1,
1250 false,
1251 BackgroundInfo::HasGeneratedBackgroundPage(extension)));
1252 }
1253
1254 // Repeat for the incognito process, if applicable. Don't try to get
1255 // app windows for incognito processes.
1256 if (extension_service_->profile()->HasOffTheRecordProfile() &&
1257 IncognitoInfo::IsSplitMode(extension) &&
1258 util::IsIncognitoEnabled(extension->id(),
1259 extension_service_->profile())) {
1260 extensions::ProcessManager* process_manager = ProcessManager::Get(
1261 extension_service_->profile()->GetOffTheRecordProfile());
1262 GetInspectablePagesForExtensionProcess(
1263 extension,
1264 process_manager->GetRenderViewHostsForExtension(extension->id()),
1265 &result);
1266
1267 if (BackgroundInfo::HasLazyBackgroundPage(extension) &&
1268 extension_is_enabled &&
1269 !process_manager->GetBackgroundHostForExtension(extension->id())) {
1270 result.push_back(ExtensionPage(
1271 BackgroundInfo::GetBackgroundURL(extension),
1272 -1,
1273 -1,
1274 true,
1275 BackgroundInfo::HasGeneratedBackgroundPage(extension)));
1276 }
1277 }
1278
1279 return result;
1280 }
1281
1282 void ExtensionSettingsHandler::GetInspectablePagesForExtensionProcess(
1283 const Extension* extension,
1284 const std::set<RenderViewHost*>& views,
1285 std::vector<ExtensionPage>* result) {
1286 bool has_generated_background_page =
1287 BackgroundInfo::HasGeneratedBackgroundPage(extension);
1288 for (std::set<RenderViewHost*>::const_iterator iter = views.begin();
1289 iter != views.end(); ++iter) {
1290 RenderViewHost* host = *iter;
1291 WebContents* web_contents = WebContents::FromRenderViewHost(host);
1292 ViewType host_type = GetViewType(web_contents);
1293 if (host == deleting_rvh_ ||
1294 VIEW_TYPE_EXTENSION_POPUP == host_type ||
1295 VIEW_TYPE_EXTENSION_DIALOG == host_type)
1296 continue;
1297
1298 GURL url = web_contents->GetURL();
1299 content::RenderProcessHost* process = host->GetProcess();
1300 bool is_background_page =
1301 (url == BackgroundInfo::GetBackgroundURL(extension));
1302 result->push_back(
1303 ExtensionPage(url,
1304 process->GetID(),
1305 host->GetRoutingID(),
1306 process->GetBrowserContext()->IsOffTheRecord(),
1307 is_background_page && has_generated_background_page));
1308 }
1309 }
1310
1311 void ExtensionSettingsHandler::GetAppWindowPagesForExtensionProfile(
1312 const Extension* extension,
1313 Profile* profile,
1314 std::vector<ExtensionPage>* result) {
1315 AppWindowRegistry* registry = AppWindowRegistry::Get(profile);
1316 if (!registry) return;
1317
1318 const AppWindowRegistry::AppWindowList windows =
1319 registry->GetAppWindowsForApp(extension->id());
1320
1321 bool has_generated_background_page =
1322 BackgroundInfo::HasGeneratedBackgroundPage(extension);
1323 for (AppWindowRegistry::const_iterator it = windows.begin();
1324 it != windows.end();
1325 ++it) {
1326 WebContents* web_contents = (*it)->web_contents();
1327 RenderViewHost* host = web_contents->GetRenderViewHost();
1328 content::RenderProcessHost* process = host->GetProcess();
1329
1330 bool is_background_page =
1331 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension));
1332 result->push_back(
1333 ExtensionPage(web_contents->GetURL(),
1334 process->GetID(),
1335 host->GetRoutingID(),
1336 process->GetBrowserContext()->IsOffTheRecord(),
1337 is_background_page && has_generated_background_page));
1338 }
1339 }
1340
1341 void ExtensionSettingsHandler::OnReinstallComplete( 1196 void ExtensionSettingsHandler::OnReinstallComplete(
1342 bool success, 1197 bool success,
1343 const std::string& error, 1198 const std::string& error,
1344 webstore_install::Result result) { 1199 webstore_install::Result result) {
1345 MaybeUpdateAfterNotification(); 1200 MaybeUpdateAfterNotification();
1346 } 1201 }
1347 1202
1348 } // namespace extensions 1203 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698