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" |
12 #include "base/logging.h" | 18 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
20 #include "base/message_loop/message_loop.h" | |
21 #include "base/message_loop/message_loop_proxy.h" | |
22 #include "base/threading/thread.h" | |
14 #include "ui/accessibility/platform/atk_util_auralinux.h" | 23 #include "ui/accessibility/platform/atk_util_auralinux.h" |
15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" | 24 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
16 | 25 |
17 namespace { | 26 namespace { |
18 | 27 |
19 #if defined(USE_GCONF) | 28 #if defined(USE_GCONF) |
20 | 29 |
21 const char kGnomeAccessibilityEnabledKey[] = | 30 const char kGnomeAccessibilityEnabledKey[] = |
22 "/desktop/gnome/interface/accessibility"; | 31 "/desktop/gnome/interface/accessibility"; |
23 | 32 |
24 bool ShouldEnableAccessibility() { | 33 #elif defined(USE_DBUS) |
25 GConfClient* client = gconf_client_get_default(); | 34 |
26 if (!client) { | 35 const char kServiceName[] = "org.a11y.Bus"; |
27 LOG(ERROR) << "gconf_client_get_default failed"; | 36 const char kObjectPath[] = "/org/a11y/bus"; |
28 return false; | 37 const char kInterfaceName[] = "org.a11y.Status"; |
38 const char kPropertyName[] = "IsEnabled"; | |
39 | |
40 #endif | |
41 | |
42 void accessibilityModuleInit() { | |
dmazzoni
2015/04/20 16:33:22
AccessibilityModuleInit
| |
43 // Try to load libatk-bridge.so. | |
44 base::FilePath atk_bridge_path(ATK_LIB_DIR); | |
45 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so"); | |
46 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), | |
47 static_cast<GModuleFlags>(0)); | |
48 if (!bridge) { | |
49 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); | |
50 return; | |
29 } | 51 } |
30 | 52 |
31 GError* error = nullptr; | 53 // Try to call gnome_accessibility_module_init from libatk-bridge.so. |
32 gboolean value = gconf_client_get_bool(client, | 54 void (*gnome_accessibility_module_init)(); |
33 kGnomeAccessibilityEnabledKey, | 55 if (g_module_symbol(bridge, "gnome_accessibility_module_init", |
34 &error); | 56 (gpointer *)&gnome_accessibility_module_init)) { |
35 if (error) { | 57 (*gnome_accessibility_module_init)(); |
36 VLOG(1) << "gconf_client_get_bool failed"; | |
37 g_error_free(error); | |
38 g_object_unref(client); | |
39 return false; | |
40 } | 58 } |
41 | |
42 g_object_unref(client); | |
43 return value; | |
44 } | 59 } |
45 | 60 |
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 | |
55 } // namespace | 61 } // namespace |
56 | 62 |
57 G_BEGIN_DECLS | 63 G_BEGIN_DECLS |
58 | 64 |
59 // | 65 // |
60 // atk_util_auralinux AtkObject definition and implementation. | 66 // atk_util_auralinux AtkObject definition and implementation. |
61 // | 67 // |
62 | 68 |
63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 69 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) |
64 #define ATK_UTIL_AURALINUX(obj) \ | 70 #define ATK_UTIL_AURALINUX(obj) \ |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 142 |
137 // static | 143 // static |
138 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { | 144 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
139 return Singleton<AtkUtilAuraLinux>::get(); | 145 return Singleton<AtkUtilAuraLinux>::get(); |
140 } | 146 } |
141 | 147 |
142 AtkUtilAuraLinux::AtkUtilAuraLinux() { | 148 AtkUtilAuraLinux::AtkUtilAuraLinux() { |
143 // Register our util class. | 149 // Register our util class. |
144 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); | 150 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
145 | 151 |
146 if (!ShouldEnableAccessibility()) { | 152 char* enableAccessibility = getenv("ACCESSIBILITY_ENABLED"); |
dmazzoni
2015/04/20 16:33:22
Use enable_accessibility for the variable name.
M
| |
153 if (enableAccessibility && atoi(enableAccessibility) == 1) { | |
154 accessibilityModuleInit(); | |
155 return; | |
156 } | |
157 | |
158 CheckIfAccessibilityIsEnabled(); | |
159 } | |
160 | |
161 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | |
162 } | |
163 | |
164 #if defined(USE_GCONF) || defined(USE_DBUS) | |
165 | |
166 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabled() { | |
167 isEnabled = false; | |
168 | |
169 accessibility_init_thread_.reset( | |
170 new base::Thread("Accessibility Init Thread")); | |
171 base::Thread::Options threadOptions(base::MessageLoop::Type::TYPE_IO, 0); | |
dmazzoni
2015/04/20 16:33:22
thread_options
| |
172 accessibility_init_thread_->StartWithOptions(threadOptions); | |
173 accessibility_init_thread_->task_runner()->PostTaskAndReply( | |
174 FROM_HERE, | |
175 base::Bind(&AtkUtilAuraLinux::CheckPlatformAccessibilitySupport, | |
176 base::Unretained(this)), | |
177 base::Bind(&AtkUtilAuraLinux::OnStopAccessibilityThread, | |
178 base::Unretained(this))); | |
179 } | |
180 | |
181 void AtkUtilAuraLinux::OnStopAccessibilityThread() { | |
182 accessibility_init_thread_.reset(); | |
183 if (!isEnabled) { | |
147 VLOG(1) << "Will not enable ATK accessibility support."; | 184 VLOG(1) << "Will not enable ATK accessibility support."; |
148 return; | 185 return; |
149 } | 186 } |
150 | 187 |
151 VLOG(1) << "Enabling ATK accessibility support."; | 188 VLOG(1) << "Enabling ATK accessibility support."; |
189 accessibilityModuleInit(); | |
190 } | |
152 | 191 |
153 // Try to load libatk-bridge.so. | 192 #else |
154 base::FilePath atk_bridge_path(ATK_LIB_DIR); | 193 |
155 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so"); | 194 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabled() { |
156 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), | 195 } |
157 static_cast<GModuleFlags>(0)); | 196 |
158 if (!bridge) { | 197 void AtkUtilAuraLinux::OnStopAccessibilityThread() { |
159 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); | 198 } |
199 | |
200 #endif | |
201 | |
202 #if defined(USE_GCONF) | |
203 void AtkUtilAuraLinux::CheckPlatformAccessibilitySupport() { | |
204 DCHECK(accessibility_init_thread_->task_runner()->RunsTasksOnCurrentThread()); | |
205 | |
206 GConfClient* client = gconf_client_get_default(); | |
207 if (!client) { | |
208 LOG(ERROR) << "gconf_client_get_default failed"; | |
160 return; | 209 return; |
161 } | 210 } |
162 | 211 |
163 // Try to call gnome_accessibility_module_init from libatk-bridge.so. | 212 GError* error = nullptr; |
164 void (*gnome_accessibility_module_init)(); | 213 isEnabled = gconf_client_get_bool(client, |
165 if (g_module_symbol(bridge, "gnome_accessibility_module_init", | 214 kGnomeAccessibilityEnabledKey, |
dmazzoni
2015/04/20 16:33:22
indentation
| |
166 (gpointer *)&gnome_accessibility_module_init)) { | 215 &error); |
167 (*gnome_accessibility_module_init)(); | 216 |
217 g_object_unref(client); | |
218 | |
219 if (error) { | |
220 VLOG(1) << "gconf_client_get_bool failed"; | |
221 g_error_free(error); | |
222 return; | |
168 } | 223 } |
169 } | 224 } |
170 | 225 |
171 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 226 #elif defined(USE_DBUS) |
227 | |
228 void AtkUtilAuraLinux::CheckPlatformAccessibilitySupport() { | |
229 DCHECK(accessibility_init_thread_->task_runner()->RunsTasksOnCurrentThread()); | |
230 | |
231 dbus::Bus::Options options; | |
232 options.dbus_task_runner = accessibility_init_thread_->task_runner(); | |
233 | |
234 scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options)); | |
235 dbus::ObjectProxy* objectProxy = dbus->GetObjectProxy( | |
dmazzoni
2015/04/20 16:33:22
object_proxy
| |
236 kServiceName, dbus::ObjectPath(kObjectPath)); | |
237 | |
238 DCHECK(objectProxy); | |
239 | |
240 dbus::MethodCall methodCall(DBUS_INTERFACE_PROPERTIES, "Get"); | |
241 dbus::MessageWriter messageWriter(&methodCall); | |
242 messageWriter.AppendString(kInterfaceName); | |
243 messageWriter.AppendString(kPropertyName); | |
244 | |
245 scoped_ptr<dbus::Response> response( | |
246 objectProxy->CallMethodAndBlock(&methodCall, | |
247 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
248 | |
249 if (!response) { | |
250 LOG(ERROR) << "AtSpi: failed to get " << kPropertyName; | |
251 dbus->ShutdownAndBlock(); | |
252 return; | |
253 } | |
254 | |
255 dbus::MessageReader reader(response.get()); | |
256 if (!reader.PopVariantOfBool(&isEnabled)) { | |
257 LOG(ERROR) << "AtSpi: unexpected response"; | |
258 dbus->ShutdownAndBlock(); | |
259 return; | |
260 } | |
261 | |
262 dbus->ShutdownAndBlock(); | |
172 } | 263 } |
173 | 264 |
265 #else | |
266 | |
267 void AtkUtilAuraLinux::CheckPlatformAccessibilitySupport() { | |
268 } | |
269 | |
270 #endif | |
271 | |
174 } // namespace ui | 272 } // namespace ui |
OLD | NEW |