blob: 3cd9723c4d58dca9db2724687a39bf854516beab [file] [log] [blame]
[email protected]411f8ae2014-05-22 11:12:231// 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
lazyboy4c82177a2016-10-18 00:04:097#include "content/public/browser/browser_context.h"
8#include "content/public/browser/site_instance.h"
[email protected]411f8ae2014-05-22 11:12:239#include "extensions/browser/extension_prefs.h"
10#include "extensions/browser/extension_registry.h"
karandeepb810e33402017-04-05 23:41:2211#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"
tfarina01710e32015-07-13 21:53:2215#include "extensions/common/manifest_handlers/app_isolation_info.h"
kundajie548e7442015-09-18 23:19:0916#include "extensions/common/manifest_handlers/incognito_info.h"
[email protected]411f8ae2014-05-22 11:12:2317
18namespace extensions {
19namespace util {
20
tfarina01710e32015-07-13 21:53:2221bool 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
kundajie548e7442015-09-18 23:19:0929bool CanBeIncognitoEnabled(const Extension* extension) {
30 return IncognitoInfo::IsIncognitoAllowed(extension) &&
31 (!extension->is_platform_app() ||
32 extension->location() == Manifest::COMPONENT);
33}
34
karandeepb810e33402017-04-05 23:41:2235bool 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 Hendrichd03bafa2019-05-29 22:18:0347 if (extension->is_login_screen_extension())
48 return true;
karandeepb810e33402017-04-05 23:41:2249 }
50 return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id);
51}
52
Michael Giuffrida7efeed142017-06-07 06:29:2153GURL GetSiteForExtensionId(const std::string& extension_id,
54 content::BrowserContext* context) {
55 return content::SiteInstance::GetSiteForURL(
56 context, Extension::GetBaseURLFromExtensionId(extension_id));
57}
58
lazyboy4c82177a2016-10-18 00:04:0959content::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]411f8ae2014-05-22 11:12:2370} // namespace util
71} // namespace extensions