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

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

Issue 2709963004: Remove gconf usage from atk_util_auralinux (Closed)
Patch Set: Remove gconf config, move constants to top Created 3 years, 9 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
« no previous file with comments | « ui/accessibility/platform/atk_util_auralinux.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
7 #include <gconf/gconf-client.h>
8 #endif
9 #include <glib-2.0/gmodule.h> 6 #include <glib-2.0/gmodule.h>
10 7
11 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/environment.h"
12 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
13 #include "base/location.h" 11 #include "base/location.h"
14 #include "base/logging.h" 12 #include "base/logging.h"
15 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h"
16 #include "base/task_runner.h" 16 #include "base/task_runner.h"
17 #include "ui/accessibility/platform/atk_util_auralinux.h" 17 #include "ui/accessibility/platform/atk_util_auralinux.h"
18 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" 18 #include "ui/accessibility/platform/ax_platform_node_auralinux.h"
19 19
20 namespace { 20 namespace {
21 21
22 typedef void (*gnome_accessibility_module_init)(); 22 typedef void (*gnome_accessibility_module_init)();
23 23
24 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED";
25 const char kAtkBridgeModule[] = "gail:atk-bridge";
24 const char kAtkBridgePath[] = "gtk-2.0/modules/libatk-bridge.so"; 26 const char kAtkBridgePath[] = "gtk-2.0/modules/libatk-bridge.so";
25 const char kAtkBridgeSymbolName[] = "gnome_accessibility_module_init"; 27 const char kAtkBridgeSymbolName[] = "gnome_accessibility_module_init";
28 const char kGtkModules[] = "GTK_MODULES";
26 29
27 gnome_accessibility_module_init g_accessibility_module_init = nullptr; 30 gnome_accessibility_module_init g_accessibility_module_init = nullptr;
28 31
29 bool AccessibilityModuleInitOnFileThread() { 32 bool AccessibilityModuleInitOnFileThread() {
30 // Try to load libatk-bridge.so. 33 // Try to load libatk-bridge.so.
31 base::FilePath atk_bridge_path(ATK_LIB_DIR); 34 base::FilePath atk_bridge_path(ATK_LIB_DIR);
32 atk_bridge_path = atk_bridge_path.Append(kAtkBridgePath); 35 atk_bridge_path = atk_bridge_path.Append(kAtkBridgePath);
33 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), 36 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(),
34 static_cast<GModuleFlags>(0)); 37 static_cast<GModuleFlags>(0));
35 if (!bridge) { 38 if (!bridge) {
36 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); 39 VLOG(1) << "Unable to open module " << atk_bridge_path.value();
37 return false; 40 return false;
38 } 41 }
39 42
40 if (!g_module_symbol(bridge, kAtkBridgeSymbolName, 43 if (!g_module_symbol(bridge, kAtkBridgeSymbolName,
41 (gpointer *)&g_accessibility_module_init)) { 44 (gpointer *)&g_accessibility_module_init)) {
42 VLOG(1) << "Unable to get symbol pointer from " << atk_bridge_path.value(); 45 VLOG(1) << "Unable to get symbol pointer from " << atk_bridge_path.value();
43 // Just to make sure it's null; 46 // Just to make sure it's null;
44 g_accessibility_module_init = nullptr; 47 g_accessibility_module_init = nullptr;
45 return false; 48 return false;
46 } 49 }
47 50
48 return true; 51 return true;
49 } 52 }
50 53
51 #if defined(USE_GCONF) 54 bool PlatformShouldEnableAccessibility() {
55 std::unique_ptr<base::Environment> env(base::Environment::Create());
56 std::string gtk_modules;
57 if (!env->GetVar(kGtkModules, &gtk_modules))
58 return false;
52 59
53 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; 60 for (const std::string& module :
54 const char kGnomeAccessibilityEnabledKey[] = 61 base::SplitString(gtk_modules, base::kWhitespaceASCII,
55 "/desktop/gnome/interface/accessibility"; 62 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
56 63 if (module == kAtkBridgeModule)
57 bool PlatformShouldEnableAccessibility() { 64 return true;
58 GConfClient* client = gconf_client_get_default();
59 if (!client) {
60 LOG(ERROR) << "gconf_client_get_default failed";
61 return false;
62 } 65 }
63
64 GError* error = nullptr;
65 gboolean value = gconf_client_get_bool(client,
66 kGnomeAccessibilityEnabledKey,
67 &error);
68 g_object_unref(client);
69
70 if (error) {
71 VLOG(1) << "gconf_client_get_bool failed";
72 g_error_free(error);
73 return false;
74 }
75
76 return value;
77 }
78
79 #else // !defined(USE_GCONF)
80
81 bool PlatformShouldEnableAccessibility() {
82 // TODO(iceman): implement this for non-GNOME desktops.
83 return false; 66 return false;
84 } 67 }
85 68
86 #endif // defined(USE_GCONF)
87
88 bool ShouldEnableAccessibility() { 69 bool ShouldEnableAccessibility() {
89 #if defined(USE_GCONF)
90 char* enable_accessibility = getenv(kAccessibilityEnabled); 70 char* enable_accessibility = getenv(kAccessibilityEnabled);
91 if ((enable_accessibility && atoi(enable_accessibility) == 1) || 71 if ((enable_accessibility && atoi(enable_accessibility) == 1) ||
92 PlatformShouldEnableAccessibility()) 72 PlatformShouldEnableAccessibility())
93 return true; 73 return true;
94 #endif // defined(USE_GCONF)
95
96 return false; 74 return false;
97 } 75 }
98 76
99 } // namespace 77 } // namespace
100 78
101 G_BEGIN_DECLS 79 G_BEGIN_DECLS
102 80
103 // 81 //
104 // atk_util_auralinux AtkObject definition and implementation. 82 // atk_util_auralinux AtkObject definition and implementation.
105 // 83 //
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // AtkUtilAuraLinuxClass implementation. 154 // AtkUtilAuraLinuxClass implementation.
177 // 155 //
178 156
179 namespace ui { 157 namespace ui {
180 158
181 // static 159 // static
182 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { 160 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() {
183 return base::Singleton<AtkUtilAuraLinux>::get(); 161 return base::Singleton<AtkUtilAuraLinux>::get();
184 } 162 }
185 163
186 #if defined(USE_GCONF) 164 AtkUtilAuraLinux::AtkUtilAuraLinux() : is_enabled_(false) {}
187
188 AtkUtilAuraLinux::AtkUtilAuraLinux()
189 : is_enabled_(false) {
190 }
191
192 #else
193
194 AtkUtilAuraLinux::AtkUtilAuraLinux() {
195 }
196
197 #endif // defined(USE_GCONF)
198 165
199 void AtkUtilAuraLinux::Initialize( 166 void AtkUtilAuraLinux::Initialize(
200 scoped_refptr<base::TaskRunner> init_task_runner) { 167 scoped_refptr<base::TaskRunner> init_task_runner) {
201 168
202 // Register our util class. 169 // Register our util class.
203 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); 170 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE));
204 171
205 if (!ShouldEnableAccessibility()) 172 if (!ShouldEnableAccessibility())
206 return; 173 return;
207 174
208 init_task_runner->PostTaskAndReply( 175 init_task_runner->PostTaskAndReply(
209 FROM_HERE, 176 FROM_HERE,
210 base::Bind( 177 base::Bind(
211 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, 178 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread,
212 base::Unretained(this)), 179 base::Unretained(this)),
213 base::Bind( 180 base::Bind(
214 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, 181 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread,
215 base::Unretained(this))); 182 base::Unretained(this)));
216 } 183 }
217 184
218 AtkUtilAuraLinux::~AtkUtilAuraLinux() { 185 AtkUtilAuraLinux::~AtkUtilAuraLinux() {
219 } 186 }
220 187
221 #if defined(USE_GCONF)
222
223 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { 188 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() {
224 is_enabled_ = AccessibilityModuleInitOnFileThread(); 189 is_enabled_ = AccessibilityModuleInitOnFileThread();
225 } 190 }
226 191
227 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { 192 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() {
228 if (!is_enabled_) { 193 if (!is_enabled_) {
229 VLOG(1) << "Will not enable ATK accessibility support."; 194 VLOG(1) << "Will not enable ATK accessibility support.";
230 return; 195 return;
231 } 196 }
232 197
233 DCHECK(g_accessibility_module_init); 198 DCHECK(g_accessibility_module_init);
234 g_accessibility_module_init(); 199 g_accessibility_module_init();
235 } 200 }
236 201
237 #else
238
239 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() {
240 }
241
242 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() {
243 }
244
245 #endif // defined(USE_GCONF)
246
247 } // namespace ui 202 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/atk_util_auralinux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698