Make dbus activation sandbox-aware

When we call org.freedesktop.Application.Open to activate
an application and pass file uris, the application may not
be able to see the files due to a flatpak sandbox.

Flatpak puts the flatpak app-id in the  X-Flatpak key in
desktop files that it exports, so we can easily recognize
applications that may be affected by this.

In this case, call the document portal to export the files
and pass the resulting uri's instead of the original ones.

https://bugzilla.gnome.org/show_bug.cgi?id=783130
This commit is contained in:
Matthias Clasen 2017-05-06 14:22:38 -04:00
parent 60a1cc9fac
commit d3b4f7c9f6

View File

@ -48,6 +48,10 @@
#include "gappinfoprivate.h"
#include "glocalfilemonitor.h"
#ifdef G_OS_UNIX
#include "gdocumentportal.h"
#endif
/**
* SECTION:gdesktopappinfo
* @title: GDesktopAppInfo
@ -2835,17 +2839,15 @@ g_desktop_app_info_make_platform_data (GDesktopAppInfo *info,
return g_variant_builder_end (&builder);
}
static gboolean
g_desktop_app_info_launch_uris_with_dbus (GDesktopAppInfo *info,
GDBusConnection *session_bus,
GList *uris,
GAppLaunchContext *launch_context)
static void
launch_uris_with_dbus (GDesktopAppInfo *info,
GDBusConnection *session_bus,
GList *uris,
GAppLaunchContext *launch_context)
{
GVariantBuilder builder;
gchar *object_path;
g_return_val_if_fail (info != NULL, FALSE);
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
if (uris)
@ -2869,6 +2871,33 @@ g_desktop_app_info_launch_uris_with_dbus (GDesktopAppInfo *info,
uris ? "Open" : "Activate", g_variant_builder_end (&builder),
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
g_free (object_path);
}
static gboolean
g_desktop_app_info_launch_uris_with_dbus (GDesktopAppInfo *info,
GDBusConnection *session_bus,
GList *uris,
GAppLaunchContext *launch_context)
{
GList *ruris = uris;
g_autofree char *app_id = NULL;
g_return_val_if_fail (info != NULL, FALSE);
#ifdef G_OS_UNIX
app_id = g_desktop_app_info_get_string (info, "X-Flatpak");
if (app_id && *app_id)
{
ruris = g_document_portal_add_documents (uris, app_id, NULL);
if (ruris == NULL)
ruris = uris;
}
#endif
launch_uris_with_dbus (info, session_bus, ruris, launch_context);
if (ruris != uris)
g_list_free_full (ruris, g_free);
return TRUE;
}