From db41ea811747caf80f4231d0a8f388f8e181511b Mon Sep 17 00:00:00 2001 From: Tete17 Date: Sun, 10 Aug 2025 23:49:19 +0200 Subject: [PATCH] LibWeb: Amend Element interface to make it compatible with TrustedTypes --- Libraries/LibWeb/DOM/Element.cpp | 79 +++++++++++++------ Libraries/LibWeb/DOM/Element.h | 12 +-- Libraries/LibWeb/DOM/Element.idl | 13 ++- Libraries/LibWeb/DOM/Node.cpp | 8 +- Libraries/LibWeb/DOM/Node.h | 2 +- Libraries/LibWeb/DOM/ShadowRoot.cpp | 2 +- Libraries/LibWeb/HTML/HTMLInputElement.cpp | 4 +- Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 2 +- Libraries/LibWeb/TrustedTypes/InjectionSink.h | 4 + Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 2 +- Services/WebContent/ConnectionFromClient.cpp | 18 ++--- Services/WebContent/WebDriverConnection.cpp | 8 +- 12 files changed, 93 insertions(+), 61 deletions(-) diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 7c540cb7dd..0c9b5b1656 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -89,6 +89,7 @@ #include #include #include +#include #include #include #include @@ -370,7 +371,7 @@ WebIDL::ExceptionOr Element::set_attribute_ns(Optional const& n auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name, ValidationContext::Element)); // 2. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value - // with localName, namespace, element, and value. + // with localName, namespace, this, and value. auto const verified_value = TRY(TrustedTypes::get_trusted_types_compliant_attribute_value( extracted_qualified_name.local_name(), extracted_qualified_name.namespace_().has_value() ? Utf16String::from_utf8(extracted_qualified_name.namespace_().value()) : Optional(), @@ -1057,15 +1058,22 @@ WebIDL::ExceptionOr Element::closest(StringView selectors) } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml -WebIDL::ExceptionOr Element::set_inner_html(StringView value) +WebIDL::ExceptionOr Element::set_inner_html(TrustedTypes::TrustedHTMLOrString const& value) { - // 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, "Element innerHTML", and "script". + // 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, "Element innerHTML", and "script". + auto const compliant_string = TRY(TrustedTypes::get_trusted_type_compliant_string( + TrustedTypes::TrustedTypeName::TrustedHTML, + HTML::relevant_global_object(*this), + value, + TrustedTypes::InjectionSink::ElementinnerHTML, + TrustedTypes::Script.to_string())); // 2. Let context be this. DOM::Node* context = this; - // 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString. FIXME: Use compliantString. - auto fragment = TRY(as(*context).parse_fragment(value)); + // 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString. + auto fragment = TRY(as(*context).parse_fragment(compliant_string.to_utf8_but_should_be_ported_to_utf16())); // 4. If context is a template element, then set context to the template element's template contents (a DocumentFragment). auto* template_element = as_if(*context); @@ -1089,9 +1097,9 @@ WebIDL::ExceptionOr Element::set_inner_html(StringView value) } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml -WebIDL::ExceptionOr Element::inner_html() const +WebIDL::ExceptionOr Element::inner_html() const { - return serialize_fragment(HTML::RequireWellFormed::Yes); + return TRY(serialize_fragment(HTML::RequireWellFormed::Yes)); } bool Element::is_focused() const @@ -2098,15 +2106,22 @@ WebIDL::ExceptionOr> Element::parse_fragment(Stri } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml -WebIDL::ExceptionOr Element::outer_html() const +WebIDL::ExceptionOr Element::outer_html() const { - return serialize_fragment(HTML::RequireWellFormed::Yes, FragmentSerializationMode::Outer); + return TRY(serialize_fragment(HTML::RequireWellFormed::Yes, FragmentSerializationMode::Outer)); } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml -WebIDL::ExceptionOr Element::set_outer_html(String const& value) +WebIDL::ExceptionOr Element::set_outer_html(TrustedTypes::TrustedHTMLOrString const& value) { - // 1. FIXME: Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "Element outerHTML", and "script". + // 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, "Element outerHTML", and "script". + auto const compliant_string = TRY(TrustedTypes::get_trusted_type_compliant_string( + TrustedTypes::TrustedTypeName::TrustedHTML, + HTML::relevant_global_object(*this), + value, + TrustedTypes::InjectionSink::ElementouterHTML, + TrustedTypes::Script.to_string())); // 2. Let parent be this's parent. auto* parent = this->parent(); @@ -2123,8 +2138,8 @@ WebIDL::ExceptionOr Element::set_outer_html(String const& value) if (parent->is_document_fragment()) parent = TRY(create_element(document(), HTML::TagNames::body, Namespace::HTML)); - // 6. Let fragment be the result of invoking the fragment parsing algorithm steps given parent and compliantString. FIXME: Use compliantString. - auto fragment = TRY(as(*parent).parse_fragment(value)); + // 6. Let fragment be the result of invoking the fragment parsing algorithm steps given parent and compliantString. + auto fragment = TRY(as(*parent).parse_fragment(compliant_string.to_utf8_but_should_be_ported_to_utf16())); // 6. Replace this with fragment within this's parent. TRY(parent->replace_child(fragment, *this)); @@ -2133,12 +2148,21 @@ WebIDL::ExceptionOr Element::set_outer_html(String const& value) } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#the-insertadjacenthtml()-method -WebIDL::ExceptionOr Element::insert_adjacent_html(String const& position, String const& string) +WebIDL::ExceptionOr Element::insert_adjacent_html(String const& position, TrustedTypes::TrustedHTMLOrString const& string) { - // 1. Let context be null. + // 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with + // TrustedHTML, this's relevant global object, string, "Element insertAdjacentHTML", and "script". + auto const compliant_string = TRY(TrustedTypes::get_trusted_type_compliant_string( + TrustedTypes::TrustedTypeName::TrustedHTML, + HTML::relevant_global_object(*this), + string, + TrustedTypes::InjectionSink::ElementinsertAdjacentHTML, + TrustedTypes::Script.to_string())); + + // 2. Let context be null. GC::Ptr context; - // 2. Use the first matching item from this list: + // 3. Use the first matching item from this list: // - If position is an ASCII case-insensitive match for the string "beforebegin" // - If position is an ASCII case-insensitive match for the string "afterend" if (position.equals_ignoring_ascii_case("beforebegin"sv) @@ -2163,7 +2187,7 @@ WebIDL::ExceptionOr Element::insert_adjacent_html(String const& position, return WebIDL::SyntaxError::create(realm(), "insertAdjacentHTML: invalid position argument"_utf16); } - // 3. If context is not an Element or the following are all true: + // 4. If context is not an Element or the following are all true: // - context's node document is an HTML document, // - context's local name is "html", and // - context's namespace is the HTML namespace; @@ -2175,10 +2199,10 @@ WebIDL::ExceptionOr Element::insert_adjacent_html(String const& position, context = TRY(create_element(document(), HTML::TagNames::body, Namespace::HTML)); } - // 4. Let fragment be the result of invoking the fragment parsing algorithm steps with context and string. - auto fragment = TRY(as(*context).parse_fragment(string)); + // 5. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString. + auto fragment = TRY(as(*context).parse_fragment(compliant_string.to_utf8_but_should_be_ported_to_utf16())); - // 5. Use the first matching item from this list: + // 6. Use the first matching item from this list: // - If position is an ASCII case-insensitive match for the string "beforebegin" if (position.equals_ignoring_ascii_case("beforebegin"sv)) { @@ -3936,17 +3960,24 @@ WebIDL::ExceptionOr Element::get_html(GetHTMLOptions const& options) con } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-sethtmlunsafe -WebIDL::ExceptionOr Element::set_html_unsafe(StringView html) +WebIDL::ExceptionOr Element::set_html_unsafe(TrustedTypes::TrustedHTMLOrString const& html) { - // FIXME: 1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with TrustedHTML, this's relevant global object, html, "Element setHTMLUnsafe", and "script". + // 1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with + // TrustedHTML, this's relevant global object, html, "Element setHTMLUnsafe", and "script". + auto const compliant_html = TRY(TrustedTypes::get_trusted_type_compliant_string( + TrustedTypes::TrustedTypeName::TrustedHTML, + HTML::relevant_global_object(*this), + html, + TrustedTypes::InjectionSink::ElementsetHTMLUnsafe, + TrustedTypes::Script.to_string())); // 2. Let target be this's template contents if this is a template element; otherwise this. DOM::Node* target = this; if (is(*this)) target = as(*this).content().ptr(); - // 3. Unsafe set HTML given target, this, and compliantHTML. FIXME: Use compliantHTML. - TRY(target->unsafely_set_html(*this, html)); + // 3. Unsafe set HTML given target, this, and compliantHTML. + TRY(target->unsafely_set_html(*this, compliant_html.to_utf8_but_should_be_ported_to_utf16())); return {}; } diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 996cbffd8b..1ae51ce322 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -239,17 +239,17 @@ public: [[nodiscard]] GC::Ptr element_to_inherit_style_from(Optional) const; - WebIDL::ExceptionOr inner_html() const; - WebIDL::ExceptionOr set_inner_html(StringView); + WebIDL::ExceptionOr inner_html() const; + WebIDL::ExceptionOr set_inner_html(TrustedTypes::TrustedHTMLOrString const&); - WebIDL::ExceptionOr set_html_unsafe(StringView); + WebIDL::ExceptionOr set_html_unsafe(TrustedTypes::TrustedHTMLOrString const&); WebIDL::ExceptionOr get_html(GetHTMLOptions const&) const; - WebIDL::ExceptionOr insert_adjacent_html(String const& position, String const&); + WebIDL::ExceptionOr insert_adjacent_html(String const& position, TrustedTypes::TrustedHTMLOrString const&); - WebIDL::ExceptionOr outer_html() const; - WebIDL::ExceptionOr set_outer_html(String const&); + WebIDL::ExceptionOr outer_html() const; + WebIDL::ExceptionOr set_outer_html(TrustedTypes::TrustedHTMLOrString const&); bool is_focused() const; bool is_active() const; diff --git a/Libraries/LibWeb/DOM/Element.idl b/Libraries/LibWeb/DOM/Element.idl index 60cad7a00f..f2f9c2e4f6 100644 --- a/Libraries/LibWeb/DOM/Element.idl +++ b/Libraries/LibWeb/DOM/Element.idl @@ -14,6 +14,7 @@ #import #import #import +#import #import enum ScrollLogicalPosition { "start", "center", "end", "nearest" }; @@ -109,18 +110,14 @@ interface Element : Node { readonly attribute double currentCSSZoom; // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization - // FIXME: [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html); - [CEReactions] undefined setHTMLUnsafe(DOMString html); + [CEReactions] undefined setHTMLUnsafe((TrustedHTML or Utf16DOMString) html); DOMString getHTML(optional GetHTMLOptions options = {}); - // FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML; - [CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML; + [CEReactions, LegacyNullToEmptyString] attribute (TrustedHTML or Utf16DOMString) innerHTML; - // FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) outerHTML; - [CEReactions, LegacyNullToEmptyString] attribute DOMString outerHTML; + [CEReactions, LegacyNullToEmptyString] attribute (TrustedHTML or Utf16DOMString) outerHTML; - // FIXME: [CEReactions] undefined insertAdjacentHTML(DOMString position, (TrustedHTML or DOMString) string); - [CEReactions] undefined insertAdjacentHTML(DOMString position, DOMString text); + [CEReactions] undefined insertAdjacentHTML(DOMString position, (TrustedHTML or Utf16DOMString) text); // https://w3c.github.io/pointerevents/#extensions-to-the-element-interface undefined setPointerCapture(long pointerId); diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 5bc5837f51..cf1fe1a07c 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -2091,14 +2091,14 @@ void Node::string_replace_all(Utf16String string) } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#fragment-serializing-algorithm-steps -WebIDL::ExceptionOr Node::serialize_fragment(HTML::RequireWellFormed require_well_formed, FragmentSerializationMode fragment_serialization_mode) const +WebIDL::ExceptionOr Node::serialize_fragment(HTML::RequireWellFormed require_well_formed, FragmentSerializationMode fragment_serialization_mode) const { // 1. Let context document be the value of node's node document. auto const& context_document = document(); // 2. If context document is an HTML document, return the result of HTML fragment serialization algorithm with node, false, and « ». if (context_document.is_html_document()) - return HTML::HTMLParser::serialize_html_fragment(*this, HTML::HTMLParser::SerializableShadowRoots::No, {}, fragment_serialization_mode); + return Utf16String::from_utf8(HTML::HTMLParser::serialize_html_fragment(*this, HTML::HTMLParser::SerializableShadowRoots::No, {}, fragment_serialization_mode)); // 3. Return the XML serialization of node given require well-formed. // AD-HOC: XML serialization algorithm returns the "outer" XML serialization of the node. @@ -2109,9 +2109,9 @@ WebIDL::ExceptionOr Node::serialize_fragment(HTML::RequireWellFormed req auto child_markup = TRY(HTML::serialize_node_to_xml_string(*child, require_well_formed)); markup.append(child_markup.bytes_as_string_view()); } - return MUST(markup.to_string()); + return Utf16String::from_utf8(MUST(markup.to_string())); } - return HTML::serialize_node_to_xml_string(*this, require_well_formed); + return Utf16String::from_utf8(TRY(HTML::serialize_node_to_xml_string(*this, require_well_formed))); } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#unsafely-set-html diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 1d3b402dc1..37bfc3c1d1 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -403,7 +403,7 @@ public: [[nodiscard]] UniqueNodeID unique_id() const { return m_unique_id; } static Node* from_unique_id(UniqueNodeID); - WebIDL::ExceptionOr serialize_fragment(HTML::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const; + WebIDL::ExceptionOr serialize_fragment(HTML::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const; WebIDL::ExceptionOr unsafely_set_html(Element&, StringView); diff --git a/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Libraries/LibWeb/DOM/ShadowRoot.cpp index 2878938130..aad25ba940 100644 --- a/Libraries/LibWeb/DOM/ShadowRoot.cpp +++ b/Libraries/LibWeb/DOM/ShadowRoot.cpp @@ -65,7 +65,7 @@ EventTarget* ShadowRoot::get_parent(Event const& event) // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml WebIDL::ExceptionOr ShadowRoot::inner_html() const { - return serialize_fragment(HTML::RequireWellFormed::Yes); + return TRY(serialize_fragment(HTML::RequireWellFormed::Yes)).to_utf8_but_should_be_ported_to_utf16(); } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 5b89dc65c1..3c8da03455 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1103,7 +1103,7 @@ void HTMLInputElement::create_text_input_shadow_tree() padding: 0; cursor: default; )~~~"_string)); - MUST(up_button->set_inner_html(""sv)); + MUST(up_button->set_inner_html(""_utf16)); MUST(element->append_child(up_button)); auto mouseup_callback_function = JS::NativeFunction::create( @@ -1135,7 +1135,7 @@ void HTMLInputElement::create_text_input_shadow_tree() padding: 0; cursor: default; )~~~"_string)); - MUST(down_button->set_inner_html(""sv)); + MUST(down_button->set_inner_html(""_utf16)); MUST(element->append_child(down_button)); auto down_callback_function = JS::NativeFunction::create( diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 5de6a60fc4..d50d3264ab 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -612,7 +612,7 @@ void HTMLSelectElement::create_shadow_tree_if_needed() height: 16px; margin-left: 4px; )~~~"_string)); - MUST(m_chevron_icon_element->set_inner_html(chevron_svg)); + MUST(m_chevron_icon_element->set_inner_html(Utf16String::from_utf8(chevron_svg))); MUST(border->append_child(*m_chevron_icon_element)); update_inner_text_element(); diff --git a/Libraries/LibWeb/TrustedTypes/InjectionSink.h b/Libraries/LibWeb/TrustedTypes/InjectionSink.h index 5c6ad5c9dc..7847dc64e9 100644 --- a/Libraries/LibWeb/TrustedTypes/InjectionSink.h +++ b/Libraries/LibWeb/TrustedTypes/InjectionSink.h @@ -21,6 +21,10 @@ namespace Web::TrustedTypes { __ENUMERATE_INJECTION_SINKS(Documentwrite, "Document write") \ __ENUMERATE_INJECTION_SINKS(Documentwriteln, "Document writeln") \ __ENUMERATE_INJECTION_SINKS(DocumentexecCommand, "Document execCommand") \ + __ENUMERATE_INJECTION_SINKS(ElementinnerHTML, "Element innerHTML") \ + __ENUMERATE_INJECTION_SINKS(ElementinsertAdjacentHTML, "Element insertAdjacentHTML") \ + __ENUMERATE_INJECTION_SINKS(ElementouterHTML, "Element outerHTML") \ + __ENUMERATE_INJECTION_SINKS(ElementsetHTMLUnsafe, "Element setHTMLUnsafe") \ __ENUMERATE_INJECTION_SINKS(Function, "Function") \ __ENUMERATE_INJECTION_SINKS(HTMLIFrameElementsrcdoc, "HTMLIFrameElement srcdoc") \ __ENUMERATE_INJECTION_SINKS(HTMLScriptElementinnerText, "HTMLScriptElement innerText") \ diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 2270472156..1b407dab0f 100644 --- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -573,7 +573,7 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optionalhas>()) { auto string_serialized_document = TRY(body->get>().cell()->serialize_fragment(HTML::RequireWellFormed::No)); - m_request_body = Fetch::Infrastructure::byte_sequence_as_body(realm, string_serialized_document.bytes()); + m_request_body = Fetch::Infrastructure::byte_sequence_as_body(realm, string_serialized_document.to_utf8().bytes()); } // 3. Otherwise: else { diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index 617fd99104..50887cf49a 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -661,19 +661,19 @@ void ConnectionFromClient::get_dom_node_inner_html(u64 page_id, Web::UniqueNodeI if (!dom_node) return; - String html; + Utf16String html; if (dom_node->is_element()) { auto const& element = static_cast(*dom_node); - html = element.inner_html().release_value_but_fixme_should_propagate_errors(); + html = element.inner_html().release_value_but_fixme_should_propagate_errors().get(); } else if (dom_node->is_text() || dom_node->is_comment()) { auto const& character_data = static_cast(*dom_node); - html = character_data.data().to_utf8_but_should_be_ported_to_utf16(); + html = character_data.data(); } else { return; } - async_did_get_dom_node_html(page_id, html); + async_did_get_dom_node_html(page_id, html.to_utf8_but_should_be_ported_to_utf16()); } void ConnectionFromClient::get_dom_node_outer_html(u64 page_id, Web::UniqueNodeID node_id) @@ -682,19 +682,19 @@ void ConnectionFromClient::get_dom_node_outer_html(u64 page_id, Web::UniqueNodeI if (!dom_node) return; - String html; + Utf16String html; if (dom_node->is_element()) { auto const& element = static_cast(*dom_node); - html = element.outer_html().release_value_but_fixme_should_propagate_errors(); + html = element.outer_html().release_value_but_fixme_should_propagate_errors().get(); } else if (dom_node->is_text() || dom_node->is_comment()) { auto const& character_data = static_cast(*dom_node); - html = character_data.data().to_utf8_but_should_be_ported_to_utf16(); + html = character_data.data(); } else { return; } - async_did_get_dom_node_html(page_id, html); + async_did_get_dom_node_html(page_id, html.to_utf8_but_should_be_ported_to_utf16()); } void ConnectionFromClient::set_dom_node_outer_html(u64 page_id, Web::UniqueNodeID node_id, String html) @@ -707,7 +707,7 @@ void ConnectionFromClient::set_dom_node_outer_html(u64 page_id, Web::UniqueNodeI if (dom_node->is_element()) { auto& element = static_cast(*dom_node); - element.set_outer_html(html).release_value_but_fixme_should_propagate_errors(); + element.set_outer_html(Utf16String::from_utf8(html)).release_value_but_fixme_should_propagate_errors(); } else if (dom_node->is_text() || dom_node->is_comment()) { auto& character_data = static_cast(*dom_node); character_data.set_data(Utf16String::from_utf8(html)); diff --git a/Services/WebContent/WebDriverConnection.cpp b/Services/WebContent/WebDriverConnection.cpp index 7171316379..5f7db813d0 100644 --- a/Services/WebContent/WebDriverConnection.cpp +++ b/Services/WebContent/WebDriverConnection.cpp @@ -1749,14 +1749,14 @@ Web::WebDriver::Response WebDriverConnection::element_clear_impl(StringView elem // https://w3c.github.io/webdriver/#dfn-clear-a-content-editable-element auto clear_content_editable_element = [&](Web::DOM::Element& element) { // 1. If element's innerHTML IDL attribute is an empty string do nothing and return. - if (auto result = element.inner_html(); result.is_error() || result.value().is_empty()) + if (auto result = element.inner_html(); result.is_error() || result.value().get().is_empty()) return; // 2. Run the focusing steps for element. Web::HTML::run_focusing_steps(&element); // 3. Set element's innerHTML IDL attribute to an empty string. - (void)element.set_inner_html({}); + (void)element.set_inner_html(""_utf16); // 4. Run the unfocusing steps for the element. Web::HTML::run_unfocusing_steps(&element); @@ -2028,7 +2028,7 @@ Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source() // 2. Try to handle any user prompts with session. handle_any_user_prompts([this]() { auto* document = current_browsing_context().active_document(); - Optional source; + Optional source; // 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only // child is the document element providing true for the require well-formed flag. If this causes an exception @@ -2042,7 +2042,7 @@ Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source() source = MUST(document->serialize_fragment(Web::HTML::RequireWellFormed::No)); // 5. Return success with data source. - async_driver_execution_complete({ source.release_value() }); + async_driver_execution_complete({ source.release_value().to_utf8_but_should_be_ported_to_utf16() }); }); return JsonValue {};