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

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 1060993003: [Extensions UI] Use developerPrivate API for profile configuration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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/extensions/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/devtools/devtools_window.h" 15 #include "chrome/browser/devtools/devtools_window.h"
15 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" 16 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h"
16 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" 17 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
17 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" 18 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h"
18 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h" 19 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h"
19 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 20 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
20 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
21 #include "chrome/browser/extensions/devtools_util.h" 22 #include "chrome/browser/extensions/devtools_util.h"
22 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_ui_util.h" 24 #include "chrome/browser/extensions/extension_ui_util.h"
24 #include "chrome/browser/extensions/extension_util.h" 25 #include "chrome/browser/extensions/extension_util.h"
26 #include "chrome/browser/extensions/install_verifier.h"
25 #include "chrome/browser/extensions/shared_module_service.h" 27 #include "chrome/browser/extensions/shared_module_service.h"
26 #include "chrome/browser/extensions/unpacked_installer.h" 28 #include "chrome/browser/extensions/unpacked_installer.h"
27 #include "chrome/browser/extensions/updater/extension_updater.h" 29 #include "chrome/browser/extensions/updater/extension_updater.h"
30 #include "chrome/browser/prefs/incognito_mode_prefs.h"
28 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/ui/apps/app_info_dialog.h"
29 #include "chrome/browser/ui/browser_finder.h" 33 #include "chrome/browser/ui/browser_finder.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/common/extensions/api/developer_private.h" 35 #include "chrome/common/extensions/api/developer_private.h"
32 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 36 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
37 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
34 #include "chrome/grit/generated_resources.h" 39 #include "chrome/grit/generated_resources.h"
35 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/render_process_host.h" 42 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/render_view_host.h" 43 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/site_instance.h" 44 #include "content/public/browser/site_instance.h"
40 #include "content/public/browser/storage_partition.h" 45 #include "content/public/browser/storage_partition.h"
41 #include "content/public/browser/web_contents.h" 46 #include "content/public/browser/web_contents.h"
42 #include "extensions/browser/app_window/app_window.h" 47 #include "extensions/browser/app_window/app_window.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const char kCouldNotShowSelectFileDialogError[] = 86 const char kCouldNotShowSelectFileDialogError[] =
82 "Could not show a file chooser."; 87 "Could not show a file chooser.";
83 const char kFileSelectionCanceled[] = 88 const char kFileSelectionCanceled[] =
84 "File selection was canceled."; 89 "File selection was canceled.";
85 const char kNoSuchRendererError[] = "No such renderer."; 90 const char kNoSuchRendererError[] = "No such renderer.";
86 const char kInvalidPathError[] = "Invalid path."; 91 const char kInvalidPathError[] = "Invalid path.";
87 const char kManifestKeyIsRequiredError[] = 92 const char kManifestKeyIsRequiredError[] =
88 "The 'manifestKey' argument is required for manifest files."; 93 "The 'manifestKey' argument is required for manifest files.";
89 const char kCouldNotFindWebContentsError[] = 94 const char kCouldNotFindWebContentsError[] =
90 "Could not find a valid web contents."; 95 "Could not find a valid web contents.";
96 const char kCannotUpdateSupervisedProfileSettingsError[] =
97 "Cannot change settings for a supervised profile.";
91 98
92 const char kUnpackedAppsFolder[] = "apps_target"; 99 const char kUnpackedAppsFolder[] = "apps_target";
93 const char kManifestFile[] = "manifest.json"; 100 const char kManifestFile[] = "manifest.json";
94 101
95 ExtensionService* GetExtensionService(content::BrowserContext* context) { 102 ExtensionService* GetExtensionService(content::BrowserContext* context) {
96 return ExtensionSystem::Get(context)->extension_service(); 103 return ExtensionSystem::Get(context)->extension_service();
97 } 104 }
98 105
99 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { 106 ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
100 return GetExtensionService(profile)->updater(); 107 return GetExtensionService(profile)->updater();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 LOG(ERROR) << "Attempt to change settings of an extension that is " 177 LOG(ERROR) << "Attempt to change settings of an extension that is "
171 << "non-usermanagable was made. Extension id : " 178 << "non-usermanagable was made. Extension id : "
172 << extension->id(); 179 << extension->id();
173 *error = kCannotModifyPolicyExtensionError; 180 *error = kCannotModifyPolicyExtensionError;
174 return false; 181 return false;
175 } 182 }
176 183
177 return true; 184 return true;
178 } 185 }
179 186
187 // Runs the install verifier for all extensions that are enabled, disabled, or
188 // terminated.
189 void PerformVerificationCheck(content::BrowserContext* context) {
190 scoped_ptr<ExtensionSet> extensions =
191 ExtensionRegistry::Get(context)->GenerateInstalledExtensionsSet(
192 ExtensionRegistry::ENABLED |
193 ExtensionRegistry::DISABLED |
194 ExtensionRegistry::TERMINATED);
195 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
196 bool should_do_verification_check = false;
197 for (const scoped_refptr<const Extension>& extension : *extensions) {
198 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), context) &&
199 ((prefs->GetDisableReasons(extension->id()) &
200 Extension::DISABLE_NOT_VERIFIED) != 0)) {
201 should_do_verification_check = true;
202 break;
203 }
204 }
205
206 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck",
207 should_do_verification_check);
208 if (should_do_verification_check)
209 ExtensionSystem::Get(context)->install_verifier()->VerifyAllExtensions();
210 }
211
180 } // namespace 212 } // namespace
181 213
182 namespace ChoosePath = api::developer_private::ChoosePath; 214 namespace ChoosePath = api::developer_private::ChoosePath;
183 namespace GetItemsInfo = api::developer_private::GetItemsInfo; 215 namespace GetItemsInfo = api::developer_private::GetItemsInfo;
184 namespace PackDirectory = api::developer_private::PackDirectory; 216 namespace PackDirectory = api::developer_private::PackDirectory;
185 namespace Reload = api::developer_private::Reload; 217 namespace Reload = api::developer_private::Reload;
186 218
187 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > 219 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> >
188 g_factory = LAZY_INSTANCE_INITIALIZER; 220 g_factory = LAZY_INSTANCE_INITIALIZER;
189 221
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 content::BrowserThread::PostTask( 481 content::BrowserThread::PostTask(
450 content::BrowserThread::UI, 482 content::BrowserThread::UI,
451 FROM_HERE, 483 FROM_HERE,
452 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this)); 484 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this));
453 } 485 }
454 486
455 void DeveloperPrivateGetItemsInfoFunction::Finish() { 487 void DeveloperPrivateGetItemsInfoFunction::Finish() {
456 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_))); 488 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_)));
457 } 489 }
458 490
491 DeveloperPrivateGetProfileConfigurationFunction::
492 ~DeveloperPrivateGetProfileConfigurationFunction() {
493 }
494
495 ExtensionFunction::ResponseAction
496 DeveloperPrivateGetProfileConfigurationFunction::Run() {
497 developer::ProfileInfo info;
498 info.is_supervised = GetProfile()->IsSupervised();
499 info.is_incognito_available =
500 IncognitoModePrefs::GetAvailability(GetProfile()->GetPrefs()) !=
501 IncognitoModePrefs::DISABLED;
502 info.in_developer_mode =
503 !info.is_supervised &&
504 GetProfile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
505 info.app_info_dialog_enabled = CanShowAppInfoDialog();
506 info.can_load_unpacked =
507 !ExtensionManagementFactory::GetForBrowserContext(browser_context())
508 ->BlacklistedByDefault();
509
510 // If this is called from the chrome://extensions page, we use this as a
511 // heuristic that it's a good time to verify installs. We do this on startup,
512 // but there's a chance that it failed erroneously, so it's good to double-
513 // check.
514 if (source_context_type() == Feature::WEBUI_CONTEXT)
515 PerformVerificationCheck(browser_context());
516
517 return RespondNow(OneArgument(info.ToValue()));
518 }
519
520 DeveloperPrivateUpdateProfileConfigurationFunction::
521 ~DeveloperPrivateUpdateProfileConfigurationFunction() {
522 }
523
524 ExtensionFunction::ResponseAction
525 DeveloperPrivateUpdateProfileConfigurationFunction::Run() {
526 scoped_ptr<developer::UpdateProfileConfiguration::Params> params(
527 developer::UpdateProfileConfiguration::Params::Create(*args_));
528 EXTENSION_FUNCTION_VALIDATE(params);
529
530 const developer::ProfileConfigurationUpdate& update = params->update;
531 PrefService* prefs = GetProfile()->GetPrefs();
532 if (update.in_developer_mode) {
533 if (GetProfile()->IsSupervised())
534 return RespondNow(Error(kCannotUpdateSupervisedProfileSettingsError));
535 prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode,
536 *update.in_developer_mode);
537 }
538
539 return RespondNow(NoArguments());
540 }
541
459 DeveloperPrivateUpdateExtensionConfigurationFunction:: 542 DeveloperPrivateUpdateExtensionConfigurationFunction::
460 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {} 543 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {}
461 544
462 ExtensionFunction::ResponseAction 545 ExtensionFunction::ResponseAction
463 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() { 546 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() {
464 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params( 547 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params(
465 developer::UpdateExtensionConfiguration::Params::Create(*args_)); 548 developer::UpdateExtensionConfiguration::Params::Create(*args_));
466 EXTENSION_FUNCTION_VALIDATE(params); 549 EXTENSION_FUNCTION_VALIDATE(params);
467 550
468 const developer::ExtensionConfigurationUpdate& update = params->update; 551 const developer::ExtensionConfigurationUpdate& update = params->update;
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 const developer::OpenDevToolsProperties& properties = params->properties; 1185 const developer::OpenDevToolsProperties& properties = params->properties;
1103 1186
1104 if (properties.render_process_id == -1) { 1187 if (properties.render_process_id == -1) {
1105 // This is a lazy background page. 1188 // This is a lazy background page.
1106 const Extension* extension = properties.extension_id ? 1189 const Extension* extension = properties.extension_id ?
1107 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID( 1190 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID(
1108 *properties.extension_id) : nullptr; 1191 *properties.extension_id) : nullptr;
1109 if (!extension) 1192 if (!extension)
1110 return RespondNow(Error(kNoSuchExtensionError)); 1193 return RespondNow(Error(kNoSuchExtensionError));
1111 1194
1112 Profile* profile = Profile::FromBrowserContext(browser_context()); 1195 Profile* profile = GetProfile();
1113 if (properties.incognito && *properties.incognito) 1196 if (properties.incognito && *properties.incognito)
1114 profile = profile->GetOffTheRecordProfile(); 1197 profile = profile->GetOffTheRecordProfile();
1115 1198
1116 // Wakes up the background page and opens the inspect window. 1199 // Wakes up the background page and opens the inspect window.
1117 devtools_util::InspectBackgroundPage(extension, profile); 1200 devtools_util::InspectBackgroundPage(extension, profile);
1118 return RespondNow(NoArguments()); 1201 return RespondNow(NoArguments());
1119 } 1202 }
1120 1203
1121 content::RenderViewHost* rvh = 1204 content::RenderViewHost* rvh =
1122 content::RenderViewHost::FromID(properties.render_process_id, 1205 content::RenderViewHost::FromID(properties.render_process_id,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 ~DeveloperPrivateDeleteExtensionErrorsFunction() {} 1247 ~DeveloperPrivateDeleteExtensionErrorsFunction() {}
1165 1248
1166 ExtensionFunction::ResponseAction 1249 ExtensionFunction::ResponseAction
1167 DeveloperPrivateDeleteExtensionErrorsFunction::Run() { 1250 DeveloperPrivateDeleteExtensionErrorsFunction::Run() {
1168 scoped_ptr<developer::DeleteExtensionErrors::Params> params( 1251 scoped_ptr<developer::DeleteExtensionErrors::Params> params(
1169 developer::DeleteExtensionErrors::Params::Create(*args_)); 1252 developer::DeleteExtensionErrors::Params::Create(*args_));
1170 EXTENSION_FUNCTION_VALIDATE(params); 1253 EXTENSION_FUNCTION_VALIDATE(params);
1171 const developer::DeleteExtensionErrorsProperties& properties = 1254 const developer::DeleteExtensionErrorsProperties& properties =
1172 params->properties; 1255 params->properties;
1173 1256
1174 ErrorConsole* error_console = 1257 ErrorConsole* error_console = ErrorConsole::Get(GetProfile());
1175 ErrorConsole::Get(Profile::FromBrowserContext(browser_context()));
1176 int type = -1; 1258 int type = -1;
1177 if (properties.type != developer::ERROR_TYPE_NONE) { 1259 if (properties.type != developer::ERROR_TYPE_NONE) {
1178 type = properties.type == developer::ERROR_TYPE_MANIFEST ? 1260 type = properties.type == developer::ERROR_TYPE_MANIFEST ?
1179 ExtensionError::MANIFEST_ERROR : ExtensionError::RUNTIME_ERROR; 1261 ExtensionError::MANIFEST_ERROR : ExtensionError::RUNTIME_ERROR;
1180 } 1262 }
1181 std::set<int> error_ids; 1263 std::set<int> error_ids;
1182 if (properties.error_ids) { 1264 if (properties.error_ids) {
1183 error_ids.insert(properties.error_ids->begin(), 1265 error_ids.insert(properties.error_ids->begin(),
1184 properties.error_ids->end()); 1266 properties.error_ids->end());
1185 } 1267 }
1186 error_console->RemoveErrors(ErrorMap::Filter( 1268 error_console->RemoveErrors(ErrorMap::Filter(
1187 properties.extension_id, type, error_ids, false)); 1269 properties.extension_id, type, error_ids, false));
1188 1270
1189 return RespondNow(NoArguments()); 1271 return RespondNow(NoArguments());
1190 } 1272 }
1191 1273
1192 } // namespace api 1274 } // namespace api
1193 1275
1194 } // namespace extensions 1276 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698