diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-08 19:40:48 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-08 19:40:48 +0200 |
commit | a1c8c754ebae32952800ffab8617bce67a8eb024 (patch) | |
tree | c5ef01deabd4495a8a5dab7178bb109d077c8f59 /Libraries | |
parent | 3be6d1aff0b68692cc905c656e15206854fcf76d (diff) | |
download | serenity-a1c8c754ebae32952800ffab8617bce67a8eb024.zip |
LibHTML: Fire the file:// load completion callback asynchronously
This makes it consistent with how http:// callbacks are fired.
It would probably be fine to have file:// be synchronous, but at the
same time it's nice to have consistency.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibHTML/ResourceLoader.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibHTML/ResourceLoader.h | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Libraries/LibHTML/ResourceLoader.cpp b/Libraries/LibHTML/ResourceLoader.cpp index 8345c6ca6b..95c8c2106a 100644 --- a/Libraries/LibHTML/ResourceLoader.cpp +++ b/Libraries/LibHTML/ResourceLoader.cpp @@ -8,7 +8,7 @@ ResourceLoader& ResourceLoader::the() { static ResourceLoader* s_the; if (!s_the) - s_the = new ResourceLoader; + s_the = &ResourceLoader::construct().leak_ref(); return *s_the; } @@ -18,13 +18,15 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> call auto f = CFile::construct(); f->set_filename(url.path()); if (!f->open(CIODevice::OpenMode::ReadOnly)) { - dbg() << "HtmlView::load: Error: " << f->error_string(); + dbg() << "ResourceLoader::load: Error: " << f->error_string(); callback({}); return; } auto data = f->read_all(); - callback(data); + deferred_invoke([data = move(data), callback = move(callback)](auto&) { + callback(data); + }); return; } diff --git a/Libraries/LibHTML/ResourceLoader.h b/Libraries/LibHTML/ResourceLoader.h index 44df58c751..8255e5a8cd 100644 --- a/Libraries/LibHTML/ResourceLoader.h +++ b/Libraries/LibHTML/ResourceLoader.h @@ -2,8 +2,10 @@ #include <AK/Function.h> #include <AK/URL.h> +#include <LibCore/CObject.h> -class ResourceLoader { +class ResourceLoader : public CObject { + C_OBJECT(ResourceLoader) public: static ResourceLoader& the(); |