Fix accessibility of root apps on Linux
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / accessible-adaptor.c
index 844ab6a..d0d77e7 100644 (file)
@@ -28,6 +28,7 @@
 #include "common/spi-dbus.h"
 #include "common/spi-stateset.h"
 #include "object.h"
+#include "introspection.h"
 
 static dbus_bool_t
 impl_get_Name (DBusMessageIter * iter, void *user_data)
@@ -91,7 +92,6 @@ impl_get_Parent (DBusMessageIter * iter, void *user_data)
   parent = atk_object_get_parent (obj);
   if (parent == NULL)
     {
-#ifdef SPI_ATK_PLUG_SOCKET
       /* TODO, move in to a 'Plug' wrapper. */
       if (ATK_IS_PLUG (obj))
         {
@@ -102,22 +102,27 @@ impl_get_Parent (DBusMessageIter * iter, void *user_data)
           if (id)
             {
               bus_parent = g_strdup (id);
-            if (bus_parent && (path_parent = g_utf8_strchr (bus_parent + 1, -1, ':')))
-              {
-                DBusMessageIter iter_parent;
-                *(path_parent++) = '\0';
-                dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL,
-                                                  &iter_parent);
-                dbus_message_iter_append_basic (&iter_parent, DBUS_TYPE_STRING, &bus_parent);
-                dbus_message_iter_append_basic (&iter_parent, DBUS_TYPE_OBJECT_PATH, &path_parent);
-                dbus_message_iter_close_container (&iter_variant, &iter_parent);
-              }
+              if (bus_parent && (path_parent = g_utf8_strchr (bus_parent + 1, -1, ':')))
+                {
+                  DBusMessageIter iter_parent;
+                  *(path_parent++) = '\0';
+                  dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL,
+                                                    &iter_parent);
+                  dbus_message_iter_append_basic (&iter_parent, DBUS_TYPE_STRING, &bus_parent);
+                  dbus_message_iter_append_basic (&iter_parent, DBUS_TYPE_OBJECT_PATH, &path_parent);
+                  dbus_message_iter_close_container (&iter_variant, &iter_parent);
+                }
+              else
+                {
+                  spi_object_append_null_reference (&iter_variant);
+                }
+            }
+          else
+            {
+              spi_object_append_null_reference (&iter_variant);
             }
         }
       else if (role != Accessibility_ROLE_APPLICATION)
-#else
-      if (role != Accessibility_ROLE_APPLICATION)
-#endif
          spi_object_append_null_reference (&iter_variant);
       else
          spi_object_append_desktop_reference (&iter_variant);
@@ -136,12 +141,14 @@ static dbus_bool_t
 impl_get_ChildCount (DBusMessageIter * iter, void *user_data)
 {
   AtkObject *object = (AtkObject *) user_data;
+  int childCount;
 
   g_return_val_if_fail (ATK_IS_OBJECT (user_data), FALSE);
 
-  return droute_return_v_int32 (iter,
-                                atk_object_get_n_accessible_children
-                                (object));
+  childCount = (ATK_IS_SOCKET (object) && atk_socket_is_occupied (ATK_SOCKET (object)))
+               ? 1
+               : atk_object_get_n_accessible_children (object);
+  return droute_return_v_int32 (iter, childCount);
 }
 
 static DBusMessage *
@@ -149,6 +156,7 @@ impl_GetChildAtIndex (DBusConnection * bus,
                       DBusMessage * message, void *user_data)
 {
   AtkObject *object = (AtkObject *) user_data;
+  DBusMessage *reply;
   DBusError error;
   dbus_int32_t i;
   AtkObject *child;
@@ -161,8 +169,35 @@ impl_GetChildAtIndex (DBusConnection * bus,
     {
       return droute_invalid_arguments_error (message);
     }
+
+  if (ATK_IS_SOCKET (object) && atk_socket_is_occupied (ATK_SOCKET (object)) && i == 0)
+    {
+      AtkSocket *socket = ATK_SOCKET (object);
+      gchar *child_name, *child_path;
+      child_name = g_strdup (socket->embedded_plug_id);
+      child_path = g_utf8_strchr (child_name + 1, -1, ':');
+      if (child_path)
+        {
+          DBusMessageIter iter, iter_socket;
+          *(child_path++) = '\0';
+          reply = dbus_message_new_method_return (message);
+          if (!reply)
+            return NULL;
+          dbus_message_iter_init_append (reply, &iter);
+          dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
+                                            &iter_socket);
+          dbus_message_iter_append_basic (&iter_socket, DBUS_TYPE_STRING, &child_name);
+          dbus_message_iter_append_basic (&iter_socket, DBUS_TYPE_OBJECT_PATH, &child_path);
+          dbus_message_iter_close_container (&iter, &iter_socket);
+          return reply;
+        }
+      g_free (child_name);
+    }
   child = atk_object_ref_accessible_child (object, i);
-  return spi_object_return_reference (message, child);
+  reply = spi_object_return_reference (message, child);
+  g_object_unref (child);
+
+  return reply;
 }
 
 static DBusMessage *
@@ -287,7 +322,9 @@ impl_GetRelationSet (DBusConnection * bus,
     {
       goto oom;
     }
-  count = atk_relation_set_get_n_relations (set);
+  count = 0;
+  if (set)
+    count = atk_relation_set_get_n_relations (set);
   for (i = 0; i < count; i++)
     {
       AtkRelation *r = atk_relation_set_get_relation (set, i);
@@ -461,8 +498,7 @@ static DBusMessage *
 impl_GetApplication (DBusConnection * bus,
                      DBusMessage * message, void *user_data)
 {
-  AtkObject *root = g_object_ref (atk_get_root ());
-  return spi_object_return_reference (message, root);
+  return spi_object_return_reference (message, atk_get_root ());
 }
 
 static DBusMessage *
@@ -470,8 +506,6 @@ impl_GetInterfaces (DBusConnection * bus,
                     DBusMessage * message, void *user_data)
 {
   AtkObject *object = (AtkObject *) user_data;
-  gint role;
-  const char *role_name;
   DBusMessage *reply;
   DBusMessageIter iter, iter_array;
 
@@ -489,27 +523,6 @@ impl_GetInterfaces (DBusConnection * bus,
   return reply;
 }
 
-static DBusMessage *
-impl_Embedded (DBusConnection *bus,
-                    DBusMessage *message,
-                    void *user_data)
-{
-  AtkObject *object = (AtkObject *) user_data;
-  char *path;
-  gchar *id;
-
-  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID))
-    {
-      return droute_invalid_arguments_error (message);
-    }
-  id = g_object_get_data (G_OBJECT (object), "dbus-plug-parent");
-  if (id)
-    g_free (id);
-  id = g_strconcat (dbus_message_get_sender (message), ":", path, NULL);
-  g_object_set_data (G_OBJECT (object), "dbus-plug-parent", id);
-  return dbus_message_new_method_return (message);
-}
-
 static DRouteMethod methods[] = {
   {impl_GetChildAtIndex, "GetChildAtIndex"},
   {impl_GetChildren, "GetChildren"},
@@ -522,7 +535,6 @@ static DRouteMethod methods[] = {
   {impl_GetAttributes, "GetAttributes"},
   {impl_GetApplication, "GetApplication"},
   {impl_GetInterfaces, "GetInterfaces"},
-  {impl_Embedded, "Embedded"},
   {NULL, NULL}
 };
 
@@ -539,5 +551,6 @@ spi_initialize_accessible (DRoutePath * path)
 {
   droute_path_add_interface (path,
                              SPI_DBUS_INTERFACE_ACCESSIBLE,
+                             spi_org_a11y_atspi_Accessible,    
                              methods, properties);
 };