diff --git a/data/org.freedesktop.impl.portal.AppChooser.xml b/data/org.freedesktop.impl.portal.AppChooser.xml index 03a4ea090..cbb42ee88 100644 --- a/data/org.freedesktop.impl.portal.AppChooser.xml +++ b/data/org.freedesktop.impl.portal.AppChooser.xml @@ -24,6 +24,8 @@ This backend can be used by portal implementations that need to choose an application from a list of applications. + + This documentation describes version 2 of this interface. --> diff --git a/data/org.freedesktop.portal.OpenURI.xml b/data/org.freedesktop.portal.OpenURI.xml index 5ed054cf1..c1bdc0d13 100644 --- a/data/org.freedesktop.portal.OpenURI.xml +++ b/data/org.freedesktop.portal.OpenURI.xml @@ -27,7 +27,7 @@ URIs (e.g. a http: link to the applications homepage) under the control of the user. - This documentation describes version 3 of this interface. + This documentation describes version 4 of this interface. --> @@ -119,6 +127,14 @@ The ask option was introduced in version 3 of the interface. + + activation_token s + + A token that can be used to activate the chosen application. + + The activation_token option was introduced in version 4 of the interface. + + The OpenFile method was introduced in version 2 of the OpenURI portal API. @@ -150,6 +166,14 @@ more information about the @handle. + + activation_token s + + A token that can be used to activate the chosen application. + + The activation_token option was introduced in version 4 of the interface. + + The OpenDirectory method was introduced in version 3 of the OpenURI portal API. diff --git a/src/open-uri.c b/src/open-uri.c index a1b65f1e8..bc53dbffe 100644 --- a/src/open-uri.c +++ b/src/open-uri.c @@ -235,6 +235,7 @@ launch_application_with_uri (const char *choice_id, const char *uri, const char *parent_window, gboolean writable, + const char *activation_token, GError **error) { g_autofree char *desktop_id = g_strconcat (choice_id, ".desktop", NULL); @@ -271,6 +272,9 @@ launch_application_with_uri (const char *choice_id, g_app_launch_context_setenv (context, "PARENT_WINDOW_ID", parent_window); + if (activation_token) + g_app_launch_context_setenv (context, "XDG_ACTIVATION_TOKEN", activation_token); + uris.data = (gpointer)ruri; uris.next = NULL; @@ -363,6 +367,7 @@ send_response_in_thread_func (GTask *task, const char *parent_window; gboolean writable; const char *content_type; + const char *activation_token = NULL; g_debug ("Received choice %s", choice); @@ -371,7 +376,9 @@ send_response_in_thread_func (GTask *task, writable = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "writable")); content_type = (const char *)g_object_get_data (G_OBJECT (request), "content-type"); - if (launch_application_with_uri (choice, uri, parent_window, writable, NULL)) + g_variant_lookup (options, "activation_token", "&s", &activation_token); + + if (launch_application_with_uri (choice, uri, parent_window, writable, activation_token, NULL)) update_permissions_store (xdp_app_info_get_id (request->app_info), content_type, choice); } @@ -580,6 +587,7 @@ handle_open_in_thread_func (GTask *task, Request *request = (Request *)task_data; const char *parent_window; const char *app_id = xdp_app_info_get_id (request->app_info); + const char *activation_token; g_autofree char *uri = NULL; g_autoptr(XdpImplRequest) impl_request = NULL; g_autofree char *default_app = NULL; @@ -607,6 +615,7 @@ handle_open_in_thread_func (GTask *task, writable = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "writable")); ask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "ask")); open_dir = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "open-dir")); + activation_token = (const char *)g_object_get_data (G_OBJECT (request), "activation-token"); REQUEST_AUTOLOCK (request); @@ -809,7 +818,7 @@ handle_open_in_thread_func (GTask *task, g_debug ("Skipping app chooser"); - gboolean result = launch_application_with_uri (app, uri, parent_window, writable, &error); + gboolean result = launch_application_with_uri (app, uri, parent_window, writable, activation_token, &error); if (request->exported) { if (!result) @@ -839,6 +848,8 @@ handle_open_in_thread_func (GTask *task, g_variant_builder_add (&opts_builder, "{sv}", "filename", g_variant_new_string (basename)); if (uri) g_variant_builder_add (&opts_builder, "{sv}", "uri", g_variant_new_string (uri)); + if (activation_token) + g_variant_builder_add (&opts_builder, "{sv}", "activation_token", g_variant_new_string (uri)); impl_request = xdp_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)), G_DBUS_PROXY_FLAGS_NONE, @@ -874,6 +885,7 @@ handle_open_uri (XdpOpenURI *object, g_autoptr(GTask) task = NULL; gboolean writable; gboolean ask; + const char *activation_token = NULL; if (xdp_impl_lockdown_get_disable_application_handlers (lockdown)) { @@ -891,12 +903,17 @@ handle_open_uri (XdpOpenURI *object, if (!g_variant_lookup (arg_options, "ask", "b", &ask)) ask = FALSE; + g_variant_lookup (arg_options, "activation_token", "&s", &activation_token); + g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (-1)); g_object_set_data_full (G_OBJECT (request), "uri", g_strdup (arg_uri), g_free); g_object_set_data_full (G_OBJECT (request), "parent-window", g_strdup (arg_parent_window), g_free); g_object_set_data (G_OBJECT (request), "writable", GINT_TO_POINTER (writable)); g_object_set_data (G_OBJECT (request), "ask", GINT_TO_POINTER (ask)); + if (activation_token) + g_object_set_data_full (G_OBJECT (request), "activation-token", g_strdup (activation_token), g_free); + request_export (request, g_dbus_method_invocation_get_connection (invocation)); xdp_open_uri_complete_open_uri (object, invocation, request->id); @@ -920,6 +937,7 @@ handle_open_file (XdpOpenURI *object, gboolean writable; gboolean ask; int fd_id, fd; + const char *activation_token = NULL; g_autoptr(GError) error = NULL; if (xdp_impl_lockdown_get_disable_application_handlers (lockdown)) @@ -946,11 +964,16 @@ handle_open_file (XdpOpenURI *object, return TRUE; } + g_variant_lookup (arg_options, "activation_token", "&s", &activation_token); + g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (fd)); g_object_set_data_full (G_OBJECT (request), "parent-window", g_strdup (arg_parent_window), g_free); g_object_set_data (G_OBJECT (request), "writable", GINT_TO_POINTER (writable)); g_object_set_data (G_OBJECT (request), "ask", GINT_TO_POINTER (ask)); + if (activation_token) + g_object_set_data_full (G_OBJECT (request), "activation-token", g_strdup (activation_token), g_free); + request_export (request, g_dbus_method_invocation_get_connection (invocation)); xdp_open_uri_complete_open_file (object, invocation, NULL, request->id); @@ -972,6 +995,7 @@ handle_open_directory (XdpOpenURI *object, Request *request = request_from_invocation (invocation); g_autoptr(GTask) task = NULL; int fd_id, fd; + const char *activation_token = NULL; g_autoptr(GError) error = NULL; if (xdp_impl_lockdown_get_disable_application_handlers (lockdown)) @@ -992,12 +1016,17 @@ handle_open_directory (XdpOpenURI *object, return TRUE; } + g_variant_lookup (arg_options, "activation_token", "&s", &activation_token); + g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (fd)); g_object_set_data_full (G_OBJECT (request), "parent-window", g_strdup (arg_parent_window), g_free); g_object_set_data (G_OBJECT (request), "writable", GINT_TO_POINTER (0)); g_object_set_data (G_OBJECT (request), "ask", GINT_TO_POINTER (0)); g_object_set_data (G_OBJECT (request), "open-dir", GINT_TO_POINTER (1)); + if (activation_token) + g_object_set_data_full (G_OBJECT (request), "activation-token", g_strdup (activation_token), g_free); + request_export (request, g_dbus_method_invocation_get_connection (invocation)); xdp_open_uri_complete_open_file (object, invocation, NULL, request->id);