Skip to content

Commit df0d2b8

Browse files
authored
Merge pull request electron#6446 from electron/accessibility-api
Add API for Chrome's accessibility support state
2 parents 21a8a72 + 4e22d5d commit df0d2b8

File tree

9 files changed

+56
-0
lines changed

9 files changed

+56
-0
lines changed

atom/browser/api/atom_api_app.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "base/strings/string_util.h"
3333
#include "brightray/browser/brightray_paths.h"
3434
#include "chrome/common/chrome_paths.h"
35+
#include "content/public/browser/browser_accessibility_state.h"
3536
#include "content/public/browser/client_certificate_delegate.h"
3637
#include "content/public/browser/gpu_data_manager.h"
3738
#include "content/public/browser/render_frame_host.h"
@@ -281,6 +282,10 @@ void App::OnFinishLaunching() {
281282
Emit("ready");
282283
}
283284

285+
void App::OnAccessibilitySupportChanged() {
286+
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
287+
}
288+
284289
#if defined(OS_MACOSX)
285290
void App::OnContinueUserActivity(
286291
bool* prevent_default,
@@ -486,6 +491,11 @@ void App::DisableHardwareAcceleration(mate::Arguments* args) {
486491
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
487492
}
488493

494+
bool App::IsAccessibilitySupportEnabled() {
495+
auto ax_state = content::BrowserAccessibilityState::GetInstance();
496+
return ax_state->IsAccessibleBrowser();
497+
}
498+
489499
#if defined(USE_NSS_CERTS)
490500
void App::ImportCertificate(
491501
const base::DictionaryValue& options,
@@ -578,6 +588,8 @@ void App::BuildPrototype(
578588
.SetMethod("makeSingleInstance", &App::MakeSingleInstance)
579589
.SetMethod("releaseSingleInstance", &App::ReleaseSingleInstance)
580590
.SetMethod("relaunch", &App::Relaunch)
591+
.SetMethod("isAccessibilitySupportEnabled",
592+
&App::IsAccessibilitySupportEnabled)
581593
.SetMethod("disableHardwareAcceleration",
582594
&App::DisableHardwareAcceleration);
583595
}

atom/browser/api/atom_api_app.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class App : public AtomBrowserClient::Delegate,
7272
void OnFinishLaunching() override;
7373
void OnLogin(LoginHandler* login_handler,
7474
const base::DictionaryValue& request_details) override;
75+
void OnAccessibilitySupportChanged() override;
7576
#if defined(OS_MACOSX)
7677
void OnContinueUserActivity(
7778
bool* prevent_default,
@@ -113,6 +114,7 @@ class App : public AtomBrowserClient::Delegate,
113114
void ReleaseSingleInstance();
114115
bool Relaunch(mate::Arguments* args);
115116
void DisableHardwareAcceleration(mate::Arguments* args);
117+
bool IsAccessibilitySupportEnabled();
116118
#if defined(USE_NSS_CERTS)
117119
void ImportCertificate(const base::DictionaryValue& options,
118120
const net::CompletionCallback& callback);

atom/browser/browser.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ void Browser::DidFinishLaunching() {
155155
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
156156
}
157157

158+
void Browser::OnAccessibilitySupportChanged() {
159+
FOR_EACH_OBSERVER(BrowserObserver,
160+
observers_,
161+
OnAccessibilitySupportChanged());
162+
}
163+
158164
void Browser::RequestLogin(
159165
LoginHandler* login_handler,
160166
std::unique_ptr<base::DictionaryValue> request_details) {

atom/browser/browser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class Browser : public WindowListObserver {
185185
void WillFinishLaunching();
186186
void DidFinishLaunching();
187187

188+
void OnAccessibilitySupportChanged();
189+
188190
// Request basic auth login.
189191
void RequestLogin(LoginHandler* login_handler,
190192
std::unique_ptr<base::DictionaryValue> request_details);

atom/browser/browser_observer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class BrowserObserver {
5252
virtual void OnLogin(LoginHandler* login_handler,
5353
const base::DictionaryValue& request_details) {}
5454

55+
// The browser's accessibility suppport has changed.
56+
virtual void OnAccessibilitySupportChanged() {}
57+
5558
#if defined(OS_MACOSX)
5659
// The browser wants to resume a user activity via handoff. (macOS only)
5760
virtual void OnContinueUserActivity(

atom/browser/mac/atom_application.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ - (void)updateAccessibilityEnabled:(BOOL)enabled {
8383
} else {
8484
ax_state->DisableAccessibility();
8585
}
86+
87+
atom::Browser::Get()->OnAccessibilitySupportChanged();
8688
}
8789

8890
@end

atom/browser/native_window_views_win.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by the MIT license that can be
33
// found in the LICENSE file.
44

5+
#include "atom/browser/browser.h"
56
#include "atom/browser/native_window_views.h"
67
#include "content/public/browser/browser_accessibility_state.h"
78

@@ -98,6 +99,7 @@ bool NativeWindowViews::PreHandleMSG(
9899
if (axState && !axState->IsAccessibleBrowser()) {
99100
axState->OnScreenReaderDetected();
100101
enabled_a11y_support_ = true;
102+
Browser::Get()->OnAccessibilitySupportChanged();
101103
}
102104
}
103105

docs/api/app.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,19 @@ app.on('login', (event, webContents, request, authInfo, callback) => {
259259

260260
Emitted when the gpu process crashes.
261261

262+
### Event: 'accessibility-support-changed' _macOS_ _Windows_
263+
264+
Returns:
265+
266+
* `event` Event
267+
* `accessibilitySupportEnabled` Boolean - `true` when Chrome's accessibility
268+
support is enabled, `false` otherwise.
269+
270+
Emitted when Chrome's accessibility support changes. This event fires when
271+
assistive technologies, such as screen readers, are enabled or disabled.
272+
See https://www.chromium.org/developers/design-documents/accessibility for more
273+
details.
274+
262275
## Methods
263276

264277
The `app` object has the following methods:
@@ -625,6 +638,14 @@ Return an Object with the login item settings of the app.
625638

626639
Set the app's login item settings.
627640

641+
### `app.isAccessibilitySupportEnabled()` _macOS_ _Windows_
642+
643+
Returns a `Boolean`, `true` if Chrome's accessibility support is enabled,
644+
`false` otherwise. This API will return `true` if the use of assistive
645+
technologies, such as screen readers, has been detected. See
646+
https://www.chromium.org/developers/design-documents/accessibility for more
647+
details.
648+
628649
### `app.commandLine.appendSwitch(switch[, value])`
629650

630651
Append a switch (with optional `value`) to Chromium's command line.

spec/api-app-spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,10 @@ describe('app module', function () {
339339
})
340340
})
341341
})
342+
343+
describe('isAccessibilitySupportEnabled API', function () {
344+
it('returns whether the Chrome has accessibility APIs enabled', function () {
345+
assert.equal(typeof app.isAccessibilitySupportEnabled(), 'boolean')
346+
})
347+
})
342348
})

0 commit comments

Comments
 (0)