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" | |
13 #endif | 8 #endif |
14 #include <glib-2.0/gmodule.h> | 9 #include <glib-2.0/gmodule.h> |
15 | 10 |
16 #include "base/bind.h" | |
17 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
18 #include "base/location.h" | |
19 #include "base/logging.h" | 12 #include "base/logging.h" |
20 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
21 #include "ui/accessibility/platform/atk_util_auralinux.h" | 14 #include "ui/accessibility/platform/atk_util_auralinux.h" |
22 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" | 15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
23 | 16 |
24 namespace { | 17 namespace { |
25 | 18 |
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 | |
56 #if defined(USE_GCONF) | 19 #if defined(USE_GCONF) |
57 | 20 |
58 const char kGnomeAccessibilityEnabledKey[] = | 21 const char kGnomeAccessibilityEnabledKey[] = |
59 "/desktop/gnome/interface/accessibility"; | 22 "/desktop/gnome/interface/accessibility"; |
60 | 23 |
61 #elif defined(USE_DBUS) | 24 bool ShouldEnableAccessibility() { |
| 25 GConfClient* client = gconf_client_get_default(); |
| 26 if (!client) { |
| 27 LOG(ERROR) << "gconf_client_get_default failed"; |
| 28 return false; |
| 29 } |
62 | 30 |
63 const char kServiceName[] = "org.a11y.Bus"; | 31 GError* error = nullptr; |
64 const char kObjectPath[] = "/org/a11y/bus"; | 32 gboolean value = gconf_client_get_bool(client, |
65 const char kInterfaceName[] = "org.a11y.Status"; | 33 kGnomeAccessibilityEnabledKey, |
66 const char kPropertyName[] = "IsEnabled"; | 34 &error); |
| 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 } |
67 | 41 |
68 #endif | 42 g_object_unref(client); |
| 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) |
69 | 54 |
70 } // namespace | 55 } // namespace |
71 | 56 |
72 G_BEGIN_DECLS | 57 G_BEGIN_DECLS |
73 | 58 |
74 // | 59 // |
75 // atk_util_auralinux AtkObject definition and implementation. | 60 // atk_util_auralinux AtkObject definition and implementation. |
76 // | 61 // |
77 | 62 |
78 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // AtkUtilAuraLinuxClass implementation. | 132 // AtkUtilAuraLinuxClass implementation. |
148 // | 133 // |
149 | 134 |
150 namespace ui { | 135 namespace ui { |
151 | 136 |
152 // static | 137 // static |
153 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { | 138 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
154 return Singleton<AtkUtilAuraLinux>::get(); | 139 return Singleton<AtkUtilAuraLinux>::get(); |
155 } | 140 } |
156 | 141 |
157 #if defined(USE_GCONF) || defined(USE_DBUS) | |
158 | |
159 AtkUtilAuraLinux::AtkUtilAuraLinux() | |
160 : is_enabled_(false) { | |
161 } | |
162 | |
163 #else | |
164 | |
165 AtkUtilAuraLinux::AtkUtilAuraLinux() { | 142 AtkUtilAuraLinux::AtkUtilAuraLinux() { |
166 } | 143 } |
167 | 144 |
168 #endif | |
169 | |
170 void AtkUtilAuraLinux::Initialize( | 145 void AtkUtilAuraLinux::Initialize( |
171 scoped_refptr<base::TaskRunner> init_task_runner) { | 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 |
172 | 150 |
173 // Register our util class. | 151 // Register our util class. |
174 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); | 152 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
175 | 153 |
176 init_task_runner->PostTaskAndReply( | 154 if (!ShouldEnableAccessibility()) { |
177 FROM_HERE, | 155 VLOG(1) << "Will not enable ATK accessibility support."; |
178 base::Bind( | 156 return; |
179 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, | 157 } |
180 base::Unretained(this)), | 158 |
181 base::Bind( | 159 VLOG(1) << "Enabling ATK accessibility support."; |
182 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, | 160 |
183 base::Unretained(this))); | 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. |
| 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)(); |
| 176 } |
184 } | 177 } |
185 | 178 |
186 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 179 AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
187 } | 180 } |
188 | 181 |
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_) { | |
271 VLOG(1) << "Will not enable ATK accessibility support."; | |
272 return; | |
273 } | |
274 | |
275 VLOG(1) << "Enabling ATK accessibility support."; | |
276 // Try to call gnome_accessibility_module_init from libatk-bridge.so. | |
277 DCHECK(g_accessibility_module_init); | |
278 g_accessibility_module_init(); | |
279 } | |
280 | |
281 #else | |
282 | |
283 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | |
284 } | |
285 | |
286 #endif | |
287 | |
288 } // namespace ui | 182 } // namespace ui |
OLD | NEW |