blob: 70b726136c06bb477d9cfe9df716a56cf870dd76 [file] [log] [blame]
[email protected]a7ff4b72013-10-17 20:56:021// 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
dchengc963c7142016-04-08 03:55:228#include <memory>
[email protected]a7ff4b72013-10-17 20:56:029#include <string>
10
Alan Cutter70927ec92018-03-22 00:58:4911#include "base/optional.h"
12#include "extensions/common/constants.h"
13
[email protected]bb2feea2014-03-18 22:08:1314namespace base {
15class DictionaryValue;
16}
17
[email protected]1d5cf4142014-01-24 18:25:2218namespace content {
19class BrowserContext;
[email protected]a7ff4b72013-10-17 20:56:0220}
21
[email protected]7eb20e32014-04-30 08:50:5622namespace gfx {
23class ImageSkia;
24}
25
Alan Cutter70927ec92018-03-22 00:58:4926class GURL;
treibbb9a1962015-02-25 13:40:5927class Profile;
28
[email protected]1d5cf4142014-01-24 18:25:2229namespace extensions {
[email protected]a7ff4b72013-10-17 20:56:0230
[email protected]1d5cf4142014-01-24 18:25:2231class Extension;
[email protected]a7ff4b72013-10-17 20:56:0232
[email protected]1d5cf4142014-01-24 18:25:2233namespace util {
34
Pavol Marko41c37b12019-08-07 10:56:3235// 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.
39bool SiteHasIsolatedStorage(const GURL& extension_site_url,
40 content::BrowserContext* context);
41
[email protected]1d5cf4142014-01-24 18:25:2242// 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]a7ff4b72013-10-17 20:56:0245void SetIsIncognitoEnabled(const std::string& extension_id,
[email protected]1d5cf4142014-01-24 18:25:2246 content::BrowserContext* context,
[email protected]a7ff4b72013-10-17 20:56:0247 bool enabled);
48
[email protected]1d5cf4142014-01-24 18:25:2249// Returns true if |extension| can be loaded in incognito.
[email protected]a7ff4b72013-10-17 20:56:0250bool CanLoadInIncognito(const extensions::Extension* extension,
[email protected]1d5cf4142014-01-24 18:25:2251 content::BrowserContext* context);
[email protected]a7ff4b72013-10-17 20:56:0252
[email protected]1d5cf4142014-01-24 18:25:2253// Returns true if this extension can inject scripts into pages with file URLs.
54bool AllowFileAccess(const std::string& extension_id,
55 content::BrowserContext* context);
[email protected]a7ff4b72013-10-17 20:56:0256
[email protected]1d5cf4142014-01-24 18:25:2257// 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.
60void SetAllowFileAccess(const std::string& extension_id,
61 content::BrowserContext* context,
[email protected]a7ff4b72013-10-17 20:56:0262 bool allow);
63
mamir192d7882016-06-22 17:10:1664// 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.
67bool 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).
74void SetWasInstalledByCustodian(const std::string& extension_id,
75 content::BrowserContext* context,
76 bool installed_by_custodian);
77
[email protected]1d5cf4142014-01-24 18:25:2278// Returns true if |extension_id| can be launched (possibly only after being
79// enabled).
[email protected]f5ea0962013-11-22 09:20:4780bool IsAppLaunchable(const std::string& extension_id,
[email protected]1d5cf4142014-01-24 18:25:2281 content::BrowserContext* context);
[email protected]f5ea0962013-11-22 09:20:4782
[email protected]1d5cf4142014-01-24 18:25:2283// Returns true if |extension_id| can be launched without being enabled first.
[email protected]f5ea0962013-11-22 09:20:4784bool IsAppLaunchableWithoutEnabling(const std::string& extension_id,
[email protected]1d5cf4142014-01-24 18:25:2285 content::BrowserContext* context);
[email protected]f5ea0962013-11-22 09:20:4786
[email protected]658eae52014-06-14 20:28:0587// Returns true if |extension| should be synced.
treibc644a1c2015-07-13 08:37:0488bool ShouldSync(const Extension* extension, content::BrowserContext* context);
[email protected]30e190f82014-05-26 16:44:3989
[email protected]1d5cf4142014-01-24 18:25:2290// Returns true if |extension_id| is idle and it is safe to perform actions such
91// as updating.
[email protected]617342a42013-12-18 23:34:0392bool IsExtensionIdle(const std::string& extension_id,
[email protected]1d5cf4142014-01-24 18:25:2293 content::BrowserContext* context);
[email protected]617342a42013-12-18 23:34:0394
[email protected]bb2feea2014-03-18 22:08:1395// Sets the name, id, and icon resource path of the given extension into the
96// returned dictionary.
dchengc963c7142016-04-08 03:55:2297std::unique_ptr<base::DictionaryValue> GetExtensionInfo(
98 const Extension* extension);
[email protected]bb2feea2014-03-18 22:08:1399
[email protected]7eb20e32014-04-30 08:50:56100// Returns the default extension/app icon (for extensions or apps that don't
101// have one).
102const gfx::ImageSkia& GetDefaultExtensionIcon();
103const gfx::ImageSkia& GetDefaultAppIcon();
104
treibbb9a1962015-02-25 13:40:59105// Returns true for custodian-installed extensions in a supervised profile.
mamir192d7882016-06-22 17:10:16106bool IsExtensionSupervised(const Extension* extension, Profile* profile);
treibbb9a1962015-02-25 13:40:59107
Alan Cutter70927ec92018-03-22 00:58:49108// Finds the first PWA with |url| in its scope, returns nullptr if there are
109// none.
110const Extension* GetInstalledPwaForUrl(
111 content::BrowserContext* context,
112 const GURL& url,
113 base::Optional<LaunchContainer> launch_container_filter = base::nullopt);
114
[email protected]1d5cf4142014-01-24 18:25:22115} // namespace util
116} // namespace extensions
[email protected]a7ff4b72013-10-17 20:56:02117
118#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_