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