From 0df21afcdfe1a92f9f56b1fa3b5b226402b0e5bd Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 13 Oct 2016 11:46:55 -0700 Subject: [PATCH] Check harder before enabling Accessibility support --- atom/browser/native_window_views.h | 5 +++++ atom/browser/native_window_views_win.cc | 26 +++++++++++++++++-------- electron.gyp | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 0b4a9245db10..e81f61ca0a93 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -18,6 +18,8 @@ #include "atom/browser/ui/win/message_handler_delegate.h" #include "atom/browser/ui/win/taskbar_host.h" #include "base/win/scoped_gdi_object.h" +#include "ui/base/win/accessibility_misc_utils.h" +#include #endif namespace views { @@ -228,6 +230,9 @@ class NativeWindowViews : public NativeWindow, // In charge of running taskbar related APIs. TaskbarHost taskbar_host_; + // Memoized version of a11y check + bool checked_for_a11y_support_; + // If true we have enabled a11y bool enabled_a11y_support_; diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index bb6d9858f045..b8fc690a30c6 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -92,15 +92,25 @@ bool NativeWindowViews::PreHandleMSG( // accessibility object. case WM_GETOBJECT: { const DWORD obj_id = static_cast(l_param); - if (enabled_a11y_support_) return false; + if (checked_for_a11y_support_) return false; - if (obj_id == OBJID_CLIENT) { - const auto axState = content::BrowserAccessibilityState::GetInstance(); - if (axState && !axState->IsAccessibleBrowser()) { - axState->OnScreenReaderDetected(); - enabled_a11y_support_ = true; - Browser::Get()->OnAccessibilitySupportChanged(); - } + checked_for_a11y_support_ = true; + + if (obj_id != OBJID_CLIENT) { + return false; + } + + UINT screenReader = 0; + SystemParametersInfo(SPI_GETSCREENREADER, 0, &screenReader, 0); + if (!screenReader || !UiaClientsAreListening()) { + return false; + } + + const auto axState = content::BrowserAccessibilityState::GetInstance(); + if (axState && !axState->IsAccessibleBrowser()) { + axState->OnScreenReaderDetected(); + enabled_a11y_support_ = true; + Browser::Get()->OnAccessibilitySupportChanged(); } return false; diff --git a/electron.gyp b/electron.gyp index 821ec27707a4..a186197f4743 100644 --- a/electron.gyp +++ b/electron.gyp @@ -281,6 +281,7 @@ '-lwininet.lib', '-lwinmm.lib', '-lcrypt32.lib', + '-luiautomationcore.lib', ], }, 'dependencies': [