forked from xvrh/chrome_extension.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeclarative_net_request.dart
2240 lines (1784 loc) · 72.4 KB
/
declarative_net_request.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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ignore_for_file: unnecessary_parenthesis
library;
import 'dart:js_util';
import 'extension_types.dart';
import 'src/internal_helpers.dart';
import 'src/js/declarative_net_request.dart' as $js;
export 'src/chrome.dart' show chrome, EventStream;
final _declarativeNetRequest = ChromeDeclarativeNetRequest._();
extension ChromeDeclarativeNetRequestExtension on Chrome {
/// The `chrome.declarativeNetRequest` API is used to block or modify
/// network requests by specifying declarative rules. This lets extensions
/// modify network requests without intercepting them and viewing their
/// content,
/// thus providing more privacy.
ChromeDeclarativeNetRequest get declarativeNetRequest =>
_declarativeNetRequest;
}
class ChromeDeclarativeNetRequest {
ChromeDeclarativeNetRequest._();
bool get isAvailable =>
$js.chrome.declarativeNetRequestNullable != null && alwaysTrue;
/// Modifies the current set of dynamic rules for the extension.
/// The rules with IDs listed in `options.removeRuleIds` are first
/// removed, and then the rules given in `options.addRules` are
/// added. Notes:
/// <ul>
/// <li>This update happens as a single atomic operation: either all
/// specified rules are added and removed, or an error is returned.</li>
/// <li>These rules are persisted across browser sessions and across
/// extension updates.</li>
/// <li>Static rules specified as part of the extension package can not be
/// removed using this function.</li>
/// <li>[MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES] is the maximum number
/// of combined dynamic and session rules an extension can add.</li>
/// </ul>
/// |callback|: Called once the update is complete or has failed. In case of
/// an error, [runtime.lastError] will be set and no change will be made
/// to the rule set. This can happen for multiple reasons, such as invalid
/// rule format, duplicate rule ID, rule count limit exceeded, internal
/// errors, and others.
Future<void> updateDynamicRules(UpdateRuleOptions options) async {
await promiseToFuture<void>(
$js.chrome.declarativeNetRequest.updateDynamicRules(options.toJS));
}
/// Returns the current set of dynamic rules for the extension. Callers can
/// optionally filter the list of fetched rules by specifying a
/// `filter`.
/// |filter|: An object to filter the list of fetched rules.
/// |callback|: Called with the set of dynamic rules. An error might be
/// raised in case of transient internal errors.
Future<List<Rule>> getDynamicRules(GetRulesFilter? filter) async {
var $res = await promiseToFuture<JSArray>(
$js.chrome.declarativeNetRequest.getDynamicRules(filter?.toJS));
return $res.toDart.cast<$js.Rule>().map((e) => Rule.fromJS(e)).toList();
}
/// Modifies the current set of session scoped rules for the extension.
/// The rules with IDs listed in `options.removeRuleIds` are first
/// removed, and then the rules given in `options.addRules` are
/// added. Notes:
/// <ul>
/// <li>This update happens as a single atomic operation: either all
/// specified rules are added and removed, or an error is returned.</li>
/// <li>These rules are not persisted across sessions and are backed in
/// memory.</li>
/// <li>[MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES] is the maximum number
/// of combined dynamic and session rules an extension can add.</li>
/// </ul>
/// |callback|: Called once the update is complete or has failed. In case of
/// an error, [runtime.lastError] will be set and no change will be made
/// to the rule set. This can happen for multiple reasons, such as invalid
/// rule format, duplicate rule ID, rule count limit exceeded, and others.
Future<void> updateSessionRules(UpdateRuleOptions options) async {
await promiseToFuture<void>(
$js.chrome.declarativeNetRequest.updateSessionRules(options.toJS));
}
/// Returns the current set of session scoped rules for the extension.
/// Callers can optionally filter the list of fetched rules by specifying a
/// `filter`.
/// |filter|: An object to filter the list of fetched rules.
/// |callback|: Called with the set of session scoped rules.
Future<List<Rule>> getSessionRules(GetRulesFilter? filter) async {
var $res = await promiseToFuture<JSArray>(
$js.chrome.declarativeNetRequest.getSessionRules(filter?.toJS));
return $res.toDart.cast<$js.Rule>().map((e) => Rule.fromJS(e)).toList();
}
/// Updates the set of enabled static rulesets for the extension. The
/// rulesets with IDs listed in `options.disableRulesetIds` are
/// first removed, and then the rulesets listed in
/// `options.enableRulesetIds` are added.<br/>
/// Note that the set of enabled static rulesets is persisted across sessions
/// but not across extension updates, i.e. the `rule_resources`
/// manifest key will determine the set of enabled static rulesets on each
/// extension update.
/// |callback|: Called once the update is complete. In case of an error,
/// [runtime.lastError] will be set and no change will be made to set of
/// enabled rulesets. This can happen for multiple reasons, such as invalid
/// ruleset IDs, rule count limit exceeded, or internal errors.
Future<void> updateEnabledRulesets(UpdateRulesetOptions options) async {
await promiseToFuture<void>(
$js.chrome.declarativeNetRequest.updateEnabledRulesets(options.toJS));
}
/// Returns the ids for the current set of enabled static rulesets.
/// |callback|: Called with a list of ids, where each id corresponds to an
/// enabled static [Ruleset].
Future<List<String>> getEnabledRulesets() async {
var $res = await promiseToFuture<JSArray>(
$js.chrome.declarativeNetRequest.getEnabledRulesets());
return $res.toDart.cast<String>().map((e) => e).toList();
}
/// Disables and enables individual static rules in a [Ruleset].
/// Changes to rules belonging to a disabled [Ruleset] will take
/// effect the next time that it becomes enabled.
/// |callback|: Called once the update is complete. In case of an error,
/// [runtime.lastError] will be set and no change will be made to the
/// enabled static rules.
Future<void> updateStaticRules(UpdateStaticRulesOptions options) async {
await promiseToFuture<void>(
$js.chrome.declarativeNetRequest.updateStaticRules(options.toJS));
}
/// Returns the list of static rules in the given [Ruleset] that are
/// currently disabled.
/// |options|: Specifies the ruleset to query.
/// |callback|: Called with a list of ids that correspond to the disabled
/// rules in that ruleset.
Future<List<int>> getDisabledRuleIds(
GetDisabledRuleIdsOptions options) async {
var $res = await promiseToFuture<JSArray>(
$js.chrome.declarativeNetRequest.getDisabledRuleIds(options.toJS));
return $res.toDart.cast<int>().map((e) => e).toList();
}
/// Returns all rules matched for the extension. Callers can optionally
/// filter the list of matched rules by specifying a `filter`.
/// This method is only available to extensions with the
/// `declarativeNetRequestFeedback` permission or having the
/// `activeTab` permission granted for the `tabId`
/// specified in `filter`.
/// Note: Rules not associated with an active document that were matched more
/// than five minutes ago will not be returned.
/// |filter|: An object to filter the list of matched rules.
/// |callback|: Called once the list of matched rules has been fetched. In
/// case of an error, [runtime.lastError] will be set and no rules will
/// be returned. This can happen for multiple reasons, such as insufficient
/// permissions, or exceeding the quota.
Future<RulesMatchedDetails> getMatchedRules(
MatchedRulesFilter? filter) async {
var $res = await promiseToFuture<$js.RulesMatchedDetails>(
$js.chrome.declarativeNetRequest.getMatchedRules(filter?.toJS));
return RulesMatchedDetails.fromJS($res);
}
/// Configures if the action count for tabs should be displayed as the
/// extension action's badge text and provides a way for that action count to
/// be incremented.
Future<void> setExtensionActionOptions(ExtensionActionOptions options) async {
await promiseToFuture<void>($js.chrome.declarativeNetRequest
.setExtensionActionOptions(options.toJS));
}
/// Checks if the given regular expression will be supported as a
/// `regexFilter` rule condition.
/// |regexOptions|: The regular expression to check.
/// |callback|: Called with details consisting of whether the regular
/// expression is supported and the reason if not.
Future<IsRegexSupportedResult> isRegexSupported(
RegexOptions regexOptions) async {
var $res = await promiseToFuture<$js.IsRegexSupportedResult>(
$js.chrome.declarativeNetRequest.isRegexSupported(regexOptions.toJS));
return IsRegexSupportedResult.fromJS($res);
}
/// Returns the number of static rules an extension can enable before the
/// [global static rule limit](#global-static-rule-limit) is
/// reached.
Future<int> getAvailableStaticRuleCount() async {
var $res = await promiseToFuture<int>(
$js.chrome.declarativeNetRequest.getAvailableStaticRuleCount());
return $res;
}
/// Checks if any of the extension's declarativeNetRequest rules would match
/// a hypothetical request.
/// Note: Only available for unpacked extensions as this is only intended to
/// be used during extension development.
/// |requestDetails|: The request details to test.
/// |callback|: Called with the details of matched rules.
Future<TestMatchOutcomeResult> testMatchOutcome(
TestMatchRequestDetails request) async {
var $res = await promiseToFuture<$js.TestMatchOutcomeResult>(
$js.chrome.declarativeNetRequest.testMatchOutcome(request.toJS));
return TestMatchOutcomeResult.fromJS($res);
}
/// The minimum number of static rules guaranteed to an extension across its
/// enabled static rulesets. Any rules above this limit will count towards
/// the [global static rule limit](#global-static-rule-limit).
int get guaranteedMinimumStaticRules =>
$js.chrome.declarativeNetRequest.GUARANTEED_MINIMUM_STATIC_RULES;
/// The maximum number of combined dynamic and session scoped rules an
/// extension can add.
int get maxNumberOfDynamicAndSessionRules =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES;
/// The maximum number of dynamic rules that an extension can add.
int get maxNumberOfDynamicRules =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_DYNAMIC_RULES;
/// The maximum number of "unsafe" dynamic rules that an extension can add.
int get maxNumberOfUnsafeDynamicRules =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_UNSAFE_DYNAMIC_RULES;
/// The maximum number of session scoped rules that an extension can add.
int get maxNumberOfSessionRules =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_SESSION_RULES;
/// The maximum number of "unsafe" session scoped rules that an extension can
/// add.
int get maxNumberOfUnsafeSessionRules =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_UNSAFE_SESSION_RULES;
/// Time interval within which `MAX_GETMATCHEDRULES_CALLS_PER_INTERVAL
/// getMatchedRules` calls can be made, specified in minutes.
/// Additional calls will fail immediately and set [runtime.lastError].
/// Note: `getMatchedRules` calls associated with a user gesture
/// are exempt from the quota.
int get getmatchedrulesQuotaInterval =>
$js.chrome.declarativeNetRequest.GETMATCHEDRULES_QUOTA_INTERVAL;
/// The number of times `getMatchedRules` can be called within a
/// period of `GETMATCHEDRULES_QUOTA_INTERVAL`.
int get maxGetmatchedrulesCallsPerInterval =>
$js.chrome.declarativeNetRequest.MAX_GETMATCHEDRULES_CALLS_PER_INTERVAL;
/// The maximum number of regular expression rules that an extension can
/// add. This limit is evaluated separately for the set of dynamic rules and
/// those specified in the rule resources file.
int get maxNumberOfRegexRules =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_REGEX_RULES;
/// The maximum number of static `Rulesets` an extension can
/// specify as part of the `"rule_resources"` manifest key.
int get maxNumberOfStaticRulesets =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_STATIC_RULESETS;
/// The maximum number of static `Rulesets` an extension can
/// enable at any one time.
int get maxNumberOfEnabledStaticRulesets =>
$js.chrome.declarativeNetRequest.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS;
/// Ruleset ID for the dynamic rules added by the extension.
String get dynamicRulesetId =>
$js.chrome.declarativeNetRequest.DYNAMIC_RULESET_ID;
/// Ruleset ID for the session-scoped rules added by the extension.
String get sessionRulesetId =>
$js.chrome.declarativeNetRequest.SESSION_RULESET_ID;
/// Fired when a rule is matched with a request. Only available for unpacked
/// extensions with the `declarativeNetRequestFeedback` permission
/// as this is intended to be used for debugging purposes only.
/// |info|: The rule that has been matched along with information about the
/// associated request.
EventStream<MatchedRuleInfoDebug> get onRuleMatchedDebug =>
$js.chrome.declarativeNetRequest.onRuleMatchedDebug
.asStream(($c) => ($js.MatchedRuleInfoDebug info) {
return $c(MatchedRuleInfoDebug.fromJS(info));
}.toJS);
}
/// This describes the resource type of the network request.
enum ResourceType {
mainFrame('main_frame'),
subFrame('sub_frame'),
stylesheet('stylesheet'),
script('script'),
image('image'),
font('font'),
object('object'),
xmlhttprequest('xmlhttprequest'),
ping('ping'),
cspReport('csp_report'),
media('media'),
websocket('websocket'),
webtransport('webtransport'),
webbundle('webbundle'),
other('other');
const ResourceType(this.value);
final String value;
String get toJS => value;
static ResourceType fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// This describes the HTTP request method of a network request.
enum RequestMethod {
connect('connect'),
delete('delete'),
get('get'),
head('head'),
options('options'),
patch('patch'),
post('post'),
put('put'),
other('other');
const RequestMethod(this.value);
final String value;
String get toJS => value;
static RequestMethod fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// This describes whether the request is first or third party to the frame in
/// which it originated. A request is said to be first party if it has the same
/// domain (eTLD+1) as the frame in which the request originated.
enum DomainType {
/// The network request is first party to the frame in which it originated.
firstParty('firstParty'),
/// The network request is third party to the frame in which it originated.
thirdParty('thirdParty');
const DomainType(this.value);
final String value;
String get toJS => value;
static DomainType fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// This describes the possible operations for a "modifyHeaders" rule.
enum HeaderOperation {
/// Adds a new entry for the specified header. This operation is not
/// supported for request headers.
append('append'),
/// Sets a new value for the specified header, removing any existing headers
/// with the same name.
set('set'),
/// Removes all entries for the specified header.
remove('remove');
const HeaderOperation(this.value);
final String value;
String get toJS => value;
static HeaderOperation fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// Describes the kind of action to take if a given RuleCondition matches.
enum RuleActionType {
/// Block the network request.
block('block'),
/// Redirect the network request.
redirect('redirect'),
/// Allow the network request. The request won't be intercepted if there is
/// an allow rule which matches it.
allow('allow'),
/// Upgrade the network request url's scheme to https if the request is http
/// or ftp.
upgradeScheme('upgradeScheme'),
/// Modify request/response headers from the network request.
modifyHeaders('modifyHeaders'),
/// Allow all requests within a frame hierarchy, including the frame request
/// itself.
allowAllRequests('allowAllRequests');
const RuleActionType(this.value);
final String value;
String get toJS => value;
static RuleActionType fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
/// Describes the reason why a given regular expression isn't supported.
enum UnsupportedRegexReason {
/// The regular expression is syntactically incorrect, or uses features
/// not available in the
/// <a href = "https://github.com/google/re2/wiki/Syntax">RE2 syntax</a>.
syntaxError('syntaxError'),
/// The regular expression exceeds the memory limit.
memoryLimitExceeded('memoryLimitExceeded');
const UnsupportedRegexReason(this.value);
final String value;
String get toJS => value;
static UnsupportedRegexReason fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
class Ruleset {
Ruleset.fromJS(this._wrapped);
Ruleset({
/// A non-empty string uniquely identifying the ruleset. IDs beginning with
/// '_' are reserved for internal use.
required String id,
/// The path of the JSON ruleset relative to the extension directory.
required String path,
/// Whether the ruleset is enabled by default.
required bool enabled,
}) : _wrapped = $js.Ruleset(
id: id,
path: path,
enabled: enabled,
);
final $js.Ruleset _wrapped;
$js.Ruleset get toJS => _wrapped;
/// A non-empty string uniquely identifying the ruleset. IDs beginning with
/// '_' are reserved for internal use.
String get id => _wrapped.id;
set id(String v) {
_wrapped.id = v;
}
/// The path of the JSON ruleset relative to the extension directory.
String get path => _wrapped.path;
set path(String v) {
_wrapped.path = v;
}
/// Whether the ruleset is enabled by default.
bool get enabled => _wrapped.enabled;
set enabled(bool v) {
_wrapped.enabled = v;
}
}
class QueryKeyValue {
QueryKeyValue.fromJS(this._wrapped);
QueryKeyValue({
required String key,
required String value,
/// If true, the query key is replaced only if it's already present.
/// Otherwise, the key is also added if it's missing. Defaults to false.
bool? replaceOnly,
}) : _wrapped = $js.QueryKeyValue(
key: key,
value: value,
replaceOnly: replaceOnly,
);
final $js.QueryKeyValue _wrapped;
$js.QueryKeyValue get toJS => _wrapped;
String get key => _wrapped.key;
set key(String v) {
_wrapped.key = v;
}
String get value => _wrapped.value;
set value(String v) {
_wrapped.value = v;
}
/// If true, the query key is replaced only if it's already present.
/// Otherwise, the key is also added if it's missing. Defaults to false.
bool? get replaceOnly => _wrapped.replaceOnly;
set replaceOnly(bool? v) {
_wrapped.replaceOnly = v;
}
}
class QueryTransform {
QueryTransform.fromJS(this._wrapped);
QueryTransform({
/// The list of query keys to be removed.
List<String>? removeParams,
/// The list of query key-value pairs to be added or replaced.
List<QueryKeyValue>? addOrReplaceParams,
}) : _wrapped = $js.QueryTransform(
removeParams: removeParams?.toJSArray((e) => e),
addOrReplaceParams: addOrReplaceParams?.toJSArray((e) => e.toJS),
);
final $js.QueryTransform _wrapped;
$js.QueryTransform get toJS => _wrapped;
/// The list of query keys to be removed.
List<String>? get removeParams =>
_wrapped.removeParams?.toDart.cast<String>().map((e) => e).toList();
set removeParams(List<String>? v) {
_wrapped.removeParams = v?.toJSArray((e) => e);
}
/// The list of query key-value pairs to be added or replaced.
List<QueryKeyValue>? get addOrReplaceParams =>
_wrapped.addOrReplaceParams?.toDart
.cast<$js.QueryKeyValue>()
.map((e) => QueryKeyValue.fromJS(e))
.toList();
set addOrReplaceParams(List<QueryKeyValue>? v) {
_wrapped.addOrReplaceParams = v?.toJSArray((e) => e.toJS);
}
}
class URLTransform {
URLTransform.fromJS(this._wrapped);
URLTransform({
/// The new scheme for the request. Allowed values are "http", "https",
/// "ftp" and "chrome-extension".
String? scheme,
/// The new host for the request.
String? host,
/// The new port for the request. If empty, the existing port is cleared.
String? port,
/// The new path for the request. If empty, the existing path is cleared.
String? path,
/// The new query for the request. Should be either empty, in which case the
/// existing query is cleared; or should begin with '?'.
String? query,
/// Add, remove or replace query key-value pairs.
QueryTransform? queryTransform,
/// The new fragment for the request. Should be either empty, in which case
/// the existing fragment is cleared; or should begin with '#'.
String? fragment,
/// The new username for the request.
String? username,
/// The new password for the request.
String? password,
}) : _wrapped = $js.URLTransform(
scheme: scheme,
host: host,
port: port,
path: path,
query: query,
queryTransform: queryTransform?.toJS,
fragment: fragment,
username: username,
password: password,
);
final $js.URLTransform _wrapped;
$js.URLTransform get toJS => _wrapped;
/// The new scheme for the request. Allowed values are "http", "https",
/// "ftp" and "chrome-extension".
String? get scheme => _wrapped.scheme;
set scheme(String? v) {
_wrapped.scheme = v;
}
/// The new host for the request.
String? get host => _wrapped.host;
set host(String? v) {
_wrapped.host = v;
}
/// The new port for the request. If empty, the existing port is cleared.
String? get port => _wrapped.port;
set port(String? v) {
_wrapped.port = v;
}
/// The new path for the request. If empty, the existing path is cleared.
String? get path => _wrapped.path;
set path(String? v) {
_wrapped.path = v;
}
/// The new query for the request. Should be either empty, in which case the
/// existing query is cleared; or should begin with '?'.
String? get query => _wrapped.query;
set query(String? v) {
_wrapped.query = v;
}
/// Add, remove or replace query key-value pairs.
QueryTransform? get queryTransform =>
_wrapped.queryTransform?.let(QueryTransform.fromJS);
set queryTransform(QueryTransform? v) {
_wrapped.queryTransform = v?.toJS;
}
/// The new fragment for the request. Should be either empty, in which case
/// the existing fragment is cleared; or should begin with '#'.
String? get fragment => _wrapped.fragment;
set fragment(String? v) {
_wrapped.fragment = v;
}
/// The new username for the request.
String? get username => _wrapped.username;
set username(String? v) {
_wrapped.username = v;
}
/// The new password for the request.
String? get password => _wrapped.password;
set password(String? v) {
_wrapped.password = v;
}
}
class Redirect {
Redirect.fromJS(this._wrapped);
Redirect({
/// Path relative to the extension directory. Should start with '/'.
String? extensionPath,
/// Url transformations to perform.
URLTransform? transform,
/// The redirect url. Redirects to JavaScript urls are not allowed.
String? url,
/// Substitution pattern for rules which specify a `regexFilter`.
/// The first match of `regexFilter` within the url will be
/// replaced with this pattern. Within `regexSubstitution`,
/// backslash-escaped digits (\1 to \9) can be used to insert the
/// corresponding capture groups. \0 refers to the entire matching text.
String? regexSubstitution,
}) : _wrapped = $js.Redirect(
extensionPath: extensionPath,
transform: transform?.toJS,
url: url,
regexSubstitution: regexSubstitution,
);
final $js.Redirect _wrapped;
$js.Redirect get toJS => _wrapped;
/// Path relative to the extension directory. Should start with '/'.
String? get extensionPath => _wrapped.extensionPath;
set extensionPath(String? v) {
_wrapped.extensionPath = v;
}
/// Url transformations to perform.
URLTransform? get transform => _wrapped.transform?.let(URLTransform.fromJS);
set transform(URLTransform? v) {
_wrapped.transform = v?.toJS;
}
/// The redirect url. Redirects to JavaScript urls are not allowed.
String? get url => _wrapped.url;
set url(String? v) {
_wrapped.url = v;
}
/// Substitution pattern for rules which specify a `regexFilter`.
/// The first match of `regexFilter` within the url will be
/// replaced with this pattern. Within `regexSubstitution`,
/// backslash-escaped digits (\1 to \9) can be used to insert the
/// corresponding capture groups. \0 refers to the entire matching text.
String? get regexSubstitution => _wrapped.regexSubstitution;
set regexSubstitution(String? v) {
_wrapped.regexSubstitution = v;
}
}
class HeaderInfo {
HeaderInfo.fromJS(this._wrapped);
HeaderInfo({
/// The name of the header.
required String header,
/// If specified, match this rule if the header's value contains at least
/// one
/// element in this list.
List<String>? values,
/// If specified, the rule is not matched if the header exists but its value
/// contains at least one element in this list.
List<String>? excludedValues,
}) : _wrapped = $js.HeaderInfo(
header: header,
values: values?.toJSArray((e) => e),
excludedValues: excludedValues?.toJSArray((e) => e),
);
final $js.HeaderInfo _wrapped;
$js.HeaderInfo get toJS => _wrapped;
/// The name of the header.
String get header => _wrapped.header;
set header(String v) {
_wrapped.header = v;
}
/// If specified, match this rule if the header's value contains at least one
/// element in this list.
List<String>? get values =>
_wrapped.values?.toDart.cast<String>().map((e) => e).toList();
set values(List<String>? v) {
_wrapped.values = v?.toJSArray((e) => e);
}
/// If specified, the rule is not matched if the header exists but its value
/// contains at least one element in this list.
List<String>? get excludedValues =>
_wrapped.excludedValues?.toDart.cast<String>().map((e) => e).toList();
set excludedValues(List<String>? v) {
_wrapped.excludedValues = v?.toJSArray((e) => e);
}
}
class RuleCondition {
RuleCondition.fromJS(this._wrapped);
RuleCondition({
/// The pattern which is matched against the network request url.
/// Supported constructs:
///
/// **'*'** : Wildcard: Matches any number of characters.
///
/// **'|'** : Left/right anchor: If used at either end of the pattern,
/// specifies the beginning/end of the url respectively.
///
/// **'||'** : Domain name anchor: If used at the beginning of the pattern,
/// specifies the start of a (sub-)domain of the URL.
///
/// **'^'** : Separator character: This matches anything except a letter, a
/// digit or one of the following: _ - . %. This can also
/// match
/// the end of the URL.
///
/// Therefore `urlFilter` is composed of the following parts:
/// (optional Left/Domain name anchor) + pattern + (optional Right anchor).
///
/// If omitted, all urls are matched. An empty string is not allowed.
///
/// A pattern beginning with `||*` is not allowed. Use
/// `*` instead.
///
/// Note: Only one of `urlFilter` or `regexFilter` can
/// be specified.
///
/// Note: The `urlFilter` must be composed of only ASCII
/// characters. This is matched against a url where the host is encoded in
/// the punycode format (in case of internationalized domains) and any other
/// non-ascii characters are url encoded in utf-8.
/// For example, when the request url is
/// http://abc.рф?q=ф, the
/// `urlFilter` will be matched against the url
/// http://abc.xn--p1ai/?q=%D1%84.
String? urlFilter,
/// Regular expression to match against the network request url. This
/// follows
/// the <a href = "https://github.com/google/re2/wiki/Syntax">RE2
/// syntax</a>.
///
/// Note: Only one of `urlFilter` or `regexFilter` can
/// be specified.
///
/// Note: The `regexFilter` must be composed of only ASCII
/// characters. This is matched against a url where the host is encoded in
/// the punycode format (in case of internationalized domains) and any other
/// non-ascii characters are url encoded in utf-8.
String? regexFilter,
/// Whether the `urlFilter` or `regexFilter`
/// (whichever is specified) is case sensitive. Default is false.
bool? isUrlFilterCaseSensitive,
/// The rule will only match network requests originating from the list of
/// `initiatorDomains`. If the list is omitted, the rule is
/// applied to requests from all domains. An empty list is not allowed.
///
/// Notes:
/// <ul>
/// <li>Sub-domains like "a.example.com" are also allowed.</li>
/// <li>The entries must consist of only ascii characters.</li>
/// <li>Use punycode encoding for internationalized domains.</li>
/// <li>
/// This matches against the request initiator and not the request url.
/// </li>
/// <li>Sub-domains of the listed domains are also matched.</li>
/// </ul>
List<String>? initiatorDomains,
/// The rule will not match network requests originating from the list of
/// `excludedInitiatorDomains`. If the list is empty or omitted,
/// no domains are excluded. This takes precedence over
/// `initiatorDomains`.
///
/// Notes:
/// <ul>
/// <li>Sub-domains like "a.example.com" are also allowed.</li>
/// <li>The entries must consist of only ascii characters.</li>
/// <li>Use punycode encoding for internationalized domains.</li>
/// <li>
/// This matches against the request initiator and not the request url.
/// </li>
/// <li>Sub-domains of the listed domains are also excluded.</li>
/// </ul>
List<String>? excludedInitiatorDomains,
/// The rule will only match network requests when the domain matches one
/// from the list of `requestDomains`. If the list is omitted,
/// the rule is applied to requests from all domains. An empty list is not
/// allowed.
///
/// Notes:
/// <ul>
/// <li>Sub-domains like "a.example.com" are also allowed.</li>
/// <li>The entries must consist of only ascii characters.</li>
/// <li>Use punycode encoding for internationalized domains.</li>
/// <li>Sub-domains of the listed domains are also matched.</li>
/// </ul>
List<String>? requestDomains,
/// The rule will not match network requests when the domains matches one
/// from the list of `excludedRequestDomains`. If the list is
/// empty or omitted, no domains are excluded. This takes precedence over
/// `requestDomains`.
///
/// Notes:
/// <ul>
/// <li>Sub-domains like "a.example.com" are also allowed.</li>
/// <li>The entries must consist of only ascii characters.</li>
/// <li>Use punycode encoding for internationalized domains.</li>
/// <li>Sub-domains of the listed domains are also excluded.</li>
/// </ul>
List<String>? excludedRequestDomains,
/// The rule will only match network requests originating from the list of
/// `domains`.
List<String>? domains,
/// The rule will not match network requests originating from the list of
/// `excludedDomains`.
List<String>? excludedDomains,
/// List of resource types which the rule can match. An empty list is not
/// allowed.
///
/// Note: this must be specified for `allowAllRequests` rules and
/// may only include the `sub_frame` and `main_frame`
/// resource types.
List<ResourceType>? resourceTypes,
/// List of resource types which the rule won't match. Only one of
/// `resourceTypes` and `excludedResourceTypes` should
/// be specified. If neither of them is specified, all resource types except
/// "main_frame" are blocked.
List<ResourceType>? excludedResourceTypes,
/// List of HTTP request methods which the rule can match. An empty list is
/// not allowed.
///
/// Note: Specifying a `requestMethods` rule condition will also
/// exclude non-HTTP(s) requests, whereas specifying
/// `excludedRequestMethods` will not.
List<RequestMethod>? requestMethods,
/// List of request methods which the rule won't match. Only one of
/// `requestMethods` and `excludedRequestMethods`
/// should be specified. If neither of them is specified, all request
/// methods
/// are matched.
List<RequestMethod>? excludedRequestMethods,
/// Specifies whether the network request is first-party or third-party to
/// the domain from which it originated. If omitted, all requests are
/// accepted.
DomainType? domainType,
/// List of [tabs.Tab.id] which the rule should match. An ID of
/// [tabs.TAB_ID_NONE] matches requests which don't originate from a
/// tab. An empty list is not allowed. Only supported for session-scoped
/// rules.
List<int>? tabIds,
/// List of [tabs.Tab.id] which the rule should not match. An ID of
/// [tabs.TAB_ID_NONE] excludes requests which don't originate from a
/// tab. Only supported for session-scoped rules.
List<int>? excludedTabIds,
/// Rule matches if the request matches any response header in this list (if
/// specified).
/// TODO(crbug,com/1141166): Add documentation once feature is complete.
List<HeaderInfo>? responseHeaders,
/// Rule does not match if the request has any of the specified headers.
/// TODO(crbug,com/1141166): Add documentation once feature is complete.
List<String>? excludedResponseHeaders,
}) : _wrapped = $js.RuleCondition(
urlFilter: urlFilter,
regexFilter: regexFilter,
isUrlFilterCaseSensitive: isUrlFilterCaseSensitive,
initiatorDomains: initiatorDomains?.toJSArray((e) => e),
excludedInitiatorDomains:
excludedInitiatorDomains?.toJSArray((e) => e),
requestDomains: requestDomains?.toJSArray((e) => e),
excludedRequestDomains: excludedRequestDomains?.toJSArray((e) => e),
domains: domains?.toJSArray((e) => e),
excludedDomains: excludedDomains?.toJSArray((e) => e),
resourceTypes: resourceTypes?.toJSArray((e) => e.toJS),
excludedResourceTypes:
excludedResourceTypes?.toJSArray((e) => e.toJS),
requestMethods: requestMethods?.toJSArray((e) => e.toJS),
excludedRequestMethods:
excludedRequestMethods?.toJSArray((e) => e.toJS),
domainType: domainType?.toJS,
tabIds: tabIds?.toJSArray((e) => e),
excludedTabIds: excludedTabIds?.toJSArray((e) => e),
responseHeaders: responseHeaders?.toJSArray((e) => e.toJS),
excludedResponseHeaders: excludedResponseHeaders?.toJSArray((e) => e),
);
final $js.RuleCondition _wrapped;
$js.RuleCondition get toJS => _wrapped;
/// The pattern which is matched against the network request url.
/// Supported constructs:
///
/// **'*'** : Wildcard: Matches any number of characters.
///
/// **'|'** : Left/right anchor: If used at either end of the pattern,
/// specifies the beginning/end of the url respectively.
///
/// **'||'** : Domain name anchor: If used at the beginning of the pattern,
/// specifies the start of a (sub-)domain of the URL.