mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
Browser: Add error page
Add a simple HTML error page that gets loaded into the HtmlView when loading the page fails. Closes #1210 and #1516
This commit is contained in:
parent
b1365d94f4
commit
021d78f8f7
Notes:
sideshowbarker
2024-07-19 08:01:04 +09:00
Author: https://github.com/linusg
Commit: 021d78f8f7
Pull-request: https://github.com/SerenityOS/serenity/pull/1557
Issue: https://github.com/SerenityOS/serenity/issues/1210
Reviewed-by: https://github.com/awesomekling ✅
Reviewed-by: https://github.com/bugaevc
5 changed files with 79 additions and 28 deletions
|
@ -346,23 +346,51 @@ void HtmlView::load(const URL& url)
|
|||
if (on_load_start)
|
||||
on_load_start(url);
|
||||
|
||||
ResourceLoader::the().load(url, [this, url](auto data) {
|
||||
if (data.is_null()) {
|
||||
dbg() << "Load failed!";
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
ResourceLoader::the().load(
|
||||
url,
|
||||
[this, url](auto data) {
|
||||
if (data.is_null()) {
|
||||
load_error_page(url, "No data");
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<Document> document;
|
||||
if (url.path().ends_with(".png")) {
|
||||
document = create_image_document(data, url);
|
||||
} else {
|
||||
document = parse_html_document(data, url);
|
||||
}
|
||||
ASSERT(document);
|
||||
set_document(document);
|
||||
if (on_title_change)
|
||||
on_title_change(document->title());
|
||||
});
|
||||
RefPtr<Document> document;
|
||||
if (url.path().ends_with(".png")) {
|
||||
document = create_image_document(data, url);
|
||||
} else {
|
||||
document = parse_html_document(data, url);
|
||||
}
|
||||
ASSERT(document);
|
||||
set_document(document);
|
||||
if (on_title_change)
|
||||
on_title_change(document->title());
|
||||
},
|
||||
[this, url](auto error) {
|
||||
load_error_page(url, error);
|
||||
});
|
||||
}
|
||||
|
||||
void HtmlView::load_error_page(const URL& failed_url, const String& error)
|
||||
{
|
||||
auto error_page_url = "file:///res/html/error.html";
|
||||
ResourceLoader::the().load(
|
||||
error_page_url,
|
||||
[this, failed_url, error](auto data) {
|
||||
ASSERT(!data.is_null());
|
||||
auto html = String::format(
|
||||
String::copy(data).characters(),
|
||||
escape_html_entities(failed_url.to_string()).characters(),
|
||||
escape_html_entities(error).characters());
|
||||
auto document = parse_html_document(html, failed_url);
|
||||
ASSERT(document);
|
||||
set_document(document);
|
||||
if (on_title_change)
|
||||
on_title_change(document->title());
|
||||
},
|
||||
[](auto error) {
|
||||
dbg() << "Failed to load error page: " << error;
|
||||
ASSERT_NOT_REACHED();
|
||||
});
|
||||
}
|
||||
|
||||
const LayoutDocument* HtmlView::layout_root() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue