diff options
author | Andreas Kling <kling@serenityos.org> | 2021-12-05 15:33:49 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-06 19:22:16 +0100 |
commit | 58b99df16dda1c5b4f81a30239f3bb5bb04ded6b (patch) | |
tree | 45598a7365820f662250897e7ec459e51010a7e9 /Userland/Libraries/LibWeb | |
parent | e8b85b13e2522d87a2514ea953fc0c80cfbcfee9 (diff) | |
download | serenity-58b99df16dda1c5b4f81a30239f3bb5bb04ded6b.zip |
LibWeb: Make StyleSheet::m_parent_style_sheet a WeakPtr
It's not safe for this to be a raw pointer, as the child can outlive the
parent.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleSheet.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleSheet.h | 5 |
3 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index 3ebe1877ce..6ce28b1735 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h @@ -18,7 +18,9 @@ namespace Web::CSS { class CSSImportRule; -class CSSStyleSheet final : public StyleSheet { +class CSSStyleSheet final + : public StyleSheet + , public Weakable<CSSStyleSheet> { public: using WrapperType = Bindings::CSSStyleSheetWrapper; diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp index bafec2d802..36c04d7702 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <LibWeb/CSS/CSSStyleSheet.h> #include <LibWeb/CSS/StyleSheet.h> #include <LibWeb/DOM/Element.h> @@ -18,4 +19,9 @@ void StyleSheet::set_owner_node(DOM::Element* element) m_owner_node = nullptr; } +void StyleSheet::set_parent_css_style_sheet(CSSStyleSheet* parent) +{ + m_parent_style_sheet = parent; +} + } diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheet.h b/Userland/Libraries/LibWeb/CSS/StyleSheet.h index 36f9e7a610..dc809624c4 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/StyleSheet.h @@ -41,7 +41,7 @@ public: void set_disabled(bool disabled) { m_disabled = disabled; } CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet; } - void set_parent_css_style_sheet(CSSStyleSheet* sheet) { m_parent_style_sheet = sheet; } + void set_parent_css_style_sheet(CSSStyleSheet*); protected: StyleSheet() = default; @@ -49,8 +49,7 @@ protected: private: WeakPtr<DOM::Element> m_owner_node; - // FIXME: Use WeakPtr. - CSSStyleSheet* m_parent_style_sheet { nullptr }; + WeakPtr<CSSStyleSheet> m_parent_style_sheet; String m_title; String m_type_string; |