summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-28 00:08:29 +0330
committerAndreas Kling <kling@serenityos.org>2021-09-28 22:32:31 +0200
commitf0e2c517fc6c5f9eae904cbd2aadede28a432850 (patch)
tree98d675caa0f43873e2892c5ac1847bbd3a38812f /Userland
parente9b9f89e707cf8e64377bc221ed5297ae5dc1f36 (diff)
downloadserenity-f0e2c517fc6c5f9eae904cbd2aadede28a432850.zip
LibWeb: Implement the dns-prefetch and preconnect link relationships
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp14
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h2
-rw-r--r--Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp10
-rw-r--r--Userland/Libraries/LibWeb/Loader/ResourceLoader.h3
4 files changed, 26 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
index 29548d04b2..47f40c798f 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
@@ -42,6 +42,10 @@ void HTMLLinkElement::inserted()
LoadRequest request;
request.set_url(document().parse_url(attribute(HTML::AttributeNames::href)));
m_preload_resource = ResourceLoader::the().load_resource(Resource::Type::Generic, request);
+ } else if (m_relationship & Relationship::DNSPrefetch) {
+ ResourceLoader::the().prefetch_dns(document().parse_url(attribute(HTML::AttributeNames::href)));
+ } else if (m_relationship & Relationship::Preconnect) {
+ ResourceLoader::the().preconnect(document().parse_url(attribute(HTML::AttributeNames::href)));
}
}
@@ -51,12 +55,16 @@ void HTMLLinkElement::parse_attribute(const FlyString& name, const String& value
m_relationship = 0;
auto parts = value.split_view(' ');
for (auto& part : parts) {
- if (part == "stylesheet")
+ if (part == "stylesheet"sv)
m_relationship |= Relationship::Stylesheet;
- else if (part == "alternate")
+ else if (part == "alternate"sv)
m_relationship |= Relationship::Alternate;
- else if (part == "preload")
+ else if (part == "preload"sv)
m_relationship |= Relationship::Preload;
+ else if (part == "dns-prefetch"sv)
+ m_relationship |= Relationship::DNSPrefetch;
+ else if (part == "preconnect"sv)
+ m_relationship |= Relationship::Preconnect;
}
}
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h
index aebd3a38d1..3405c92a99 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h
@@ -33,6 +33,8 @@ private:
Alternate = 1 << 0,
Stylesheet = 1 << 1,
Preload = 1 << 2,
+ DNSPrefetch = 1 << 3,
+ Preconnect = 1 << 4,
};
};
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
index 9d9f4c8efd..02ba6d19b0 100644
--- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
@@ -52,6 +52,16 @@ void ResourceLoader::load_sync(LoadRequest& request, Function<void(ReadonlyBytes
loop.exec();
}
+void ResourceLoader::prefetch_dns(AK::URL const& url)
+{
+ m_protocol_client->ensure_connection(url, RequestServer::CacheLevel::ResolveOnly);
+}
+
+void ResourceLoader::preconnect(AK::URL const& url)
+{
+ m_protocol_client->ensure_connection(url, RequestServer::CacheLevel::CreateConnection);
+}
+
static HashMap<LoadRequest, NonnullRefPtr<Resource>> s_resource_cache;
RefPtr<Resource> ResourceLoader::load_resource(Resource::Type type, LoadRequest& request)
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
index 0e2ffeec72..e311baddea 100644
--- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
+++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
@@ -37,6 +37,9 @@ public:
void load(const AK::URL&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
void load_sync(LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
+ void prefetch_dns(AK::URL const&);
+ void preconnect(AK::URL const&);
+
Function<void()> on_load_counter_change;
int pending_loads() const { return m_pending_loads; }