| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 #if defined(USE_GCONF) | 50 #if defined(USE_GCONF) |
| 51 | 51 |
| 52 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; | 52 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; |
| 53 const char kGnomeAccessibilityEnabledKey[] = | 53 const char kGnomeAccessibilityEnabledKey[] = |
| 54 "/desktop/gnome/interface/accessibility"; | 54 "/desktop/gnome/interface/accessibility"; |
| 55 | 55 |
| 56 #endif | 56 bool PlatformShouldEnableAccessibility() { |
| 57 GConfClient* client = gconf_client_get_default(); |
| 58 if (!client) { |
| 59 LOG(ERROR) << "gconf_client_get_default failed"; |
| 60 return false; |
| 61 } |
| 62 |
| 63 GError* error = nullptr; |
| 64 gboolean value = gconf_client_get_bool(client, |
| 65 kGnomeAccessibilityEnabledKey, |
| 66 &error); |
| 67 g_object_unref(client); |
| 68 |
| 69 if (error) { |
| 70 VLOG(1) << "gconf_client_get_bool failed"; |
| 71 g_error_free(error); |
| 72 return false; |
| 73 } |
| 74 |
| 75 return value; |
| 76 } |
| 77 |
| 78 #else // !defined(USE_GCONF) |
| 79 |
| 80 bool PlatformShouldEnableAccessibility() { |
| 81 // TODO(iceman): implement this for non-GNOME desktops. |
| 82 return false; |
| 83 } |
| 84 |
| 85 #endif // defined(USE_GCONF) |
| 86 |
| 87 bool ShouldEnableAccessibility() { |
| 88 char* enable_accessibility = getenv(kAccessibilityEnabled); |
| 89 if ((enable_accessibility && atoi(enable_accessibility) == 1) || |
| 90 PlatformShouldEnableAccessibility()) |
| 91 return true; |
| 92 |
| 93 return false; |
| 94 } |
| 57 | 95 |
| 58 } // namespace | 96 } // namespace |
| 59 | 97 |
| 60 G_BEGIN_DECLS | 98 G_BEGIN_DECLS |
| 61 | 99 |
| 62 // | 100 // |
| 63 // atk_util_auralinux AtkObject definition and implementation. | 101 // atk_util_auralinux AtkObject definition and implementation. |
| 64 // | 102 // |
| 65 | 103 |
| 66 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 104 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 192 } |
| 155 | 193 |
| 156 #endif // defined(USE_GCONF) | 194 #endif // defined(USE_GCONF) |
| 157 | 195 |
| 158 void AtkUtilAuraLinux::Initialize( | 196 void AtkUtilAuraLinux::Initialize( |
| 159 scoped_refptr<base::TaskRunner> init_task_runner) { | 197 scoped_refptr<base::TaskRunner> init_task_runner) { |
| 160 | 198 |
| 161 // Register our util class. | 199 // Register our util class. |
| 162 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); | 200 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
| 163 | 201 |
| 202 if (!ShouldEnableAccessibility()) |
| 203 return; |
| 204 |
| 164 init_task_runner->PostTaskAndReply( | 205 init_task_runner->PostTaskAndReply( |
| 165 FROM_HERE, | 206 FROM_HERE, |
| 166 base::Bind( | 207 base::Bind( |
| 167 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, | 208 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, |
| 168 base::Unretained(this)), | 209 base::Unretained(this)), |
| 169 base::Bind( | 210 base::Bind( |
| 170 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, | 211 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, |
| 171 base::Unretained(this))); | 212 base::Unretained(this))); |
| 172 } | 213 } |
| 173 | 214 |
| 174 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 215 AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| 175 } | 216 } |
| 176 | 217 |
| 177 #if defined(USE_GCONF) | 218 #if defined(USE_GCONF) |
| 178 | 219 |
| 179 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { | 220 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
| 180 char* enable_accessibility = getenv(kAccessibilityEnabled); | 221 is_enabled_ = AccessibilityModuleInitOnFileThread(); |
| 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 } | 222 } |
| 208 | 223 |
| 209 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | 224 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| 210 if (!is_enabled_) { | 225 if (!is_enabled_) { |
| 211 VLOG(1) << "Will not enable ATK accessibility support."; | 226 VLOG(1) << "Will not enable ATK accessibility support."; |
| 212 return; | 227 return; |
| 213 } | 228 } |
| 214 | 229 |
| 215 DCHECK(g_accessibility_module_init); | 230 DCHECK(g_accessibility_module_init); |
| 216 g_accessibility_module_init(); | 231 g_accessibility_module_init(); |
| 217 } | 232 } |
| 218 | 233 |
| 219 #else | 234 #else |
| 220 | 235 |
| 221 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { | 236 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
| 222 } | 237 } |
| 223 | 238 |
| 224 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | 239 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| 225 } | 240 } |
| 226 | 241 |
| 227 #endif // defined(USE_GCONF) | 242 #endif // defined(USE_GCONF) |
| 228 | 243 |
| 229 } // namespace ui | 244 } // namespace ui |
| OLD | NEW |