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
3 // found in the LICENSE file.
7 #include <gconf/gconf-client.h>
9 #include <glib-2.0/gmodule.h>
11 #include "base/files/file_path.h"
12 #include "base/logging.h"
13 #include "base/memory/singleton.h"
14 #include "ui/accessibility/platform/atk_util_auralinux.h"
15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h"
19 #if defined(USE_GCONF)
21 const char kGnomeAccessibilityEnabledKey
[] =
22 "/desktop/gnome/interface/accessibility";
24 bool ShouldEnableAccessibility() {
25 GConfClient
* client
= gconf_client_get_default();
27 LOG(ERROR
) << "gconf_client_get_default failed";
31 GError
* error
= nullptr;
32 gboolean value
= gconf_client_get_bool(client
,
33 kGnomeAccessibilityEnabledKey
,
36 VLOG(1) << "gconf_client_get_bool failed";
38 g_object_unref(client
);
42 g_object_unref(client
);
46 #else // !defined(USE_GCONF)
48 bool ShouldEnableAccessibility() {
49 // TODO(k.czech): implement this for non-GNOME desktops.
53 #endif // defined(USE_GCONF)
60 // atk_util_auralinux AtkObject definition and implementation.
63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type())
64 #define ATK_UTIL_AURALINUX(obj) \
65 (G_TYPE_CHECK_INSTANCE_CAST((obj), \
66 ATK_UTIL_AURALINUX_TYPE, \
68 #define ATK_UTIL_AURALINUX_CLASS(klass) \
69 (G_TYPE_CHECK_CLASS_CAST((klass), \
70 ATK_UTIL_AURALINUX_TYPE, \
71 AtkUtilAuraLinuxClass))
72 #define IS_ATK_UTIL_AURALINUX(obj) \
73 (G_TYPE_CHECK_INSTANCE_TYPE((obj), ATK_UTIL_AURALINUX_TYPE))
74 #define IS_ATK_UTIL_AURALINUX_CLASS(klass) \
75 (G_TYPE_CHECK_CLASS_TYPE((klass), ATK_UTIL_AURALINUX_TYPE))
76 #define ATK_UTIL_AURALINUX_GET_CLASS(obj) \
77 (G_TYPE_INSTANCE_GET_CLASS((obj), \
78 ATK_UTIL_AURALINUX_TYPE, \
79 AtkUtilAuraLinuxClass))
81 typedef struct _AtkUtilAuraLinux AtkUtilAuraLinux
;
82 typedef struct _AtkUtilAuraLinuxClass AtkUtilAuraLinuxClass
;
84 struct _AtkUtilAuraLinux
89 struct _AtkUtilAuraLinuxClass
91 AtkUtilClass parent_class
;
94 GType
atk_util_auralinux_get_type();
96 G_DEFINE_TYPE(AtkUtilAuraLinux
, atk_util_auralinux
, ATK_TYPE_UTIL
);
98 static void atk_util_auralinux_init(AtkUtilAuraLinux
*ax_util
) {
101 static AtkObject
* atk_util_auralinux_get_root() {
102 ui::AXPlatformNode
* application
= ui::AXPlatformNodeAuraLinux::application();
104 return application
->GetNativeViewAccessible();
109 static G_CONST_RETURN gchar
* atk_util_auralinux_get_toolkit_name(void) {
113 static G_CONST_RETURN gchar
* atk_util_auralinux_get_toolkit_version(void) {
117 static void atk_util_auralinux_class_init(AtkUtilAuraLinuxClass
*klass
) {
118 AtkUtilClass
*atk_class
;
121 data
= g_type_class_peek(ATK_TYPE_UTIL
);
122 atk_class
= ATK_UTIL_CLASS(data
);
124 atk_class
->get_root
= atk_util_auralinux_get_root
;
125 atk_class
->get_toolkit_name
= atk_util_auralinux_get_toolkit_name
;
126 atk_class
->get_toolkit_version
= atk_util_auralinux_get_toolkit_version
;
132 // AtkUtilAuraLinuxClass implementation.
138 AtkUtilAuraLinux
* AtkUtilAuraLinux::GetInstance() {
139 return base::Singleton
<AtkUtilAuraLinux
>::get();
142 AtkUtilAuraLinux::AtkUtilAuraLinux() {
145 void AtkUtilAuraLinux::Initialize(
146 scoped_refptr
<base::TaskRunner
> /* init_task_runner */) {
147 // TODO(k.czech): use |init_task_runner| to post a task to do the
148 // initialization rather than doing it on this thread.
149 // http://crbug.com/468112
151 // Register our util class.
152 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE
));
154 if (!ShouldEnableAccessibility()) {
155 VLOG(1) << "Will not enable ATK accessibility support.";
159 VLOG(1) << "Enabling ATK accessibility support.";
161 // Try to load libatk-bridge.so.
162 base::FilePath
atk_bridge_path(ATK_LIB_DIR
);
163 atk_bridge_path
= atk_bridge_path
.Append("gtk-2.0/modules/libatk-bridge.so");
164 GModule
* bridge
= g_module_open(atk_bridge_path
.value().c_str(),
165 static_cast<GModuleFlags
>(0));
167 VLOG(1) << "Unable to open module " << atk_bridge_path
.value();
171 // Try to call gnome_accessibility_module_init from libatk-bridge.so.
172 void (*gnome_accessibility_module_init
)();
173 if (g_module_symbol(bridge
, "gnome_accessibility_module_init",
174 (gpointer
*)&gnome_accessibility_module_init
)) {
175 (*gnome_accessibility_module_init
)();
179 AtkUtilAuraLinux::~AtkUtilAuraLinux() {