Truly independent web browser
LibWebView: Read a session history's current entry as always present
Shannon Booth5f98e8c4fbb3
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex bd46efa0e4e..8eadaf304ea 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -444,9 +444,7 @@ ErrorOr<NonnullRefPtr<WebContentPage>> CanonicalTraversable::obtain_page_to_hostif (host && display_page && display_page->is_open() && host == &display_page->client())return display_page.release_nonnull();- auto const* current_entry = m_session_history.get_the_target_history_entry(*this, m_session_history.current_step());- VERIFY(current_entry);- auto current_entry_descriptor = current_entry->descriptor();+ auto current_entry_descriptor = m_session_history.current_entry().descriptor();Web::PageId page_id;if (host && host->page_id_for_traversable(*this).has_value()) {@@ -923,9 +921,7 @@ ErrorOr<URL::URL> CanonicalTraversable::restore_session_history_from_ui_snapshotTRY(m_session_history.restore_from_ui_snapshot(move(snapshot.entries), move(snapshot.used_steps), snapshot.current_used_step_index, [] { return Application::the().allocate_ui_process_cross_process_id(); }));session_history_changed();- auto* current_entry = m_session_history.current_entry();- VERIFY(current_entry);- return current_entry->url;+ return m_session_history.current_entry().url;}void CanonicalTraversable::reset_session_history_for_testing(@@ -945,10 +941,9 @@ bool CanonicalTraversable::initialize_session_history_for_testing(Vector<Web::HTabandon_history_operations();if (!m_session_history.initialize_for_testing(move(entries), move(used_steps), current_used_step_index))return false;- auto* active_entry = m_session_history.current_entry();- VERIFY(active_entry);+ auto& active_entry = m_session_history.current_entry();if (auto const& previous_active_entry = active_session_history_entry())- active_entry->document_state->document = previous_active_entry->document_state->document;+ active_entry.document_state->document = previous_active_entry->document_state->document;set_current_session_history_entry(active_entry);set_active_session_history_entry(active_entry);session_history_changed();@@ -1056,7 +1051,7 @@ CanonicalTraversable::~CanonicalTraversable()});}-Optional<size_t> CanonicalTraversable::effective_current_session_history_step_index() const+size_t CanonicalTraversable::effective_current_session_history_step_index() const{if (m_browser_history_traversal) {if (auto target = m_session_history.traversal_target_for_step(m_browser_history_traversal->browser_traversal().target_step); target.has_value())@@ -2731,8 +2726,7 @@ void CanonicalTraversable::report_history_operation_completion(HistoryOperation&{if (committed_step.has_value()) {if (auto view = this->view(); view.has_value()) {- if (auto* current_entry = m_session_history.current_entry())- view->set_url(current_entry->url);+ view->set_url(m_session_history.current_entry().url);}}diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.hindex a2992887292..a8d8d657374 100644--- a/Libraries/LibWebView/CanonicalTraversable.h+++ b/Libraries/LibWebView/CanonicalTraversable.h@@ -133,7 +133,7 @@ public:TraversableSessionHistory const& session_history() const { return m_session_history; }NonnullRefPtr<CanonicalSessionHistoryEntry> session_history_entry_for(CanonicalNavigable const&, Web::HTML::SameDocumentNavigationEntry const&) const;- Optional<size_t> effective_current_session_history_step_index() const;+ size_t effective_current_session_history_step_index() const;StorageJar& session_storage() { return *m_session_storage; }void clone_session_storage_from(CanonicalTraversable const&);diff --git a/Libraries/LibWebView/HistoryDebug.cpp b/Libraries/LibWebView/HistoryDebug.cppindex 7aaea31fcd4..06283b25f2d 100644--- a/Libraries/LibWebView/HistoryDebug.cpp+++ b/Libraries/LibWebView/HistoryDebug.cpp@@ -173,7 +173,7 @@ ByteString history_log_entries(TraversableSessionHistory const& history)auto const* entry = history.entry_at(i);VERIFY(entry);- if (auto const* current_entry = history.current_entry(); current_entry == entry)+ if (&history.current_entry() == entry)builder.append("*"sv);builder.appendff("{}:", i);append_history_log_entry(builder, entry->descriptor());diff --git a/Libraries/LibWebView/SessionHistory.cpp b/Libraries/LibWebView/SessionHistory.cppindex e1d83dfee12..899c5da97ab 100644--- a/Libraries/LibWebView/SessionHistory.cpp+++ b/Libraries/LibWebView/SessionHistory.cpp@@ -351,17 +351,14 @@ bool TraversableSessionHistory::replace_session_history_entry(CanonicalNavigablereturn true;}-Optional<size_t> TraversableSessionHistory::current_top_level_entry_index() const+size_t TraversableSessionHistory::current_top_level_entry_index() const{- return top_level_entry_index_for_step(m_entries, m_current_session_history_step);+ return top_level_entry_index_for_step(m_entries, m_current_session_history_step).value();}-Optional<size_t> TraversableSessionHistory::current_used_step_index() const+size_t TraversableSessionHistory::current_used_step_index() const{- auto used_step = get_the_used_step(m_current_session_history_step);- if (!used_step.has_value())- return {};- return used_steps().find_first_index(*used_step);+ return used_steps().find_first_index(get_the_used_step(m_current_session_history_step).value()).value();}Vector<Web::HTML::SessionHistoryEntryDescriptor> TraversableSessionHistory::entries() const@@ -381,14 +378,12 @@ Vector<i32> TraversableSessionHistory::used_steps() constbool TraversableSessionHistory::can_go_back() const{- auto current_used_step_index = this->current_used_step_index();- return current_used_step_index.has_value() && *current_used_step_index > 0;+ return current_used_step_index() > 0;}bool TraversableSessionHistory::can_go_forward() const{- auto current_used_step_index = this->current_used_step_index();- return current_used_step_index.has_value() && *current_used_step_index + 1 < used_step_count();+ return current_used_step_index() + 1 < used_step_count();}bool TraversableSessionHistory::has_only_top_level_used_steps() const@@ -436,8 +431,7 @@ Optional<TraversableSessionHistory::TraversalTarget> TraversableSessionHistory::auto target_top_level_entry_index = top_level_entry_index_for_step(m_entries, step);VERIFY(target_top_level_entry_index.has_value());auto const* target_top_level_entry = m_entries[*target_top_level_entry_index].ptr();- auto const* current_top_level_entry = current_entry();- VERIFY(current_top_level_entry);+ auto const* current_top_level_entry = ¤t_entry();return TraversalTarget {.target_step_index = *target_step_index,@@ -513,17 +507,17 @@ Optional<size_t> TraversableSessionHistory::target_step_index_for_delta(int delt// targetStepIndex be currentStepIndex plus delta. If allSteps[targetStepIndex]// does not exist, then abort these steps.auto current_used_step_index = this->current_used_step_index();- if (!current_used_step_index.has_value() || delta == 0)+ if (delta == 0)return {};if (delta < 0) {auto magnitude = static_cast<size_t>(-static_cast<i64>(delta));- if (magnitude > *current_used_step_index)+ if (magnitude > current_used_step_index)return {};- return *current_used_step_index - magnitude;+ return current_used_step_index - magnitude;}- auto target_index = *current_used_step_index + static_cast<size_t>(delta);+ auto target_index = current_used_step_index + static_cast<size_t>(delta);if (target_index >= used_step_count())return {};return target_index;@@ -537,9 +531,9 @@ Optional<i32> TraversableSessionHistory::step_at(size_t index) constreturn used_steps[index];}-CanonicalSessionHistoryEntry* TraversableSessionHistory::current_entry() const+CanonicalSessionHistoryEntry& TraversableSessionHistory::current_entry() const{- return top_level_entry_for_step(m_current_session_history_step);+ return *m_entries[current_top_level_entry_index()];}CanonicalSessionHistoryEntry* TraversableSessionHistory::entry_at(size_t index) constdiff --git a/Libraries/LibWebView/SessionHistory.h b/Libraries/LibWebView/SessionHistory.hindex 45eb5f587c4..336390e25f8 100644--- a/Libraries/LibWebView/SessionHistory.h+++ b/Libraries/LibWebView/SessionHistory.h@@ -42,13 +42,12 @@ public:TraversableSessionHistory(TraversableSessionHistory&&) = default;TraversableSessionHistory& operator=(TraversableSessionHistory&&) = default;- bool is_empty() const { return m_entries.is_empty(); }size_t size() const { return m_entries.size(); }size_t used_step_count() const { return used_steps().size(); }i32 current_step() const { return m_current_session_history_step; }// The index in the used steps of the used step the current step resolves to.- Optional<size_t> current_used_step_index() const;- Optional<size_t> current_top_level_entry_index() const;+ size_t current_used_step_index() const;+ size_t current_top_level_entry_index() const;bool initialize_for_testing(Vector<Web::HTML::SessionHistoryEntryDescriptor>, Vector<i32> used_steps, size_t current_used_step_index);[[nodiscard]] ErrorOr<void> restore_from_ui_snapshot(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index, Function<Web::HTML::CrossProcessId()> allocate_cross_process_id);@@ -85,7 +84,7 @@ public:}[[nodiscard]] Optional<size_t> target_step_index_for_delta(int delta) const;[[nodiscard]] Optional<i32> step_at(size_t index) const;- [[nodiscard]] CanonicalSessionHistoryEntry* current_entry() const;+ [[nodiscard]] CanonicalSessionHistoryEntry& current_entry() const;[[nodiscard]] CanonicalSessionHistoryEntry* entry_at(size_t index) const;[[nodiscard]] CanonicalSessionHistoryEntry* entry_for_step(i32 step) const;[[nodiscard]] CanonicalSessionHistoryEntry* top_level_entry_for_step(i32 step) const;diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex 6c47d9a91ff..5739fbc5a11 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -468,8 +468,7 @@ void ViewImplementation::did_stop_loading(Badge<CanonicalTraversable>, bool stop// The address shown is the current entry's again, and a navigation WebDriver waits on is over.void ViewImplementation::did_end_uncommitted_navigation(StringView reason){- if (auto const* current_entry = traversable().session_history().current_entry())- set_url(current_entry->url);+ set_url(traversable().session_history().current_entry().url);if (m_webdriver_navigation_observation.has_value())complete_webdriver_navigation(m_webdriver_navigation_observation->navigation_id);dump_session_history(reason);@@ -530,12 +529,14 @@ Vector<ViewImplementation::SessionHistoryTraversalMenuItem> ViewImplementation::{VERIFY(direction == -1 || direction == 1);- auto current_used_step_index = traversable().session_history().current_used_step_index();- if (!current_used_step_index.has_value())- return {};+ auto const& session_history = traversable().session_history();+ auto used_steps = session_history.used_steps();+ auto current_used_step_index = session_history.current_used_step_index();Vector<SessionHistoryTraversalMenuItem> items;- auto append_item = [&](i32 target_step, CanonicalSessionHistoryEntry const& target_entry) {+ auto append_item = [&](size_t target_step_index) {+ auto target_step = used_steps[target_step_index];+ auto const& target_entry = *session_history.top_level_entry_for_step(target_step);auto history_entry = m_session->history_store->entry_for_url(target_entry.url);auto url = target_entry.url.serialize();auto title = history_entry.has_value() && history_entry->title.has_value() && !history_entry->title->is_empty()@@ -550,25 +551,11 @@ Vector<ViewImplementation::SessionHistoryTraversalMenuItem> ViewImplementation::};if (direction < 0) {- for (size_t target_step_index = *current_used_step_index; target_step_index > 0; --target_step_index) {- auto target_step = traversable().session_history().step_at(target_step_index - 1);- if (!target_step.has_value())- continue;- auto const* target_entry = traversable().session_history().top_level_entry_for_step(*target_step);- if (!target_entry)- continue;- append_item(*target_step, *target_entry);- }+ for (size_t target_step_index = current_used_step_index; target_step_index > 0; --target_step_index)+ append_item(target_step_index - 1);} else {- for (size_t target_step_index = *current_used_step_index + 1; target_step_index < traversable().session_history().used_step_count(); ++target_step_index) {- auto target_step = traversable().session_history().step_at(target_step_index);- if (!target_step.has_value())- continue;- auto const* target_entry = traversable().session_history().top_level_entry_for_step(*target_step);- if (!target_entry)- continue;- append_item(*target_step, *target_entry);- }+ for (size_t target_step_index = current_used_step_index + 1; target_step_index < used_steps.size(); ++target_step_index)+ append_item(target_step_index);}return items;@@ -2991,10 +2978,7 @@ JsonValue ViewImplementation::webdriver_session_history() constserialized.set("crashOverlayActive"sv, crash_overlay_active());serialized.set("hasOnlyTopLevelUsedSteps"sv, traversable().session_history().has_only_top_level_used_steps());- if (auto current_used_step_index = traversable().session_history().current_used_step_index(); current_used_step_index.has_value())- serialized.set("currentUsedStepIndex"sv, *current_used_step_index);- else- serialized.set("currentUsedStepIndex"sv, JsonValue {});+ serialized.set("currentUsedStepIndex"sv, traversable().session_history().current_used_step_index());if (auto traversal = traversable().browser_history_traversal_for_testing(); traversal.has_value()) {JsonObject pending_traversal;@@ -3020,24 +3004,19 @@ String ViewImplementation::ui_process_session_history_for_testing(Badge<WebContevoid ViewImplementation::update_navigation_action_state(){auto effective_current_index = traversable().effective_current_session_history_step_index();- m_navigate_back_action->set_enabled(effective_current_index.has_value() && *effective_current_index > 0);- m_navigate_forward_action->set_enabled(effective_current_index.has_value()- && *effective_current_index + 1 < traversable().session_history().used_step_count());+ m_navigate_back_action->set_enabled(effective_current_index > 0);+ m_navigate_forward_action->set_enabled(effective_current_index + 1 < traversable().session_history().used_step_count());}void ViewImplementation::recover_current_session_history_entry_with_history_operation(){m_history_visit_transition_for_next_load = HistoryVisitTransition::Restore;- auto const* current_entry = traversable().session_history().current_entry();- auto current_url = current_entry ? current_entry->url : m_url;- set_url(current_url);+ set_url(traversable().session_history().current_entry().url);auto navigation_id = begin_webdriver_navigation(WebDriverNavigationCompletionSource::CrashRecovery);traversable().recover_from_web_content_process_crash([this, navigation_id](Web::HTML::HistoryStepResult, Optional<i32> committed_step) {if (committed_step.has_value())update_navigation_action_state();- auto const* current_entry = traversable().session_history().current_entry();- if (current_entry)- set_url(current_entry->url);+ set_url(traversable().session_history().current_entry().url);if (m_webdriver_navigation_observation.has_value()&& m_webdriver_navigation_observation->navigation_id == navigation_id@@ -3053,28 +3032,19 @@ void ViewImplementation::recover_current_session_history_entry_with_history_opervoid ViewImplementation::reconstruct_current_session_history_entry_with_history_operation(StringView reason){m_history_visit_transition_for_next_load = HistoryVisitTransition::Restore;- auto const* current_entry = traversable().session_history().current_entry();- if (!current_entry)- return;-- set_url(current_entry->url);+ set_url(traversable().session_history().current_entry().url);begin_webdriver_navigation(WebDriverNavigationCompletionSource::HistoryTraversal);traversable().reconstruct_the_history_to_step(traversable().session_history().current_step());dump_session_history(reason);}-Optional<SessionHistorySnapshot> ViewImplementation::session_history_snapshot() const+SessionHistorySnapshot ViewImplementation::session_history_snapshot() const{auto const& session_history = traversable().session_history();-- auto current_used_step_index = session_history.current_used_step_index();- if (!current_used_step_index.has_value())- return {};-return SessionHistorySnapshot {.entries = session_history.entries(),.used_steps = session_history.used_steps(),- .current_used_step_index = *current_used_step_index,+ .current_used_step_index = session_history.current_used_step_index(),};}@@ -3090,7 +3060,7 @@ ErrorOr<void> ViewImplementation::restore_session_history_from_snapshot(SessionHbool ViewImplementation::capture_session_history_snapshot_for_testing(Badge<WebContentPage>){m_captured_session_history_snapshot_for_testing = session_history_snapshot();- return m_captured_session_history_snapshot_for_testing.has_value();+ return true;}bool ViewImplementation::restore_captured_session_history_snapshot_for_testing(Badge<WebContentPage>)@@ -3155,9 +3125,7 @@ void ViewImplementation::notify_session_history_changed(){if (!m_session_tab_id.has_value())return;- auto url = m_url;- if (auto const* current_entry = traversable().session_history().current_entry())- url = current_entry->url;+ auto url = traversable().session_history().current_entry().url;SessionStore::TabStateUpdate update {.tab_id = *m_session_tab_id,.history = session_history_snapshot(),@@ -3199,10 +3167,8 @@ void ViewImplementation::request_history_operation(Badge<WebContentPage>, WebConif (m_webdriver_navigation_observation.has_value())complete_webdriver_navigation(m_webdriver_navigation_observation->navigation_id);}- if (finalizes_top_level_cross_document_navigation && result == Web::HTML::HistoryStepResult::Applied) {- if (auto const* current_entry = traversable().session_history().current_entry())- set_url(current_entry->url);- }+ if (finalizes_top_level_cross_document_navigation && result == Web::HTML::HistoryStepResult::Applied)+ set_url(traversable().session_history().current_entry().url);if (committed_step.has_value())update_navigation_action_state();dump_session_history("requested-history-operation-complete"sv);@@ -3259,8 +3225,7 @@ void ViewImplementation::handle_web_content_process_crash(){auto failed_url = m_url;Optional<NavigationToRetry> navigation_to_retry;- auto const* current_entry = traversable().session_history().current_entry();- if (!current_entry || current_entry->url != failed_url) {+ if (traversable().session_history().current_entry().url != failed_url) {navigation_to_retry = NavigationToRetry { failed_url, {} };if (auto ongoing = navigation_to_retry_for_ongoing_navigation(); ongoing.has_value() && ongoing->url == failed_url)navigation_to_retry = ongoing.release_value();diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex ed09045faeb..a6b0cc71cbf 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -171,7 +171,7 @@ public:Function<void()> on_ready = nullptr);[[nodiscard]] Vector<SessionHistoryTraversalMenuItem> session_history_traversal_menu_items(int direction) const;- [[nodiscard]] Optional<SessionHistorySnapshot> session_history_snapshot() const;+ [[nodiscard]] SessionHistorySnapshot session_history_snapshot() const;[[nodiscard]] ErrorOr<void> restore_session_history_from_snapshot(SessionHistorySnapshot);Optional<SessionTabId> session_tab_id() const { return m_session_tab_id; }diff --git a/Tests/LibWebView/TestApplyHistoryStep.cpp b/Tests/LibWebView/TestApplyHistoryStep.cppindex 1e42f37745d..69bf011fab6 100644--- a/Tests/LibWebView/TestApplyHistoryStep.cpp+++ b/Tests/LibWebView/TestApplyHistoryStep.cpp@@ -224,8 +224,7 @@ struct TestTraversable {VERIFY(history.initialize_for_testing({ initial_entry }, { 0 }, 0));initialize_navigable_entry_identities();- auto* current_entry = history.current_entry();- VERIFY(current_entry);+ auto* current_entry = &history.current_entry();VERIFY(history.replace_session_history_entry(traversable, *current_entry, MUST(WebView::CanonicalSessionHistoryEntry::create_from_descriptor(entry(0, "https://b.example/"sv)))));}@@ -246,9 +245,7 @@ struct TestTraversable {Optional<i32> current_step() const{- if (!history.current_used_step_index().has_value())- return {};- return history.step_at(*history.current_used_step_index());+ return history.step_at(history.current_used_step_index());}void initialize_navigable_entry_identities()@@ -798,7 +795,7 @@ TEST_CASE(a_paused_traversal_is_abandoned_once_a_jumping_push_removes_its_targetEXPECT(test.result == Web::HTML::HistoryStepResult::Applied);EXPECT(!test.operation->committed_step().has_value());EXPECT_EQ(test.current_step(), 2);- EXPECT_EQ(test.history.current_entry()->url, parse_url("https://b.example/pushed"sv));+ EXPECT_EQ(test.history.current_entry().url, parse_url("https://b.example/pushed"sv));EXPECT(!test.traversable.ongoing_navigation().has<WebView::CanonicalNavigable::Traversal>());}@@ -858,7 +855,7 @@ TEST_CASE(a_paused_push_appends_its_entry_again_once_a_jumping_push_clears_it)EXPECT(test.result == Web::HTML::HistoryStepResult::Applied);EXPECT_EQ(test.operation->committed_step(), 3);EXPECT_EQ(test.current_step(), 3);- EXPECT_EQ(test.history.current_entry()->url, navigation_entry->url);+ EXPECT_EQ(test.history.current_entry().url, navigation_entry->url);auto entries = test.history.get_session_history_entries(test.traversable);VERIFY(entries.has_value());EXPECT_EQ(entries->size(), 4u);@@ -870,7 +867,7 @@ TEST_CASE(a_paused_reload_continues_with_the_entry_that_a_jumping_replace_put_inCore::EventLoop event_loop;TestTraversable test;test.with_two_top_level_entries();- test.history.current_entry()->document_state->reload_pending = true;+ test.history.current_entry().document_state->reload_pending = true;// A same-document replace from the page being reloaded is queued behind the reload, and jumps the queue while the// reload waits on its changing job. It replaces the entry that the reload has claimed, keeping its navigation APIdiff --git a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp b/Tests/LibWebView/TestBrowserHistoryTraversal.cppindex 10f7c08f95b..9f6c83ba859 100644--- a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp+++ b/Tests/LibWebView/TestBrowserHistoryTraversal.cpp@@ -130,8 +130,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)});auto spare_view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });VERIFY(spare_view->traversable().session_history().current_step() == 0);- VERIFY(spare_view->traversable().session_history().current_entry());- VERIFY(spare_view->traversable().session_history().current_entry()->url == URL::about_blank());+ VERIFY(spare_view->traversable().session_history().current_entry().url == URL::about_blank());size_t spare_view_loads_finished = 0;spare_view->on_load_finish = [&](auto const&) { ++spare_view_loads_finished; };@@ -232,7 +231,6 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)// Reopening a closed tab restores its history into a view whose process is still starting up.auto closed_tab_history = view->session_history_snapshot();- VERIFY(closed_tab_history.has_value());auto closed_tab_url = view->url();// Closing a view may synchronously cause the UI to generate input, geometry, and visibility events while removing@@ -265,13 +263,13 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)bool restored_view_traversal_completed = false;restored_view->on_load_finish = [&](auto const&) { ++restored_view_loads_finished; };restored_view->on_browser_history_traversal_complete = [&] { restored_view_traversal_completed = true; };- MUST(restored_view->restore_session_history_from_snapshot(closed_tab_history.release_value()));+ MUST(restored_view->restore_session_history_from_snapshot(move(closed_tab_history)));Core::EventLoop::current().spin_until([&] {return restored_view_loads_finished >= 1&& restored_view->url() == closed_tab_url&& restored_view_traversal_completed;});- VERIFY(restored_view->traversable().session_history().current_entry()->url == closed_tab_url);+ VERIFY(restored_view->traversable().session_history().current_entry().url == closed_tab_url);// Exercise the record of pages the client was given across popup detachment and close// acknowledgement, without pumping the event loop between those transitions.diff --git a/Tests/LibWebView/TestCrashOverlay.cpp b/Tests/LibWebView/TestCrashOverlay.cppindex 2cb574b163b..aea5d8e149b 100644--- a/Tests/LibWebView/TestCrashOverlay.cpp+++ b/Tests/LibWebView/TestCrashOverlay.cpp@@ -86,7 +86,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(view->url() == failed_url);VERIFY(view->title() == "Failed page"_utf16);VERIFY(view->traversable().session_history().current_step() == history_step);- VERIFY(view->traversable().session_history().current_entry()->url == failed_url);+ VERIFY(view->traversable().session_history().current_entry().url == failed_url);VERIFY(view->crash_overlay_failed_url() == failed_url.serialize());};diff --git a/Tests/LibWebView/TestSessionHistory.cpp b/Tests/LibWebView/TestSessionHistory.cppindex 87c23ca11be..060bb422b7d 100644--- a/Tests/LibWebView/TestSessionHistory.cpp+++ b/Tests/LibWebView/TestSessionHistory.cpp@@ -286,8 +286,7 @@ static void expect_entry(WebView::TraversableSessionHistory const& history, sizestatic void expect_current_entry(WebView::TraversableSessionHistory const& history, i32 expected_step, StringView expected_url){- auto* entry = history.current_entry();- VERIFY(entry);+ auto* entry = &history.current_entry();EXPECT_EQ(entry->step, expected_step);EXPECT_EQ(entry->url, parse_url(expected_url));}@@ -414,8 +413,7 @@ TEST_CASE(entry_updates_require_entry_and_document_state_identity)entry_identity.navigation_api_id = Utf16String::from_utf8("current-id"sv);EXPECT(traversable.update_session_history_entry_scroll_restoration_mode(traversable, entry_identity, Web::HTML::ScrollRestorationMode::Manual));- auto const* updated_entry = traversable.session_history().current_entry();- VERIFY(updated_entry);+ auto const* updated_entry = &traversable.session_history().current_entry();EXPECT_EQ(updated_entry->scroll_restoration_mode, Web::HTML::ScrollRestorationMode::Manual);}@@ -469,8 +467,7 @@ TEST_CASE(queued_same_document_entries_are_addressed_by_identity)EXPECT_EQ(queued_entries[0]->scroll_restoration_mode, Web::HTML::ScrollRestorationMode::Auto);EXPECT(queued_entries[1]->navigation_api_state == state_record(9));EXPECT_EQ(queued_entries[1]->scroll_restoration_mode, Web::HTML::ScrollRestorationMode::Manual);- auto const* updated_current_entry = traversable.session_history().current_entry();- VERIFY(updated_current_entry);+ auto const* updated_current_entry = &traversable.session_history().current_entry();EXPECT_EQ(updated_current_entry->document_state->navigable_target_name, Utf16String::from_utf8("updated-name"sv));}@@ -748,8 +745,7 @@ TEST_CASE(clear_forward_session_history_rebuilds_traversal_state)expect_used_step(history, 1, 1);EXPECT(!history.step_at(2).has_value());- auto* current_entry = history.current_entry();- VERIFY(current_entry);+ auto* current_entry = &history.current_entry();expect_nested_history(*current_entry, 0, "frame-1"sv, 2);expect_nested_entry(current_entry->document_state->nested_histories[0], 0, 0, "https://frame.example/a"sv);expect_nested_entry(current_entry->document_state->nested_histories[0], 1, 1, "https://frame.example/b"sv);@@ -823,8 +819,7 @@ TEST_CASE(history_log_entries_marks_current_entries_steps_and_reload_pending)"nested={1:2=[3:https://frame.example/]}] ""used_steps=[0:0, *1:1, 2:2, 3:3]"sv });- auto current_entry = history.current_entry();- VERIFY(current_entry);+ auto* current_entry = &history.current_entry();auto serialized_entry = WebView::history_json_entry(current_entry->descriptor(), true);EXPECT_EQ(serialized_entry.get_string("resource"sv), "post"sv);@@ -873,8 +868,7 @@ TEST_CASE(cross_document_push_preserves_document_resource)EXPECT_EQ(*target_step, 1);history.set_current_session_history_step(1);- auto current_entry = history.current_entry();- VERIFY(current_entry);+ auto* current_entry = &history.current_entry();expect_entry_resource(current_entry->descriptor(), "post"sv);}@@ -913,8 +907,7 @@ TEST_CASE(cross_document_replacement_preserves_forward_history)expect_used_step(history, 0, 0);expect_used_step(history, 1, 2);- auto* current_entry = history.current_entry();- VERIFY(current_entry);+ auto* current_entry = &history.current_entry();EXPECT(current_entry->document_state->id.namespace_id > 0);EXPECT(current_entry->document_state->id.local_id > 0);EXPECT(current_entry->document_state->navigable_target_name.is_empty());diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cppindex 6cda095ff19..ad44700e8f6 100644--- a/UI/Qt/BrowserWindow.cpp+++ b/UI/Qt/BrowserWindow.cpp@@ -505,7 +505,7 @@ void BrowserWindow::duplicate_tab(Tab& source_tab)auto source_url = source_tab.view().url();auto& duplicate = create_new_tab(Web::HTML::ActivateTab::Yes, TabLocation::after_tab(source_tab));- if (!history.has_value() || duplicate.view().restore_session_history_from_snapshot(history.release_value()).is_error())+ if (duplicate.view().restore_session_history_from_snapshot(AK::move(history)).is_error())duplicate.navigate(source_url);}