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

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
102 const char kAppsDeveloperToolsExtensionId[] =
103 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc";
104
95 ExtensionService* GetExtensionService(content::BrowserContext* context) { 105 ExtensionService* GetExtensionService(content::BrowserContext* context) {
96 return ExtensionSystem::Get(context)->extension_service(); 106 return ExtensionSystem::Get(context)->extension_service();
97 } 107 }
98 108
99 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { 109 ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
100 return GetExtensionService(profile)->updater(); 110 return GetExtensionService(profile)->updater();
101 } 111 }
102 112
103 GURL GetImageURLFromData(const std::string& contents) { 113 GURL GetImageURLFromData(const std::string& contents) {
104 std::string contents_base64; 114 std::string contents_base64;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 LOG(ERROR) << "Attempt to change settings of an extension that is " 180 LOG(ERROR) << "Attempt to change settings of an extension that is "
171 << "non-usermanagable was made. Extension id : " 181 << "non-usermanagable was made. Extension id : "
172 << extension->id(); 182 << extension->id();
173 *error = kCannotModifyPolicyExtensionError; 183 *error = kCannotModifyPolicyExtensionError;
174 return false; 184 return false;
175 } 185 }
176 186
177 return true; 187 return true;
178 } 188 }
179 189
190 // Runs the install verifier for all extensions that are enabled, disabled, or
191 // terminated.
192 void PerformVerificationCheck(content::BrowserContext* context) {
193 scoped_ptr<ExtensionSet> extensions =
194 ExtensionRegistry::Get(context)->GenerateInstalledExtensionsSet(
195 ExtensionRegistry::ENABLED |
196 ExtensionRegistry::DISABLED |
197 ExtensionRegistry::TERMINATED);
198 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
199 bool should_do_verification_check = false;
200 for (const scoped_refptr<const Extension>& extension : *extensions) {
201 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), context) &&
202 ((prefs->GetDisableReasons(extension->id()) &
203 Extension::DISABLE_NOT_VERIFIED) != 0)) {
204 should_do_verification_check = true;
205 break;
206 }
207 }
208
209 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck",
210 should_do_verification_check);
211 if (should_do_verification_check)
212 ExtensionSystem::Get(context)->install_verifier()->VerifyAllExtensions();
213 }
214
180 } // namespace 215 } // namespace
181 216
182 namespace ChoosePath = api::developer_private::ChoosePath; 217 namespace ChoosePath = api::developer_private::ChoosePath;
183 namespace GetItemsInfo = api::developer_private::GetItemsInfo; 218 namespace GetItemsInfo = api::developer_private::GetItemsInfo;
184 namespace PackDirectory = api::developer_private::PackDirectory; 219 namespace PackDirectory = api::developer_private::PackDirectory;
185 namespace Reload = api::developer_private::Reload; 220 namespace Reload = api::developer_private::Reload;
186 221
187 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > 222 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> >
188 g_factory = LAZY_INSTANCE_INITIALIZER; 223 g_factory = LAZY_INSTANCE_INITIALIZER;
189 224
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 content::BrowserThread::PostTask( 484 content::BrowserThread::PostTask(
450 content::BrowserThread::UI, 485 content::BrowserThread::UI,
451 FROM_HERE, 486 FROM_HERE,
452 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this)); 487 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this));
453 } 488 }
454 489
455 void DeveloperPrivateGetItemsInfoFunction::Finish() { 490 void DeveloperPrivateGetItemsInfoFunction::Finish() {
456 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_))); 491 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_)));
457 } 492 }
458 493
494 DeveloperPrivateGetProfileConfigurationFunction::
495 ~DeveloperPrivateGetProfileConfigurationFunction() {
496 }
497
498 ExtensionFunction::ResponseAction
499 DeveloperPrivateGetProfileConfigurationFunction::Run() {
500 developer::ProfileInfo info;
501 Profile* profile = Profile::FromBrowserContext(browser_context());
not at google - send to devlin 2015/04/08 17:12:02 If you inherit from ChromeUIThreadExtensionFunctio
Devlin 2015/04/09 19:57:24 Done.
502 info.is_supervised = profile->IsSupervised();
503 info.is_incognito_available =
504 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) !=
505 IncognitoModePrefs::DISABLED;
506 info.in_developer_mode =
507 !info.is_supervised &&
508 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
509 info.app_info_dialog_enabled = CanShowAppInfoDialog();
510 info.can_load_unpacked =
511 !ExtensionManagementFactory::GetForBrowserContext(profile)
512 ->BlacklistedByDefault();
513
514 // Promote the Chrome Apps & Extensions Developer Tools if they are not
515 // installed and the user has not previously dismissed the warning.
516 bool promote_apps_dev_tools = false;
517 if (!ExtensionRegistry::Get(profile)->GetExtensionById(
518 kAppsDeveloperToolsExtensionId, ExtensionRegistry::EVERYTHING) &&
519 !profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDismissedADTPromo)) {
520 promote_apps_dev_tools = true;
not at google - send to devlin 2015/04/08 17:12:02 you could also assign these directly to info.shoul
Devlin 2015/04/09 19:57:24 Moot - die, ADT promo, die!
521 }
522 info.should_show_adt_promo = promote_apps_dev_tools;
523
524 // If this is called from the chrome://extensions page, we use this as a
525 // heuristic that it's a good time to verify installs. We do this on startup,
526 // but there's a chance that it failed erroneously, so it's good to double-
527 // check.
528 if (source_context_type() == Feature::WEBUI_CONTEXT)
529 PerformVerificationCheck(browser_context());
530
531 return RespondNow(OneArgument(info.ToValue().release()));
not at google - send to devlin 2015/04/08 17:12:02 It's more principled to use the generated Result s
Devlin 2015/04/09 19:57:24 I like the latter.
532 }
533
534 DeveloperPrivateUpdateProfileConfigurationFunction::
535 ~DeveloperPrivateUpdateProfileConfigurationFunction() {
536 }
537
538 ExtensionFunction::ResponseAction
539 DeveloperPrivateUpdateProfileConfigurationFunction::Run() {
540 scoped_ptr<developer::UpdateProfileConfiguration::Params> params(
541 developer::UpdateProfileConfiguration::Params::Create(*args_));
542 EXTENSION_FUNCTION_VALIDATE(params);
543
544 Profile* profile = Profile::FromBrowserContext(browser_context());
545
546 const developer::ProfileConfigurationUpdate& update = params->update;
547 PrefService* prefs = profile->GetPrefs();
548 if (update.in_developer_mode) {
549 if (profile->IsSupervised())
550 return RespondNow(Error(kCannotUpdateSupervisedProfileSettingsError));
551 prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode,
552 *update.in_developer_mode);
553 }
554 if (update.dismissed_adt_promo) {
555 // It doesn't make sense for the user to "un-dismiss" the promo, so if this
556 // is present, it should always be true.
557 EXTENSION_FUNCTION_VALIDATE(*update.dismissed_adt_promo);
not at google - send to devlin 2015/04/08 17:12:02 Unless you do renderer validation, EXTENSION_FUNCT
Devlin 2015/04/09 19:57:24 Moot.
558 prefs->SetBoolean(prefs::kExtensionsUIDismissedADTPromo, true);
559 }
560
561 return RespondNow(NoArguments());
562 }
563
459 DeveloperPrivateUpdateExtensionConfigurationFunction:: 564 DeveloperPrivateUpdateExtensionConfigurationFunction::
460 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {} 565 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {}
461 566
462 ExtensionFunction::ResponseAction 567 ExtensionFunction::ResponseAction
463 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() { 568 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() {
464 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params( 569 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params(
465 developer::UpdateExtensionConfiguration::Params::Create(*args_)); 570 developer::UpdateExtensionConfiguration::Params::Create(*args_));
466 EXTENSION_FUNCTION_VALIDATE(params); 571 EXTENSION_FUNCTION_VALIDATE(params);
467 572
468 const developer::ExtensionConfigurationUpdate& update = params->update; 573 const developer::ExtensionConfigurationUpdate& update = params->update;
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 } 1290 }
1186 error_console->RemoveErrors(ErrorMap::Filter( 1291 error_console->RemoveErrors(ErrorMap::Filter(
1187 properties.extension_id, type, error_ids, false)); 1292 properties.extension_id, type, error_ids, false));
1188 1293
1189 return RespondNow(NoArguments()); 1294 return RespondNow(NoArguments());
1190 } 1295 }
1191 1296
1192 } // namespace api 1297 } // namespace api
1193 1298
1194 } // namespace extensions 1299 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698