Skip to content
Permalink
Browse files
[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.

Canonical link: https://commits.webkit.org/243155@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284370 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Oct 18, 2021
1 parent 51b057a commit a4101da645cd966fdc36e76fde27419577cd7e95
Showing 10 changed files with 225 additions and 163 deletions.
@@ -1,3 +1,23 @@
2021-10-18 Carlos Garcia Campos <cgarcia@igalia.com>

[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 <ysuzuki@apple.com>

Remove AVOID_NATIVE_INT128_T
@@ -8,6 +8,7 @@ list(APPEND WTF_PUBLIC_HEADERS
glib/GTypedefs.h
glib/GUniquePtr.h
glib/RunLoopSourcePriority.h
glib/Sandbox.h
glib/SocketConnection.h
glib/WTFGType.h
)
@@ -32,6 +33,7 @@ list(APPEND WTF_SOURCES
glib/GRefPtr.cpp
glib/GSocketMonitor.cpp
glib/RunLoopGLib.cpp
glib/Sandbox.cpp
glib/SocketConnection.cpp
glib/URLGLib.cpp

@@ -6,6 +6,7 @@ list(APPEND WTF_PUBLIC_HEADERS
glib/GTypedefs.h
glib/GUniquePtr.h
glib/RunLoopSourcePriority.h
glib/Sandbox.h
glib/SocketConnection.h
glib/WTFGType.h

@@ -23,6 +24,7 @@ list(APPEND WTF_SOURCES
glib/GRefPtr.cpp
glib/GSocketMonitor.cpp
glib/RunLoopGLib.cpp
glib/Sandbox.cpp
glib/SocketConnection.cpp
glib/URLGLib.cpp

@@ -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
@@ -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;
@@ -1,3 +1,24 @@
2021-10-18 Carlos Garcia Campos <cgarcia@igalia.com>

[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 <ddkilzer@apple.com>

Build fix #3: Adopt attribution AVCaptureSession SPI for GPU process

0 comments on commit a4101da

Please sign in to comment.