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 5d25c510e3258a7a990185f625cfc181eb1ad462..a0397e01532d5ba6dac13516da1aeddfd6e4cf66 100644 |
| --- a/ui/accessibility/platform/atk_util_auralinux.cc |
| +++ b/ui/accessibility/platform/atk_util_auralinux.cc |
| @@ -5,10 +5,17 @@ |
| #include <atk/atk.h> |
| #if defined(USE_GCONF) |
| #include <gconf/gconf-client.h> |
| +#elif defined(USE_DBUS) |
| +#include "dbus/bus.h" |
| +#include "dbus/message.h" |
| +#include "dbus/object_path.h" |
| +#include "dbus/object_proxy.h" |
| #endif |
| #include <glib-2.0/gmodule.h> |
| +#include "base/bind.h" |
| #include "base/files/file_path.h" |
| +#include "base/location.h" |
| #include "base/logging.h" |
| #include "base/memory/singleton.h" |
| #include "ui/accessibility/platform/atk_util_auralinux.h" |
| @@ -16,41 +23,42 @@ |
| namespace { |
| -#if defined(USE_GCONF) |
| +const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; |
| -const char kGnomeAccessibilityEnabledKey[] = |
| - "/desktop/gnome/interface/accessibility"; |
| +void AccessibilityModuleInitOnUIThread() { |
| + VLOG(1) << "Enabling ATK accessibility support."; |
| -bool ShouldEnableAccessibility() { |
| - GConfClient* client = gconf_client_get_default(); |
| - if (!client) { |
| - LOG(ERROR) << "gconf_client_get_default failed"; |
| - return false; |
| + // 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(), |
|
Peter Lundblad
2015/05/04 12:20:25
I agree with Dominic's earlier comment aht this, i
|
| + static_cast<GModuleFlags>(0)); |
| + if (!bridge) { |
| + VLOG(1) << "Unable to open module " << atk_bridge_path.value(); |
| + return; |
| } |
| - GError* error = nullptr; |
| - gboolean value = gconf_client_get_bool(client, |
| - kGnomeAccessibilityEnabledKey, |
| - &error); |
| - if (error) { |
| - VLOG(1) << "gconf_client_get_bool failed"; |
| - g_error_free(error); |
| - g_object_unref(client); |
| - return false; |
| + // 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)(); |
| } |
| - |
| - g_object_unref(client); |
| - return value; |
| } |
| -#else // !defined(USE_GCONF) |
| +#if defined(USE_GCONF) |
| -bool ShouldEnableAccessibility() { |
| - // TODO(k.czech): implement this for non-GNOME desktops. |
| - return false; |
| -} |
| +const char kGnomeAccessibilityEnabledKey[] = |
| + "/desktop/gnome/interface/accessibility"; |
| -#endif // defined(USE_GCONF) |
| +#elif defined(USE_DBUS) |
| + |
| +const char kServiceName[] = "org.a11y.Bus"; |
| +const char kObjectPath[] = "/org/a11y/bus"; |
| +const char kInterfaceName[] = "org.a11y.Status"; |
| +const char kPropertyName[] = "IsEnabled"; |
| + |
| +#endif |
| } // namespace |
| @@ -139,44 +147,124 @@ AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
| return Singleton<AtkUtilAuraLinux>::get(); |
| } |
| +#if defined(USE_GCONF) || defined(USE_DBUS) |
| + |
| +AtkUtilAuraLinux::AtkUtilAuraLinux() |
| + : is_enabled_(false) { |
| +} |
| + |
| +#else |
| + |
| AtkUtilAuraLinux::AtkUtilAuraLinux() { |
| } |
| +#endif |
| + |
| void AtkUtilAuraLinux::Initialize( |
| scoped_refptr<base::TaskRunner> init_task_runner) { |
| - // TODO(k.czech): use |init_task_runner| to post a task to do the |
| - // initialization rather than doing it on this thread. |
| - // http://crbug.com/468112 |
| // Register our util class. |
| g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
| - if (!ShouldEnableAccessibility()) { |
| - VLOG(1) << "Will not enable ATK accessibility support."; |
| + char* enable_accessibility = getenv(kAccessibilityEnabled); |
| + if (enable_accessibility && atoi(enable_accessibility) == 1) { |
| + AccessibilityModuleInitOnUIThread(); |
| return; |
| } |
| - VLOG(1) << "Enabling ATK accessibility support."; |
| + init_task_runner->PostTaskAndReply( |
| + FROM_HERE, |
| + base::Bind( |
| + &AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread, |
| + base::Unretained(this)), |
| + base::Bind( |
| + &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, |
| + base::Unretained(this))); |
| +} |
| - // 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(); |
| +AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| +} |
| + |
| +#if defined(USE_GCONF) |
| + |
| +void AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
| + GConfClient* client = gconf_client_get_default(); |
| + if (!client) { |
| + LOG(ERROR) << "gconf_client_get_default failed"; |
| 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)(); |
| + GError* error = nullptr; |
| + is_enabled_ = gconf_client_get_bool(client, |
| + kGnomeAccessibilityEnabledKey, |
| + &error); |
| + |
| + g_object_unref(client); |
| + |
| + if (error) { |
| + VLOG(1) << "gconf_client_get_bool failed"; |
| + g_error_free(error); |
| } |
| } |
| -AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| +#elif defined(USE_DBUS) |
| + |
| +void AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
| + dbus::Bus::Options options; |
| + scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options)); |
| + dbus::ObjectProxy* object_proxy = dbus->GetObjectProxy( |
| + kServiceName, dbus::ObjectPath(kObjectPath)); |
| + |
| + DCHECK(object_proxy); |
| + |
| + dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); |
| + dbus::MessageWriter message_writer(&method_call); |
| + message_writer.AppendString(kInterfaceName); |
| + message_writer.AppendString(kPropertyName); |
| + |
| + // TODO(k.czech) replace this with asynchronous call |
| + scoped_ptr<dbus::Response> response( |
| + object_proxy->CallMethodAndBlock(&method_call, |
| + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| + |
| + if (!response) { |
| + LOG(ERROR) << "AtSpi: failed to get " << kPropertyName; |
| + dbus->ShutdownAndBlock(); |
| + return; |
| + } |
| + |
| + // TODO(k.czech) handle case for at-spi2-core version 2.2.0/2.2.2 |
| + // org.a11y.Bus.Enabled returns variant struct with a bool instead of bool |
| + dbus::MessageReader reader(response.get()); |
| + if (!reader.PopVariantOfBool(&is_enabled_)) |
| + LOG(ERROR) << "AtSpi: unexpected response"; |
| + |
| + dbus->ShutdownAndBlock(); |
| +} |
| + |
| +#else |
| + |
| +void AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
| +} |
| + |
| +#endif |
| + |
| +#if defined(USE_GCONF) || defined(USE_DBUS) |
| + |
| +void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| + if (!is_enabled_) { |
| + VLOG(1) << "Will not enable ATK accessibility support."; |
| + return; |
| + } |
| + |
| + AccessibilityModuleInitOnUIThread(); |
| +} |
| + |
| +#else |
| + |
| +void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| } |
| +#endif |
| + |
| } // namespace ui |