2023-04-06 15:50:22 +03:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2023-04-06 15:50:22 +03:00
|
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2024-04-21 19:57:33 +00:00
|
|
|
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
|
2025-10-16 14:07:09 +01:00
|
|
|
#include <LibWeb/HTML/Navigable.h>
|
|
|
|
|
#include <LibWeb/HTML/UserNavigationInvolvement.h>
|
2023-04-06 15:50:22 +03:00
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
|
2023-11-17 15:12:03 +02:00
|
|
|
bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional<String> content_encoding);
|
2025-07-04 10:53:28 +05:30
|
|
|
GC::Ptr<DOM::Document> load_document(HTML::NavigationParams const& navigation_params, NonnullRefPtr<Core::Promise<Empty>> signal_to_continue_session_history_processing);
|
2024-04-16 11:23:48 +02:00
|
|
|
bool can_load_document_with_type(MimeSniff::MimeType const&);
|
2023-12-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline
|
|
|
|
|
template<typename MutateDocument>
|
2025-01-07 14:58:48 +00:00
|
|
|
GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::Navigable> navigable, Optional<String> navigation_id, HTML::UserNavigationInvolvement user_involvement, MutateDocument mutate_document)
|
2023-12-19 16:16:24 +00:00
|
|
|
{
|
|
|
|
|
auto& vm = navigable->vm();
|
2024-11-25 14:30:12 +00:00
|
|
|
VERIFY(navigable->active_document());
|
2023-12-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
// 1. Let origin be a new opaque origin.
|
2025-06-15 19:08:58 +12:00
|
|
|
auto origin = URL::Origin::create_opaque();
|
2023-12-19 16:16:24 +00:00
|
|
|
|
2024-09-18 19:48:22 +02:00
|
|
|
// 2. Let coop be a new opener policy.
|
|
|
|
|
auto coop = HTML::OpenerPolicy {};
|
2023-12-19 16:16:24 +00:00
|
|
|
|
2024-09-18 19:48:22 +02:00
|
|
|
// 3. Let coopEnforcementResult be a new opener policy enforcement result with
|
2023-12-19 16:16:24 +00:00
|
|
|
// url: response's URL
|
|
|
|
|
// origin: origin
|
2024-09-18 19:48:22 +02:00
|
|
|
// opener policy: coop
|
|
|
|
|
HTML::OpenerPolicyEnforcementResult coop_enforcement_result {
|
2025-11-13 14:05:19 +01:00
|
|
|
.url = URL::about_error(), // AD-HOC: https://github.com/whatwg/html/issues/9122
|
2023-12-19 16:16:24 +00:00
|
|
|
.origin = origin,
|
2024-09-18 19:48:22 +02:00
|
|
|
.opener_policy = coop
|
2023-12-19 16:16:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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
|
2024-09-18 19:48:22 +02:00
|
|
|
// opener policy: coop
|
2023-12-19 16:16:24 +00:00
|
|
|
// FIXME: navigation timing type: navTimingType
|
|
|
|
|
// about base URL: null
|
2025-01-07 14:58:48 +00:00
|
|
|
// user involvement: userInvolvement
|
2023-12-19 16:16:24 +00:00
|
|
|
auto response = Fetch::Infrastructure::Response::create(vm);
|
2025-02-15 23:51:45 +13:00
|
|
|
response->url_list().append(URL::about_error()); // AD-HOC: https://github.com/whatwg/html/issues/9122
|
2025-06-15 14:33:29 +12:00
|
|
|
auto navigation_params = vm.heap().allocate<HTML::NavigationParams>(
|
|
|
|
|
move(navigation_id),
|
|
|
|
|
navigable,
|
|
|
|
|
nullptr,
|
|
|
|
|
response,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
move(coop_enforcement_result),
|
|
|
|
|
nullptr,
|
|
|
|
|
move(origin),
|
|
|
|
|
vm.heap().allocate<HTML::PolicyContainer>(vm.heap()),
|
|
|
|
|
HTML::SandboxingFlagSet {},
|
|
|
|
|
move(coop),
|
|
|
|
|
OptionalNone {},
|
|
|
|
|
user_involvement);
|
2023-12-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
2025-11-27 16:28:38 +00:00
|
|
|
// 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.
|
2023-12-19 16:16:24 +00:00
|
|
|
mutate_document(*document);
|
|
|
|
|
|
2025-11-27 16:28:38 +00:00
|
|
|
// FIXME: 7. Act as if the user agent had stopped parsing document.
|
|
|
|
|
// We currently do this in the caller instead, to avoid deadlocks.
|
|
|
|
|
|
|
|
|
|
// 8. Return document.
|
2023-12-19 16:16:24 +00:00
|
|
|
return document;
|
|
|
|
|
}
|
2023-04-06 15:50:22 +03:00
|
|
|
|
|
|
|
|
}
|