File: extension_util.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (181 lines) | stat: -rw-r--r-- 7,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_EXTENSION_UTIL_H_
#define EXTENSIONS_BROWSER_EXTENSION_UTIL_H_

#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/manifest.h"
#include "url/gurl.h"

namespace base {
class FilePath;
}  // namespace base

namespace gfx {
class ImageSkia;
}  // namespace gfx

namespace content {
class BrowserContext;
class ServiceWorkerContext;
class SiteInstance;
class StoragePartition;
class StoragePartitionConfig;
class RenderFrameHost;
}  // namespace content

namespace extensions {
class Extension;
class ExtensionSet;

namespace util {

// TODO(crbug.com/40893821): Move functions from
// chrome/browser/extensions/extension_util.h/cc that are only dependent on
// extensions/ here.

// Returns true if the extension can be enabled in incognito mode.
bool CanBeIncognitoEnabled(const Extension* extension);

// Returns true if `extension_id` can run in an incognito window.
bool IsIncognitoEnabled(const ExtensionId& extension_id,
                        content::BrowserContext* context);

// Returns true if `extension` can see events and data from another sub-profile
// (incognito to original profile, or vice versa).
bool CanCrossIncognito(const Extension* extension,
                       content::BrowserContext* context);

// Returns true if the extension associated with `extension_id` is idle and it
// is safe to perform actions such as updating.
bool IsExtensionIdle(const ExtensionId& extension_id,
                     content::BrowserContext* browser_context);

// Returns true if prompting for external extensions is enabled.
bool IsPromptingEnabled();

// Returns true if this extension can inject scripts into pages with file URLs.
bool AllowFileAccess(const ExtensionId& extension_id,
                     content::BrowserContext* context);

// Returns the StoragePartition domain for `extension`.
// Note: The reference returned has the same lifetime as `extension`.
const std::string& GetPartitionDomainForExtension(const Extension* extension);

// Returns an extension specific StoragePartitionConfig if the extension
// associated with `extension_id` has isolated storage.
// Otherwise, return the default StoragePartitionConfig.
content::StoragePartitionConfig GetStoragePartitionConfigForExtensionId(
    const ExtensionId& extension_id,
    content::BrowserContext* browser_context);

content::StoragePartition* GetStoragePartitionForExtensionId(
    const ExtensionId& extension_id,
    content::BrowserContext* browser_context,
    bool can_create = true);

// Returns the ServiceWorkerContext associated with the given `extension_id`.
content::ServiceWorkerContext* GetServiceWorkerContextForExtensionId(
    const ExtensionId& extension_id,
    content::BrowserContext* browser_context);

// Maps a `file_url` to a `file_path` on the local filesystem, including
// resources in extensions. Returns true on success. See NaClBrowserDelegate for
// full details. If `use_blocking_api` is false, only a subset of URLs will be
// handled. If `use_blocking_api` is true, blocking file operations may be used,
// and this must be called on threads that allow blocking. Otherwise this can be
// called on any thread.
bool MapUrlToLocalFilePath(const ExtensionSet* extensions,
                           const GURL& file_url,
                           bool use_blocking_api,
                           base::FilePath* file_path);

// Returns true if the browser can potentially withhold permissions from the
// extension.
bool CanWithholdPermissionsFromExtension(const Extension& extension);
bool CanWithholdPermissionsFromExtension(
    const ExtensionId& extension_id,
    const Manifest::Type type,
    const mojom::ManifestLocation location);

// Returns a unique int id for each context. Prefer using
// `BrowserContext::UniqueId()` directly.
// TODO(crbug.com/40267637):  Migrate callers to use the `context` unique id
// directly. For that we need to update all data keyed by integer context ids to
// be keyed by strings instead.
int GetBrowserContextId(content::BrowserContext* context);

// Returns whether the `extension` should be loaded in the given
// `browser_context`.
bool IsExtensionVisibleToContext(const Extension& extension,
                                 content::BrowserContext* browser_context);

// Initializes file scheme access if the extension has such permission.
void InitializeFileSchemeAccessForExtension(
    int render_process_id,
    const ExtensionId& extension_id,
    content::BrowserContext* browser_context);

// Returns the default extension/app icon (for extensions or apps that don't
// have one).
const gfx::ImageSkia& GetDefaultExtensionIcon();
const gfx::ImageSkia& GetDefaultAppIcon();

// Gets the ExtensionId associated with the given `site_instance`.  An empty
// string is returned when `site_instance` is not associated with an extension.
ExtensionId GetExtensionIdForSiteInstance(content::SiteInstance& site_instance);

// Returns the extension id associated with the given `render_frame_host`, or
// the empty string if there is none.
std::string GetExtensionIdFromFrame(
    content::RenderFrameHost* render_frame_host);

// Returns true if the process corresponding to `render_process_id` can host an
// extension with `extension_id`.  (It doesn't necessarily mean that the process
// *does* host this specific extension at this point in time.) `is_sandboxed`
// specifies whether this is asking about a sandboxed extension document and is
// needed to accurately compute the expected extension origin for that case.
bool CanRendererHostExtensionOrigin(int render_process_id,
                                    const ExtensionId& extension_id,
                                    bool is_sandboxed);

// Returns `true` if `render_process_host` can legitimately claim to send IPC
// messages on behalf of `extension_id`.  `render_frame_host` parameter is
// needed to account for scenarios involving a Chrome Web Store frame.
bool CanRendererActOnBehalfOfExtension(
    const ExtensionId& extension_id,
    content::RenderFrameHost* render_frame_host,
    content::RenderProcessHost& render_process_host,
    bool include_user_scripts);

// Returns true if the extension associated with `extension_id` is a Chrome App.
bool IsChromeApp(const ExtensionId& extension_id,
                 content::BrowserContext* context);

// Returns true if `extension_id` can be launched (possibly only after being
// enabled).
bool IsAppLaunchable(const ExtensionId& extension_id,
                     content::BrowserContext* context);

// Returns true if `extension_id` can be launched without being enabled first.
bool IsAppLaunchableWithoutEnabling(const ExtensionId& extension_id,
                                    content::BrowserContext* context);

// Returns `true` if any currently installed extension was installed from the
// webstore, otherwise false.
bool AnyCurrentlyInstalledExtensionIsFromWebstore(
    content::BrowserContext* context);

}  // namespace util
}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_EXTENSION_UTIL_H_