Skip to content

Commit 975e55c

Browse files
authored
Add TrustedTypes (#173)
Fixes #172
1 parent 0447807 commit 975e55c

File tree

7 files changed

+96
-6
lines changed

7 files changed

+96
-6
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
# TODO(srujzs): Replace with stable when 3.3 is out.
25-
sdk: [beta]
25+
sdk: [dev, 3.3]
2626
steps:
2727
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
2828
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
@@ -46,8 +46,7 @@ jobs:
4646
fail-fast: false
4747
matrix:
4848
os: [ubuntu-latest]
49-
# TODO(srujzs): Add back stable when 3.3 is out.
50-
sdk: [dev, beta]
49+
sdk: [dev, 3.3]
5150
steps:
5251
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
5352
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
@@ -68,7 +67,7 @@ jobs:
6867
fail-fast: false
6968
matrix:
7069
os: [ubuntu-latest]
71-
sdk: [main, dev]
70+
sdk: [dev]
7271
steps:
7372
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
7473
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.1-wip
2+
3+
- Add [`TrustedTypes`](https://web.dev/trusted-types) members.
4+
15
## 0.5.0
26

37
- Redeprecate APIs that were deprecated in `0.4.1` but undeprecated in `0.4.2`.

lib/src/dom.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export 'dom/streams.dart';
9191
export 'dom/svg.dart';
9292
export 'dom/svg_animations.dart';
9393
export 'dom/touch_events.dart';
94+
export 'dom/trusted_types.dart';
9495
export 'dom/uievents.dart';
9596
export 'dom/url.dart';
9697
export 'dom/user_timing.dart';

lib/src/dom/html.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import 'selection_api.dart';
3838
import 'service_workers.dart';
3939
import 'speech_api.dart';
4040
import 'storage.dart';
41+
import 'trusted_types.dart';
4142
import 'uievents.dart';
4243
import 'vibration.dart';
4344
import 'web_locks.dart';
@@ -3094,6 +3095,7 @@ extension type Window._(JSObject _) implements EventTarget, JSObject {
30943095
external bool get isSecureContext;
30953096
external bool get crossOriginIsolated;
30963097
external CacheStorage get caches;
3098+
external TrustedTypePolicyFactory get trustedTypes;
30973099
external Storage get sessionStorage;
30983100
external Storage get localStorage;
30993101
}
@@ -3745,6 +3747,7 @@ extension type WorkerGlobalScope._(JSObject _)
37453747
external bool get isSecureContext;
37463748
external bool get crossOriginIsolated;
37473749
external CacheStorage get caches;
3750+
external TrustedTypePolicyFactory get trustedTypes;
37483751
}
37493752
extension type DedicatedWorkerGlobalScope._(JSObject _)
37503753
implements WorkerGlobalScope, JSObject {

lib/src/dom/trusted_types.dart

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Generated from Web IDL definitions.
6+
7+
@JS()
8+
library;
9+
10+
import 'dart:js_interop';
11+
12+
typedef HTMLString = String;
13+
typedef ScriptString = String;
14+
typedef ScriptURLString = String;
15+
typedef TrustedType = JSObject;
16+
typedef CreateHTMLCallback = JSFunction;
17+
typedef CreateScriptCallback = JSFunction;
18+
typedef CreateScriptURLCallback = JSFunction;
19+
extension type TrustedHTML._(JSObject _) implements JSObject {
20+
external static TrustedHTML fromLiteral(JSObject templateStringsArray);
21+
external String toJSON();
22+
}
23+
extension type TrustedScript._(JSObject _) implements JSObject {
24+
external static TrustedScript fromLiteral(JSObject templateStringsArray);
25+
external String toJSON();
26+
}
27+
extension type TrustedScriptURL._(JSObject _) implements JSObject {
28+
external static TrustedScriptURL fromLiteral(JSObject templateStringsArray);
29+
external String toJSON();
30+
}
31+
extension type TrustedTypePolicyFactory._(JSObject _) implements JSObject {
32+
external TrustedTypePolicy createPolicy(
33+
String policyName, [
34+
TrustedTypePolicyOptions policyOptions,
35+
]);
36+
external bool isHTML(JSAny? value);
37+
external bool isScript(JSAny? value);
38+
external bool isScriptURL(JSAny? value);
39+
external String? getAttributeType(
40+
String tagName,
41+
String attribute, [
42+
String elementNs,
43+
String attrNs,
44+
]);
45+
external String? getPropertyType(
46+
String tagName,
47+
String property, [
48+
String elementNs,
49+
]);
50+
external TrustedHTML get emptyHTML;
51+
external TrustedScript get emptyScript;
52+
external TrustedTypePolicy? get defaultPolicy;
53+
}
54+
extension type TrustedTypePolicy._(JSObject _) implements JSObject {
55+
external TrustedHTML createHTML(
56+
String input,
57+
JSAny? arguments,
58+
);
59+
external TrustedScript createScript(
60+
String input,
61+
JSAny? arguments,
62+
);
63+
external TrustedScriptURL createScriptURL(
64+
String input,
65+
JSAny? arguments,
66+
);
67+
external String get name;
68+
}
69+
extension type TrustedTypePolicyOptions._(JSObject _) implements JSObject {
70+
external factory TrustedTypePolicyOptions({
71+
CreateHTMLCallback createHTML,
72+
CreateScriptCallback createScript,
73+
CreateScriptURLCallback createScriptURL,
74+
});
75+
76+
external set createHTML(CreateHTMLCallback value);
77+
external CreateHTMLCallback get createHTML;
78+
external set createScript(CreateScriptCallback value);
79+
external CreateScriptCallback get createScript;
80+
external set createScriptURL(CreateScriptURLCallback value);
81+
external CreateScriptURLCallback get createScriptURL;
82+
}

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: web
2-
version: 0.5.0
2+
version: 0.5.1-wip
33
description: Lightweight browser API bindings built around JS static interop.
44
repository: https://github.com/dart-lang/web
55

66
environment:
7-
sdk: ^3.3.0-76.0.dev
7+
sdk: ^3.3.0
88

99
dev_dependencies:
1010
analyzer: ^6.3.0

tool/generator/translator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ class Translator {
976976
'touch-events',
977977
'vibration',
978978
'webrtc-stats',
979+
'trusted-types',
979980
};
980981
if (allowList.contains(name)) {
981982
return true;

0 commit comments

Comments
 (0)