File: accessibility_manager.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (805 lines) | stat: -rw-r--r-- 30,305 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
#define CHROME_BROWSER_ASH_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_

#include <map>
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <vector>

#include "ash/public/cpp/window_tree_host_lookup.h"
#include "base/callback_list.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_multi_source_observation.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chrome/browser/ash/accessibility/chromevox_panel.h"
#include "chrome/browser/ash/accessibility/service/accessibility_service_client.h"
#include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/common/extensions/api/accessibility_private.h"
#include "chromeos/ash/components/audio/cras_audio_handler.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "components/soda/soda_installer.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/scoped_accessibility_mode.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/extension_system.h"
#include "facegaze_settings_event_handler.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/accessibility/public/mojom/assistive_technology_type.mojom.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
#include "ui/accessibility/ax_enums.mojom-forward.h"
#include "ui/base/ime/ash/input_method_manager.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/devices/input_device_event_observer.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/wm/core/coordinate_conversion.h"

namespace content {
struct FocusedNodeDetails;
}  // namespace content

namespace gfx {
class Rect;
}  // namespace gfx

namespace ash {

namespace language_packs {
struct PackResult;
}  // namespace language_packs

class AccessibilityDlcInstaller;
class AccessibilityExtensionLoader;
class Dictation;
class SelectToSpeakEventHandlerDelegateImpl;
enum class SelectToSpeakState;
enum class SelectToSpeakPanelAction;
enum class Sound;
struct AccessibilityFocusRingInfo;
class AccessibilityServiceClient;

enum class AccessibilityNotificationType {
  kManagerShutdown,
  kToggleHighContrastMode,
  kToggleLargeCursor,
  kToggleLiveCaption,
  kToggleStickyKeys,
  kToggleScreenMagnifier,
  kToggleSpokenFeedback,
  kToggleSelectToSpeak,
  kToggleSwitchAccess,
  kToggleVirtualKeyboard,
  kToggleMonoAudio,
  kToggleCaretHighlight,
  kToggleCursorHighlight,
  kToggleFocusHighlight,
  kToggleDictation,
  kToggleDockedMagnifier,
};

struct AccessibilityStatusEventDetails {
  AccessibilityStatusEventDetails(
      AccessibilityNotificationType notification_type,
      bool enabled);

  AccessibilityNotificationType notification_type;
  bool enabled;
};

struct FaceGazeGestureInfo {
  std::string gesture;
  int confidence;
};

using AccessibilityStatusCallbackList =
    base::RepeatingCallbackList<void(const AccessibilityStatusEventDetails&)>;
using AccessibilityStatusCallback =
    AccessibilityStatusCallbackList::CallbackType;
using GetTtsDlcContentsCallback =
    base::OnceCallback<void(const std::vector<uint8_t>&,
                            std::optional<std::string>)>;
using InstallFaceGazeAssetsCallback = base::OnceCallback<void(
    std::optional<::extensions::api::accessibility_private::FaceGazeAssets>)>;
using InstallPumpkinCallback = base::OnceCallback<void(
    std::optional<::extensions::api::accessibility_private::PumpkinData>)>;

class AccessibilityPanelWidgetObserver;

enum class PlaySoundOption {
  // The sound is always played.
  kAlways = 0,

  // The sound is played only if spoken feedback is enabled, and
  // --ash-disable-system-sounds is not set.
  kOnlyIfSpokenFeedbackEnabled,
};

// AccessibilityManager changes the statuses of accessibility features
// watching profile notifications and pref-changes.
class AccessibilityManager
    : public session_manager::SessionManagerObserver,
      public extensions::api::braille_display_private::BrailleObserver,
      public extensions::ExtensionRegistryObserver,
      public user_manager::UserManager::UserSessionStateObserver,
      public input_method::InputMethodManager::Observer,
      public CrasAudioHandler::AudioObserver,
      public ProfileObserver,
      public speech::SodaInstaller::Observer,
      public ui::InputDeviceEventObserver {
 public:
  AccessibilityManager(const AccessibilityManager&) = delete;
  AccessibilityManager& operator=(const AccessibilityManager&) = delete;

  // Creates an instance of AccessibilityManager, this should be called once,
  // because only one instance should exist at the same time.
  static void Initialize();
  // Deletes the existing instance of AccessibilityManager.
  static void Shutdown();
  // Returns the existing instance. If there is no instance, returns NULL.
  static AccessibilityManager* Get();

  // Show the accessibility help as a tab in the browser.
  static void ShowAccessibilityHelp();

  // Returns true when the accessibility menu should be shown.
  bool ShouldShowAccessibilityMenu();

  void ShowChromeVoxTutorial();

  // Enables or disables the large cursor.
  void EnableLargeCursor(bool enabled);

  // Returns true if the large cursor is enabled, or false if not.
  bool IsLargeCursorEnabled() const;

  // Enables or disables Live Caption.
  void EnableLiveCaption(bool enabled);

  // Returns true if Live Caption is enabled, or false if not.
  bool IsLiveCaptionEnabled() const;

  // Enables or disable Sticky Keys.
  void EnableStickyKeys(bool enabled);

  // Returns true if the Sticky Keys is enabled, or false if not.
  bool IsStickyKeysEnabled() const;

  // Returns true if the built-in touchpad is disabled, or false if not.
  bool IsTouchpadDisabled() const;

  // Enables or disables spoken feedback. Enabling spoken feedback installs the
  // ChromeVox component extension.
  void EnableSpokenFeedback(bool enabled);

  // Enables spoken feedback. Automatically opens the tutorial once ChromeVox
  // loads.
  void EnableSpokenFeedbackWithTutorial();

  // Returns true if spoken feedback is enabled, or false if not.
  bool IsSpokenFeedbackEnabled() const;

  // Enables or disables the high contrast mode for Chrome.
  void EnableHighContrast(bool enabled);

  // Returns true if High Contrast is enabled, or false if not.
  bool IsHighContrastEnabled() const;

  // Enables or disables autoclick.
  void EnableAutoclick(bool enabled);

  // Returns true if autoclick is enabled.
  bool IsAutoclickEnabled() const;

  // Enables or disables ReducedAnimations.
  void EnableReducedAnimations(bool enabled);

  // Returns true if ReducedAnimations is enabled.
  bool IsReducedAnimationsEnabled() const;

  // Enables or disables the always show scrollbars feature.
  void EnableAlwaysShowScrollbars(bool enabled);

  // Returns true if the always show scrollbars feature is enabled.
  bool IsAlwaysShowScrollbarsEnabled() const;

  // Enables or disables FaceGaze.
  void EnableFaceGaze(bool enabled);

  // Returns true if FaceGaze is enabled.
  bool IsFaceGazeEnabled() const;

  // Called from settings to turn FaceGaze on/off.
  void RequestEnableFaceGaze(bool enable);

  // Called when the FaceGaze disable dialog is accepted/rejected so that the
  // settings UI can be properly updated.
  void SendFaceGazeDisableDialogResultToSettings(bool accepted);

  // Adds the FaceGazeSettingsEventHandler to process events from FaceGaze.
  void AddFaceGazeSettingsEventHandler(FaceGazeSettingsEventHandler* handler);

  // Removes the FaceGazeSettingsEventHandler.
  void RemoveFaceGazeSettingsEventHandler();

  // Toggles whether FaceGaze is sending gesture detection information to
  // settings.
  void ToggleGestureInfoForSettings(bool enabled) const;

  // Sends information about detected facial gestures from FaceGaze to settings.
  void SendGestureInfoToSettings(
      const std::vector<FaceGazeGestureInfo>& gesture_info) const;

  // Requests the Autoclick extension find the bounds of the nearest scrollable
  // ancestor to the point in the screen, as given in screen coordinates.
  void RequestAutoclickScrollableBoundsForPoint(
      const gfx::Point& point_in_screen);

  // Dispatches magnifier bounds update to Magnifier (through Accessibility
  // Common extension).
  void MagnifierBoundsChanged(const gfx::Rect& bounds_in_screen);

  // Enables or disables the virtual keyboard.
  void EnableVirtualKeyboard(bool enabled);
  // Returns true if the virtual keyboard is enabled, otherwise false.
  bool IsVirtualKeyboardEnabled() const;

  // Enables or disables mono audio output.
  void EnableMonoAudio(bool enabled);
  // Returns true if mono audio output is enabled, otherwise false.
  bool IsMonoAudioEnabled() const;

  // Starts or stops darkening the screen.
  void SetDarkenScreen(bool darken);

  // Invoked to enable or disable caret highlighting.
  void SetCaretHighlightEnabled(bool enabled);

  // Returns if caret highlighting is enabled.
  bool IsCaretHighlightEnabled() const;

  // Invoked to enable or disable cursor highlighting.
  void SetCursorHighlightEnabled(bool enabled);

  // Returns if cursor highlighting is enabled.
  bool IsCursorHighlightEnabled() const;

  // Enables or disables dictation.
  void SetDictationEnabled(bool enabled) const;

  // Returns if dictation is enabled.
  bool IsDictationEnabled() const;

  // Invoked to enable or disable focus highlighting.
  void SetFocusHighlightEnabled(bool enabled);

  // Returns if focus highlighting is enabled.
  bool IsFocusHighlightEnabled() const;

  // Enables or disables tap dragging.
  void EnableTapDragging(bool enabled);

  // Returns true if the tap dragging is enabled, or false if not.
  bool IsTapDraggingEnabled() const;

  // Invoked to enable or disable select-to-speak.
  void SetSelectToSpeakEnabled(bool enabled);

  // Returns if select-to-speak is enabled.
  bool IsSelectToSpeakEnabled() const;

  // Requests that the Select-to-Speak extension change its state.
  void RequestSelectToSpeakStateChange();

  // Called when the Select-to-Speak extension state has changed.
  void SetSelectToSpeakState(SelectToSpeakState state);

  // Called when the Select to Speak context menu is clicked from
  // outside Ash browser/webui (for example, on Lacros).
  void OnSelectToSpeakContextMenuClick();

  // Invoked to enable or disable Switch Access.
  void SetSwitchAccessEnabled(bool enabled);

  // Returns if Switch Access is enabled.
  bool IsSwitchAccessEnabled() const;

  // Invoked to enable or disable Color Correction.
  void SetColorCorrectionEnabled(bool enabled);

  // Returns if Color Correction is enabled.
  bool IsColorCorrectionEnabled() const;

  // Returns true if a braille display is connected to the system, otherwise
  // false.
  bool IsBrailleDisplayConnected() const;

  // Returns if Fullscreen Magnifier is enabled.
  bool IsFullscreenMagnifierEnabled() const;

  // Returns if Docked Magnifier is enabled.
  bool IsDockedMagnifierEnabled() const;

  // Returns false if any accessibility settings are enabled that would indicate
  // that a user might have trouble pointing their phone camera at their
  // Chomebook screen in order to scan a QR code.
  bool AllowQRCodeUX() const;

  // user_manager::UserManager::UserSessionStateObserver overrides:
  void ActiveUserChanged(user_manager::User* active_user) override;

  // Initiates play of shutdown sound and returns it's duration.
  base::TimeDelta PlayShutdownSound();

  // Register a callback to be notified when the status of an accessibility
  // option changes.
  [[nodiscard]] base::CallbackListSubscription RegisterCallback(
      const AccessibilityStatusCallback& cb);

  // Notify registered callbacks of a status change in an accessibility setting.
  void NotifyAccessibilityStatusChanged(
      const AccessibilityStatusEventDetails& details);

  // Notify accessibility when locale changes occur.
  void OnLocaleChanged();

  // Whether or not to enable toggling spoken feedback via holding down
  // two fingers on the screen.
  bool ShouldToggleSpokenFeedbackViaTouch();

  // Play tick sound indicating spoken feedback will be toggled after countdown.
  bool PlaySpokenFeedbackToggleCountdown(int tick_count);

  // Update when a view is focused in ARC++.
  void OnViewFocusedInArc(const gfx::Rect& bounds_in_screen);

  // Plays an earcon. Earcons are brief and distinctive sounds that indicate
  // the their mapped event has occurred. The |sound_key| enums can be found in
  // chromeos/ash/components/audio/sounds.h.
  bool PlayEarcon(Sound sound_key, PlaySoundOption option);

  // Forward an accessibility gesture from the touch exploration controller
  // to ChromeVox.
  void HandleAccessibilityGesture(ax::mojom::Gesture gesture,
                                  gfx::PointF location);

  // Update the touch exploration controller so that synthesized
  // touch events are anchored at this point.
  void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);

  // Called by our widget observer when the respective panel is closing.
  void OnChromeVoxPanelDestroying();

  // Profile having the a11y context.
  Profile* profile() { return profile_; }

  // Extension id of extension receiving keyboard events.
  void SetKeyboardListenerExtensionId(const std::string& id,
                                      content::BrowserContext* context);
  const std::string& keyboard_listener_extension_id() {
    return keyboard_listener_extension_id_;
  }

  // Unloads Switch Access.
  void OnSwitchAccessDisabled();

  // Starts or stops dictation (type what you speak).
  bool ToggleDictation();

  // Sets the focus ring with the given ID based on |focus_ring|.
  void SetFocusRing(std::string focus_ring_id,
                    std::unique_ptr<AccessibilityFocusRingInfo> focus_ring);

  // Hides focus ring on screen.
  void HideFocusRing(std::string focus_ring_id);

  // Initializes the focus rings when a feature loads.
  std::set<std::string>& GetFocusRingsForATType(
      ax::mojom::AssistiveTechnologyType at_type);

  // Hides all focus rings for the `at_type`, and removes that `at_type` from
  // |focus_ring_names_for_at_type_|.
  void RemoveFocusRings(ax::mojom::AssistiveTechnologyType at_type);

  // Draws a highlight at the given rects in screen coordinates. Rects may be
  // overlapping and will be merged into one layer. This looks similar to
  // selecting a region with the cursor, except it is drawn in the foreground
  // rather than behind a text layer.
  void SetHighlights(const std::vector<gfx::Rect>& rects_in_screen,
                     SkColor color);

  // Hides highlight on screen.
  void HideHighlights();

  // Sets the bounds used to highlight the text input caret.
  void SetCaretBounds(const gfx::Rect& bounds_in_screen);

  // Gets the startup sound user preference.
  bool GetStartupSoundEnabled() const;

  // Sets the startup sound user preference.
  void SetStartupSoundEnabled(bool value) const;

  // Requests that the system display a preview of the flash notifications
  // feature.
  void PreviewFlashNotification() const;

  // Gets the bluetooth braille display device address for the current user.
  const std::string GetBluetoothBrailleDisplayAddress() const;

  // Sets the bluetooth braille display device address for the current user.
  void UpdateBluetoothBrailleDisplayAddress(const std::string& address);

  // Opens a specified subpage in the ChromeOS Settings app.
  void OpenSettingsSubpage(const std::string& subpage);

  // Create a focus ring ID from the `at_type` and the name of the ring.
  const std::string GetFocusRingId(ax::mojom::AssistiveTechnologyType at_type,
                                   const std::string& focus_ring_name);

  // Sends a panel action event to the Select-to-speak extension.
  void OnSelectToSpeakPanelAction(SelectToSpeakPanelAction action,
                                  double value);

  // Sends the keys currently pressed to the Select-to-speak extension.
  void SendKeysCurrentlyDownToSelectToSpeak(
      const std::set<ui::KeyboardCode>& pressed_keys);

  // Sends a mouse event to the Select-to-speak extension.
  void SendMouseEventToSelectToSpeak(ui::EventType type,
                                     const gfx::PointF& position);

  // Called when Shimless RMA launches to enable accessibility features.
  void OnShimlessRmaLaunched();

  // Generates and fires a synthetic mouse event.
  void SendSyntheticMouseEvent(ui::EventType type,
                               int flags,
                               int changed_button_flags,
                               gfx::Point location_in_screen,
                               bool use_rewriters);

  // Looks up the action key that translates to F7 for caret browsing dialog.
  std::optional<ui::KeyboardCode> GetCaretBrowsingActionKey();

  // SodaInstaller::Observer:
  void OnSodaInstalled(speech::LanguageCode language_code) override;
  void OnSodaInstallError(speech::LanguageCode language_code,
                          speech::SodaInstaller::ErrorCode error_code) override;
  void OnSodaProgress(speech::LanguageCode language_code,
                      int progress) override;

  // ui::InputDeviceEventObserver
  void OnInputDeviceConfigurationChanged(uint8_t input_device_type) override;
  void OnDeviceListsComplete() override;

  // Test helpers:
  void SetProfileForTest(Profile* profile);
  static void SetBrailleControllerForTest(
      extensions::api::braille_display_private::BrailleController* controller);
  void SetScreenDarkenObserverForTest(base::RepeatingCallback<void()> observer);
  void SetOpenSettingsSubpageObserverForTest(
      base::RepeatingCallback<void()> observer);
  void SetFocusRingObserverForTest(base::RepeatingCallback<void()> observer);
  // Runs when highlights are set or updated, but not when they are removed.
  void SetHighlightsObserverForTest(base::RepeatingCallback<void()> observer);
  void SetSelectToSpeakStateObserverForTest(
      base::RepeatingCallback<void()> observer);
  void SetCaretBoundsObserverForTest(
      base::RepeatingCallback<void(const gfx::Rect&)> observer);
  void SetMagnifierBoundsObserverForTest(
      base::RepeatingCallback<void()> observer);
  void SetSwitchAccessKeysForTest(const std::set<int>& action_keys,
                                  const std::string& pref_name);

  const std::set<std::string>& GetAccessibilityCommonEnabledFeaturesForTest() {
    return accessibility_common_enabled_features_;
  }
  bool IsDisableAutoclickDialogVisibleForTest();
  bool is_pumpkin_installed_for_testing() {
    return is_pumpkin_installed_for_testing_;
  }

  // Triggers a request to install the FaceGaze assets DLC. Runs `callback` with
  // the file bytes if the DLC was successfully downloaded. Runs `callback` with
  // an empty object otherwise.
  void InstallFaceGazeAssets(InstallFaceGazeAssetsCallback callback);

  // Triggers a request to install Pumpkin. Runs `callback` with the file bytes
  // if the DLC was successfully downloaded. Runs `callback` with an empty
  // object otherwise.
  void InstallPumpkinForDictation(InstallPumpkinCallback callback);

  // Reads the contents of a DLC file and runs `callback` with the results.
  void GetTtsDlcContents(
      ::extensions::api::accessibility_private::DlcType dlc,
      ::extensions::api::accessibility_private::TtsVariant variant,
      GetTtsDlcContentsCallback callback);
  // A helper for GetTtsDlcContents, which is called after retrieving the state
  // of the target DLC.
  void GetTtsDlcContentsOnPackState(
      ::extensions::api::accessibility_private::TtsVariant variant,
      GetTtsDlcContentsCallback callback,
      const language_packs::PackResult& pack_result);
  void SetDlcPathForTest(base::FilePath path);

  void LoadEnhancedNetworkTtsForTest();

 protected:
  AccessibilityManager();
  ~AccessibilityManager() override;

 private:
  void PostLoadChromeVox();
  void PostUnloadChromeVox();
  void PostSwitchChromeVoxProfile();

  void PostLoadSelectToSpeak();
  void PostUnloadSelectToSpeak();

  void PostUnloadSwitchAccess();

  void PostUnloadAccessibilityCommon();

  void UpdateEnhancedNetworkTts();
  void LoadEnhancedNetworkTts();
  void UnloadEnhancedNetworkTts();
  void PostLoadEnhancedNetworkTts();

  void UpdateAlwaysShowMenuFromPref();
  void OnFaceGazeChanged();
  void OnLargeCursorChanged();
  void OnLiveCaptionChanged();
  void OnStickyKeysChanged();
  void OnSpokenFeedbackChanged();
  void OnHighContrastChanged();
  void OnVirtualKeyboardChanged();
  void OnMonoAudioChanged();
  void OnCaretHighlightChanged();
  void OnCursorHighlightChanged();
  void OnFocusHighlightChanged();
  void OnTapDraggingChanged();
  void OnSelectToSpeakChanged();
  void OnAccessibilityCommonChanged(const std::string& pref_name);
  void OnSwitchAccessChanged();
  void OnReducedAnimationsChanged() const;
  void OnFocusChangedInPage(const content::FocusedNodeDetails& details);
  // |triggered_by_user| is false when Dictation pref is changed at startup,
  // and true if Dictation enabled changed because the user changed their
  // Dictation enabled setting in Chrome OS settings or in the tray quick
  // settings menu.
  void OnDictationChanged(bool triggered_by_user);
  // Called after the Dictation locale pref is changed.
  void OnDictationLocaleChanged();
  // Called after Dictation is enabled by the user to ensure the correct
  // dialogs/downloads occur.
  void MaybeShowNetworkDictationDialogOrInstallSoda(
      const std::string& dictation_locale);

  void CheckBrailleState();
  void ReceiveBrailleDisplayState(
      std::unique_ptr<extensions::api::braille_display_private::DisplayState>
          state);
  void UpdateBrailleImeState();

  void SetProfile(Profile* profile);

  void SetProfileByUser(const user_manager::User* user);

  void UpdateChromeOSAccessibilityHistograms();

  void PlayVolumeAdjustSound();

  // session_manager::SessionManagerObserver:
  void OnLoginOrLockScreenVisible() override;
  void OnSessionStateChanged() override;

  // Sets the current profile using the active profile.
  void SetActiveProfile();

  // extensions::api::braille_display_private::BrailleObserver implementation.
  // Enables spoken feedback if a braille display becomes available.
  void OnBrailleDisplayStateChanged(
      const extensions::api::braille_display_private::DisplayState&
          display_state) override;
  void OnBrailleKeyEvent(
      const extensions::api::braille_display_private::KeyEvent& event) override;

  // ExtensionRegistryObserver implementation.
  void OnExtensionUnloaded(content::BrowserContext* browser_context,
                           const extensions::Extension* extension,
                           extensions::UnloadedExtensionReason reason) override;
  void OnShutdown(extensions::ExtensionRegistry* registry) override;

  // InputMethodManager::Observer
  void InputMethodChanged(input_method::InputMethodManager* manager,
                          Profile* profile,
                          bool show_message) override;

  // CrasAudioHandler::AudioObserver:
  void OnActiveOutputNodeChanged() override;

  // ProfileObserver:
  void OnProfileWillBeDestroyed(Profile* profile) override;

  // Dictation dialog methods.
  bool ShouldShowNetworkDictationDialog(const std::string& locale);
  void ShowNetworkDictationDialog();
  void OnNetworkDictationDialogAccepted();
  void OnNetworkDictationDialogDismissed();

  // SODA-related methods.
  void MaybeInstallSoda(const std::string& locale);
  void OnSodaInstallUpdated(int progress);
  bool ShouldShowSodaSucceededNotificationForDictation();
  bool ShouldShowSodaFailedNotificationForDictation(
      speech::LanguageCode language_code);

  // Updates the Dictation notification according to DLC states. Assumes that
  // it's only called when a Dictation-related DLC has downloaded (or failed to
  // download).
  void UpdateDictationNotification();

  void ShowDictationLanguageUpgradedNudge(const std::string& locale);
  speech::LanguageCode GetDictationLanguageCode();

  void CreateChromeVoxPanel();

  // Methods for managing the FaceGaze assets DLC.
  void OnFaceGazeAssetsInstalled(bool success, const std::string& root_path);
  void OnFaceGazeAssetsFailed(std::string_view error);
  void OnFaceGazeAssetsCreated(
      std::optional<::extensions::api::accessibility_private::FaceGazeAssets>
          assets);

  // Pumpkin-related methods.
  void OnPumpkinInstalled(bool success, const std::string& root_path);
  void OnPumpkinError(std::string_view error);
  void OnPumpkinDataCreated(
      std::optional<::extensions::api::accessibility_private::PumpkinData>
          data);

  void OnAppTerminating();

  void MaybeLogBrailleDisplayConnectedTime();

  bool spoken_feedback_enabled() const { return bool(screen_reader_mode_); }

  // Profile which has the current a11y context.
  raw_ptr<Profile> profile_ = nullptr;
  base::ScopedObservation<Profile, ProfileObserver> profile_observation_{this};

  base::ScopedObservation<session_manager::SessionManager,
                          session_manager::SessionManagerObserver>
      session_observation_{this};

  std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
  std::unique_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;

  // Only used for ChromeVox aka when spoken feedback is enabled.
  std::unique_ptr<content::ScopedAccessibilityMode> screen_reader_mode_;
  bool select_to_speak_enabled_ = false;
  bool switch_access_enabled_ = false;

  bool start_chromevox_with_tutorial_ = false;

  // A set of pref names of enabled accessibility features using the
  // accessibility common extension.
  std::set<std::string> accessibility_common_enabled_features_;

  AccessibilityStatusCallbackList callback_list_;

  std::unique_ptr<AccessibilityServiceClient> accessibility_service_client_;

  bool braille_display_connected_ = false;
  base::Time braille_display_connect_time_;
  base::ScopedObservation<
      extensions::api::braille_display_private::BrailleController,
      extensions::api::braille_display_private::BrailleObserver>
      scoped_braille_observation_{this};

  base::ScopedObservation<speech::SodaInstaller,
                          speech::SodaInstaller::Observer>
      soda_observation_{this};

  bool braille_ime_current_ = false;

  raw_ptr<FaceGazeSettingsEventHandler> facegaze_settings_event_handler_;

  raw_ptr<ChromeVoxPanel> chromevox_panel_ = nullptr;
  std::unique_ptr<AccessibilityPanelWidgetObserver>
      chromevox_panel_widget_observer_;

  std::string keyboard_listener_extension_id_;
  bool keyboard_listener_capture_ = false;

  // Listen to extension unloaded notifications.
  base::ScopedMultiSourceObservation<extensions::ExtensionRegistry,
                                     extensions::ExtensionRegistryObserver>
      extension_registry_observations_{this};

  std::unique_ptr<AccessibilityExtensionLoader>
      accessibility_common_extension_loader_;

  std::unique_ptr<AccessibilityExtensionLoader> chromevox_loader_;

  std::unique_ptr<AccessibilityExtensionLoader> select_to_speak_loader_;

  std::unique_ptr<SelectToSpeakEventHandlerDelegateImpl>
      select_to_speak_event_handler_delegate_;

  std::unique_ptr<AccessibilityExtensionLoader> switch_access_loader_;

  std::unique_ptr<AccessibilityDlcInstaller> dlc_installer_;

  std::map<ax::mojom::AssistiveTechnologyType, std::set<std::string>>
      focus_ring_names_for_at_type_;

  bool app_terminating_ = false;

  bool dictation_active_ = false;
  bool network_dictation_dialog_is_showing_ = false;
  // Whether a SODA download failed notification has been shown. This is
  // reset each time download is initialized because each download attempt
  // could fail separately.
  bool soda_failed_notification_shown_ = false;
  bool dictation_triggered_by_user_ = false;
  bool ignore_dictation_locale_pref_change_ = false;

  base::RepeatingCallback<void()> screen_darken_observer_for_test_;
  base::RepeatingCallback<void()> open_settings_subpage_observer_for_test_;
  base::RepeatingCallback<void()> highlights_observer_for_test_;
  base::RepeatingCallback<void()> select_to_speak_state_observer_for_test_;
  base::RepeatingCallback<void(const gfx::Rect&)>
      caret_bounds_observer_for_test_;
  base::RepeatingCallback<void()> magnifier_bounds_observer_for_test_;
  base::OnceClosure enhanced_network_tts_waiter_for_test_;

  // Used to set the audio focus enforcement type for ChromeVox.
  mojo::Remote<media_session::mojom::AudioFocusManager> audio_focus_manager_;

  // Whether the virtual keyboard was enabled before Switch Access loaded.
  bool was_vk_enabled_before_switch_access_ = false;

  // Tracks whether or not on the locked screen currently.
  bool locked_ = false;

  InstallFaceGazeAssetsCallback install_facegaze_assets_callback_;

  InstallPumpkinCallback install_pumpkin_callback_;
  bool is_pumpkin_installed_for_testing_ = false;

  base::FilePath dlc_path_for_test_;

  base::CallbackListSubscription focus_changed_subscription_;

  base::CallbackListSubscription on_app_terminating_subscription_;

  base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_{this};

  friend class AccessibilityManagerDictationDialogTest;
  friend class AccessibilityManagerDictationKeyboardImprovementsTest;
  friend class AccessibilityManagerDlcTest;
  friend class AccessibilityManagerNoOnDeviceSpeechRecognitionTest;
  friend class AccessibilityManagerTest;
  friend class AccessibilityServiceClientTest;
  friend class DictationTest;
  friend class SwitchAccessTest;
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_