diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 0500e1989a0..39cb95964c6 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -37,13 +37,13 @@ WebIDL::ExceptionOr> CSSStyleSheet::construct_impl(JS::Re // 2. Set sheet’s location to the base URL of the associated Document for the current principal global object. auto associated_document = as(HTML::current_principal_global_object()).document(); - sheet->set_location(associated_document->base_url().to_string()); + sheet->set_location(associated_document->base_url()); // 3. Set sheet’s stylesheet base URL to the baseURL attribute value from options. if (options.has_value() && options->base_url.has_value()) { Optional sheet_location_url; if (sheet->location().has_value()) - sheet_location_url = URL::Parser::basic_parse(sheet->location().release_value()); + sheet_location_url = sheet->location().release_value(); // AD-HOC: This isn't explicitly mentioned in the specification, but multiple modern browsers do this. Optional url = sheet->location().has_value() ? sheet_location_url->complete_url(options->base_url.value()) : URL::Parser::basic_parse(options->base_url.value()); @@ -100,7 +100,7 @@ CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, MediaList& me , m_rules(&rules) { if (location.has_value()) - set_location(location->to_string()); + set_location(move(location)); for (auto& rule : *m_rules) rule->set_parent_style_sheet(this); diff --git a/Libraries/LibWeb/CSS/StyleSheet.cpp b/Libraries/LibWeb/CSS/StyleSheet.cpp index 2d908e00c15..f1387c98b47 100644 --- a/Libraries/LibWeb/CSS/StyleSheet.cpp +++ b/Libraries/LibWeb/CSS/StyleSheet.cpp @@ -27,6 +27,13 @@ void StyleSheet::visit_edges(Cell::Visitor& visitor) visitor.visit(m_media); } +Optional StyleSheet::href() const +{ + if (m_location.has_value()) + return m_location->to_string(); + return {}; +} + void StyleSheet::set_owner_node(DOM::Element* element) { m_owner_node = element; diff --git a/Libraries/LibWeb/CSS/StyleSheet.h b/Libraries/LibWeb/CSS/StyleSheet.h index 3e73f0e3f75..8f03bcdd7e0 100644 --- a/Libraries/LibWeb/CSS/StyleSheet.h +++ b/Libraries/LibWeb/CSS/StyleSheet.h @@ -13,6 +13,7 @@ namespace Web::CSS { +// https://drafts.csswg.org/cssom-1/#the-stylesheet-interface class StyleSheet : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(StyleSheet, Bindings::PlatformObject); @@ -24,10 +25,10 @@ public: DOM::Element* owner_node() { return m_owner_node; } void set_owner_node(DOM::Element*); - Optional href() const { return m_location; } + Optional href() const; - Optional location() const { return m_location; } - void set_location(Optional location) { m_location = move(location); } + Optional location() const { return m_location; } + void set_location(Optional location) { m_location = move(location); } String title() const { return m_title; } Optional title_for_bindings() const; @@ -67,7 +68,7 @@ private: GC::Ptr m_owner_node; GC::Ptr m_parent_style_sheet; - Optional m_location; + Optional m_location; String m_title; String m_type_string; diff --git a/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Libraries/LibWeb/CSS/StyleSheetList.cpp index e7e204f8599..18c49b2db11 100644 --- a/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -60,7 +60,7 @@ void StyleSheetList::add_a_css_style_sheet(CSS::CSSStyleSheet& sheet) } // https://www.w3.org/TR/cssom/#create-a-css-style-sheet -void StyleSheetList::create_a_css_style_sheet(String type, DOM::Element* owner_node, String media, String title, bool alternate, bool origin_clean, Optional location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet) +void StyleSheetList::create_a_css_style_sheet(String type, DOM::Element* owner_node, String media, String title, bool alternate, bool origin_clean, Optional location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet) { // 1. Create a new CSS style sheet object and set its properties as specified. // FIXME: We receive `sheet` from the caller already. This is weird. diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index e8a3d0b437e..759c4dbd891 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -5879,7 +5879,7 @@ void Document::for_each_active_css_style_sheet(Function find_style_sheet_with_url(String const& url, CSS::CSSStyleSheet& style_sheet) { - if (style_sheet.location() == url) + if (style_sheet.href() == url) return style_sheet; for (auto& import_rule : style_sheet.import_rules()) { diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index d5242517c4c..a37b421c82c 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -492,7 +492,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru if (m_loaded_style_sheet) { Optional location; if (!response.url_list().is_empty()) - location = response.url_list().first().to_string(); + location = response.url_list().first(); document_or_shadow_root_style_sheets().create_a_css_style_sheet( "text/css"_string, diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp index 57b57b7ce55..1749b33db44 100644 --- a/Services/WebContent/PageClient.cpp +++ b/Services/WebContent/PageClient.cpp @@ -834,8 +834,8 @@ static void gather_style_sheets(Vector& results, } if (valid) { - if (auto location = sheet.location(); location.has_value()) - identifier.url = location.release_value(); + if (auto sheet_url = sheet.href(); sheet_url.has_value()) + identifier.url = sheet_url.release_value(); identifier.rule_count = sheet.rules().length(); results.append(move(identifier));