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..a92894d1f718aec2b0c704aae5942b58c5df38b6 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,49 @@ 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) { |
| + if (installed_by_custodian == WasInstalledByCustodian(extension_id, context)) |
| + return; |
| + |
| + ExtensionPrefs::Get(context)->UpdateExtensionPref( |
| + extension_id, kWasInstalledByCustodianPrefName, |
| + installed_by_custodian ? new base::FundamentalValue(true) : nullptr); |
| + ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| + const Extension* extension = registry->GetInstalledExtension(extension_id); |
| + |
| + // If the installed_by_custodian flag is reset, do nothing. |
| + if (!installed_by_custodian) { |
| + // If installed_by_custodian changes to false, the extension may need to |
| + // be unloaded now. |
| + service->ReloadExtension(extension_id); |
|
Devlin
2016/06/20 17:09:24
Where is service defined?
mamir
2016/06/21 11:38:22
Sorry!
Done!
|
| + return; |
| + } |
| + |
| + // If it is already enabled, do nothing. |
| + if (registry->enabled_extensions().Contains(extension_id)) |
| + return; |
| + |
| + // If the extension is not installed, it may need to be reloaded. |
|
Devlin
2016/06/20 17:09:25
This comment doesn't make sense. If it's not inst
mamir
2016/06/21 11:38:22
Done.
|
| + // Example is a pre-installed extension that was unloaded when a |
| + // supervised user flag has been received. |
| + if (!extension) { |
| + ExtensionService* service = |
| + ExtensionSystem::Get(context)->extension_service(); |
| + 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; |
| @@ -378,8 +425,9 @@ bool CanHostedAppsOpenInWindows() { |
| #endif |
| } |
| -bool IsExtensionSupervised(const Extension* extension, const Profile* profile) { |
| - return extension->was_installed_by_custodian() && profile->IsSupervised(); |
| +bool IsExtensionSupervised(const Extension* extension, Profile* profile) { |
| + return WasInstalledByCustodian(extension->id(), profile) && |
| + profile->IsSupervised(); |
| } |
| bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) { |