forked from AuroraMiddleware/gtk
a11y: Compute the base path in the root object
The root path is shared by all AtSpiContext instances, so we should compute it once, instead of every time we instantiate a new context. This allows us to defer the path creation at realization time and ensure that we have a registered application.
This commit is contained in:
parent
d392f6f2a4
commit
eec92b40ea
@ -1458,45 +1458,6 @@ gtk_at_spi_context_constructed (GObject *gobject)
|
|||||||
/* Make sure that we were properly constructed */
|
/* Make sure that we were properly constructed */
|
||||||
g_assert (self->bus_address);
|
g_assert (self->bus_address);
|
||||||
|
|
||||||
/* We use the application's object path to build the path of each
|
|
||||||
* accessible object exposed on the accessibility bus; the path is
|
|
||||||
* also used to access the object cache
|
|
||||||
*/
|
|
||||||
GApplication *application = g_application_get_default ();
|
|
||||||
char *base_path = NULL;
|
|
||||||
|
|
||||||
if (application != NULL)
|
|
||||||
{
|
|
||||||
const char *app_path = g_application_get_dbus_object_path (application);
|
|
||||||
base_path = g_strconcat (app_path, "/a11y", NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char *uuid = g_uuid_string_random ();
|
|
||||||
base_path = g_strconcat ("/org/gtk/application/", uuid, "/a11y", NULL);
|
|
||||||
g_free (uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We use a unique id to ensure that we don't have conflicting
|
|
||||||
* objects on the bus
|
|
||||||
*/
|
|
||||||
char *uuid = g_uuid_string_random ();
|
|
||||||
|
|
||||||
self->context_path = g_strconcat (base_path, "/", uuid, NULL);
|
|
||||||
|
|
||||||
/* UUIDs use '-' as the separator, but that's not a valid character
|
|
||||||
* for a DBus object path
|
|
||||||
*/
|
|
||||||
size_t path_len = strlen (self->context_path);
|
|
||||||
for (size_t i = 0; i < path_len; i++)
|
|
||||||
{
|
|
||||||
if (self->context_path[i] == '-')
|
|
||||||
self->context_path[i] = '_';
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (base_path);
|
|
||||||
g_free (uuid);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_at_spi_context_parent_class)->constructed (gobject);
|
G_OBJECT_CLASS (gtk_at_spi_context_parent_class)->constructed (gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1526,6 +1487,22 @@ gtk_at_spi_context_realize (GtkATContext *context)
|
|||||||
g_object_ref (self->root);
|
g_object_ref (self->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* UUIDs use '-' as the separator, but that's not a valid character
|
||||||
|
* for a DBus object path
|
||||||
|
*/
|
||||||
|
char *uuid = g_uuid_string_random ();
|
||||||
|
size_t len = strlen (uuid);
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (uuid[i] == '-')
|
||||||
|
uuid[i] = '_';
|
||||||
|
}
|
||||||
|
|
||||||
|
self->context_path =
|
||||||
|
g_strconcat (gtk_at_spi_root_get_base_path (self->root), "/", uuid, NULL);
|
||||||
|
|
||||||
|
g_free (uuid);
|
||||||
|
|
||||||
self->connection = gtk_at_spi_root_get_connection (self->root);
|
self->connection = gtk_at_spi_root_get_connection (self->root);
|
||||||
if (self->connection == NULL)
|
if (self->connection == NULL)
|
||||||
return;
|
return;
|
||||||
@ -1812,7 +1789,13 @@ gtk_at_spi_context_get_context_path (GtkAtSpiContext *self)
|
|||||||
GVariant *
|
GVariant *
|
||||||
gtk_at_spi_context_to_ref (GtkAtSpiContext *self)
|
gtk_at_spi_context_to_ref (GtkAtSpiContext *self)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_AT_SPI_CONTEXT (self), NULL);
|
||||||
|
|
||||||
|
if (self->context_path == NULL)
|
||||||
|
return gtk_at_spi_null_ref ();
|
||||||
|
|
||||||
const char *name = g_dbus_connection_get_unique_name (self->connection);
|
const char *name = g_dbus_connection_get_unique_name (self->connection);
|
||||||
|
|
||||||
return g_variant_new ("(so)", name, self->context_path);
|
return g_variant_new ("(so)", name, self->context_path);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -51,6 +51,8 @@ struct _GtkAtSpiRoot
|
|||||||
char *bus_address;
|
char *bus_address;
|
||||||
GDBusConnection *connection;
|
GDBusConnection *connection;
|
||||||
|
|
||||||
|
char *base_path;
|
||||||
|
|
||||||
const char *root_path;
|
const char *root_path;
|
||||||
|
|
||||||
const char *toolkit_name;
|
const char *toolkit_name;
|
||||||
@ -87,6 +89,7 @@ gtk_at_spi_root_finalize (GObject *gobject)
|
|||||||
g_clear_handle_id (&self->register_id, g_source_remove);
|
g_clear_handle_id (&self->register_id, g_source_remove);
|
||||||
|
|
||||||
g_free (self->bus_address);
|
g_free (self->bus_address);
|
||||||
|
g_free (self->base_path);
|
||||||
g_free (self->desktop_name);
|
g_free (self->desktop_name);
|
||||||
g_free (self->desktop_path);
|
g_free (self->desktop_path);
|
||||||
|
|
||||||
@ -613,6 +616,27 @@ gtk_at_spi_root_constructed (GObject *gobject)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We use the application's object path to build the path of each
|
||||||
|
* accessible object exposed on the accessibility bus; the path is
|
||||||
|
* also used to access the object cache
|
||||||
|
*/
|
||||||
|
GApplication *application = g_application_get_default ();
|
||||||
|
|
||||||
|
if (application != NULL && g_application_get_is_registered (application))
|
||||||
|
{
|
||||||
|
const char *app_path = g_application_get_dbus_object_path (application);
|
||||||
|
|
||||||
|
self->base_path = g_strconcat (app_path, "/a11y", NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->base_path = g_strconcat ("/org/gtk/application/",
|
||||||
|
g_get_prgname (),
|
||||||
|
"/a11y",
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
G_OBJECT_CLASS (gtk_at_spi_root_parent_class)->constructed (gobject);
|
G_OBJECT_CLASS (gtk_at_spi_root_parent_class)->constructed (gobject);
|
||||||
}
|
}
|
||||||
@ -687,3 +711,11 @@ gtk_at_spi_root_to_ref (GtkAtSpiRoot *self)
|
|||||||
|
|
||||||
return g_variant_new ("(so)", self->desktop_name, self->desktop_path);
|
return g_variant_new ("(so)", self->desktop_name, self->desktop_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
gtk_at_spi_root_get_base_path (GtkAtSpiRoot *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_AT_SPI_ROOT (self), NULL);
|
||||||
|
|
||||||
|
return self->base_path;
|
||||||
|
}
|
||||||
|
@ -42,6 +42,9 @@ gtk_at_spi_root_get_connection (GtkAtSpiRoot *self);
|
|||||||
GtkAtSpiCache *
|
GtkAtSpiCache *
|
||||||
gtk_at_spi_root_get_cache (GtkAtSpiRoot *self);
|
gtk_at_spi_root_get_cache (GtkAtSpiRoot *self);
|
||||||
|
|
||||||
|
const char *
|
||||||
|
gtk_at_spi_root_get_base_path (GtkAtSpiRoot *self);
|
||||||
|
|
||||||
GVariant *
|
GVariant *
|
||||||
gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
|
gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user