From 03eae096198c9d38f3f6ee858f8988829de819ab Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 25 Aug 2023 20:34:50 -0600 Subject: [PATCH] LibWeb: Implement snapshotting source snapshot params per the spec --- Userland/Libraries/LibWeb/DOM/Document.cpp | 27 ++++++++++++++++++- Userland/Libraries/LibWeb/DOM/Document.h | 4 ++- Userland/Libraries/LibWeb/HTML/Navigable.cpp | 8 +----- .../LibWeb/HTML/TraversableNavigable.cpp | 10 ++----- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 8b056b1e95a..dd2588a808f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1315,7 +1315,7 @@ Color Document::visited_link_color() const } // https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object -HTML::EnvironmentSettingsObject& Document::relevant_settings_object() +HTML::EnvironmentSettingsObject& Document::relevant_settings_object() const { // Then, the relevant settings object for a platform object o is the environment settings object of the relevant Realm for o. return Bindings::host_defined_environment_settings_object(realm()); @@ -2514,6 +2514,31 @@ HTML::PolicyContainer Document::policy_container() const return m_policy_container; } +// https://html.spec.whatwg.org/multipage/browsing-the-web.html#snapshotting-source-snapshot-params +HTML::SourceSnapshotParams Document::snapshot_source_snapshot_params() const +{ + // To snapshot source snapshot params given a Document sourceDocument, return a new source snapshot params with + + // has transient activation + // true if sourceDocument's relevant global object has transient activation; otherwise false + // sandboxing flags + // sourceDocument's active sandboxing flag set + // allows downloading + // false if sourceDocument's active sandboxing flag set has the sandboxed downloads browsing context flag set; otherwise true + // fetch client + // sourceDocument's relevant settings object + // source policy container + // sourceDocument's policy container + + return HTML::SourceSnapshotParams { + .has_transient_activation = verify_cast(HTML::relevant_global_object(*this)).has_transient_activation(), + .sandboxing_flags = m_active_sandboxing_flag_set, + .allows_downloading = (m_active_sandboxing_flag_set.flags & HTML::SandboxingFlagSet::SandboxedDownloads) != HTML::SandboxingFlagSet::SandboxedDownloads, + .fetch_client = relevant_settings_object(), + .source_policy_container = m_policy_container + }; +} + // https://html.spec.whatwg.org/multipage/document-sequences.html#descendant-navigables Vector> Document::descendant_navigables() { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index ea45f1c0b85..e262f1eb8f3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -232,7 +232,7 @@ public: DeprecatedString const& source() const { return m_source; } void set_source(DeprecatedString source) { m_source = move(source); } - HTML::EnvironmentSettingsObject& relevant_settings_object(); + HTML::EnvironmentSettingsObject& relevant_settings_object() const; void navigate_to_javascript_url(StringView url); void evaluate_javascript_url(StringView url); @@ -530,6 +530,8 @@ public: u32 unload_counter() const { return m_unload_counter; } + HTML::SourceSnapshotParams snapshot_source_snapshot_params() const; + protected: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index e7bcf2440ee..41deeb57928 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -814,13 +814,7 @@ WebIDL::ExceptionOr Navigable::navigate( ReferrerPolicy::ReferrerPolicy referrer_policy) { // 1. Let sourceSnapshotParams be the result of snapshotting source snapshot params given sourceDocument. - auto source_snapshot_params = SourceSnapshotParams { - .has_transient_activation = false, - .sandboxing_flags = source_document->active_sandboxing_flag_set(), - .allows_downloading = true, - .fetch_client = source_document->relevant_settings_object(), - .source_policy_container = source_document->policy_container() - }; + auto source_snapshot_params = source_document->snapshot_source_snapshot_params(); // 2. Let initiatorOriginSnapshot be sourceDocument's origin. auto initiator_origin_snapshot = source_document->origin(); diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index e2d4a8e2612..dbc06365161 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -330,15 +330,9 @@ void TraversableNavigable::apply_the_history_step(int step, Optional potentially_target_specific_source_snapshot_params = source_snapshot_params; - // FIXME: 4. If potentiallyTargetSpecificSourceSnapshotParams is null, then set it to the result of snapshotting source snapshot params given navigable's active document. + // 4. If potentiallyTargetSpecificSourceSnapshotParams is null, then set it to the result of snapshotting source snapshot params given navigable's active document. if (!potentially_target_specific_source_snapshot_params.has_value()) { - potentially_target_specific_source_snapshot_params = SourceSnapshotParams { - .has_transient_activation = false, - .sandboxing_flags = navigable->active_document()->active_sandboxing_flag_set(), - .allows_downloading = true, - .fetch_client = navigable->active_document()->relevant_settings_object(), - .source_policy_container = navigable->active_document()->policy_container() - }; + potentially_target_specific_source_snapshot_params = navigable->active_document()->snapshot_source_snapshot_params(); } // 5. Set targetEntry's document state's reload pending to false.