mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
LibWeb: Bring document & browsing context creation in line with spec
We had drifted away from the spec steps a little bit here. This patch brings us back in line and knocks off some FIXMEs in the process.
This commit is contained in:
parent
a5c62b953f
commit
ff9ae5ff40
Notes:
sideshowbarker
2024-07-16 18:26:46 +09:00
Author: https://github.com/awesomekling
Commit: ff9ae5ff40
Pull-request: https://github.com/SerenityOS/serenity/pull/24123
3 changed files with 42 additions and 30 deletions
|
@ -2915,6 +2915,11 @@ HTML::PolicyContainer Document::policy_container() const
|
|||
return m_policy_container;
|
||||
}
|
||||
|
||||
void Document::set_policy_container(HTML::PolicyContainer policy_container)
|
||||
{
|
||||
m_policy_container = move(policy_container);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#snapshotting-source-snapshot-params
|
||||
HTML::SourceSnapshotParams Document::snapshot_source_snapshot_params() const
|
||||
{
|
||||
|
|
|
@ -501,6 +501,7 @@ public:
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container
|
||||
HTML::PolicyContainer policy_container() const;
|
||||
void set_policy_container(HTML::PolicyContainer);
|
||||
|
||||
Vector<JS::Handle<HTML::Navigable>> descendant_navigables();
|
||||
Vector<JS::Handle<HTML::Navigable>> const descendant_navigables() const;
|
||||
|
|
|
@ -120,6 +120,16 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
return BrowsingContext::BrowsingContextAndDocument { browsing_context, document };
|
||||
}
|
||||
|
||||
static void populate_with_html_head_body(JS::NonnullGCPtr<DOM::Document> document)
|
||||
{
|
||||
auto html_node = MUST(DOM::create_element(document, HTML::TagNames::html, Namespace::HTML));
|
||||
auto head_element = MUST(DOM::create_element(document, HTML::TagNames::head, Namespace::HTML));
|
||||
MUST(html_node->append_child(head_element));
|
||||
auto body_element = MUST(DOM::create_element(document, HTML::TagNames::body, Namespace::HTML));
|
||||
MUST(html_node->append_child(body_element));
|
||||
MUST(document->append_child(html_node));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-browsing-context
|
||||
WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext::create_a_new_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::GCPtr<DOM::Document> creator, JS::GCPtr<DOM::Element> embedder, JS::NonnullGCPtr<BrowsingContextGroup> group)
|
||||
{
|
||||
|
@ -134,35 +144,35 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
// 3. Let creatorOrigin be null.
|
||||
Optional<Origin> creator_origin = {};
|
||||
|
||||
// FIXME: This algorithm needs re-aligned with the spec
|
||||
// 4. Let creatorBaseURL be null.
|
||||
Optional<URL::URL> creator_base_url = {};
|
||||
|
||||
// 4. If creator is non-null, then:
|
||||
// 5. If creator is non-null, then:
|
||||
if (creator) {
|
||||
// 1. Set creatorOrigin to creator's origin.
|
||||
creator_origin = creator->origin();
|
||||
|
||||
// FIXME: This algorithm needs re-aligned with the spec
|
||||
// 2. Set creatorBaseURL to creator's document base URL.
|
||||
creator_base_url = creator->base_url();
|
||||
|
||||
// FIXME: 2. Set browsingContext's creator base URL to an algorithm which returns creator's base URL.
|
||||
|
||||
// FIXME: 3. Set browsingContext's virtual browsing context group ID to creator's browsing context's top-level browsing context's virtual browsing context group ID.
|
||||
// 3. Set browsingContext's virtual browsing context group ID to creator's browsing context's top-level browsing context's virtual browsing context group ID.
|
||||
VERIFY(creator->browsing_context());
|
||||
browsing_context->m_virtual_browsing_context_group_id = creator->browsing_context()->top_level_browsing_context()->m_virtual_browsing_context_group_id;
|
||||
}
|
||||
|
||||
// FIXME: 5. Let sandboxFlags be the result of determining the creation sandboxing flags given browsingContext and embedder.
|
||||
// 6. Let sandboxFlags be the result of determining the creation sandboxing flags given browsingContext and embedder.
|
||||
SandboxingFlagSet sandbox_flags = {};
|
||||
|
||||
// 6. Let origin be the result of determining the origin given about:blank, sandboxFlags, and creatorOrigin.
|
||||
// 7. Let origin be the result of determining the origin given about:blank, sandboxFlags, and creatorOrigin.
|
||||
auto origin = determine_the_origin(URL::URL("about:blank"sv), sandbox_flags, creator_origin);
|
||||
|
||||
// FIXME: 7. Let permissionsPolicy be the result of creating a permissions policy given browsingContext and origin. [PERMISSIONSPOLICY]
|
||||
// FIXME: 8. Let permissionsPolicy be the result of creating a permissions policy given embedder and origin. [PERMISSIONSPOLICY]
|
||||
|
||||
// FIXME: 8. Let agent be the result of obtaining a similar-origin window agent given origin, group, and false.
|
||||
// FIXME: 9. Let agent be the result of obtaining a similar-origin window agent given origin, group, and false.
|
||||
|
||||
JS::GCPtr<Window> window;
|
||||
|
||||
// 9. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
||||
// 10. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
||||
auto realm_execution_context = Bindings::create_a_new_javascript_realm(
|
||||
Bindings::main_thread_vm(),
|
||||
[&](JS::Realm& realm) -> JS::Object* {
|
||||
|
@ -178,13 +188,13 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
return browsing_context->window_proxy();
|
||||
});
|
||||
|
||||
// 10. Let topLevelCreationURL be about:blank if embedder is null; otherwise embedder's relevant settings object's top-level creation URL.
|
||||
// 11. Let topLevelCreationURL be about:blank if embedder is null; otherwise embedder's relevant settings object's top-level creation URL.
|
||||
auto top_level_creation_url = !embedder ? URL::URL("about:blank") : relevant_settings_object(*embedder).top_level_creation_url;
|
||||
|
||||
// 11. Let topLevelOrigin be origin if embedder is null; otherwise embedder's relevant settings object's top-level origin.
|
||||
// 12. Let topLevelOrigin be origin if embedder is null; otherwise embedder's relevant settings object's top-level origin.
|
||||
auto top_level_origin = !embedder ? origin : relevant_settings_object(*embedder).origin();
|
||||
|
||||
// 12. Set up a window environment settings object with about:blank, realm execution context, null, topLevelCreationURL, and topLevelOrigin.
|
||||
// 13. Set up a window environment settings object with about:blank, realm execution context, null, topLevelCreationURL, and topLevelOrigin.
|
||||
WindowEnvironmentSettingsObject::setup(
|
||||
page,
|
||||
URL::URL("about:blank"),
|
||||
|
@ -193,14 +203,14 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
top_level_creation_url,
|
||||
top_level_origin);
|
||||
|
||||
// 13. Let loadTimingInfo be a new document load timing info with its navigation start time set to the result of calling
|
||||
// 14. Let loadTimingInfo be a new document load timing info with its navigation start time set to the result of calling
|
||||
// coarsen time with unsafeContextCreationTime and the new environment settings object's cross-origin isolated capability.
|
||||
auto load_timing_info = DOM::DocumentLoadTimingInfo();
|
||||
load_timing_info.navigation_start_time = HighResolutionTime::coarsen_time(
|
||||
unsafe_context_creation_time,
|
||||
verify_cast<WindowEnvironmentSettingsObject>(Bindings::host_defined_environment_settings_object(window->realm())).cross_origin_isolated_capability() == CanUseCrossOriginIsolatedAPIs::Yes);
|
||||
|
||||
// 14. Let document be a new Document, with:
|
||||
// 15. Let document be a new Document, with:
|
||||
auto document = HTML::HTMLDocument::create(window->realm());
|
||||
|
||||
// Non-standard
|
||||
|
@ -236,12 +246,13 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
// about base URL: creatorBaseURL
|
||||
document->set_about_base_url(creator_base_url);
|
||||
|
||||
// 15. If creator is non-null, then:
|
||||
// 16. If creator is non-null, then:
|
||||
if (creator) {
|
||||
// 1. Set document's referrer to the serialization of creator's URL.
|
||||
document->set_referrer(MUST(String::from_byte_string(creator->url().serialize())));
|
||||
|
||||
// FIXME: 2. Set document's policy container to a clone of creator's policy container.
|
||||
// 2. Set document's policy container to a clone of creator's policy container.
|
||||
document->set_policy_container(creator->policy_container());
|
||||
|
||||
// 3. If creator's origin is same origin with creator's relevant settings object's top-level origin,
|
||||
if (creator->origin().is_same_origin(creator->relevant_settings_object().top_level_origin)) {
|
||||
|
@ -252,28 +263,23 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
}
|
||||
}
|
||||
|
||||
// 16. Assert: document's URL and document's relevant settings object's creation URL are about:blank.
|
||||
// 17. Assert: document's URL and document's relevant settings object's creation URL are about:blank.
|
||||
VERIFY(document->url() == "about:blank"sv);
|
||||
VERIFY(document->relevant_settings_object().creation_url == "about:blank"sv);
|
||||
|
||||
// 17. Mark document as ready for post-load tasks.
|
||||
// 18. Mark document as ready for post-load tasks.
|
||||
document->set_ready_for_post_load_tasks(true);
|
||||
|
||||
// 18. Ensure that document has a single child html node, which itself has two empty child nodes: a head element, and a body element.
|
||||
auto html_node = TRY(DOM::create_element(document, HTML::TagNames::html, Namespace::HTML));
|
||||
auto head_element = TRY(DOM::create_element(document, HTML::TagNames::head, Namespace::HTML));
|
||||
TRY(html_node->append_child(head_element));
|
||||
auto body_element = TRY(DOM::create_element(document, HTML::TagNames::body, Namespace::HTML));
|
||||
TRY(html_node->append_child(body_element));
|
||||
TRY(document->append_child(html_node));
|
||||
// 19. Populate with html/head/body given document.
|
||||
populate_with_html_head_body(*document);
|
||||
|
||||
// 19. Make active document.
|
||||
// 20. Make active document.
|
||||
document->make_active();
|
||||
|
||||
// 20. Completely finish loading document.
|
||||
// 21. Completely finish loading document.
|
||||
document->completely_finish_loading();
|
||||
|
||||
// 21. Return browsingContext and document.
|
||||
// 22. Return browsingContext and document.
|
||||
return BrowsingContext::BrowsingContextAndDocument { browsing_context, document };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue