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 02563199409a73ee6e061bab124384f911e08de0..46ad3be53be8341c11e50c91f17197f360e8b567 100644 |
--- a/ui/accessibility/platform/atk_util_auralinux.cc |
+++ b/ui/accessibility/platform/atk_util_auralinux.cc |
@@ -8,7 +8,9 @@ |
#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 +18,42 @@ |
namespace { |
-#if defined(USE_GCONF) |
+typedef void (*gnome_accessibility_module_init)(); |
-const char kGnomeAccessibilityEnabledKey[] = |
- "/desktop/gnome/interface/accessibility"; |
+const char kAtkBridgePath[] = "gtk-2.0/modules/libatk-bridge.so"; |
+const char kAtkBridgeSymbolName[] = "gnome_accessibility_module_init"; |
-bool ShouldEnableAccessibility() { |
- GConfClient* client = gconf_client_get_default(); |
- if (!client) { |
- LOG(ERROR) << "gconf_client_get_default failed"; |
+gnome_accessibility_module_init g_accessibility_module_init = nullptr; |
+ |
+bool AccessibilityModuleInitOnFileThread() { |
+ // Try to load libatk-bridge.so. |
+ base::FilePath atk_bridge_path(ATK_LIB_DIR); |
+ atk_bridge_path = atk_bridge_path.Append(kAtkBridgePath); |
+ 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 false; |
} |
- 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); |
+ if (!g_module_symbol(bridge, kAtkBridgeSymbolName, |
+ (gpointer *)&g_accessibility_module_init)) { |
+ VLOG(1) << "Unable to get symbol pointer from " << atk_bridge_path.value(); |
+ // Just to make sure it's null; |
+ g_accessibility_module_init = nullptr; |
return false; |
} |
- g_object_unref(client); |
- return value; |
+ return true; |
} |
-#else // !defined(USE_GCONF) |
+#if defined(USE_GCONF) |
-bool ShouldEnableAccessibility() { |
- // TODO(k.czech): implement this for non-GNOME desktops. |
- return false; |
-} |
+const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; |
+const char kGnomeAccessibilityEnabledKey[] = |
+ "/desktop/gnome/interface/accessibility"; |
-#endif // defined(USE_GCONF) |
+#endif |
} // namespace |
@@ -139,44 +142,88 @@ AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
return base::Singleton<AtkUtilAuraLinux>::get(); |
} |
+#if defined(USE_GCONF) |
+ |
+AtkUtilAuraLinux::AtkUtilAuraLinux() |
+ : is_enabled_(false) { |
+} |
+ |
+#else |
+ |
AtkUtilAuraLinux::AtkUtilAuraLinux() { |
} |
+#endif // defined(USE_GCONF) |
+ |
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 |
+ scoped_refptr<base::TaskRunner> init_task_runner) { |
// 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."; |
- return; |
+ init_task_runner->PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind( |
+ &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, |
+ base::Unretained(this)), |
+ base::Bind( |
+ &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, |
+ base::Unretained(this))); |
+} |
+ |
+AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
+} |
+ |
+#if defined(USE_GCONF) |
+ |
+void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
+ char* enable_accessibility = getenv(kAccessibilityEnabled); |
+ if ((enable_accessibility && atoi(enable_accessibility) == 1) || |
+ CheckPlatformAccessibilitySupportOnFileThread()) |
+ is_enabled_ = AccessibilityModuleInitOnFileThread(); |
+} |
+ |
+bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
+ GConfClient* client = gconf_client_get_default(); |
+ if (!client) { |
+ LOG(ERROR) << "gconf_client_get_default failed"; |
+ return false; |
} |
- VLOG(1) << "Enabling ATK accessibility support."; |
+ GError* error = nullptr; |
+ bool is_enabled = gconf_client_get_bool(client, |
+ kGnomeAccessibilityEnabledKey, |
+ &error); |
- // 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; |
+ g_object_unref(client); |
+ |
+ if (error) { |
+ VLOG(1) << "gconf_client_get_bool failed"; |
+ g_error_free(error); |
+ 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)(); |
+ return is_enabled; |
+} |
+ |
+void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
+ if (!is_enabled_) { |
+ VLOG(1) << "Will not enable ATK accessibility support."; |
+ return; |
} |
+ |
+ DCHECK(g_accessibility_module_init); |
+ g_accessibility_module_init(); |
} |
-AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
+#else |
+ |
+void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
+} |
+ |
+void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
} |
+#endif // defined(USE_GCONF) |
+ |
} // namespace ui |