diff options
author | stelar7 <dudedbz@gmail.com> | 2023-06-01 09:38:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-06-01 14:28:52 +0200 |
commit | 9c74f49b1ddacd56dd35667b0fa76ff4de422c19 (patch) | |
tree | 546d8bcb7a815a5492099c275b7debedb5dcc618 | |
parent | 29029de83901847ba97a5994c870ef2fa6b2e9b9 (diff) | |
download | serenity-9c74f49b1ddacd56dd35667b0fa76ff4de422c19.zip |
LibWeb: Implement `has_transient_activation`
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Window.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 41fcfe60fa..e434b64351 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -621,7 +621,23 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Storage>> Window::session_storage() // https://html.spec.whatwg.org/multipage/interaction.html#transient-activation bool Window::has_transient_activation() const { - // FIXME: Implement this. + // The transient activation duration is expected be at most a few seconds, so that the user can possibly + // perceive the link between an interaction with the page and the page calling the activation-gated API. + auto transient_activation_duration = 5; + + // When the current high resolution time given W + auto unsafe_shared_time = HighResolutionTime::unsafe_shared_current_time(); + auto current_time = HighResolutionTime::relative_high_resolution_time(unsafe_shared_time, realm().global_object()); + + // is greater than or equal to the last activation timestamp in W + if (current_time >= m_last_activation_timestamp) { + // and less than the last activation timestamp in W plus the transient activation duration + if (current_time < m_last_activation_timestamp + transient_activation_duration) { + // then W is said to have transient activation. + return true; + } + } + return false; } |