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 #if defined(USE_GCONF) | 6 #if defined(USE_GCONF) |
7 #include <gconf/gconf-client.h> | 7 #include <gconf/gconf-client.h> |
| 8 #elif defined(USE_DBUS) |
| 9 #include "dbus/bus.h" |
| 10 #include "dbus/message.h" |
| 11 #include "dbus/object_path.h" |
| 12 #include "dbus/object_proxy.h" |
8 #endif | 13 #endif |
9 #include <glib-2.0/gmodule.h> | 14 #include <glib-2.0/gmodule.h> |
10 | 15 |
| 16 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/location.h" |
12 #include "base/logging.h" | 19 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 20 #include "base/memory/singleton.h" |
14 #include "ui/accessibility/platform/atk_util_auralinux.h" | 21 #include "ui/accessibility/platform/atk_util_auralinux.h" |
15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" | 22 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
16 | 23 |
17 namespace { | 24 namespace { |
18 | 25 |
| 26 typedef void (*gnome_accessibility_module_init)(); |
| 27 |
| 28 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; |
| 29 const char kAtkBridgePath[] = "gtk-2.0/modules/libatk-bridge.so"; |
| 30 const char kAtkBridgeSymbolName[] = "gnome_accessibility_module_init"; |
| 31 |
| 32 gnome_accessibility_module_init g_accessibility_module_init = nullptr; |
| 33 |
| 34 bool AccessibilityModuleInitOnFileThread() { |
| 35 // Try to load libatk-bridge.so. |
| 36 base::FilePath atk_bridge_path(ATK_LIB_DIR); |
| 37 atk_bridge_path = atk_bridge_path.Append(kAtkBridgePath); |
| 38 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), |
| 39 static_cast<GModuleFlags>(0)); |
| 40 if (!bridge) { |
| 41 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); |
| 42 return false; |
| 43 } |
| 44 |
| 45 if (!g_module_symbol(bridge, kAtkBridgeSymbolName, |
| 46 (gpointer *)&g_accessibility_module_init)) { |
| 47 VLOG(1) << "Unable to get symbol pointer from " << atk_bridge_path.value(); |
| 48 // Just to make sure it's null; |
| 49 g_accessibility_module_init = nullptr; |
| 50 return false; |
| 51 } |
| 52 |
| 53 return true; |
| 54 } |
| 55 |
19 #if defined(USE_GCONF) | 56 #if defined(USE_GCONF) |
20 | 57 |
21 const char kGnomeAccessibilityEnabledKey[] = | 58 const char kGnomeAccessibilityEnabledKey[] = |
22 "/desktop/gnome/interface/accessibility"; | 59 "/desktop/gnome/interface/accessibility"; |
23 | 60 |
24 bool ShouldEnableAccessibility() { | 61 #elif defined(USE_DBUS) |
25 GConfClient* client = gconf_client_get_default(); | |
26 if (!client) { | |
27 LOG(ERROR) << "gconf_client_get_default failed"; | |
28 return false; | |
29 } | |
30 | 62 |
31 GError* error = nullptr; | 63 const char kServiceName[] = "org.a11y.Bus"; |
32 gboolean value = gconf_client_get_bool(client, | 64 const char kObjectPath[] = "/org/a11y/bus"; |
33 kGnomeAccessibilityEnabledKey, | 65 const char kInterfaceName[] = "org.a11y.Status"; |
34 &error); | 66 const char kPropertyName[] = "IsEnabled"; |
35 if (error) { | |
36 VLOG(1) << "gconf_client_get_bool failed"; | |
37 g_error_free(error); | |
38 g_object_unref(client); | |
39 return false; | |
40 } | |
41 | 67 |
42 g_object_unref(client); | 68 #endif |
43 return value; | |
44 } | |
45 | |
46 #else // !defined(USE_GCONF) | |
47 | |
48 bool ShouldEnableAccessibility() { | |
49 // TODO(k.czech): implement this for non-GNOME desktops. | |
50 return false; | |
51 } | |
52 | |
53 #endif // defined(USE_GCONF) | |
54 | 69 |
55 } // namespace | 70 } // namespace |
56 | 71 |
57 G_BEGIN_DECLS | 72 G_BEGIN_DECLS |
58 | 73 |
59 // | 74 // |
60 // atk_util_auralinux AtkObject definition and implementation. | 75 // atk_util_auralinux AtkObject definition and implementation. |
61 // | 76 // |
62 | 77 |
63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 78 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // AtkUtilAuraLinuxClass implementation. | 147 // AtkUtilAuraLinuxClass implementation. |
133 // | 148 // |
134 | 149 |
135 namespace ui { | 150 namespace ui { |
136 | 151 |
137 // static | 152 // static |
138 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { | 153 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
139 return Singleton<AtkUtilAuraLinux>::get(); | 154 return Singleton<AtkUtilAuraLinux>::get(); |
140 } | 155 } |
141 | 156 |
| 157 #if defined(USE_GCONF) || defined(USE_DBUS) |
| 158 |
| 159 AtkUtilAuraLinux::AtkUtilAuraLinux() |
| 160 : is_enabled_(false) { |
| 161 } |
| 162 |
| 163 #else |
| 164 |
142 AtkUtilAuraLinux::AtkUtilAuraLinux() { | 165 AtkUtilAuraLinux::AtkUtilAuraLinux() { |
143 } | 166 } |
144 | 167 |
| 168 #endif |
| 169 |
145 void AtkUtilAuraLinux::Initialize( | 170 void AtkUtilAuraLinux::Initialize( |
146 scoped_refptr<base::TaskRunner> init_task_runner) { | 171 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 | |
150 | 172 |
151 // Register our util class. | 173 // Register our util class. |
152 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); | 174 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
153 | 175 |
154 if (!ShouldEnableAccessibility()) { | 176 init_task_runner->PostTaskAndReply( |
| 177 FROM_HERE, |
| 178 base::Bind( |
| 179 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, |
| 180 base::Unretained(this)), |
| 181 base::Bind( |
| 182 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, |
| 183 base::Unretained(this))); |
| 184 } |
| 185 |
| 186 AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| 187 } |
| 188 |
| 189 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
| 190 char* enable_accessibility = getenv(kAccessibilityEnabled); |
| 191 if ((enable_accessibility && atoi(enable_accessibility) == 1) || |
| 192 CheckPlatformAccessibilitySupportOnFileThread()) |
| 193 is_enabled_ = AccessibilityModuleInitOnFileThread(); |
| 194 } |
| 195 |
| 196 #if defined(USE_GCONF) |
| 197 |
| 198 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
| 199 GConfClient* client = gconf_client_get_default(); |
| 200 if (!client) { |
| 201 LOG(ERROR) << "gconf_client_get_default failed"; |
| 202 return false; |
| 203 } |
| 204 |
| 205 GError* error = nullptr; |
| 206 bool is_enabled = gconf_client_get_bool(client, |
| 207 kGnomeAccessibilityEnabledKey, |
| 208 &error); |
| 209 |
| 210 g_object_unref(client); |
| 211 |
| 212 if (error) { |
| 213 VLOG(1) << "gconf_client_get_bool failed"; |
| 214 g_error_free(error); |
| 215 return false; |
| 216 } |
| 217 |
| 218 return is_enabled; |
| 219 } |
| 220 |
| 221 #elif defined(USE_DBUS) |
| 222 |
| 223 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
| 224 dbus::Bus::Options options; |
| 225 scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options)); |
| 226 dbus::ObjectProxy* object_proxy = dbus->GetObjectProxy( |
| 227 kServiceName, dbus::ObjectPath(kObjectPath)); |
| 228 |
| 229 DCHECK(object_proxy); |
| 230 |
| 231 dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); |
| 232 dbus::MessageWriter message_writer(&method_call); |
| 233 message_writer.AppendString(kInterfaceName); |
| 234 message_writer.AppendString(kPropertyName); |
| 235 |
| 236 // TODO(k.czech) replace this with asynchronous call |
| 237 scoped_ptr<dbus::Response> response( |
| 238 object_proxy->CallMethodAndBlock(&method_call, |
| 239 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 240 |
| 241 if (!response) { |
| 242 LOG(ERROR) << "AtSpi: failed to get " << kPropertyName; |
| 243 dbus->ShutdownAndBlock(); |
| 244 return false; |
| 245 } |
| 246 |
| 247 // TODO(k.czech) handle case for at-spi2-core version 2.2.0/2.2.2 |
| 248 // org.a11y.Bus.Enabled returns variant struct with a bool instead of bool |
| 249 bool is_enabled = false; |
| 250 dbus::MessageReader reader(response.get()); |
| 251 if (!reader.PopVariantOfBool(&is_enabled)) |
| 252 LOG(ERROR) << "AtSpi: unexpected response"; |
| 253 |
| 254 dbus->ShutdownAndBlock(); |
| 255 |
| 256 return is_enabled; |
| 257 } |
| 258 |
| 259 #else |
| 260 |
| 261 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { |
| 262 return false; |
| 263 } |
| 264 |
| 265 #endif |
| 266 |
| 267 #if defined(USE_GCONF) || defined(USE_DBUS) |
| 268 |
| 269 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| 270 if (!is_enabled_) { |
155 VLOG(1) << "Will not enable ATK accessibility support."; | 271 VLOG(1) << "Will not enable ATK accessibility support."; |
156 return; | 272 return; |
157 } | 273 } |
158 | 274 |
159 VLOG(1) << "Enabling ATK accessibility support."; | 275 VLOG(1) << "Enabling ATK accessibility support."; |
160 | |
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)); | |
166 if (!bridge) { | |
167 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); | |
168 return; | |
169 } | |
170 | |
171 // Try to call gnome_accessibility_module_init from libatk-bridge.so. | 276 // Try to call gnome_accessibility_module_init from libatk-bridge.so. |
172 void (*gnome_accessibility_module_init)(); | 277 DCHECK(g_accessibility_module_init); |
173 if (g_module_symbol(bridge, "gnome_accessibility_module_init", | 278 g_accessibility_module_init(); |
174 (gpointer *)&gnome_accessibility_module_init)) { | |
175 (*gnome_accessibility_module_init)(); | |
176 } | |
177 } | 279 } |
178 | 280 |
179 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 281 #else |
| 282 |
| 283 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
180 } | 284 } |
181 | 285 |
| 286 #endif |
| 287 |
182 } // namespace ui | 288 } // namespace ui |
OLD | NEW |