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 accessibility_module_init = nullptr; | |
dmazzoni
2015/05/04 15:41:05
nit: this is a global, so by convention we prefix
| |
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 *)&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 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 if (AccessibilityModuleInitOnFileThread()) | |
193 is_enabled_ = true; | |
dmazzoni
2015/05/04 15:41:05
nit: indent by only 2.
How about just this instea
| |
194 return; | |
195 } | |
196 | |
197 if (CheckPlatformAccessibilitySupportOnFileThread()) | |
198 AccessibilityModuleInitOnFileThread(); | |
dmazzoni
2015/05/04 15:41:05
You need to set is_enabled_ here too:
is_enabled_
| |
199 } | |
200 | |
201 #if defined(USE_GCONF) | |
202 | |
203 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { | |
204 GConfClient* client = gconf_client_get_default(); | |
205 if (!client) { | |
206 LOG(ERROR) << "gconf_client_get_default failed"; | |
207 return false; | |
208 } | |
209 | |
210 GError* error = nullptr; | |
211 is_enabled_ = gconf_client_get_bool(client, | |
dmazzoni
2015/05/04 15:41:05
Nit: make this a local variable: bool is_enabled =
| |
212 kGnomeAccessibilityEnabledKey, | |
213 &error); | |
214 | |
215 g_object_unref(client); | |
216 | |
217 if (error) { | |
218 VLOG(1) << "gconf_client_get_bool failed"; | |
219 g_error_free(error); | |
220 return false | |
221 } | |
222 | |
223 return is_enabled_; | |
dmazzoni
2015/05/04 15:41:05
return is_enabled (not is_enabled_)
| |
224 } | |
225 | |
226 #elif defined(USE_DBUS) | |
227 | |
228 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { | |
229 dbus::Bus::Options options; | |
230 scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options)); | |
231 dbus::ObjectProxy* object_proxy = dbus->GetObjectProxy( | |
232 kServiceName, dbus::ObjectPath(kObjectPath)); | |
233 | |
234 DCHECK(object_proxy); | |
235 | |
236 dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); | |
237 dbus::MessageWriter message_writer(&method_call); | |
238 message_writer.AppendString(kInterfaceName); | |
239 message_writer.AppendString(kPropertyName); | |
240 | |
241 // TODO(k.czech) replace this with asynchronous call | |
242 scoped_ptr<dbus::Response> response( | |
243 object_proxy->CallMethodAndBlock(&method_call, | |
244 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
245 | |
246 if (!response) { | |
247 LOG(ERROR) << "AtSpi: failed to get " << kPropertyName; | |
248 dbus->ShutdownAndBlock(); | |
249 return false; | |
250 } | |
251 | |
252 // TODO(k.czech) handle case for at-spi2-core version 2.2.0/2.2.2 | |
253 // org.a11y.Bus.Enabled returns variant struct with a bool instead of bool | |
254 dbus::MessageReader reader(response.get()); | |
255 if (!reader.PopVariantOfBool(&is_enabled_)) | |
dmazzoni
2015/05/04 15:41:05
Same here, put this in a local variable and return
| |
256 LOG(ERROR) << "AtSpi: unexpected response"; | |
257 | |
258 dbus->ShutdownAndBlock(); | |
259 | |
260 return is_enabled_; | |
dmazzoni
2015/05/04 15:41:05
Return is_enabled, not is_enabled_
| |
261 } | |
262 | |
263 #else | |
264 | |
265 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { | |
266 return false; | |
267 } | |
268 | |
269 #endif | |
270 | |
271 #if defined(USE_GCONF) || defined(USE_DBUS) | |
272 | |
273 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | |
274 if (!is_enabled_) { | |
155 VLOG(1) << "Will not enable ATK accessibility support."; | 275 VLOG(1) << "Will not enable ATK accessibility support."; |
156 return; | 276 return; |
157 } | 277 } |
158 | 278 |
159 VLOG(1) << "Enabling ATK accessibility support."; | 279 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. | 280 // Try to call gnome_accessibility_module_init from libatk-bridge.so. |
172 void (*gnome_accessibility_module_init)(); | 281 if (accessibility_module_init) |
173 if (g_module_symbol(bridge, "gnome_accessibility_module_init", | 282 accessibility_module_init(); |
174 (gpointer *)&gnome_accessibility_module_init)) { | |
175 (*gnome_accessibility_module_init)(); | |
176 } | |
177 } | 283 } |
178 | 284 |
179 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 285 #else |
286 | |
287 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | |
180 } | 288 } |
181 | 289 |
290 #endif | |
291 | |
182 } // namespace ui | 292 } // namespace ui |
OLD | NEW |