Modified: trunk/Source/WebCore/ChangeLog (284669 => 284670)
--- trunk/Source/WebCore/ChangeLog 2021-10-22 07:35:57 UTC (rev 284669)
+++ trunk/Source/WebCore/ChangeLog 2021-10-22 08:07:47 UTC (rev 284670)
@@ -1,3 +1,25 @@
+2021-10-22 Patrick Griffis <[email protected]>
+
+ [GTK] Rewrite LowPowerModeNotifier to use GPowerProfileMonitor
+ https://bugs.webkit.org/show_bug.cgi?id=231958
+
+ Reviewed by Carlos Garcia Campos.
+
+ This replaces the previous direct use of UPower with some advantages:
+
+ - Fixes support while being sandboxed without UPower DBus access
+ - Respects a system-wide low power mode rather than only being
+ enabled when the battery is low
+
+ I decided to remove the old behavior entirely as it is a very
+ different behavior than the new one and subjectively worse.
+
+ * platform/LowPowerModeNotifier.h:
+ * platform/glib/LowPowerModeNotifierGLib.cpp:
+ (WebCore::LowPowerModeNotifier::LowPowerModeNotifier):
+ (WebCore::LowPowerModeNotifier::powerSaverEnabledNotifyCallback):
+ (WebCore::LowPowerModeNotifier::~LowPowerModeNotifier):
+
2021-10-22 Kimmo Kinnunen <[email protected]>
WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
Modified: trunk/Source/WebCore/platform/LowPowerModeNotifier.h (284669 => 284670)
--- trunk/Source/WebCore/platform/LowPowerModeNotifier.h 2021-10-22 07:35:57 UTC (rev 284669)
+++ trunk/Source/WebCore/platform/LowPowerModeNotifier.h 2021-10-22 08:07:47 UTC (rev 284670)
@@ -34,7 +34,7 @@
#if USE(GLIB)
#include <wtf/glib/GRefPtr.h>
-typedef struct _GDBusProxy GDBusProxy;
+typedef struct _GPowerProfileMonitor GPowerProfileMonitor;
#endif
namespace WebCore {
@@ -56,15 +56,11 @@
RetainPtr<WebLowPowerModeObserver> m_observer;
LowPowerModeChangeCallback m_callback;
#elif USE(GLIB)
- void updateWarningLevel();
- void warningLevelChanged();
- static void gPropertiesChangedCallback(LowPowerModeNotifier*, GVariant* changedProperties);
-
- GRefPtr<GDBusProxy> m_displayDeviceProxy;
- GRefPtr<GCancellable> m_cancellable;
+#if GLIB_CHECK_VERSION(2, 69, 1)
LowPowerModeChangeCallback m_callback;
- bool m_lowPowerModeEnabled { false };
+ GRefPtr<GPowerProfileMonitor> m_powerProfileMonitor;
#endif
+#endif
};
}
Modified: trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp (284669 => 284670)
--- trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp 2021-10-22 07:35:57 UTC (rev 284669)
+++ trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp 2021-10-22 08:07:47 UTC (rev 284670)
@@ -26,83 +26,34 @@
namespace WebCore {
-static const char kWarningLevel[] = "WarningLevel";
LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&& callback)
- : m_cancellable(adoptGRef(g_cancellable_new()))
- , m_callback(WTFMove(callback))
+ : m_callback(WTFMove(callback))
+#if GLIB_CHECK_VERSION(2, 69, 1)
+ , m_powerProfileMonitor(adoptGRef(g_power_profile_monitor_dup_default()))
+#endif
{
- g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES),
- nullptr, "org.freedesktop.UPower", "/org/freedesktop/UPower/devices/DisplayDevice", "org.freedesktop.UPower.Device", m_cancellable.get(),
- [](GObject*, GAsyncResult* result, gpointer userData) {
- GUniqueOutPtr<GError> error;
- GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
- if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
- return;
-
- auto* self = static_cast<LowPowerModeNotifier*>(userData);
- if (proxy) {
- GUniquePtr<char> nameOwner(g_dbus_proxy_get_name_owner(proxy.get()));
- if (nameOwner) {
- self->m_displayDeviceProxy = WTFMove(proxy);
- self->updateWarningLevel();
- g_signal_connect_swapped(self->m_displayDeviceProxy.get(), "g-properties-changed", G_CALLBACK(gPropertiesChangedCallback), self);
- return;
- }
- }
-
- // Now, if there is no name owner, it would be good to try to
- // connect to a Flatpak battery status portal instead.
- // Unfortunately, no such portal currently exists.
- self->m_cancellable = nullptr;
- }, this);
+#if GLIB_CHECK_VERSION(2, 69, 1)
+ g_signal_connect_swapped(m_powerProfileMonitor.get(), "notify::power-saver-enabled", G_CALLBACK(+[] (LowPowerModeNotifier* self, GParamSpec*, GPowerProfileMonitor*) {
+ self->m_callback(self->isLowPowerModeEnabled());
+ }), this);
+#endif
}
-void LowPowerModeNotifier::updateWarningLevel()
-{
- GRefPtr<GVariant> variant = adoptGRef(g_dbus_proxy_get_cached_property(m_displayDeviceProxy.get(), kWarningLevel));
- if (!variant) {
- m_lowPowerModeEnabled = false;
- return;
- }
-
- // 0: Unknown
- // 1: None
- // 2: Discharging (only for universal power supplies)
- // 3: Low
- // 4: Critical
- // 5: Action
- m_lowPowerModeEnabled = g_variant_get_uint32(variant.get()) > 1;
-}
-
-void LowPowerModeNotifier::warningLevelChanged()
-{
- updateWarningLevel();
- m_callback(m_lowPowerModeEnabled);
-}
-
-void LowPowerModeNotifier::gPropertiesChangedCallback(LowPowerModeNotifier* self, GVariant* changedProperties)
-{
- GUniqueOutPtr<GVariantIter> iter;
- g_variant_get(changedProperties, "a{sv}", &iter.outPtr());
-
- const char* propertyName;
- while (g_variant_iter_next(iter.get(), "{&sv}", &propertyName, nullptr)) {
- if (!strcmp(propertyName, kWarningLevel)) {
- self->warningLevelChanged();
- break;
- }
- }
-}
-
LowPowerModeNotifier::~LowPowerModeNotifier()
{
- g_cancellable_cancel(m_cancellable.get());
+#if GLIB_CHECK_VERSION(2, 69, 1)
+ g_signal_handlers_disconnect_by_data(m_powerProfileMonitor.get(), this);
+#endif
}
bool LowPowerModeNotifier::isLowPowerModeEnabled() const
{
- return m_lowPowerModeEnabled;
+#if GLIB_CHECK_VERSION(2, 69, 1)
+ return g_power_profile_monitor_get_power_saver_enabled(m_powerProfileMonitor.get());
+#else
+ return false;
+#endif
}
} // namespace WebCore