Chromium Code Reviews| Index: chrome/browser/extensions/extension_util.cc |
| diff --git a/chrome/browser/extensions/extension_util.cc b/chrome/browser/extensions/extension_util.cc |
| index 4a861653b6ebb4e3906532324f16a8e501d3f259..5541919155e3072585351e54c53783d0d2abf025 100644 |
| --- a/chrome/browser/extensions/extension_util.cc |
| +++ b/chrome/browser/extensions/extension_util.cc |
| @@ -54,6 +54,10 @@ const char kExtensionAllowedOnAllUrlsPrefName[] = |
| // allowed on all urls" pref. |
| const char kHasSetScriptOnAllUrlsPrefName[] = "has_set_script_all_urls"; |
| +// The entry into the prefs used to flag an extension as installed by custodian. |
| +// It is relevant only for supervised users |
| +const char kWasInstalledByCustodianPrefName[] = "was_installed_by_custodian"; |
| + |
| // Returns true if |extension| should always be enabled in incognito mode. |
| bool IsWhitelistedForIncognito(const Extension* extension) { |
| const Feature* feature = FeatureProvider::GetBehaviorFeature( |
| @@ -220,6 +224,35 @@ void SetAllowFileAccess(const std::string& extension_id, |
| ReloadExtensionIfEnabled(extension_id, context); |
| } |
| +void SetWasInstalledByCustodian(const std::string& extension_id, |
| + content::BrowserContext* context, |
| + bool installed_by_custodian) { |
| + const Extension* extension = |
| + ExtensionRegistry::Get(context)->GetInstalledExtension(extension_id); |
| + // Extension can be null if it exists in the sync data but not yet installed. |
| + if (extension && |
| + installed_by_custodian == extension->was_installed_by_custodian()) |
| + return; |
| + ExtensionPrefs::Get(context)->UpdateExtensionPref( |
| + extension_id, kWasInstalledByCustodianPrefName, |
| + new base::FundamentalValue(installed_by_custodian)); |
| + |
|
Devlin
2016/06/15 00:30:36
maybe also:
if (!extension)
return;
mamir
2016/06/15 09:54:41
Done.
mamir
2016/06/15 15:09:59
Not really.
If we return here, the extension won't
|
| + ExtensionService* service = |
| + ExtensionSystem::Get(context)->extension_service(); |
| + // Since the was_installed_by_custodian is stored as a creation flag in the |
| + // Extension immutable object, a reload is required. |
| + service->ReloadExtension(extension_id); |
| +} |
| + |
| +bool WasInstalledByCustodian(const std::string& extension_id, |
| + content::BrowserContext* context) { |
| + bool installed_by_custodian = false; |
| + ExtensionPrefs* prefs = ExtensionPrefs::Get(context); |
| + prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName, |
| + &installed_by_custodian); |
| + return installed_by_custodian; |
| +} |
| + |
| bool AllowedScriptingOnAllUrls(const std::string& extension_id, |
| content::BrowserContext* context) { |
| bool allowed = false; |