Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SchemeSupported to the OpenURI portal #1203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions data/org.freedesktop.portal.OpenURI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@
<arg type="o" name="handle" direction="out"/>
</method>

<!--
SchemeSupported:
@scheme: The URI protocol scheme to check
@supported: True when URI scheme is supported on the host system

Asks whenever host system supports the protocol scheme.

The SchemeSupported method was introduced in version 4 of the OpenURI portal API.
-->
<method name="SchemeSupported">
<arg type="s" name="scheme" direction="in"/>
<arg type="b" name="supported" direction="out"/>
</method>

<property name="version" type="u" access="read"/>
</interface>
</node>
25 changes: 24 additions & 1 deletion src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,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,
Expand Down Expand Up @@ -1088,12 +1110,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), 3);
xdp_dbus_open_uri_set_version (XDP_DBUS_OPEN_URI (openuri), 4);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion tests/test-portals.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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, 3)
DEFINE_TEST_EXISTS(open_uri, OPEN_URI, 4)
xhorak marked this conversation as resolved.
Show resolved Hide resolved
DEFINE_TEST_EXISTS(print, PRINT, 2)
DEFINE_TEST_EXISTS(proxy_resolver, PROXY_RESOLVER, 1)
DEFINE_TEST_EXISTS(screenshot, SCREENSHOT, 2)
Expand Down
Loading