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 #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" |
13 #include "base/location.h" | |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
14 #include "ui/accessibility/platform/atk_util_auralinux.h" | 16 #include "ui/accessibility/platform/atk_util_auralinux.h" |
15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" | 17 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
21 typedef void (*gnome_accessibility_module_init)(); | |
22 | |
23 const char kAtkBridgePath[] = "gtk-2.0/modules/libatk-bridge.so"; | |
24 const char kAtkBridgeSymbolName[] = "gnome_accessibility_module_init"; | |
25 | |
26 gnome_accessibility_module_init g_accessibility_module_init = nullptr; | |
27 | |
28 bool AccessibilityModuleInitOnFileThread() { | |
29 // Try to load libatk-bridge.so. | |
30 base::FilePath atk_bridge_path(ATK_LIB_DIR); | |
31 atk_bridge_path = atk_bridge_path.Append(kAtkBridgePath); | |
32 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), | |
33 static_cast<GModuleFlags>(0)); | |
34 if (!bridge) { | |
35 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); | |
36 return false; | |
37 } | |
38 | |
39 if (!g_module_symbol(bridge, kAtkBridgeSymbolName, | |
40 (gpointer *)&g_accessibility_module_init)) { | |
dmazzoni
2016/01/27 16:28:36
nit: either indent this 4 spaces from the previous
| |
41 VLOG(1) << "Unable to get symbol pointer from " << atk_bridge_path.value(); | |
42 // Just to make sure it's null; | |
43 g_accessibility_module_init = nullptr; | |
44 return false; | |
45 } | |
46 | |
47 return true; | |
48 } | |
49 | |
19 #if defined(USE_GCONF) | 50 #if defined(USE_GCONF) |
20 | 51 |
52 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; | |
21 const char kGnomeAccessibilityEnabledKey[] = | 53 const char kGnomeAccessibilityEnabledKey[] = |
22 "/desktop/gnome/interface/accessibility"; | 54 "/desktop/gnome/interface/accessibility"; |
23 | 55 |
24 bool ShouldEnableAccessibility() { | 56 #endif |
25 GConfClient* client = gconf_client_get_default(); | |
26 if (!client) { | |
27 LOG(ERROR) << "gconf_client_get_default failed"; | |
28 return false; | |
29 } | |
30 | |
31 GError* error = nullptr; | |
32 gboolean value = gconf_client_get_bool(client, | |
33 kGnomeAccessibilityEnabledKey, | |
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 } | |
41 | |
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) | |
54 | 57 |
55 } // namespace | 58 } // namespace |
56 | 59 |
57 G_BEGIN_DECLS | 60 G_BEGIN_DECLS |
58 | 61 |
59 // | 62 // |
60 // atk_util_auralinux AtkObject definition and implementation. | 63 // atk_util_auralinux AtkObject definition and implementation. |
61 // | 64 // |
62 | 65 |
63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 66 #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. | 135 // AtkUtilAuraLinuxClass implementation. |
133 // | 136 // |
134 | 137 |
135 namespace ui { | 138 namespace ui { |
136 | 139 |
137 // static | 140 // static |
138 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { | 141 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
139 return base::Singleton<AtkUtilAuraLinux>::get(); | 142 return base::Singleton<AtkUtilAuraLinux>::get(); |
140 } | 143 } |
141 | 144 |
145 #if defined(USE_GCONF) | |
146 | |
147 AtkUtilAuraLinux::AtkUtilAuraLinux() | |
148 : is_enabled_(false) { | |
149 } | |
150 | |
151 #else | |
152 | |
142 AtkUtilAuraLinux::AtkUtilAuraLinux() { | 153 AtkUtilAuraLinux::AtkUtilAuraLinux() { |
143 } | 154 } |
144 | 155 |
156 #endif // defined(USE_GCONF) | |
157 | |
145 void AtkUtilAuraLinux::Initialize( | 158 void AtkUtilAuraLinux::Initialize( |
146 scoped_refptr<base::TaskRunner> /* init_task_runner */) { | 159 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 | 160 |
151 // Register our util class. | 161 // Register our util class. |
152 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); | 162 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
153 | 163 |
154 if (!ShouldEnableAccessibility()) { | 164 init_task_runner->PostTaskAndReply( |
155 VLOG(1) << "Will not enable ATK accessibility support."; | 165 FROM_HERE, |
156 return; | 166 base::Bind( |
157 } | 167 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, |
158 | 168 base::Unretained(this)), |
159 VLOG(1) << "Enabling ATK accessibility support."; | 169 base::Bind( |
160 | 170 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, |
161 // Try to load libatk-bridge.so. | 171 base::Unretained(this))); |
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 } | |
177 } | 172 } |
178 | 173 |
179 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 174 AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
180 } | 175 } |
181 | 176 |
177 #if defined(USE_GCONF) | |
178 | |
179 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { | |
180 char* enable_accessibility = getenv(kAccessibilityEnabled); | |
181 if ((enable_accessibility && atoi(enable_accessibility) == 1) || | |
182 CheckPlatformAccessibilitySupportOnFileThread()) | |
183 is_enabled_ = AccessibilityModuleInitOnFileThread(); | |
184 } | |
185 | |
186 bool AtkUtilAuraLinux::CheckPlatformAccessibilitySupportOnFileThread() { | |
187 GConfClient* client = gconf_client_get_default(); | |
188 if (!client) { | |
189 LOG(ERROR) << "gconf_client_get_default failed"; | |
190 return false; | |
191 } | |
192 | |
193 GError* error = nullptr; | |
194 bool is_enabled = gconf_client_get_bool(client, | |
195 kGnomeAccessibilityEnabledKey, | |
196 &error); | |
197 | |
198 g_object_unref(client); | |
199 | |
200 if (error) { | |
201 VLOG(1) << "gconf_client_get_bool failed"; | |
202 g_error_free(error); | |
203 return false; | |
204 } | |
205 | |
206 return is_enabled; | |
207 } | |
208 | |
209 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | |
210 if (!is_enabled_) { | |
211 VLOG(1) << "Will not enable ATK accessibility support."; | |
212 return; | |
213 } | |
214 | |
215 DCHECK(g_accessibility_module_init); | |
216 g_accessibility_module_init(); | |
217 } | |
218 | |
219 #else | |
220 | |
221 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { | |
222 } | |
223 | |
224 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | |
225 } | |
226 | |
227 #endif // defined(USE_GCONF) | |
228 | |
182 } // namespace ui | 229 } // namespace ui |
OLD | NEW |