From 9bb4020195b926aba777589d475b44ca259072a4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 15 Jun 2020 20:25:25 +0200 Subject: LibWeb: Don't load stylesheets with rel="alternate" We're not supposed to load these by default. Alternate stylesheets can be offered in a menu or something, if the user is interested. --- Libraries/LibWeb/DOM/HTMLLinkElement.cpp | 16 +++++++++++++++- Libraries/LibWeb/DOM/HTMLLinkElement.h | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/DOM/HTMLLinkElement.cpp b/Libraries/LibWeb/DOM/HTMLLinkElement.cpp index 73ccf247b5..40779cafde 100644 --- a/Libraries/LibWeb/DOM/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLLinkElement.cpp @@ -47,7 +47,7 @@ void HTMLLinkElement::inserted_into(Node& node) { HTMLElement::inserted_into(node); - if (rel().split_view(' ').contains_slow("stylesheet")) + if (m_relationship & Relationship::Stylesheet && !(m_relationship & Relationship::Alternate)) load_stylesheet(document().complete_url(href())); } @@ -87,4 +87,18 @@ void HTMLLinkElement::load_stylesheet(const URL& url) set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request)); } +void HTMLLinkElement::parse_attribute(const FlyString& name, const String& value) +{ + if (name == HTML::AttributeNames::rel) { + m_relationship = 0; + auto parts = value.split_view(' '); + for (auto& part : parts) { + if (part == "stylesheet") + m_relationship |= Relationship::Stylesheet; + else if (part == "alternate") + m_relationship |= Relationship::Alternate; + } + } +} + } diff --git a/Libraries/LibWeb/DOM/HTMLLinkElement.h b/Libraries/LibWeb/DOM/HTMLLinkElement.h index c2fc343bba..07eb119a7b 100644 --- a/Libraries/LibWeb/DOM/HTMLLinkElement.h +++ b/Libraries/LibWeb/DOM/HTMLLinkElement.h @@ -49,8 +49,18 @@ private: virtual void resource_did_fail() override; virtual void resource_did_load() override; + void parse_attribute(const FlyString&, const String&) override; + void load_stylesheet(const URL&); + struct Relationship { + enum { + Alternate = 1 << 0, + Stylesheet = 1 << 1, + }; + }; + + unsigned m_relationship { 0 }; RefPtr m_style_sheet; }; -- cgit v1.2.3