Truly independent web browser
LibWebView+AudioServer+UI/Qt: Linger tab indicators in the UI process
Luke Wildeadadc10ce6ac
diff --git a/Libraries/LibAudio/Audibility.h b/Libraries/LibAudio/Audibility.hindex 465b3797384..13e90109775 100644--- a/Libraries/LibAudio/Audibility.h+++ b/Libraries/LibAudio/Audibility.h@@ -17,7 +17,8 @@ enum class Audibility : u8 {Audible,};-// How long a group goes on counting as audible after its sound stops.-static constexpr AK::Duration AUDIBILITY_LINGER = AK::Duration::from_seconds(3);+// How long a group goes on counting as audible after its sound stops, so a pause between sounds isn't reported as one+// sound ending and another starting.+static constexpr AK::Duration AUDIBILITY_SMOOTHING = AK::Duration::from_milliseconds(500);}diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 87cf03e1616..2257c0739b3 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -2344,6 +2344,11 @@ bool Internals::tab_is_playing_audio()return window().associated_document().page().client().page_did_request_tab_is_playing_audio_for_testing();}+bool Internals::tab_is_heard_playing_audio()+{+ return window().associated_document().page().client().page_did_request_tab_is_heard_playing_audio_for_testing();+}+WebIDL::UnsignedLongLong Internals::tab_audibility_change_count(){return window().associated_document().page().client().page_did_request_tab_audibility_change_count_for_testing();diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex 29e34c33a06..e82300aea89 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -356,6 +356,7 @@ public:bool media_element_is_playing_audio(HTML::HTMLMediaElement&);bool document_is_playing_audio(DOM::Document&);bool tab_is_playing_audio();+ bool tab_is_heard_playing_audio();WebIDL::UnsignedLongLong tab_audibility_change_count();bool media_element_video_sink_is_ticking(HTML::HTMLMediaElement&);void set_media_element_ready_state(HTML::HTMLMediaElement&, u16 ready_state);diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex a483de5919b..ce7ccca82b1 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -463,8 +463,11 @@ interface Internals {boolean mediaElementIsFetching(HTMLMediaElement element);boolean mediaElementIsPlayingAudio(HTMLMediaElement element);boolean documentIsPlayingAudio(Document document);- // Whether the UI process shows this window's tab as playing audio, which the AudioServer decides by what it hears.+ // Whether the UI process shows this window's tab as playing audio: while the AudioServer has recently heard the tab,+ // and for a while after.boolean tabIsPlayingAudio();+ // Whether the AudioServer has recently heard this window's tab, whatever the tab shows.+ boolean tabIsHeardPlayingAudio();// How many times the UI process has changed whether this window's tab is shown as playing audio.unsigned long long tabAudibilityChangeCount();boolean mediaElementVideoSinkIsTicking(HTMLMediaElement element);diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex bc45956fc5b..ad2bcc31588 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -886,6 +886,7 @@ public:virtual String page_did_request_ui_process_session_history_for_testing() { return "{}"_string; }virtual bool page_did_request_has_populated_document_for_testing([[maybe_unused]] HTML::CrossProcessId navigable_id) { return false; }virtual bool page_did_request_tab_is_playing_audio_for_testing() { return false; }+ virtual bool page_did_request_tab_is_heard_playing_audio_for_testing() { return false; }virtual u64 page_did_request_tab_audibility_change_count_for_testing() { return 0; }virtual bool page_did_request_capture_session_history_snapshot_for_testing() { return false; }virtual bool page_did_request_restore_session_history_snapshot_for_testing() { return false; }diff --git a/Libraries/LibWebView/AudibilityHold.cpp b/Libraries/LibWebView/AudibilityHold.cppdeleted file mode 100644index d8998b6216d..00000000000--- a/Libraries/LibWebView/AudibilityHold.cpp+++ /dev/null@@ -1,38 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibAudio/Audibility.h>-#include <LibWebView/AudibilityHold.h>--namespace WebView {--void AudibilityHold::page_began_hosting(Web::PageId page_id)-{- m_left_pages.remove(page_id);-}--bool AudibilityHold::page_left(Web::PageId page_id, MonotonicTime now)-{- if (m_left_pages.set(page_id) != HashSetResult::InsertedNewEntry)- return false;- auto held_until = now + Audio::AUDIBILITY_LINGER;- if (m_held_until.has_value() && *m_held_until >= held_until)- return false;- m_held_until = held_until;- return true;-}--void AudibilityHold::page_closed(Web::PageId page_id)-{- m_left_pages.remove(page_id);-}--bool AudibilityHold::is_held(MonotonicTime now) const-{- return m_held_until.has_value() && now < *m_held_until;-}--}diff --git a/Libraries/LibWebView/AudibilityHold.h b/Libraries/LibWebView/AudibilityHold.hdeleted file mode 100644index 61ed0480a15..00000000000--- a/Libraries/LibWebView/AudibilityHold.h+++ /dev/null@@ -1,34 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/HashTable.h>-#include <AK/Optional.h>-#include <AK/Time.h>-#include <LibWebCommon/Page/PageId.h>-#include <LibWebView/Export.h>--namespace WebView {--// Keeps a tab audible after an audible page leaves it, for as long as the page would have lingered had its sound stopped-// as it left. A page leaves once each time it begins hosting the tab's documents. Closing isn't leaving: a closed page-// holds nothing, and ends no hold.-class WEBVIEW_API AudibilityHold {-public:- void page_began_hosting(Web::PageId);- bool page_left(Web::PageId, MonotonicTime now);- void page_closed(Web::PageId);-- bool is_held(MonotonicTime now) const;- Optional<MonotonicTime> held_until() const { return m_held_until; }--private:- HashTable<Web::PageId> m_left_pages;- Optional<MonotonicTime> m_held_until;-};--}diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txtindex 2562d3ac870..73255813250 100644--- a/Libraries/LibWebView/CMakeLists.txt+++ b/Libraries/LibWebView/CMakeLists.txt@@ -2,7 +2,6 @@ set(SOURCESAccessibilityTreeManager.cppApplication.cppApplyHistoryStep.cpp- AudibilityHold.cppAudioServerAudibility.cppAudioServerControlClient.cppAutocomplete.cpp@@ -43,6 +42,7 @@ set(SOURCESHistoryDebug.cppHistoryStore.cppHSTSStore.cpp+ LingeringIndicator.cppMenu.cppNavigationLoader.cppOmnibox.cpp@@ -56,6 +56,7 @@ set(SOURCESProcess.cppProcessManager.cppProcessSnapshot.cpp+ TabIndicators.cppTabPerformanceStats.cppTabPerformanceMonitor.cppProcessMonitor.cppdiff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 30dfc964858..2fc67ca7faa 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -414,7 +414,7 @@ void CanonicalTraversable::release_page_if_unused(NonnullRefPtr<WebContentPage>if (auto* bidi = WebDriverBiDi::the())bidi->push_session_state_for_client(page->client());if (auto view = this->view(); view.has_value())- view->did_release_page({}, page);+ view->did_release_page({});page->client().revoke_audio_playback(page->id());// A page left hosting none of the tab's documents goes on representing the tab to a process holding part of// another tab of its group, whose documents can hold the tab's WindowProxies.diff --git a/Libraries/LibWebView/LingeringIndicator.cpp b/Libraries/LibWebView/LingeringIndicator.cppnew file mode 100644index 00000000000..5e217e936a2--- /dev/null+++ b/Libraries/LibWebView/LingeringIndicator.cpp@@ -0,0 +1,27 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibWebView/LingeringIndicator.h>++namespace WebView {++void LingeringIndicator::set_active(bool active, MonotonicTime now)+{+ if (active == m_active)+ return;+ m_active = active;+ if (active)+ m_visible_until.clear();+ else+ m_visible_until = now + m_linger;+}++bool LingeringIndicator::is_visible(MonotonicTime now) const+{+ return m_active || (m_visible_until.has_value() && now < *m_visible_until);+}++}diff --git a/Libraries/LibWebView/LingeringIndicator.h b/Libraries/LibWebView/LingeringIndicator.hnew file mode 100644index 00000000000..b7258448074--- /dev/null+++ b/Libraries/LibWebView/LingeringIndicator.h@@ -0,0 +1,37 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Optional.h>+#include <AK/Time.h>+#include <LibWebView/Export.h>++namespace WebView {++// Shows an indicator while what it indicates is active, and for a linger once that stops, so the user sees it happened+// even when it stops at once. Only stopping starts the linger: being told again that it's inactive doesn't extend it,+// and becoming active again cancels it.+class WEBVIEW_API LingeringIndicator {+public:+ explicit LingeringIndicator(AK::Duration linger)+ : m_linger(linger)+ {+ }++ void set_active(bool, MonotonicTime now);++ bool is_active() const { return m_active; }+ bool is_visible(MonotonicTime now) const;+ Optional<MonotonicTime> visible_until() const { return m_visible_until; }++private:+ AK::Duration m_linger;+ bool m_active { false };+ Optional<MonotonicTime> m_visible_until;+};++}diff --git a/Libraries/LibWebView/TabIndicators.cpp b/Libraries/LibWebView/TabIndicators.cppnew file mode 100644index 00000000000..35ff6e6eb84--- /dev/null+++ b/Libraries/LibWebView/TabIndicators.cpp@@ -0,0 +1,83 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibCore/Timer.h>+#include <LibWebView/TabIndicators.h>++namespace WebView {++TabIndicators::TabIndicators()+ : m_timer(Core::Timer::create_single_shot(AK::Duration::zero(), [this] {+ // The deadlines, not the timer's resolution, decide when an indicator stops showing.+ update_visibility(MonotonicTime::now());+ }))+{+}++TabIndicators::~TabIndicators() = default;++void TabIndicators::set_active(TabIndicator indicator, bool active, MonotonicTime now)+{+ auto& lingering = entry(indicator).lingering;+ lingering.set_active(active, now);++ // Even when the indicator's activity hasn't changed, another's deadline may have passed without the timer having+ // run yet.+ update_visibility(now);+}++bool TabIndicators::is_active(TabIndicator indicator) const+{+ auto const& lingering = entry(indicator).lingering;+ return lingering.is_active();+}++void TabIndicators::update_visibility(MonotonicTime now)+{+ for (auto& entry : m_entries)+ entry.visible = entry.lingering.is_visible(now);++ // Wake before notifying, so a listener that makes an indicator active again schedules from settled state.+ if (auto deadline = next_deadline(now); deadline.has_value())+ m_timer->restart(*deadline - now);+ else+ m_timer->stop();++ // A listener that changes an indicator reports it from a nested update, so an indicator is reported only while what+ // was last reported for it is out of date.+ for (auto& entry : m_entries) {+ if (entry.reported_visible == entry.visible)+ continue;++ entry.reported_visible = entry.visible;+ if (on_visibility_change)+ on_visibility_change(entry.indicator, entry.visible);+ }+}++TabIndicators::Entry& TabIndicators::entry(TabIndicator indicator)+{+ for (auto& entry : m_entries) {+ if (entry.indicator == indicator)+ return entry;+ }+ VERIFY_NOT_REACHED();+}++Optional<MonotonicTime> TabIndicators::next_deadline(MonotonicTime now) const+{+ Optional<MonotonicTime> next_deadline;+ for (auto const& entry : m_entries) {+ auto deadline = entry.lingering.visible_until();+ if (!deadline.has_value() || *deadline <= now)+ continue;+ if (!next_deadline.has_value() || *deadline < *next_deadline)+ next_deadline = deadline;+ }+ return next_deadline;+}++}diff --git a/Libraries/LibWebView/TabIndicators.h b/Libraries/LibWebView/TabIndicators.hnew file mode 100644index 00000000000..910afd72b20--- /dev/null+++ b/Libraries/LibWebView/TabIndicators.h@@ -0,0 +1,64 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Array.h>+#include <AK/Function.h>+#include <AK/Noncopyable.h>+#include <AK/NonnullRefPtr.h>+#include <AK/Optional.h>+#include <AK/Time.h>+#include <LibCore/Forward.h>+#include <LibWebView/Export.h>+#include <LibWebView/LingeringIndicator.h>++namespace WebView {++enum class TabIndicator : u8 {+ PlayingAudio,+ UsingLocation,+};++// Each indicator lingers on a deadline of its own once what it shows stops, however it stopped.+class WEBVIEW_API TabIndicators {+ AK_MAKE_NONCOPYABLE(TabIndicators);+ AK_MAKE_NONMOVABLE(TabIndicators);++public:+ static constexpr AK::Duration LINGER = AK::Duration::from_seconds(3);++ TabIndicators();+ ~TabIndicators();++ Function<void(TabIndicator, bool visible)> on_visibility_change;++ void set_active(TabIndicator, bool active, MonotonicTime now);+ bool is_active(TabIndicator) const;+ bool is_visible(TabIndicator indicator) const { return entry(indicator).visible; }++ void update_visibility(MonotonicTime now);+ Optional<MonotonicTime> next_deadline(MonotonicTime now) const;++private:+ struct Entry {+ TabIndicator indicator;+ LingeringIndicator lingering { LINGER };+ bool visible { false };+ bool reported_visible { false };+ };++ Entry& entry(TabIndicator);+ Entry const& entry(TabIndicator indicator) const { return const_cast<TabIndicators&>(*this).entry(indicator); }++ Array<Entry, 2> m_entries {+ Entry { .indicator = TabIndicator::PlayingAudio },+ Entry { .indicator = TabIndicator::UsingLocation },+ };+ NonnullRefPtr<Core::Timer> m_timer;+};++}diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex bf43f16a8b3..fa9edf7cbfb 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -101,25 +101,21 @@ ViewImplementation::ViewImplementation(IsPrivate is_private)this->m_crash_count = 0;});- m_audibility_hold_timer = Core::Timer::create_single_shot(AK::Duration::zero(), [this] {- // The hold, not the timer's resolution, decides when it has ended.- auto now = MonotonicTime::now();- if (m_audibility_hold.is_held(now)) {- m_audibility_hold_timer->restart(*m_audibility_hold.held_until() - now);- return;- }- update_audibility();- });+ m_tab_indicators.on_visibility_change = [this](TabIndicator indicator, bool visible) {+ if (indicator == TabIndicator::PlayingAudio)+ ++m_playing_audio_indicator_change_count;+ if (on_tab_indicator_change)+ on_tab_indicator_change(indicator, visible);+ };}ViewImplementation::~ViewImplementation(){// The frontend may be torn down already, so clearing the ongoing navigation must not report a URL change to it, nor- // cancelling the view's location requests that the location is no longer in use, nor closing the view's page (which- // revokes its audio playback) that the tab went quiet.+ // cancelling the view's location requests or closing the view's page (which revokes its audio playback) a change+ // in what the tab shows.on_url_change = nullptr;- on_location_in_use_change = nullptr;- on_audibility_changed = nullptr;+ on_tab_indicator_change = nullptr;answer_pending_console_input_completions();TabPerformanceMonitor::forget_view(view_id());// Leave the views before the permission manager hears: a one-time grant that ends with this view has it revoke@@ -2956,28 +2952,12 @@ void ViewImplementation::toggle_page_mute_state()void ViewImplementation::update_audibility(){- auto audibility = Audio::Audibility::Inaudible;- if (m_audibility_hold.is_held(MonotonicTime::now()))- audibility = Audio::Audibility::Audible;+ auto audible = false;traversable().for_each_hosting_page([&](WebContentPage& page) {if (page.audibility() == Audio::Audibility::Audible)- audibility = Audio::Audibility::Audible;+ audible = true;});- if (m_audibility == audibility)- return;- m_audibility = audibility;- ++m_audibility_change_count;- if (on_audibility_changed)- on_audibility_changed(m_audibility);-}--void ViewImplementation::page_left(WebContentPage const& page)-{- if (page.audibility() != Audio::Audibility::Audible)- return;- auto now = MonotonicTime::now();- if (m_audibility_hold.page_left(page.id(), now))- m_audibility_hold_timer->restart(*m_audibility_hold.held_until() - now);+ m_tab_indicators.set_active(TabIndicator::PlayingAudio, audible, MonotonicTime::now());}void ViewImplementation::reset_page_media_state()@@ -3547,7 +3527,6 @@ void ViewImplementation::prepare_page_for_navigable(WebContentPage& page)// The page's sound plays while it hosts the tab's documents, unless the tab is muted.page.client().set_audio_playback_mute_state(page.id(), m_mute_state);page.client().authorize_audio_playback(page.id());- m_audibility_hold.page_began_hosting(page.id());if (Application::browser_options().webdriver_browser_endpoint.has_value())Application::the().push_webdriver_session_config(page);Application::the().apply_view_options({}, *this, page);@@ -3608,15 +3587,6 @@ void ViewImplementation::display_page_changed(RefPtr<WebContentPage> previous_pam_debugger_overlay_pointer_state.reset();fail_pending_debugger_requests();reject_pending_selection_requests();-- // The previous page leaves the tab now, before it is let go of, unless it goes on hosting some of it.- auto previous_page_goes_on_hosting = false;- traversable().for_each_hosting_page([&](WebContentPage& page) {- if (&page == previous_page.ptr())- previous_page_goes_on_hosting = true;- });- if (!previous_page_goes_on_hosting)- page_left(*previous_page);reset_page_media_state();// Keep showing the outgoing page until the page paints its first frame.@@ -4667,11 +4637,7 @@ u64 ViewImplementation::system_microphone_requests_for_testing() constvoid ViewImplementation::update_location_in_use(){auto in_use = !m_geolocation_position_request_ids.is_empty() || !m_geolocation_watch_ids.is_empty();- if (in_use == m_location_in_use)- return;- m_location_in_use = in_use;- if (on_location_in_use_change)- on_location_in_use_change(in_use);+ m_tab_indicators.set_active(TabIndicator::UsingLocation, in_use, MonotonicTime::now());}void ViewImplementation::revoke_geolocation_without_permission()diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex db97a517f15..9ddf06cb960 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -69,7 +69,6 @@#include <LibWebCommon/WebView/PageInfo.h>#include <LibWebCommon/WebView/StorageSetResult.h>#include <LibWebCommon/WebView/ZoomLevel.h>-#include <LibWebView/AudibilityHold.h>#include <LibWebView/BookmarkStore.h>#include <LibWebView/BrowsingSession.h>#include <LibWebView/CanonicalTraversable.h>@@ -83,6 +82,7 @@#include <LibWebView/SessionStore.h>#include <LibWebView/Settings.h>#include <LibWebView/SpellChecker.h>+#include <LibWebView/TabIndicators.h>#include <LibWebView/TabPerformanceStats.h>#include <LibWebView/WebContentClient.h>#include <LibWebView/WebContentPage.h>@@ -181,7 +181,7 @@ public:u64 system_microphone_requests_for_testing() const;u64 microphone_denied_notices_shown_for_testing() const { return m_microphone_denied_notices_shown; }- bool location_in_use() const { return m_location_in_use; }+ bool location_in_use() const { return m_tab_indicators.is_active(TabIndicator::UsingLocation); }// Ends every location request and watch whose document the user has since taken the permission away from.void revoke_geolocation_without_permission();@@ -510,13 +510,13 @@ public:Web::HTML::MuteState page_mute_state() const { return m_mute_state; }void toggle_page_mute_state();- // The tab is audible while the AudioServer has recently heard any page of it, and for a while after a page leaves it- // while heard. A page lost along with its process doesn't leave.+ // The tab plays audio while the AudioServer has recently heard any page of it.void update_audibility(Badge<WebContentPage>) { update_audibility(); }- void did_release_page(Badge<CanonicalTraversable>, WebContentPage const& page) { page_left(page); }- void did_close_page(Badge<WebContentPage>, Web::PageId page_id) { m_audibility_hold.page_closed(page_id); }- Audio::Audibility audibility() const { return m_audibility; }- u64 audibility_change_count() const { return m_audibility_change_count; }+ void did_release_page(Badge<CanonicalTraversable>) { update_audibility(); }+ bool is_playing_audio() const { return m_tab_indicators.is_active(TabIndicator::PlayingAudio); }++ bool tab_indicator_visible(TabIndicator indicator) const { return m_tab_indicators.is_visible(indicator); }+ u64 playing_audio_indicator_change_count() const { return m_playing_audio_indicator_change_count; }void did_change_screen_wake_lock_state(Badge<WebContentPage>, Web::ScreenWakeLockState);void did_reset_state_for_testing(Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor);@@ -664,7 +664,7 @@ public:Function<void(WebContentPage& requesting_page, u64 request_id)> on_stop_geolocation_position_watch;Function<void(PermissionPromptRequest const&, PermissionPromptCallback)> on_request_permission;Function<void(PermissionPromptRequest const&)> on_cancel_permission_prompt;- Function<void(bool)> on_location_in_use_change;+ Function<void(TabIndicator, bool visible)> on_tab_indicator_change;Function<void(Web::HTML::FileFilter const& accepted_file_types, Web::HTML::AllowMultipleFiles)> on_request_file_picker;Function<void(Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items)> on_request_select_dropdown;Function<void(Web::KeyEvent const&)> on_finish_handling_key_event;@@ -677,7 +677,6 @@ public:Function<void(size_t current_match_index, Optional<size_t> const& total_match_count)> on_find_in_page;Function<void(Gfx::Color)> on_theme_color_change;Function<void(Gfx::Color)> on_page_background_color_change;- Function<void(Audio::Audibility)> on_audibility_changed;Function<void(Web::ScreenWakeLockState)> on_screen_wake_lock_state_changed;enum class WebContentCrashReason {ProcessCrash,@@ -823,7 +822,6 @@ protected:WebContentPage& focused_navigable_host() const;void reset_page_media_state();void update_audibility();- void page_left(WebContentPage const&);// A navigation to make again on reload: one the user stopped before its document was activated, or one a crash cut// short. It's made again from the source it was first made from, when it has one (a javascript: URL has none).@@ -1116,10 +1114,8 @@ protected:// https://w3c.github.io/webdriver/#dfn-current-parent-browsing-contextOptional<Web::HTML::CrossProcessId> m_webdriver_current_parent_navigable_id;- Audio::Audibility m_audibility { Audio::Audibility::Inaudible };- u64 m_audibility_change_count { 0 };- AudibilityHold m_audibility_hold;- RefPtr<Core::Timer> m_audibility_hold_timer;+ TabIndicators m_tab_indicators;+ u64 m_playing_audio_indicator_change_count { 0 };Web::ScreenWakeLockState m_screen_wake_lock_state { Web::ScreenWakeLockState::Released };Web::HTML::MuteState m_mute_state { Web::HTML::MuteState::Unmuted };@@ -1162,7 +1158,6 @@ protected:HashMap<GeolocationRequestKey, Core::GeolocationProvider::RequestId> m_geolocation_position_request_ids;HashMap<GeolocationRequestKey, Core::GeolocationProvider::WatchId> m_geolocation_watch_ids;HashMap<GeolocationRequestKey, Web::HTML::CrossProcessId> m_geolocation_request_documents;- bool m_location_in_use { false };Vector<Web::Permissions::PermissionName> m_permissions_requested_by_page;struct PendingPermissionPrompt {diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex cde1ab2695a..f0c7fc833eb 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -663,10 +663,6 @@ void WebContentPage::close()m_client->forget_audio_playback(m_id);GamepadManager::the().page_closed(*this);}- if (m_traversable) {- if (auto view = m_traversable->view(); view.has_value())- view->did_close_page({}, m_id);- }set_audibility(Audio::Audibility::Inaudible);m_web_ui = nullptr;auto owed_replies = move(m_owed_replies);@@ -3394,13 +3390,19 @@ Messages::WebContentTestClient::DidRequestSiteIsolationProcessTreeForTestingRespMessages::WebContentTestClient::DidRequestTabIsPlayingAudioForTestingResponse WebContentPage::did_request_tab_is_playing_audio_for_testing(){auto view = traversable().view();- return view.has_value() && view->audibility() == Audio::Audibility::Audible;+ return view.has_value() && view->tab_indicator_visible(TabIndicator::PlayingAudio);+}++Messages::WebContentTestClient::DidRequestTabIsHeardPlayingAudioForTestingResponse WebContentPage::did_request_tab_is_heard_playing_audio_for_testing()+{+ auto view = traversable().view();+ return view.has_value() && view->is_playing_audio();}Messages::WebContentTestClient::DidRequestTabAudibilityChangeCountForTestingResponse WebContentPage::did_request_tab_audibility_change_count_for_testing(){auto view = traversable().view();- return view.has_value() ? view->audibility_change_count() : 0;+ return view.has_value() ? view->playing_audio_indicator_change_count() : 0;}void WebContentPage::did_request_crash_of_remote_frame_processes_for_testing()diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.hindex 859be6dfa1e..c5b8e80768e 100644--- a/Libraries/LibWebView/WebContentPage.h+++ b/Libraries/LibWebView/WebContentPage.h@@ -403,6 +403,7 @@ private:Messages::WebContentTestClient::DidRequestUiProcessSessionHistoryForTestingResponse did_request_ui_process_session_history_for_testing();Messages::WebContentTestClient::DidRequestSiteIsolationProcessTreeForTestingResponse did_request_site_isolation_process_tree_for_testing();Messages::WebContentTestClient::DidRequestTabIsPlayingAudioForTestingResponse did_request_tab_is_playing_audio_for_testing();+ Messages::WebContentTestClient::DidRequestTabIsHeardPlayingAudioForTestingResponse did_request_tab_is_heard_playing_audio_for_testing();Messages::WebContentTestClient::DidRequestTabAudibilityChangeCountForTestingResponse did_request_tab_audibility_change_count_for_testing();virtual void did_request_crash_of_remote_frame_processes_for_testing() override;virtual void did_request_stop_loading_for_testing() override;diff --git a/Libraries/LibWebView/WebContentTestClient.cpp b/Libraries/LibWebView/WebContentTestClient.cppindex 828fa017da7..12284557e61 100644--- a/Libraries/LibWebView/WebContentTestClient.cpp+++ b/Libraries/LibWebView/WebContentTestClient.cpp@@ -129,6 +129,14 @@ Messages::WebContentTestClient::DidRequestTabIsPlayingAudioForTestingResponse Wereturn false;}+Messages::WebContentTestClient::DidRequestTabIsHeardPlayingAudioForTestingResponse WebContentTestClient::did_request_tab_is_heard_playing_audio_for_testing(Web::PageId page_id)+{+ if (auto* page = m_client.page(page_id))+ return page->did_request_tab_is_heard_playing_audio_for_testing();++ return false;+}+Messages::WebContentTestClient::DidRequestTabAudibilityChangeCountForTestingResponse WebContentTestClient::did_request_tab_audibility_change_count_for_testing(Web::PageId page_id){if (auto* page = m_client.page(page_id))diff --git a/Libraries/LibWebView/WebContentTestClient.h b/Libraries/LibWebView/WebContentTestClient.hindex bfd80c8ecaa..facad6ff59d 100644--- a/Libraries/LibWebView/WebContentTestClient.h+++ b/Libraries/LibWebView/WebContentTestClient.h@@ -38,6 +38,7 @@ private:virtual Messages::WebContentTestClient::DidRequestUiProcessSessionHistoryForTestingResponse did_request_ui_process_session_history_for_testing(Web::PageId page_id) override;virtual Messages::WebContentTestClient::DidRequestSiteIsolationProcessTreeForTestingResponse did_request_site_isolation_process_tree_for_testing(Web::PageId page_id) override;virtual Messages::WebContentTestClient::DidRequestTabIsPlayingAudioForTestingResponse did_request_tab_is_playing_audio_for_testing(Web::PageId page_id) override;+ virtual Messages::WebContentTestClient::DidRequestTabIsHeardPlayingAudioForTestingResponse did_request_tab_is_heard_playing_audio_for_testing(Web::PageId page_id) override;virtual Messages::WebContentTestClient::DidRequestTabAudibilityChangeCountForTestingResponse did_request_tab_audibility_change_count_for_testing(Web::PageId page_id) override;virtual Messages::WebContentTestClient::DidRequestHasPopulatedDocumentForTestingResponse did_request_has_populated_document_for_testing(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;virtual Messages::WebContentTestClient::DidRequestCaptureSessionHistorySnapshotForTestingResponse did_request_capture_session_history_snapshot_for_testing(Web::PageId page_id) override;diff --git a/Services/AudioServer/PlaybackStreamMixer.cpp b/Services/AudioServer/PlaybackStreamMixer.cppindex 09109340e0a..32638374fe9 100644--- a/Services/AudioServer/PlaybackStreamMixer.cpp+++ b/Services/AudioServer/PlaybackStreamMixer.cpp@@ -13,10 +13,10 @@namespace Audio {-NonnullRefPtr<PlaybackStreamMixer> PlaybackStreamMixer::create(Core::EventLoop& control_loop, u32 target_latency_ms, DeviceStreamFactory factory, AK::Duration audibility_linger)+NonnullRefPtr<PlaybackStreamMixer> PlaybackStreamMixer::create(Core::EventLoop& control_loop, u32 target_latency_ms, DeviceStreamFactory factory, AK::Duration audibility_smoothing){auto state = make_ref_counted<MixState>(control_loop);- auto mixer = adopt_ref(*new PlaybackStreamMixer(state, target_latency_ms, audibility_linger));+ auto mixer = adopt_ref(*new PlaybackStreamMixer(state, target_latency_ms, audibility_smoothing));state->m_mixer = mixer.ptr();auto promise = factory(OutputState::Suspended, target_latency_ms, [state](Span<float> buffer, MonotonicTime buffer_starts_playing_at) {@@ -33,10 +33,10 @@ NonnullRefPtr<PlaybackStreamMixer> PlaybackStreamMixer::create(Core::EventLoop&return mixer;}-PlaybackStreamMixer::PlaybackStreamMixer(NonnullRefPtr<MixState> state, u32 device_target_latency_ms, AK::Duration audibility_linger)+PlaybackStreamMixer::PlaybackStreamMixer(NonnullRefPtr<MixState> state, u32 device_target_latency_ms, AK::Duration audibility_smoothing): m_state(move(state)), m_device_target_latency_ms(device_target_latency_ms)- , m_audibility_linger(audibility_linger)+ , m_audibility_smoothing(audibility_smoothing), m_audibility_timer(Core::Timer::create_single_shot(AK::Duration::zero(), [this] { expire_audibility(); })){}@@ -145,13 +145,13 @@ void PlaybackStreamMixer::group_became_audible(PlaybackGroupId group)void PlaybackStreamMixer::expire_audibility(){auto now_ns = MonotonicTime::now().nanoseconds();- auto linger_ns = m_audibility_linger.to_nanoseconds();+ auto smoothing_ns = m_audibility_smoothing.to_nanoseconds();Vector<PlaybackGroupId> expired_groups;Optional<i64> next_expiry_ns;{MutexLocker locker(m_state->m_mutex);m_state->m_audible_until_ns.remove_all_matching([&](PlaybackGroupId group, i64 audible_until_ns) {- auto expiry_ns = audible_until_ns + linger_ns;+ auto expiry_ns = audible_until_ns + smoothing_ns;if (expiry_ns <= now_ns) {expired_groups.append(group);return true;diff --git a/Services/AudioServer/PlaybackStreamMixer.h b/Services/AudioServer/PlaybackStreamMixer.hindex 29545f6d2d2..4a6daa98fae 100644--- a/Services/AudioServer/PlaybackStreamMixer.h+++ b/Services/AudioServer/PlaybackStreamMixer.h@@ -47,10 +47,10 @@ public:using DeviceStreamFactory = Function<NonnullRefPtr<PlaybackStream::CreatePromise>(OutputState, u32 target_latency_ms, PlaybackStream::AudioDataRequestCallback)>;// Control thread. The device stream opens suspended through the factory.- static NonnullRefPtr<PlaybackStreamMixer> create(Core::EventLoop& control_loop, u32 target_latency_ms, DeviceStreamFactory, AK::Duration audibility_linger = AUDIBILITY_LINGER);+ static NonnullRefPtr<PlaybackStreamMixer> create(Core::EventLoop& control_loop, u32 target_latency_ms, DeviceStreamFactory, AK::Duration audibility_smoothing = AUDIBILITY_SMOOTHING);- // Control thread. A group becomes audible as soon as it is heard, and inaudible once the linger has passed since it- // last was, or at once when it is revoked or the mixer is let go of.+ // Control thread. A group becomes audible as soon as it is heard, and inaudible once the smoothing has passed since+ // it last was, or at once when it is revoked or the mixer is let go of.Function<void(PlaybackGroupId, Audibility)> on_group_audibility_changed;void report_every_group_inaudible();~PlaybackStreamMixer();@@ -126,7 +126,7 @@ private:HashMap<PlaybackGroupId, i64> m_audible_until_ns;};- PlaybackStreamMixer(NonnullRefPtr<MixState>, u32 device_target_latency_ms, AK::Duration audibility_linger);+ PlaybackStreamMixer(NonnullRefPtr<MixState>, u32 device_target_latency_ms, AK::Duration audibility_smoothing);void set_device_stream(NonnullRefPtr<PlaybackStream>);void set_device_error(Error);@@ -150,9 +150,9 @@ private:bool m_device_is_playing { false };HashMap<MixerClientId, NonnullRefPtr<Core::Timer>> m_drain_timers;- AK::Duration const m_audibility_linger;+ AK::Duration const m_audibility_smoothing;HashTable<PlaybackGroupId> m_audible_groups;- // Runs when the earliest audible group's linger would pass, which the device need not be playing for.+ // Runs when the earliest audible group's smoothing would pass, which the device need not be playing for.RefPtr<Core::Timer> m_audibility_timer;};diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cppindex 9fe7d9c07d2..1709a536695 100644--- a/Services/WebContent/PageClient.cpp+++ b/Services/WebContent/PageClient.cpp@@ -1946,6 +1946,13 @@ bool PageClient::page_did_request_tab_is_playing_audio_for_testing()return false;}+bool PageClient::page_did_request_tab_is_heard_playing_audio_for_testing()+{+ if (auto* test_connection = client().test_connection())+ return test_connection->did_request_tab_is_heard_playing_audio_for_testing(m_id);+ return false;+}+u64 PageClient::page_did_request_tab_audibility_change_count_for_testing(){if (auto* test_connection = client().test_connection())diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.hindex 318244e3dbc..cf96bf7e0ac 100644--- a/Services/WebContent/PageClient.h+++ b/Services/WebContent/PageClient.h@@ -345,6 +345,7 @@ private:virtual String page_did_request_ui_process_session_history_for_testing() override;virtual bool page_did_request_has_populated_document_for_testing(Web::HTML::CrossProcessId navigable_id) override;virtual bool page_did_request_tab_is_playing_audio_for_testing() override;+ virtual bool page_did_request_tab_is_heard_playing_audio_for_testing() override;virtual u64 page_did_request_tab_audibility_change_count_for_testing() override;virtual bool page_did_request_capture_session_history_snapshot_for_testing() override;virtual bool page_did_request_restore_session_history_snapshot_for_testing() override;diff --git a/Services/WebContent/WebContentTestClient.ipc b/Services/WebContent/WebContentTestClient.ipcindex 4585eb8387a..20f720e7abf 100644--- a/Services/WebContent/WebContentTestClient.ipc+++ b/Services/WebContent/WebContentTestClient.ipc@@ -31,6 +31,7 @@ endpoint WebContentTestClient routed by Web::PageId page_id[NotRouted] did_request_ui_process_session_history_for_testing(Web::PageId page_id) => (String session_history)[NotRouted] did_request_site_isolation_process_tree_for_testing(Web::PageId page_id) => (String process_tree)[NotRouted] did_request_tab_is_playing_audio_for_testing(Web::PageId page_id) => (bool is_playing_audio)+ [NotRouted] did_request_tab_is_heard_playing_audio_for_testing(Web::PageId page_id) => (bool is_heard_playing_audio)[NotRouted] did_request_tab_audibility_change_count_for_testing(Web::PageId page_id) => (u64 change_count)[NotRouted] did_request_has_populated_document_for_testing(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) => (bool has_populated_document)did_request_crash_of_remote_frame_processes_for_testing(Web::PageId page_id) =|diff --git a/Tests/AudioServer/TestPlaybackStreamMixer.cpp b/Tests/AudioServer/TestPlaybackStreamMixer.cppindex 2ff6ec1a033..5fbd6ad90af 100644--- a/Tests/AudioServer/TestPlaybackStreamMixer.cpp+++ b/Tests/AudioServer/TestPlaybackStreamMixer.cpp@@ -27,7 +27,7 @@ struct MixerFixture {RefPtr<Audio::PlaybackStreamMixer> mixer;Vector<AudibilityReport> audibility_reports;- explicit MixerFixture(AK::Duration audibility_linger = Audio::AUDIBILITY_LINGER)+ explicit MixerFixture(AK::Duration audibility_smoothing = Audio::AUDIBILITY_SMOOTHING){mixer = Audio::PlaybackStreamMixer::create(loop, 100, [this](Audio::OutputState state, u32, Audio::PlaybackStream::AudioDataRequestCallback callback) {@@ -36,7 +36,7 @@ struct MixerFixture {promise->resolve(*device);return promise;},- audibility_linger);+ audibility_smoothing);EXPECT(device);EXPECT(mixer->device_sample_specification().has_value());mixer->set_group_authorization(AUTHORIZED_GROUP, Audio::PlaybackGroupAuthorization::Authorized);@@ -628,16 +628,16 @@ TEST_CASE(a_muted_group_does_not_cancel_what_quiet_groups_play_together)EXPECT(fixture.audibility_reports.contains_slow(AudibilityReport { OTHER_GROUP, AUDIBLE }));}-TEST_CASE(a_group_stays_audible_until_the_linger_has_passed_since_it_was_last_heard)+TEST_CASE(a_group_stays_audible_until_the_smoothing_has_passed_since_it_was_last_heard){- static constexpr auto LINGER = AK::Duration::from_milliseconds(200);- MixerFixture fixture(LINGER);+ static constexpr auto SMOOTHING = AK::Duration::from_milliseconds(200);+ MixerFixture fixture(SMOOTHING);auto client = fixture.add_client(1);fixture.mixer->resume_client(1);auto heard_since = MonotonicTime::now();auto last_heard_at = heard_since;- while (MonotonicTime::now() - heard_since < LINGER + LINGER) {+ while (MonotonicTime::now() - heard_since < SMOOTHING + SMOOTHING) {(void)client.try_push(constant_frames(32, 1.0f));last_heard_at = MonotonicTime::now();fixture.render_and_report(32);@@ -646,7 +646,7 @@ TEST_CASE(a_group_stays_audible_until_the_linger_has_passed_since_it_was_last_he// Nothing more is rendered, as when the device has stopped.EXPECT(fixture.pump_until([&] { return fixture.audibility_reports.size() == 2; }));- EXPECT(MonotonicTime::now() - last_heard_at >= LINGER);+ EXPECT(MonotonicTime::now() - last_heard_at >= SMOOTHING);EXPECT(fixture.audibility_reports.last() == AudibilityReport { AUTHORIZED_GROUP, INAUDIBLE });}diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.txtindex 3176d90a3d0..5cbdfd26b19 100644--- a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.txt+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.txt@@ -1,4 +1,6 @@plays audio heard in the isolated iframe: true-plays audio heard after the hold: true+stops being heard once the iframe is gone: true+is heard playing audio in this document: true+plays audio after it would have stopped: truestops playing audio once nothing is heard: truechanged whether it plays audio once: truediff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.txtindex 73ec2b0fee8..7428dc2783f 100644--- a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.txt+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.txt@@ -1,6 +1,5 @@plays audio heard in the isolated iframe: truethe iframe's next process is gone: true-plays audio: truestops playing audio a while later: truewent on playing audio for at least two and a half seconds after navigating: truechanged whether it plays audio once: truediff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.txtindex ac6889876b5..108ef12b61e 100644--- a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.txt+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.txt@@ -1,8 +1,8 @@plays audio heard in the isolated iframe: true-stops playing audio once the iframe's process is gone: true-before the sound would have been forgotten: true+stops being heard once the iframe's process is gone: true+stops playing audio a while later: true+went on playing audio for at least two and a half seconds after the crash: truechanged whether it plays audio once: true-plays audio heard in another isolated iframe: true+is heard playing audio in this document: trueits process is gone: true-plays audio heard in this document: true-went on playing audio: true+is still heard playing audio in this document: truediff --git a/Tests/LibWeb/Text/expected/WebAudio/tab-plays-audio-only-while-heard.txt b/Tests/LibWeb/Text/expected/WebAudio/tab-plays-audio-only-while-heard.txtindex 37efb210902..aa1df2f7f10 100644--- a/Tests/LibWeb/Text/expected/WebAudio/tab-plays-audio-only-while-heard.txt+++ b/Tests/LibWeb/Text/expected/WebAudio/tab-plays-audio-only-while-heard.txt@@ -1,4 +1,4 @@while only silence plays: falseonce sound plays: truestops once the sound has stopped: true-about three seconds later: true+at least three seconds later: truediff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.htmlindex 6662dbc44f7..90aa2eb0eeb 100644--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.html+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves.html@@ -14,6 +14,15 @@// The tab can still be remembered as playing a previous test's sound.await waitForCondition(() => !internals.tabIsPlayingAudio());const httpServer = httpTestServer();++ // This document's audio runs silently from the start, so its sound is heard as soon as it is let through.+ const context = new AudioContext();+ const gain = new GainNode(context, { gain: 0 });+ const oscillator = new OscillatorNode(context);+ oscillator.connect(gain).connect(context.destination);+ oscillator.start();+ await waitForCondition(() => context.currentTime >= 0.5);+const childUrl = new URL(await httpServer.createEcho("GET", "/tab-keeps-playing-audio-heard-after-an-isolated-iframe-leaves-child", {status: 200,@@ -28,12 +37,18 @@document.body.appendChild(iframe);println(`plays audio heard in the isolated iframe: ${await waitForCondition(() => internals.tabIsPlayingAudio())}`);- // This document's sound starts while the iframe's page holds the tab, and goes on after the hold has ended.+ // This document's sound starts while the tab goes on playing the sound of the iframe's page that left it, and+ // keeps the tab playing audio past when it would have stopped.const changes = internals.tabAudibilityChangeCount();iframe.remove();- const context = play();- await new Promise(resolve => setTimeout(resolve, 4000));- println(`plays audio heard after the hold: ${internals.tabIsPlayingAudio()}`);+ println(`stops being heard once the iframe is gone: ${await waitForCondition(() => !internals.tabIsHeardPlayingAudio())}`);+ const leftAt = performance.now();+ gain.gain.value = 1;+ println(`is heard playing audio in this document: ${await waitForCondition(() => internals.tabIsHeardPlayingAudio())}`);++ // The tab would have stopped playing audio a while after the iframe left, which only time passing can show.+ await new Promise(resolve => setTimeout(resolve, Math.max(0, leftAt + 4000 - performance.now())));+ println(`plays audio after it would have stopped: ${internals.tabIsPlayingAudio()}`);await context.close();println(`stops playing audio once nothing is heard: ${await waitForCondition(() => !internals.tabIsPlayingAudio())}`);diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.htmlindex 82e1df68e0a..ccd726905d8 100644--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.html+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-keeps-playing-audio-of-a-navigated-isolated-iframe-through-a-crash.html@@ -34,7 +34,7 @@println(`plays audio heard in the isolated iframe: ${await waitForCondition(() => internals.tabIsPlayingAudio())}`);// The iframe's page leaves the tab while it is heard, as the iframe navigates to another site. Losing the process- // of the iframe's next document doesn't end the hold.+ // of the iframe's next document doesn't cut short how long the tab goes on playing audio.const changes = internals.tabAudibilityChangeCount();const arrived = nextMessage();const navigatedAt = performance.now();@@ -42,7 +42,6 @@await arrived;internals.crashRemoteFrameProcesses();println(`the iframe's next process is gone: ${await waitForCondition(() => remoteFrameCount() === 0)}`);- println(`plays audio: ${internals.tabIsPlayingAudio()}`);println(`stops playing audio a while later: ${await waitForCondition(() => !internals.tabIsPlayingAudio())}`);const heldFor = performance.now() - navigatedAt;println(`went on playing audio for at least two and a half seconds after navigating: ${heldFor >= 2500}`);diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.htmlindex 82e8e9734dd..28bf0fabbfc 100644--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.html+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/tab-stops-playing-audio-of-a-crashed-isolated-iframe.html@@ -25,29 +25,31 @@url.hostname = uniqueLocalhostHostname(name);const iframe = document.createElement("iframe");iframe.src = url;+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));document.body.appendChild(iframe);+ await loaded;};- // A page lost along with its process doesn't leave the tab, so its sound is forgotten at once.+ // A page lost along with its process stops being heard at once, and the tab goes on playing audio for a while,+ // as it does whenever its sound stops.await appendPlayingIframe("tab-stops-playing-audio-of-a-crashed-isolated-iframe");println(`plays audio heard in the isolated iframe: ${await waitForCondition(() => internals.tabIsPlayingAudio())}`);- let changes = internals.tabAudibilityChangeCount();+ const changes = internals.tabAudibilityChangeCount();const crashedAt = performance.now();internals.crashRemoteFrameProcesses();- println(`stops playing audio once the iframe's process is gone: ${await waitForCondition(() => !internals.tabIsPlayingAudio())}`);- println(`before the sound would have been forgotten: ${performance.now() - crashedAt < 2000}`);+ println(`stops being heard once the iframe's process is gone: ${await waitForCondition(() => !internals.tabIsHeardPlayingAudio())}`);+ println(`stops playing audio a while later: ${await waitForCondition(() => !internals.tabIsPlayingAudio())}`);+ const heldFor = performance.now() - crashedAt;+ println(`went on playing audio for at least two and a half seconds after the crash: ${heldFor >= 2500}`);println(`changed whether it plays audio once: ${internals.tabAudibilityChangeCount() - changes === 1}`);// The sound of the tab's other pages goes on being heard.- await appendPlayingIframe("tab-stops-playing-audio-of-a-crashed-isolated-iframe-again");- println(`plays audio heard in another isolated iframe: ${await waitForCondition(() => internals.tabIsPlayingAudio())}`);const context = play();- await waitForCondition(() => context.currentTime >= 0.5);- changes = internals.tabAudibilityChangeCount();+ println(`is heard playing audio in this document: ${await waitForCondition(() => internals.tabIsHeardPlayingAudio())}`);+ await appendPlayingIframe("tab-stops-playing-audio-of-a-crashed-isolated-iframe-again");internals.crashRemoteFrameProcesses();println(`its process is gone: ${await waitForCondition(() => remoteFrameCount() === 0)}`);- println(`plays audio heard in this document: ${internals.tabIsPlayingAudio()}`);- println(`went on playing audio: ${internals.tabAudibilityChangeCount() === changes}`);+ println(`is still heard playing audio in this document: ${internals.tabIsHeardPlayingAudio()}`);await context.close();});</script>diff --git a/Tests/LibWeb/Text/input/WebAudio/tab-plays-audio-only-while-heard.html b/Tests/LibWeb/Text/input/WebAudio/tab-plays-audio-only-while-heard.htmlindex 1a52b3423cb..101a7bf1e7d 100644--- a/Tests/LibWeb/Text/input/WebAudio/tab-plays-audio-only-while-heard.html+++ b/Tests/LibWeb/Text/input/WebAudio/tab-plays-audio-only-while-heard.html@@ -21,7 +21,7 @@const silencedAt = performance.now();println(`stops once the sound has stopped: ${await waitForCondition(() => !internals.tabIsPlayingAudio())}`);const silentFor = performance.now() - silencedAt;- println(`about three seconds later: ${silentFor >= 2500 && silentFor < 5000}`);+ println(`at least three seconds later: ${silentFor >= 3000}`);await context.close();});diff --git a/Tests/LibWebView/CMakeLists.txt b/Tests/LibWebView/CMakeLists.txtindex 1de5828f966..306e32901d8 100644--- a/Tests/LibWebView/CMakeLists.txt+++ b/Tests/LibWebView/CMakeLists.txt@@ -50,7 +50,6 @@ ladybird_test_suite(LibWebView)set(TEST_SOURCESTestAccessibilityTreeManager.cpp- TestAudibilityHold.cppTestAudioServerAudibility.cppTestAutocompleteMuxer.cppTestAutocompleteRanker.cpp@@ -66,6 +65,7 @@ set(TEST_SOURCESTestHelperProcessEnvironment.cppTestHistoryStore.cppTestHSTSStore.cpp+ TestLingeringIndicator.cppTestNavigationLoader.cppTestNotificationAttribution.cppTestNotificationFreedesktopArguments.cpp@@ -81,6 +81,7 @@ set(TEST_SOURCESTestStartupSettings.cppTestStorageAreaRegistry.cppTestStorageJar.cpp+ TestTabIndicators.cppTestTabPerformanceStats.cppTestWebDriverBiDiNetwork.cppTestWebViewURL.cppdiff --git a/Tests/LibWebView/TestAudibilityHold.cpp b/Tests/LibWebView/TestAudibilityHold.cppdeleted file mode 100644index ece17dfdc6e..00000000000--- a/Tests/LibWebView/TestAudibilityHold.cpp+++ /dev/null@@ -1,73 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibAudio/Audibility.h>-#include <LibTest/TestCase.h>-#include <LibWebView/AudibilityHold.h>--static constexpr Web::PageId PAGE { 1 };-static constexpr Web::PageId OTHER_PAGE { 2 };-static constexpr auto LINGER = Audio::AUDIBILITY_LINGER;--static AK::Duration seconds(i64 seconds)-{- return AK::Duration::from_seconds(seconds);-}--TEST_CASE(a_page_that_leaves_holds_the_tab_until_its_linger_has_passed)-{- WebView::AudibilityHold hold;- auto left_at = MonotonicTime::now();- EXPECT(!hold.is_held(left_at));-- EXPECT(hold.page_left(PAGE, left_at));- EXPECT(hold.is_held(left_at));- EXPECT(hold.is_held(left_at + LINGER - AK::Duration::from_milliseconds(1)));- EXPECT(!hold.is_held(left_at + LINGER));-}--TEST_CASE(a_page_leaves_once_each_time_it_begins_hosting)-{- WebView::AudibilityHold hold;- auto left_at = MonotonicTime::now();- EXPECT(hold.page_left(PAGE, left_at));-- // The page is let go of after it stops being displayed, or is let go of again.- EXPECT(!hold.page_left(PAGE, left_at + seconds(1)));- EXPECT(hold.held_until() == left_at + LINGER);-- hold.page_began_hosting(PAGE);- EXPECT(hold.page_left(PAGE, left_at + seconds(1)));- EXPECT(hold.held_until() == left_at + seconds(1) + LINGER);-}--TEST_CASE(the_tab_is_held_until_the_last_page_to_leave_has_lingered)-{- WebView::AudibilityHold hold;- auto left_at = MonotonicTime::now();- EXPECT(hold.page_left(PAGE, left_at));- EXPECT(hold.page_left(OTHER_PAGE, left_at + seconds(1)));- EXPECT(hold.is_held(left_at + LINGER));- EXPECT(!hold.is_held(left_at + seconds(1) + LINGER));-- // A page whose linger would end sooner doesn't shorten the hold.- hold.page_began_hosting(PAGE);- EXPECT(!hold.page_left(PAGE, left_at));- EXPECT(hold.held_until() == left_at + seconds(1) + LINGER);-}--TEST_CASE(a_closed_page_holds_nothing_but_keeps_the_hold_it_left)-{- WebView::AudibilityHold hold;- auto now = MonotonicTime::now();- hold.page_closed(PAGE);- EXPECT(!hold.is_held(now));-- EXPECT(hold.page_left(PAGE, now));- hold.page_closed(PAGE);- EXPECT(hold.is_held(now + LINGER - AK::Duration::from_milliseconds(1)));- EXPECT(hold.held_until() == now + LINGER);-}diff --git a/Tests/LibWebView/TestLingeringIndicator.cpp b/Tests/LibWebView/TestLingeringIndicator.cppnew file mode 100644index 00000000000..2f06b3cf60d--- /dev/null+++ b/Tests/LibWebView/TestLingeringIndicator.cpp@@ -0,0 +1,72 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibTest/TestCase.h>+#include <LibWebView/LingeringIndicator.h>++static constexpr auto LINGER = AK::Duration::from_seconds(3);++static AK::Duration seconds(i64 seconds)+{+ return AK::Duration::from_seconds(seconds);+}++TEST_CASE(shows_only_once_active)+{+ WebView::LingeringIndicator indicator { LINGER };+ auto now = MonotonicTime::now();+ EXPECT(!indicator.is_visible(now));++ indicator.set_active(false, now);+ EXPECT(!indicator.is_visible(now));++ indicator.set_active(true, now);+ EXPECT(indicator.is_visible(now + seconds(60)));+ EXPECT(!indicator.visible_until().has_value());+}++TEST_CASE(lingers_for_exactly_the_linger_once_inactive)+{+ WebView::LingeringIndicator indicator { LINGER };+ auto started_at = MonotonicTime::now();+ indicator.set_active(true, started_at);++ auto stopped_at = started_at + seconds(10);+ indicator.set_active(false, stopped_at);+ EXPECT(!indicator.is_active());+ EXPECT(indicator.visible_until() == stopped_at + LINGER);+ EXPECT(indicator.is_visible(stopped_at + LINGER - AK::Duration::from_milliseconds(1)));+ EXPECT(!indicator.is_visible(stopped_at + LINGER));+}++TEST_CASE(being_told_again_that_it_is_inactive_does_not_extend_the_linger)+{+ WebView::LingeringIndicator indicator { LINGER };+ auto stopped_at = MonotonicTime::now();+ indicator.set_active(true, stopped_at);+ indicator.set_active(false, stopped_at);++ indicator.set_active(false, stopped_at + seconds(1));+ indicator.set_active(false, stopped_at + seconds(2));+ EXPECT(indicator.visible_until() == stopped_at + LINGER);+ EXPECT(!indicator.is_visible(stopped_at + LINGER));+}++TEST_CASE(becoming_active_again_cancels_the_linger)+{+ WebView::LingeringIndicator indicator { LINGER };+ auto stopped_at = MonotonicTime::now();+ indicator.set_active(true, stopped_at);+ indicator.set_active(false, stopped_at);++ indicator.set_active(true, stopped_at + seconds(1));+ EXPECT(!indicator.visible_until().has_value());+ EXPECT(indicator.is_visible(stopped_at + LINGER + seconds(10)));++ auto stopped_again_at = stopped_at + LINGER + seconds(10);+ indicator.set_active(false, stopped_again_at);+ EXPECT(indicator.visible_until() == stopped_again_at + LINGER);+}diff --git a/Tests/LibWebView/TestTabIndicators.cpp b/Tests/LibWebView/TestTabIndicators.cppnew file mode 100644index 00000000000..599389e491b--- /dev/null+++ b/Tests/LibWebView/TestTabIndicators.cpp@@ -0,0 +1,160 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibCore/EventLoop.h>+#include <LibTest/TestCase.h>+#include <LibWebView/TabIndicators.h>++using WebView::TabIndicator;++static constexpr auto LINGER = WebView::TabIndicators::LINGER;++static AK::Duration seconds(i64 seconds)+{+ return AK::Duration::from_seconds(seconds);+}++struct VisibilityChange {+ TabIndicator indicator;+ bool visible;++ bool operator==(VisibilityChange const&) const = default;+};++// The indicators' timer is never run: each test moves time forward itself.+struct IndicatorsFixture {+ Core::EventLoop loop;+ WebView::TabIndicators indicators;+ Vector<VisibilityChange> changes;++ IndicatorsFixture()+ {+ indicators.on_visibility_change = [this](TabIndicator indicator, bool visible) {+ changes.append({ indicator, visible });+ };+ }++ Vector<VisibilityChange> take_changes() { return exchange(changes, {}); }+};++TEST_CASE(an_indicator_shows_as_soon_as_it_is_active)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);++ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::PlayingAudio, true } });+ EXPECT(fixture.indicators.is_visible(TabIndicator::PlayingAudio));+ EXPECT(!fixture.indicators.is_visible(TabIndicator::UsingLocation));+ EXPECT(!fixture.indicators.next_deadline(now).has_value());+}++TEST_CASE(an_indicator_shows_until_its_linger_has_passed)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);+ (void)fixture.take_changes();++ fixture.indicators.set_active(TabIndicator::PlayingAudio, false, now + seconds(1));+ EXPECT(fixture.take_changes().is_empty());+ EXPECT(!fixture.indicators.is_active(TabIndicator::PlayingAudio));+ EXPECT(fixture.indicators.is_visible(TabIndicator::PlayingAudio));+ EXPECT(fixture.indicators.next_deadline(now + seconds(1)) == now + seconds(1) + LINGER);++ fixture.indicators.update_visibility(now + seconds(1) + LINGER);+ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::PlayingAudio, false } });+ EXPECT(!fixture.indicators.next_deadline(now + seconds(1) + LINGER).has_value());+}++TEST_CASE(indicators_linger_on_deadlines_of_their_own)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, true, now);+ fixture.indicators.set_active(TabIndicator::PlayingAudio, false, now + seconds(1));+ fixture.indicators.set_active(TabIndicator::UsingLocation, false, now + seconds(2));+ (void)fixture.take_changes();+ EXPECT(fixture.indicators.next_deadline(now + seconds(2)) == now + seconds(1) + LINGER);++ auto first_deadline = now + seconds(1) + LINGER;+ fixture.indicators.update_visibility(first_deadline);+ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::PlayingAudio, false } });+ EXPECT(fixture.indicators.is_visible(TabIndicator::UsingLocation));+ EXPECT(fixture.indicators.next_deadline(first_deadline) == now + seconds(2) + LINGER);++ fixture.indicators.update_visibility(now + seconds(2) + LINGER);+ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::UsingLocation, false } });+}++TEST_CASE(indicators_that_stop_together_go_together)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, true, now);+ fixture.indicators.set_active(TabIndicator::PlayingAudio, false, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, false, now);+ (void)fixture.take_changes();+ EXPECT(fixture.indicators.next_deadline(now) == now + LINGER);++ fixture.indicators.update_visibility(now + LINGER);+ EXPECT(fixture.take_changes() == (Vector<VisibilityChange> { { TabIndicator::PlayingAudio, false }, { TabIndicator::UsingLocation, false } }));+}++TEST_CASE(one_indicator_resuming_leaves_the_other_lingering)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, true, now);+ fixture.indicators.set_active(TabIndicator::PlayingAudio, false, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, false, now);++ fixture.indicators.set_active(TabIndicator::UsingLocation, true, now + seconds(1));+ (void)fixture.take_changes();+ EXPECT(fixture.indicators.next_deadline(now + seconds(1)) == now + LINGER);++ fixture.indicators.update_visibility(now + LINGER);+ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::PlayingAudio, false } });+ EXPECT(fixture.indicators.is_visible(TabIndicator::UsingLocation));+}++TEST_CASE(an_indicator_a_listener_makes_active_again_is_not_reported_twice)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, true, now);+ fixture.indicators.set_active(TabIndicator::PlayingAudio, false, now);+ fixture.indicators.set_active(TabIndicator::UsingLocation, false, now);+ (void)fixture.take_changes();++ // As the playing indicator stops showing, its listener makes the location one active again.+ fixture.indicators.on_visibility_change = [&](TabIndicator indicator, bool visible) {+ fixture.changes.append({ indicator, visible });+ if (indicator == TabIndicator::PlayingAudio)+ fixture.indicators.set_active(TabIndicator::UsingLocation, true, now + LINGER);+ };+ fixture.indicators.update_visibility(now + LINGER);++ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::PlayingAudio, false } });+ EXPECT(fixture.indicators.is_visible(TabIndicator::UsingLocation));+ EXPECT(!fixture.indicators.next_deadline(now + LINGER).has_value());+}++TEST_CASE(a_passed_deadline_is_noticed_when_any_indicator_is_updated)+{+ IndicatorsFixture fixture;+ auto now = MonotonicTime::now();+ fixture.indicators.set_active(TabIndicator::PlayingAudio, true, now);+ fixture.indicators.set_active(TabIndicator::PlayingAudio, false, now);+ (void)fixture.take_changes();++ fixture.indicators.set_active(TabIndicator::UsingLocation, false, now + LINGER);+ EXPECT(fixture.take_changes() == Vector<VisibilityChange> { { TabIndicator::PlayingAudio, false } });+}diff --git a/Tests/LibWebView/TestViewDestruction.cpp b/Tests/LibWebView/TestViewDestruction.cppindex aca563aeda5..d8950e5c0d1 100644--- a/Tests/LibWebView/TestViewDestruction.cpp+++ b/Tests/LibWebView/TestViewDestruction.cpp@@ -9,14 +9,36 @@#include <LibCore/EventLoop.h>#include <LibGfx/SystemTheme.h>#include <LibTest/TestCase.h>-#include <LibWebView/CanonicalTraversable.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>-#include <LibWebView/WebContentPage.h>-// A frontend destroys its widgets before the view they hold: the view's teardown, which closes its page, must not call-// back into the frontend.-TEST_CASE(a_view_being_destroyed_does_not_report_its_audibility)+// A view whose location indicator is overdue to stop showing, as when the timer that would hide it hasn't run yet.+class ViewWithAnOverdueIndicator final : public WebView::HeadlessWebView {+public:+ static NonnullOwnPtr<ViewWithAnOverdueIndicator> create(Core::AnonymousBuffer theme)+ {+ auto view = adopt_own(*new ViewWithAnOverdueIndicator(move(theme)));+ view->initialize_tab(Web::HTML::VisibilityState::Visible);+ return view;+ }++ void stop_using_location_long_ago()+ {+ auto long_ago = MonotonicTime::now() - WebView::TabIndicators::LINGER - WebView::TabIndicators::LINGER;+ m_tab_indicators.set_active(WebView::TabIndicator::UsingLocation, true, long_ago);+ m_tab_indicators.set_active(WebView::TabIndicator::UsingLocation, false, long_ago);+ }++private:+ explicit ViewWithAnOverdueIndicator(Core::AnonymousBuffer theme)+ : HeadlessWebView(move(theme), { 800, 600 })+ {+ }+};++// A frontend destroys its widgets before the view they hold: the view's teardown, which ends its location requests and+// closes its page, must not call back into the frontend.+TEST_CASE(a_view_being_destroyed_does_not_report_what_its_tab_shows){Test::HeadlessTestEnvironment environment { "TestViewDestruction"sv };@@ -24,20 +46,18 @@ TEST_CASE(a_view_being_destroyed_does_not_report_its_audibility)auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));- OwnPtr<WebView::HeadlessWebView> view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });+ OwnPtr<ViewWithAnOverdueIndicator> view = ViewWithAnOverdueIndicator::create(move(theme));size_t loads_finished = 0;view->on_load_finish = [&](auto const&) { ++loads_finished; };Core::EventLoop::current().spin_until([&] { return loads_finished == 1; });- Optional<Audio::Audibility> reported_audibility;- view->on_audibility_changed = [&](auto audibility) { reported_audibility = audibility; };- view->traversable().for_each_hosting_page([](WebView::WebContentPage& page) {- page.set_audibility(Audio::Audibility::Audible);- });- EXPECT(reported_audibility == Audio::Audibility::Audible);+ // Ending the location requests is the next time the view looks at what its tab shows.+ view->stop_using_location_long_ago();+ EXPECT(view->tab_indicator_visible(WebView::TabIndicator::UsingLocation));- reported_audibility.clear();+ Optional<bool> reported_visibility;+ view->on_tab_indicator_change = [&](auto, bool visible) { reported_visibility = visible; };view = nullptr;- EXPECT(!reported_audibility.has_value());+ EXPECT(!reported_visibility.has_value());}diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cppindex 2b32766644d..3c712025941 100644--- a/UI/Qt/BrowserWindow.cpp+++ b/UI/Qt/BrowserWindow.cpp@@ -849,7 +849,7 @@ void BrowserWindow::initialize_tab(Tab* tab)QObject::connect(tab, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);QObject::connect(tab, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);- QObject::connect(tab, &Tab::audibility_changed, this, &BrowserWindow::tab_audibility_changed);+ QObject::connect(tab, &Tab::playing_audio_indicator_changed, this, &BrowserWindow::tab_playing_audio_indicator_changed);QObject::connect(tab, &Tab::loading_changed, this, [this] {m_tabs_container->tab_bar()->update_loading_ring_animation();});@@ -1409,21 +1409,22 @@ void BrowserWindow::set_always_on_top(bool always_on_top)handle->setFlags(flags);}-void BrowserWindow::tab_audibility_changed(int index, Audio::Audibility)+void BrowserWindow::tab_playing_audio_indicator_changed(int index){if (index < 0)return;update_tab_audio_button(*m_tabs_container->tab(index));}-// The tab is shown playing audio, muted or not, while the AudioServer recently heard it. A muted tab keeps its button,-// as that is the only way to unmute it.+// The tab is shown playing audio, muted or not, while the view shows it playing audio. A muted tab keeps its button, as+// that is the only way to unmute it.void BrowserWindow::update_tab_audio_button(Tab& tab){auto index = tab_index(&tab);auto* tab_bar = m_tabs_container->tab_bar();+ auto shows_playing_audio = tab.is_loaded() && tab.view().tab_indicator_visible(WebView::TabIndicator::PlayingAudio);- if (!tab.is_loaded() || (tab.view().audibility() == Audio::Audibility::Inaudible && tab.view().page_mute_state() == Web::HTML::MuteState::Unmuted)) {+ if (!tab.is_loaded() || (!shows_playing_audio && tab.view().page_mute_state() == Web::HTML::MuteState::Unmuted)) {// The tab bar only hides the button it lets go of.if (auto* button = tab_bar->tabButton(index, AUDIO_STATE_BUTTON_POSITION))button->deleteLater();diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.hindex 6095d167a5b..a58b745a00d 100644--- a/UI/Qt/BrowserWindow.h+++ b/UI/Qt/BrowserWindow.h@@ -9,7 +9,6 @@#include <AK/Optional.h>#include <AK/kmalloc.h>-#include <LibAudio/Audibility.h>#include <LibURL/URL.h>#include <LibWebCommon/HTML/ActivateTab.h>#include <LibWebCommon/Page/PageId.h>@@ -239,7 +238,7 @@ public:public slots:void tab_title_changed(int index, QString const&);void tab_favicon_changed(int index, QIcon const& icon);- void tab_audibility_changed(int index, Audio::Audibility);+ void tab_playing_audio_indicator_changed(int index);Tab& new_tab_from_url(URL::URL const&, Web::HTML::ActivateTab, TabLocation);void open_new_tab();void activate_tab(int index);diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex bf360cdb980..e0e5556f7c4 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -576,8 +576,15 @@ void Tab::initialize(Optional<WebView::CanonicalTraversable&> traversable)m_permission_prompts.cancel(request);};- view().on_location_in_use_change = [this](bool in_use) {- m_location_edit->set_location_in_use(in_use);+ view().on_tab_indicator_change = [this](WebView::TabIndicator indicator, bool visible) {+ switch (indicator) {+ case WebView::TabIndicator::PlayingAudio:+ emit playing_audio_indicator_changed(tab_index());+ break;+ case WebView::TabIndicator::UsingLocation:+ m_location_edit->set_location_in_use(visible);+ break;+ }};view().on_request_accept_dialog = [this]() {@@ -838,10 +845,6 @@ void Tab::initialize(Optional<WebView::CanonicalTraversable&> traversable)m_window->fullscreen_mode().exit(FullscreenMode::ExitInitiatedBy::WebContent);};- view().on_audibility_changed = [this](auto audibility) {- emit audibility_changed(tab_index(), audibility);- };-view().on_screen_wake_lock_state_changed = [this](auto wake_lock_state) {set_screen_wake_lock_state(wake_lock_state);};diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.hindex e20d96d0996..9e53330f9d2 100644--- a/UI/Qt/Tab.h+++ b/UI/Qt/Tab.h@@ -13,7 +13,6 @@#include <AK/String.h>#include <AK/Vector.h>#include <AK/kmalloc.h>-#include <LibAudio/Audibility.h>#include <LibWakeLock/DisplaySleepInhibitor.h>#include <LibWebCommon/Page/PageId.h>#include <LibWebCommon/Page/ScreenWakeLockState.h>@@ -188,7 +187,7 @@ public slots:signals:void title_changed(int id, QString const&);void favicon_changed(int id, QIcon const&);- void audibility_changed(int id, Audio::Audibility);+ void playing_audio_indicator_changed(int id);void loading_changed();void performance_stats_changed();void loaded();