Chromium Code Reviews| 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 #elif defined(USE_DBUS) | |
| 9 #include "dbus/bus.h" | |
| 10 #include "dbus/message.h" | |
| 11 #include "dbus/object_path.h" | |
| 12 #include "dbus/object_proxy.h" | |
| 8 #endif | 13 #endif |
| 9 #include <glib-2.0/gmodule.h> | 14 #include <glib-2.0/gmodule.h> |
| 10 | 15 |
| 16 #include "base/bind.h" | |
| 11 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 18 #include "base/logging.h" |
| 13 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
| 20 #include "base/message_loop/message_loop.h" | |
| 21 #include "base/message_loop/message_loop_proxy.h" | |
| 22 #include "base/threading/thread.h" | |
| 14 #include "ui/accessibility/platform/atk_util_auralinux.h" | 23 #include "ui/accessibility/platform/atk_util_auralinux.h" |
| 15 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" | 24 #include "ui/accessibility/platform/ax_platform_node_auralinux.h" |
| 16 | 25 |
| 17 namespace { | 26 namespace { |
| 18 | 27 |
| 28 const char kAccessibilityEnabled[] = "ACCESSIBILITY_ENABLED"; | |
| 29 | |
| 19 #if defined(USE_GCONF) | 30 #if defined(USE_GCONF) |
| 20 | 31 |
| 21 const char kGnomeAccessibilityEnabledKey[] = | 32 const char kGnomeAccessibilityEnabledKey[] = |
| 22 "/desktop/gnome/interface/accessibility"; | 33 "/desktop/gnome/interface/accessibility"; |
| 23 | 34 |
| 24 bool ShouldEnableAccessibility() { | 35 #elif defined(USE_DBUS) |
| 25 GConfClient* client = gconf_client_get_default(); | 36 |
| 26 if (!client) { | 37 const char kServiceName[] = "org.a11y.Bus"; |
| 27 LOG(ERROR) << "gconf_client_get_default failed"; | 38 const char kObjectPath[] = "/org/a11y/bus"; |
| 28 return false; | 39 const char kInterfaceName[] = "org.a11y.Status"; |
| 40 const char kPropertyName[] = "IsEnabled"; | |
| 41 | |
| 42 #endif | |
| 43 | |
| 44 void AccessibilityModuleInit() { | |
| 45 // Try to load libatk-bridge.so. | |
| 46 base::FilePath atk_bridge_path(ATK_LIB_DIR); | |
| 47 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so"); | |
| 48 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), | |
| 49 static_cast<GModuleFlags>(0)); | |
| 50 if (!bridge) { | |
| 51 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); | |
| 52 return; | |
| 29 } | 53 } |
| 30 | 54 |
| 31 GError* error = nullptr; | 55 // Try to call gnome_accessibility_module_init from libatk-bridge.so. |
| 32 gboolean value = gconf_client_get_bool(client, | 56 void (*gnome_accessibility_module_init)(); |
| 33 kGnomeAccessibilityEnabledKey, | 57 if (g_module_symbol(bridge, "gnome_accessibility_module_init", |
| 34 &error); | 58 (gpointer *)&gnome_accessibility_module_init)) { |
| 35 if (error) { | 59 (*gnome_accessibility_module_init)(); |
| 36 VLOG(1) << "gconf_client_get_bool failed"; | |
| 37 g_error_free(error); | |
| 38 g_object_unref(client); | |
| 39 return false; | |
| 40 } | 60 } |
| 41 | |
| 42 g_object_unref(client); | |
| 43 return value; | |
| 44 } | 61 } |
| 45 | 62 |
| 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 | |
| 55 } // namespace | 63 } // namespace |
| 56 | 64 |
| 57 G_BEGIN_DECLS | 65 G_BEGIN_DECLS |
| 58 | 66 |
| 59 // | 67 // |
| 60 // atk_util_auralinux AtkObject definition and implementation. | 68 // atk_util_auralinux AtkObject definition and implementation. |
| 61 // | 69 // |
| 62 | 70 |
| 63 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) | 71 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type()) |
| 64 #define ATK_UTIL_AURALINUX(obj) \ | 72 #define ATK_UTIL_AURALINUX(obj) \ |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // AtkUtilAuraLinuxClass implementation. | 140 // AtkUtilAuraLinuxClass implementation. |
| 133 // | 141 // |
| 134 | 142 |
| 135 namespace ui { | 143 namespace ui { |
| 136 | 144 |
| 137 // static | 145 // static |
| 138 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { | 146 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() { |
| 139 return Singleton<AtkUtilAuraLinux>::get(); | 147 return Singleton<AtkUtilAuraLinux>::get(); |
| 140 } | 148 } |
| 141 | 149 |
| 142 AtkUtilAuraLinux::AtkUtilAuraLinux() { | 150 AtkUtilAuraLinux::AtkUtilAuraLinux() { |
|
dmazzoni
2015/04/21 22:32:42
I would initialize is_enabled_ to false here to be
| |
| 143 // Register our util class. | 151 // Register our util class. |
| 144 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); | 152 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE)); |
| 145 | 153 |
| 146 if (!ShouldEnableAccessibility()) { | 154 char* enableAccessibility = getenv(kAccessibilityEnabled); |
|
dmazzoni
2015/04/21 22:32:42
enable_accessibility
| |
| 155 if (enableAccessibility && atoi(enableAccessibility) == 1) { | |
| 156 AccessibilityModuleInit(); | |
| 157 return; | |
| 158 } | |
| 159 | |
| 160 CheckIfAccessibilityIsEnabled(); | |
| 161 } | |
| 162 | |
| 163 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | |
| 164 } | |
| 165 | |
| 166 #if defined(USE_GCONF) || defined(USE_DBUS) | |
| 167 | |
| 168 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabled() { | |
| 169 is_enabled_ = false; | |
| 170 | |
| 171 accessibility_init_thread_.reset( | |
| 172 new base::Thread("Accessibility Init Thread")); | |
| 173 base::Thread::Options thread_options(base::MessageLoop::Type::TYPE_IO, 0); | |
| 174 accessibility_init_thread_->StartWithOptions(thread_options); | |
| 175 accessibility_init_thread_->task_runner()->PostTaskAndReply( | |
| 176 FROM_HERE, | |
| 177 base::Bind(&AtkUtilAuraLinux::CheckPlatformAccessibilitySupport, | |
| 178 base::Unretained(this)), | |
| 179 base::Bind(&AtkUtilAuraLinux::OnStopAccessibilityThread, | |
| 180 base::Unretained(this))); | |
| 181 } | |
| 182 | |
| 183 void AtkUtilAuraLinux::OnStopAccessibilityThread() { | |
| 184 accessibility_init_thread_.reset(); | |
| 185 if (!is_enabled_) { | |
| 147 VLOG(1) << "Will not enable ATK accessibility support."; | 186 VLOG(1) << "Will not enable ATK accessibility support."; |
| 148 return; | 187 return; |
| 149 } | 188 } |
| 150 | 189 |
| 151 VLOG(1) << "Enabling ATK accessibility support."; | 190 VLOG(1) << "Enabling ATK accessibility support."; |
| 191 AccessibilityModuleInit(); | |
| 192 } | |
| 152 | 193 |
| 153 // Try to load libatk-bridge.so. | 194 #else |
| 154 base::FilePath atk_bridge_path(ATK_LIB_DIR); | 195 |
| 155 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so"); | 196 void AtkUtilAuraLinux::CheckIfAccessibilityIsEnabled() { |
| 156 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(), | 197 } |
| 157 static_cast<GModuleFlags>(0)); | 198 |
| 158 if (!bridge) { | 199 void AtkUtilAuraLinux::OnStopAccessibilityThread() { |
| 159 VLOG(1) << "Unable to open module " << atk_bridge_path.value(); | 200 } |
| 201 | |
| 202 #endif | |
| 203 | |
| 204 #if defined(USE_GCONF) | |
| 205 void AtkUtilAuraLinux::CheckPlatformAccessibilitySupport() { | |
| 206 DCHECK(accessibility_init_thread_->task_runner()->RunsTasksOnCurrentThread()); | |
| 207 | |
| 208 GConfClient* client = gconf_client_get_default(); | |
| 209 if (!client) { | |
| 210 LOG(ERROR) << "gconf_client_get_default failed"; | |
| 160 return; | 211 return; |
| 161 } | 212 } |
| 162 | 213 |
| 163 // Try to call gnome_accessibility_module_init from libatk-bridge.so. | 214 GError* error = nullptr; |
| 164 void (*gnome_accessibility_module_init)(); | 215 is_enabled_ = gconf_client_get_bool(client, |
| 165 if (g_module_symbol(bridge, "gnome_accessibility_module_init", | 216 kGnomeAccessibilityEnabledKey, |
| 166 (gpointer *)&gnome_accessibility_module_init)) { | 217 &error); |
| 167 (*gnome_accessibility_module_init)(); | 218 |
| 219 g_object_unref(client); | |
| 220 | |
| 221 if (error) { | |
| 222 VLOG(1) << "gconf_client_get_bool failed"; | |
| 223 g_error_free(error); | |
| 224 return; | |
| 168 } | 225 } |
| 169 } | 226 } |
| 170 | 227 |
| 171 AtkUtilAuraLinux::~AtkUtilAuraLinux() { | 228 #elif defined(USE_DBUS) |
| 229 | |
| 230 void AtkUtilAuraLinux::CheckPlatformAccessibilitySupport() { | |
| 231 DCHECK(accessibility_init_thread_->task_runner()->RunsTasksOnCurrentThread()); | |
| 232 | |
| 233 dbus::Bus::Options options; | |
| 234 options.dbus_task_runner = accessibility_init_thread_->task_runner(); | |
| 235 | |
| 236 scoped_refptr<dbus::Bus> dbus(new dbus::Bus(options)); | |
| 237 dbus::ObjectProxy* object_proxy = dbus->GetObjectProxy( | |
| 238 kServiceName, dbus::ObjectPath(kObjectPath)); | |
| 239 | |
| 240 DCHECK(object_proxy); | |
| 241 | |
| 242 dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); | |
| 243 dbus::MessageWriter message_writer(&method_call); | |
| 244 message_writer.AppendString(kInterfaceName); | |
| 245 message_writer.AppendString(kPropertyName); | |
| 246 | |
| 247 scoped_ptr<dbus::Response> response( | |
| 248 object_proxy->CallMethodAndBlock(&method_call, | |
| 249 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 250 | |
| 251 if (!response) { | |
| 252 LOG(ERROR) << "AtSpi: failed to get " << kPropertyName; | |
| 253 dbus->ShutdownAndBlock(); | |
| 254 return; | |
| 255 } | |
| 256 | |
| 257 dbus::MessageReader reader(response.get()); | |
| 258 if (!reader.PopVariantOfBool(&is_enabled_)) | |
| 259 LOG(ERROR) << "AtSpi: unexpected response"; | |
| 260 | |
| 261 dbus->ShutdownAndBlock(); | |
| 172 } | 262 } |
| 173 | 263 |
| 264 #else | |
| 265 | |
| 266 void AtkUtilAuraLinux::CheckPlatformAccessibilitySupport() { | |
| 267 } | |
| 268 | |
| 269 #endif | |
| 270 | |
| 174 } // namespace ui | 271 } // namespace ui |
| OLD | NEW |