1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 22:54:57 +00:00

LibHTML: Add ResourceLoader to support protocol-agnostic URL loading

We now support loading both file:// and http:// URLs. Feel free to
visit http://www.serenityos.org/ and enjoy the fancy good times. :^)
This commit is contained in:
Andreas Kling 2019-10-08 19:37:15 +02:00
parent 3fdc595e0c
commit 3be6d1aff0
6 changed files with 89 additions and 18 deletions

View file

@ -10,6 +10,7 @@
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/Parser/HTMLParser.h>
#include <LibHTML/RenderingContext.h>
#include <LibHTML/ResourceLoader.h>
#include <stdio.h>
HtmlView::HtmlView(GWidget* parent)
@ -174,19 +175,18 @@ void HtmlView::load(const URL& url)
if (on_load_start)
on_load_start(url);
auto f = CFile::construct();
f->set_filename(url.path());
if (!f->open(CIODevice::OpenMode::ReadOnly)) {
dbg() << "HtmlView::load: Error: " << f->error_string();
return;
}
ResourceLoader::the().load(url, [=](auto data) {
if (data.is_null()) {
dbg() << "Load failed!";
ASSERT_NOT_REACHED();
}
auto html = f->read_all();
auto document = parse_html(html, url);
document->normalize();
auto document = parse_html(data, url);
document->normalize();
set_document(document);
set_document(document);
if (on_title_change)
on_title_change(document->title());
if (on_title_change)
on_title_change(document->title());
});
}