summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2020-11-19 14:25:35 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2020-11-19 15:20:56 +0000
commitd436c2e8391bc684da933008d5a4483cbc536bc8 (patch)
tree4277c45afb662db699b6df8a1ca92b2c35633856
parentb37634dcd5c76f6a1294cd1d73bd7bd7dcb9a43b (diff)
downloadgtk+-d436c2e8391bc684da933008d5a4483cbc536bc8.tar.gz
a11y: Remove weak ref from atspi.Cache
The GtkAtSpiContext is responsible for removing itself from the root, which will remove itself from the cache. Any code path that leads to the GtkAtSpiContext instance being collected passes through the unrealization phase, which will also unregister the context from the accessibility bus and from the cache.
-rw-r--r--gtk/a11y/gtkatspicache.c39
1 files changed, 7 insertions, 32 deletions
diff --git a/gtk/a11y/gtkatspicache.c b/gtk/a11y/gtkatspicache.c
index 880a64cc5c..81bfd030f2 100644
--- a/gtk/a11y/gtkatspicache.c
+++ b/gtk/a11y/gtkatspicache.c
@@ -191,9 +191,11 @@ emit_add_accessible (GtkAtSpiCache *self,
}
static void
-emit_remove_accessible (GtkAtSpiCache *self,
- GVariant *ref)
+emit_remove_accessible (GtkAtSpiCache *self,
+ GtkAtSpiContext *context)
{
+ GVariant *ref = gtk_at_spi_context_to_ref (context);
+
g_dbus_connection_emit_signal (self->connection,
NULL,
self->cache_path,
@@ -325,29 +327,6 @@ gtk_at_spi_cache_new (GDBusConnection *connection,
NULL);
}
-static void
-context_weak_unref (gpointer data,
- GObject *stale_context)
-{
- GtkAtSpiCache *self = data;
-
- const char *path = g_hash_table_lookup (self->contexts_to_path, stale_context);
- if (path == NULL)
- return;
-
- /* By the time we get here, the context has already been dropped,
- * so we need to generate the reference ourselves
- */
- emit_remove_accessible (self, g_variant_new ("(so)",
- g_dbus_connection_get_unique_name (self->connection),
- path));
-
- GTK_NOTE (A11Y, g_message ("Removing stale context '%s' from cache", path));
-
- g_hash_table_remove (self->contexts_by_path, path);
- g_hash_table_remove (self->contexts_to_path, stale_context);
-}
-
void
gtk_at_spi_cache_add_context (GtkAtSpiCache *self,
GtkAtSpiContext *context)
@@ -362,15 +341,13 @@ gtk_at_spi_cache_add_context (GtkAtSpiCache *self,
if (g_hash_table_contains (self->contexts_by_path, path))
return;
- g_object_weak_ref (G_OBJECT (context), context_weak_unref, self);
-
char *path_key = g_strdup (path);
g_hash_table_insert (self->contexts_by_path, path_key, context);
g_hash_table_insert (self->contexts_to_path, context, path_key);
- emit_add_accessible (self, context);
-
GTK_NOTE (A11Y, g_message ("Adding context '%s' to cache", path_key));
+
+ emit_add_accessible (self, context);
}
void
@@ -384,9 +361,7 @@ gtk_at_spi_cache_remove_context (GtkAtSpiCache *self,
if (!g_hash_table_contains (self->contexts_by_path, path))
return;
- emit_remove_accessible (self, gtk_at_spi_context_to_ref (context));
-
- g_object_weak_unref (G_OBJECT (context), context_weak_unref, self);
+ emit_remove_accessible (self, context);
/* The order is important: the value in contexts_by_path is the
* key in contexts_to_path