summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-09-11 21:15:15 -0700
committerAndreas Kling <kling@serenityos.org>2021-09-12 16:39:23 +0200
commitbca8707e1520133788f3a299a324a8b0d04dd02e (patch)
tree2e7db9bd96f9e27256321cb85cec587e38a6383e /Userland/Libraries/LibWeb
parent1d4be9ca33ce12265c161b2da6a8182ea14bc314 (diff)
downloadserenity-bca8707e1520133788f3a299a324a8b0d04dd02e.zip
LibWeb: Start tracking elapsed time when a resource is loaded
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Loader/FrameLoader.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Loader/FrameLoader.h2
-rw-r--r--Userland/Libraries/LibWeb/Loader/LoadRequest.h6
-rw-r--r--Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Loader/ResourceLoader.h6
-rw-r--r--Userland/Libraries/LibWeb/Page/Page.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Page/Page.h2
7 files changed, 17 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
index c4f47c723e..f56aff7918 100644
--- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
@@ -137,7 +137,7 @@ bool FrameLoader::parse_document(DOM::Document& document, const ByteBuffer& data
return false;
}
-bool FrameLoader::load(const LoadRequest& request, Type type)
+bool FrameLoader::load(LoadRequest& request, Type type)
{
if (!request.is_valid()) {
load_error_page(request.url(), "Invalid request");
diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.h b/Userland/Libraries/LibWeb/Loader/FrameLoader.h
index 993025d826..95d3b5bbcc 100644
--- a/Userland/Libraries/LibWeb/Loader/FrameLoader.h
+++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.h
@@ -27,7 +27,7 @@ public:
~FrameLoader();
bool load(const URL&, Type);
- bool load(const LoadRequest&, Type);
+ bool load(LoadRequest&, Type);
void load_html(const StringView&, const URL&);
diff --git a/Userland/Libraries/LibWeb/Loader/LoadRequest.h b/Userland/Libraries/LibWeb/Loader/LoadRequest.h
index 5481fdbabe..314f974fe4 100644
--- a/Userland/Libraries/LibWeb/Loader/LoadRequest.h
+++ b/Userland/Libraries/LibWeb/Loader/LoadRequest.h
@@ -8,7 +8,9 @@
#include <AK/ByteBuffer.h>
#include <AK/HashMap.h>
+#include <AK/Time.h>
#include <AK/URL.h>
+#include <LibCore/ElapsedTimer.h>
#include <LibWeb/Forward.h>
namespace Web {
@@ -32,6 +34,9 @@ public:
const ByteBuffer& body() const { return m_body; }
void set_body(const ByteBuffer& body) { m_body = body; }
+ void start_timer() { m_load_timer.start(); };
+ Time load_time() const { return m_load_timer.elapsed_time(); }
+
unsigned hash() const
{
auto body_hash = string_hash((const char*)m_body.data(), m_body.size());
@@ -64,6 +69,7 @@ private:
String m_method { "GET" };
HashMap<String, String> m_headers;
ByteBuffer m_body;
+ Core::ElapsedTimer m_load_timer;
};
}
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
index 99d52c4fb8..33df84b933 100644
--- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
@@ -7,6 +7,7 @@
#include <AK/Base64.h>
#include <AK/Debug.h>
#include <AK/JsonObject.h>
+#include <LibCore/ElapsedTimer.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibProtocol/Request.h>
@@ -32,7 +33,7 @@ ResourceLoader::ResourceLoader()
{
}
-void ResourceLoader::load_sync(const LoadRequest& request, 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)
+void ResourceLoader::load_sync(LoadRequest& request, 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)
{
Core::EventLoop loop;
@@ -53,7 +54,7 @@ void ResourceLoader::load_sync(const LoadRequest& request, Function<void(Readonl
static HashMap<LoadRequest, NonnullRefPtr<Resource>> s_resource_cache;
-RefPtr<Resource> ResourceLoader::load_resource(Resource::Type type, const LoadRequest& request)
+RefPtr<Resource> ResourceLoader::load_resource(Resource::Type type, LoadRequest& request)
{
if (!request.is_valid())
return nullptr;
@@ -92,6 +93,7 @@ RefPtr<Resource> ResourceLoader::load_resource(Resource::Type type, const LoadRe
void ResourceLoader::load(const LoadRequest& request, 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)
{
auto& url = request.url();
+ request.start_timer();
if (is_port_blocked(url.port())) {
dbgln("ResourceLoader::load: Error: blocked port {} from URL {}", url.port(), url);
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
index 2829b0cb24..f3756700c1 100644
--- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
+++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
@@ -30,11 +30,11 @@ class ResourceLoader : public Core::Object {
public:
static ResourceLoader& the();
- RefPtr<Resource> load_resource(Resource::Type, const LoadRequest&);
+ RefPtr<Resource> load_resource(Resource::Type, LoadRequest&);
- void load(const 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 load(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 load(const 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(const 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 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);
Function<void()> on_load_counter_change;
diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp
index 9219869684..065747768e 100644
--- a/Userland/Libraries/LibWeb/Page/Page.cpp
+++ b/Userland/Libraries/LibWeb/Page/Page.cpp
@@ -36,7 +36,7 @@ void Page::load(const URL& url)
top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation);
}
-void Page::load(const LoadRequest& request)
+void Page::load(LoadRequest& request)
{
top_level_browsing_context().loader().load(request, FrameLoader::Type::Navigation);
}
diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h
index 217b7bffd2..d0f82a3a7c 100644
--- a/Userland/Libraries/LibWeb/Page/Page.h
+++ b/Userland/Libraries/LibWeb/Page/Page.h
@@ -42,7 +42,7 @@ public:
void set_focused_browsing_context(Badge<EventHandler>, BrowsingContext&);
void load(const URL&);
- void load(const LoadRequest&);
+ void load(LoadRequest&);
void load_html(const StringView&, const URL&);