summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibWeb/ResourceLoader.cpp19
-rw-r--r--Libraries/LibWeb/ResourceLoader.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/Libraries/LibWeb/ResourceLoader.cpp b/Libraries/LibWeb/ResourceLoader.cpp
index daf2b813eb..47fa1741ee 100644
--- a/Libraries/LibWeb/ResourceLoader.cpp
+++ b/Libraries/LibWeb/ResourceLoader.cpp
@@ -25,6 +25,7 @@
*/
#include <AK/SharedBuffer.h>
+#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibProtocol/Client.h>
#include <LibProtocol/Download.h>
@@ -45,6 +46,24 @@ ResourceLoader::ResourceLoader()
{
}
+void ResourceLoader::load_sync(const URL& url, Function<void(const ByteBuffer&)> success_callback, Function<void(const String&)> error_callback)
+{
+ Core::EventLoop loop;
+
+ load(
+ url,
+ [&](auto& data) {
+ success_callback(data);
+ loop.quit(0);
+ },
+ [&](auto& string) {
+ error_callback(string);
+ loop.quit(0);
+ });
+
+ loop.exec();
+}
+
void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> success_callback, Function<void(const String&)> error_callback)
{
if (url.protocol() == "file") {
diff --git a/Libraries/LibWeb/ResourceLoader.h b/Libraries/LibWeb/ResourceLoader.h
index 26f122bbf6..4a98b16591 100644
--- a/Libraries/LibWeb/ResourceLoader.h
+++ b/Libraries/LibWeb/ResourceLoader.h
@@ -42,6 +42,7 @@ public:
static ResourceLoader& the();
void load(const URL&, Function<void(const ByteBuffer&)> success_callback, Function<void(const String&)> error_callback = nullptr);
+ void load_sync(const URL&, Function<void(const ByteBuffer&)> success_callback, Function<void(const String&)> error_callback = nullptr);
Function<void()> on_load_counter_change;