OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/extension_util.h" | 5 #include "extensions/browser/extension_util.h" |
6 | 6 |
7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
8 #include "content/public/browser/site_instance.h" | 8 #include "content/public/browser/site_instance.h" |
9 #include "extensions/browser/extension_prefs.h" | 9 #include "extensions/browser/extension_prefs.h" |
10 #include "extensions/browser/extension_registry.h" | 10 #include "extensions/browser/extension_registry.h" |
| 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" |
11 #include "extensions/common/manifest_handlers/app_isolation_info.h" | 15 #include "extensions/common/manifest_handlers/app_isolation_info.h" |
12 #include "extensions/common/manifest_handlers/incognito_info.h" | 16 #include "extensions/common/manifest_handlers/incognito_info.h" |
13 | 17 |
14 namespace extensions { | 18 namespace extensions { |
15 namespace util { | 19 namespace util { |
16 | 20 |
| 21 namespace { |
| 22 |
| 23 // Returns true if |extension| should always be enabled in incognito mode. |
| 24 bool IsWhitelistedForIncognito(const Extension* extension) { |
| 25 const Feature* feature = FeatureProvider::GetBehaviorFeature( |
| 26 behavior_feature::kWhitelistedForIncognito); |
| 27 return feature && feature->IsAvailableToExtension(extension).is_available(); |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
17 bool HasIsolatedStorage(const ExtensionInfo& info) { | 32 bool HasIsolatedStorage(const ExtensionInfo& info) { |
18 if (!info.extension_manifest.get()) | 33 if (!info.extension_manifest.get()) |
19 return false; | 34 return false; |
20 | 35 |
21 std::string error; | 36 std::string error; |
22 scoped_refptr<const Extension> extension(Extension::Create( | 37 scoped_refptr<const Extension> extension(Extension::Create( |
23 info.extension_path, | 38 info.extension_path, |
24 info.extension_location, | 39 info.extension_location, |
25 *info.extension_manifest, | 40 *info.extension_manifest, |
26 Extension::NO_FLAGS, | 41 Extension::NO_FLAGS, |
(...skipping 11 matching lines...) Expand all Loading... |
38 | 53 |
39 return extension && AppIsolationInfo::HasIsolatedStorage(extension); | 54 return extension && AppIsolationInfo::HasIsolatedStorage(extension); |
40 } | 55 } |
41 | 56 |
42 bool CanBeIncognitoEnabled(const Extension* extension) { | 57 bool CanBeIncognitoEnabled(const Extension* extension) { |
43 return IncognitoInfo::IsIncognitoAllowed(extension) && | 58 return IncognitoInfo::IsIncognitoAllowed(extension) && |
44 (!extension->is_platform_app() || | 59 (!extension->is_platform_app() || |
45 extension->location() == Manifest::COMPONENT); | 60 extension->location() == Manifest::COMPONENT); |
46 } | 61 } |
47 | 62 |
| 63 bool IsIncognitoEnabled(const std::string& extension_id, |
| 64 content::BrowserContext* context) { |
| 65 const Extension* extension = |
| 66 ExtensionRegistry::Get(context)->GetExtensionById( |
| 67 extension_id, ExtensionRegistry::ENABLED); |
| 68 if (extension) { |
| 69 if (!CanBeIncognitoEnabled(extension)) |
| 70 return false; |
| 71 // If this is an existing component extension we always allow it to |
| 72 // work in incognito mode. |
| 73 if (Manifest::IsComponentLocation(extension->location())) |
| 74 return true; |
| 75 if (IsWhitelistedForIncognito(extension)) |
| 76 return true; |
| 77 } |
| 78 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id); |
| 79 } |
| 80 |
48 content::StoragePartition* GetStoragePartitionForExtensionId( | 81 content::StoragePartition* GetStoragePartitionForExtensionId( |
49 const std::string& extension_id, | 82 const std::string& extension_id, |
50 content::BrowserContext* browser_context) { | 83 content::BrowserContext* browser_context) { |
51 GURL site_url = content::SiteInstance::GetSiteForURL( | 84 GURL site_url = content::SiteInstance::GetSiteForURL( |
52 browser_context, Extension::GetBaseURLFromExtensionId(extension_id)); | 85 browser_context, Extension::GetBaseURLFromExtensionId(extension_id)); |
53 content::StoragePartition* storage_partition = | 86 content::StoragePartition* storage_partition = |
54 content::BrowserContext::GetStoragePartitionForSite(browser_context, | 87 content::BrowserContext::GetStoragePartitionForSite(browser_context, |
55 site_url); | 88 site_url); |
56 return storage_partition; | 89 return storage_partition; |
57 } | 90 } |
58 | 91 |
59 } // namespace util | 92 } // namespace util |
60 } // namespace extensions | 93 } // namespace extensions |
OLD | NEW |