Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: ui/accessibility/platform/atk_util_auralinux.cc

Issue 1028553003: Linux Aura accessibility is enabled only on GNOME desktops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create a separate thread to run dbus callings Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #endif 8 #endif
9 #include <glib-2.0/gmodule.h> 9 #include <glib-2.0/gmodule.h>
10 10
11 #include "base/bind.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/threading/thread.h"
18 #include "dbus/bus.h"
19 #include "dbus/message.h"
20 #include "dbus/object_path.h"
21 #include "dbus/object_proxy.h"
14 #include "ui/accessibility/platform/atk_util_auralinux.h" 22 #include "ui/accessibility/platform/atk_util_auralinux.h"
15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" 23 #include "ui/accessibility/platform/ax_platform_node_auralinux.h"
16 24
17 namespace { 25 namespace {
18 26
19 #if defined(USE_GCONF) 27 #if defined(USE_GCONF)
20 28
21 const char kGnomeAccessibilityEnabledKey[] = 29 const char kGnomeAccessibilityEnabledKey[] =
22 "/desktop/gnome/interface/accessibility"; 30 "/desktop/gnome/interface/accessibility";
23 31
24 bool ShouldEnableAccessibility() { 32 bool CheckGnomeAccessibilityKey() {
25 GConfClient* client = gconf_client_get_default(); 33 GConfClient* client = gconf_client_get_default();
26 if (!client) { 34 if (!client) {
27 LOG(ERROR) << "gconf_client_get_default failed"; 35 LOG(ERROR) << "gconf_client_get_default failed";
28 return false; 36 return false;
29 } 37 }
30 38
31 GError* error = nullptr; 39 GError* error = nullptr;
32 gboolean value = gconf_client_get_bool(client, 40 gboolean value = gconf_client_get_bool(client,
33 kGnomeAccessibilityEnabledKey, 41 kGnomeAccessibilityEnabledKey,
34 &error); 42 &error);
35 if (error) { 43 if (error) {
36 VLOG(1) << "gconf_client_get_bool failed"; 44 VLOG(1) << "gconf_client_get_bool failed";
37 g_error_free(error); 45 g_error_free(error);
38 g_object_unref(client); 46 g_object_unref(client);
39 return false; 47 return false;
40 } 48 }
41 49
42 g_object_unref(client); 50 g_object_unref(client);
43 return value; 51 return value;
44 } 52 }
45 53
46 #else // !defined(USE_GCONF) 54 #else // !defined(USE_GCONF)
47 55
48 bool ShouldEnableAccessibility() { 56 const char kServiceName[] = "org.a11y.Bus";
49 // TODO(k.czech): implement this for non-GNOME desktops. 57 const char kObjectPath[] = "/org/a11y/bus";
50 return false; 58 const char kInterfaceName[] = "org.a11y.Status";
59 const char kPropertyName[] = "IsEnabled";
60
61 #endif // defined(USE_GCONF)
62
63 void accessibilityModuleInit() {
64 // Try to load libatk-bridge.so.
65 base::FilePath atk_bridge_path(ATK_LIB_DIR);
66 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so");
67 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(),
68 static_cast<GModuleFlags>(0));
69 if (!bridge) {
70 VLOG(1) << "Unable to open module " << atk_bridge_path.value();
71 return;
72 }
73
74 // Try to call gnome_accessibility_module_init from libatk-bridge.so.
75 void (*gnome_accessibility_module_init)();
76 if (g_module_symbol(bridge, "gnome_accessibility_module_init",
77 (gpointer *)&gnome_accessibility_module_init)) {
78 (*gnome_accessibility_module_init)();
79 }
51 } 80 }
52 81
53 #endif // defined(USE_GCONF)
54
55 } // namespace 82 } // namespace
56 83
57 G_BEGIN_DECLS 84 G_BEGIN_DECLS
58 85
59 // 86 //
60 // atk_util_auralinux AtkObject definition and implementation. 87 // atk_util_auralinux AtkObject definition and implementation.
61 // 88 //
62 89
63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) 90 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type())
64 #define ATK_UTIL_AURALINUX(obj) \ 91 #define ATK_UTIL_AURALINUX(obj) \
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 namespace ui { 162 namespace ui {
136 163
137 // static 164 // static
138 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { 165 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() {
139 return Singleton<AtkUtilAuraLinux>::get(); 166 return Singleton<AtkUtilAuraLinux>::get();
140 } 167 }
141 168
142 AtkUtilAuraLinux::AtkUtilAuraLinux() { 169 AtkUtilAuraLinux::AtkUtilAuraLinux() {
143 // Register our util class. 170 // Register our util class.
144 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); 171 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE));
145 172 ShouldAccessibilityBeEnabled();
dmazzoni 2015/04/15 16:48:35 I'd rename this to CheckIfAccessibilityIsEnabled s
146 if (!ShouldEnableAccessibility()) {
147 VLOG(1) << "Will not enable ATK accessibility support.";
148 return;
149 }
150
151 VLOG(1) << "Enabling ATK accessibility support.";
152
153 // Try to load libatk-bridge.so.
154 base::FilePath atk_bridge_path(ATK_LIB_DIR);
155 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so");
156 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(),
157 static_cast<GModuleFlags>(0));
158 if (!bridge) {
159 VLOG(1) << "Unable to open module " << atk_bridge_path.value();
160 return;
161 }
162
163 // Try to call gnome_accessibility_module_init from libatk-bridge.so.
164 void (*gnome_accessibility_module_init)();
165 if (g_module_symbol(bridge, "gnome_accessibility_module_init",
166 (gpointer *)&gnome_accessibility_module_init)) {
167 (*gnome_accessibility_module_init)();
168 }
169 } 173 }
170 174
171 AtkUtilAuraLinux::~AtkUtilAuraLinux() { 175 AtkUtilAuraLinux::~AtkUtilAuraLinux() {
172 } 176 }
173 177
178 void AtkUtilAuraLinux::ShouldAccessibilityBeEnabled() {
179 #if defined(USE_GCONF)
180 if (CheckGnomeAccessibilityKey()) {
dmazzoni 2015/04/15 16:48:35 I think we should run this in a separate thread to
181 VLOG(1) << "Will not enable ATK accessibility support."
182 return;
183 }
184
185 VLOG(1) << "Enabling ATK accessibility support.";
186 accessibilityModuleInit();
187 #else
dmazzoni 2015/04/15 16:48:35 Should this check USE_DBUS like the gyp file does?
188 dbusThread_.reset(new base::Thread("AtSpi D-Bus Thread"));
189 base::Thread::Options threadOptions(base::MessageLoop::Type::TYPE_IO, 0);
190 dbusThread_->StartWithOptions(threadOptions);
191 dbusThread_->task_runner()->PostTask(
192 FROM_HERE,
193 base::Bind(&AtkUtilAuraLinux::CheckAtSpiIsEnabledProperty,
194 base::Unretained(this)));
195 #endif
196 }
197
198 void AtkUtilAuraLinux::CheckAtSpiIsEnabledProperty() {
199 DCHECK(dbusThread_->task_runner()->RunsTasksOnCurrentThread());
200
201 dbus::Bus::Options options;
202 options.connection_type = dbus::Bus::PRIVATE;
203 options.dbus_task_runner = dbusThread_->task_runner();
204
205 scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options));
206 dbus::ObjectProxy* objectProxy = dbus->GetObjectProxy(
207 kServiceName, dbus::ObjectPath(kObjectPath));
dmazzoni 2015/04/15 16:48:35 nit: indent 4 spaces for line continuation
208
209 if (!objectProxy) {
210 LOG(ERROR) << "Does not support " << kServiceName << " over DBUS";
211 return;
212 }
213
214 dbus::MethodCall methodCall(DBUS_INTERFACE_PROPERTIES, "Get");
215 dbus::MessageWriter messageWriter(&methodCall);
216 messageWriter.AppendString(kInterfaceName);
217 messageWriter.AppendString(kPropertyName);
218
219 scoped_ptr<dbus::Response> response(
220 objectProxy->CallMethodAndBlock(&methodCall,
dmazzoni 2015/04/15 16:48:35 nit: same (4 spaces)
221 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
222
223 if (!response) {
224 LOG(ERROR) << "AtSpi: failed to get " << kPropertyName;
225 return;
226 }
227
228 dbus::MessageReader reader(response.get());
229 bool IsEnabled = false;
230 if (!reader.PopVariantOfBool(&IsEnabled)) {
231 LOG(ERROR) << "AtSpi: unexpected response";
232 return;
233 }
234
235 if (!IsEnabled) {
236 VLOG(1) << "Will not enable ATK accessibility support.";
237 return;
238 }
239
240 accessibilityModuleInit();
241 dbus->ShutdownAndBlock();
242 }
243
174 } // namespace ui 244 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698