Skip to content

Commit

Permalink
Add TrustedTypes (#173)
Browse files Browse the repository at this point in the history
Fixes #172
  • Loading branch information
kevmoo committed Feb 15, 2024
1 parent 0447807 commit 975e55c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
# TODO(srujzs): Replace with stable when 3.3 is out.
sdk: [beta]
sdk: [dev, 3.3]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
Expand All @@ -46,8 +46,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
# TODO(srujzs): Add back stable when 3.3 is out.
sdk: [dev, beta]
sdk: [dev, 3.3]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
Expand All @@ -68,7 +67,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [main, dev]
sdk: [dev]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.1-wip

- Add [`TrustedTypes`](https://web.dev/trusted-types) members.

## 0.5.0

- Redeprecate APIs that were deprecated in `0.4.1` but undeprecated in `0.4.2`.
Expand Down
1 change: 1 addition & 0 deletions lib/src/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export 'dom/streams.dart';
export 'dom/svg.dart';
export 'dom/svg_animations.dart';
export 'dom/touch_events.dart';
export 'dom/trusted_types.dart';
export 'dom/uievents.dart';
export 'dom/url.dart';
export 'dom/user_timing.dart';
Expand Down
3 changes: 3 additions & 0 deletions lib/src/dom/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import 'selection_api.dart';
import 'service_workers.dart';
import 'speech_api.dart';
import 'storage.dart';
import 'trusted_types.dart';
import 'uievents.dart';
import 'vibration.dart';
import 'web_locks.dart';
Expand Down Expand Up @@ -3094,6 +3095,7 @@ extension type Window._(JSObject _) implements EventTarget, JSObject {
external bool get isSecureContext;
external bool get crossOriginIsolated;
external CacheStorage get caches;
external TrustedTypePolicyFactory get trustedTypes;
external Storage get sessionStorage;
external Storage get localStorage;
}
Expand Down Expand Up @@ -3745,6 +3747,7 @@ extension type WorkerGlobalScope._(JSObject _)
external bool get isSecureContext;
external bool get crossOriginIsolated;
external CacheStorage get caches;
external TrustedTypePolicyFactory get trustedTypes;
}
extension type DedicatedWorkerGlobalScope._(JSObject _)
implements WorkerGlobalScope, JSObject {
Expand Down
82 changes: 82 additions & 0 deletions lib/src/dom/trusted_types.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Generated from Web IDL definitions.

@JS()
library;

import 'dart:js_interop';

typedef HTMLString = String;
typedef ScriptString = String;
typedef ScriptURLString = String;
typedef TrustedType = JSObject;
typedef CreateHTMLCallback = JSFunction;
typedef CreateScriptCallback = JSFunction;
typedef CreateScriptURLCallback = JSFunction;
extension type TrustedHTML._(JSObject _) implements JSObject {
external static TrustedHTML fromLiteral(JSObject templateStringsArray);
external String toJSON();
}
extension type TrustedScript._(JSObject _) implements JSObject {
external static TrustedScript fromLiteral(JSObject templateStringsArray);
external String toJSON();
}
extension type TrustedScriptURL._(JSObject _) implements JSObject {
external static TrustedScriptURL fromLiteral(JSObject templateStringsArray);
external String toJSON();
}
extension type TrustedTypePolicyFactory._(JSObject _) implements JSObject {
external TrustedTypePolicy createPolicy(
String policyName, [
TrustedTypePolicyOptions policyOptions,
]);
external bool isHTML(JSAny? value);
external bool isScript(JSAny? value);
external bool isScriptURL(JSAny? value);
external String? getAttributeType(
String tagName,
String attribute, [
String elementNs,
String attrNs,
]);
external String? getPropertyType(
String tagName,
String property, [
String elementNs,
]);
external TrustedHTML get emptyHTML;
external TrustedScript get emptyScript;
external TrustedTypePolicy? get defaultPolicy;
}
extension type TrustedTypePolicy._(JSObject _) implements JSObject {
external TrustedHTML createHTML(
String input,
JSAny? arguments,
);
external TrustedScript createScript(
String input,
JSAny? arguments,
);
external TrustedScriptURL createScriptURL(
String input,
JSAny? arguments,
);
external String get name;
}
extension type TrustedTypePolicyOptions._(JSObject _) implements JSObject {
external factory TrustedTypePolicyOptions({
CreateHTMLCallback createHTML,
CreateScriptCallback createScript,
CreateScriptURLCallback createScriptURL,
});

external set createHTML(CreateHTMLCallback value);
external CreateHTMLCallback get createHTML;
external set createScript(CreateScriptCallback value);
external CreateScriptCallback get createScript;
external set createScriptURL(CreateScriptURLCallback value);
external CreateScriptURLCallback get createScriptURL;
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: web
version: 0.5.0
version: 0.5.1-wip
description: Lightweight browser API bindings built around JS static interop.
repository: https://github.com/dart-lang/web

environment:
sdk: ^3.3.0-76.0.dev
sdk: ^3.3.0

dev_dependencies:
analyzer: ^6.3.0
Expand Down
1 change: 1 addition & 0 deletions tool/generator/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ class Translator {
'touch-events',
'vibration',
'webrtc-stats',
'trusted-types',
};
if (allowList.contains(name)) {
return true;
Expand Down

0 comments on commit 975e55c

Please sign in to comment.