| 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 bool PlatformShouldEnableAccessibility() { | 56 #endif |
| 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 } | |
| 95 | 57 |
| 96 } // namespace | 58 } // namespace |
| 97 | 59 |
| 98 G_BEGIN_DECLS | 60 G_BEGIN_DECLS |
| 99 | 61 |
| 100 // | 62 // |
| 101 // atk_util_auralinux AtkObject definition and implementation. | 63 // atk_util_auralinux AtkObject definition and implementation. |
| 102 // | 64 // |
| 103 | 65 |
| 104 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 66 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 154 } |
| 193 | 155 |
| 194 #endif // defined(USE_GCONF) | 156 #endif // defined(USE_GCONF) |
| 195 | 157 |
| 196 void AtkUtilAuraLinux::Initialize( | 158 void AtkUtilAuraLinux::Initialize( |
| 197 scoped_refptr<base::TaskRunner> init_task_runner) { | 159 scoped_refptr<base::TaskRunner> init_task_runner) { |
| 198 | 160 |
| 199 // Register our util class. | 161 // Register our util class. |
| 200 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)); |
| 201 | 163 |
| 202 if (!ShouldEnableAccessibility()) | |
| 203 return; | |
| 204 | |
| 205 init_task_runner->PostTaskAndReply( | 164 init_task_runner->PostTaskAndReply( |
| 206 FROM_HERE, | 165 FROM_HERE, |
| 207 base::Bind( | 166 base::Bind( |
| 208 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, | 167 &AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread, |
| 209 base::Unretained(this)), | 168 base::Unretained(this)), |
| 210 base::Bind( | 169 base::Bind( |
| 211 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, | 170 &AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread, |
| 212 base::Unretained(this))); | 171 base::Unretained(this))); |
| 213 } | 172 } |
| 214 | 173 |
| 215 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 174 AtkUtilAuraLinux::~AtkUtilAuraLinux() { |
| 216 } | 175 } |
| 217 | 176 |
| 218 #if defined(USE_GCONF) | 177 #if defined(USE_GCONF) |
| 219 | 178 |
| 220 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { | 179 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
| 221 is_enabled_ = AccessibilityModuleInitOnFileThread(); | 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; |
| 222 } | 207 } |
| 223 | 208 |
| 224 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | 209 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| 225 if (!is_enabled_) { | 210 if (!is_enabled_) { |
| 226 VLOG(1) << "Will not enable ATK accessibility support."; | 211 VLOG(1) << "Will not enable ATK accessibility support."; |
| 227 return; | 212 return; |
| 228 } | 213 } |
| 229 | 214 |
| 230 DCHECK(g_accessibility_module_init); | 215 DCHECK(g_accessibility_module_init); |
| 231 g_accessibility_module_init(); | 216 g_accessibility_module_init(); |
| 232 } | 217 } |
| 233 | 218 |
| 234 #else | 219 #else |
| 235 | 220 |
| 236 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { | 221 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabledOnFileThread() { |
| 237 } | 222 } |
| 238 | 223 |
| 239 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { | 224 void AtkUtilAuraLinux::FinishAccessibilityInitOnUIThread() { |
| 240 } | 225 } |
| 241 | 226 |
| 242 #endif // defined(USE_GCONF) | 227 #endif // defined(USE_GCONF) |
| 243 | 228 |
| 244 } // namespace ui | 229 } // namespace ui |
| OLD | NEW |