File: WebExtensionContentScript.webidl

package info (click to toggle)
firefox 148.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,719,656 kB
  • sloc: cpp: 7,618,171; javascript: 6,701,506; ansic: 3,781,787; python: 1,418,364; xml: 638,647; asm: 438,962; java: 186,285; sh: 62,885; makefile: 19,010; objc: 13,092; perl: 12,763; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (253 lines) | stat: -rw-r--r-- 7,478 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

interface LoadInfo;
interface URI;
interface WindowProxy;

typedef (MatchPatternSet or sequence<DOMString>) MatchPatternSetOrStringSequence;
typedef (MatchGlob or UTF8String) MatchGlobOrString;

[ChromeOnly, Exposed=Window]
interface MozDocumentMatcher {
  [Throws]
  constructor(MozDocumentMatcherInit options);

  /**
   * Returns true if the script's match and exclude patterns match the given
   * URI, without reference to attributes such as `allFrames`.
   */
  boolean matchesURI(URI uri);

  /**
   * Returns true if the given window matches. This should be used to
   * determine whether to run a script in a window at load time. Use
   * ignorePermissions to match without origin permissions in MV3.
   */
  boolean matchesWindowGlobal(WindowGlobalChild windowGlobal,
                              optional boolean ignorePermissions = false);

  /**
   * If true, match all frames. If false, match only top-level frames.
   */
  [Constant]
  readonly attribute boolean allFrames;

  /**
   * If we can't check extension has permissions to access the URI upfront,
   * set the flag to perform the origin check at runtime, upon matching.
   * This is always true in MV3, where host permissions are optional.
   */
  [Constant]
  readonly attribute boolean checkPermissions;

  /**
   * If true, this causes us to match about:blank and about:srcdoc documents by
   * the URL of the inherit principal, usually the initial URL of the document
   * that triggered the navigation.
   * If false, we only match frames with an explicit matching URL.
   */
  [Constant]
  readonly attribute boolean matchAboutBlank;

  /**
   * If true, this causes us to match documents with opaque URLs (such as
   * about:blank, about:srcdoc, data:, blob:, and sandboxed versions thereof)
   * by the document principal's origin URI. In case of null principals, their
   * precursor is used for matching.
   * When true, matchAboutBlank is implicitly true.
   * If false, we only match frames with an explicit matching URL.
   */
  [Constant]
  readonly attribute boolean matchOriginAsFallback;

  /**
   * The outer window ID of the frame in which to run the script, or 0 if it
   * should run in the top-level frame. Should only be used for
   * dynamically-injected scripts.
   */
  [Constant]
  readonly attribute unsigned long long? frameID;

  /**
   * The set of match patterns for URIs of pages in which this script should
   * run. This attribute is mandatory, and is a prerequisite for all other
   * match patterns.
   */
  [Constant]
  readonly attribute MatchPatternSet matches;

  /**
   * A set of match patterns for URLs in which this script should not run,
   * even if they match other include patterns or globs.
   */
  [Constant]
  readonly attribute MatchPatternSet? excludeMatches;

  /**
   * Whether the matcher is used by the MV3 userScripts API.
   * If true, URLs are matched when they match "matches" OR "includeGlobs",
   * instead of the usual AND.
   */
  [Constant]
  readonly attribute boolean isUserScript;

  /**
   * The originAttributesPattern for which this script should be enabled for.
   */
  [Constant, Throws]
  readonly attribute any originAttributesPatterns;

  /**
   * The policy object for the extension that this matcher belongs to.
   */
  [Constant]
  readonly attribute WebExtensionPolicy? extension;
};

dictionary MozDocumentMatcherInit {
  boolean allFrames = false;

  boolean checkPermissions = false;

  sequence<OriginAttributesPatternDictionary>? originAttributesPatterns = null;

  boolean matchAboutBlank = false;

  boolean matchOriginAsFallback = false;

  unsigned long long? frameID = null;

  required MatchPatternSetOrStringSequence matches;

  MatchPatternSetOrStringSequence? excludeMatches = null;

  sequence<MatchGlobOrString>? includeGlobs = null;

  sequence<MatchGlobOrString>? excludeGlobs = null;

  boolean isUserScript = false;

  boolean hasActiveTabPermission = false;
};

/**
 * Describes the earliest point in the load cycle at which a script should
 * run.
 */
enum ContentScriptRunAt {
  /**
   * The point in the load cycle just after the document element has been
   * inserted, before any page scripts have been allowed to run.
   */
  "document_start",
  /**
   * The point after which the page DOM has fully loaded, but before all page
   * resources have necessarily been loaded. Corresponds approximately to the
   * DOMContentLoaded event.
   */
  "document_end",
  /**
   * The first point after the page and all of its resources has fully loaded
   * when the event loop is idle, and can run scripts without delaying a paint
   * event.
   */
  "document_idle",
};

/**
 * Describes the world where a script should run.
 */
enum ContentScriptExecutionWorld {
  /**
   * The default execution environment of content scripts.
   * The name refers to "isolated world", which is a concept from Chromium and
   * WebKit, used to enforce isolation of the JavaScript execution environments
   * of content scripts and web pages.
   *
   * Not supported when isUserScript=true.
   */
  "ISOLATED",
  /**
   * The execution environment of the web page.
   */
  "MAIN",
  /**
   * The execution environment of a sandbox running scripts registered through
   * the MV3 userScripts API.
   *
   * Only supported when isUserScript=true.
   */
  "USER_SCRIPT",
};

enum ContentScriptCssOrigin {
  "author",
  "user",
};

[ChromeOnly, Exposed=Window]
interface WebExtensionContentScript : MozDocumentMatcher {
  [Throws]
  constructor(WebExtensionPolicy extension,
              WebExtensionContentScriptInit options);

  /**
   * The earliest point in the load cycle at which this script should run. For
   * static content scripts, in extensions which were present at browser
   * startup, the browser makes every effort to make sure that the script runs
   * no later than this point in the load cycle. For dynamic content scripts,
   * and scripts from extensions installed during this session, the scripts
   * may run at a later point.
   */
  [Constant]
  readonly attribute ContentScriptRunAt runAt;

  /**
   * The world where the script should run.
   */
  [Constant]
  readonly attribute ContentScriptExecutionWorld world;

  /**
   * When world is "USER_SCRIPT", worldId can be used to specify a specific
   * extension-specific sandbox to execute in, instead of the default one.
   */
  [Constant]
  readonly attribute DOMString? worldId;

  /**
   * The css origin of the stylesheet to inject.
   */
  [Constant]
  readonly attribute ContentScriptCssOrigin cssOrigin;

  /**
   * A set of paths, relative to the extension root, of CSS sheets to inject
   * into matching pages.
   */
  [Cached, Constant, Frozen]
  readonly attribute sequence<DOMString> cssPaths;

  /**
   * A set of paths, relative to the extension root, of JavaScript scripts to
   * execute in matching pages.
   */
  [Cached, Constant, Frozen]
  readonly attribute sequence<DOMString> jsPaths;
};

dictionary WebExtensionContentScriptInit : MozDocumentMatcherInit {
  ContentScriptRunAt runAt = "document_idle";

  ContentScriptExecutionWorld world = "ISOLATED";

  DOMString? worldId = null;

  ContentScriptCssOrigin cssOrigin = "author";

  sequence<DOMString> cssPaths = [];

  sequence<DOMString> jsPaths = [];
};