diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2022-07-02 22:32:25 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-03 13:26:32 +0200 |
commit | 92a3803066569a5475f49298a909f803fdd9ff67 (patch) | |
tree | e512cea33f0e8f6d67c02bfa0c667921e46d000a /Userland/Libraries/LibWeb | |
parent | 07b6c7114bd972e4eb6826a588f6cf19015f8a56 (diff) | |
download | serenity-92a3803066569a5475f49298a909f803fdd9ff67.zip |
LibWeb: Add timeout_callback to ResourceLoader::load()
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Loader/ResourceLoader.h | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index 3aa46c6d5f..7cde613cfc 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -138,7 +138,7 @@ static void emit_signpost(String const& message, int id) static size_t resource_id = 0; -void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback, Optional<u32> timeout) +void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback, Optional<u32> timeout, Function<void()> timeout_callback) { auto& url = request.url(); request.start_timer(); @@ -283,8 +283,10 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has if (timeout.has_value() && timeout.value() > 0) { auto timer = Core::Timer::create_single_shot(timeout.value(), nullptr); - timer->on_timeout = [timer, protocol_request]() mutable { + timer->on_timeout = [timer, protocol_request, timeout_callback = move(timeout_callback)]() mutable { protocol_request->stop(); + if (timeout_callback) + timeout_callback(); }; timer->start(); } @@ -328,11 +330,11 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has error_callback(not_implemented_error, {}); } -void ResourceLoader::load(const AK::URL& url, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback, Optional<u32> timeout) +void ResourceLoader::load(const AK::URL& url, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback, Optional<u32> timeout, Function<void()> timeout_callback) { LoadRequest request; request.set_url(url); - load(request, move(success_callback), move(error_callback), timeout); + load(request, move(success_callback), move(error_callback), timeout, move(timeout_callback)); } bool ResourceLoader::is_port_blocked(int port) diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h index c8ed264668..a9370dc91a 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h @@ -70,8 +70,8 @@ public: RefPtr<Resource> load_resource(Resource::Type, LoadRequest&); - void load(LoadRequest&, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback = nullptr, Optional<u32> timeout = {}); - void load(const AK::URL&, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback = nullptr, Optional<u32> timeout = {}); + void load(LoadRequest&, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback = nullptr, Optional<u32> timeout = {}, Function<void()> timeout_callback = nullptr); + void load(const AK::URL&, Function<void(ReadonlyBytes, HashMap<String, String, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> status_code)> success_callback, Function<void(String const&, Optional<u32> status_code)> error_callback = nullptr, Optional<u32> timeout = {}, Function<void()> timeout_callback = nullptr); ResourceLoaderConnector& connector() { return *m_connector; } |