Skip to content

Commit bda31c2

Browse files
srujzscommit-bot@chromium.org
authored andcommitted
[dart:html] Update Trusted Types APIs
Closes b/195948578 Modifies Trusted Types APIs to be compliant with the spec in https://w3c.github.io/webappsec-trusted-types/dist/spec/. Change-Id: I65d52ace12342ce777ab596a9dd2e9a3f74b2f05 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212270 Commit-Queue: Srujan Gaddam <[email protected]> Reviewed-by: Riley Porter <[email protected]>
1 parent b3cb952 commit bda31c2

File tree

4 files changed

+357
-3
lines changed

4 files changed

+357
-3
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@
7878
- The experimental `waitFor` functionality, and the library containing only that
7979
function, are now deprecated.
8080

81+
#### `dart:html`
82+
83+
- **Breaking Change**: Trusted Types APIs have been updated to comply to the
84+
latest [W3C spec]. This includes adding `TrustedScript`, `TrustedScriptURL`,
85+
`TrustedTypePolicy`, and `TrustedTypePolicyFactory`, as well as modifying the
86+
methods within the types, like removing the now deprecated `escape` and
87+
and `unsafelyCreate` methods. These deprecated methods are already unsupported
88+
on most modern browsers, so this would simply make them static failures now.
89+
Users of the old API are encouraged to use the `TrustedTypePolicy` to create
90+
Trusted Types. Please see the [MDN Web Docs] for examples.
91+
92+
[W3C spec]: https://w3c.github.io/webappsec-trusted-types/dist/spec/
93+
[MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API#interfaces
94+
8195
### Tools
8296

8397
#### Dart command line

sdk/lib/html/dart2js/html_dart2js.dart

Lines changed: 148 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,45 @@ class Coordinates extends Interceptor {
32853285
// for details. All rights reserved. Use of this source code is governed by a
32863286
// BSD-style license that can be found in the LICENSE file.
32873287

3288+
// WARNING: Do not edit - generated code.
3289+
3290+
typedef void CreateHtmlCallback(String input,
3291+
[Object? arg1,
3292+
Object? arg2,
3293+
Object? arg3,
3294+
Object? arg4,
3295+
Object? arg5,
3296+
Object? arg6]);
3297+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3298+
// for details. All rights reserved. Use of this source code is governed by a
3299+
// BSD-style license that can be found in the LICENSE file.
3300+
3301+
// WARNING: Do not edit - generated code.
3302+
3303+
typedef void CreateScriptCallback(String input,
3304+
[Object? arg1,
3305+
Object? arg2,
3306+
Object? arg3,
3307+
Object? arg4,
3308+
Object? arg5,
3309+
Object? arg6]);
3310+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3311+
// for details. All rights reserved. Use of this source code is governed by a
3312+
// BSD-style license that can be found in the LICENSE file.
3313+
3314+
// WARNING: Do not edit - generated code.
3315+
3316+
typedef void CreateScriptUrlCallback(String input,
3317+
[Object? arg1,
3318+
Object? arg2,
3319+
Object? arg3,
3320+
Object? arg4,
3321+
Object? arg5,
3322+
Object? arg6]);
3323+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3324+
// for details. All rights reserved. Use of this source code is governed by a
3325+
// BSD-style license that can be found in the LICENSE file.
3326+
32883327
@Native("Credential")
32893328
class Credential extends Interceptor {
32903329
// To suppress missing implicit constructor warnings.
@@ -30691,9 +30730,26 @@ class TrustedHtml extends Interceptor {
3069130730
throw new UnsupportedError("Not supported");
3069230731
}
3069330732

30694-
static TrustedHtml escape(String html) native;
30733+
@JSName('toJSON')
30734+
String toJson() native;
30735+
30736+
String toString() native;
30737+
}
30738+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
30739+
// for details. All rights reserved. Use of this source code is governed by a
30740+
// BSD-style license that can be found in the LICENSE file.
30741+
30742+
@Native("TrustedScript")
30743+
class TrustedScript extends Interceptor {
30744+
// To suppress missing implicit constructor warnings.
30745+
factory TrustedScript._() {
30746+
throw new UnsupportedError("Not supported");
30747+
}
30748+
30749+
@JSName('toJSON')
30750+
String toJson() native;
3069530751

30696-
static TrustedHtml unsafelyCreate(String html) native;
30752+
String toString() native;
3069730753
}
3069830754
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3069930755
// for details. All rights reserved. Use of this source code is governed by a
@@ -30706,7 +30762,94 @@ class TrustedScriptUrl extends Interceptor {
3070630762
throw new UnsupportedError("Not supported");
3070730763
}
3070830764

30709-
static TrustedScriptUrl unsafelyCreate(String url) native;
30765+
@JSName('toJSON')
30766+
String toJson() native;
30767+
30768+
String toString() native;
30769+
}
30770+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
30771+
// for details. All rights reserved. Use of this source code is governed by a
30772+
// BSD-style license that can be found in the LICENSE file.
30773+
30774+
@Native("TrustedTypePolicy")
30775+
class TrustedTypePolicy extends Interceptor {
30776+
// To suppress missing implicit constructor warnings.
30777+
factory TrustedTypePolicy._() {
30778+
throw new UnsupportedError("Not supported");
30779+
}
30780+
30781+
String? get name native;
30782+
30783+
@JSName('createHTML')
30784+
TrustedHtml createHtml(String input,
30785+
[Object? arg1,
30786+
Object? arg2,
30787+
Object? arg3,
30788+
Object? arg4,
30789+
Object? arg5,
30790+
Object? arg6]) native;
30791+
30792+
TrustedScript createScript(String input,
30793+
[Object? arg1,
30794+
Object? arg2,
30795+
Object? arg3,
30796+
Object? arg4,
30797+
Object? arg5,
30798+
Object? arg6]) native;
30799+
30800+
@JSName('createScriptURL')
30801+
TrustedScriptUrl createScriptUrl(String input,
30802+
[Object? arg1,
30803+
Object? arg2,
30804+
Object? arg3,
30805+
Object? arg4,
30806+
Object? arg5,
30807+
Object? arg6]) native;
30808+
}
30809+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
30810+
// for details. All rights reserved. Use of this source code is governed by a
30811+
// BSD-style license that can be found in the LICENSE file.
30812+
30813+
@Native("TrustedTypePolicyFactory")
30814+
class TrustedTypePolicyFactory extends Interceptor {
30815+
// To suppress missing implicit constructor warnings.
30816+
factory TrustedTypePolicyFactory._() {
30817+
throw new UnsupportedError("Not supported");
30818+
}
30819+
30820+
TrustedTypePolicy? get defaultPolicy native;
30821+
30822+
@JSName('emptyHTML')
30823+
TrustedHtml? get emptyHtml native;
30824+
30825+
TrustedScript? get emptyScript native;
30826+
30827+
TrustedTypePolicy createPolicy(String policyName, [Map? policyOptions]) {
30828+
if (policyOptions != null) {
30829+
var policyOptions_1 = convertDartToNative_Dictionary(policyOptions);
30830+
return _createPolicy_1(policyName, policyOptions_1);
30831+
}
30832+
return _createPolicy_2(policyName);
30833+
}
30834+
30835+
@JSName('createPolicy')
30836+
TrustedTypePolicy _createPolicy_1(policyName, policyOptions) native;
30837+
@JSName('createPolicy')
30838+
TrustedTypePolicy _createPolicy_2(policyName) native;
30839+
30840+
String? getAttributeType(String tagName, String attribute,
30841+
[String? elementNs, String? attrNs]) native;
30842+
30843+
String? getPropertyType(String tagName, String property, [String? elementNs])
30844+
native;
30845+
30846+
@JSName('isHTML')
30847+
bool isHtml(Object value) native;
30848+
30849+
bool isScript(Object value) native;
30850+
30851+
@JSName('isScriptURL')
30852+
bool isScriptUrl(Object value) native;
3071030853
}
3071130854
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3071230855
// for details. All rights reserved. Use of this source code is governed by a
@@ -32839,6 +32982,8 @@ class Window extends EventTarget
3283932982
@Returns('Window|=Object')
3284032983
dynamic get _get_top native;
3284132984

32985+
TrustedTypePolicyFactory? get trustedTypes native;
32986+
3284232987
VisualViewport? get visualViewport native;
3284332988

3284432989
/**

tools/dom/dom.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,6 +5133,18 @@
51335133
},
51345134
"support_level": "deprecated"
51355135
},
5136+
"CreateHTMLCallback": {
5137+
"members": {},
5138+
"support_level": "untriaged"
5139+
},
5140+
"CreateScriptCallback": {
5141+
"members": {},
5142+
"support_level": "untriaged"
5143+
},
5144+
"CreateScriptURLCallback": {
5145+
"members": {},
5146+
"support_level": "untriaged"
5147+
},
51365148
"Credential": {
51375149
"members": {
51385150
"avatarURL": {
@@ -22486,20 +22498,92 @@
2248622498
"escape": {
2248722499
"support_level": "untriaged"
2248822500
},
22501+
"toJSON": {
22502+
"support_level": "untriaged"
22503+
},
22504+
"toString": {
22505+
"support_level": "untriaged"
22506+
},
2248922507
"unsafelyCreate": {
2249022508
"support_level": "untriaged"
2249122509
}
2249222510
},
2249322511
"support_level": "untriaged"
2249422512
},
22513+
"TrustedScript": {
22514+
"members": {
22515+
"toJSON": {
22516+
"support_level": "untriaged"
22517+
},
22518+
"toString": {
22519+
"support_level": "untriaged"
22520+
}
22521+
},
22522+
"support_level": "untriaged"
22523+
},
2249522524
"TrustedScriptURL": {
2249622525
"members": {
22526+
"toJSON": {
22527+
"support_level": "untriaged"
22528+
},
22529+
"toString": {
22530+
"support_level": "untriaged"
22531+
},
2249722532
"unsafelyCreate": {
2249822533
"support_level": "untriaged"
2249922534
}
2250022535
},
2250122536
"support_level": "untriaged"
2250222537
},
22538+
"TrustedTypePolicy": {
22539+
"members": {
22540+
"createHTML": {
22541+
"support_level": "untriaged"
22542+
},
22543+
"createScript": {
22544+
"support_level": "untriaged"
22545+
},
22546+
"createScriptURL": {
22547+
"support_level": "untriaged"
22548+
},
22549+
"name": {
22550+
"support_level": "untriaged"
22551+
}
22552+
},
22553+
"support_level": "untriaged"
22554+
},
22555+
"TrustedTypePolicyFactory": {
22556+
"members": {
22557+
"createPolicy": {
22558+
"support_level": "untriaged"
22559+
},
22560+
"defaultPolicy": {
22561+
"support_level": "untriaged"
22562+
},
22563+
"emptyHTML": {
22564+
"support_level": "untriaged"
22565+
},
22566+
"emptyScript": {
22567+
"support_level": "untriaged"
22568+
},
22569+
"getAttributeType": {
22570+
"support_level": "untriaged"
22571+
},
22572+
"getPropertyType": {
22573+
"support_level": "untriaged"
22574+
},
22575+
"isHTML": {
22576+
"support_level": "untriaged"
22577+
},
22578+
"isScript": {
22579+
"support_level": "untriaged"
22580+
},
22581+
"isScriptURL": {
22582+
"support_level": "untriaged"
22583+
}
22584+
},
22585+
"support_level": "untriaged"
22586+
},
2250322587
"TrustedURL": {
2250422588
"members": {
2250522589
"create": {
@@ -30731,6 +30815,9 @@
3073130815
"toString": {},
3073230816
"toolbar": {},
3073330817
"top": {},
30818+
"trustedTypes": {
30819+
"support_level": "untriaged"
30820+
},
3073430821
"visualViewport": {
3073530822
"support_level": "untriaged"
3073630823
},

0 commit comments

Comments
 (0)