Title: [228888] trunk
Revision
228888
Author
mcatanz...@igalia.com
Date
2018-02-21 11:42:35 -0800 (Wed, 21 Feb 2018)

Log Message

[GTK] USE_UPOWER causes crashes inside a chroot or on systems with broken dbus/upower
https://bugs.webkit.org/show_bug.cgi?id=181825

Reviewed by Carlos Garcia Campos.

.:

Get rid of the upower-glib dependency. We will use upower's D-Bus API instead.

* Source/cmake/FindUPowerGLib.cmake: Removed.
* Source/cmake/OptionsGTK.cmake:

Source/WebCore:

We could fix this crash, but that would not be good enough, because upower-glib is a
synchronous API that wraps D-Bus calls. That's not acceptable for use in the web process.
Rewrite LowPowerModeNotifierGLib to use upower's D-Bus API directly, instead.

Note that this also enables LowPowerModeNotifier for WPE, since the USE(UPOWER) build
flag is no longer needed.

* platform/LowPowerModeNotifier.cpp:
* platform/LowPowerModeNotifier.h:
* platform/glib/LowPowerModeNotifierGLib.cpp:
(WebCore::LowPowerModeNotifier::LowPowerModeNotifier):
(WebCore::LowPowerModeNotifier::updateWarningLevel):
(WebCore::LowPowerModeNotifier::warningLevelChanged):
(WebCore::LowPowerModeNotifier::gPropertiesChangedCallback):
(WebCore::LowPowerModeNotifier::~LowPowerModeNotifier):
(WebCore::LowPowerModeNotifier::updateState): Deleted.
(WebCore::LowPowerModeNotifier::warningLevelCallback): Deleted.

Modified Paths

Removed Paths

Diff

Modified: trunk/ChangeLog (228887 => 228888)


--- trunk/ChangeLog	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/ChangeLog	2018-02-21 19:42:35 UTC (rev 228888)
@@ -1,3 +1,15 @@
+2018-02-21  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        [GTK] USE_UPOWER causes crashes inside a chroot or on systems with broken dbus/upower
+        https://bugs.webkit.org/show_bug.cgi?id=181825
+
+        Reviewed by Carlos Garcia Campos.
+
+        Get rid of the upower-glib dependency. We will use upower's D-Bus API instead.
+
+        * Source/cmake/FindUPowerGLib.cmake: Removed.
+        * Source/cmake/OptionsGTK.cmake:
+
 2018-02-20  Adrian Perez de Castro  <ape...@igalia.com>
 
         [GTK][CMake] Support building with Enchant 2.x

Modified: trunk/Source/WebCore/ChangeLog (228887 => 228888)


--- trunk/Source/WebCore/ChangeLog	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/Source/WebCore/ChangeLog	2018-02-21 19:42:35 UTC (rev 228888)
@@ -1,3 +1,28 @@
+2018-02-21  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        [GTK] USE_UPOWER causes crashes inside a chroot or on systems with broken dbus/upower
+        https://bugs.webkit.org/show_bug.cgi?id=181825
+
+        Reviewed by Carlos Garcia Campos.
+
+        We could fix this crash, but that would not be good enough, because upower-glib is a
+        synchronous API that wraps D-Bus calls. That's not acceptable for use in the web process.
+        Rewrite LowPowerModeNotifierGLib to use upower's D-Bus API directly, instead.
+
+        Note that this also enables LowPowerModeNotifier for WPE, since the USE(UPOWER) build
+        flag is no longer needed.
+
+        * platform/LowPowerModeNotifier.cpp:
+        * platform/LowPowerModeNotifier.h:
+        * platform/glib/LowPowerModeNotifierGLib.cpp:
+        (WebCore::LowPowerModeNotifier::LowPowerModeNotifier):
+        (WebCore::LowPowerModeNotifier::updateWarningLevel):
+        (WebCore::LowPowerModeNotifier::warningLevelChanged):
+        (WebCore::LowPowerModeNotifier::gPropertiesChangedCallback):
+        (WebCore::LowPowerModeNotifier::~LowPowerModeNotifier):
+        (WebCore::LowPowerModeNotifier::updateState): Deleted.
+        (WebCore::LowPowerModeNotifier::warningLevelCallback): Deleted.
+
 2018-02-21  Chris Dumez  <cdu...@apple.com>
 
         VTTCue constructor should use 'double' type for startTime / endTime

Modified: trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp (228887 => 228888)


--- trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp	2018-02-21 19:42:35 UTC (rev 228888)
@@ -28,7 +28,7 @@
 
 namespace WebCore {
 
-#if !PLATFORM(IOS) && !USE(UPOWER)
+#if !PLATFORM(IOS) && !USE(GLIB)
 
 LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&&)
 {

Modified: trunk/Source/WebCore/platform/LowPowerModeNotifier.h (228887 => 228888)


--- trunk/Source/WebCore/platform/LowPowerModeNotifier.h	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/Source/WebCore/platform/LowPowerModeNotifier.h	2018-02-21 19:42:35 UTC (rev 228888)
@@ -28,15 +28,13 @@
 #include <wtf/Function.h>
 
 #if PLATFORM(IOS)
-
 #include <wtf/RetainPtr.h>
 OBJC_CLASS WebLowPowerModeObserver;
-
 #endif
 
-#if USE(UPOWER)
-#include <libupower-glib/upower.h>
+#if USE(GLIB)
 #include <wtf/glib/GRefPtr.h>
+typedef _GDBusProxy GDBusProxy;
 #endif
 
 namespace WebCore {
@@ -56,12 +54,13 @@
 
     RetainPtr<WebLowPowerModeObserver> m_observer;
     LowPowerModeChangeCallback m_callback;
-#elif USE(UPOWER)
-    static void warningLevelCallback(LowPowerModeNotifier*);
-    void updateState();
+#elif USE(GLIB)
+    void updateWarningLevel();
+    void warningLevelChanged();
+    static void gPropertiesChangedCallback(LowPowerModeNotifier*, GVariant* changedProperties);
 
-    GRefPtr<UpClient> m_upClient;
-    GRefPtr<UpDevice> m_device;
+    GRefPtr<GDBusProxy> m_displayDeviceProxy;
+    GRefPtr<GCancellable> m_cancellable;
     LowPowerModeChangeCallback m_callback;
     bool m_lowPowerModeEnabled { false };
 #endif

Modified: trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp (228887 => 228888)


--- trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp	2018-02-21 19:42:35 UTC (rev 228888)
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 2017 Collabora Ltd.
+ *  Copyright (C) 2018 Igalia S.L.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -19,35 +20,83 @@
 #include "config.h"
 #include "LowPowerModeNotifier.h"
 
-#if USE(UPOWER)
+#include <cstring>
+#include <gio/gio.h>
+
 namespace WebCore {
 
+static const char kWarningLevel[] = "WarningLevel";
+
 LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&& callback)
-    : m_upClient(adoptGRef(up_client_new()))
-    , m_device(adoptGRef(up_client_get_display_device(m_upClient.get())))
+    : m_cancellable(adoptGRef(g_cancellable_new()))
     , m_callback(WTFMove(callback))
 {
-    updateState();
+    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;
 
-    g_signal_connect_swapped(m_device.get(), "notify::warning-level", G_CALLBACK(warningLevelCallback), this);
+            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);
 }
 
-void LowPowerModeNotifier::updateState()
+void LowPowerModeNotifier::updateWarningLevel()
 {
-    UpDeviceLevel warningLevel;
-    g_object_get(G_OBJECT(m_device.get()), "warning-level", &warningLevel, nullptr);
-    m_lowPowerModeEnabled = warningLevel > UP_DEVICE_LEVEL_NONE && warningLevel <= UP_DEVICE_LEVEL_ACTION;
+    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::warningLevelCallback(LowPowerModeNotifier* notifier)
+void LowPowerModeNotifier::warningLevelChanged()
 {
-    notifier->updateState();
-    notifier->m_callback(notifier->m_lowPowerModeEnabled);
+    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_signal_handlers_disconnect_by_data(m_device.get(), this);
+    g_cancellable_cancel(m_cancellable.get());
 }
 
 bool LowPowerModeNotifier::isLowPowerModeEnabled() const
@@ -55,5 +104,4 @@
     return m_lowPowerModeEnabled;
 }
 
-}
-#endif
+} // namespace WebCore

Deleted: trunk/Source/cmake/FindUPowerGLib.cmake (228887 => 228888)


--- trunk/Source/cmake/FindUPowerGLib.cmake	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/Source/cmake/FindUPowerGLib.cmake	2018-02-21 19:42:35 UTC (rev 228888)
@@ -1,47 +0,0 @@
-# - Try to find libupower-glib.
-# Once done, this will define
-#
-#  UPOWERGLIB_INCLUDE_DIRS - the libtasn1 include directories
-#  UPOWERGLIB_LIBRARIES - the libtasn1 libraries.
-#
-# Copyright (C) 2017 Collabora Ltd.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
-# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-# THE POSSIBILITY OF SUCH DAMAGE.
-
-find_package(PkgConfig)
-pkg_check_modules(PC_UPOWERGLIB QUIET upower-glib)
-
-find_path(UPOWERGLIB_INCLUDE_DIRS
-    NAMES libupower-glib/upower.h
-    PATHS ${PC_UPOWERGLIB_INCLUDEDIR} ${PC_UPOWERGLIB_INCLUDE_DIRS}
-)
-
-find_library(UPOWERGLIB_LIBRARIES
-    NAMES upower-glib
-    PATHS ${PC_UPOWERGLIB_LIBDIR} ${PC_UPOWERGLIB_LIBRARY_DIRS}
-)
-
-mark_as_advanced(UPOWERGLIB_INCLUDE_DIRS UPOWERGLIB_LIBRARIES)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(UPowerGLib REQUIRED_VARS UPOWERGLIB_INCLUDE_DIRS UPOWERGLIB_LIBRARIES
-                                  VERSION_VAR   PC_UPOWERGLIB_VERSION)

Modified: trunk/Source/cmake/OptionsGTK.cmake (228887 => 228888)


--- trunk/Source/cmake/OptionsGTK.cmake	2018-02-21 19:41:03 UTC (rev 228887)
+++ trunk/Source/cmake/OptionsGTK.cmake	2018-02-21 19:42:35 UTC (rev 228888)
@@ -81,7 +81,6 @@
 WEBKIT_OPTION_DEFINE(USE_LIBNOTIFY "Whether to enable the default web notification implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBHYPHEN "Whether to enable the default automatic hyphenation implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBSECRET "Whether to enable the persistent credential storage using libsecret." PUBLIC ON)
-WEBKIT_OPTION_DEFINE(USE_UPOWER "Whether to enable the low power mode implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_WOFF2 "Whether to enable support for WOFF2 Web Fonts." PUBLIC ON)
 
 # Private options specific to the GTK+ port. Changing these options is
@@ -341,13 +340,6 @@
     endif ()
 endif ()
 
-if (USE_UPOWER)
-    find_package(UPowerGLib)
-    if (NOT UPOWERGLIB_FOUND)
-       message(FATAL_ERROR "upower-glib is needed for USE_UPOWER.")
-    endif ()
-endif ()
-
 if (USE_WOFF2)
     find_package(WOFF2Dec 1.0.2)
     if (NOT WOFF2DEC_FOUND)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to