diff --git a/data/org.freedesktop.portal.OpenURI.xml b/data/org.freedesktop.portal.OpenURI.xml index dd1d326a0..db170ef5c 100644 --- a/data/org.freedesktop.portal.OpenURI.xml +++ b/data/org.freedesktop.portal.OpenURI.xml @@ -163,6 +163,20 @@ + + + + + + diff --git a/src/open-uri.c b/src/open-uri.c index 2b106657e..843a25073 100644 --- a/src/open-uri.c +++ b/src/open-uri.c @@ -925,6 +925,28 @@ handle_open_in_thread_func (GTask *task, g_object_ref (request)); } +static gboolean +handle_scheme_supported (XdpDbusOpenURI *object, + GDBusMethodInvocation *invocation, + const gchar *arg_scheme) +{ + 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; + } + + g_autoptr(GAppInfo) 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, @@ -1094,12 +1116,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 diff --git a/tests/openuri.c b/tests/openuri.c index b78b37eaf..ad1536eb6 100644 --- a/tests/openuri.c +++ b/tests/openuri.c @@ -478,3 +478,61 @@ test_open_directory (void) while (!got_info) g_main_context_iteration (NULL, TRUE); } + +void +test_scheme_supported(void) { + g_autoptr(GError) error = NULL; + + g_autoptr(GDBusProxy) proxy = g_dbus_proxy_new_for_bus_sync ( + G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop", + "org.freedesktop.portal.OpenURI", + NULL, + &error); + + g_assert_no_error (error); + + GVariant *result; + gboolean supported; + + // Existing scheme + result = g_dbus_proxy_call_sync (proxy, + "SchemeSupported", + g_variant_new("(s)", "https"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_assert_no_error (error); + g_variant_get (result, "(b)", &supported); + g_assert_true (supported); + g_variant_unref (result); + + // Non existing scheme + result = g_dbus_proxy_call_sync (proxy, + "SchemeSupported", + g_variant_new("(s)", "bogusnonexistanthandler"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_assert_no_error (error); + g_variant_get (result, "(b)", &supported); + g_assert_false (supported); + g_variant_unref (result); + + // Missing scheme name + g_dbus_proxy_call_sync (proxy, + "SchemeSupported", + g_variant_new("(s)", ""), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_assert_error (error, + XDG_DESKTOP_PORTAL_ERROR, + XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT); +} diff --git a/tests/openuri.h b/tests/openuri.h index f5dcf87db..c6e19ba78 100644 --- a/tests/openuri.h +++ b/tests/openuri.h @@ -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); diff --git a/tests/test-portals.c b/tests/test-portals.c index 8fd78ea78..8fcaf8e76 100644 --- a/tests/test-portals.c +++ b/tests/test-portals.c @@ -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) @@ -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);