4
4
5
5
import 'dart:js_interop' ;
6
6
7
- import 'package:web/web.dart' ;
7
+ import 'package:web/web.dart' as web ;
8
8
9
- /// This extension type exists to handle unsupported features by certain browsers.
10
- @JS ()
11
- extension type WindowWithTrustedTypes (Window _) implements JSObject {
12
- /// Get the `trustedTypes` object from the window, if it is supported.
9
+ /// This extension gives [web.Window] a nullable getter to the `trustedTypes`
10
+ /// property, which is used to check for feature support.
11
+ extension NullableTrustedTypesGetter on web.Window {
12
+ /// (Nullable) Bindings to window.trustedTypes.
13
+ ///
14
+ /// This may be null if the browser doesn't support the Trusted Types API.
15
+ ///
16
+ /// See: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API
13
17
@JS ('trustedTypes' )
14
- external TrustedTypePolicyFactory ? get trustedTypesNullable ;
18
+ external GoogleMapsTrustedTypePolicyFactory ? get nullableTrustedTypes ;
15
19
}
16
20
17
21
// TODO(ditman): remove this extension type when we depend on package:web 0.5.1
18
22
/// This extension exists as a stop gap until `package:web 0.5.1` is released.
19
23
/// That version provides the `TrustedTypes` API.
20
- @JS ()
21
- extension type TrustedTypePolicyFactory ._(JSObject _) implements JSObject {
22
- /// Create a new `TrustedTypePolicy` instance
23
- /// with the given [policyName] and [policyOptions] .
24
- external TrustedTypePolicy createPolicy (
24
+ @JS ('TrustedTypePolicyFactory' )
25
+ extension type GoogleMapsTrustedTypePolicyFactory ._(JSObject _)
26
+ implements JSObject {
27
+ /// The `TrustedTypePolicy` for Google Maps Flutter.
28
+ static GoogleMapsTrustedTypePolicy ? _policy;
29
+
30
+ @JS ('createPolicy' )
31
+ external GoogleMapsTrustedTypePolicy _createPolicy (
25
32
String policyName, [
26
- TrustedTypePolicyOptions policyOptions,
33
+ GoogleMapsTrustedTypePolicyOptions policyOptions,
27
34
]);
35
+
36
+ /// Get a new [GoogleMapsTrustedTypePolicy] .
37
+ ///
38
+ /// If a policy already exists, it will be returned.
39
+ /// Otherwise, a new policy is created.
40
+ GoogleMapsTrustedTypePolicy getTrustedTypesPolicy (
41
+ String policyName, [
42
+ GoogleMapsTrustedTypePolicyOptions ? policyOptions,
43
+ ]) {
44
+ if (_policy == null ) {
45
+ if (policyOptions != null ) {
46
+ _policy = _createPolicy (policyName, policyOptions);
47
+ } else {
48
+ _policy = _createPolicy (policyName);
49
+ }
50
+ }
51
+
52
+ return _policy! ;
53
+ }
28
54
}
29
55
30
56
// TODO(ditman): remove this extension type when we depend on package:web 0.5.1
31
57
/// This extension exists as a stop gap until `package:web 0.5.1` is released.
32
58
/// That version provides the `TrustedTypes` API.
33
- extension type TrustedTypePolicy ._(JSObject _) implements JSObject {
59
+ @JS ('TrustedTypePolicy' )
60
+ extension type GoogleMapsTrustedTypePolicy ._(JSObject _) implements JSObject {
34
61
/// Create a new `TrustedHTML` instance with the given [input] and [arguments] .
35
- external TrustedHTML createHTML (
62
+ external GoogleMapsTrustedHTML createHTML (
36
63
String input,
37
64
JSAny ? arguments,
38
65
);
@@ -41,19 +68,25 @@ extension type TrustedTypePolicy._(JSObject _) implements JSObject {
41
68
// TODO(ditman): remove this extension type when we depend on package:web 0.5.1
42
69
/// This extension exists as a stop gap until `package:web 0.5.1` is released.
43
70
/// That version provides the `TrustedTypes` API.
44
- @JS ()
45
- extension type TrustedTypePolicyOptions ._(JSObject _) implements JSObject {
71
+ @JS ('TrustedTypePolicyOptions' )
72
+ extension type GoogleMapsTrustedTypePolicyOptions ._(JSObject _)
73
+ implements JSObject {
46
74
/// Create a new `TrustedTypePolicyOptions` instance.
47
- external factory TrustedTypePolicyOptions ({
75
+ external factory GoogleMapsTrustedTypePolicyOptions ({
48
76
JSFunction createHTML,
49
77
});
50
78
}
51
79
52
80
// TODO(ditman): remove this extension type when we depend on package:web 0.5.1
53
81
/// This extension exists as a stop gap until `package:web 0.5.1` is released.
54
82
/// That version provides the `TrustedTypes` API.
55
- @JS ()
56
- extension type TrustedHTML ._(JSObject _) implements JSObject {
57
- // This type inherits `toString()` from `Object`.
58
- // See also: https://developer.mozilla.org/en-US/docs/Web/API/TrustedHTML/toString
83
+ @JS ('TrustedHTML' )
84
+ extension type GoogleMapsTrustedHTML ._(JSObject _) implements JSObject {}
85
+
86
+ /// This extension provides a setter for the [web.HTMLElement] `innerHTML` property,
87
+ /// that accepts trusted HTML only.
88
+ extension TrustedInnerHTML on web.HTMLElement {
89
+ /// Set the inner HTML of this element to the given [trustedHTML] .
90
+ @JS ('innerHTML' )
91
+ external set trustedInnerHTML (GoogleMapsTrustedHTML trustedHTML);
59
92
}
0 commit comments