[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "extensions/browser/extension_util.h" |
| 6 | |
lazyboy | 4c82177a | 2016-10-18 00:04:09 | [diff] [blame] | 7 | #include "content/public/browser/browser_context.h" |
| 8 | #include "content/public/browser/site_instance.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 9 | #include "extensions/browser/extension_prefs.h" |
| 10 | #include "extensions/browser/extension_registry.h" |
karandeepb | 810e3340 | 2017-04-05 23:41:22 | [diff] [blame] | 11 | #include "extensions/common/features/behavior_feature.h" |
| 12 | #include "extensions/common/features/feature.h" |
| 13 | #include "extensions/common/features/feature_provider.h" |
| 14 | #include "extensions/common/manifest.h" |
tfarina | 01710e3 | 2015-07-13 21:53:22 | [diff] [blame] | 15 | #include "extensions/common/manifest_handlers/app_isolation_info.h" |
kundaji | e548e744 | 2015-09-18 23:19:09 | [diff] [blame] | 16 | #include "extensions/common/manifest_handlers/incognito_info.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 17 | |
| 18 | namespace extensions { |
| 19 | namespace util { |
| 20 | |
tfarina | 01710e3 | 2015-07-13 21:53:22 | [diff] [blame] | 21 | bool SiteHasIsolatedStorage(const GURL& extension_site_url, |
| 22 | content::BrowserContext* context) { |
| 23 | const Extension* extension = ExtensionRegistry::Get(context)-> |
| 24 | enabled_extensions().GetExtensionOrAppByURL(extension_site_url); |
| 25 | |
| 26 | return extension && AppIsolationInfo::HasIsolatedStorage(extension); |
| 27 | } |
| 28 | |
kundaji | e548e744 | 2015-09-18 23:19:09 | [diff] [blame] | 29 | bool CanBeIncognitoEnabled(const Extension* extension) { |
| 30 | return IncognitoInfo::IsIncognitoAllowed(extension) && |
| 31 | (!extension->is_platform_app() || |
| 32 | extension->location() == Manifest::COMPONENT); |
| 33 | } |
| 34 | |
karandeepb | 810e3340 | 2017-04-05 23:41:22 | [diff] [blame] | 35 | bool IsIncognitoEnabled(const std::string& extension_id, |
| 36 | content::BrowserContext* context) { |
| 37 | const Extension* extension = |
| 38 | ExtensionRegistry::Get(context)->GetExtensionById( |
| 39 | extension_id, ExtensionRegistry::ENABLED); |
| 40 | if (extension) { |
| 41 | if (!CanBeIncognitoEnabled(extension)) |
| 42 | return false; |
| 43 | // If this is an existing component extension we always allow it to |
| 44 | // work in incognito mode. |
| 45 | if (Manifest::IsComponentLocation(extension->location())) |
| 46 | return true; |
Alexander Hendrich | d03bafa | 2019-05-29 22:18:03 | [diff] [blame^] | 47 | if (extension->is_login_screen_extension()) |
| 48 | return true; |
karandeepb | 810e3340 | 2017-04-05 23:41:22 | [diff] [blame] | 49 | } |
| 50 | return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); |
| 51 | } |
| 52 | |
Michael Giuffrida | 7efeed14 | 2017-06-07 06:29:21 | [diff] [blame] | 53 | GURL GetSiteForExtensionId(const std::string& extension_id, |
| 54 | content::BrowserContext* context) { |
| 55 | return content::SiteInstance::GetSiteForURL( |
| 56 | context, Extension::GetBaseURLFromExtensionId(extension_id)); |
| 57 | } |
| 58 | |
lazyboy | 4c82177a | 2016-10-18 00:04:09 | [diff] [blame] | 59 | content::StoragePartition* GetStoragePartitionForExtensionId( |
| 60 | const std::string& extension_id, |
| 61 | content::BrowserContext* browser_context) { |
| 62 | GURL site_url = content::SiteInstance::GetSiteForURL( |
| 63 | browser_context, Extension::GetBaseURLFromExtensionId(extension_id)); |
| 64 | content::StoragePartition* storage_partition = |
| 65 | content::BrowserContext::GetStoragePartitionForSite(browser_context, |
| 66 | site_url); |
| 67 | return storage_partition; |
| 68 | } |
| 69 | |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 70 | } // namespace util |
| 71 | } // namespace extensions |