Title: [284370] trunk/Source
Revision
284370
Author
[email protected]
Date
2021-10-18 06:18:33 -0700 (Mon, 18 Oct 2021)

Log Message

[GLIB] Simplify SleepDisabler by checking if we are under sandbox
https://bugs.webkit.org/show_bug.cgi?id=231670

Reviewed by Adrian Perez de Castro.

Source/WebCore/PAL:

Current implementation always tries to connect to ScreenSaver interface and if that fails tries with the portal
one. It's simpler to check if we are under sandbox and it avoids a connection that we know is always going to
fail.

* pal/system/glib/SleepDisablerGLib.cpp:
(PAL::SleepDisablerGLib::SleepDisablerGLib):
(PAL::SleepDisablerGLib::acquireInhibitor):
(PAL::SleepDisablerGLib::releaseInhibitor):
(PAL::SleepDisablerGLib::acquireInhibitorViaScreenSaverProxy): Deleted.
(PAL::SleepDisablerGLib::acquireInhibitorViaInhibitPortalProxy): Deleted.
(PAL::SleepDisablerGLib::releaseInhibitorViaScreenSaverProxy): Deleted.
(PAL::SleepDisablerGLib::releaseInhibitorViaInhibitPortalProxy): Deleted.
* pal/system/glib/SleepDisablerGLib.h:

Source/WebKit:

Move functions to check if running inside a sandbox to WTF.

* UIProcess/Launcher/glib/ProcessLauncherGLib.cpp:
(WebKit::isInsideDocker): Deleted.
(WebKit::isInsideFlatpak): Deleted.
(WebKit::isInsideSnap): Deleted.

Source/WTF:

Move function to check if running inside a sandbox and add shouldUsePortal() to check whether portal sandbox
should be used. WEBKIT_USE_PORTAL environment variable can be used to force the use of portals when not running
under the sandbox.

* wtf/PlatformGTK.cmake:
* wtf/PlatformWPE.cmake:
* wtf/glib/Sandbox.cpp: Added.
(WTF::isInsideFlatpak):
(WTF::isInsideDocker):
(WTF::isInsideSnap):
(WTF::shouldUsePortal):
* wtf/glib/Sandbox.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (284369 => 284370)


--- trunk/Source/WTF/ChangeLog	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WTF/ChangeLog	2021-10-18 13:18:33 UTC (rev 284370)
@@ -1,3 +1,23 @@
+2021-10-18  Carlos Garcia Campos  <[email protected]>
+
+        [GLIB] Simplify SleepDisabler by checking if we are under sandbox
+        https://bugs.webkit.org/show_bug.cgi?id=231670
+
+        Reviewed by Adrian Perez de Castro.
+
+        Move function to check if running inside a sandbox and add shouldUsePortal() to check whether portal sandbox
+        should be used. WEBKIT_USE_PORTAL environment variable can be used to force the use of portals when not running
+        under the sandbox.
+
+        * wtf/PlatformGTK.cmake:
+        * wtf/PlatformWPE.cmake:
+        * wtf/glib/Sandbox.cpp: Added.
+        (WTF::isInsideFlatpak):
+        (WTF::isInsideDocker):
+        (WTF::isInsideSnap):
+        (WTF::shouldUsePortal):
+        * wtf/glib/Sandbox.h: Added.
+
 2021-10-18  Yusuke Suzuki  <[email protected]>
 
         Remove AVOID_NATIVE_INT128_T

Modified: trunk/Source/WTF/wtf/PlatformGTK.cmake (284369 => 284370)


--- trunk/Source/WTF/wtf/PlatformGTK.cmake	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WTF/wtf/PlatformGTK.cmake	2021-10-18 13:18:33 UTC (rev 284370)
@@ -8,6 +8,7 @@
     glib/GTypedefs.h
     glib/GUniquePtr.h
     glib/RunLoopSourcePriority.h
+    glib/Sandbox.h
     glib/SocketConnection.h
     glib/WTFGType.h
 )
@@ -32,6 +33,7 @@
     glib/GRefPtr.cpp
     glib/GSocketMonitor.cpp
     glib/RunLoopGLib.cpp
+    glib/Sandbox.cpp
     glib/SocketConnection.cpp
     glib/URLGLib.cpp
 

Modified: trunk/Source/WTF/wtf/PlatformWPE.cmake (284369 => 284370)


--- trunk/Source/WTF/wtf/PlatformWPE.cmake	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WTF/wtf/PlatformWPE.cmake	2021-10-18 13:18:33 UTC (rev 284370)
@@ -6,6 +6,7 @@
     glib/GTypedefs.h
     glib/GUniquePtr.h
     glib/RunLoopSourcePriority.h
+    glib/Sandbox.h
     glib/SocketConnection.h
     glib/WTFGType.h
 
@@ -23,6 +24,7 @@
     glib/GRefPtr.cpp
     glib/GSocketMonitor.cpp
     glib/RunLoopGLib.cpp
+    glib/Sandbox.cpp
     glib/SocketConnection.cpp
     glib/URLGLib.cpp
 

Added: trunk/Source/WTF/wtf/glib/Sandbox.cpp (0 => 284370)


--- trunk/Source/WTF/wtf/glib/Sandbox.cpp	                        (rev 0)
+++ trunk/Source/WTF/wtf/glib/Sandbox.cpp	2021-10-18 13:18:33 UTC (rev 284370)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ * 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. ``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
+ * 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.
+ */
+
+#include "config.h"
+#include <wtf/glib/Sandbox.h>
+
+#include <glib.h>
+
+namespace WTF {
+
+bool isInsideFlatpak()
+{
+    static bool returnValue = g_file_test("/.flatpak-info", G_FILE_TEST_EXISTS);
+    return returnValue;
+}
+
+bool isInsideDocker()
+{
+    static bool returnValue = g_file_test("/.dockerenv", G_FILE_TEST_EXISTS);
+    return returnValue;
+}
+
+bool isInsideSnap()
+{
+    // The "SNAP" environment variable is not unlikely to be set for/by something other
+    // than Snap, so check a couple of additional variables to avoid false positives.
+    // See: https://snapcraft.io/docs/environment-variables
+    static bool returnValue = g_getenv("SNAP") && g_getenv("SNAP_NAME") && g_getenv("SNAP_REVISION");
+    return returnValue;
+}
+
+bool shouldUsePortal()
+{
+    static bool returnValue = []() -> bool {
+        const char* usePortal = isInsideFlatpak() || isInsideSnap() ? "1" : g_getenv("WEBKIT_USE_PORTAL");
+        return usePortal && usePortal[0] != '0';
+    }();
+    return returnValue;
+}
+
+} // namespace WTF

Added: trunk/Source/WTF/wtf/glib/Sandbox.h (0 => 284370)


--- trunk/Source/WTF/wtf/glib/Sandbox.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/glib/Sandbox.h	2021-10-18 13:18:33 UTC (rev 284370)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+namespace WTF {
+
+WTF_EXPORT_PRIVATE bool isInsideFlatpak();
+WTF_EXPORT_PRIVATE bool isInsideDocker();
+WTF_EXPORT_PRIVATE bool isInsideSnap();
+WTF_EXPORT_PRIVATE bool shouldUsePortal();
+
+} // namespace WTF
+
+using WTF::isInsideFlatpak;
+using WTF::isInsideDocker;
+using WTF::isInsideSnap;
+using WTF::shouldUsePortal;

Modified: trunk/Source/WebCore/PAL/ChangeLog (284369 => 284370)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-10-18 13:18:33 UTC (rev 284370)
@@ -1,3 +1,24 @@
+2021-10-18  Carlos Garcia Campos  <[email protected]>
+
+        [GLIB] Simplify SleepDisabler by checking if we are under sandbox
+        https://bugs.webkit.org/show_bug.cgi?id=231670
+
+        Reviewed by Adrian Perez de Castro.
+
+        Current implementation always tries to connect to ScreenSaver interface and if that fails tries with the portal
+        one. It's simpler to check if we are under sandbox and it avoids a connection that we know is always going to
+        fail.
+
+        * pal/system/glib/SleepDisablerGLib.cpp:
+        (PAL::SleepDisablerGLib::SleepDisablerGLib):
+        (PAL::SleepDisablerGLib::acquireInhibitor):
+        (PAL::SleepDisablerGLib::releaseInhibitor):
+        (PAL::SleepDisablerGLib::acquireInhibitorViaScreenSaverProxy): Deleted.
+        (PAL::SleepDisablerGLib::acquireInhibitorViaInhibitPortalProxy): Deleted.
+        (PAL::SleepDisablerGLib::releaseInhibitorViaScreenSaverProxy): Deleted.
+        (PAL::SleepDisablerGLib::releaseInhibitorViaInhibitPortalProxy): Deleted.
+        * pal/system/glib/SleepDisablerGLib.h:
+
 2021-10-17  David Kilzer  <[email protected]>
 
         Build fix #3: Adopt attribution AVCaptureSession SPI for GPU process

Modified: trunk/Source/WebCore/PAL/pal/system/glib/SleepDisablerGLib.cpp (284369 => 284370)


--- trunk/Source/WebCore/PAL/pal/system/glib/SleepDisablerGLib.cpp	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WebCore/PAL/pal/system/glib/SleepDisablerGLib.cpp	2021-10-18 13:18:33 UTC (rev 284370)
@@ -28,6 +28,7 @@
 
 #include <gio/gio.h>
 #include <wtf/glib/GUniquePtr.h>
+#include <wtf/glib/Sandbox.h>
 
 namespace PAL {
 
@@ -49,49 +50,29 @@
     // ever need this distinction, which seems unlikely, then we'll need to
     // audit all use of SleepDisabler.
 
-    // First, try to use the ScreenSaver API.
+    const char* busName = shouldUsePortal() ? "org.freedesktop.portal.Desktop" : "org.freedesktop.ScreenSaver";
+    const char* objectPath = shouldUsePortal() ? "/org/freedesktop/portal/desktop" : "/org/freedesktop/ScreenSaver";
+    const char* interfaceName = shouldUsePortal() ? "org.freedesktop.portal.Inhibit" : "org.freedesktop.ScreenSaver";
     g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS),
-        nullptr, "org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver", 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))
+        nullptr, busName, objectPath, interfaceName, 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<SleepDisablerGLib*>(userData);
+        if (proxy) {
+            GUniquePtr<char> nameOwner(g_dbus_proxy_get_name_owner(proxy.get()));
+            if (nameOwner) {
+                self->m_screenSaverProxy = WTFMove(proxy);
+                self->acquireInhibitor();
                 return;
-
-            auto* self = static_cast<SleepDisablerGLib*>(userData);
-            if (proxy) {
-                // Under Flatpak, we'll get a useless proxy with no name owner.
-                GUniquePtr<char> nameOwner(g_dbus_proxy_get_name_owner(proxy.get()));
-                if (nameOwner) {
-                    self->m_screenSaverProxy = WTFMove(proxy);
-                    self->acquireInhibitor();
-                    return;
-                }
             }
+        }
 
-            // It failed. Try to use the Flatpak portal instead.
-            g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS),
-                nullptr, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.Inhibit", self->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<SleepDisablerGLib*>(userData);
-                    if (proxy) {
-                        GUniquePtr<char> nameOwner(g_dbus_proxy_get_name_owner(proxy.get()));
-                        if (nameOwner) {
-                            self->m_inhibitPortalProxy = WTFMove(proxy);
-                            self->acquireInhibitor();
-                            return;
-                        }
-                    }
-
-                    // Give up. Don't warn the user: this is expected.
-                    self->m_cancellable = nullptr;
-            }, self);
-        }, this);
+        // Give up. Don't warn the user: this is expected.
+        self->m_cancellable = nullptr;
+    }, this);
 }
 
 SleepDisablerGLib::~SleepDisablerGLib()
@@ -104,105 +85,67 @@
 
 void SleepDisablerGLib::acquireInhibitor()
 {
-    if (m_screenSaverProxy) {
-        ASSERT(!m_inhibitPortalProxy);
-        acquireInhibitorViaScreenSaverProxy();
-    } else {
-        ASSERT(m_inhibitPortalProxy);
-        acquireInhibitorViaInhibitPortalProxy();
-    }
-}
+    GVariant* parameters;
+    if (shouldUsePortal()) {
+        GVariantBuilder builder;
+        g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+        g_variant_builder_add(&builder, "{sv}", "reason", g_variant_new_string(m_reason.data()));
+        parameters = g_variant_new("(su@a{sv})", "" /* no window */, 8 /* idle */, g_variant_builder_end(&builder));
+    } else
+        parameters = g_variant_new("(ss)", g_get_prgname(), m_reason.data());
 
-void SleepDisablerGLib::acquireInhibitorViaScreenSaverProxy()
-{
-    g_dbus_proxy_call(m_screenSaverProxy.get(), "Inhibit", g_variant_new("(ss)", g_get_prgname(), m_reason.data()),
-        G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(), [](GObject* proxy, GAsyncResult* result, gpointer userData) {
-            GUniqueOutPtr<GError> error;
-            GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error.outPtr()));
-            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
-                return;
+    g_dbus_proxy_call(m_screenSaverProxy.get(), "Inhibit", parameters, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(), [](GObject* proxy, GAsyncResult* result, gpointer userData) {
+        GUniqueOutPtr<GError> error;
+        GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error.outPtr()));
+        if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+            return;
 
-            auto* self = static_cast<SleepDisablerGLib*>(userData);
-            if (error)
-                g_warning("Calling %s.Inhibit failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
-            else {
-                ASSERT(returnValue);
+        auto* self = static_cast<SleepDisablerGLib*>(userData);
+        if (error)
+            g_warning("Calling %s.Inhibit failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
+        else {
+            ASSERT(returnValue);
+            if (shouldUsePortal())
+                g_variant_get(returnValue.get(), "(o)", &self->m_inhibitPortalRequestObjectPath.outPtr());
+            else
                 g_variant_get(returnValue.get(), "(u)", &self->m_screenSaverCookie);
-            }
-            self->m_cancellable = nullptr;
-        }, this);
+        }
+        self->m_cancellable = nullptr;
+    }, this);
 }
 
-void SleepDisablerGLib::acquireInhibitorViaInhibitPortalProxy()
+void SleepDisablerGLib::releaseInhibitor()
 {
-    GVariantBuilder builder;
-    g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
-    g_variant_builder_add(&builder, "{sv}", "reason", g_variant_new_string(m_reason.data()));
-    g_dbus_proxy_call(m_inhibitPortalProxy.get(), "Inhibit", g_variant_new("(su@a{sv})", "" /* no window */, 8 /* idle */, g_variant_builder_end(&builder)),
-        G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(), [](GObject* proxy, GAsyncResult* result, gpointer userData) {
+    if (!shouldUsePortal()) {
+        ASSERT(m_screenSaverCookie);
+        g_dbus_proxy_call(m_screenSaverProxy.get(), "UnInhibit", g_variant_new("(u)", m_screenSaverCookie), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, [](GObject* proxy, GAsyncResult* result, gpointer) {
             GUniqueOutPtr<GError> error;
             GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error.outPtr()));
-            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
-                return;
-
-            auto* self = static_cast<SleepDisablerGLib*>(userData);
             if (error)
-                g_warning("Calling %s.Inhibit failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
-            else {
-                ASSERT(returnValue);
-                g_variant_get(returnValue.get(), "(o)", &self->m_inhibitPortalRequestObjectPath.outPtr());
-            }
-            self->m_cancellable = nullptr;
-        }, this);
-}
+                g_warning("Calling %s.UnInhibit failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
+        }, nullptr);
 
-void SleepDisablerGLib::releaseInhibitor()
-{
-    if (m_screenSaverProxy) {
-        ASSERT(!m_inhibitPortalProxy);
-        releaseInhibitorViaScreenSaverProxy();
-    } else {
-        ASSERT(m_inhibitPortalProxy);
-        releaseInhibitorViaInhibitPortalProxy();
+        return;
     }
-}
 
-void SleepDisablerGLib::releaseInhibitorViaScreenSaverProxy()
-{
-    ASSERT(m_screenSaverCookie);
+    ASSERT(m_inhibitPortalRequestObjectPath);
+    g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS),
+        nullptr, "org.freedesktop.portal.Desktop", m_inhibitPortalRequestObjectPath.get(), "org.freedesktop.portal.Request", nullptr, [](GObject*, GAsyncResult* result, gpointer) {
+        GUniqueOutPtr<GError> error;
+        GRefPtr<GDBusProxy> requestProxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
+        if (error) {
+            g_warning("Failed to create org.freedesktop.portal.Request proxy: %s", error->message);
+            return;
+        }
 
-    g_dbus_proxy_call(m_screenSaverProxy.get(), "UnInhibit", g_variant_new("(u)", m_screenSaverCookie),
-        G_DBUS_CALL_FLAGS_NONE, -1, nullptr, [](GObject* proxy, GAsyncResult* result, gpointer) {
+        ASSERT(requestProxy);
+        g_dbus_proxy_call(requestProxy.get(), "Close", g_variant_new("()"), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, [](GObject* proxy, GAsyncResult* result, gpointer) {
             GUniqueOutPtr<GError> error;
             GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error.outPtr()));
             if (error)
-                g_warning("Calling %s.UnInhibit failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
+                g_warning("Calling %s.Close failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
+        }, nullptr);
     }, nullptr);
 }
 
-void SleepDisablerGLib::releaseInhibitorViaInhibitPortalProxy()
-{
-    ASSERT(m_inhibitPortalRequestObjectPath);
-
-    g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS),
-        nullptr, "org.freedesktop.portal.Desktop", m_inhibitPortalRequestObjectPath.get(), "org.freedesktop.portal.Request", nullptr,
-        [](GObject*, GAsyncResult* result, gpointer) {
-            GUniqueOutPtr<GError> error;
-            GRefPtr<GDBusProxy> requestProxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
-            if (error) {
-                g_warning("Failed to create org.freedesktop.portal.Request proxy: %s", error->message);
-                return;
-            }
-
-            ASSERT(requestProxy);
-            g_dbus_proxy_call(requestProxy.get(), "Close", g_variant_new("()"), G_DBUS_CALL_FLAGS_NONE, -1, nullptr,
-                [](GObject* proxy, GAsyncResult* result, gpointer) {
-                    GUniqueOutPtr<GError> error;
-                    GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error.outPtr()));
-                    if (error)
-                        g_warning("Calling %s.Close failed: %s", g_dbus_proxy_get_interface_name(G_DBUS_PROXY(proxy)), error->message);
-                }, nullptr);
-        }, nullptr);
-}
-
 } // namespace PAL

Modified: trunk/Source/WebCore/PAL/pal/system/glib/SleepDisablerGLib.h (284369 => 284370)


--- trunk/Source/WebCore/PAL/pal/system/glib/SleepDisablerGLib.h	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WebCore/PAL/pal/system/glib/SleepDisablerGLib.h	2021-10-18 13:18:33 UTC (rev 284370)
@@ -35,7 +35,7 @@
 
 namespace PAL {
 
-class SleepDisablerGLib : public SleepDisabler {
+class SleepDisablerGLib final : public SleepDisabler {
 public:
     SleepDisablerGLib(const char*, Type);
     virtual ~SleepDisablerGLib();
@@ -51,10 +51,7 @@
 
     GRefPtr<GDBusProxy> m_screenSaverProxy;
     unsigned m_screenSaverCookie { 0 };
-
-    GRefPtr<GDBusProxy> m_inhibitPortalProxy;
     GUniqueOutPtr<char> m_inhibitPortalRequestObjectPath;
-
     GRefPtr<GCancellable> m_cancellable;
     CString m_reason;
 };

Modified: trunk/Source/WebKit/ChangeLog (284369 => 284370)


--- trunk/Source/WebKit/ChangeLog	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WebKit/ChangeLog	2021-10-18 13:18:33 UTC (rev 284370)
@@ -1,3 +1,17 @@
+2021-10-18  Carlos Garcia Campos  <[email protected]>
+
+        [GLIB] Simplify SleepDisabler by checking if we are under sandbox
+        https://bugs.webkit.org/show_bug.cgi?id=231670
+
+        Reviewed by Adrian Perez de Castro.
+
+        Move functions to check if running inside a sandbox to WTF.
+
+        * UIProcess/Launcher/glib/ProcessLauncherGLib.cpp:
+        (WebKit::isInsideDocker): Deleted.
+        (WebKit::isInsideFlatpak): Deleted.
+        (WebKit::isInsideSnap): Deleted.
+
 2021-10-18  Philippe Normand  <[email protected]>
 
         [GStreamer] fast/mediastream/video-rotation tests are failing due to missing TestController::takeViewPortSnapshot

Modified: trunk/Source/WebKit/UIProcess/Launcher/glib/ProcessLauncherGLib.cpp (284369 => 284370)


--- trunk/Source/WebKit/UIProcess/Launcher/glib/ProcessLauncherGLib.cpp	2021-10-18 13:17:20 UTC (rev 284369)
+++ trunk/Source/WebKit/UIProcess/Launcher/glib/ProcessLauncherGLib.cpp	2021-10-18 13:18:33 UTC (rev 284370)
@@ -38,6 +38,7 @@
 #include <wtf/RunLoop.h>
 #include <wtf/UniStdExtras.h>
 #include <wtf/glib/GUniquePtr.h>
+#include <wtf/glib/Sandbox.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
@@ -63,41 +64,6 @@
 }
 #endif
 
-#if ENABLE(BUBBLEWRAP_SANDBOX)
-static bool isInsideDocker()
-{
-    static std::optional<bool> ret;
-    if (ret)
-        return *ret;
-
-    ret = g_file_test("/.dockerenv", G_FILE_TEST_EXISTS);
-    return *ret;
-}
-
-static bool isInsideFlatpak()
-{
-    static std::optional<bool> ret;
-    if (ret)
-        return *ret;
-
-    ret = g_file_test("/.flatpak-info", G_FILE_TEST_EXISTS);
-    return *ret;
-}
-
-static bool isInsideSnap()
-{
-    static std::optional<bool> ret;
-    if (ret)
-        return *ret;
-
-    // The "SNAP" environment variable is not unlikely to be set for/by something other
-    // than Snap, so check a couple of additional variables to avoid false positives.
-    // See: https://snapcraft.io/docs/environment-variables
-    ret = g_getenv("SNAP") && g_getenv("SNAP_NAME") && g_getenv("SNAP_REVISION");
-    return *ret;
-}
-#endif
-
 void ProcessLauncher::launchProcess()
 {
     IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection(IPC::Connection::ConnectionOptions::SetCloexecOnServer);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to