summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-15 20:25:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-15 20:31:18 +0200
commit9bb4020195b926aba777589d475b44ca259072a4 (patch)
tree52b9b1c9481ccccbfeca07762066fe06b38e76fd
parent2f26d4c6a1ae9bfaf76787277f81e2eb7bb8ac5a (diff)
downloadserenity-9bb4020195b926aba777589d475b44ca259072a4.zip
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.
-rw-r--r--Libraries/LibWeb/DOM/HTMLLinkElement.cpp16
-rw-r--r--Libraries/LibWeb/DOM/HTMLLinkElement.h10
2 files changed, 25 insertions, 1 deletions
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<StyleSheet> m_style_sheet;
};