mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 14:58:11 +00:00
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.
This commit is contained in:
parent
3be6d1aff0
commit
a1c8c754eb
2 changed files with 8 additions and 4 deletions
|
@ -8,7 +8,7 @@ ResourceLoader& ResourceLoader::the()
|
||||||
{
|
{
|
||||||
static ResourceLoader* s_the;
|
static ResourceLoader* s_the;
|
||||||
if (!s_the)
|
if (!s_the)
|
||||||
s_the = new ResourceLoader;
|
s_the = &ResourceLoader::construct().leak_ref();
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,13 +18,15 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> call
|
||||||
auto f = CFile::construct();
|
auto f = CFile::construct();
|
||||||
f->set_filename(url.path());
|
f->set_filename(url.path());
|
||||||
if (!f->open(CIODevice::OpenMode::ReadOnly)) {
|
if (!f->open(CIODevice::OpenMode::ReadOnly)) {
|
||||||
dbg() << "HtmlView::load: Error: " << f->error_string();
|
dbg() << "ResourceLoader::load: Error: " << f->error_string();
|
||||||
callback({});
|
callback({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = f->read_all();
|
auto data = f->read_all();
|
||||||
|
deferred_invoke([data = move(data), callback = move(callback)](auto&) {
|
||||||
callback(data);
|
callback(data);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
|
#include <LibCore/CObject.h>
|
||||||
|
|
||||||
class ResourceLoader {
|
class ResourceLoader : public CObject {
|
||||||
|
C_OBJECT(ResourceLoader)
|
||||||
public:
|
public:
|
||||||
static ResourceLoader& the();
|
static ResourceLoader& the();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue