forked from xvrh/chrome_extension.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.dart
510 lines (411 loc) · 16.6 KB
/
events.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
// ignore_for_file: unnecessary_parenthesis
library;
import 'src/internal_helpers.dart';
import 'src/js/events.dart' as $js;
export 'src/chrome.dart' show chrome, EventStream;
final _events = ChromeEvents._();
extension ChromeEventsExtension on Chrome {
/// The `chrome.events` namespace contains common types used by APIs
/// dispatching events to notify you when something interesting happens.
ChromeEvents get events => _events;
}
class ChromeEvents {
ChromeEvents._();
bool get isAvailable => $js.chrome.eventsNullable != null && alwaysTrue;
}
class Rule {
Rule.fromJS(this._wrapped);
Rule({
/// Optional identifier that allows referencing this rule.
String? id,
/// Tags can be used to annotate rules and perform operations on sets of
/// rules.
List<String>? tags,
/// List of conditions that can trigger the actions.
required List<Object> conditions,
/// List of actions that are triggered if one of the conditions is
/// fulfilled.
required List<Object> actions,
/// Optional priority of this rule. Defaults to 100.
int? priority,
}) : _wrapped = $js.Rule(
id: id,
tags: tags?.toJSArray((e) => e),
conditions: conditions.toJSArray((e) => e.jsify()!),
actions: actions.toJSArray((e) => e.jsify()!),
priority: priority,
);
final $js.Rule _wrapped;
$js.Rule get toJS => _wrapped;
/// Optional identifier that allows referencing this rule.
String? get id => _wrapped.id;
set id(String? v) {
_wrapped.id = v;
}
/// Tags can be used to annotate rules and perform operations on sets of
/// rules.
List<String>? get tags =>
_wrapped.tags?.toDart.cast<String>().map((e) => e).toList();
set tags(List<String>? v) {
_wrapped.tags = v?.toJSArray((e) => e);
}
/// List of conditions that can trigger the actions.
List<Object> get conditions => _wrapped.conditions.toDart
.cast<JSAny>()
.map((e) => e.dartify()!)
.toList();
set conditions(List<Object> v) {
_wrapped.conditions = v.toJSArray((e) => e.jsify()!);
}
/// List of actions that are triggered if one of the conditions is fulfilled.
List<Object> get actions =>
_wrapped.actions.toDart.cast<JSAny>().map((e) => e.dartify()!).toList();
set actions(List<Object> v) {
_wrapped.actions = v.toJSArray((e) => e.jsify()!);
}
/// Optional priority of this rule. Defaults to 100.
int? get priority => _wrapped.priority;
set priority(int? v) {
_wrapped.priority = v;
}
}
class Event {
Event.fromJS(this._wrapped);
Event() : _wrapped = $js.Event();
final $js.Event _wrapped;
$js.Event get toJS => _wrapped;
/// Registers an event listener _callback_ to an event.
/// [callback] Called when an event occurs. The parameters of this function
/// depend on the type of event.
void addListener(JSFunction callback) {
_wrapped.addListener(callback);
}
/// Deregisters an event listener _callback_ from an event.
/// [callback] Listener that shall be unregistered.
void removeListener(JSFunction callback) {
_wrapped.removeListener(callback);
}
/// [callback] Listener whose registration status shall be tested.
/// [returns] True if _callback_ is registered to the event.
bool hasListener(JSFunction callback) {
return _wrapped.hasListener(callback);
}
/// [returns] True if any event listeners are registered to the event.
bool hasListeners() {
return _wrapped.hasListeners();
}
/// Registers rules to handle events.
/// [eventName] Name of the event this function affects.
/// [webViewInstanceId] If provided, this is an integer that uniquely
/// identfies the <webview> associated with this function call.
/// [rules] Rules to be registered. These do not replace previously
/// registered rules.
/// [returns] Called with registered rules.
Future<List<Rule>> addRules(
String eventName,
int webViewInstanceId,
List<Rule> rules,
) {
var $completer = Completer<List<Rule>>();
_wrapped.addRules(
eventName,
webViewInstanceId,
rules.toJSArray((e) => e.toJS),
(JSArray rules) {
if (checkRuntimeLastError($completer)) {
$completer.complete(rules.toDart
.cast<$js.Rule>()
.map((e) => Rule.fromJS(e))
.toList());
}
}.toJS,
);
return $completer.future;
}
/// Returns currently registered rules.
/// [eventName] Name of the event this function affects.
/// [webViewInstanceId] If provided, this is an integer that uniquely
/// identfies the <webview> associated with this function call.
/// [ruleIdentifiers] If an array is passed, only rules with identifiers
/// contained in this array are returned.
/// [returns] Called with registered rules.
Future<List<Rule>> getRules(
String eventName,
int webViewInstanceId,
List<String>? ruleIdentifiers,
) {
var $completer = Completer<List<Rule>>();
_wrapped.getRules(
eventName,
webViewInstanceId,
ruleIdentifiers?.toJSArray((e) => e),
(JSArray rules) {
if (checkRuntimeLastError($completer)) {
$completer.complete(rules.toDart
.cast<$js.Rule>()
.map((e) => Rule.fromJS(e))
.toList());
}
}.toJS,
);
return $completer.future;
}
/// Unregisters currently registered rules.
/// [eventName] Name of the event this function affects.
/// [webViewInstanceId] If provided, this is an integer that uniquely
/// identfies the <webview> associated with this function call.
/// [ruleIdentifiers] If an array is passed, only rules with identifiers
/// contained in this array are unregistered.
/// [returns] Called when rules were unregistered.
Future<void> removeRules(
String eventName,
int webViewInstanceId,
List<String>? ruleIdentifiers,
) {
var $completer = Completer<void>();
_wrapped.removeRules(
eventName,
webViewInstanceId,
ruleIdentifiers?.toJSArray((e) => e),
() {
if (checkRuntimeLastError($completer)) {
$completer.complete(null);
}
}.toJS,
);
return $completer.future;
}
}
class UrlFilter {
UrlFilter.fromJS(this._wrapped);
UrlFilter({
/// Matches if the host name of the URL contains a specified string. To test
/// whether a host name component has a prefix 'foo', use hostContains:
/// '.foo'. This matches 'www.foobar.com' and 'foo.com', because an implicit
/// dot is added at the beginning of the host name. Similarly, hostContains
/// can be used to match against component suffix ('foo.') and to exactly
/// match against components ('.foo.'). Suffix- and exact-matching for the
/// last components need to be done separately using hostSuffix, because no
/// implicit dot is added at the end of the host name.
String? hostContains,
/// Matches if the host name of the URL is equal to a specified string.
String? hostEquals,
/// Matches if the host name of the URL starts with a specified string.
String? hostPrefix,
/// Matches if the host name of the URL ends with a specified string.
String? hostSuffix,
/// Matches if the path segment of the URL contains a specified string.
String? pathContains,
/// Matches if the path segment of the URL is equal to a specified string.
String? pathEquals,
/// Matches if the path segment of the URL starts with a specified string.
String? pathPrefix,
/// Matches if the path segment of the URL ends with a specified string.
String? pathSuffix,
/// Matches if the query segment of the URL contains a specified string.
String? queryContains,
/// Matches if the query segment of the URL is equal to a specified string.
String? queryEquals,
/// Matches if the query segment of the URL starts with a specified string.
String? queryPrefix,
/// Matches if the query segment of the URL ends with a specified string.
String? querySuffix,
/// Matches if the URL (without fragment identifier) contains a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? urlContains,
/// Matches if the URL (without fragment identifier) is equal to a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? urlEquals,
/// Matches if the URL (without fragment identifier) matches a specified
/// regular expression. Port numbers are stripped from the URL if they match
/// the default port number. The regular expressions use the [RE2
/// syntax](https://github.com/google/re2/blob/master/doc/syntax.txt).
String? urlMatches,
/// Matches if the URL without query segment and fragment identifier matches
/// a specified regular expression. Port numbers are stripped from the URL
/// if they match the default port number. The regular expressions use the
/// [RE2 syntax](https://github.com/google/re2/blob/master/doc/syntax.txt).
String? originAndPathMatches,
/// Matches if the URL (without fragment identifier) starts with a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? urlPrefix,
/// Matches if the URL (without fragment identifier) ends with a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? urlSuffix,
/// Matches if the scheme of the URL is equal to any of the schemes
/// specified in the array.
List<String>? schemes,
/// Matches if the port of the URL is contained in any of the specified port
/// lists. For example `[80, 443, [1000, 1200]]` matches all requests on
/// port 80, 443 and in the range 1000-1200.
List<Object>? ports,
}) : _wrapped = $js.UrlFilter(
hostContains: hostContains,
hostEquals: hostEquals,
hostPrefix: hostPrefix,
hostSuffix: hostSuffix,
pathContains: pathContains,
pathEquals: pathEquals,
pathPrefix: pathPrefix,
pathSuffix: pathSuffix,
queryContains: queryContains,
queryEquals: queryEquals,
queryPrefix: queryPrefix,
querySuffix: querySuffix,
urlContains: urlContains,
urlEquals: urlEquals,
urlMatches: urlMatches,
originAndPathMatches: originAndPathMatches,
urlPrefix: urlPrefix,
urlSuffix: urlSuffix,
schemes: schemes?.toJSArray((e) => e),
ports: ports?.toJSArray((e) => switch (e) {
int() => e.jsify()!,
List<int>() => e.toJSArray((e) => e),
_ => throw UnsupportedError(
'Received type: ${e.runtimeType}. Supported types are: int, List<int>')
}),
);
final $js.UrlFilter _wrapped;
$js.UrlFilter get toJS => _wrapped;
/// Matches if the host name of the URL contains a specified string. To test
/// whether a host name component has a prefix 'foo', use hostContains:
/// '.foo'. This matches 'www.foobar.com' and 'foo.com', because an implicit
/// dot is added at the beginning of the host name. Similarly, hostContains
/// can be used to match against component suffix ('foo.') and to exactly
/// match against components ('.foo.'). Suffix- and exact-matching for the
/// last components need to be done separately using hostSuffix, because no
/// implicit dot is added at the end of the host name.
String? get hostContains => _wrapped.hostContains;
set hostContains(String? v) {
_wrapped.hostContains = v;
}
/// Matches if the host name of the URL is equal to a specified string.
String? get hostEquals => _wrapped.hostEquals;
set hostEquals(String? v) {
_wrapped.hostEquals = v;
}
/// Matches if the host name of the URL starts with a specified string.
String? get hostPrefix => _wrapped.hostPrefix;
set hostPrefix(String? v) {
_wrapped.hostPrefix = v;
}
/// Matches if the host name of the URL ends with a specified string.
String? get hostSuffix => _wrapped.hostSuffix;
set hostSuffix(String? v) {
_wrapped.hostSuffix = v;
}
/// Matches if the path segment of the URL contains a specified string.
String? get pathContains => _wrapped.pathContains;
set pathContains(String? v) {
_wrapped.pathContains = v;
}
/// Matches if the path segment of the URL is equal to a specified string.
String? get pathEquals => _wrapped.pathEquals;
set pathEquals(String? v) {
_wrapped.pathEquals = v;
}
/// Matches if the path segment of the URL starts with a specified string.
String? get pathPrefix => _wrapped.pathPrefix;
set pathPrefix(String? v) {
_wrapped.pathPrefix = v;
}
/// Matches if the path segment of the URL ends with a specified string.
String? get pathSuffix => _wrapped.pathSuffix;
set pathSuffix(String? v) {
_wrapped.pathSuffix = v;
}
/// Matches if the query segment of the URL contains a specified string.
String? get queryContains => _wrapped.queryContains;
set queryContains(String? v) {
_wrapped.queryContains = v;
}
/// Matches if the query segment of the URL is equal to a specified string.
String? get queryEquals => _wrapped.queryEquals;
set queryEquals(String? v) {
_wrapped.queryEquals = v;
}
/// Matches if the query segment of the URL starts with a specified string.
String? get queryPrefix => _wrapped.queryPrefix;
set queryPrefix(String? v) {
_wrapped.queryPrefix = v;
}
/// Matches if the query segment of the URL ends with a specified string.
String? get querySuffix => _wrapped.querySuffix;
set querySuffix(String? v) {
_wrapped.querySuffix = v;
}
/// Matches if the URL (without fragment identifier) contains a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? get urlContains => _wrapped.urlContains;
set urlContains(String? v) {
_wrapped.urlContains = v;
}
/// Matches if the URL (without fragment identifier) is equal to a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? get urlEquals => _wrapped.urlEquals;
set urlEquals(String? v) {
_wrapped.urlEquals = v;
}
/// Matches if the URL (without fragment identifier) matches a specified
/// regular expression. Port numbers are stripped from the URL if they match
/// the default port number. The regular expressions use the [RE2
/// syntax](https://github.com/google/re2/blob/master/doc/syntax.txt).
String? get urlMatches => _wrapped.urlMatches;
set urlMatches(String? v) {
_wrapped.urlMatches = v;
}
/// Matches if the URL without query segment and fragment identifier matches a
/// specified regular expression. Port numbers are stripped from the URL if
/// they match the default port number. The regular expressions use the [RE2
/// syntax](https://github.com/google/re2/blob/master/doc/syntax.txt).
String? get originAndPathMatches => _wrapped.originAndPathMatches;
set originAndPathMatches(String? v) {
_wrapped.originAndPathMatches = v;
}
/// Matches if the URL (without fragment identifier) starts with a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? get urlPrefix => _wrapped.urlPrefix;
set urlPrefix(String? v) {
_wrapped.urlPrefix = v;
}
/// Matches if the URL (without fragment identifier) ends with a specified
/// string. Port numbers are stripped from the URL if they match the default
/// port number.
String? get urlSuffix => _wrapped.urlSuffix;
set urlSuffix(String? v) {
_wrapped.urlSuffix = v;
}
/// Matches if the scheme of the URL is equal to any of the schemes specified
/// in the array.
List<String>? get schemes =>
_wrapped.schemes?.toDart.cast<String>().map((e) => e).toList();
set schemes(List<String>? v) {
_wrapped.schemes = v?.toJSArray((e) => e);
}
/// Matches if the port of the URL is contained in any of the specified port
/// lists. For example `[80, 443, [1000, 1200]]` matches all requests on port
/// 80, 443 and in the range 1000-1200.
List<Object>? get ports => _wrapped.ports?.toDart
.cast<JSAny>()
.map((e) => e.when(
isInt: (v) => v,
isArray: (v) => v.toDart.cast<int>().map((e) => e).toList(),
))
.toList();
set ports(List<Object>? v) {
_wrapped.ports = v?.toJSArray((e) => switch (e) {
int() => e.jsify()!,
List<int>() => e.toJSArray((e) => e),
_ => throw UnsupportedError(
'Received type: ${e.runtimeType}. Supported types are: int, List<int>')
});
}
}