Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| index d89f9f0cf65fb8fabf9c9263855aa85d7fcdfab6..6744c3a88e9918d50868efaada5ff535b3421ebd 100644 |
| --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/bind.h" |
| #include "base/files/file_util.h" |
| #include "base/lazy_instance.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -22,14 +23,18 @@ |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/extension_ui_util.h" |
| #include "chrome/browser/extensions/extension_util.h" |
| +#include "chrome/browser/extensions/install_verifier.h" |
| #include "chrome/browser/extensions/shared_module_service.h" |
| #include "chrome/browser/extensions/unpacked_installer.h" |
| #include "chrome/browser/extensions/updater/extension_updater.h" |
| +#include "chrome/browser/prefs/incognito_mode_prefs.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/apps/app_info_dialog.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/common/extensions/api/developer_private.h" |
| #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -88,10 +93,15 @@ const char kManifestKeyIsRequiredError[] = |
| "The 'manifestKey' argument is required for manifest files."; |
| const char kCouldNotFindWebContentsError[] = |
| "Could not find a valid web contents."; |
| +const char kCannotUpdateSupervisedProfileSettingsError[] = |
| + "Cannot change settings for a supervised profile."; |
| const char kUnpackedAppsFolder[] = "apps_target"; |
| const char kManifestFile[] = "manifest.json"; |
| +const char kAppsDeveloperToolsExtensionId[] = |
| + "ohmmkhmmmpcnpikjeljgnaoabkaalbgc"; |
| + |
| ExtensionService* GetExtensionService(content::BrowserContext* context) { |
| return ExtensionSystem::Get(context)->extension_service(); |
| } |
| @@ -177,6 +187,31 @@ bool UserCanModifyExtensionConfiguration( |
| return true; |
| } |
| +// Runs the install verifier for all extensions that are enabled, disabled, or |
| +// terminated. |
| +void PerformVerificationCheck(content::BrowserContext* context) { |
| + scoped_ptr<ExtensionSet> extensions = |
| + ExtensionRegistry::Get(context)->GenerateInstalledExtensionsSet( |
| + ExtensionRegistry::ENABLED | |
| + ExtensionRegistry::DISABLED | |
| + ExtensionRegistry::TERMINATED); |
| + ExtensionPrefs* prefs = ExtensionPrefs::Get(context); |
| + bool should_do_verification_check = false; |
| + for (const scoped_refptr<const Extension>& extension : *extensions) { |
| + if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), context) && |
| + ((prefs->GetDisableReasons(extension->id()) & |
| + Extension::DISABLE_NOT_VERIFIED) != 0)) { |
| + should_do_verification_check = true; |
| + break; |
| + } |
| + } |
| + |
| + UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", |
| + should_do_verification_check); |
| + if (should_do_verification_check) |
| + ExtensionSystem::Get(context)->install_verifier()->VerifyAllExtensions(); |
| +} |
| + |
| } // namespace |
| namespace ChoosePath = api::developer_private::ChoosePath; |
| @@ -456,6 +491,76 @@ void DeveloperPrivateGetItemsInfoFunction::Finish() { |
| Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_))); |
| } |
| +DeveloperPrivateGetProfileConfigurationFunction:: |
| +~DeveloperPrivateGetProfileConfigurationFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +DeveloperPrivateGetProfileConfigurationFunction::Run() { |
| + developer::ProfileInfo info; |
| + 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.
|
| + info.is_supervised = profile->IsSupervised(); |
| + info.is_incognito_available = |
| + IncognitoModePrefs::GetAvailability(profile->GetPrefs()) != |
| + IncognitoModePrefs::DISABLED; |
| + info.in_developer_mode = |
| + !info.is_supervised && |
| + profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| + info.app_info_dialog_enabled = CanShowAppInfoDialog(); |
| + info.can_load_unpacked = |
| + !ExtensionManagementFactory::GetForBrowserContext(profile) |
| + ->BlacklistedByDefault(); |
| + |
| + // Promote the Chrome Apps & Extensions Developer Tools if they are not |
| + // installed and the user has not previously dismissed the warning. |
| + bool promote_apps_dev_tools = false; |
| + if (!ExtensionRegistry::Get(profile)->GetExtensionById( |
| + kAppsDeveloperToolsExtensionId, ExtensionRegistry::EVERYTHING) && |
| + !profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDismissedADTPromo)) { |
| + 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!
|
| + } |
| + info.should_show_adt_promo = promote_apps_dev_tools; |
| + |
| + // If this is called from the chrome://extensions page, we use this as a |
| + // heuristic that it's a good time to verify installs. We do this on startup, |
| + // but there's a chance that it failed erroneously, so it's good to double- |
| + // check. |
| + if (source_context_type() == Feature::WEBUI_CONTEXT) |
| + PerformVerificationCheck(browser_context()); |
| + |
| + 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.
|
| +} |
| + |
| +DeveloperPrivateUpdateProfileConfigurationFunction:: |
| +~DeveloperPrivateUpdateProfileConfigurationFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +DeveloperPrivateUpdateProfileConfigurationFunction::Run() { |
| + scoped_ptr<developer::UpdateProfileConfiguration::Params> params( |
| + developer::UpdateProfileConfiguration::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params); |
| + |
| + Profile* profile = Profile::FromBrowserContext(browser_context()); |
| + |
| + const developer::ProfileConfigurationUpdate& update = params->update; |
| + PrefService* prefs = profile->GetPrefs(); |
| + if (update.in_developer_mode) { |
| + if (profile->IsSupervised()) |
| + return RespondNow(Error(kCannotUpdateSupervisedProfileSettingsError)); |
| + prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode, |
| + *update.in_developer_mode); |
| + } |
| + if (update.dismissed_adt_promo) { |
| + // It doesn't make sense for the user to "un-dismiss" the promo, so if this |
| + // is present, it should always be true. |
| + 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.
|
| + prefs->SetBoolean(prefs::kExtensionsUIDismissedADTPromo, true); |
| + } |
| + |
| + return RespondNow(NoArguments()); |
| +} |
| + |
| DeveloperPrivateUpdateExtensionConfigurationFunction:: |
| ~DeveloperPrivateUpdateExtensionConfigurationFunction() {} |