Changeset 228888 in webkit


Ignore:
Timestamp:
Feb 21, 2018 11:42:35 AM (6 years ago)
Author:
Michael Catanzaro
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.

Location:
trunk
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r228826 r228888  
     12018-02-21  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [GTK] USE_UPOWER causes crashes inside a chroot or on systems with broken dbus/upower
     4        https://bugs.webkit.org/show_bug.cgi?id=181825
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Get rid of the upower-glib dependency. We will use upower's D-Bus API instead.
     9
     10        * Source/cmake/FindUPowerGLib.cmake: Removed.
     11        * Source/cmake/OptionsGTK.cmake:
     12
    1132018-02-20  Adrian Perez de Castro  <aperez@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r228886 r228888  
     12018-02-21  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [GTK] USE_UPOWER causes crashes inside a chroot or on systems with broken dbus/upower
     4        https://bugs.webkit.org/show_bug.cgi?id=181825
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        We could fix this crash, but that would not be good enough, because upower-glib is a
     9        synchronous API that wraps D-Bus calls. That's not acceptable for use in the web process.
     10        Rewrite LowPowerModeNotifierGLib to use upower's D-Bus API directly, instead.
     11
     12        Note that this also enables LowPowerModeNotifier for WPE, since the USE(UPOWER) build
     13        flag is no longer needed.
     14
     15        * platform/LowPowerModeNotifier.cpp:
     16        * platform/LowPowerModeNotifier.h:
     17        * platform/glib/LowPowerModeNotifierGLib.cpp:
     18        (WebCore::LowPowerModeNotifier::LowPowerModeNotifier):
     19        (WebCore::LowPowerModeNotifier::updateWarningLevel):
     20        (WebCore::LowPowerModeNotifier::warningLevelChanged):
     21        (WebCore::LowPowerModeNotifier::gPropertiesChangedCallback):
     22        (WebCore::LowPowerModeNotifier::~LowPowerModeNotifier):
     23        (WebCore::LowPowerModeNotifier::updateState): Deleted.
     24        (WebCore::LowPowerModeNotifier::warningLevelCallback): Deleted.
     25
    1262018-02-21  Chris Dumez  <cdumez@apple.com>
    227
  • trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp

    r223728 r228888  
    2929namespace WebCore {
    3030
    31 #if !PLATFORM(IOS) && !USE(UPOWER)
     31#if !PLATFORM(IOS) && !USE(GLIB)
    3232
    3333LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&&)
  • trunk/Source/WebCore/platform/LowPowerModeNotifier.h

    r222834 r228888  
    2929
    3030#if PLATFORM(IOS)
    31 
    3231#include <wtf/RetainPtr.h>
    3332OBJC_CLASS WebLowPowerModeObserver;
    34 
    3533#endif
    3634
    37 #if USE(UPOWER)
    38 #include <libupower-glib/upower.h>
     35#if USE(GLIB)
    3936#include <wtf/glib/GRefPtr.h>
     37typedef _GDBusProxy GDBusProxy;
    4038#endif
    4139
     
    5755    RetainPtr<WebLowPowerModeObserver> m_observer;
    5856    LowPowerModeChangeCallback m_callback;
    59 #elif USE(UPOWER)
    60     static void warningLevelCallback(LowPowerModeNotifier*);
    61     void updateState();
     57#elif USE(GLIB)
     58    void updateWarningLevel();
     59    void warningLevelChanged();
     60    static void gPropertiesChangedCallback(LowPowerModeNotifier*, GVariant* changedProperties);
    6261
    63     GRefPtr<UpClient> m_upClient;
    64     GRefPtr<UpDevice> m_device;
     62    GRefPtr<GDBusProxy> m_displayDeviceProxy;
     63    GRefPtr<GCancellable> m_cancellable;
    6564    LowPowerModeChangeCallback m_callback;
    6665    bool m_lowPowerModeEnabled { false };
  • trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp

    r223954 r228888  
    11/*
    22 *  Copyright (C) 2017 Collabora Ltd.
     3 *  Copyright (C) 2018 Igalia S.L.
    34 *
    45 *  This library is free software; you can redistribute it and/or
     
    2021#include "LowPowerModeNotifier.h"
    2122
    22 #if USE(UPOWER)
     23#include <cstring>
     24#include <gio/gio.h>
     25
    2326namespace WebCore {
    2427
     28static const char kWarningLevel[] = "WarningLevel";
     29
    2530LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&& callback)
    26     : m_upClient(adoptGRef(up_client_new()))
    27     , m_device(adoptGRef(up_client_get_display_device(m_upClient.get())))
     31    : m_cancellable(adoptGRef(g_cancellable_new()))
    2832    , m_callback(WTFMove(callback))
    2933{
    30     updateState();
     34    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),
     35        nullptr, "org.freedesktop.UPower", "/org/freedesktop/UPower/devices/DisplayDevice", "org.freedesktop.UPower.Device", m_cancellable.get(),
     36        [](GObject*, GAsyncResult* result, gpointer userData) {
     37            GUniqueOutPtr<GError> error;
     38            GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
     39            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
     40                return;
    3141
    32     g_signal_connect_swapped(m_device.get(), "notify::warning-level", G_CALLBACK(warningLevelCallback), this);
     42            auto* self = static_cast<LowPowerModeNotifier*>(userData);
     43            if (proxy) {
     44                GUniquePtr<char> nameOwner(g_dbus_proxy_get_name_owner(proxy.get()));
     45                if (nameOwner) {
     46                    self->m_displayDeviceProxy = WTFMove(proxy);
     47                    self->updateWarningLevel();
     48                    g_signal_connect_swapped(self->m_displayDeviceProxy.get(), "g-properties-changed", G_CALLBACK(gPropertiesChangedCallback), self);
     49                    return;
     50                }
     51            }
     52
     53            // Now, if there is no name owner, it would be good to try to
     54            // connect to a Flatpak battery status portal instead.
     55            // Unfortunately, no such portal currently exists.
     56            self->m_cancellable = nullptr;
     57    }, this);
    3358}
    3459
    35 void LowPowerModeNotifier::updateState()
     60void LowPowerModeNotifier::updateWarningLevel()
    3661{
    37     UpDeviceLevel warningLevel;
    38     g_object_get(G_OBJECT(m_device.get()), "warning-level", &warningLevel, nullptr);
    39     m_lowPowerModeEnabled = warningLevel > UP_DEVICE_LEVEL_NONE && warningLevel <= UP_DEVICE_LEVEL_ACTION;
     62    GRefPtr<GVariant> variant = adoptGRef(g_dbus_proxy_get_cached_property(m_displayDeviceProxy.get(), kWarningLevel));
     63    if (!variant) {
     64        m_lowPowerModeEnabled = false;
     65        return;
     66    }
     67
     68    // 0: Unknown
     69    // 1: None
     70    // 2: Discharging (only for universal power supplies)
     71    // 3: Low
     72    // 4: Critical
     73    // 5: Action
     74    m_lowPowerModeEnabled = g_variant_get_uint32(variant.get()) > 1;
    4075}
    4176
    42 void LowPowerModeNotifier::warningLevelCallback(LowPowerModeNotifier* notifier)
     77void LowPowerModeNotifier::warningLevelChanged()
    4378{
    44     notifier->updateState();
    45     notifier->m_callback(notifier->m_lowPowerModeEnabled);
     79    updateWarningLevel();
     80    m_callback(m_lowPowerModeEnabled);
     81}
     82
     83void LowPowerModeNotifier::gPropertiesChangedCallback(LowPowerModeNotifier* self, GVariant* changedProperties)
     84{
     85    GUniqueOutPtr<GVariantIter> iter;
     86    g_variant_get(changedProperties, "a{sv}", &iter.outPtr());
     87
     88    const char* propertyName;
     89    while (g_variant_iter_next(iter.get(), "{&sv}", &propertyName, nullptr)) {
     90        if (!strcmp(propertyName, kWarningLevel)) {
     91            self->warningLevelChanged();
     92            break;
     93        }
     94    }
    4695}
    4796
    4897LowPowerModeNotifier::~LowPowerModeNotifier()
    4998{
    50     g_signal_handlers_disconnect_by_data(m_device.get(), this);
     99    g_cancellable_cancel(m_cancellable.get());
    51100}
    52101
     
    56105}
    57106
    58 }
    59 #endif
     107} // namespace WebCore
  • trunk/Source/cmake/OptionsGTK.cmake

    r228590 r228888  
    8282WEBKIT_OPTION_DEFINE(USE_LIBHYPHEN "Whether to enable the default automatic hyphenation implementation." PUBLIC ON)
    8383WEBKIT_OPTION_DEFINE(USE_LIBSECRET "Whether to enable the persistent credential storage using libsecret." PUBLIC ON)
    84 WEBKIT_OPTION_DEFINE(USE_UPOWER "Whether to enable the low power mode implementation." PUBLIC ON)
    8584WEBKIT_OPTION_DEFINE(USE_WOFF2 "Whether to enable support for WOFF2 Web Fonts." PUBLIC ON)
    8685
     
    342341endif ()
    343342
    344 if (USE_UPOWER)
    345     find_package(UPowerGLib)
    346     if (NOT UPOWERGLIB_FOUND)
    347        message(FATAL_ERROR "upower-glib is needed for USE_UPOWER.")
    348     endif ()
    349 endif ()
    350 
    351343if (USE_WOFF2)
    352344    find_package(WOFF2Dec 1.0.2)
Note: See TracChangeset for help on using the changeset viewer.