[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 1 | // Copyright 2013 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 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_ |
| 7 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 8 | #include <memory> |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Alan Cutter | 70927ec9 | 2018-03-22 00:58:49 | [diff] [blame] | 11 | #include "base/optional.h" |
| 12 | #include "extensions/common/constants.h" |
| 13 | |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 14 | namespace base { |
| 15 | class DictionaryValue; |
| 16 | } |
| 17 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 18 | namespace content { |
| 19 | class BrowserContext; |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 22 | namespace gfx { |
| 23 | class ImageSkia; |
| 24 | } |
| 25 | |
Alan Cutter | 70927ec9 | 2018-03-22 00:58:49 | [diff] [blame] | 26 | class GURL; |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 27 | class Profile; |
| 28 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 29 | namespace extensions { |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 30 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 31 | class Extension; |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 32 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 33 | namespace util { |
| 34 | |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 35 | // Returns true if the site URL corresponds to an extension or app which |
| 36 | // has isolated storage. This can be either because it is an app that |
| 37 | // requested this in its manifest, or because it is a policy-installed app or |
| 38 | // extension running on the Chrome OS sign-in profile. |
| 39 | bool SiteHasIsolatedStorage(const GURL& extension_site_url, |
| 40 | content::BrowserContext* context); |
| 41 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 42 | // Sets whether |extension_id| can run in an incognito window. Reloads the |
| 43 | // extension if it's enabled since this permission is applied at loading time |
| 44 | // only. Note that an ExtensionService must exist. |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 45 | void SetIsIncognitoEnabled(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 46 | content::BrowserContext* context, |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 47 | bool enabled); |
| 48 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 49 | // Returns true if |extension| can be loaded in incognito. |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 50 | bool CanLoadInIncognito(const extensions::Extension* extension, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 51 | content::BrowserContext* context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 52 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 53 | // Returns true if this extension can inject scripts into pages with file URLs. |
| 54 | bool AllowFileAccess(const std::string& extension_id, |
| 55 | content::BrowserContext* context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 56 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 57 | // Sets whether |extension_id| can inject scripts into pages with file URLs. |
| 58 | // Reloads the extension if it's enabled since this permission is applied at |
| 59 | // loading time only. Note than an ExtensionService must exist. |
| 60 | void SetAllowFileAccess(const std::string& extension_id, |
| 61 | content::BrowserContext* context, |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 62 | bool allow); |
| 63 | |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 64 | // Returns true if this extension has been installed by the custodian of |
| 65 | // a supervised user. It is relevant for supervised users and used to block |
| 66 | // them from uninstalling the extension for example. |
| 67 | bool WasInstalledByCustodian(const std::string& extension_id, |
| 68 | content::BrowserContext* context); |
| 69 | |
| 70 | // Sets whether |extension_id| is installed by a custodian. |
| 71 | // This is relevant for supervised users and is used to limit their privileges |
| 72 | // for extensions installed by their custodians (e.g. supervised users cannot |
| 73 | // uninstall such extensions). |
| 74 | void SetWasInstalledByCustodian(const std::string& extension_id, |
| 75 | content::BrowserContext* context, |
| 76 | bool installed_by_custodian); |
| 77 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 78 | // Returns true if |extension_id| can be launched (possibly only after being |
| 79 | // enabled). |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 80 | bool IsAppLaunchable(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 81 | content::BrowserContext* context); |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 82 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 83 | // Returns true if |extension_id| can be launched without being enabled first. |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 84 | bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 85 | content::BrowserContext* context); |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 86 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 87 | // Returns true if |extension| should be synced. |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 88 | bool ShouldSync(const Extension* extension, content::BrowserContext* context); |
[email protected] | 30e190f8 | 2014-05-26 16:44:39 | [diff] [blame] | 89 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 90 | // Returns true if |extension_id| is idle and it is safe to perform actions such |
| 91 | // as updating. |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 92 | bool IsExtensionIdle(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 93 | content::BrowserContext* context); |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 94 | |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 95 | // Sets the name, id, and icon resource path of the given extension into the |
| 96 | // returned dictionary. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 97 | std::unique_ptr<base::DictionaryValue> GetExtensionInfo( |
| 98 | const Extension* extension); |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 99 | |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 100 | // Returns the default extension/app icon (for extensions or apps that don't |
| 101 | // have one). |
| 102 | const gfx::ImageSkia& GetDefaultExtensionIcon(); |
| 103 | const gfx::ImageSkia& GetDefaultAppIcon(); |
| 104 | |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 105 | // Returns true for custodian-installed extensions in a supervised profile. |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 106 | bool IsExtensionSupervised(const Extension* extension, Profile* profile); |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 107 | |
Alan Cutter | 70927ec9 | 2018-03-22 00:58:49 | [diff] [blame] | 108 | // Finds the first PWA with |url| in its scope, returns nullptr if there are |
| 109 | // none. |
| 110 | const Extension* GetInstalledPwaForUrl( |
| 111 | content::BrowserContext* context, |
| 112 | const GURL& url, |
| 113 | base::Optional<LaunchContainer> launch_container_filter = base::nullopt); |
| 114 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 115 | } // namespace util |
| 116 | } // namespace extensions |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 117 | |
| 118 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_ |