Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <atk/atk.h> | 5 #include <atk/atk.h> |
| 6 #include <dbus/dbus.h> | |
| 6 #include <gconf/gconf-client.h> | 7 #include <gconf/gconf-client.h> |
| 7 #include <glib-2.0/gmodule.h> | 8 #include <glib-2.0/gmodule.h> |
| 8 | 9 |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 12 #include "ui/accessibility/platform/atk_util_auralinux.h" | 13 #include "ui/accessibility/platform/atk_util_auralinux.h" |
| 13 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" | 14 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const char kGnomeAccessibilityEnabledKey[] = | 18 const char kGnomeAccessibilityEnabledKey[] = |
| 18 "/desktop/gnome/interface/accessibility"; | 19 "/desktop/gnome/interface/accessibility"; |
| 19 | 20 |
| 21 const char destination[] = "org.a11y.Bus"; | |
|
Peter Lundblad
2015/03/23 16:45:38
Should use the naming style for constants.
| |
| 22 const char objectPathTheMessageShouldBeSentTo[] = | |
|
Peter Lundblad
2015/03/23 16:45:38
nit: slightly verbose name.
| |
| 23 "/org/a11y/bus"; | |
|
Peter Lundblad
2015/03/23 16:45:38
Does this fit on the previous line?
| |
| 24 const char interfaceToInvokeMethodOn[] = | |
| 25 "org.freedesktop.DBus.Properties"; | |
| 26 const char methodToInvoke[] = "Get"; | |
| 27 const char* interfaceName = "org.a11y.Status"; | |
| 28 const char* propertyName = "IsEnabled"; | |
| 29 | |
| 30 bool AtSpiAccessibilityIsEnabled() | |
| 31 { | |
| 32 DBusError error; | |
| 33 dbus_error_init(&error); | |
| 34 | |
| 35 DBusConnection* connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); | |
|
Peter Lundblad
2015/03/23 16:45:38
Are we leaking this connection?
| |
| 36 if (!connection) { | |
| 37 dbus_error_free(&error); | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 DBusMessage* message = dbus_message_new_method_call(destination, | |
| 42 objectPathTheMessageShouldBeSentTo, | |
| 43 interfaceToInvokeMethodOn, | |
| 44 methodToInvoke); | |
| 45 if (!message) { | |
| 46 dbus_error_free(&error); | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 dbus_message_append_args(message, | |
| 51 DBUS_TYPE_STRING, | |
| 52 &interfaceName, | |
| 53 DBUS_TYPE_STRING, | |
| 54 &propertyName, | |
| 55 DBUS_TYPE_INVALID); | |
| 56 | |
| 57 DBusMessage* reply = dbus_connection_send_with_reply_and_block(connection, | |
| 58 message, | |
| 59 -1, | |
| 60 &error); | |
| 61 | |
| 62 if (dbus_error_is_set(&error)) { | |
| 63 dbus_message_unref(message); | |
| 64 dbus_error_free(&error); | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 DBusMessageIter iterator, subIterator; | |
| 69 bool shouldBeEnabled = false; | |
| 70 | |
| 71 dbus_message_iter_init(reply, &iterator); | |
| 72 dbus_message_iter_recurse(&iterator, &subIterator); | |
| 73 switch (dbus_message_iter_get_arg_type(&subIterator)) { | |
| 74 case DBUS_TYPE_BOOLEAN: | |
| 75 dbus_message_iter_get_basic(&subIterator, &shouldBeEnabled); | |
| 76 break; | |
| 77 break; | |
|
Peter Lundblad
2015/03/23 16:45:38
Not reached.
| |
| 78 } | |
| 79 | |
| 80 if (message) | |
|
Peter Lundblad
2015/03/23 16:45:38
When can message be null?
| |
| 81 dbus_message_unref(message); | |
| 82 | |
| 83 if (reply) | |
|
Peter Lundblad
2015/03/23 16:45:38
When can reply be null?
| |
| 84 dbus_message_unref(reply); | |
| 85 | |
| 86 dbus_error_free(&error); | |
| 87 | |
| 88 return shouldBeEnabled; | |
| 89 } | |
| 90 | |
| 20 bool ShouldEnableAccessibility() { | 91 bool ShouldEnableAccessibility() { |
| 92 if (AtSpiAccessibilityIsEnabled()) | |
| 93 return true; | |
| 94 | |
| 21 GConfClient* client = gconf_client_get_default(); | 95 GConfClient* client = gconf_client_get_default(); |
|
Peter Lundblad
2015/03/23 16:45:38
Is the rest of this function redundant or is there
| |
| 22 if (!client) { | 96 if (!client) { |
| 23 LOG(ERROR) << "gconf_client_get_default failed"; | 97 LOG(ERROR) << "gconf_client_get_default failed"; |
| 24 return false; | 98 return false; |
| 25 } | 99 } |
| 26 | 100 |
| 27 GError* error = nullptr; | 101 GError* error = nullptr; |
| 28 gboolean value = gconf_client_get_bool(client, | 102 gboolean value = gconf_client_get_bool(client, |
| 29 kGnomeAccessibilityEnabledKey, | 103 kGnomeAccessibilityEnabledKey, |
| 30 &error); | 104 &error); |
| 31 if (error) { | 105 if (error) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 if (g_module_symbol(bridge, "gnome_accessibility_module_init", | 226 if (g_module_symbol(bridge, "gnome_accessibility_module_init", |
| 153 (gpointer *)&gnome_accessibility_module_init)) { | 227 (gpointer *)&gnome_accessibility_module_init)) { |
| 154 (*gnome_accessibility_module_init)(); | 228 (*gnome_accessibility_module_init)(); |
| 155 } | 229 } |
| 156 } | 230 } |
| 157 | 231 |
| 158 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 232 AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| 159 } | 233 } |
| 160 | 234 |
| 161 } // namespace ui | 235 } // namespace ui |
| OLD | NEW |