diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index 8f25165efa1..fc3d6349f83 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -545,71 +545,4 @@ JS::GCPtr load_document(HTML::NavigationParams navigation_params) return nullptr; } -// https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline -JS::GCPtr create_document_for_inline_content(JS::GCPtr navigable, Optional navigation_id, StringView content_html) -{ - auto& vm = navigable->vm(); - - // 1. Let origin be a new opaque origin. - HTML::Origin origin {}; - - // 2. Let coop be a new cross-origin opener policy. - auto coop = HTML::CrossOriginOpenerPolicy {}; - - // 3. Let coopEnforcementResult be a new cross-origin opener policy enforcement result with - // url: response's URL - // origin: origin - // cross-origin opener policy: coop - HTML::CrossOriginOpenerPolicyEnforcementResult coop_enforcement_result { - .url = AK::URL("about:error"), // AD-HOC - .origin = origin, - .cross_origin_opener_policy = coop - }; - - // 4. Let navigationParams be a new navigation params with - // id: navigationId - // navigable: navigable - // request: null - // response: a new response - // origin: origin - // fetch controller: null - // commit early hints: null - // COOP enforcement result: coopEnforcementResult - // reserved environment: null - // policy container: a new policy container - // final sandboxing flag set: an empty set - // cross-origin opener policy: coop - // FIXME: navigation timing type: navTimingType - // about base URL: null - auto response = Fetch::Infrastructure::Response::create(vm); - response->url_list().append(AK::URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122 - HTML::NavigationParams navigation_params { - .id = navigation_id, - .navigable = navigable, - .request = {}, - .response = *response, - .fetch_controller = nullptr, - .commit_early_hints = nullptr, - .coop_enforcement_result = move(coop_enforcement_result), - .reserved_environment = {}, - .origin = move(origin), - .policy_container = HTML::PolicyContainer {}, - .final_sandboxing_flag_set = HTML::SandboxingFlagSet {}, - .cross_origin_opener_policy = move(coop), - .about_base_url = {}, - }; - - // 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams. - auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors(); - - // 6. Either associate document with a custom rendering that is not rendered using the normal Document rendering rules, or mutate document until it represents the content the - // user agent wants to render. - auto parser = HTML::HTMLParser::create(document, content_html, "utf-8"); - document->set_url(AK::URL("about:error")); - parser->run(); - - // 7. Return document. - return document; -} - } diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.h b/Userland/Libraries/LibWeb/DOM/DocumentLoading.h index cca7dd27cdb..87b03ba5d7b 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.h +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.h @@ -14,6 +14,71 @@ namespace Web { bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional content_encoding); bool parse_document(DOM::Document& document, ByteBuffer const& data, Optional content_encoding); JS::GCPtr load_document(HTML::NavigationParams navigation_params); -JS::GCPtr create_document_for_inline_content(JS::GCPtr navigable, Optional navigation_id, StringView content_html); + +// https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline +template +JS::NonnullGCPtr create_document_for_inline_content(JS::GCPtr navigable, Optional navigation_id, MutateDocument mutate_document) +{ + auto& vm = navigable->vm(); + + // 1. Let origin be a new opaque origin. + HTML::Origin origin {}; + + // 2. Let coop be a new cross-origin opener policy. + auto coop = HTML::CrossOriginOpenerPolicy {}; + + // 3. Let coopEnforcementResult be a new cross-origin opener policy enforcement result with + // url: response's URL + // origin: origin + // cross-origin opener policy: coop + HTML::CrossOriginOpenerPolicyEnforcementResult coop_enforcement_result { + .url = AK::URL("about:error"), // AD-HOC + .origin = origin, + .cross_origin_opener_policy = coop + }; + + // 4. Let navigationParams be a new navigation params with + // id: navigationId + // navigable: navigable + // request: null + // response: a new response + // origin: origin + // fetch controller: null + // commit early hints: null + // COOP enforcement result: coopEnforcementResult + // reserved environment: null + // policy container: a new policy container + // final sandboxing flag set: an empty set + // cross-origin opener policy: coop + // FIXME: navigation timing type: navTimingType + // about base URL: null + auto response = Fetch::Infrastructure::Response::create(vm); + response->url_list().append(AK::URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122 + HTML::NavigationParams navigation_params { + .id = navigation_id, + .navigable = navigable, + .request = {}, + .response = *response, + .fetch_controller = nullptr, + .commit_early_hints = nullptr, + .coop_enforcement_result = move(coop_enforcement_result), + .reserved_environment = {}, + .origin = move(origin), + .policy_container = HTML::PolicyContainer {}, + .final_sandboxing_flag_set = HTML::SandboxingFlagSet {}, + .cross_origin_opener_policy = move(coop), + .about_base_url = {}, + }; + + // 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams. + auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors(); + + // 6. Either associate document with a custom rendering that is not rendered using the normal Document rendering rules, or mutate document until it represents the content the + // user agent wants to render. + mutate_document(*document); + + // 7. Return document. + return document; +} } diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index 6c2af8e4ad6..49f75c5b419 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1106,7 +1107,11 @@ WebIDL::ExceptionOr 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);