1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibWeb: Adjust create_document_for_inline_content() for future use

(Apologies for bad commit title, it's hard to explain in such a short
space!)

We're going to need to call this for producing markdown and gemini
documents, both of which need a Document and Realm to fetch the entire
response body, so that they can then generate their HTML. So this
commit modifies `create_document_for_inline_content()` to take a lambda
instead of a fixed HTML string, to support these uses.

Also, we always return a nonnull pointer, so make that the return type.

This is a move and change in the same commit, (Sorry!) but all the
changes are to the function signature and step 6.
This commit is contained in:
Sam Atkins 2023-12-19 16:16:24 +00:00 committed by Andreas Kling
parent ae8e040287
commit c5223ae77f
3 changed files with 72 additions and 69 deletions

View file

@ -20,6 +20,7 @@
#include <LibWeb/HTML/Navigation.h>
#include <LibWeb/HTML/NavigationParams.h>
#include <LibWeb/HTML/POSTResource.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/SandboxingFlagSet.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/SessionHistoryEntry.h>
@ -1106,7 +1107,11 @@ WebIDL::ExceptionOr<void> Navigable::populate_session_history_entry_document(
// The inline content should indicate to the user the sort of error that occurred.
// FIXME: Add error message to generated error page
auto error_html = load_error_page(entry->url).release_value_but_fixme_should_propagate_errors();
entry->document_state->set_document(create_document_for_inline_content(this, navigation_id, error_html));
entry->document_state->set_document(create_document_for_inline_content(this, navigation_id, [error_html](auto& document) {
auto parser = HTML::HTMLParser::create(document, error_html, "utf-8");
document.set_url(AK::URL("about:error"));
parser->run();
}));
// 2. Set entry's document state's document's salvageable to false.
entry->document_state->document()->set_salvageable(false);