Index: ui/accessibility/platform/atk_util_auralinux.cc |
diff --git a/ui/accessibility/platform/atk_util_auralinux.cc b/ui/accessibility/platform/atk_util_auralinux.cc |
index a15df08137d874609305f90a6bca6e5c15e5c213..5fafeaeabb05165c77c0ab78b345845ce0e3528b 100644 |
--- a/ui/accessibility/platform/atk_util_auralinux.cc |
+++ b/ui/accessibility/platform/atk_util_auralinux.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include <atk/atk.h> |
+#include <dbus/dbus.h> |
#include <gconf/gconf-client.h> |
#include <glib-2.0/gmodule.h> |
@@ -17,7 +18,80 @@ namespace { |
const char kGnomeAccessibilityEnabledKey[] = |
"/desktop/gnome/interface/accessibility"; |
+const char destination[] = "org.a11y.Bus"; |
Peter Lundblad
2015/03/23 16:45:38
Should use the naming style for constants.
|
+const char objectPathTheMessageShouldBeSentTo[] = |
Peter Lundblad
2015/03/23 16:45:38
nit: slightly verbose name.
|
+ "/org/a11y/bus"; |
Peter Lundblad
2015/03/23 16:45:38
Does this fit on the previous line?
|
+const char interfaceToInvokeMethodOn[] = |
+ "org.freedesktop.DBus.Properties"; |
+const char methodToInvoke[] = "Get"; |
+const char* interfaceName = "org.a11y.Status"; |
+const char* propertyName = "IsEnabled"; |
+ |
+bool AtSpiAccessibilityIsEnabled() |
+{ |
+ DBusError error; |
+ dbus_error_init(&error); |
+ |
+ DBusConnection* connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); |
Peter Lundblad
2015/03/23 16:45:38
Are we leaking this connection?
|
+ if (!connection) { |
+ dbus_error_free(&error); |
+ return false; |
+ } |
+ |
+ DBusMessage* message = dbus_message_new_method_call(destination, |
+ objectPathTheMessageShouldBeSentTo, |
+ interfaceToInvokeMethodOn, |
+ methodToInvoke); |
+ if (!message) { |
+ dbus_error_free(&error); |
+ return false; |
+ } |
+ |
+ dbus_message_append_args(message, |
+ DBUS_TYPE_STRING, |
+ &interfaceName, |
+ DBUS_TYPE_STRING, |
+ &propertyName, |
+ DBUS_TYPE_INVALID); |
+ |
+ DBusMessage* reply = dbus_connection_send_with_reply_and_block(connection, |
+ message, |
+ -1, |
+ &error); |
+ |
+ if (dbus_error_is_set(&error)) { |
+ dbus_message_unref(message); |
+ dbus_error_free(&error); |
+ return false; |
+ } |
+ |
+ DBusMessageIter iterator, subIterator; |
+ bool shouldBeEnabled = false; |
+ |
+ dbus_message_iter_init(reply, &iterator); |
+ dbus_message_iter_recurse(&iterator, &subIterator); |
+ switch (dbus_message_iter_get_arg_type(&subIterator)) { |
+ case DBUS_TYPE_BOOLEAN: |
+ dbus_message_iter_get_basic(&subIterator, &shouldBeEnabled); |
+ break; |
+ break; |
Peter Lundblad
2015/03/23 16:45:38
Not reached.
|
+ } |
+ |
+ if (message) |
Peter Lundblad
2015/03/23 16:45:38
When can message be null?
|
+ dbus_message_unref(message); |
+ |
+ if (reply) |
Peter Lundblad
2015/03/23 16:45:38
When can reply be null?
|
+ dbus_message_unref(reply); |
+ |
+ dbus_error_free(&error); |
+ |
+ return shouldBeEnabled; |
+} |
+ |
bool ShouldEnableAccessibility() { |
+ if (AtSpiAccessibilityIsEnabled()) |
+ return true; |
+ |
GConfClient* client = gconf_client_get_default(); |
Peter Lundblad
2015/03/23 16:45:38
Is the rest of this function redundant or is there
|
if (!client) { |
LOG(ERROR) << "gconf_client_get_default failed"; |