Chromium Code Reviews| 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 7fcaf219351289fe7eba1f670d7a6743a8b40ddc..a8d16ed3f113fd93d2cbe700e08d07c52ad56d4e 100644 |
| --- a/ui/accessibility/platform/atk_util_auralinux.cc |
| +++ b/ui/accessibility/platform/atk_util_auralinux.cc |
| @@ -8,9 +8,17 @@ |
| #endif |
| #include <glib-2.0/gmodule.h> |
| +#include "base/bind.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/memory/singleton.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| +#include "base/threading/thread.h" |
| +#include "dbus/bus.h" |
| +#include "dbus/message.h" |
| +#include "dbus/object_path.h" |
| +#include "dbus/object_proxy.h" |
| #include "ui/accessibility/platform/atk_util_auralinux.h" |
| #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
| @@ -21,7 +29,7 @@ namespace { |
| const char kGnomeAccessibilityEnabledKey[] = |
| "/desktop/gnome/interface/accessibility"; |
| -bool ShouldEnableAccessibility() { |
| +bool CheckGnomeAccessibilityKey() { |
| GConfClient* client = gconf_client_get_default(); |
| if (!client) { |
| LOG(ERROR) << "gconf_client_get_default failed"; |
| @@ -45,12 +53,31 @@ bool ShouldEnableAccessibility() { |
| #else // !defined(USE_GCONF) |
| -bool ShouldEnableAccessibility() { |
| - // TODO(k.czech): implement this for non-GNOME desktops. |
| - return false; |
| -} |
| +const char kServiceName[] = "org.a11y.Bus"; |
| +const char kObjectPath[] = "/org/a11y/bus"; |
| +const char kInterfaceName[] = "org.a11y.Status"; |
| +const char kPropertyName[] = "IsEnabled"; |
| + |
| +#endif // defined(USE_GCONF) |
| -#endif // defined(USE_GCONF) |
| +void accessibilityModuleInit() { |
| + // Try to load libatk-bridge.so. |
| + base::FilePath atk_bridge_path(ATK_LIB_DIR); |
| + atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so"); |
| + GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), |
| + static_cast<GModuleFlags>(0)); |
| + if (!bridge) { |
| + VLOG(1) << "Unable to open module " << atk_bridge_path.value(); |
| + return; |
| + } |
| + |
| + // Try to call gnome_accessibility_module_init from libatk-bridge.so. |
| + void (*gnome_accessibility_module_init)(); |
| + if (g_module_symbol(bridge, "gnome_accessibility_module_init", |
| + (gpointer *)&gnome_accessibility_module_init)) { |
| + (*gnome_accessibility_module_init)(); |
| + } |
| +} |
| } // namespace |
| @@ -142,33 +169,76 @@ AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
| AtkUtilAuraLinux::AtkUtilAuraLinux() { |
| // Register our util class. |
| g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
| + ShouldAccessibilityBeEnabled(); |
|
dmazzoni
2015/04/15 16:48:35
I'd rename this to CheckIfAccessibilityIsEnabled s
|
| +} |
| - if (!ShouldEnableAccessibility()) { |
| - VLOG(1) << "Will not enable ATK accessibility support."; |
| +AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| +} |
| + |
| +void AtkUtilAuraLinux::ShouldAccessibilityBeEnabled() { |
| +#if defined(USE_GCONF) |
| + if (CheckGnomeAccessibilityKey()) { |
|
dmazzoni
2015/04/15 16:48:35
I think we should run this in a separate thread to
|
| + VLOG(1) << "Will not enable ATK accessibility support." |
| return; |
| } |
| VLOG(1) << "Enabling ATK accessibility support."; |
| + accessibilityModuleInit(); |
| +#else |
|
dmazzoni
2015/04/15 16:48:35
Should this check USE_DBUS like the gyp file does?
|
| + dbusThread_.reset(new base::Thread("AtSpi D-Bus Thread")); |
| + base::Thread::Options threadOptions(base::MessageLoop::Type::TYPE_IO, 0); |
| + dbusThread_->StartWithOptions(threadOptions); |
| + dbusThread_->task_runner()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AtkUtilAuraLinux::CheckAtSpiIsEnabledProperty, |
| + base::Unretained(this))); |
| +#endif |
| +} |
| - // Try to load libatk-bridge.so. |
| - base::FilePath atk_bridge_path(ATK_LIB_DIR); |
| - atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so"); |
| - GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), |
| - static_cast<GModuleFlags>(0)); |
| - if (!bridge) { |
| - VLOG(1) << "Unable to open module " << atk_bridge_path.value(); |
| +void AtkUtilAuraLinux::CheckAtSpiIsEnabledProperty() { |
| + DCHECK(dbusThread_->task_runner()->RunsTasksOnCurrentThread()); |
| + |
| + dbus::Bus::Options options; |
| + options.connection_type = dbus::Bus::PRIVATE; |
| + options.dbus_task_runner = dbusThread_->task_runner(); |
| + |
| + scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options)); |
| + dbus::ObjectProxy* objectProxy = dbus->GetObjectProxy( |
| + kServiceName, dbus::ObjectPath(kObjectPath)); |
|
dmazzoni
2015/04/15 16:48:35
nit: indent 4 spaces for line continuation
|
| + |
| + if (!objectProxy) { |
| + LOG(ERROR) << "Does not support " << kServiceName << " over DBUS"; |
| return; |
| } |
| - // Try to call gnome_accessibility_module_init from libatk-bridge.so. |
| - void (*gnome_accessibility_module_init)(); |
| - if (g_module_symbol(bridge, "gnome_accessibility_module_init", |
| - (gpointer *)&gnome_accessibility_module_init)) { |
| - (*gnome_accessibility_module_init)(); |
| + dbus::MethodCall methodCall(DBUS_INTERFACE_PROPERTIES, "Get"); |
| + dbus::MessageWriter messageWriter(&methodCall); |
| + messageWriter.AppendString(kInterfaceName); |
| + messageWriter.AppendString(kPropertyName); |
| + |
| + scoped_ptr<dbus::Response> response( |
| + objectProxy->CallMethodAndBlock(&methodCall, |
|
dmazzoni
2015/04/15 16:48:35
nit: same (4 spaces)
|
| + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| + |
| + if (!response) { |
| + LOG(ERROR) << "AtSpi: failed to get " << kPropertyName; |
| + return; |
| } |
| -} |
| -AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| + dbus::MessageReader reader(response.get()); |
| + bool IsEnabled = false; |
| + if (!reader.PopVariantOfBool(&IsEnabled)) { |
| + LOG(ERROR) << "AtSpi: unexpected response"; |
| + return; |
| + } |
| + |
| + if (!IsEnabled) { |
| + VLOG(1) << "Will not enable ATK accessibility support."; |
| + return; |
| + } |
| + |
| + accessibilityModuleInit(); |
| + dbus->ShutdownAndBlock(); |
| } |
| } // namespace ui |