Diff
Modified: trunk/Source/WebCore/ChangeLog (289527 => 289528)
--- trunk/Source/WebCore/ChangeLog 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebCore/ChangeLog 2022-02-10 13:54:57 UTC (rev 289528)
@@ -1,3 +1,17 @@
+2022-02-10 Carlos Garcia Campos <[email protected]>
+
+ [GTK][WPE] Refactor the XDGDBusProxy launcher to simplify it and fix some issues
+ https://bugs.webkit.org/show_bug.cgi?id=236437
+
+ Reviewed by Adrian Perez de Castro.
+
+ Make accessibility bus address API available for ATK too.
+
+ * platform/graphics/PlatformDisplay.cpp:
+ * platform/graphics/PlatformDisplay.h:
+ * platform/graphics/x11/PlatformDisplayX11.cpp:
+ * platform/graphics/x11/PlatformDisplayX11.h:
+
2022-02-10 Rob Buis <[email protected]>
Incorrect abspos layout when toggling contain
Modified: trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp (289527 => 289528)
--- trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp 2022-02-10 13:54:57 UTC (rev 289528)
@@ -293,7 +293,7 @@
}
#endif
-#if USE(ATSPI)
+#if USE(ATSPI) || USE(ATK)
const String& PlatformDisplay::accessibilityBusAddress() const
{
if (m_accessibilityBusAddress)
Modified: trunk/Source/WebCore/platform/graphics/PlatformDisplay.h (289527 => 289528)
--- trunk/Source/WebCore/platform/graphics/PlatformDisplay.h 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebCore/platform/graphics/PlatformDisplay.h 2022-02-10 13:54:57 UTC (rev 289528)
@@ -90,7 +90,7 @@
virtual cmsHPROFILE colorProfile() const;
#endif
-#if USE(ATSPI)
+#if USE(ATSPI) || USE(ATK)
void setAccessibilityBusAddress(String&& address) { m_accessibilityBusAddress = WTFMove(address); }
const String& accessibilityBusAddress() const;
#endif
@@ -117,7 +117,7 @@
mutable LCMSProfilePtr m_iccProfile;
#endif
-#if USE(ATSPI)
+#if USE(ATSPI) || USE(ATK)
virtual String plartformAccessibilityBusAddress() const { return { }; }
mutable std::optional<String> m_accessibilityBusAddress;
Modified: trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp (289527 => 289528)
--- trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp 2022-02-10 13:54:57 UTC (rev 289528)
@@ -217,7 +217,7 @@
}
#endif
-#if USE(ATSPI)
+#if USE(ATSPI) || USE(ATK)
String PlatformDisplayX11::plartformAccessibilityBusAddress() const
{
Atom atspiBusAtom = XInternAtom(m_display, "AT_SPI_BUS", False);
Modified: trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h (289527 => 289528)
--- trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h 2022-02-10 13:54:57 UTC (rev 289528)
@@ -64,7 +64,7 @@
cmsHPROFILE colorProfile() const override;
#endif
-#if USE(ATSPI)
+#if USE(ATSPI) || USE(ATK)
String plartformAccessibilityBusAddress() const override;
#endif
Modified: trunk/Source/WebKit/ChangeLog (289527 => 289528)
--- trunk/Source/WebKit/ChangeLog 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebKit/ChangeLog 2022-02-10 13:54:57 UTC (rev 289528)
@@ -1,3 +1,46 @@
+2022-02-10 Carlos Garcia Campos <[email protected]>
+
+ [GTK][WPE] Refactor the XDGDBusProxy launcher to simplify it and fix some issues
+ https://bugs.webkit.org/show_bug.cgi?id=236437
+
+ Reviewed by Adrian Perez de Castro.
+
+ This patch moves the XDGDBusProxy launcher implementation to its own file and fixes the following issues:
+
+ - r289369 introduced an issue with old versions of bwrap that fails to mount over an existing file, so we need
+ to ensure we only bind the original socket for the a11y socket and not the session bus one.
+ - bindA11y is GTK specific for some reason, which means WPE doesn't have a11y under the sandbox.
+ - The names of the socket paths for a11y and session bus use the same pattern dbus-proxy-XXXXXX, it helps to
+ use a different one.
+ - The code to get the a11y DBus address is now duplicated in PlatformDisplay, we can just use the
+ PlatformDisplay to get the address.
+
+ * SourcesGTK.txt:
+ * SourcesWPE.txt:
+ * UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
+ (WebKit::argumentsToFileDescriptor):
+ (WebKit::bindDBusSession):
+ (WebKit::bindA11y):
+ (WebKit::bubblewrapSpawn):
+ (WebKit::argsToFd): Deleted.
+ (WebKit::XDGDBusProxyLauncher::setAddress): Deleted.
+ (WebKit::XDGDBusProxyLauncher::isRunning const): Deleted.
+ (WebKit::XDGDBusProxyLauncher::path const): Deleted.
+ (WebKit::XDGDBusProxyLauncher::proxyPath const): Deleted.
+ (WebKit::XDGDBusProxyLauncher::setPermissions): Deleted.
+ (WebKit::XDGDBusProxyLauncher::launch): Deleted.
+ (WebKit::XDGDBusProxyLauncher::makeProxyPath): Deleted.
+ (WebKit::XDGDBusProxyLauncher::dbusAddressToPath): Deleted.
+ (): Deleted.
+ * UIProcess/Launcher/glib/BubblewrapLauncher.h:
+ * UIProcess/Launcher/glib/XDGDBusProxy.cpp: Added.
+ (WebKit::XDGDBusProxy::XDGDBusProxy):
+ (WebKit::XDGDBusProxy::makeProxy const):
+ (WebKit::XDGDBusProxy::launch const):
+ * UIProcess/Launcher/glib/XDGDBusProxy.h: Added.
+ (WebKit::XDGDBusProxy::proxyPath const):
+ (WebKit::XDGDBusProxy::path const):
+
2022-02-10 Kimmo Kinnunen <[email protected]>
Introduce a RemoteMediaSampleProxy to represent captured video frames used in Media Streams and present in GPUP
Modified: trunk/Source/WebKit/SourcesGTK.txt (289527 => 289528)
--- trunk/Source/WebKit/SourcesGTK.txt 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebKit/SourcesGTK.txt 2022-02-10 13:54:57 UTC (rev 289528)
@@ -234,6 +234,7 @@
UIProcess/Launcher/glib/ProcessLauncherGLib.cpp @no-unify
UIProcess/Launcher/glib/BubblewrapLauncher.cpp @no-unify
UIProcess/Launcher/glib/FlatpakLauncher.cpp @no-unify
+UIProcess/Launcher/glib/XDGDBusProxy.cpp @no-unify
UIProcess/linux/MemoryPressureMonitor.cpp
Modified: trunk/Source/WebKit/SourcesWPE.txt (289527 => 289528)
--- trunk/Source/WebKit/SourcesWPE.txt 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebKit/SourcesWPE.txt 2022-02-10 13:54:57 UTC (rev 289528)
@@ -210,6 +210,7 @@
UIProcess/Launcher/glib/ProcessLauncherGLib.cpp
UIProcess/Launcher/glib/BubblewrapLauncher.cpp
UIProcess/Launcher/glib/FlatpakLauncher.cpp
+UIProcess/Launcher/glib/XDGDBusProxy.cpp
UIProcess/WebsiteData/soup/WebsiteDataStoreSoup.cpp
UIProcess/WebsiteData/unix/WebsiteDataStoreUnix.cpp
Modified: trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp (289527 => 289528)
--- trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp 2022-02-10 13:54:57 UTC (rev 289528)
@@ -20,6 +20,7 @@
#if ENABLE(BUBBLEWRAP_SANDBOX)
+#include "XDGDBusProxy.h"
#include <WebCore/PlatformDisplay.h>
#include <fcntl.h>
#include <glib.h>
@@ -42,12 +43,6 @@
#include "WaylandCompositor.h"
#endif
-#if PLATFORM(GTK)
-#define BASE_DIRECTORY "webkitgtk"
-#elif PLATFORM(WPE)
-#define BASE_DIRECTORY "wpe"
-#endif
-
#if !defined(MFD_ALLOW_SEALING) && HAVE(LINUX_MEMFD_H)
// These defines were added in glibc 2.27, the same release that added memfd_create.
@@ -108,8 +103,7 @@
return fd;
}
-static int
-argsToFd(const Vector<CString>& args, const char *name)
+int argumentsToFileDescriptor(const Vector<CString>& args, const char* name)
{
GString* buffer = g_string_new(nullptr);
@@ -165,150 +159,6 @@
return createSealedMemFdWithData("flatpak-info", data->get(), size);
}
-class XDGDBusProxyLauncher {
-public:
- void setAddress(const char* dbusAddress)
- {
- if (!dbusAddress || !g_str_has_prefix(dbusAddress, "unix:"))
- return;
-
- GUniquePtr<char> appRunDir(g_build_filename(g_get_user_runtime_dir(), BASE_DIRECTORY, nullptr));
- m_proxyPath = makeProxyPath(appRunDir.get());
-
- m_socket = dbusAddress;
- m_path = dbusAddressToPath(dbusAddress);
- }
-
- bool isRunning() const { return m_isRunning; };
- const CString& path() const { return m_path; };
- const CString& proxyPath() const { return m_proxyPath; };
-
- void setPermissions(Vector<CString>&& permissions)
- {
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!isRunning());
- m_permissions = WTFMove(permissions);
- };
-
- void launch(bool enableLogging)
- {
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!isRunning());
-
- if (m_socket.isNull() || m_proxyPath.isNull())
- return;
-
- int syncFds[2];
- if (pipe(syncFds) == -1)
- g_error("Failed to make syncfds for dbus-proxy: %s", g_strerror(errno));
- setCloseOnExec(syncFds[0]);
-
- GUniquePtr<char> syncFdStr(g_strdup_printf("--fd=%d", syncFds[1]));
-
- Vector<CString> proxyArgs = {
- m_socket, m_proxyPath,
- "--filter",
- syncFdStr.get(),
- };
-
- if (enableLogging)
- proxyArgs.append("--log");
-
- GUniqueOutPtr<GError> error;
-#if ENABLE(MEDIA_SESSION)
- const char* appID = applicationId(&error.outPtr());
- if (!appID)
- g_warning("Unable to own D-Bus MPRIS name in the WebKit sandbox: %s", error->message);
-
- auto mprisSessionID = makeString("--own=org.mpris.MediaPlayer2.", appID);
- proxyArgs.append(mprisSessionID.ascii().data());
-#endif
-
- proxyArgs.appendVector(m_permissions);
-
- int proxyFd = argsToFd(proxyArgs, "dbus-proxy");
- GUniquePtr<char> proxyArgsStr(g_strdup_printf("--args=%d", proxyFd));
-
- // We have to run xdg-dbus-proxy under bubblewrap because we need /.flatpak-info to exist in
- // xdg-dbus-proxy's mount namespace. Portals may use this as a trusted way to get the
- // sandboxed process's application ID, and will break if it's missing.
- Vector<CString> args = {
- DBUS_PROXY_EXECUTABLE,
- proxyArgsStr.get(),
- };
-
- int nargs = args.size() + 1;
- int i = 0;
- char** argv = g_newa(char*, nargs);
- for (const auto& arg : args)
- argv[i++] = const_cast<char*>(arg.data());
- argv[i] = nullptr;
-
- // Warning: do not set a child setup function, because we want GIO to be able to spawn with
- // posix_spawn() rather than fork()/exec(), in order to better accomodate applications that use
- // a huge amount of memory or address space in the UI process, like Eclipse.
- GRefPtr<GSubprocessLauncher> launcher = adoptGRef(g_subprocess_launcher_new(G_SUBPROCESS_FLAGS_INHERIT_FDS));
- g_subprocess_launcher_take_fd(launcher.get(), proxyFd, proxyFd);
- g_subprocess_launcher_take_fd(launcher.get(), syncFds[1], syncFds[1]);
-
- // We are purposefully leaving syncFds[0] open here.
- // xdg-dbus-proxy will exit() itself once that is closed on our exit
-
- ProcessLauncher::LaunchOptions launchOptions;
- launchOptions.processType = ProcessLauncher::ProcessType::DBusProxy;
- if (!m_path.isNull())
- launchOptions.extraSandboxPaths.add(m_path, SandboxPermission::ReadOnly);
- GRefPtr<GSubprocess> process = bubblewrapSpawn(launcher.get(), launchOptions, argv, &error.outPtr());
- if (!process.get())
- g_error("Failed to start dbus proxy: %s", error->message);
-
- char out;
- // We need to ensure the proxy has created the socket.
- // FIXME: This is more blocking IO.
- if (read(syncFds[0], &out, 1) != 1)
- g_error("Failed to fully launch dbus-proxy %s", g_strerror(errno));
-
- m_isRunning = true;
- };
-
-private:
- static CString makeProxyPath(const char* appRunDir)
- {
- if (g_mkdir_with_parents(appRunDir, 0700) == -1) {
- g_warning("Failed to mkdir for dbus proxy (%s): %s", appRunDir, g_strerror(errno));
- return { };
- }
-
- GUniquePtr<char> proxySocketTemplate(g_build_filename(appRunDir, "dbus-proxy-XXXXXX", nullptr));
- int fd;
- if ((fd = g_mkstemp(proxySocketTemplate.get())) == -1) {
- g_warning("Failed to make socket file for dbus proxy: %s", g_strerror(errno));
- return { };
- }
-
- close(fd);
- return CString(proxySocketTemplate.get());
- };
-
- static CString dbusAddressToPath(const char* address)
- {
- const char* path = strstr(address, "path=");
- if (!path)
- return { };
-
- path += strlen("path=");
- const char* pathEnd = path;
- while (*pathEnd && *pathEnd != ',')
- pathEnd++;
-
- return CString(path, pathEnd - path);
- }
-
- CString m_socket;
- CString m_path;
- CString m_proxyPath;
- bool m_isRunning { false };
- Vector<CString> m_permissions;
-};
-
enum class BindFlags {
ReadOnly,
ReadWrite,
@@ -330,14 +180,13 @@
args.appendVector(Vector<CString>({ bindType, path, path }));
}
-static void bindDBusSession(Vector<CString>& args, XDGDBusProxyLauncher& proxy)
+static void bindDBusSession(Vector<CString>& args, bool allowPortals)
{
- if (!proxy.isRunning())
- proxy.setAddress(g_getenv("DBUS_SESSION_BUS_ADDRESS"));
+ static std::unique_ptr<XDGDBusProxy> proxy = makeUnique<XDGDBusProxy>(XDGDBusProxy::Type::SessionBus, allowPortals);
- if (!proxy.proxyPath().isNull() && !proxy.path().isNull()) {
+ if (!proxy->proxyPath().isNull() && !proxy->path().isNull()) {
args.appendVector(Vector<CString>({
- "--bind", proxy.proxyPath(), proxy.path(),
+ "--bind", proxy->proxyPath(), proxy->path(),
}));
}
}
@@ -474,65 +323,20 @@
bindIfExists(args, themeHomeData.get());
bindIfExists(args, iconHomeData.get());
}
+#endif
+#if ENABLE(ACCESSIBILITY)
static void bindA11y(Vector<CString>& args)
{
- static XDGDBusProxyLauncher proxy;
+ static std::unique_ptr<XDGDBusProxy> proxy = makeUnique<XDGDBusProxy>(XDGDBusProxy::Type::AccessibilityBus);
- if (!proxy.isRunning()) {
- // FIXME: Avoid blocking IO... (It is at least a one-time cost)
- GRefPtr<GDBusConnection> sessionBus = adoptGRef(g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr));
- if (!sessionBus.get())
- return;
-
- GRefPtr<GDBusMessage> msg = adoptGRef(g_dbus_message_new_method_call(
- "org.a11y.Bus", "/org/a11y/bus", "org.a11y.Bus", "GetAddress"));
- g_dbus_message_set_body(msg.get(), g_variant_new("()"));
- GRefPtr<GDBusMessage> reply = adoptGRef(g_dbus_connection_send_message_with_reply_sync(
- sessionBus.get(), msg.get(),
- G_DBUS_SEND_MESSAGE_FLAGS_NONE,
- 30000,
- nullptr,
- nullptr,
- nullptr));
-
- if (reply.get()) {
- GUniqueOutPtr<GError> error;
- if (g_dbus_message_to_gerror(reply.get(), &error.outPtr())) {
- if (!g_error_matches(error.get(), G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN))
- g_warning("Can't find a11y bus: %s", error->message);
- } else {
- GUniqueOutPtr<char> a11yAddress;
- g_variant_get(g_dbus_message_get_body(reply.get()), "(s)", &a11yAddress.outPtr());
- proxy.setAddress(a11yAddress.get());
-#if USE(ATSPI)
- if (!proxy.proxyPath().isNull())
- PlatformDisplay::sharedDisplay().setAccessibilityBusAddress(makeString("unix:path=", proxy.proxyPath().data()));
-#endif
- }
- }
-
- proxy.setPermissions({
- "--sloppy-names",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.Socket.Embed@/org/a11y/atspi/accessible/root",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.Socket.Unembed@/org/a11y/atspi/accessible/root",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.Registry.GetRegisteredEvents@/org/a11y/atspi/registry",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.GetKeystrokeListeners@/org/a11y/atspi/registry/deviceeventcontroller",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.GetDeviceEventListeners@/org/a11y/atspi/registry/deviceeventcontroller",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.NotifyListenersSync@/org/a11y/atspi/registry/deviceeventcontroller",
- "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.NotifyListenersAsync@/org/a11y/atspi/registry/deviceeventcontroller",
+ if (!proxy->proxyPath().isNull()) {
+ GUniquePtr<char> proxyAddress(g_strdup_printf("unix:path=%s", proxy->proxyPath().data()));
+ args.appendVector(Vector<CString> {
+ "--ro-bind", proxy->proxyPath(), proxy->proxyPath(),
+ "--setenv", "AT_SPI_BUS_ADDRESS", proxyAddress.get(),
});
-
- proxy.launch(!g_strcmp0(g_getenv("WEBKIT_ENABLE_A11Y_DBUS_PROXY_LOGGING"), "1"));
}
-
- if (!proxy.proxyPath().isNull()) {
- GUniquePtr<char> proxyAddress(g_strdup_printf("unix:path=%s", proxy.proxyPath().data()));
- args.appendVector(Vector<CString>({
- "--ro-bind", proxy.proxyPath(), proxy.proxyPath(),
- "--setenv", "AT_SPI_BUS_ADDRESS", proxyAddress.get(),
- }));
- }
}
#endif
@@ -918,8 +722,6 @@
}
if (launchOptions.processType == ProcessLauncher::ProcessType::Web) {
- static XDGDBusProxyLauncher proxy;
-
#if PLATFORM(WAYLAND) && USE(EGL)
if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland) {
bindWayland(sandboxArgs);
@@ -940,7 +742,7 @@
sandboxArgs.appendVector(Vector<CString>({ "--bind-try", extraPath.utf8(), extraPath.utf8() }));
}
- bindDBusSession(sandboxArgs, proxy);
+ bindDBusSession(sandboxArgs, flatpakInfoFd != -1);
// FIXME: We should move to Pipewire as soon as viable, Pulse doesn't restrict clients atm.
bindPulse(sandboxArgs);
bindSndio(sandboxArgs);
@@ -949,23 +751,12 @@
bindOpenGL(sandboxArgs);
// FIXME: This is also fixed by Pipewire once in use.
bindV4l(sandboxArgs);
+#if ENABLE(ACCESSIBILITY)
+ bindA11y(sandboxArgs);
+#endif
#if PLATFORM(GTK)
- bindA11y(sandboxArgs);
bindGtkData(sandboxArgs);
#endif
-
- if (!proxy.isRunning()) {
- Vector<CString> permissions = {
- // GStreamers plugin install helper.
- "--call=org.freedesktop.PackageKit=org.freedesktop.PackageKit.Modify2.InstallGStreamerResources@/org/freedesktop/PackageKit"
- };
- if (flatpakInfoFd != -1) {
- // xdg-desktop-portal used by GTK and us.
- permissions.append("--talk=org.freedesktop.portal.Desktop");
- }
- proxy.setPermissions(WTFMove(permissions));
- proxy.launch(!g_strcmp0(g_getenv("WEBKIT_ENABLE_DBUS_PROXY_LOGGING"), "1"));
- }
} else {
// Only X11 users need this for XShm which is only the Web process.
sandboxArgs.append("--unshare-ipc");
@@ -991,7 +782,7 @@
g_subprocess_launcher_take_fd(launcher, seccompFd, seccompFd);
sandboxArgs.appendVector(Vector<CString>({ "--seccomp", fdStr.get() }));
- int bwrapFd = argsToFd(sandboxArgs, "bwrap");
+ int bwrapFd = argumentsToFileDescriptor(sandboxArgs, "bwrap");
GUniquePtr<char> bwrapFdStr(g_strdup_printf("%d", bwrapFd));
g_subprocess_launcher_take_fd(launcher, bwrapFd, bwrapFd);
Modified: trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.h (289527 => 289528)
--- trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.h 2022-02-10 13:02:05 UTC (rev 289527)
+++ trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.h 2022-02-10 13:54:57 UTC (rev 289528)
@@ -37,6 +37,7 @@
namespace WebKit {
GRefPtr<GSubprocess> bubblewrapSpawn(GSubprocessLauncher*, const ProcessLauncher::LaunchOptions&, char** argv, GError**);
+int argumentsToFileDescriptor(const Vector<CString>&, const char*);
};
Added: trunk/Source/WebKit/UIProcess/Launcher/glib/XDGDBusProxy.cpp (0 => 289528)
--- trunk/Source/WebKit/UIProcess/Launcher/glib/XDGDBusProxy.cpp (rev 0)
+++ trunk/Source/WebKit/UIProcess/Launcher/glib/XDGDBusProxy.cpp 2022-02-10 13:54:57 UTC (rev 289528)
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2018, 2022 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. 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.
+ */
+
+#include "config.h"
+#include "XDGDBusProxy.h"
+
+#if ENABLE(BUBBLEWRAP_SANDBOX)
+#include "BubblewrapLauncher.h"
+#include <WebCore/PlatformDisplay.h>
+#include <wtf/UniStdExtras.h>
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/glib/GUniquePtr.h>
+
+#if PLATFORM(GTK)
+#define BASE_DIRECTORY "webkitgtk"
+#elif PLATFORM(WPE)
+#define BASE_DIRECTORY "wpe"
+#endif
+
+namespace WebKit {
+
+XDGDBusProxy::XDGDBusProxy(Type type, bool allowPortals)
+ : m_type(type)
+{
+ switch (m_type) {
+ case Type::SessionBus:
+ m_dbusAddress = g_getenv("DBUS_SESSION_BUS_ADDRESS");
+ break;
+ case Type::AccessibilityBus:
+ m_dbusAddress = WebCore::PlatformDisplay::sharedDisplay().accessibilityBusAddress().utf8();
+ break;
+ }
+
+ if (m_dbusAddress.isNull() || !g_str_has_prefix(m_dbusAddress.data(), "unix:"))
+ return;
+
+ m_proxyPath = makeProxy();
+ if (m_proxyPath.isNull())
+ return;
+
+#if USE(ATSPI)
+ if (m_type == Type::AccessibilityBus)
+ WebCore::PlatformDisplay::sharedDisplay().setAccessibilityBusAddress(makeString("unix:path=", m_proxyPath.data()));
+#endif
+
+ if (const char* path = strstr(m_dbusAddress.data(), "path=")) {
+ path += strlen("path=");
+ const char* pathEnd = path;
+ while (*pathEnd && *pathEnd != ',')
+ pathEnd++;
+
+ m_path = CString(path, pathEnd - path);
+ }
+
+ launch(allowPortals);
+}
+
+CString XDGDBusProxy::makeProxy() const
+{
+ GUniquePtr<char> appRunDir(g_build_filename(g_get_user_runtime_dir(), BASE_DIRECTORY, nullptr));
+ if (g_mkdir_with_parents(appRunDir.get(), 0700) == -1) {
+ g_warning("Failed to mkdir for dbus proxy (%s): %s", appRunDir.get(), g_strerror(errno));
+ return { };
+ }
+
+ auto proxyTemplate = [](Type type) -> const char* {
+ switch (type) {
+ case Type::SessionBus:
+ return "bus-proxy-XXXXXX";
+ case Type::AccessibilityBus:
+ return "a11y-proxy-XXXXXX";
+ }
+ RELEASE_ASSERT_NOT_REACHED();
+ };
+
+ GUniquePtr<char> proxySocketTemplate(g_build_filename(appRunDir.get(), proxyTemplate(m_type), nullptr));
+ int fd;
+ if ((fd = g_mkstemp(proxySocketTemplate.get())) == -1) {
+ g_warning("Failed to make socket file %s for dbus proxy: %s", proxySocketTemplate.get(), g_strerror(errno));
+ return { };
+ }
+
+ close(fd);
+ return proxySocketTemplate.get();
+}
+
+void XDGDBusProxy::launch(bool allowPortals) const
+{
+ int syncFds[2];
+ if (pipe(syncFds) == -1)
+ g_error("Failed to make syncfds for dbus-proxy: %s", g_strerror(errno));
+ setCloseOnExec(syncFds[0]);
+
+ GUniquePtr<char> syncFdStr(g_strdup_printf("--fd=%d", syncFds[1]));
+ Vector<CString> proxyArgs = {
+ m_dbusAddress, m_proxyPath,
+ "--filter",
+ syncFdStr.get()
+ };
+
+ auto enableLogging = [](Type type) -> bool {
+ switch (type) {
+ case Type::SessionBus:
+ return !g_strcmp0(g_getenv("WEBKIT_ENABLE_DBUS_PROXY_LOGGING"), "1");
+ case Type::AccessibilityBus:
+ return !g_strcmp0(g_getenv("WEBKIT_ENABLE_A11Y_DBUS_PROXY_LOGGING"), "1");
+ }
+ RELEASE_ASSERT_NOT_REACHED();
+ };
+ if (enableLogging(m_type))
+ proxyArgs.append("--log");
+
+ switch (m_type) {
+ case Type::SessionBus: {
+#if ENABLE(MEDIA_SESSION)
+ if (auto* app = g_application_get_default()) {
+ if (const char* appID = g_application_get_application_id(app)) {
+ auto mprisSessionID = makeString("--own=org.mpris.MediaPlayer2.", appID);
+ proxyArgs.append(mprisSessionID.ascii().data());
+ }
+ }
+#endif
+ // GStreamers plugin install helper.
+ proxyArgs.append("--call=org.freedesktop.PackageKit=org.freedesktop.PackageKit.Modify2.InstallGStreamerResources@/org/freedesktop/PackageKit");
+
+ if (allowPortals)
+ proxyArgs.append("--talk=org.freedesktop.portal.Desktop");
+ break;
+ }
+ case Type::AccessibilityBus:
+ proxyArgs.appendVector(Vector<CString> {
+ "--sloppy-names",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.Socket.Embed@/org/a11y/atspi/accessible/root",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.Socket.Unembed@/org/a11y/atspi/accessible/root",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.Registry.GetRegisteredEvents@/org/a11y/atspi/registry",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.GetKeystrokeListeners@/org/a11y/atspi/registry/deviceeventcontroller",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.GetDeviceEventListeners@/org/a11y/atspi/registry/deviceeventcontroller",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.NotifyListenersSync@/org/a11y/atspi/registry/deviceeventcontroller",
+ "--call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.NotifyListenersAsync@/org/a11y/atspi/registry/deviceeventcontroller",
+ });
+ break;
+ }
+
+ // We have to run xdg-dbus-proxy under bubblewrap because we need /.flatpak-info to exist in
+ // xdg-dbus-proxy's mount namespace. Portals may use this as a trusted way to get the
+ // sandboxed process's application ID, and will break if it's missing.
+ int proxyFd = argumentsToFileDescriptor(proxyArgs, "dbus-proxy");
+ GUniquePtr<char> proxyArgsStr(g_strdup_printf("--args=%d", proxyFd));
+ Vector<CString> args = {
+ DBUS_PROXY_EXECUTABLE,
+ proxyArgsStr.get(),
+ };
+ int nargs = args.size() + 1;
+ int i = 0;
+ char** argv = g_newa(char*, nargs);
+ for (const auto& arg : args)
+ argv[i++] = const_cast<char*>(arg.data());
+ argv[i] = nullptr;
+
+ // Warning: do not set a child setup function, because we want GIO to be able to spawn with
+ // posix_spawn() rather than fork()/exec(), in order to better accomodate applications that use
+ // a huge amount of memory or address space in the UI process, like Eclipse.
+ GRefPtr<GSubprocessLauncher> launcher = adoptGRef(g_subprocess_launcher_new(G_SUBPROCESS_FLAGS_INHERIT_FDS));
+ g_subprocess_launcher_take_fd(launcher.get(), proxyFd, proxyFd);
+ g_subprocess_launcher_take_fd(launcher.get(), syncFds[1], syncFds[1]);
+
+ // We are purposefully leaving syncFds[0] open here.
+ // xdg-dbus-proxy will exit() itself once that is closed on our exit.
+
+ ProcessLauncher::LaunchOptions launchOptions;
+ launchOptions.processType = ProcessLauncher::ProcessType::DBusProxy;
+ if (m_type == Type::AccessibilityBus && !m_path.isNull())
+ launchOptions.extraSandboxPaths.add(m_path, SandboxPermission::ReadOnly);
+ GUniqueOutPtr<GError> error;
+ GRefPtr<GSubprocess> process = bubblewrapSpawn(launcher.get(), launchOptions, argv, &error.outPtr());
+ if (!process)
+ g_error("Failed to start dbus proxy: %s", error->message);
+
+ // We need to ensure the proxy has created the socket.
+ // FIXME: This is more blocking IO.
+ char out;
+ if (read(syncFds[0], &out, 1) != 1)
+ g_error("Failed to fully launch dbus-proxy: %s", g_strerror(errno));
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(BUBBLEWRAP_SANDBOX)
Copied: trunk/Source/WebKit/UIProcess/Launcher/glib/XDGDBusProxy.h (from rev 289527, trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.h) (0 => 289528)
--- trunk/Source/WebKit/UIProcess/Launcher/glib/XDGDBusProxy.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/Launcher/glib/XDGDBusProxy.h 2022-02-10 13:54:57 UTC (rev 289528)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2018, 2022 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. 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.
+ */
+
+#pragma once
+
+#if ENABLE(BUBBLEWRAP_SANDBOX)
+#include <wtf/FastMalloc.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/text/CString.h>
+
+namespace WebKit {
+
+class XDGDBusProxy {
+ WTF_MAKE_NONCOPYABLE(XDGDBusProxy); WTF_MAKE_FAST_ALLOCATED;
+public:
+ enum class Type { SessionBus, AccessibilityBus };
+ XDGDBusProxy(Type, bool = false);
+
+ const CString& proxyPath() const { return m_proxyPath; }
+ const CString& path() const { return m_path; }
+
+private:
+ CString makeProxy() const;
+ void launch(bool) const;
+
+ Type m_type;
+ CString m_dbusAddress;
+ CString m_proxyPath;
+ CString m_path;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(BUBBLEWRAP_SANDBOX)