|
13 | 13 | #include <LibWeb/HTML/HTMLTemplateElement.h> |
14 | 14 | #include <LibWeb/HTML/Parser/HTMLParser.h> |
15 | 15 | #include <LibWeb/Layout/BlockContainer.h> |
| 16 | +#include <LibWeb/TrustedTypes/RequireTrustedTypesForDirective.h> |
| 17 | +#include <LibWeb/TrustedTypes/TrustedTypePolicy.h> |
16 | 18 |
|
17 | 19 | namespace Web::DOM { |
18 | 20 |
|
@@ -63,22 +65,29 @@ EventTarget* ShadowRoot::get_parent(Event const& event) |
63 | 65 | } |
64 | 66 |
|
65 | 67 | // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml |
66 | | -WebIDL::ExceptionOr<String> ShadowRoot::inner_html() const |
| 68 | +WebIDL::ExceptionOr<TrustedTypes::TrustedHTMLOrString> ShadowRoot::inner_html() const |
67 | 69 | { |
68 | | - return TRY(serialize_fragment(HTML::RequireWellFormed::Yes)).to_utf8_but_should_be_ported_to_utf16(); |
| 70 | + return TRY(serialize_fragment(HTML::RequireWellFormed::Yes)); |
69 | 71 | } |
70 | 72 |
|
71 | 73 | // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml |
72 | | -WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(StringView value) |
| 74 | +WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(TrustedTypes::TrustedHTMLOrString const& value) |
73 | 75 | { |
74 | | - // FIXME: 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "ShadowRoot innerHTML", and "script". |
| 76 | + // 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with |
| 77 | + // TrustedHTML, this's relevant global object, the given value, "ShadowRoot innerHTML", and "script". |
| 78 | + auto const compliant_string = TRY(TrustedTypes::get_trusted_type_compliant_string( |
| 79 | + TrustedTypes::TrustedTypeName::TrustedHTML, |
| 80 | + HTML::relevant_global_object(*this), |
| 81 | + value, |
| 82 | + TrustedTypes::InjectionSink::ShadowRootinnerHTML, |
| 83 | + TrustedTypes::Script.to_string())); |
75 | 84 |
|
76 | 85 | // 2. Let context be this's host. |
77 | 86 | auto context = this->host(); |
78 | 87 | VERIFY(context); |
79 | 88 |
|
80 | | - // 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString. FIXME: Use compliantString instead of markup. |
81 | | - auto fragment = TRY(context->parse_fragment(value)); |
| 89 | + // 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString. |
| 90 | + auto fragment = TRY(context->parse_fragment(compliant_string.to_utf8_but_should_be_ported_to_utf16())); |
82 | 91 |
|
83 | 92 | // 4. Replace all with fragment within this. |
84 | 93 | this->replace_all(fragment); |
@@ -110,12 +119,19 @@ WebIDL::ExceptionOr<String> ShadowRoot::get_html(GetHTMLOptions const& options) |
110 | 119 | } |
111 | 120 |
|
112 | 121 | // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtmlunsafe |
113 | | -WebIDL::ExceptionOr<void> ShadowRoot::set_html_unsafe(StringView html) |
114 | | -{ |
115 | | - // FIXME: 1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with TrustedHTML, this's relevant global object, html, "ShadowRoot setHTMLUnsafe", and "script". |
116 | | - |
117 | | - // 3. Unsafe set HTML given this, this's shadow host, and compliantHTML. FIXME: Use compliantHTML. |
118 | | - TRY(unsafely_set_html(*this->host(), html)); |
| 122 | +WebIDL::ExceptionOr<void> ShadowRoot::set_html_unsafe(TrustedTypes::TrustedHTMLOrString const& html) |
| 123 | +{ |
| 124 | + // 1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with |
| 125 | + // TrustedHTML, this's relevant global object, html, "ShadowRoot setHTMLUnsafe", and "script". |
| 126 | + auto const compliant_html = TRY(TrustedTypes::get_trusted_type_compliant_string( |
| 127 | + TrustedTypes::TrustedTypeName::TrustedHTML, |
| 128 | + HTML::relevant_global_object(*this), |
| 129 | + html, |
| 130 | + TrustedTypes::InjectionSink::ShadowRootsetHTMLUnsafe, |
| 131 | + TrustedTypes::Script.to_string())); |
| 132 | + |
| 133 | + // 2. Unsafely set HTML given this, this's shadow host, and compliantHTML. |
| 134 | + TRY(unsafely_set_html(*this->host(), compliant_html.to_utf8_but_should_be_ported_to_utf16())); |
119 | 135 |
|
120 | 136 | return {}; |
121 | 137 | } |
|
0 commit comments