diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.cpp b/Userland/Libraries/LibWeb/HTML/Navigation.cpp index 25f818ae262..de1a02edd74 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigation.cpp @@ -909,29 +909,6 @@ void Navigation::notify_about_the_committed_to_entry(JS::NonnullGCPtrcommitted_promise, nhe); } -// https://html.spec.whatwg.org/multipage/interaction.html#consume-history-action-user-activation -void Navigation::consume_history_action_user_activation(Window& w) -{ - // 1. If W's navigable is null, then return. - if (!w.navigable()) - return; - - // 2. Let top be W's navigable's top-level traversable. - auto top = w.navigable()->top_level_traversable(); - - // 3. Let navigables be the inclusive descendant navigables of top's active document. - auto navigables = top->active_document()->inclusive_descendant_navigables(); - - // 4. Let windows be the list of Window objects constructed by taking the active window of each item in navigables. - Vector> windows; - for (auto& navigable : navigables) - windows.append(navigable->active_window()); - - // 5. For each window in windows, set window's last history-action activation timestamp to window's last activation timestamp. - for (auto& window : windows) - window->set_last_history_action_activation_timestamp(window->last_activation_timestamp()); -} - // https://html.spec.whatwg.org/multipage/nav-history-apis.html#inner-navigate-event-firing-algorithm bool Navigation::inner_navigate_event_firing_algorithm( Bindings::NavigationType navigation_type, @@ -1093,9 +1070,9 @@ bool Navigation::inner_navigate_event_firing_algorithm( // 29. If dispatchResult is false: if (!dispatch_result) { - // 1. If navigationType is "traverse", then consume history-action user activation. + // 1. If navigationType is "traverse", then consume history-action user activation given navigation's relevant global object. if (navigation_type == Bindings::NavigationType::Traverse) - consume_history_action_user_activation(relevant_global_object); + relevant_global_object.consume_history_action_user_activation(); // 2. If event's abort controller's signal is not aborted, then abort the ongoing navigation given navigation. if (!event->abort_controller()->signal()->aborted()) diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.h b/Userland/Libraries/LibWeb/HTML/Navigation.h index fbd0e66900f..25319147e18 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.h +++ b/Userland/Libraries/LibWeb/HTML/Navigation.h @@ -150,7 +150,6 @@ private: void reject_the_finished_promise(JS::NonnullGCPtr, JS::Value exception); void clean_up(JS::NonnullGCPtr); void notify_about_the_committed_to_entry(JS::NonnullGCPtr, JS::NonnullGCPtr); - void consume_history_action_user_activation(Window& window); bool inner_navigate_event_firing_algorithm( Bindings::NavigationType, diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index ac8baea3bc8..8147a7441de 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -638,6 +638,31 @@ bool Window::has_history_action_activation() const return m_last_history_action_activation_timestamp != m_last_activation_timestamp; } +// https://html.spec.whatwg.org/multipage/interaction.html#consume-history-action-user-activation +void Window::consume_history_action_user_activation() +{ + auto navigable = this->navigable(); + + // 1. If W's navigable is null, then return. + if (navigable == nullptr) + return; + + // 2. Let top be W's navigable's top-level traversable. + auto top = navigable->top_level_traversable(); + + // 3. Let navigables be the inclusive descendant navigables of top's active document. + auto navigables = top->active_document()->inclusive_descendant_navigables(); + + // 4. Let windows be the list of Window objects constructed by taking the active window of each item in navigables. + JS::MarkedVector> windows(heap()); + for (auto& n : navigables) + windows.append(n->active_window()); + + // 5. For each window in windows, set window's last history-action activation timestamp to window's last activation timestamp. + for (auto& window : windows) + window->set_last_history_action_activation_timestamp(window->last_activation_timestamp()); +} + // https://w3c.github.io/requestidlecallback/#start-an-idle-period-algorithm void Window::start_an_idle_period() { diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index c32dbfbd8db..23dfa015494 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -220,6 +220,8 @@ public: HighResolutionTime::DOMHighResTimeStamp last_history_action_activation_timestamp() const { return m_last_history_action_activation_timestamp; } void set_last_history_action_activation_timestamp(HighResolutionTime::DOMHighResTimeStamp timestamp) { m_last_history_action_activation_timestamp = timestamp; } + void consume_history_action_user_activation(); + static void set_inspector_object_exposed(bool); static void set_internals_object_exposed(bool);