forked from xvrh/chrome_extension.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension_types.dart
365 lines (280 loc) · 10.6 KB
/
extension_types.dart
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// ignore_for_file: unnecessary_parenthesis
library;
import 'src/internal_helpers.dart';
import 'src/js/extension_types.dart' as $js;
export 'src/chrome.dart' show chrome, EventStream;
final _extensionTypes = ChromeExtensionTypes._();
extension ChromeExtensionTypesExtension on Chrome {
/// The `chrome.extensionTypes` API contains type declarations for Chrome
/// extensions.
ChromeExtensionTypes get extensionTypes => _extensionTypes;
}
class ChromeExtensionTypes {
ChromeExtensionTypes._();
bool get isAvailable =>
$js.chrome.extensionTypesNullable != null && alwaysTrue;
}
/// The format of an image.
enum ImageFormat {
jpeg('jpeg'),
png('png');
const ImageFormat(this.value);
final String value;
String get toJS => value;
static ImageFormat fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// The soonest that the JavaScript or CSS will be injected into the tab.
enum RunAt {
documentStart('document_start'),
documentEnd('document_end'),
documentIdle('document_idle');
const RunAt(this.value);
final String value;
String get toJS => value;
static RunAt fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// The [origin](https://www.w3.org/TR/css3-cascade/#cascading-origins) of
/// injected CSS.
enum CSSOrigin {
author('author'),
user('user');
const CSSOrigin(this.value);
final String value;
String get toJS => value;
static CSSOrigin fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// The type of frame.
enum FrameType {
outermostFrame('outermost_frame'),
fencedFrame('fenced_frame'),
subFrame('sub_frame');
const FrameType(this.value);
final String value;
String get toJS => value;
static FrameType fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// The document lifecycle of the frame.
enum DocumentLifecycle {
prerender('prerender'),
active('active'),
cached('cached'),
pendingDeletion('pending_deletion');
const DocumentLifecycle(this.value);
final String value;
String get toJS => value;
static DocumentLifecycle fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// The JavaScript world for a script to execute within. Can either be an
/// isolated world unique to this extension, the main world of the DOM which is
/// shared with the page's JavaScript, or a user scripts world that is only
/// available for scripts registered with the User Scripts API.
enum ExecutionWorld {
isolated('ISOLATED'),
main('MAIN'),
userScript('USER_SCRIPT');
const ExecutionWorld(this.value);
final String value;
String get toJS => value;
static ExecutionWorld fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
class ImageDetails {
ImageDetails.fromJS(this._wrapped);
ImageDetails({
/// The format of the resulting image. Default is `"jpeg"`.
ImageFormat? format,
/// When format is `"jpeg"`, controls the quality of the resulting image.
/// This value is ignored for PNG images. As quality is decreased, the
/// resulting image will have more visual artifacts, and the number of bytes
/// needed to store it will decrease.
int? quality,
}) : _wrapped = $js.ImageDetails(
format: format?.toJS,
quality: quality,
);
final $js.ImageDetails _wrapped;
$js.ImageDetails get toJS => _wrapped;
/// The format of the resulting image. Default is `"jpeg"`.
ImageFormat? get format => _wrapped.format?.let(ImageFormat.fromJS);
set format(ImageFormat? v) {
_wrapped.format = v?.toJS;
}
/// When format is `"jpeg"`, controls the quality of the resulting image.
/// This value is ignored for PNG images. As quality is decreased, the
/// resulting image will have more visual artifacts, and the number of bytes
/// needed to store it will decrease.
int? get quality => _wrapped.quality;
set quality(int? v) {
_wrapped.quality = v;
}
}
class InjectDetails {
InjectDetails.fromJS(this._wrapped);
InjectDetails({
/// JavaScript or CSS code to inject.
///
/// **Warning:**
/// Be careful using the `code` parameter. Incorrect use of it may open your
/// extension to [cross site
/// scripting](https://en.wikipedia.org/wiki/Cross-site_scripting) attacks.
String? code,
/// JavaScript or CSS file to inject.
String? file,
/// If allFrames is `true`, implies that the JavaScript or CSS should be
/// injected into all frames of current page. By default, it's `false` and
/// is only injected into the top frame. If `true` and `frameId` is set,
/// then the code is inserted in the selected frame and all of its child
/// frames.
bool? allFrames,
/// The [frame](webNavigation#frame_ids) where the script or CSS should be
/// injected. Defaults to 0 (the top-level frame).
int? frameId,
/// If matchAboutBlank is true, then the code is also injected in
/// about:blank and about:srcdoc frames if your extension has access to its
/// parent document. Code cannot be inserted in top-level about:-frames. By
/// default it is `false`.
bool? matchAboutBlank,
/// The soonest that the JavaScript or CSS will be injected into the tab.
/// Defaults to "document_idle".
RunAt? runAt,
/// The [origin](https://www.w3.org/TR/css3-cascade/#cascading-origins) of
/// the CSS to inject. This may only be specified for CSS, not JavaScript.
/// Defaults to `"author"`.
CSSOrigin? cssOrigin,
}) : _wrapped = $js.InjectDetails(
code: code,
file: file,
allFrames: allFrames,
frameId: frameId,
matchAboutBlank: matchAboutBlank,
runAt: runAt?.toJS,
cssOrigin: cssOrigin?.toJS,
);
final $js.InjectDetails _wrapped;
$js.InjectDetails get toJS => _wrapped;
/// JavaScript or CSS code to inject.
///
/// **Warning:**
/// Be careful using the `code` parameter. Incorrect use of it may open your
/// extension to [cross site
/// scripting](https://en.wikipedia.org/wiki/Cross-site_scripting) attacks.
String? get code => _wrapped.code;
set code(String? v) {
_wrapped.code = v;
}
/// JavaScript or CSS file to inject.
String? get file => _wrapped.file;
set file(String? v) {
_wrapped.file = v;
}
/// If allFrames is `true`, implies that the JavaScript or CSS should be
/// injected into all frames of current page. By default, it's `false` and is
/// only injected into the top frame. If `true` and `frameId` is set, then the
/// code is inserted in the selected frame and all of its child frames.
bool? get allFrames => _wrapped.allFrames;
set allFrames(bool? v) {
_wrapped.allFrames = v;
}
/// The [frame](webNavigation#frame_ids) where the script or CSS should be
/// injected. Defaults to 0 (the top-level frame).
int? get frameId => _wrapped.frameId;
set frameId(int? v) {
_wrapped.frameId = v;
}
/// If matchAboutBlank is true, then the code is also injected in about:blank
/// and about:srcdoc frames if your extension has access to its parent
/// document. Code cannot be inserted in top-level about:-frames. By default
/// it is `false`.
bool? get matchAboutBlank => _wrapped.matchAboutBlank;
set matchAboutBlank(bool? v) {
_wrapped.matchAboutBlank = v;
}
/// The soonest that the JavaScript or CSS will be injected into the tab.
/// Defaults to "document_idle".
RunAt? get runAt => _wrapped.runAt?.let(RunAt.fromJS);
set runAt(RunAt? v) {
_wrapped.runAt = v?.toJS;
}
/// The [origin](https://www.w3.org/TR/css3-cascade/#cascading-origins) of the
/// CSS to inject. This may only be specified for CSS, not JavaScript.
/// Defaults to `"author"`.
CSSOrigin? get cssOrigin => _wrapped.cssOrigin?.let(CSSOrigin.fromJS);
set cssOrigin(CSSOrigin? v) {
_wrapped.cssOrigin = v?.toJS;
}
}
class DeleteInjectionDetails {
DeleteInjectionDetails.fromJS(this._wrapped);
DeleteInjectionDetails({
/// CSS code to remove.
String? code,
/// CSS file to remove.
String? file,
/// If allFrames is `true`, implies that the CSS should be removed from all
/// frames of current page. By default, it's `false` and is only removed
/// from the top frame. If `true` and `frameId` is set, then the code is
/// removed from the selected frame and all of its child frames.
bool? allFrames,
/// The [frame](webNavigation#frame_ids) from where the CSS should be
/// removed. Defaults to 0 (the top-level frame).
int? frameId,
/// If matchAboutBlank is true, then the code is also removed from
/// about:blank and about:srcdoc frames if your extension has access to its
/// parent document. By default it is `false`.
bool? matchAboutBlank,
/// The [origin](https://www.w3.org/TR/css3-cascade/#cascading-origins) of
/// the CSS to remove. Defaults to `"author"`.
CSSOrigin? cssOrigin,
}) : _wrapped = $js.DeleteInjectionDetails(
code: code,
file: file,
allFrames: allFrames,
frameId: frameId,
matchAboutBlank: matchAboutBlank,
cssOrigin: cssOrigin?.toJS,
);
final $js.DeleteInjectionDetails _wrapped;
$js.DeleteInjectionDetails get toJS => _wrapped;
/// CSS code to remove.
String? get code => _wrapped.code;
set code(String? v) {
_wrapped.code = v;
}
/// CSS file to remove.
String? get file => _wrapped.file;
set file(String? v) {
_wrapped.file = v;
}
/// If allFrames is `true`, implies that the CSS should be removed from all
/// frames of current page. By default, it's `false` and is only removed from
/// the top frame. If `true` and `frameId` is set, then the code is removed
/// from the selected frame and all of its child frames.
bool? get allFrames => _wrapped.allFrames;
set allFrames(bool? v) {
_wrapped.allFrames = v;
}
/// The [frame](webNavigation#frame_ids) from where the CSS should be removed.
/// Defaults to 0 (the top-level frame).
int? get frameId => _wrapped.frameId;
set frameId(int? v) {
_wrapped.frameId = v;
}
/// If matchAboutBlank is true, then the code is also removed from about:blank
/// and about:srcdoc frames if your extension has access to its parent
/// document. By default it is `false`.
bool? get matchAboutBlank => _wrapped.matchAboutBlank;
set matchAboutBlank(bool? v) {
_wrapped.matchAboutBlank = v;
}
/// The [origin](https://www.w3.org/TR/css3-cascade/#cascading-origins) of the
/// CSS to remove. Defaults to `"author"`.
CSSOrigin? get cssOrigin => _wrapped.cssOrigin?.let(CSSOrigin.fromJS);
set cssOrigin(CSSOrigin? v) {
_wrapped.cssOrigin = v?.toJS;
}
}