diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 5c146b5f673..9b498fd04c3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2974,7 +2974,7 @@ void Document::destroy() // 7. Set document's node navigable's active session history entry's document state's document to null. if (navigable()) { - navigable()->active_session_history_entry()->document_state->set_document(nullptr); + navigable()->active_session_history_entry()->document_state()->set_document(nullptr); } // FIXME: 8. Remove document from the owner set of each WorkerGlobalScope object whose set contains document. @@ -3790,7 +3790,7 @@ void Document::restore_the_history_object_state(JS::NonnullGCPtrclassic_history_api_state, target_realm, {}); + auto state_or_error = HTML::structured_deserialize(target_realm.vm(), entry->classic_history_api_state(), target_realm, {}); if (state_or_error.is_error()) m_history->set_state(JS::js_null()); else @@ -3818,7 +3818,7 @@ void Document::update_for_history_step_application(JS::NonnullGCPtrurl : URL::URL {}; + auto old_url = m_latest_entry ? m_latest_entry->url() : URL::URL {}; // 2. Set document's latest entry to entry. m_latest_entry = entry; diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 8378b9ea77b..29e02858ac3 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -53,9 +53,9 @@ static void indent(StringBuilder& builder, int levels) static ErrorOr dump_session_history_entry(StringBuilder& builder, HTML::SessionHistoryEntry const& session_history_entry, int indent_levels) { indent(builder, indent_levels); - auto const& document = session_history_entry.document_state->document(); - TRY(builder.try_appendff("step=({}) url=({}) is-active=({})\n", session_history_entry.step.get(), session_history_entry.url, document && document->is_active())); - for (auto const& nested_history : session_history_entry.document_state->nested_histories()) { + auto const& document = session_history_entry.document_state()->document(); + TRY(builder.try_appendff("step=({}) url=({}) is-active=({})\n", session_history_entry.step().get(), session_history_entry.url(), document && document->is_active())); + for (auto const& nested_history : session_history_entry.document_state()->nested_histories()) { for (auto const& nested_she : nested_history.entries) { TRY(dump_session_history_entry(builder, *nested_she, indent_levels + 1)); } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 0406287bd16..949ce7733ad 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -483,7 +483,7 @@ struct POSTResource; struct ScrollOptions; struct ScrollToOptions; struct SerializedFormData; -struct SessionHistoryEntry; +class SessionHistoryEntry; struct ToggleTaskTracker; } diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index 8aff3c46695..c5bf31480b2 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -77,7 +77,7 @@ Vector> Navigable::child_navigables() const { Vector> results; for (auto& entry : all_navigables()) { - if (entry->current_session_history_entry()->step == SessionHistoryEntry::Pending::Tag) + if (entry->current_session_history_entry()->step() == SessionHistoryEntry::Pending::Tag) continue; if (entry->parent() == this) results.append(entry); @@ -140,10 +140,10 @@ ErrorOr Navigable::initialize_navigable(JS::NonnullGCPtr do JS::NonnullGCPtr entry = *heap().allocate_without_realm(); // URL: document's URL - entry->url = document_state->document()->url(); + entry->set_url(document_state->document()->url()); // document state: documentState - entry->document_state = document_state; + entry->set_document_state(document_state); // 2. Set navigable's current session history entry to entry. m_current_session_history_entry = entry; @@ -166,9 +166,9 @@ JS::GCPtr Navigable::get_the_target_history_entry(int targe // 2. Return the item in entries that has the greatest step less than or equal to step. JS::GCPtr result = nullptr; for (auto& entry : entries) { - auto entry_step = entry->step.get(); + auto entry_step = entry->step().get(); if (entry_step <= target_step) { - if (!result || result->step.get() < entry_step) { + if (!result || result->step().get() < entry_step) { result = entry; } } @@ -183,7 +183,7 @@ void Navigable::activate_history_entry(JS::GCPtr entry) // FIXME: 1. Save persisted state to the navigable's active session history entry. // 2. Let newDocument be entry's document. - JS::GCPtr new_document = entry->document_state->document().ptr(); + JS::GCPtr new_document = entry->document_state()->document().ptr(); // 3. Assert: newDocument's is initial about:blank is false, i.e., we never traverse // back to the initial about:blank Document because it always gets replaced when we @@ -205,7 +205,7 @@ void Navigable::activate_history_entry(JS::GCPtr entry) JS::GCPtr Navigable::active_document() { // A navigable's active document is its active session history entry's document. - return m_active_session_history_entry->document_state->document(); + return m_active_session_history_entry->document_state()->document(); } // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-bc @@ -240,7 +240,7 @@ JS::GCPtr Navigable::active_window() String Navigable::target_name() const { // A navigable's target name is its active session history entry's document state's navigable target name. - return active_session_history_entry()->document_state->navigable_target_name(); + return active_session_history_entry()->document_state()->navigable_target_name(); } // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-container @@ -478,7 +478,7 @@ Vector>& Navigable::get_session_history_en // 5. For each entry of traversable's session history entries, append entry's document state to docStates. for (auto& entry : traversable->session_history_entries()) - doc_states.append(entry->document_state); + doc_states.append(entry->document_state()); // 6. For each docState of docStates: while (!doc_states.is_empty()) { @@ -492,7 +492,7 @@ Vector>& Navigable::get_session_history_en // 2. For each entry of nestedHistory's entries, append entry's document state to docStates. for (auto& entry : nested_history.entries) - doc_states.append(entry->document_state); + doc_states.append(entry->document_state()); } } @@ -585,7 +585,7 @@ static WebIDL::ExceptionOr create_navigation_params_from_a_src auto& realm = navigable->active_window()->realm(); // 1. Let documentResource be entry's document state's resource. - auto document_resource = entry->document_state->resource(); + auto document_resource = entry->document_state()->resource(); VERIFY(document_resource.has()); // 2. Let response be a new response with @@ -599,7 +599,7 @@ static WebIDL::ExceptionOr create_navigation_params_from_a_src response->set_body(TRY(Fetch::Infrastructure::byte_sequence_as_body(realm, document_resource.get().bytes()))); // 3. Let responseOrigin be the result of determining the origin given response's URL, targetSnapshotParams's sandboxing flags, and entry's document state's origin. - auto response_origin = determine_the_origin(*response->url(), target_snapshot_params.sandboxing_flags, entry->document_state->origin()); + auto response_origin = determine_the_origin(*response->url(), target_snapshot_params.sandboxing_flags, entry->document_state()->origin()); // 4. Let coop be a new cross-origin opener policy. CrossOriginOpenerPolicy coop = {}; @@ -616,7 +616,7 @@ static WebIDL::ExceptionOr create_navigation_params_from_a_src // 6. Let policyContainer be the result of determining navigation params policy container given response's URL, // entry's document state's history policy container, null, navigable's container document's policy container, and null. - Optional history_policy_container = entry->document_state->history_policy_container().visit( + Optional history_policy_container = entry->document_state()->history_policy_container().visit( [](PolicyContainer const& c) -> Optional { return c; }, [](DocumentState::Client) -> Optional { return {}; }); PolicyContainer policy_container; @@ -655,7 +655,7 @@ static WebIDL::ExceptionOr create_navigation_params_from_a_src .policy_container = policy_container, .final_sandboxing_flag_set = target_snapshot_params.sandboxing_flags, .cross_origin_opener_policy = move(coop), - .about_base_url = entry->document_state->about_base_url(), + .about_base_url = entry->document_state()->about_base_url(), }; } @@ -671,7 +671,7 @@ static WebIDL::ExceptionOrdocument_state->resource(); + auto document_resource = entry->document_state()->resource(); // 3. Let request be a new request, with // url: entry's URL @@ -685,7 +685,7 @@ static WebIDL::ExceptionOrset_url(entry->url); + request->set_url(entry->url()); request->set_client(source_snapshot_params.fetch_client); request->set_destination(Fetch::Infrastructure::Request::Destination::Document); request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include); @@ -693,7 +693,7 @@ static WebIDL::ExceptionOrset_redirect_mode(Fetch::Infrastructure::Request::RedirectMode::Manual); request->set_replaces_client_id(active_document.relevant_settings_object().id); request->set_mode(Fetch::Infrastructure::Request::Mode::Navigate); - request->set_referrer(entry->document_state->request_referrer()); + request->set_referrer(entry->document_state()->request_referrer()); // 4. If documentResource is a POST resource, then: if (document_resource.has()) { @@ -722,11 +722,11 @@ static WebIDL::ExceptionOrdocument_state->reload_pending()) + if (entry->document_state()->reload_pending()) request->set_reload_navigation(true); // 6. Otherwise, if entry's document state's ever populated is true, then set request's history-navigation flag. - if (entry->document_state->ever_populated()) + if (entry->document_state()->ever_populated()) request->set_history_navigation(true); // 7. If sourceSnapshotParams's has transient activation is true, then set request's user-activation to true. @@ -777,7 +777,7 @@ static WebIDL::ExceptionOrdocument_state->initiator_origin().has_value() && active_document.origin().is_same_origin(*entry->document_state->initiator_origin()) + .current_context_is_navigation_source = entry->document_state()->initiator_origin().has_value() && active_document.origin().is_same_origin(*entry->document_state()->initiator_origin()) }; // 13. Let finalSandboxFlags be an empty sandboxing flag set. @@ -856,14 +856,14 @@ static WebIDL::ExceptionOrbody().has()) { - entry->document_state->set_resource(Empty {}); + entry->document_state()->set_resource(Empty {}); } // FIXME 9. Set responsePolicyContainer to the result of creating a policy container from a fetch response given response and request's reserved client. // FIXME 10. Set finalSandboxFlags to the union of targetSnapshotParams's sandboxing flags and responsePolicyContainer's CSP list's CSP-derived sandboxing flags. // 11. Set responseOrigin to the result of determining the origin given response's URL, finalSandboxFlags, and entry's document state's initiator origin. - response_origin = determine_the_origin(*response_holder->response()->url(), final_sandbox_flags, entry->document_state->initiator_origin()); + response_origin = determine_the_origin(*response_holder->response()->url(), final_sandbox_flags, entry->document_state()->initiator_origin()); // 12. If navigable is a top-level traversable, then: if (navigable->is_top_level_traversable()) { @@ -898,10 +898,10 @@ static WebIDL::ExceptionOris_valid()); // 17. Set entry's classic history API state to StructuredSerializeForStorage(null). - entry->classic_history_api_state = MUST(structured_serialize_for_storage(vm, JS::js_null())); + entry->set_classic_history_api_state(MUST(structured_serialize_for_storage(vm, JS::js_null()))); // 18. Let oldDocState be entry's document state. - auto old_doc_state = entry->document_state; + auto old_doc_state = entry->document_state(); // 19. Set entry's document state to a new document state, with // history policy container: a clone of the oldDocState's history policy container if it is non-null; null otherwise @@ -911,19 +911,20 @@ static WebIDL::ExceptionOrdocument_state = navigable->heap().allocate_without_realm(); - entry->document_state->set_history_policy_container(old_doc_state->history_policy_container()); - entry->document_state->set_request_referrer(old_doc_state->request_referrer()); - entry->document_state->set_request_referrer_policy(old_doc_state->request_referrer_policy()); - entry->document_state->set_origin(old_doc_state->origin()); - entry->document_state->set_resource(old_doc_state->resource()); - entry->document_state->set_ever_populated(old_doc_state->ever_populated()); - entry->document_state->set_navigable_target_name(old_doc_state->navigable_target_name()); + auto new_document_state = navigable->heap().allocate_without_realm(); + new_document_state->set_history_policy_container(old_doc_state->history_policy_container()); + new_document_state->set_request_referrer(old_doc_state->request_referrer()); + new_document_state->set_request_referrer_policy(old_doc_state->request_referrer_policy()); + new_document_state->set_origin(old_doc_state->origin()); + new_document_state->set_resource(old_doc_state->resource()); + new_document_state->set_ever_populated(old_doc_state->ever_populated()); + new_document_state->set_navigable_target_name(old_doc_state->navigable_target_name()); + entry->set_document_state(new_document_state); // 20. If locationURL's scheme is not an HTTP(S) scheme, then: if (!Fetch::Infrastructure::is_http_or_https_scheme(location_url.value()->scheme())) { // 1. Set entry's document state's resource to null. - entry->document_state->set_resource(Empty {}); + entry->document_state()->set_resource(Empty {}); // 2. Break. break; @@ -933,7 +934,7 @@ static WebIDL::ExceptionOrurl = current_url; + entry->set_url(current_url); } // 20. If locationURL is a URL whose scheme is not a fetch scheme, then return a new non-fetch scheme navigation params, with @@ -970,7 +971,7 @@ static WebIDL::ExceptionOr history_policy_container = entry->document_state->history_policy_container().visit( + Optional history_policy_container = entry->document_state()->history_policy_container().visit( [](PolicyContainer const& c) -> Optional { return c; }, [](DocumentState::Client) -> Optional { return {}; }); auto result_policy_container = determine_navigation_params_policy_container(*response_holder->response()->url(), history_policy_container, source_snapshot_params.source_policy_container, {}, response_policy_container); @@ -1007,7 +1008,7 @@ static WebIDL::ExceptionOrdocument_state->about_base_url(), + .about_base_url = entry->document_state()->about_base_url(), }; return navigation_params; @@ -1035,7 +1036,7 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( [[maybe_unused]] auto current_browsing_context = active_browsing_context(); // 4. Let documentResource be entry's document state's resource. - auto document_resource = entry->document_state->resource(); + auto document_resource = entry->document_state()->resource(); // 5. If navigationParams is null, then: if (navigation_params.has()) { @@ -1048,11 +1049,11 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( // 2. Otherwise, if both of the following are true: // - entry's URL's scheme is a fetch scheme; and // - documentResource is null, or allowPOST is true and documentResource's request body is not failure (FIXME: check if request body is not failure) - else if (Fetch::Infrastructure::is_fetch_scheme(entry->url.scheme()) && (document_resource.has() || allow_POST)) { + else if (Fetch::Infrastructure::is_fetch_scheme(entry->url().scheme()) && (document_resource.has() || allow_POST)) { navigation_params = TRY(create_navigation_params_by_fetching(entry, this, source_snapshot_params, target_snapshot_params, csp_navigation_type, navigation_id)); } // 3. Otherwise, if entry's URL's scheme is not a fetch scheme, then set navigationParams to a new non-fetch scheme navigation params, with: - else if (!Fetch::Infrastructure::is_fetch_scheme(entry->url.scheme())) { + else if (!Fetch::Infrastructure::is_fetch_scheme(entry->url().scheme())) { // - id: navigationId // - navigable: navigable // - URL: entry's URL @@ -1063,10 +1064,10 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( navigation_params = NonFetchSchemeNavigationParams { .id = navigation_id, .navigable = this, - .url = entry->url, + .url = entry->url(), .target_snapshot_sandboxing_flags = target_snapshot_params.sandboxing_flags, .source_snapshot_has_transient_activation = source_snapshot_params.has_transient_activation, - .initiator_origin = *entry->document_state->initiator_origin(), + .initiator_origin = *entry->document_state()->initiator_origin(), }; } } @@ -1095,9 +1096,9 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( if (navigation_params.has()) { // FIXME: https://github.com/whatwg/html/issues/9767 // We probably are expected to skip to steps 13 and 14 and return after doing this - entry->document_state->set_document(attempt_to_create_a_non_fetch_scheme_document(navigation_params.get())); - if (entry->document_state->document()) { - entry->document_state->set_ever_populated(true); + entry->document_state()->set_document(attempt_to_create_a_non_fetch_scheme_document(navigation_params.get())); + if (entry->document_state()->document()) { + entry->document_state()->set_ever_populated(true); } completion_steps(); return; @@ -1122,15 +1123,15 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( // 1. Set entry's document state's document to the result of creating a document for inline content that doesn't have a DOM, given navigable, null, and navTimingType. // 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](auto& document) { + 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](auto& document) { auto parser = HTML::HTMLParser::create(document, error_html, "utf-8"); document.set_url(URL::URL("about:error")); parser->run(); })); // 2. Set entry's document state's document's salvageable to false. - entry->document_state->document()->set_salvageable(false); + entry->document_state()->document()->set_salvageable(false); // FIXME: 3. If navigationParams is not null, then: if (!navigation_params.has()) { @@ -1162,10 +1163,10 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( } // 3. Set entry's document state's document to document. - entry->document_state->set_document(document.ptr()); + entry->document_state()->set_document(document.ptr()); // 4. Set entry's document state's origin to document's origin. - entry->document_state->set_origin(document->origin()); + entry->document_state()->set_origin(document->origin()); } // FIXME: 12. If entry's document state's request referrer is "client", then set it to request's referrer. @@ -1173,8 +1174,8 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( // What is "request" here? // 13. If entry's document state's document is not null, then set entry's document state's ever populated to true. - if (entry->document_state->document()) { - entry->document_state->set_ever_populated(true); + if (entry->document_state()->document()) { + entry->document_state()->set_ever_populated(true); } // 14. Run completionSteps. @@ -1273,7 +1274,7 @@ WebIDL::ExceptionOr Navigable::navigate(NavigateParams params) // - url's fragment is non-null if (document_resource.has() && !response - && url.equals(active_session_history_entry()->url, URL::ExcludeFragment::Yes) + && url.equals(active_session_history_entry()->url(), URL::ExcludeFragment::Yes) && url.fragment().has_value()) { // 1. Navigate to a fragment given navigable, url, historyHandling, userInvolvement, navigationAPIState, and navigationId. TRY(navigate_to_a_fragment(url, to_history_handling_behavior(history_handling), user_involvement, navigation_api_state, navigation_id)); @@ -1402,8 +1403,8 @@ WebIDL::ExceptionOr Navigable::navigate(NavigateParams params) // 6. Let historyEntry be a new session history entry, with its URL set to url and its document state set to documentState. JS::NonnullGCPtr history_entry = *heap().allocate_without_realm(); - history_entry->url = url; - history_entry->document_state = document_state; + history_entry->set_url(url); + history_entry->set_document_state(document_state); // 7. Let navigationParams be null. Variant navigation_params = Empty {}; @@ -1445,7 +1446,7 @@ WebIDL::ExceptionOr Navigable::navigate_to_a_fragment(URL::URL const& url, // 2. Let destinationNavigationAPIState be navigable's active session history entry's navigation API state. // 3. If navigationAPIState is not null, then set destinationNavigationAPIState to navigationAPIState. - auto destination_navigation_api_state = navigation_api_state.has_value() ? *navigation_api_state : active_session_history_entry()->navigation_api_state; + auto destination_navigation_api_state = navigation_api_state.has_value() ? *navigation_api_state : active_session_history_entry()->navigation_api_state(); // 4. Let continue be the result of firing a push/replace/reload navigate event at navigation with navigationType set to historyHandling, isSameDocument set to true, // userInvolvement set to userInvolvement, and destinationURL set to url, and navigationAPIState set to destinationNavigationAPIState. @@ -1462,10 +1463,10 @@ WebIDL::ExceptionOr Navigable::navigate_to_a_fragment(URL::URL const& url, // navigation API state: destinationNavigationAPIState // scroll restoration mode: navigable's active session history entry's scroll restoration mode JS::NonnullGCPtr history_entry = heap().allocate_without_realm(); - history_entry->url = url; - history_entry->document_state = active_session_history_entry()->document_state; - history_entry->navigation_api_state = destination_navigation_api_state; - history_entry->scroll_restoration_mode = active_session_history_entry()->scroll_restoration_mode; + history_entry->set_url(url); + history_entry->set_document_state(active_session_history_entry()->document_state()); + history_entry->set_navigation_api_state(destination_navigation_api_state); + history_entry->set_scroll_restoration_mode(active_session_history_entry()->scroll_restoration_mode()); // 7. Let entryToReplace be navigable's active session history entry if historyHandling is "replace", otherwise null. auto entry_to_replace = history_handling == HistoryHandlingBehavior::Replace ? active_session_history_entry() : nullptr; @@ -1658,7 +1659,7 @@ WebIDL::ExceptionOr Navigable::navigate_to_a_javascript_url(URL::URL const auto entry_to_replace = active_session_history_entry(); // 10. Let oldDocState be entryToReplace's document state. - auto old_doc_state = entry_to_replace->document_state; + auto old_doc_state = entry_to_replace->document_state(); // 11. Let documentState be a new document state with // document: newDocument @@ -1686,8 +1687,8 @@ WebIDL::ExceptionOr Navigable::navigate_to_a_javascript_url(URL::URL const // URL: entryToReplace's URL // document state: documentState JS::NonnullGCPtr history_entry = *heap().allocate_without_realm(); - history_entry->url = entry_to_replace->url; - history_entry->document_state = document_state; + history_entry->set_url(entry_to_replace->url()); + history_entry->set_document_state(document_state); // 13. Append session history traversal steps to targetNavigable's traversable to finalize a cross-document navigation with targetNavigable, historyHandling, and historyEntry. traversable_navigable()->append_session_history_traversal_steps([this, history_entry, history_handling, navigation_id] { @@ -1701,7 +1702,7 @@ WebIDL::ExceptionOr Navigable::navigate_to_a_javascript_url(URL::URL const void Navigable::reload() { // 1. Set navigable's active session history entry's document state's reload pending to true. - active_session_history_entry()->document_state->set_reload_pending(true); + active_session_history_entry()->document_state()->set_reload_pending(true); // 2. Let traversable be navigable's traversable navigable. auto traversable = traversable_navigable(); @@ -1804,7 +1805,7 @@ void finalize_a_cross_document_navigation(JS::NonnullGCPtr navigable, navigable->set_delaying_load_events(false); // 3. If historyEntry's document is null, then return. - if (!history_entry->document_state->document()) + if (!history_entry->document_state()->document()) return; // 4. If all of the following are true: @@ -1812,8 +1813,8 @@ void finalize_a_cross_document_navigation(JS::NonnullGCPtr navigable, // - historyEntry's document's browsing context is not an auxiliary browsing context whose opener browsing context is non-null; and // - historyEntry's document's origin is not navigable's active document's origin // then set historyEntry's document state's navigable target name to the empty string. - if (navigable->parent() == nullptr && history_entry->document_state->document()->browsing_context()->opener_browsing_context() != nullptr && history_entry->document_state->document()->origin() != navigable->active_document()->origin()) - history_entry->document_state->set_navigable_target_name(String {}); + if (navigable->parent() == nullptr && history_entry->document_state()->document()->browsing_context()->opener_browsing_context() != nullptr && history_entry->document_state()->document()->origin() != navigable->active_document()->origin()) + history_entry->document_state()->set_navigable_target_name(String {}); // 5. Let entryToReplace be navigable's active session history entry if historyHandling is "replace", otherwise null. auto entry_to_replace = history_handling == HistoryHandlingBehavior::Replace ? navigable->active_session_history_entry() : nullptr; @@ -1836,7 +1837,7 @@ void finalize_a_cross_document_navigation(JS::NonnullGCPtr navigable, target_step = traversable->current_session_history_step() + 1; // 3. Set historyEntry's step to targetStep. - history_entry->step = target_step; + history_entry->set_step(target_step); // 4. Append historyEntry to targetEntries. target_entries.append(history_entry); @@ -1845,12 +1846,12 @@ void finalize_a_cross_document_navigation(JS::NonnullGCPtr navigable, *(target_entries.find(*entry_to_replace)) = history_entry; // 2. Set historyEntry's step to entryToReplace's step. - history_entry->step = entry_to_replace->step; + history_entry->set_step(entry_to_replace->step()); // 3. If historyEntry's document state's origin is same origin with entryToReplace's document state's origin, // then set historyEntry's navigation API key to entryToReplace's navigation API key. - if (history_entry->document_state->origin().has_value() && entry_to_replace->document_state->origin().has_value() && history_entry->document_state->origin()->is_same_origin(*entry_to_replace->document_state->origin())) { - history_entry->navigation_api_key = entry_to_replace->navigation_api_key; + if (history_entry->document_state()->origin().has_value() && entry_to_replace->document_state()->origin().has_value() && history_entry->document_state()->origin()->is_same_origin(*entry_to_replace->document_state()->origin())) { + history_entry->set_navigation_api_key(entry_to_replace->navigation_api_key()); } // 4. Set targetStep to traversable's current session history step. @@ -1878,10 +1879,10 @@ void perform_url_and_history_update_steps(DOM::Document& document, URL::URL new_ // scroll restoration mode: activeEntry's scroll restoration mode // FIXME: persisted user state: activeEntry's persisted user state JS::NonnullGCPtr new_entry = document.heap().allocate_without_realm(); - new_entry->url = new_url; - new_entry->classic_history_api_state = serialized_data.value_or(active_entry->classic_history_api_state); - new_entry->document_state = active_entry->document_state; - new_entry->scroll_restoration_mode = active_entry->scroll_restoration_mode; + new_entry->set_url(new_url); + new_entry->set_classic_history_api_state(serialized_data.value_or(active_entry->classic_history_api_state())); + new_entry->set_document_state(active_entry->document_state()); + new_entry->set_scroll_restoration_mode(active_entry->scroll_restoration_mode()); // 4. If document's is initial about:blank is true, then set historyHandling to "replace". if (document.is_initial_about_blank()) { diff --git a/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp index 32f040ee2d9..df645856d02 100644 --- a/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp +++ b/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp @@ -112,18 +112,18 @@ WebIDL::ExceptionOr NavigableContainer::create_new_child_navigable() traversable->append_session_history_traversal_steps([traversable, navigable, parent_navigable, history_entry] { // 1. Let parentDocState be parentNavigable's active session history entry's document state. - auto parent_doc_state = parent_navigable->active_session_history_entry()->document_state; + auto parent_doc_state = parent_navigable->active_session_history_entry()->document_state(); // 2. Let parentNavigableEntries be the result of getting session history entries for parentNavigable. auto parent_navigable_entries = parent_navigable->get_session_history_entries(); // 3. Let targetStepSHE be the first session history entry in parentNavigableEntries whose document state equals parentDocState. auto target_step_she = *parent_navigable_entries.find_if([parent_doc_state](auto& entry) { - return entry->document_state == parent_doc_state; + return entry->document_state() == parent_doc_state; }); // 4. Set historyEntry's step to targetStepSHE's step. - history_entry->step = target_step_she->step; + history_entry->set_step(target_step_she->step()); // 5. Let nestedHistory be a new nested history whose id is navigable's id and entries list is « historyEntry ». DocumentState::NestedHistory nested_history { @@ -267,7 +267,7 @@ void NavigableContainer::destroy_the_child_navigable() navigable->active_document()->destroy(); // 6. Let parentDocState be container's node navigable's active session history entry's document state. - auto parent_doc_state = this->navigable()->active_session_history_entry()->document_state; + auto parent_doc_state = this->navigable()->active_session_history_entry()->document_state(); // 7. Remove the nested history from parentDocState's nested histories whose id equals navigable's id. parent_doc_state->nested_histories().remove_all_matching([&](auto& nested_history) { diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.cpp b/Userland/Libraries/LibWeb/HTML/Navigation.cpp index b9e9f43534c..75817aafda3 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigation.cpp @@ -140,7 +140,7 @@ WebIDL::ExceptionOr Navigation::update_current_entry(NavigationUpdateCurre auto serialized_state = TRY(structured_serialize_for_storage(vm(), options.state)); // 4. Set current's session history entry's navigation API state to serializedState. - current->session_history_entry().navigation_api_state = serialized_state; + current->session_history_entry().set_navigation_api_state(serialized_state); // 5. Fire an event named currententrychange at this using NavigationCurrentEntryChangeEvent, // with its navigationType attribute initialized to null and its from initialized to current. @@ -310,7 +310,7 @@ WebIDL::ExceptionOr Navigation::reload(NavigationReloadOptions // 2. If current is not null, then set serializedState to current's session history entry's navigation API state. if (current != nullptr) - serialized_state = current->session_history_entry().navigation_api_state; + serialized_state = current->session_history_entry().navigation_api_state(); } // 5. If document is not fully active, then return an early error result for an "InvalidStateError" DOMException. @@ -347,7 +347,7 @@ WebIDL::ExceptionOr Navigation::traverse_to(String key, Naviga // 2. If this's entry list does not contain a NavigationHistoryEntry whose session history entry's navigation API key equals key, // then return an early error result for an "InvalidStateError" DOMException. auto it = m_entry_list.find_if([&key](auto const& entry) { - return entry->session_history_entry().navigation_api_key == key; + return entry->session_history_entry().navigation_api_key() == key; }); if (it == m_entry_list.end()) return early_error_result(WebIDL::InvalidStateError::create(realm, "Cannot traverseTo: key not found in session history list"_fly_string)); @@ -367,7 +367,7 @@ WebIDL::ExceptionOr Navigation::back(NavigationOptions const& return early_error_result(WebIDL::InvalidStateError::create(realm, "Cannot navigate back: no previous session history entry"_fly_string)); // 2. Let key be this's entry list[this's current entry index − 1]'s session history entry's navigation API key. - auto key = m_entry_list[m_current_entry_index - 1]->session_history_entry().navigation_api_key; + auto key = m_entry_list[m_current_entry_index - 1]->session_history_entry().navigation_api_key(); // 3. Return the result of performing a navigation API traversal given this, key, and options. return perform_a_navigation_api_traversal(key, options); @@ -385,7 +385,7 @@ WebIDL::ExceptionOr Navigation::forward(NavigationOptions cons return early_error_result(WebIDL::InvalidStateError::create(realm, "Cannot navigate forward: no next session history entry"_fly_string)); // 2. Let key be this's entry list[this's current entry index + 1]'s session history entry's navigation API key. - auto key = m_entry_list[m_current_entry_index + 1]->session_history_entry().navigation_api_key; + auto key = m_entry_list[m_current_entry_index + 1]->session_history_entry().navigation_api_key(); // 3. Return the result of performing a navigation API traversal given this, key, and options. return perform_a_navigation_api_traversal(key, options); @@ -622,7 +622,7 @@ WebIDL::ExceptionOr Navigation::perform_a_navigation_api_trave // 5. If key equals current's session history entry's navigation API key, then return // «[ "committed" → a promise resolved with current, "finished" → a promise resolved with current ]». - if (key == current->session_history_entry().navigation_api_key) { + if (key == current->session_history_entry().navigation_api_key()) { return NavigationResult { .committed = WebIDL::create_resolved_promise(realm, current)->promise(), .finished = WebIDL::create_resolved_promise(realm, current)->promise() @@ -656,7 +656,7 @@ WebIDL::ExceptionOr Navigation::perform_a_navigation_api_trave // 2. Let targetSHE be the session history entry in navigableSHEs whose navigation API key is key. If no such entry exists, then: auto it = navigable_shes.find_if([&key](auto const& entry) { - return entry->navigation_api_key == key; + return entry->navigation_api_key() == key; }); if (it == navigable_shes.end()) { // NOTE: This path is taken if navigation's entry list was outdated compared to navigableSHEs, @@ -684,7 +684,7 @@ WebIDL::ExceptionOr Navigation::perform_a_navigation_api_trave // 4. Let result be the result of applying the traverse history step given by targetSHE's step to traversable, // given sourceSnapshotParams, navigable, and "none". - auto result = traversable->apply_the_traverse_history_step(target_she->step.get(), source_snapshot_params, navigable, UserNavigationInvolvement::None); + auto result = traversable->apply_the_traverse_history_step(target_she->step().get(), source_snapshot_params, navigable, UserNavigationInvolvement::None); // NOTE: When result is "canceled-by-beforeunload" or "initiator-disallowed", the navigate event was never fired, // aborting the ongoing navigation would not be correct; it would result in a navigateerror event without a @@ -885,7 +885,7 @@ void Navigation::notify_about_the_committed_to_entry(JS::NonnullGCPtrserialized_state.has_value()) { // NOTE: At this point, apiMethodTracker's serialized state is no longer needed. // Implementations might want to clear it out to avoid keeping it alive for the lifetime of the navigation API method tracker. - nhe->session_history_entry().navigation_api_state = *api_method_tracker->serialized_state; + nhe->session_history_entry().set_navigation_api_state(*api_method_tracker->serialized_state); api_method_tracker->serialized_state = {}; } @@ -1244,7 +1244,7 @@ bool Navigation::fire_a_traverse_navigate_event(JS::NonnullGCPtrset_url(destination_she->url); + destination->set_url(destination_she->url()); // 5. Let destinationNHE be the NavigationHistoryEntry in navigation's entry list whose session history entry is destinationSHE, // or null if no such NavigationHistoryEntry exists. @@ -1258,7 +1258,7 @@ bool Navigation::fire_a_traverse_navigate_event(JS::NonnullGCPtrset_entry(*destination_nhe); // 2. Set destination's state to destinationSHE's navigation API state. - destination->set_state(destination_she->navigation_api_state); + destination->set_state(destination_she->navigation_api_state()); } // 7. Otherwise: @@ -1272,7 +1272,7 @@ bool Navigation::fire_a_traverse_navigate_event(JS::NonnullGCPtrset_is_same_document(destination_she->document_state->document() == &verify_cast(relevant_global_object(*this)).associated_document()); + destination->set_is_same_document(destination_she->document_state()->document() == &verify_cast(relevant_global_object(*this)).associated_document()); // 9. Return the result of performing the inner navigate event firing algorithm given navigation, "traverse", event, destination, userInvolvement, null, and null. // AD-HOC: We don't pass the event, but we do pass the classic_history_api state at the end to be set later diff --git a/Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp b/Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp index 3a1d541e15d..653dd17c41d 100644 --- a/Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp +++ b/Userland/Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp @@ -59,13 +59,13 @@ WebIDL::ExceptionOr> NavigationHistoryEntry::url() const // 4. If she's document does not equal document, and she's document state's request referrer policy // is "no-referrer" or "origin", then return null. - if ((she->document_state->document() != &document) - && (she->document_state->request_referrer_policy() == ReferrerPolicy::ReferrerPolicy::NoReferrer - || she->document_state->request_referrer_policy() == ReferrerPolicy::ReferrerPolicy::Origin)) + if ((she->document_state()->document() != &document) + && (she->document_state()->request_referrer_policy() == ReferrerPolicy::ReferrerPolicy::NoReferrer + || she->document_state()->request_referrer_policy() == ReferrerPolicy::ReferrerPolicy::Origin)) return OptionalNone {}; // 5. Return she's URL, serialized. - return TRY_OR_THROW_OOM(vm(), String::from_byte_string(she->url.serialize())); + return TRY_OR_THROW_OOM(vm(), String::from_byte_string(she->url().serialize())); } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationhistoryentry-key @@ -78,7 +78,7 @@ String NavigationHistoryEntry::key() const return {}; // 2. Return nhe's session history entry's navigation API key. - return m_session_history_entry->navigation_api_key; + return m_session_history_entry->navigation_api_key(); } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationhistoryentry-id @@ -91,7 +91,7 @@ String NavigationHistoryEntry::id() const return {}; // 2. Return nhe's session history entry's navigation API ID. - return m_session_history_entry->navigation_api_id; + return m_session_history_entry->navigation_api_id(); } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationhistoryentry-index @@ -120,7 +120,7 @@ bool NavigationHistoryEntry::same_document() const return false; // 3. Return true if this's session history entry's document equals document, and false otherwise. - return m_session_history_entry->document_state->document() == &document; + return m_session_history_entry->document_state()->document() == &document; } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationhistoryentry-getstate @@ -135,7 +135,7 @@ WebIDL::ExceptionOr NavigationHistoryEntry::get_state() // 2. Return StructuredDeserialize(this's session history entry's navigation API state). Rethrow any exceptions. // NOTE: This can in theory throw an exception, if attempting to deserialize a large ArrayBuffer // when not enough memory is available. - return structured_deserialize(vm(), m_session_history_entry->navigation_api_state, realm(), {}); + return structured_deserialize(vm(), m_session_history_entry->navigation_api_state(), realm(), {}); } void NavigationHistoryEntry::set_ondispose(WebIDL::CallbackType* event_handler) diff --git a/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.cpp b/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.cpp index eafaa5c9b61..6df31acec4d 100644 --- a/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.cpp +++ b/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.cpp @@ -16,15 +16,15 @@ JS_DEFINE_ALLOCATOR(SessionHistoryEntry); void SessionHistoryEntry::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(document_state); - visitor.visit(original_source_browsing_context); + visitor.visit(m_document_state); + visitor.visit(m_original_source_browsing_context); } SessionHistoryEntry::SessionHistoryEntry() - : classic_history_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_null()))) - , navigation_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_undefined()))) - , navigation_api_key(MUST(Crypto::generate_random_uuid())) - , navigation_api_id(MUST(Crypto::generate_random_uuid())) + : m_classic_history_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_null()))) + , m_navigation_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_undefined()))) + , m_navigation_api_key(MUST(Crypto::generate_random_uuid())) + , m_navigation_api_id(MUST(Crypto::generate_random_uuid())) { } diff --git a/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.h b/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.h index ab8796e1a4c..eee322e5afc 100644 --- a/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.h +++ b/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.h @@ -28,10 +28,11 @@ enum class ScrollRestorationMode { }; // https://html.spec.whatwg.org/multipage/history.html#session-history-entry -struct SessionHistoryEntry final : public JS::Cell { +class SessionHistoryEntry final : public JS::Cell { JS_CELL(SessionHistoryEntry, JS::Cell); JS_DECLARE_ALLOCATOR(SessionHistoryEntry); +public: SessionHistoryEntry(); void visit_edges(Cell::Visitor&) override; @@ -40,51 +41,85 @@ struct SessionHistoryEntry final : public JS::Cell { Tag, }; + [[nodiscard]] Variant step() const { return m_step; } + void set_step(Variant step) { m_step = step; } + + [[nodiscard]] URL::URL const& url() const { return m_url; } + void set_url(URL::URL url) { m_url = move(url); } + + [[nodiscard]] JS::GCPtr document_state() const { return m_document_state; } + void set_document_state(JS::GCPtr document_state) { m_document_state = document_state; } + + [[nodiscard]] SerializationRecord const& classic_history_api_state() const { return m_classic_history_api_state; } + void set_classic_history_api_state(SerializationRecord classic_history_api_state) { m_classic_history_api_state = move(classic_history_api_state); } + + [[nodiscard]] SerializationRecord const& navigation_api_state() const { return m_navigation_api_state; } + void set_navigation_api_state(SerializationRecord navigation_api_state) { m_navigation_api_state = move(navigation_api_state); } + + [[nodiscard]] String const& navigation_api_key() const { return m_navigation_api_key; } + void set_navigation_api_key(String navigation_api_key) { m_navigation_api_key = move(navigation_api_key); } + + [[nodiscard]] String const& navigation_api_id() const { return m_navigation_api_id; } + void set_navigation_api_id(String navigation_api_id) { m_navigation_api_id = move(navigation_api_id); } + + [[nodiscard]] ScrollRestorationMode scroll_restoration_mode() const { return m_scroll_restoration_mode; } + void set_scroll_restoration_mode(ScrollRestorationMode scroll_restoration_mode) { m_scroll_restoration_mode = scroll_restoration_mode; } + + [[nodiscard]] Optional const& policy_container() const { return m_policy_container; } + void set_policy_container(Optional policy_container) { m_policy_container = move(policy_container); } + + [[nodiscard]] Optional const& browsing_context_name() const { return m_browsing_context_name; } + void set_browsing_context_name(Optional browsing_context_name) { m_browsing_context_name = move(browsing_context_name); } + + [[nodiscard]] JS::GCPtr original_source_browsing_context() const { return m_original_source_browsing_context; } + void set_original_source_browsing_context(JS::GCPtr original_source_browsing_context) { m_original_source_browsing_context = original_source_browsing_context; } + +private: // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-step // step, a non-negative integer or "pending", initially "pending". - Variant step { Pending::Tag }; + Variant m_step { Pending::Tag }; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-url // URL, a URL - URL::URL url; + URL::URL m_url; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-document-state - JS::GCPtr document_state; + JS::GCPtr m_document_state; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-classic-history-api-state // classic history API state, which is serialized state, initially StructuredSerializeForStorage(null). - SerializationRecord classic_history_api_state; + SerializationRecord m_classic_history_api_state; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-state // navigation API state, which is a serialized state, initially StructuredSerializeForStorage(undefined). - SerializationRecord navigation_api_state; + SerializationRecord m_navigation_api_state; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-key // navigation API key, which is a string, initially set to the result of generating a random UUID. - String navigation_api_key; + String m_navigation_api_key; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-id // navigation API ID, which is a string, initially set to the result of generating a random UUID. - String navigation_api_id; + String m_navigation_api_id; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-scroll-restoration-mode // scroll restoration mode, a scroll restoration mode, initially "auto" - ScrollRestorationMode scroll_restoration_mode { ScrollRestorationMode::Auto }; + ScrollRestorationMode m_scroll_restoration_mode { ScrollRestorationMode::Auto }; // policy container, a policy container or null - Optional policy_container; + Optional m_policy_container; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-scroll-position // FIXME: scroll position data, which is scroll position data for the document's restorable scrollable regions // browsing context name, a browsing context name or null, initially null - Optional browsing_context_name; + Optional m_browsing_context_name; // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-other // FIXME: persisted user state, which is implementation-defined, initially null // NOTE: This is where we could remember the state of form controls, for example. - JS::GCPtr original_source_browsing_context; + JS::GCPtr m_original_source_browsing_context; }; } diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index dbc3e750538..78e326e7821 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -100,7 +100,7 @@ WebIDL::ExceptionOr> TraversableNavigable VERIFY(initial_history_entry); // 8. Set initialHistoryEntry's step to 0. - initial_history_entry->step = 0; + initial_history_entry->set_step(0); // 9. Append initialHistoryEntry to traversable's session history entries. traversable->m_session_history_entries.append(*initial_history_entry); @@ -171,10 +171,10 @@ Vector TraversableNavigable::get_all_used_history_steps() const // 1. For each entry of entryList: for (auto& entry : entry_list) { // 1. Append entry's step to steps. - steps.set(entry->step.get()); + steps.set(entry->step().get()); // 2. For each nestedHistory of entry's document state's nested histories, append nestedHistory's entries list to entryLists. - for (auto& nested_history : entry->document_state->nested_histories()) + for (auto& nested_history : entry->document_state()->nested_histories()) entry_lists.append(nested_history.entries); } } @@ -244,12 +244,12 @@ Vector> TraversableNavigable::get_all_navigables_whose_cur auto target_entry = navigable->get_the_target_history_entry(target_step); // 2. If targetEntry is not navigable's current session history entry or targetEntry's document state's reload pending is true, then append navigable to results. - if (target_entry != navigable->current_session_history_entry() || target_entry->document_state->reload_pending()) { + if (target_entry != navigable->current_session_history_entry() || target_entry->document_state()->reload_pending()) { results.append(*navigable); } // 3. If targetEntry's document is navigable's document, and targetEntry's document state's reload pending is false, then extend navigablesToCheck with the child navigables of navigable. - if (target_entry->document_state->document() == navigable->active_document() && !target_entry->document_state->reload_pending()) { + if (target_entry->document_state()->document() == navigable->active_document() && !target_entry->document_state()->reload_pending()) { navigables_to_check.extend(navigable->child_navigables()); } } @@ -279,7 +279,7 @@ Vector> TraversableNavigable::get_all_navigables_that_only auto target_entry = navigable->get_the_target_history_entry(target_step); // 2. If targetEntry is navigable's current session history entry and targetEntry's document state's reload pending is false, then: - if (target_entry == navigable->current_session_history_entry() && !target_entry->document_state->reload_pending()) { + if (target_entry == navigable->current_session_history_entry() && !target_entry->document_state()->reload_pending()) { // 1. Append navigable to results. results.append(navigable); @@ -318,7 +318,7 @@ Vector> TraversableNavigable::get_all_navigables_that_migh // 2. If targetEntry's document is not navigable's document or targetEntry's document state's reload pending is true, then append navigable to results. // NOTE: Although navigable's active history entry can change synchronously, the new entry will always have the same Document, // so accessing navigable's document is reliable. - if (target_entry->document_state->document() != navigable->active_document() || target_entry->document_state->reload_pending()) { + if (target_entry->document_state()->document() != navigable->active_document() || target_entry->document_state()->reload_pending()) { results.append(navigable); } @@ -421,14 +421,14 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // 3. Let changingNavigableContinuation be a changing navigable continuation state with: auto changing_navigable_continuation = ChangingNavigableContinuationState { - .displayed_document = displayed_entry->document_state->document(), + .displayed_document = displayed_entry->document_state()->document(), .target_entry = target_entry, .navigable = navigable, .update_only = false }; // 4. If displayedEntry is targetEntry and targetEntry's document state's reload pending is false, then: - if (displayed_entry == target_entry && !target_entry->document_state->reload_pending()) { + if (displayed_entry == target_entry && !target_entry->document_state()->reload_pending()) { // 1. Set changingNavigableContinuation's update-only to true. changing_navigable_continuation.update_only = true; @@ -440,18 +440,18 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ } // 5. Let oldOrigin be targetEntry's document state's origin. - auto old_origin = target_entry->document_state->origin(); + auto old_origin = target_entry->document_state()->origin(); auto after_document_populated = [old_origin, target_entry, changing_navigable_continuation, &changing_navigable_continuations, &vm, &navigable]() mutable { // 1. If targetEntry's document is null, then set changingNavigableContinuation's update-only to true. - if (!target_entry->document_state->document()) { + if (!target_entry->document_state()->document()) { changing_navigable_continuation.update_only = true; } else { // 2. If targetEntry's document's origin is not oldOrigin, then set targetEntry's classic history API state to StructuredSerializeForStorage(null). - if (target_entry->document_state->document()->origin() != old_origin) { - target_entry->classic_history_api_state = MUST(structured_serialize_for_storage(vm, JS::js_null())); + if (target_entry->document_state()->document()->origin() != old_origin) { + target_entry->set_classic_history_api_state(MUST(structured_serialize_for_storage(vm, JS::js_null()))); } // 3. If all of the following are true: @@ -460,9 +460,9 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // - targetEntry's document's origin is not oldOrigin, // then set targetEntry's document state's navigable target name to the empty string. if (navigable->parent() != nullptr - && target_entry->document_state->document()->browsing_context()->opener_browsing_context() == nullptr - && target_entry->document_state->origin() != old_origin) { - target_entry->document_state->set_navigable_target_name(String {}); + && target_entry->document_state()->document()->browsing_context()->opener_browsing_context() == nullptr + && target_entry->document_state()->origin() != old_origin) { + target_entry->document_state()->set_navigable_target_name(String {}); } } @@ -471,7 +471,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ }; // 6. If targetEntry's document is null, or targetEntry's document state's reload pending is true, then: - if (!target_entry->document_state->document() || target_entry->document_state->reload_pending()) { + if (!target_entry->document_state()->document() || target_entry->document_state()->reload_pending()) { // FIXME: 1. Let navTimingType be "back_forward" if targetEntry's document is null; otherwise "reload". // 2. Let targetSnapshotParams be the result of snapshotting target snapshot params given navigable. @@ -486,10 +486,10 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ } // 5. Set targetEntry's document state's reload pending to false. - target_entry->document_state->set_reload_pending(false); + target_entry->document_state()->set_reload_pending(false); // 6. Let allowPOST be targetEntry's document state's reload pending. - auto allow_POST = target_entry->document_state->reload_pending(); + auto allow_POST = target_entry->document_state()->reload_pending(); // 7. In parallel, attempt to populate the history entry's document for targetEntry, given navigable, potentiallyTargetSpecificSourceSnapshotParams, // targetSnapshotParams, with allowPOST set to allowPOST and completionSteps set to queue a global task on the navigation and traversal task source given @@ -593,9 +593,9 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // 1. If changingNavigableContinuation's update-only is false, then: if (!update_only) { // 1. If targetEntry's document does not equal displayedDocument, then: - if (target_entry->document_state->document().ptr() != displayed_document.ptr()) { + if (target_entry->document_state()->document().ptr() != displayed_document.ptr()) { // 1. Unload displayedDocument given targetEntry's document. - displayed_document->unload(target_entry->document_state->document()); + displayed_document->unload(target_entry->document_state()->document()); // 2. For each childNavigable of displayedDocument's descendant navigables, queue a global task on the navigation and traversal task source given // childNavigable's active window to unload childNavigable's active document. @@ -612,8 +612,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // 2. If navigable is not traversable, and targetEntry is not navigable's current session history entry, and targetEntry's document state's origin is the same as // navigable's current session history entry's document state's origin, then fire a traverse navigate event given targetEntry and userInvolvementForNavigateEvents. - auto target_origin = target_entry->document_state->origin(); - auto current_origin = navigable->current_session_history_entry()->document_state->origin(); + auto target_origin = target_entry->document_state()->origin(); + auto current_origin = navigable->current_session_history_entry()->document_state()->origin(); bool const is_same_origin = target_origin.has_value() && current_origin.has_value() && target_origin->is_same_origin(*current_origin); if (!navigable->is_traversable() && target_entry.ptr() != navigable->current_session_history_entry() @@ -624,16 +624,16 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // 3. Let updateDocument be an algorithm step which performs update document for history step application given targetEntry's document, // targetEntry, changingNavigableContinuation's update-only, scriptHistoryLength, scriptHistoryIndex, and entriesForNavigationAPI. auto update_document = JS::SafeFunction([target_entry, update_only, script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api)] { - target_entry->document_state->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, entries_for_navigation_api); + target_entry->document_state()->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, entries_for_navigation_api); }); // 4. If targetEntry's document is equal to displayedDocument, then perform updateDocument. - if (target_entry->document_state->document() == displayed_document.ptr()) { + if (target_entry->document_state()->document() == displayed_document.ptr()) { update_document(); } // 5. Otherwise, queue a global task on the navigation and traversal task source given targetEntry's document's relevant global object to perform updateDocument else { - queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*target_entry->document_state->document()), move(update_document)); + queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*target_entry->document_state()->document()), move(update_document)); } // 6. Increment completedChangeJobs. @@ -707,8 +707,8 @@ Vector> TraversableNavigable::get_session_ auto max_step = 0; for (auto i = 0u; i < raw_entries.size(); ++i) { auto const& entry = raw_entries[i]; - if (entry->step.has()) { - auto step = entry->step.get(); + if (entry->step().has()) { + auto step = entry->step().get(); if (step <= target_step && step > max_step) { starting_index = static_cast(i); } @@ -719,7 +719,7 @@ Vector> TraversableNavigable::get_session_ entries_for_navigation_api.append(raw_entries[starting_index]); // 5. Let startingOrigin be rawEntries[startingIndex]'s document state's origin. - auto starting_origin = raw_entries[starting_index]->document_state->origin(); + auto starting_origin = raw_entries[starting_index]->document_state()->origin(); // 6. Let i be startingIndex − 1. auto i = starting_index - 1; @@ -728,7 +728,7 @@ Vector> TraversableNavigable::get_session_ while (i > 0) { auto& entry = raw_entries[static_cast(i)]; // 1. If rawEntries[i]'s document state's origin is not same origin with startingOrigin, then break. - auto entry_origin = entry->document_state->origin(); + auto entry_origin = entry->document_state()->origin(); if (starting_origin.has_value() && entry_origin.has_value() && !entry_origin->is_same_origin(*starting_origin)) break; @@ -746,7 +746,7 @@ Vector> TraversableNavigable::get_session_ while (i < static_cast(raw_entries.size())) { auto& entry = raw_entries[static_cast(i)]; // 1. If rawEntries[i]'s document state's origin is not same origin with startingOrigin, then break. - auto entry_origin = entry->document_state->origin(); + auto entry_origin = entry->document_state()->origin(); if (starting_origin.has_value() && entry_origin.has_value() && !entry_origin->is_same_origin(*starting_origin)) break; @@ -779,13 +779,13 @@ void TraversableNavigable::clear_the_forward_session_history() // 1. Remove every session history entry from entryList that has a step greater than step. entry_list.remove_all_matching([step](auto& entry) { - return entry->step.template get() > step; + return entry->step().template get() > step; }); // 2. For each entry of entryList: for (auto& entry : entry_list) { // 1. For each nestedHistory of entry's document state's nested histories, append nestedHistory's entries list to entryLists. - for (auto& nested_history : entry->document_state->nested_histories()) { + for (auto& nested_history : entry->document_state()->nested_histories()) { entry_lists.append(nested_history.entries); } } @@ -898,7 +898,7 @@ void TraversableNavigable::destroy_top_level_traversable() // 2. For each historyEntry in traversable's session history entries: for (auto& history_entry : m_session_history_entries) { // 1. Let document be historyEntry's document. - auto document = history_entry->document_state->document(); + auto document = history_entry->document_state()->document(); // 2. If document is not null, then destroy document. if (document) @@ -953,7 +953,7 @@ void finalize_a_same_document_navigation(JS::NonnullGCPtr target_step = traversable->current_session_history_step() + 1; // 3. Set targetEntry's step to targetStep. - target_entry->step = *target_step; + target_entry->set_step(*target_step); // 4. Append targetEntry to targetEntries. target_entries.append(target_entry); @@ -962,7 +962,7 @@ void finalize_a_same_document_navigation(JS::NonnullGCPtr *(target_entries.find(*entry_to_replace)) = target_entry; // 2. Set targetEntry's step to entryToReplace's step. - target_entry->step = entry_to_replace->step; + target_entry->set_step(entry_to_replace->step()); // 3. Set targetStep to traversable's current session history step. target_step = traversable->current_session_history_step(); diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index a6a5638069a..63708b28ea4 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -866,7 +866,7 @@ void Window::set_name(String const& name) return; // 2. Set this's navigable's active session history entry's document state's navigable target name to the given value. - navigable()->active_session_history_entry()->document_state->set_navigable_target_name(name); + navigable()->active_session_history_entry()->document_state()->set_navigable_target_name(name); } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index 95cb61d34d8..e21ccd5926b 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -86,7 +86,7 @@ ErrorOr> SVGDecodedImageData::create(JS::R auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors(); navigable->set_ongoing_navigation({}); navigable->active_document()->destroy(); - navigable->active_session_history_entry()->document_state->set_document(document); + navigable->active_session_history_entry()->document_state()->set_document(document); auto parser = HTML::HTMLParser::create_with_uncertain_encoding(document, data); parser->run(document->url());