diff --git a/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp b/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp index 552f622bd17e..89eb3899279e 100644 --- a/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp +++ b/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -124,20 +125,23 @@ int argumentsToFileDescriptor(const Vector& args, const char* name) return memfd; } -static const char* applicationId(GError** error) +static String effectiveApplicationId() { - GApplication* app = g_application_get_default(); - if (!app) { - g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "GApplication is required."); - return nullptr; + if (auto* app = g_application_get_default()) { + if (const char* appID = g_application_get_application_id(app)) + return String::fromUTF8(appID); } - const char* appID = g_application_get_application_id(app); - if (!appID) { - g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "GApplication must have a valid ID."); - return nullptr; - } - return appID; + const char* programName = g_get_prgname(); + if (programName && g_application_id_is_valid(programName)) + return String::fromUTF8(programName); + + // There must be some id for xdg-desktop-portal to function. + // xdg-desktop-portal uses this id for permissions. While we don't currently + // use any APIs that require permissions, we generate a random id to avoid + // interactions with other applications. + auto uuid = UUID::createVersion4Weak(); + return makeString("org.webkit.app-", uuid.toString()); } static int createFlatpakInfo() @@ -146,15 +150,8 @@ static int createFlatpakInfo() static size_t size; if (!data.get()) { - // xdg-desktop-portal relates your name to certain permissions so we want - // them to be application unique which is best done via GApplication. - GUniqueOutPtr error; - const char* appID = applicationId(&error.outPtr()); - if (!appID) - g_error("Unable to configure xdg-desktop-portal access in the WebKit sandbox: %s", error->message); - GUniquePtr keyFile(g_key_file_new()); - g_key_file_set_string(keyFile.get(), "Application", "name", appID); + g_key_file_set_string(keyFile.get(), "Application", "name", effectiveApplicationId().utf8().data()); data->reset(g_key_file_to_data(keyFile.get(), &size, nullptr)); }