forked from xvrh/chrome_extension.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_settings.dart
639 lines (491 loc) · 19.6 KB
/
content_settings.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
// ignore_for_file: unnecessary_parenthesis
library;
import 'dart:js_util';
import 'src/internal_helpers.dart';
import 'src/js/content_settings.dart' as $js;
export 'src/chrome.dart' show chrome, EventStream;
final _contentSettings = ChromeContentSettings._();
extension ChromeContentSettingsExtension on Chrome {
/// Use the `chrome.contentSettings` API to change settings that control
/// whether websites can use features such as cookies, JavaScript, and
/// plugins. More generally speaking, content settings allow you to customize
/// Chrome's behavior on a per-site basis instead of globally.
ChromeContentSettings get contentSettings => _contentSettings;
}
class ChromeContentSettings {
ChromeContentSettings._();
bool get isAvailable =>
$js.chrome.contentSettingsNullable != null && alwaysTrue;
/// Whether to allow sites to use the [Private State Tokens
/// API](https://developer.chrome.com/docs/privacy-sandbox/trust-tokens/). One
/// of
/// [allow]: Allow sites to use the Private State Tokens API,
/// [block]: Block sites from using the Private State Tokens API.
/// Default is [allow].
/// The primary URL is the URL of the top-level frame. The secondary URL is
/// not used. NOTE: When calling `set()`, the primary pattern must be
/// `<all_urls>`.
ContentSetting get autoVerify =>
ContentSetting.fromJS($js.chrome.contentSettings.autoVerify);
/// Whether to allow cookies and other local data to be set by websites. One
/// of
/// [allow]: Accept cookies,
/// [block]: Block cookies,
/// [session_only]: Accept cookies only for the current session.
/// Default is [allow].
/// The primary URL is the URL representing the cookie origin. The secondary
/// URL is the URL of the top-level frame.
ContentSetting get cookies =>
ContentSetting.fromJS($js.chrome.contentSettings.cookies);
/// Whether to show images. One of
/// [allow]: Show images,
/// [block]: Don't show images.
/// Default is [allow].
/// The primary URL is the URL of the top-level frame. The secondary URL is
/// the URL of the image.
ContentSetting get images =>
ContentSetting.fromJS($js.chrome.contentSettings.images);
/// Whether to run JavaScript. One of
/// [allow]: Run JavaScript,
/// [block]: Don't run JavaScript.
/// Default is [allow].
/// The primary URL is the URL of the top-level frame. The secondary URL is
/// not used.
ContentSetting get javascript =>
ContentSetting.fromJS($js.chrome.contentSettings.javascript);
/// Whether to allow Geolocation. One of
/// [allow]: Allow sites to track your physical location,
/// [block]: Don't allow sites to track your physical location,
/// [ask]: Ask before allowing sites to track your physical location.
/// Default is [ask].
/// The primary URL is the URL of the document which requested location data.
/// The secondary URL is the URL of the top-level frame (which may or may not
/// differ from the requesting URL).
ContentSetting get location =>
ContentSetting.fromJS($js.chrome.contentSettings.location);
/// <i>Deprecated.</i> With Flash support removed in Chrome 88, this
/// permission no longer has any effect. Value is always [block]. Calls to
/// `set()` and `clear()` will be ignored.
ContentSetting get plugins =>
ContentSetting.fromJS($js.chrome.contentSettings.plugins);
/// Whether to allow sites to show pop-ups. One of
/// [allow]: Allow sites to show pop-ups,
/// [block]: Don't allow sites to show pop-ups.
/// Default is [block].
/// The primary URL is the URL of the top-level frame. The secondary URL is
/// not used.
ContentSetting get popups =>
ContentSetting.fromJS($js.chrome.contentSettings.popups);
/// Whether to allow sites to show desktop notifications. One of
/// [allow]: Allow sites to show desktop notifications,
/// [block]: Don't allow sites to show desktop notifications,
/// [ask]: Ask when a site wants to show desktop notifications.
/// Default is [ask].
/// The primary URL is the URL of the document which wants to show the
/// notification. The secondary URL is not used.
ContentSetting get notifications =>
ContentSetting.fromJS($js.chrome.contentSettings.notifications);
/// <i>Deprecated.</i> No longer has any effect. Fullscreen permission is now
/// automatically granted for all sites. Value is always [allow].
ContentSetting get fullscreen =>
ContentSetting.fromJS($js.chrome.contentSettings.fullscreen);
/// <i>Deprecated.</i> No longer has any effect. Mouse lock permission is now
/// automatically granted for all sites. Value is always [allow].
ContentSetting get mouselock =>
ContentSetting.fromJS($js.chrome.contentSettings.mouselock);
/// Whether to allow sites to access the microphone. One of
/// [allow]: Allow sites to access the microphone,
/// [block]: Don't allow sites to access the microphone,
/// [ask]: Ask when a site wants to access the microphone.
/// Default is [ask].
/// The primary URL is the URL of the document which requested microphone
/// access. The secondary URL is not used.
/// NOTE: The 'allow' setting is not valid if both patterns are '<all_urls>'.
ContentSetting get microphone =>
ContentSetting.fromJS($js.chrome.contentSettings.microphone);
/// Whether to allow sites to access the clipboard via advanced capabilities
/// of the Async Clipboard API. "Advanced" capabilities include anything
/// besides writing built-in formats after a user gesture, i.e. the ability to
/// read, the ability to write custom formats, and the ability to write
/// without a user gesture. One of
/// [allow]: Allow sites to use advanced clipboard capabilities,
/// [block]: Don't allow sites to use advanced clipboard capabilties,
/// [ask]: Ask when a site wants to use advanced clipboard capabilities.
/// Default is [ask].
/// The primary URL is the URL of the document which requested clipboard
/// access. The secondary URL is not used.
ContentSetting get clipboard =>
ContentSetting.fromJS($js.chrome.contentSettings.clipboard);
/// Whether to allow sites to access the camera. One of
/// [allow]: Allow sites to access the camera,
/// [block]: Don't allow sites to access the camera,
/// [ask]: Ask when a site wants to access the camera.
/// Default is [ask].
/// The primary URL is the URL of the document which requested camera access.
/// The secondary URL is not used.
/// NOTE: The 'allow' setting is not valid if both patterns are '<all_urls>'.
ContentSetting get camera =>
ContentSetting.fromJS($js.chrome.contentSettings.camera);
/// <i>Deprecated.</i> Previously, controlled whether to allow sites to run
/// plugins unsandboxed, however, with the Flash broker process removed in
/// Chrome 88, this permission no longer has any effect. Value is always
/// [block]. Calls to `set()` and `clear()` will be ignored.
ContentSetting get unsandboxedPlugins =>
ContentSetting.fromJS($js.chrome.contentSettings.unsandboxedPlugins);
/// Whether to allow sites to download multiple files automatically. One of
/// [allow]: Allow sites to download multiple files automatically,
/// [block]: Don't allow sites to download multiple files automatically,
/// [ask]: Ask when a site wants to download files automatically after the
/// first file.
/// Default is [ask].
/// The primary URL is the URL of the top-level frame. The secondary URL is
/// not used.
ContentSetting get automaticDownloads =>
ContentSetting.fromJS($js.chrome.contentSettings.automaticDownloads);
}
/// The scope of the ContentSetting. One of
/// [regular]: setting for regular profile (which is inherited by the incognito
/// profile if not overridden elsewhere),
/// [incognito_session_only]: setting for incognito profile that can only be set
/// during an incognito session and is deleted when the incognito session ends
/// (overrides regular settings).
enum Scope {
regular('regular'),
incognitoSessionOnly('incognito_session_only');
const Scope(this.value);
final String value;
String get toJS => value;
static Scope fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum AutoVerifyContentSetting {
allow('allow'),
block('block');
const AutoVerifyContentSetting(this.value);
final String value;
String get toJS => value;
static AutoVerifyContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum ClipboardContentSetting {
allow('allow'),
block('block'),
ask('ask');
const ClipboardContentSetting(this.value);
final String value;
String get toJS => value;
static ClipboardContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum CookiesContentSetting {
allow('allow'),
block('block'),
sessionOnly('session_only');
const CookiesContentSetting(this.value);
final String value;
String get toJS => value;
static CookiesContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum ImagesContentSetting {
allow('allow'),
block('block');
const ImagesContentSetting(this.value);
final String value;
String get toJS => value;
static ImagesContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum JavascriptContentSetting {
allow('allow'),
block('block');
const JavascriptContentSetting(this.value);
final String value;
String get toJS => value;
static JavascriptContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum LocationContentSetting {
allow('allow'),
block('block'),
ask('ask');
const LocationContentSetting(this.value);
final String value;
String get toJS => value;
static LocationContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum PluginsContentSetting {
block('block');
const PluginsContentSetting(this.value);
final String value;
String get toJS => value;
static PluginsContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum PopupsContentSetting {
allow('allow'),
block('block');
const PopupsContentSetting(this.value);
final String value;
String get toJS => value;
static PopupsContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum NotificationsContentSetting {
allow('allow'),
block('block'),
ask('ask');
const NotificationsContentSetting(this.value);
final String value;
String get toJS => value;
static NotificationsContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum FullscreenContentSetting {
allow('allow');
const FullscreenContentSetting(this.value);
final String value;
String get toJS => value;
static FullscreenContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum MouselockContentSetting {
allow('allow');
const MouselockContentSetting(this.value);
final String value;
String get toJS => value;
static MouselockContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum MicrophoneContentSetting {
allow('allow'),
block('block'),
ask('ask');
const MicrophoneContentSetting(this.value);
final String value;
String get toJS => value;
static MicrophoneContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum CameraContentSetting {
allow('allow'),
block('block'),
ask('ask');
const CameraContentSetting(this.value);
final String value;
String get toJS => value;
static CameraContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum PpapiBrokerContentSetting {
block('block');
const PpapiBrokerContentSetting(this.value);
final String value;
String get toJS => value;
static PpapiBrokerContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
enum MultipleAutomaticDownloadsContentSetting {
allow('allow'),
block('block'),
ask('ask');
const MultipleAutomaticDownloadsContentSetting(this.value);
final String value;
String get toJS => value;
static MultipleAutomaticDownloadsContentSetting fromJS(String value) =>
values.firstWhere((e) => e.value == value);
}
class ResourceIdentifier {
ResourceIdentifier.fromJS(this._wrapped);
ResourceIdentifier({
/// The resource identifier for the given content type.
required String id,
/// A human readable description of the resource.
String? description,
}) : _wrapped = $js.ResourceIdentifier(
id: id,
description: description,
);
final $js.ResourceIdentifier _wrapped;
$js.ResourceIdentifier get toJS => _wrapped;
/// The resource identifier for the given content type.
String get id => _wrapped.id;
set id(String v) {
_wrapped.id = v;
}
/// A human readable description of the resource.
String? get description => _wrapped.description;
set description(String? v) {
_wrapped.description = v;
}
}
class ContentSetting {
ContentSetting.fromJS(this._wrapped);
ContentSetting() : _wrapped = $js.ContentSetting();
final $js.ContentSetting _wrapped;
$js.ContentSetting get toJS => _wrapped;
/// Clear all content setting rules set by this extension.
Future<void> clear(ClearDetails details) async {
await promiseToFuture<void>(_wrapped.clear(details.toJS));
}
/// Gets the current content setting for a given pair of URLs.
Future<GetCallbackDetails> get(GetDetails details) async {
var $res = await promiseToFuture<$js.GetCallbackDetails>(
_wrapped.get(details.toJS));
return GetCallbackDetails.fromJS($res);
}
/// Applies a new content setting rule.
Future<void> set(SetDetails details) async {
await promiseToFuture<void>(_wrapped.set(details.toJS));
}
Future<List<ResourceIdentifier>?> getResourceIdentifiers() async {
var $res =
await promiseToFuture<JSArray?>(_wrapped.getResourceIdentifiers());
return $res?.toDart
.cast<$js.ResourceIdentifier>()
.map((e) => ResourceIdentifier.fromJS(e))
.toList();
}
}
class ClearDetails {
ClearDetails.fromJS(this._wrapped);
ClearDetails(
{
/// Where to clear the setting (default: regular).
Scope? scope})
: _wrapped = $js.ClearDetails(scope: scope?.toJS);
final $js.ClearDetails _wrapped;
$js.ClearDetails get toJS => _wrapped;
/// Where to clear the setting (default: regular).
Scope? get scope => _wrapped.scope?.let(Scope.fromJS);
set scope(Scope? v) {
_wrapped.scope = v?.toJS;
}
}
class GetCallbackDetails {
GetCallbackDetails.fromJS(this._wrapped);
GetCallbackDetails(
{
/// The content setting. See the description of the individual
/// ContentSetting objects for the possible values.
required Object setting})
: _wrapped = $js.GetCallbackDetails(setting: setting.jsify()!);
final $js.GetCallbackDetails _wrapped;
$js.GetCallbackDetails get toJS => _wrapped;
/// The content setting. See the description of the individual ContentSetting
/// objects for the possible values.
Object get setting => _wrapped.setting.dartify()!;
set setting(Object v) {
_wrapped.setting = v.jsify()!;
}
}
class GetDetails {
GetDetails.fromJS(this._wrapped);
GetDetails({
/// The primary URL for which the content setting should be retrieved. Note
/// that the meaning of a primary URL depends on the content type.
required String primaryUrl,
/// The secondary URL for which the content setting should be retrieved.
/// Defaults to the primary URL. Note that the meaning of a secondary URL
/// depends on the content type, and not all content types use secondary
/// URLs.
String? secondaryUrl,
/// A more specific identifier of the type of content for which the settings
/// should be retrieved.
ResourceIdentifier? resourceIdentifier,
/// Whether to check the content settings for an incognito session. (default
/// false)
bool? incognito,
}) : _wrapped = $js.GetDetails(
primaryUrl: primaryUrl,
secondaryUrl: secondaryUrl,
resourceIdentifier: resourceIdentifier?.toJS,
incognito: incognito,
);
final $js.GetDetails _wrapped;
$js.GetDetails get toJS => _wrapped;
/// The primary URL for which the content setting should be retrieved. Note
/// that the meaning of a primary URL depends on the content type.
String get primaryUrl => _wrapped.primaryUrl;
set primaryUrl(String v) {
_wrapped.primaryUrl = v;
}
/// The secondary URL for which the content setting should be retrieved.
/// Defaults to the primary URL. Note that the meaning of a secondary URL
/// depends on the content type, and not all content types use secondary URLs.
String? get secondaryUrl => _wrapped.secondaryUrl;
set secondaryUrl(String? v) {
_wrapped.secondaryUrl = v;
}
/// A more specific identifier of the type of content for which the settings
/// should be retrieved.
ResourceIdentifier? get resourceIdentifier =>
_wrapped.resourceIdentifier?.let(ResourceIdentifier.fromJS);
set resourceIdentifier(ResourceIdentifier? v) {
_wrapped.resourceIdentifier = v?.toJS;
}
/// Whether to check the content settings for an incognito session. (default
/// false)
bool? get incognito => _wrapped.incognito;
set incognito(bool? v) {
_wrapped.incognito = v;
}
}
class SetDetails {
SetDetails.fromJS(this._wrapped);
SetDetails({
/// The pattern for the primary URL. For details on the format of a pattern,
/// see [Content Setting Patterns](contentSettings#patterns).
required String primaryPattern,
/// The pattern for the secondary URL. Defaults to matching all URLs. For
/// details on the format of a pattern, see [Content Setting
/// Patterns](contentSettings#patterns).
String? secondaryPattern,
/// The resource identifier for the content type.
ResourceIdentifier? resourceIdentifier,
/// The setting applied by this rule. See the description of the individual
/// ContentSetting objects for the possible values.
required Object setting,
/// Where to set the setting (default: regular).
Scope? scope,
}) : _wrapped = $js.SetDetails(
primaryPattern: primaryPattern,
secondaryPattern: secondaryPattern,
resourceIdentifier: resourceIdentifier?.toJS,
setting: setting.jsify()!,
scope: scope?.toJS,
);
final $js.SetDetails _wrapped;
$js.SetDetails get toJS => _wrapped;
/// The pattern for the primary URL. For details on the format of a pattern,
/// see [Content Setting Patterns](contentSettings#patterns).
String get primaryPattern => _wrapped.primaryPattern;
set primaryPattern(String v) {
_wrapped.primaryPattern = v;
}
/// The pattern for the secondary URL. Defaults to matching all URLs. For
/// details on the format of a pattern, see [Content Setting
/// Patterns](contentSettings#patterns).
String? get secondaryPattern => _wrapped.secondaryPattern;
set secondaryPattern(String? v) {
_wrapped.secondaryPattern = v;
}
/// The resource identifier for the content type.
ResourceIdentifier? get resourceIdentifier =>
_wrapped.resourceIdentifier?.let(ResourceIdentifier.fromJS);
set resourceIdentifier(ResourceIdentifier? v) {
_wrapped.resourceIdentifier = v?.toJS;
}
/// The setting applied by this rule. See the description of the individual
/// ContentSetting objects for the possible values.
Object get setting => _wrapped.setting.dartify()!;
set setting(Object v) {
_wrapped.setting = v.jsify()!;
}
/// Where to set the setting (default: regular).
Scope? get scope => _wrapped.scope?.let(Scope.fromJS);
set scope(Scope? v) {
_wrapped.scope = v?.toJS;
}
}