Skip to content

Commit

Permalink
Added SchemeSupported to the OpenURI portal
Browse files Browse the repository at this point in the history
  • Loading branch information
xhorak authored and matthiasclasen committed Oct 11, 2024
1 parent 8c85331 commit 1ae592a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 3 deletions.
20 changes: 19 additions & 1 deletion data/org.freedesktop.portal.OpenURI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
URIs (e.g. a http: link to the applications homepage)
under the control of the user.
This documentation describes version 4 of this interface.
This documentation describes version 5 of this interface.
-->
<interface name="org.freedesktop.portal.OpenURI">
<!--
Expand Down Expand Up @@ -163,6 +163,24 @@
<arg type="o" name="handle" direction="out"/>
</method>

<!--
SchemeSupported:
@scheme: The URI protocol scheme to check
@options: Vardict with optional further information
@supported: True if the URI scheme is supported
Checks if OpenURI supports the protocol scheme @scheme.
The @options vardict currently has no supported entries.
The SchemeSupported method was introduced in version 5 of the OpenURI portal API.
-->
<method name="SchemeSupported">
<arg type="s" name="scheme" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<arg type="b" name="supported" direction="out"/>
</method>

<property name="version" type="u" access="read"/>
</interface>
</node>
28 changes: 27 additions & 1 deletion src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,31 @@ handle_open_in_thread_func (GTask *task,
g_object_ref (request));
}

static gboolean
handle_scheme_supported (XdpDbusOpenURI *object,
GDBusMethodInvocation *invocation,
const gchar *arg_scheme,
GVariant *arg_options)
{
g_autoptr(GAppInfo) app_info = NULL;

if (arg_scheme == NULL || *arg_scheme == '\0')
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Scheme not specified");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

app_info = g_app_info_get_default_for_uri_scheme (arg_scheme);

g_debug ("Handler for scheme: %s%s found.", arg_scheme, app_info ? "" : " not");
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", app_info != NULL));

return G_DBUS_METHOD_INVOCATION_HANDLED;
}

static gboolean
handle_open_uri (XdpDbusOpenURI *object,
GDBusMethodInvocation *invocation,
Expand Down Expand Up @@ -1093,12 +1118,13 @@ open_uri_iface_init (XdpDbusOpenURIIface *iface)
iface->handle_open_uri = handle_open_uri;
iface->handle_open_file = handle_open_file;
iface->handle_open_directory = handle_open_directory;
iface->handle_scheme_supported = handle_scheme_supported;
}

static void
open_uri_init (OpenURI *openuri)
{
xdp_dbus_open_uri_set_version (XDP_DBUS_OPEN_URI (openuri), 4);
xdp_dbus_open_uri_set_version (XDP_DBUS_OPEN_URI (openuri), 5);
}

static void
Expand Down
54 changes: 54 additions & 0 deletions tests/openuri.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <libportal/portal.h>
#include "xdp-utils.h"
#include "xdp-impl-dbus.h"
#include "xdp-dbus.h"

#include "utils.h"

Expand Down Expand Up @@ -478,3 +479,56 @@ test_open_directory (void)
while (!got_info)
g_main_context_iteration (NULL, TRUE);
}

void
test_scheme_supported (void)
{
gboolean supported;
GVariantBuilder builder;
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) options = NULL;
g_autoptr(GDBusConnection) session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);

XdpDbusOpenURI *proxy = xdp_dbus_open_uri_proxy_new_sync (session_bus,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
NULL,
&error);

g_assert_no_error (error);

g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
options = g_variant_ref_sink (g_variant_builder_end (&builder));
/* Existing scheme */
xdp_dbus_open_uri_call_scheme_supported_sync (proxy,
"https",
options,
&supported,
NULL,
&error);
g_assert_no_error (error);
g_assert_true (supported);

/* Non existing scheme */
xdp_dbus_open_uri_call_scheme_supported_sync (proxy,
"bogusnonexistanthandler",
options,
&supported,
NULL,
&error);
g_assert_no_error (error);
g_assert_false (supported);

/* Missing scheme name */
xdp_dbus_open_uri_call_scheme_supported_sync (proxy,
"",
options,
&supported,
NULL,
&error);
g_assert_error (error,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT);
g_object_unref (proxy);
}
1 change: 1 addition & 0 deletions tests/openuri.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ void test_open_uri_close (void);
void test_open_uri_cancel (void);
void test_open_uri_lockdown (void);
void test_open_directory (void);
void test_scheme_supported (void);
3 changes: 2 additions & 1 deletion tests/test-portals.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ DEFINE_TEST_EXISTS(inhibit, INHIBIT, 3)
DEFINE_TEST_EXISTS(location, LOCATION, 1)
DEFINE_TEST_EXISTS(network_monitor, NETWORK_MONITOR, 3)
DEFINE_TEST_EXISTS(notification, NOTIFICATION, 1)
DEFINE_TEST_EXISTS(open_uri, OPEN_URI, 4)
DEFINE_TEST_EXISTS(open_uri, OPEN_URI, 5)
DEFINE_TEST_EXISTS(print, PRINT, 3)
DEFINE_TEST_EXISTS(proxy_resolver, PROXY_RESOLVER, 1)
DEFINE_TEST_EXISTS(screenshot, SCREENSHOT, 2)
Expand Down Expand Up @@ -585,6 +585,7 @@ main (int argc, char **argv)
g_test_add_func ("/portal/openuri/cancel", test_open_uri_cancel);
g_test_add_func ("/portal/openuri/lockdown", test_open_uri_lockdown);
g_test_add_func ("/portal/openuri/directory", test_open_directory);
g_test_add_func ("/portal/openuri/scheme-supported", test_scheme_supported);

g_test_add_func ("/portal/wallpaper/basic", test_wallpaper_basic);
g_test_add_func ("/portal/wallpaper/delay", test_wallpaper_delay);
Expand Down

0 comments on commit 1ae592a

Please sign in to comment.