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