tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a694e4ac07504fecfb69699e0b4f3dd08c2b83c3
parent f95b20bfa25962f932cddd363844bce7f96a648b
Author: stransky <stransky@redhat.com>
Date:   Tue,  4 Nov 2025 19:15:10 +0000

Bug 1996504 [Linux] Process both foreground and background inhibit states together r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D271201

Diffstat:
Mwidget/gtk/WakeLockListener.cpp | 37+++++++++++++++++++++++++++----------
Mwidget/gtk/WakeLockListener.h | 1+
2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/widget/gtk/WakeLockListener.cpp b/widget/gtk/WakeLockListener.cpp @@ -1063,6 +1063,24 @@ WakeLockListener::~WakeLockListener() { } } +void WakeLockListener::SetState(const nsAString& topic, bool aBackground, + bool aInhibit) { + WAKE_LOCK_LOG( + "WakeLockListener::SetState() topic %s background %d inhibit %d", + NS_ConvertUTF16toUTF8(topic).get(), aBackground, aInhibit); + + nsRefPtrHashtable<nsStringHashKey, WakeLockTopic>* topicTable = + aBackground ? &mBackgroundTopics : &mForegroundTopics; + RefPtr<WakeLockTopic> topicLock = topicTable->LookupOrInsertWith( + topic, [&] { return MakeRefPtr<WakeLockTopic>(topic, aBackground); }); + + if (aInhibit) { + topicLock->InhibitScreensaver(); + } else { + topicLock->UninhibitScreensaver(); + } +} + nsresult WakeLockListener::Callback(const nsAString& topic, const nsAString& state) { WAKE_LOCK_LOG("WakeLockListener::Callback() topic %s state %s", @@ -1073,18 +1091,17 @@ nsresult WakeLockListener::Callback(const nsAString& topic, return NS_OK; } - bool backgroundLock = !(topic.Equals(u"video-playing"_ns) && - state.EqualsLiteral("locked-foreground")); + bool backgroundLock = state.EqualsLiteral("locked-background"); bool shouldLock = state.EqualsLiteral("locked-background") || state.EqualsLiteral("locked-foreground"); - nsRefPtrHashtable<nsStringHashKey, WakeLockTopic>* topicTable = - backgroundLock ? &mBackgroundTopics : &mForegroundTopics; - RefPtr<WakeLockTopic> topicLock = topicTable->LookupOrInsertWith( - topic, [&] { return MakeRefPtr<WakeLockTopic>(topic, backgroundLock); }); - WAKE_LOCK_LOG("Adding WakeLockListener lock %d background %d", shouldLock, - backgroundLock); + // If there's a switch between lock types (background / foreground) we need to + // un-inhibit a complementary one. + SetState(topic, !backgroundLock, /* aInhibited */ false); - return shouldLock ? topicLock->InhibitScreensaver() - : topicLock->UninhibitScreensaver(); + // And set requested one accordingly. Uninhibit state doesn't hold + // foreground/background state so release both. + SetState(topic, backgroundLock, /* aInhibited */ shouldLock); + + return NS_OK; } diff --git a/widget/gtk/WakeLockListener.h b/widget/gtk/WakeLockListener.h @@ -24,6 +24,7 @@ class WakeLockListener final : public nsIDOMMozWakeLockListener { NS_DECL_ISUPPORTS; nsresult Callback(const nsAString& topic, const nsAString& state) override; + void SetState(const nsAString& topic, bool aBackground, bool aInhibit); WakeLockListener();