Skip to content

Truly independent web browser

LibWeb: Keep the style attribute's pending CSP check in Element

Andreas Kling85d3a7141e64
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 5e05df9da4e..a0d52036931 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -3259,20 +3259,18 @@ static void prefetch_inline_style_image_resources(CSS::CSSStyleProperties const&
void Element::clone_inline_style_from(Element const& source)
{
// NB: A source whose style attribute still awaits its check leaves the copy to make that check once connected.
- auto const* source_rare_data = source.element_rare_data();
- if (!m_inline_style || !source.m_inline_style || (source_rare_data && source_rare_data->style_attribute_awaits_content_security_policy_check))
+ if (!m_inline_style || !source.m_inline_style || source.m_style_attribute_awaits_content_security_policy_check)
return;
m_inline_style->set_declarations_from(*source.m_inline_style);
- if (auto* rare_data = element_rare_data())
- rare_data->style_attribute_awaits_content_security_policy_check = false;
+ m_style_attribute_awaits_content_security_policy_check = false;
}
void Element::inserted()
{
Base::inserted();
- if (auto* rare_data = element_rare_data(); rare_data && rare_data->style_attribute_awaits_content_security_policy_check && is_connected()) {
- rare_data->style_attribute_awaits_content_security_policy_check = false;
+ if (m_style_attribute_awaits_content_security_policy_check && is_connected()) {
+ m_style_attribute_awaits_content_security_policy_check = false;
if (auto value = attribute(HTML::AttributeNames::style); value.has_value() && m_inline_style) {
if (style_attribute_is_blocked_by_content_security_policy(*this, value->utf16_view()))
m_inline_style->set_declarations_from_text({});
@@ -6595,12 +6593,11 @@ void Element::attribute_changed(Utf16FlyString const& local_name, Optional<Utf16
// into it, and are styled by the user agent rather than the document. So the check is made when an
// element that is not connected becomes connected, and the resources its declarations use are fetched then.
if (value.has_value() && !is_connected()) {
- ensure_element_rare_data().style_attribute_awaits_content_security_policy_check = true;
+ m_style_attribute_awaits_content_security_policy_check = true;
m_inline_style->set_declarations_from_text(*value);
return;
}
- if (auto* rare_data = element_rare_data())
- rare_data->style_attribute_awaits_content_security_policy_check = false;
+ m_style_attribute_awaits_content_security_policy_check = false;
if (!value.has_value()) {
m_inline_style->set_declarations_from_text({});
return;
diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h
index 6ee879b5dc2..e043da33991 100644
--- a/Libraries/LibWeb/DOM/Element.h
+++ b/Libraries/LibWeb/DOM/Element.h
@@ -1119,6 +1119,9 @@ private:
bool m_has_name : 1 { false };
mutable bool m_style_attribute_is_dirty : 1 { false };
bool m_is_in_set_of_elements_with_rendered_text : 1 { false };
+ // Whether the style attribute was set while the element was not connected, so that whether Content Security
+ // Policy blocks it is decided when the element is inserted.
+ bool m_style_attribute_awaits_content_security_policy_check : 1 { false };
// The child indices the element remembers, or zero for those not counted yet, and the generation of its parent's
// child list they were counted in; zero for none.
diff --git a/Libraries/LibWeb/DOM/ElementRareData.h b/Libraries/LibWeb/DOM/ElementRareData.h
index f39732bc2ab..c2be3cf19d2 100644
--- a/Libraries/LibWeb/DOM/ElementRareData.h
+++ b/Libraries/LibWeb/DOM/ElementRareData.h
@@ -93,10 +93,6 @@ struct Element::RareData
// flag is set.
bool had_duplicate_attribute_during_tokenization { false };
- // Whether the style attribute was set while the element was not connected, so that whether Content Security
- // Policy blocks it is decided when the element is inserted.
- bool style_attribute_awaits_content_security_policy_check { false };
-
// https://drafts.csswg.org/css-contain/#proximity-to-the-viewport
ProximityToTheViewport proximity_to_the_viewport { ProximityToTheViewport::NotDetermined };