mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Amend Element interface to make it compatible with TrustedTypes
This commit is contained in:
parent
1368744d33
commit
db41ea8117
|
|
@ -89,6 +89,7 @@
|
||||||
#include <LibWeb/Painting/ViewportPaintable.h>
|
#include <LibWeb/Painting/ViewportPaintable.h>
|
||||||
#include <LibWeb/SVG/SVGAElement.h>
|
#include <LibWeb/SVG/SVGAElement.h>
|
||||||
#include <LibWeb/Selection/Selection.h>
|
#include <LibWeb/Selection/Selection.h>
|
||||||
|
#include <LibWeb/TrustedTypes/RequireTrustedTypesForDirective.h>
|
||||||
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
|
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
|
||||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||||
#include <LibWeb/WebIDL/DOMException.h>
|
#include <LibWeb/WebIDL/DOMException.h>
|
||||||
|
|
@ -370,7 +371,7 @@ WebIDL::ExceptionOr<void> Element::set_attribute_ns(Optional<FlyString> const& n
|
||||||
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name, ValidationContext::Element));
|
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
|
// 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(
|
auto const verified_value = TRY(TrustedTypes::get_trusted_types_compliant_attribute_value(
|
||||||
extracted_qualified_name.local_name(),
|
extracted_qualified_name.local_name(),
|
||||||
extracted_qualified_name.namespace_().has_value() ? Utf16String::from_utf8(extracted_qualified_name.namespace_().value()) : Optional<Utf16String>(),
|
extracted_qualified_name.namespace_().has_value() ? Utf16String::from_utf8(extracted_qualified_name.namespace_().value()) : Optional<Utf16String>(),
|
||||||
|
|
@ -1057,15 +1058,22 @@ WebIDL::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml
|
||||||
WebIDL::ExceptionOr<void> Element::set_inner_html(StringView value)
|
WebIDL::ExceptionOr<void> 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.
|
// 2. Let context be this.
|
||||||
DOM::Node* context = 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.
|
// 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString.
|
||||||
auto fragment = TRY(as<Element>(*context).parse_fragment(value));
|
auto fragment = TRY(as<Element>(*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).
|
// 4. If context is a template element, then set context to the template element's template contents (a DocumentFragment).
|
||||||
auto* template_element = as_if<HTML::HTMLTemplateElement>(*context);
|
auto* template_element = as_if<HTML::HTMLTemplateElement>(*context);
|
||||||
|
|
@ -1089,9 +1097,9 @@ WebIDL::ExceptionOr<void> Element::set_inner_html(StringView value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml
|
||||||
WebIDL::ExceptionOr<String> Element::inner_html() const
|
WebIDL::ExceptionOr<TrustedTypes::TrustedHTMLOrString> Element::inner_html() const
|
||||||
{
|
{
|
||||||
return serialize_fragment(HTML::RequireWellFormed::Yes);
|
return TRY(serialize_fragment(HTML::RequireWellFormed::Yes));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Element::is_focused() const
|
bool Element::is_focused() const
|
||||||
|
|
@ -2098,15 +2106,22 @@ WebIDL::ExceptionOr<GC::Ref<DOM::DocumentFragment>> Element::parse_fragment(Stri
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml
|
||||||
WebIDL::ExceptionOr<String> Element::outer_html() const
|
WebIDL::ExceptionOr<TrustedTypes::TrustedHTMLOrString> 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
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml
|
||||||
WebIDL::ExceptionOr<void> Element::set_outer_html(String const& value)
|
WebIDL::ExceptionOr<void> 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.
|
// 2. Let parent be this's parent.
|
||||||
auto* parent = this->parent();
|
auto* parent = this->parent();
|
||||||
|
|
@ -2123,8 +2138,8 @@ WebIDL::ExceptionOr<void> Element::set_outer_html(String const& value)
|
||||||
if (parent->is_document_fragment())
|
if (parent->is_document_fragment())
|
||||||
parent = TRY(create_element(document(), HTML::TagNames::body, Namespace::HTML));
|
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.
|
// 6. Let fragment be the result of invoking the fragment parsing algorithm steps given parent and compliantString.
|
||||||
auto fragment = TRY(as<Element>(*parent).parse_fragment(value));
|
auto fragment = TRY(as<Element>(*parent).parse_fragment(compliant_string.to_utf8_but_should_be_ported_to_utf16()));
|
||||||
|
|
||||||
// 6. Replace this with fragment within this's parent.
|
// 6. Replace this with fragment within this's parent.
|
||||||
TRY(parent->replace_child(fragment, *this));
|
TRY(parent->replace_child(fragment, *this));
|
||||||
|
|
@ -2133,12 +2148,21 @@ WebIDL::ExceptionOr<void> Element::set_outer_html(String const& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#the-insertadjacenthtml()-method
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#the-insertadjacenthtml()-method
|
||||||
WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position, String const& string)
|
WebIDL::ExceptionOr<void> 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<Node> context;
|
GC::Ptr<Node> 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 "beforebegin"
|
||||||
// - If position is an ASCII case-insensitive match for the string "afterend"
|
// - If position is an ASCII case-insensitive match for the string "afterend"
|
||||||
if (position.equals_ignoring_ascii_case("beforebegin"sv)
|
if (position.equals_ignoring_ascii_case("beforebegin"sv)
|
||||||
|
|
@ -2163,7 +2187,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position,
|
||||||
return WebIDL::SyntaxError::create(realm(), "insertAdjacentHTML: invalid position argument"_utf16);
|
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 node document is an HTML document,
|
||||||
// - context's local name is "html", and
|
// - context's local name is "html", and
|
||||||
// - context's namespace is the HTML namespace;
|
// - context's namespace is the HTML namespace;
|
||||||
|
|
@ -2175,10 +2199,10 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position,
|
||||||
context = TRY(create_element(document(), HTML::TagNames::body, Namespace::HTML));
|
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.
|
// 5. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString.
|
||||||
auto fragment = TRY(as<Element>(*context).parse_fragment(string));
|
auto fragment = TRY(as<Element>(*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 is an ASCII case-insensitive match for the string "beforebegin"
|
||||||
if (position.equals_ignoring_ascii_case("beforebegin"sv)) {
|
if (position.equals_ignoring_ascii_case("beforebegin"sv)) {
|
||||||
|
|
@ -3936,17 +3960,24 @@ WebIDL::ExceptionOr<String> Element::get_html(GetHTMLOptions const& options) con
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-sethtmlunsafe
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-sethtmlunsafe
|
||||||
WebIDL::ExceptionOr<void> Element::set_html_unsafe(StringView html)
|
WebIDL::ExceptionOr<void> 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.
|
// 2. Let target be this's template contents if this is a template element; otherwise this.
|
||||||
DOM::Node* target = this;
|
DOM::Node* target = this;
|
||||||
if (is<HTML::HTMLTemplateElement>(*this))
|
if (is<HTML::HTMLTemplateElement>(*this))
|
||||||
target = as<HTML::HTMLTemplateElement>(*this).content().ptr();
|
target = as<HTML::HTMLTemplateElement>(*this).content().ptr();
|
||||||
|
|
||||||
// 3. Unsafe set HTML given target, this, and compliantHTML. FIXME: Use compliantHTML.
|
// 3. Unsafe set HTML given target, this, and compliantHTML.
|
||||||
TRY(target->unsafely_set_html(*this, html));
|
TRY(target->unsafely_set_html(*this, compliant_html.to_utf8_but_should_be_ported_to_utf16()));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -239,17 +239,17 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] GC::Ptr<Element const> element_to_inherit_style_from(Optional<CSS::PseudoElement>) const;
|
[[nodiscard]] GC::Ptr<Element const> element_to_inherit_style_from(Optional<CSS::PseudoElement>) const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> inner_html() const;
|
WebIDL::ExceptionOr<TrustedTypes::TrustedHTMLOrString> inner_html() const;
|
||||||
WebIDL::ExceptionOr<void> set_inner_html(StringView);
|
WebIDL::ExceptionOr<void> set_inner_html(TrustedTypes::TrustedHTMLOrString const&);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> set_html_unsafe(StringView);
|
WebIDL::ExceptionOr<void> set_html_unsafe(TrustedTypes::TrustedHTMLOrString const&);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> get_html(GetHTMLOptions const&) const;
|
WebIDL::ExceptionOr<String> get_html(GetHTMLOptions const&) const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> insert_adjacent_html(String const& position, String const&);
|
WebIDL::ExceptionOr<void> insert_adjacent_html(String const& position, TrustedTypes::TrustedHTMLOrString const&);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> outer_html() const;
|
WebIDL::ExceptionOr<TrustedTypes::TrustedHTMLOrString> outer_html() const;
|
||||||
WebIDL::ExceptionOr<void> set_outer_html(String const&);
|
WebIDL::ExceptionOr<void> set_outer_html(TrustedTypes::TrustedHTMLOrString const&);
|
||||||
|
|
||||||
bool is_focused() const;
|
bool is_focused() const;
|
||||||
bool is_active() const;
|
bool is_active() const;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#import <Geometry/DOMRectList.idl>
|
#import <Geometry/DOMRectList.idl>
|
||||||
#import <HTML/HTMLSlotElement.idl>
|
#import <HTML/HTMLSlotElement.idl>
|
||||||
#import <HTML/Window.idl>
|
#import <HTML/Window.idl>
|
||||||
|
#import <TrustedTypes/TrustedHTML.idl>
|
||||||
#import <TrustedTypes/TrustedTypePolicy.idl>
|
#import <TrustedTypes/TrustedTypePolicy.idl>
|
||||||
|
|
||||||
enum ScrollLogicalPosition { "start", "center", "end", "nearest" };
|
enum ScrollLogicalPosition { "start", "center", "end", "nearest" };
|
||||||
|
|
@ -109,18 +110,14 @@ interface Element : Node {
|
||||||
readonly attribute double currentCSSZoom;
|
readonly attribute double currentCSSZoom;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
|
// 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((TrustedHTML or Utf16DOMString) html);
|
||||||
[CEReactions] undefined setHTMLUnsafe(DOMString html);
|
|
||||||
DOMString getHTML(optional GetHTMLOptions options = {});
|
DOMString getHTML(optional GetHTMLOptions options = {});
|
||||||
|
|
||||||
// FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
|
[CEReactions, LegacyNullToEmptyString] attribute (TrustedHTML or Utf16DOMString) innerHTML;
|
||||||
[CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML;
|
|
||||||
|
|
||||||
// FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) outerHTML;
|
[CEReactions, LegacyNullToEmptyString] attribute (TrustedHTML or Utf16DOMString) outerHTML;
|
||||||
[CEReactions, LegacyNullToEmptyString] attribute DOMString outerHTML;
|
|
||||||
|
|
||||||
// FIXME: [CEReactions] undefined insertAdjacentHTML(DOMString position, (TrustedHTML or DOMString) string);
|
[CEReactions] undefined insertAdjacentHTML(DOMString position, (TrustedHTML or Utf16DOMString) text);
|
||||||
[CEReactions] undefined insertAdjacentHTML(DOMString position, DOMString text);
|
|
||||||
|
|
||||||
// https://w3c.github.io/pointerevents/#extensions-to-the-element-interface
|
// https://w3c.github.io/pointerevents/#extensions-to-the-element-interface
|
||||||
undefined setPointerCapture(long pointerId);
|
undefined setPointerCapture(long pointerId);
|
||||||
|
|
|
||||||
|
|
@ -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
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#fragment-serializing-algorithm-steps
|
||||||
WebIDL::ExceptionOr<String> Node::serialize_fragment(HTML::RequireWellFormed require_well_formed, FragmentSerializationMode fragment_serialization_mode) const
|
WebIDL::ExceptionOr<Utf16String> 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.
|
// 1. Let context document be the value of node's node document.
|
||||||
auto const& context_document = 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 « ».
|
// 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())
|
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.
|
// 3. Return the XML serialization of node given require well-formed.
|
||||||
// AD-HOC: XML serialization algorithm returns the "outer" XML serialization of the node.
|
// AD-HOC: XML serialization algorithm returns the "outer" XML serialization of the node.
|
||||||
|
|
@ -2109,9 +2109,9 @@ WebIDL::ExceptionOr<String> Node::serialize_fragment(HTML::RequireWellFormed req
|
||||||
auto child_markup = TRY(HTML::serialize_node_to_xml_string(*child, require_well_formed));
|
auto child_markup = TRY(HTML::serialize_node_to_xml_string(*child, require_well_formed));
|
||||||
markup.append(child_markup.bytes_as_string_view());
|
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
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#unsafely-set-html
|
||||||
|
|
|
||||||
|
|
@ -403,7 +403,7 @@ public:
|
||||||
[[nodiscard]] UniqueNodeID unique_id() const { return m_unique_id; }
|
[[nodiscard]] UniqueNodeID unique_id() const { return m_unique_id; }
|
||||||
static Node* from_unique_id(UniqueNodeID);
|
static Node* from_unique_id(UniqueNodeID);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> serialize_fragment(HTML::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const;
|
WebIDL::ExceptionOr<Utf16String> serialize_fragment(HTML::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> unsafely_set_html(Element&, StringView);
|
WebIDL::ExceptionOr<void> unsafely_set_html(Element&, StringView);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ EventTarget* ShadowRoot::get_parent(Event const& event)
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml
|
||||||
WebIDL::ExceptionOr<String> ShadowRoot::inner_html() const
|
WebIDL::ExceptionOr<String> 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
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml
|
||||||
|
|
|
||||||
|
|
@ -1103,7 +1103,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
||||||
padding: 0;
|
padding: 0;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
)~~~"_string));
|
)~~~"_string));
|
||||||
MUST(up_button->set_inner_html("<svg style=\"width: 1em; height: 1em;\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z\" /></svg>"sv));
|
MUST(up_button->set_inner_html("<svg style=\"width: 1em; height: 1em;\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z\" /></svg>"_utf16));
|
||||||
MUST(element->append_child(up_button));
|
MUST(element->append_child(up_button));
|
||||||
|
|
||||||
auto mouseup_callback_function = JS::NativeFunction::create(
|
auto mouseup_callback_function = JS::NativeFunction::create(
|
||||||
|
|
@ -1135,7 +1135,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
||||||
padding: 0;
|
padding: 0;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
)~~~"_string));
|
)~~~"_string));
|
||||||
MUST(down_button->set_inner_html("<svg style=\"width: 1em; height: 1em;\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z\" /></svg>"sv));
|
MUST(down_button->set_inner_html("<svg style=\"width: 1em; height: 1em;\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z\" /></svg>"_utf16));
|
||||||
MUST(element->append_child(down_button));
|
MUST(element->append_child(down_button));
|
||||||
|
|
||||||
auto down_callback_function = JS::NativeFunction::create(
|
auto down_callback_function = JS::NativeFunction::create(
|
||||||
|
|
|
||||||
|
|
@ -612,7 +612,7 @@ void HTMLSelectElement::create_shadow_tree_if_needed()
|
||||||
height: 16px;
|
height: 16px;
|
||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
)~~~"_string));
|
)~~~"_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));
|
MUST(border->append_child(*m_chevron_icon_element));
|
||||||
|
|
||||||
update_inner_text_element();
|
update_inner_text_element();
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ namespace Web::TrustedTypes {
|
||||||
__ENUMERATE_INJECTION_SINKS(Documentwrite, "Document write") \
|
__ENUMERATE_INJECTION_SINKS(Documentwrite, "Document write") \
|
||||||
__ENUMERATE_INJECTION_SINKS(Documentwriteln, "Document writeln") \
|
__ENUMERATE_INJECTION_SINKS(Documentwriteln, "Document writeln") \
|
||||||
__ENUMERATE_INJECTION_SINKS(DocumentexecCommand, "Document execCommand") \
|
__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(Function, "Function") \
|
||||||
__ENUMERATE_INJECTION_SINKS(HTMLIFrameElementsrcdoc, "HTMLIFrameElement srcdoc") \
|
__ENUMERATE_INJECTION_SINKS(HTMLIFrameElementsrcdoc, "HTMLIFrameElement srcdoc") \
|
||||||
__ENUMERATE_INJECTION_SINKS(HTMLScriptElementinnerText, "HTMLScriptElement innerText") \
|
__ENUMERATE_INJECTION_SINKS(HTMLScriptElementinnerText, "HTMLScriptElement innerText") \
|
||||||
|
|
|
||||||
|
|
@ -573,7 +573,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
|
||||||
// 2. If body is a Document, then set this’s request body to body, serialized, converted, and UTF-8 encoded.
|
// 2. If body is a Document, then set this’s request body to body, serialized, converted, and UTF-8 encoded.
|
||||||
if (body->has<GC::Root<DOM::Document>>()) {
|
if (body->has<GC::Root<DOM::Document>>()) {
|
||||||
auto string_serialized_document = TRY(body->get<GC::Root<DOM::Document>>().cell()->serialize_fragment(HTML::RequireWellFormed::No));
|
auto string_serialized_document = TRY(body->get<GC::Root<DOM::Document>>().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:
|
// 3. Otherwise:
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -661,19 +661,19 @@ void ConnectionFromClient::get_dom_node_inner_html(u64 page_id, Web::UniqueNodeI
|
||||||
if (!dom_node)
|
if (!dom_node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String html;
|
Utf16String html;
|
||||||
|
|
||||||
if (dom_node->is_element()) {
|
if (dom_node->is_element()) {
|
||||||
auto const& element = static_cast<Web::DOM::Element const&>(*dom_node);
|
auto const& element = static_cast<Web::DOM::Element const&>(*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<Utf16String>();
|
||||||
} else if (dom_node->is_text() || dom_node->is_comment()) {
|
} else if (dom_node->is_text() || dom_node->is_comment()) {
|
||||||
auto const& character_data = static_cast<Web::DOM::CharacterData const&>(*dom_node);
|
auto const& character_data = static_cast<Web::DOM::CharacterData const&>(*dom_node);
|
||||||
html = character_data.data().to_utf8_but_should_be_ported_to_utf16();
|
html = character_data.data();
|
||||||
} else {
|
} else {
|
||||||
return;
|
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)
|
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)
|
if (!dom_node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String html;
|
Utf16String html;
|
||||||
|
|
||||||
if (dom_node->is_element()) {
|
if (dom_node->is_element()) {
|
||||||
auto const& element = static_cast<Web::DOM::Element const&>(*dom_node);
|
auto const& element = static_cast<Web::DOM::Element const&>(*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<Utf16String>();
|
||||||
} else if (dom_node->is_text() || dom_node->is_comment()) {
|
} else if (dom_node->is_text() || dom_node->is_comment()) {
|
||||||
auto const& character_data = static_cast<Web::DOM::CharacterData const&>(*dom_node);
|
auto const& character_data = static_cast<Web::DOM::CharacterData const&>(*dom_node);
|
||||||
html = character_data.data().to_utf8_but_should_be_ported_to_utf16();
|
html = character_data.data();
|
||||||
} else {
|
} else {
|
||||||
return;
|
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)
|
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()) {
|
if (dom_node->is_element()) {
|
||||||
auto& element = static_cast<Web::DOM::Element&>(*dom_node);
|
auto& element = static_cast<Web::DOM::Element&>(*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()) {
|
} else if (dom_node->is_text() || dom_node->is_comment()) {
|
||||||
auto& character_data = static_cast<Web::DOM::CharacterData&>(*dom_node);
|
auto& character_data = static_cast<Web::DOM::CharacterData&>(*dom_node);
|
||||||
character_data.set_data(Utf16String::from_utf8(html));
|
character_data.set_data(Utf16String::from_utf8(html));
|
||||||
|
|
|
||||||
|
|
@ -1749,14 +1749,14 @@ Web::WebDriver::Response WebDriverConnection::element_clear_impl(StringView elem
|
||||||
// https://w3c.github.io/webdriver/#dfn-clear-a-content-editable-element
|
// https://w3c.github.io/webdriver/#dfn-clear-a-content-editable-element
|
||||||
auto clear_content_editable_element = [&](Web::DOM::Element& 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.
|
// 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<Utf16String>().is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 2. Run the focusing steps for element.
|
// 2. Run the focusing steps for element.
|
||||||
Web::HTML::run_focusing_steps(&element);
|
Web::HTML::run_focusing_steps(&element);
|
||||||
|
|
||||||
// 3. Set element's innerHTML IDL attribute to an empty string.
|
// 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.
|
// 4. Run the unfocusing steps for the element.
|
||||||
Web::HTML::run_unfocusing_steps(&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.
|
// 2. Try to handle any user prompts with session.
|
||||||
handle_any_user_prompts([this]() {
|
handle_any_user_prompts([this]() {
|
||||||
auto* document = current_browsing_context().active_document();
|
auto* document = current_browsing_context().active_document();
|
||||||
Optional<String> source;
|
Optional<Utf16String> source;
|
||||||
|
|
||||||
// 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only
|
// 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
|
// 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));
|
source = MUST(document->serialize_fragment(Web::HTML::RequireWellFormed::No));
|
||||||
|
|
||||||
// 5. Return success with data source.
|
// 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 {};
|
return JsonValue {};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user