[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 6 | |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 9 | |
| 10 | #include <memory> |
dcheng | 7c802f0 | 2015-12-31 16:09:55 | [diff] [blame] | 11 | #include <utility> |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 12 | #include <vector> |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 13 | |
James Cook | 08e91dc | 2018-03-08 18:53:19 | [diff] [blame] | 14 | #include "ash/accessibility/accessibility_controller.h" |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 15 | #include "ash/public/cpp/ash_pref_names.h" |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 16 | #include "ash/public/interfaces/accessibility_focus_ring_controller.mojom.h" |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 17 | #include "ash/public/interfaces/constants.mojom.h" |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 18 | #include "ash/root_window_controller.h" |
pkotwicz | 04d5c89 | 2015-01-15 00:05:36 | [diff] [blame] | 19 | #include "ash/shell.h" |
pkotwicz | 04d5c89 | 2015-01-15 00:05:36 | [diff] [blame] | 20 | #include "ash/sticky_keys/sticky_keys_controller.h" |
[email protected] | 44beb03 | 2014-06-11 06:24:37 | [diff] [blame] | 21 | #include "base/callback.h" |
| 22 | #include "base/callback_helpers.h" |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 23 | #include "base/command_line.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 24 | #include "base/memory/ptr_util.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 25 | #include "base/memory/singleton.h" |
asvitkine | b5663751 | 2016-09-01 19:41:40 | [diff] [blame] | 26 | #include "base/metrics/histogram_macros.h" |
[email protected] | ab38d19 | 2013-12-13 11:38:58 | [diff] [blame] | 27 | #include "base/path_service.h" |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 29 | #include "base/strings/string_split.h" |
| 30 | #include "base/strings/string_util.h" |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 31 | #include "base/values.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 32 | #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 33 | #include "chrome/browser/browser_process.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 34 | #include "chrome/browser/chrome_notification_types.h" |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 35 | #include "chrome/browser/chromeos/accessibility/accessibility_extension_loader.h" |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 36 | #include "chrome/browser/chromeos/accessibility/dictation_chromeos.h" |
pkotwicz | 04d5c89 | 2015-01-15 00:05:36 | [diff] [blame] | 37 | #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
elichtenberg | c4b4bf46 | 2017-02-28 20:48:10 | [diff] [blame] | 38 | #include "chrome/browser/chromeos/accessibility/switch_access_event_handler.h" |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 39 | #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 40 | #include "chrome/browser/chromeos/ash_config.h" |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 41 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 42 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 43 | #include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 45 | #include "chrome/browser/profiles/profile.h" |
| 46 | #include "chrome/browser/profiles/profile_manager.h" |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 47 | #include "chrome/browser/speech/tts_controller.h" |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 48 | #include "chrome/browser/ui/singleton_tabs.h" |
[email protected] | ab38d19 | 2013-12-13 11:38:58 | [diff] [blame] | 49 | #include "chrome/common/chrome_paths.h" |
[email protected] | 9848bf6c | 2014-05-09 12:34:00 | [diff] [blame] | 50 | #include "chrome/common/extensions/api/accessibility_private.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 51 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 52 | #include "chrome/common/pref_names.h" |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 53 | #include "chrome/common/url_constants.h" |
[email protected] | b58d2f8 | 2014-08-09 05:36:14 | [diff] [blame] | 54 | #include "chrome/grit/browser_resources.h" |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 55 | #include "chromeos/audio/chromeos_sounds.h" |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 56 | #include "chromeos/chromeos_switches.h" |
dtseng | 3a17f21 | 2017-03-25 08:58:52 | [diff] [blame] | 57 | #include "chromeos/dbus/dbus_thread_manager.h" |
| 58 | #include "chromeos/dbus/power_manager_client.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 59 | #include "components/prefs/pref_member.h" |
| 60 | #include "components/prefs/pref_service.h" |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 61 | #include "components/session_manager/core/session_manager.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 62 | #include "content/public/browser/browser_accessibility_state.h" |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 63 | #include "content/public/browser/browser_thread.h" |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 64 | #include "content/public/browser/focused_node_details.h" |
[email protected] | 9cf54f36 | 2013-07-01 07:28:12 | [diff] [blame] | 65 | #include "content/public/browser/notification_details.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 66 | #include "content/public/browser/notification_service.h" |
[email protected] | 9cf54f36 | 2013-07-01 07:28:12 | [diff] [blame] | 67 | #include "content/public/browser/notification_source.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 68 | #include "content/public/browser/web_ui.h" |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 69 | #include "content/public/common/content_switches.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 70 | #include "content/public/common/service_manager_connection.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 71 | #include "extensions/browser/extension_registry.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 72 | #include "extensions/common/extension.h" |
[email protected] | fb820c0 | 2014-03-13 15:07:08 | [diff] [blame] | 73 | #include "extensions/common/extension_messages.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 74 | #include "extensions/common/extension_resource.h" |
hanxi | 79f7a57 | 2015-03-09 20:46:59 | [diff] [blame] | 75 | #include "extensions/common/host_id.h" |
Ken Rockot | 388ba4fc | 2018-02-10 17:23:41 | [diff] [blame] | 76 | #include "mash/public/mojom/launchable.mojom.h" |
[email protected] | 12b0a84 | 2013-12-04 20:48:13 | [diff] [blame] | 77 | #include "media/audio/sounds/sounds_manager.h" |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 78 | #include "media/base/media_switches.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 79 | #include "services/service_manager/public/cpp/connector.h" |
Qiang Xu | c4b0575 | 2018-02-13 20:10:28 | [diff] [blame] | 80 | #include "ui/accessibility/ax_enum_util.h" |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 81 | #include "ui/base/ime/chromeos/extension_ime_util.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 82 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 66193f7 | 2017-06-26 22:24:18 | [diff] [blame] | 83 | #include "ui/views/widget/widget.h" |
jamescook | 9eb0f91 | 2017-02-03 19:13:39 | [diff] [blame] | 84 | #include "ui/views/widget/widget_observer.h" |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 85 | #include "url/gurl.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 86 | |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 87 | using content::BrowserThread; |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 88 | using extensions::api::braille_display_private::BrailleController; |
| 89 | using extensions::api::braille_display_private::DisplayState; |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 90 | using extensions::api::braille_display_private::KeyEvent; |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 91 | using extensions::api::braille_display_private::StubBrailleController; |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 92 | |
| 93 | namespace chromeos { |
| 94 | |
| 95 | namespace { |
| 96 | |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 97 | // When this flag is set, system sounds will not be played. |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 98 | constexpr char kAshDisableSystemSounds[] = "ash-disable-system-sounds"; |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 99 | |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 100 | static chromeos::AccessibilityManager* g_accessibility_manager = nullptr; |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 101 | |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 102 | static BrailleController* g_braille_controller_for_test = nullptr; |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 103 | |
| 104 | BrailleController* GetBrailleController() { |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 105 | if (g_braille_controller_for_test) |
| 106 | return g_braille_controller_for_test; |
| 107 | // Don't use the real braille controller for tests to avoid automatically |
| 108 | // starting ChromeVox which confuses some tests. |
| 109 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 110 | if (command_line->HasSwitch(::switches::kTestType)) |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 111 | return StubBrailleController::GetInstance(); |
| 112 | return BrailleController::GetInstance(); |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 115 | } // namespace |
| 116 | |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 117 | class ChromeVoxPanelWidgetObserver : public views::WidgetObserver { |
| 118 | public: |
| 119 | ChromeVoxPanelWidgetObserver(views::Widget* widget, |
| 120 | AccessibilityManager* manager) |
| 121 | : widget_(widget), manager_(manager) { |
| 122 | widget_->AddObserver(this); |
| 123 | } |
| 124 | |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 125 | ~ChromeVoxPanelWidgetObserver() override = default; |
| 126 | |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 127 | void OnWidgetClosing(views::Widget* widget) override { |
| 128 | CHECK_EQ(widget_, widget); |
| 129 | widget->RemoveObserver(this); |
| 130 | manager_->OnChromeVoxPanelClosing(); |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 131 | // |this| is deleted. |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void OnWidgetDestroying(views::Widget* widget) override { |
| 135 | CHECK_EQ(widget_, widget); |
| 136 | widget->RemoveObserver(this); |
| 137 | manager_->OnChromeVoxPanelDestroying(); |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 138 | // |this| is deleted. |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | private: |
| 142 | views::Widget* widget_; |
| 143 | AccessibilityManager* manager_; |
| 144 | |
| 145 | DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWidgetObserver); |
| 146 | }; |
| 147 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 148 | /////////////////////////////////////////////////////////////////////////////// |
| 149 | // AccessibilityStatusEventDetails |
| 150 | |
| 151 | AccessibilityStatusEventDetails::AccessibilityStatusEventDetails( |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 152 | AccessibilityNotificationType notification_type, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 153 | bool enabled, |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 154 | ash::AccessibilityNotificationVisibility notify) |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 155 | : notification_type(notification_type), enabled(enabled), notify(notify) {} |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 156 | |
| 157 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 158 | // AccessibilityManager::PrefHandler |
| 159 | |
| 160 | AccessibilityManager::PrefHandler::PrefHandler(const char* pref_path) |
| 161 | : pref_path_(pref_path) {} |
| 162 | |
| 163 | AccessibilityManager::PrefHandler::~PrefHandler() {} |
| 164 | |
| 165 | void AccessibilityManager::PrefHandler::HandleProfileChanged( |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 166 | Profile* previous_profile, |
| 167 | Profile* current_profile) { |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 168 | // Returns if the current profile is null. |
| 169 | if (!current_profile) |
| 170 | return; |
| 171 | |
| 172 | // If the user set a pref value on the login screen and is now starting a |
| 173 | // session with a new profile, copy the pref value to the profile. |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 174 | if ((previous_profile && ProfileHelper::IsSigninProfile(previous_profile) && |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 175 | current_profile->IsNewProfile() && |
| 176 | !ProfileHelper::IsSigninProfile(current_profile)) || |
| 177 | // Special case for Guest mode: |
| 178 | // Guest mode launches a guest-mode browser process before session starts, |
| 179 | // so the previous profile is null. |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 180 | (!previous_profile && current_profile->IsGuestSession())) { |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 181 | // Returns if the pref has not been set by the user. |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 182 | const PrefService::Preference* pref = |
| 183 | ProfileHelper::GetSigninProfile()->GetPrefs()->FindPreference( |
| 184 | pref_path_); |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 185 | if (!pref || !pref->IsUserControlled()) |
| 186 | return; |
| 187 | |
| 188 | // Copy the pref value from the signin screen. |
| 189 | const base::Value* value_on_login = pref->GetValue(); |
| 190 | PrefService* user_prefs = current_profile->GetPrefs(); |
| 191 | user_prefs->Set(pref_path_, *value_on_login); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /////////////////////////////////////////////////////////////////////////////// |
| 196 | // |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 197 | // AccessibilityManager |
| 198 | |
| 199 | // static |
| 200 | void AccessibilityManager::Initialize() { |
| 201 | CHECK(g_accessibility_manager == NULL); |
| 202 | g_accessibility_manager = new AccessibilityManager(); |
| 203 | } |
| 204 | |
| 205 | // static |
| 206 | void AccessibilityManager::Shutdown() { |
| 207 | CHECK(g_accessibility_manager); |
| 208 | delete g_accessibility_manager; |
| 209 | g_accessibility_manager = NULL; |
| 210 | } |
| 211 | |
| 212 | // static |
| 213 | AccessibilityManager* AccessibilityManager::Get() { |
| 214 | return g_accessibility_manager; |
| 215 | } |
| 216 | |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 217 | // static |
| 218 | void AccessibilityManager::ShowAccessibilityHelp(Browser* browser) { |
| 219 | ShowSingletonTab(browser, GURL(chrome::kChromeAccessibilityHelpURL)); |
| 220 | } |
| 221 | |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 222 | AccessibilityManager::AccessibilityManager() |
| 223 | : profile_(NULL), |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 224 | large_cursor_pref_handler_(ash::prefs::kAccessibilityLargeCursorEnabled), |
| 225 | sticky_keys_pref_handler_(ash::prefs::kAccessibilityStickyKeysEnabled), |
| 226 | spoken_feedback_pref_handler_( |
| 227 | ash::prefs::kAccessibilitySpokenFeedbackEnabled), |
| 228 | high_contrast_pref_handler_( |
| 229 | ash::prefs::kAccessibilityHighContrastEnabled), |
| 230 | autoclick_pref_handler_(ash::prefs::kAccessibilityAutoclickEnabled), |
| 231 | autoclick_delay_pref_handler_(ash::prefs::kAccessibilityAutoclickDelayMs), |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 232 | virtual_keyboard_pref_handler_( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 233 | ash::prefs::kAccessibilityVirtualKeyboardEnabled), |
| 234 | mono_audio_pref_handler_(ash::prefs::kAccessibilityMonoAudioEnabled), |
| 235 | caret_highlight_pref_handler_( |
| 236 | ash::prefs::kAccessibilityCaretHighlightEnabled), |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 237 | cursor_highlight_pref_handler_( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 238 | ash::prefs::kAccessibilityCursorHighlightEnabled), |
| 239 | focus_highlight_pref_handler_( |
| 240 | ash::prefs::kAccessibilityFocusHighlightEnabled), |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 241 | tap_dragging_pref_handler_(ash::prefs::kTapDraggingEnabled), |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 242 | select_to_speak_pref_handler_( |
| 243 | ash::prefs::kAccessibilitySelectToSpeakEnabled), |
| 244 | switch_access_pref_handler_( |
| 245 | ash::prefs::kAccessibilitySwitchAccessEnabled), |
Qiang(Joe) Xu | a0f64459 | 2017-12-01 02:16:50 | [diff] [blame] | 246 | spoken_feedback_enabled_(false), |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 247 | select_to_speak_enabled_(false), |
| 248 | switch_access_enabled_(false), |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 249 | spoken_feedback_notification_(ash::A11Y_NOTIFICATION_NONE), |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 250 | braille_display_connected_(false), |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 251 | scoped_braille_observer_(this), |
anand.ratn | 04aae9ef | 2014-09-16 04:16:51 | [diff] [blame] | 252 | braille_ime_current_(false), |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 253 | chromevox_panel_(nullptr), |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 254 | extension_registry_observer_(this), |
anand.ratn | 04aae9ef | 2014-09-16 04:16:51 | [diff] [blame] | 255 | weak_ptr_factory_(this) { |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 256 | notification_registrar_.Add(this, |
[email protected] | 093d9ba | 2013-07-23 19:26:21 | [diff] [blame] | 257 | chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 258 | content::NotificationService::AllSources()); |
| 259 | notification_registrar_.Add(this, |
Yuki Awano | d59b649 | 2017-07-28 00:52:11 | [diff] [blame] | 260 | chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 261 | content::NotificationService::AllSources()); |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 262 | notification_registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 263 | content::NotificationService::AllSources()); |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 264 | notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 265 | content::NotificationService::AllSources()); |
David Tseng | 768d798 | 2017-12-21 00:20:11 | [diff] [blame] | 266 | notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 267 | content::NotificationService::AllSources()); |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 268 | notification_registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 269 | content::NotificationService::AllSources()); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 270 | input_method::InputMethodManager::Get()->AddObserver(this); |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 271 | session_manager::SessionManager::Get()->AddObserver(this); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 272 | |
[email protected] | 12b0a84 | 2013-12-04 20:48:13 | [diff] [blame] | 273 | ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 274 | media::SoundsManager* manager = media::SoundsManager::Get(); |
| 275 | manager->Initialize(SOUND_SHUTDOWN, |
| 276 | bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); |
| 277 | manager->Initialize( |
| 278 | SOUND_SPOKEN_FEEDBACK_ENABLED, |
| 279 | bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); |
| 280 | manager->Initialize( |
| 281 | SOUND_SPOKEN_FEEDBACK_DISABLED, |
| 282 | bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); |
[email protected] | 07f3ea9 | 2014-08-14 05:23:38 | [diff] [blame] | 283 | manager->Initialize(SOUND_PASSTHROUGH, |
| 284 | bundle.GetRawDataResource(IDR_SOUND_PASSTHROUGH_WAV)); |
| 285 | manager->Initialize(SOUND_EXIT_SCREEN, |
| 286 | bundle.GetRawDataResource(IDR_SOUND_EXIT_SCREEN_WAV)); |
| 287 | manager->Initialize(SOUND_ENTER_SCREEN, |
| 288 | bundle.GetRawDataResource(IDR_SOUND_ENTER_SCREEN_WAV)); |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 289 | manager->Initialize(SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_HIGH, |
| 290 | bundle.GetRawDataResource( |
| 291 | IDR_SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_HIGH_WAV)); |
| 292 | manager->Initialize(SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_LOW, |
| 293 | bundle.GetRawDataResource( |
| 294 | IDR_SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_LOW_WAV)); |
David Tseng | 580f050e | 2017-09-05 21:18:41 | [diff] [blame] | 295 | manager->Initialize(SOUND_TOUCH_TYPE, |
| 296 | bundle.GetRawDataResource(IDR_SOUND_TOUCH_TYPE_WAV)); |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 297 | |
| 298 | base::FilePath resources_path; |
| 299 | if (!PathService::Get(chrome::DIR_RESOURCES, &resources_path)) |
| 300 | NOTREACHED(); |
| 301 | chromevox_loader_ = base::WrapUnique(new AccessibilityExtensionLoader( |
| 302 | extension_misc::kChromeVoxExtensionId, |
| 303 | resources_path.Append(extension_misc::kChromeVoxExtensionPath), |
| 304 | base::Bind(&AccessibilityManager::PostUnloadChromeVox, |
| 305 | weak_ptr_factory_.GetWeakPtr()))); |
dmazzoni | 5288b261 | 2016-09-16 23:05:39 | [diff] [blame] | 306 | select_to_speak_loader_ = base::WrapUnique(new AccessibilityExtensionLoader( |
| 307 | extension_misc::kSelectToSpeakExtensionId, |
| 308 | resources_path.Append(extension_misc::kSelectToSpeakExtensionPath), |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 309 | base::Bind(&AccessibilityManager::PostUnloadSelectToSpeak, |
| 310 | weak_ptr_factory_.GetWeakPtr()))); |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 311 | switch_access_loader_ = base::WrapUnique(new AccessibilityExtensionLoader( |
| 312 | extension_misc::kSwitchAccessExtensionId, |
| 313 | resources_path.Append(extension_misc::kSwitchAccessExtensionPath), |
| 314 | base::Closure())); |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 315 | |
| 316 | // Connect to ash's AccessibilityController interface. |
| 317 | content::ServiceManagerConnection::GetForProcess() |
| 318 | ->GetConnector() |
| 319 | ->BindInterface(ash::mojom::kServiceName, &accessibility_controller_); |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 320 | |
| 321 | // Connect to ash's AccessibilityFocusRingController interface. |
| 322 | content::ServiceManagerConnection::GetForProcess() |
| 323 | ->GetConnector() |
| 324 | ->BindInterface(ash::mojom::kServiceName, |
| 325 | &accessibility_focus_ring_controller_); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | AccessibilityManager::~AccessibilityManager() { |
| 329 | CHECK(this == g_accessibility_manager); |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 330 | AccessibilityStatusEventDetails details(ACCESSIBILITY_MANAGER_SHUTDOWN, false, |
| 331 | ash::A11Y_NOTIFICATION_NONE); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 332 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 333 | input_method::InputMethodManager::Get()->RemoveObserver(this); |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 334 | session_manager::SessionManager::Get()->RemoveObserver(this); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 335 | |
| 336 | if (chromevox_panel_) { |
James Cook | 769799b | 2018-03-12 16:59:04 | [diff] [blame] | 337 | chromevox_panel_->CloseNow(); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 338 | chromevox_panel_ = nullptr; |
| 339 | } |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 342 | bool AccessibilityManager::ShouldShowAccessibilityMenu() { |
| 343 | // If any of the loaded profiles has an accessibility feature turned on - or |
| 344 | // enforced to always show the menu - we return true to show the menu. |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 345 | // NOTE: This includes the login screen profile, so if a feature is turned on |
| 346 | // at the login screen the menu will show even if the user has no features |
| 347 | // enabled inside the session. http://crbug.com/755631 |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 348 | std::vector<Profile*> profiles = |
| 349 | g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 350 | for (std::vector<Profile*>::iterator it = profiles.begin(); |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 351 | it != profiles.end(); ++it) { |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 352 | PrefService* prefs = (*it)->GetPrefs(); |
| 353 | if (prefs->GetBoolean(ash::prefs::kAccessibilityStickyKeysEnabled) || |
| 354 | prefs->GetBoolean(ash::prefs::kAccessibilityLargeCursorEnabled) || |
| 355 | prefs->GetBoolean(ash::prefs::kAccessibilitySpokenFeedbackEnabled) || |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 356 | prefs->GetBoolean(ash::prefs::kAccessibilitySelectToSpeakEnabled) || |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 357 | prefs->GetBoolean(ash::prefs::kAccessibilityHighContrastEnabled) || |
| 358 | prefs->GetBoolean(ash::prefs::kAccessibilityAutoclickEnabled) || |
| 359 | prefs->GetBoolean(ash::prefs::kShouldAlwaysShowAccessibilityMenu) || |
| 360 | prefs->GetBoolean(ash::prefs::kAccessibilityScreenMagnifierEnabled) || |
| 361 | prefs->GetBoolean(ash::prefs::kAccessibilityVirtualKeyboardEnabled) || |
| 362 | prefs->GetBoolean(ash::prefs::kAccessibilityMonoAudioEnabled) || |
| 363 | prefs->GetBoolean(ash::prefs::kAccessibilityCaretHighlightEnabled) || |
| 364 | prefs->GetBoolean(ash::prefs::kAccessibilityCursorHighlightEnabled) || |
| 365 | prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled) || |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 366 | prefs->GetBoolean(ash::prefs::kTapDraggingEnabled)) |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 367 | return true; |
| 368 | } |
| 369 | return false; |
| 370 | } |
| 371 | |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 372 | void AccessibilityManager::UpdateAlwaysShowMenuFromPref() { |
| 373 | if (!profile_) |
| 374 | return; |
| 375 | |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 376 | // TODO(crbug.com/594887): Fix for mash by moving pref into ash. |
| 377 | if (GetAshConfig() == ash::Config::MASH) |
| 378 | return; |
| 379 | |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 380 | // Update system tray menu visibility. |
James Cook | 08e91dc | 2018-03-08 18:53:19 | [diff] [blame] | 381 | ash::Shell::Get() |
| 382 | ->accessibility_controller() |
| 383 | ->NotifyAccessibilityStatusChanged(ash::A11Y_NOTIFICATION_NONE); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 384 | } |
| 385 | |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 386 | void AccessibilityManager::EnableLargeCursor(bool enabled) { |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 387 | if (!profile_) |
| 388 | return; |
| 389 | |
| 390 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 391 | pref_service->SetBoolean(ash::prefs::kAccessibilityLargeCursorEnabled, |
| 392 | enabled); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 393 | pref_service->CommitPendingWrite(); |
| 394 | } |
| 395 | |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 396 | void AccessibilityManager::OnLargeCursorChanged() { |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 397 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_LARGE_CURSOR, |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 398 | IsLargeCursorEnabled(), |
| 399 | ash::A11Y_NOTIFICATION_NONE); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 400 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 401 | } |
| 402 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 403 | bool AccessibilityManager::IsLargeCursorEnabled() const { |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 404 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 405 | ash::prefs::kAccessibilityLargeCursorEnabled); |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 408 | void AccessibilityManager::EnableStickyKeys(bool enabled) { |
| 409 | if (!profile_) |
| 410 | return; |
| 411 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 412 | pref_service->SetBoolean(ash::prefs::kAccessibilityStickyKeysEnabled, |
| 413 | enabled); |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 414 | pref_service->CommitPendingWrite(); |
| 415 | } |
| 416 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 417 | bool AccessibilityManager::IsStickyKeysEnabled() const { |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 418 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 419 | ash::prefs::kAccessibilityStickyKeysEnabled); |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 420 | } |
| 421 | |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 422 | void AccessibilityManager::OnStickyKeysChanged() { |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 423 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_STICKY_KEYS, |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 424 | IsStickyKeysEnabled(), |
| 425 | ash::A11Y_NOTIFICATION_NONE); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 426 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 427 | } |
| 428 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 429 | void AccessibilityManager::EnableSpokenFeedback( |
| 430 | bool enabled, |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 431 | ash::AccessibilityNotificationVisibility notify) { |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 432 | if (!profile_) |
| 433 | return; |
[email protected] | 5d2ea36 | 2013-12-13 08:10:18 | [diff] [blame] | 434 | |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 435 | spoken_feedback_notification_ = notify; |
| 436 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 437 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 438 | pref_service->SetBoolean(ash::prefs::kAccessibilitySpokenFeedbackEnabled, |
| 439 | enabled); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 440 | pref_service->CommitPendingWrite(); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 441 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 442 | spoken_feedback_notification_ = ash::A11Y_NOTIFICATION_NONE; |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 443 | } |
| 444 | |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 445 | void AccessibilityManager::OnSpokenFeedbackChanged() { |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 446 | if (!profile_) |
| 447 | return; |
| 448 | |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 449 | const bool enabled = profile_->GetPrefs()->GetBoolean( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 450 | ash::prefs::kAccessibilitySpokenFeedbackEnabled); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 451 | |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 452 | if (enabled) { |
| 453 | chromevox_loader_->SetProfile( |
| 454 | profile_, base::Bind(&AccessibilityManager::PostSwitchChromeVoxProfile, |
| 455 | weak_ptr_factory_.GetWeakPtr())); |
| 456 | } |
dmazzoni | 2c01320 | 2016-09-07 19:59:37 | [diff] [blame] | 457 | |
Qiang(Joe) Xu | a0f64459 | 2017-12-01 02:16:50 | [diff] [blame] | 458 | if (spoken_feedback_enabled_ == enabled) |
| 459 | return; |
| 460 | |
| 461 | spoken_feedback_enabled_ = enabled; |
| 462 | |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 463 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK, |
| 464 | enabled, |
| 465 | spoken_feedback_notification_); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 466 | |
| 467 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 468 | |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 469 | if (enabled) { |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 470 | chromevox_loader_->Load(profile_, |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 471 | base::Bind(&AccessibilityManager::PostLoadChromeVox, |
| 472 | weak_ptr_factory_.GetWeakPtr())); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 473 | } else { |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 474 | chromevox_loader_->Unload(); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 475 | } |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 476 | UpdateBrailleImeState(); |
[email protected] | b0a2ce3 | 2013-07-23 15:24:53 | [diff] [blame] | 477 | } |
| 478 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 479 | bool AccessibilityManager::IsSpokenFeedbackEnabled() const { |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 480 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 481 | ash::prefs::kAccessibilitySpokenFeedbackEnabled); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 482 | } |
| 483 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 484 | void AccessibilityManager::EnableHighContrast(bool enabled) { |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 485 | if (!profile_) |
| 486 | return; |
| 487 | |
| 488 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 489 | pref_service->SetBoolean(ash::prefs::kAccessibilityHighContrastEnabled, |
| 490 | enabled); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 491 | pref_service->CommitPendingWrite(); |
| 492 | } |
| 493 | |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 494 | bool AccessibilityManager::IsHighContrastEnabled() const { |
| 495 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 496 | ash::prefs::kAccessibilityHighContrastEnabled); |
| 497 | } |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 498 | |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 499 | void AccessibilityManager::OnHighContrastChanged() { |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 500 | AccessibilityStatusEventDetails details( |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 501 | ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE, IsHighContrastEnabled(), |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 502 | ash::A11Y_NOTIFICATION_NONE); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 503 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | 628b890 | 2014-03-12 05:26:41 | [diff] [blame] | 506 | void AccessibilityManager::OnLocaleChanged() { |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 507 | if (!profile_) |
| 508 | return; |
| 509 | |
| 510 | if (!IsSpokenFeedbackEnabled()) |
| 511 | return; |
| 512 | |
| 513 | // If the system locale changes and spoken feedback is enabled, |
| 514 | // reload ChromeVox so that it switches its internal translations |
| 515 | // to the new language. |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 516 | EnableSpokenFeedback(false, ash::A11Y_NOTIFICATION_NONE); |
| 517 | EnableSpokenFeedback(true, ash::A11Y_NOTIFICATION_NONE); |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 518 | } |
| 519 | |
yawano | ca05a1af | 2017-01-25 02:38:17 | [diff] [blame] | 520 | void AccessibilityManager::OnViewFocusedInArc( |
| 521 | const gfx::Rect& bounds_in_screen) { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 522 | accessibility_controller_->SetFocusHighlightRect(bounds_in_screen); |
yawano | ca05a1af | 2017-01-25 02:38:17 | [diff] [blame] | 523 | } |
| 524 | |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 525 | bool AccessibilityManager::PlayEarcon(int sound_key, PlaySoundOption option) { |
[email protected] | 07f3ea9 | 2014-08-14 05:23:38 | [diff] [blame] | 526 | DCHECK(sound_key < chromeos::SOUND_COUNT); |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 527 | base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 528 | if (cl->HasSwitch(kAshDisableSystemSounds)) |
| 529 | return false; |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 530 | if (option == PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED && |
David Tseng | 89850d1 | 2017-08-29 02:23:41 | [diff] [blame] | 531 | !IsSpokenFeedbackEnabled()) { |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 532 | return false; |
| 533 | } |
| 534 | return media::SoundsManager::Get()->Play(sound_key); |
[email protected] | 07f3ea9 | 2014-08-14 05:23:38 | [diff] [blame] | 535 | } |
| 536 | |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 537 | void AccessibilityManager::OnTwoFingerTouchStart() { |
dmazzoni | c613a56 | 2017-05-02 03:19:19 | [diff] [blame] | 538 | if (!profile()) |
| 539 | return; |
| 540 | |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 541 | extensions::EventRouter* event_router = |
| 542 | extensions::EventRouter::Get(profile()); |
| 543 | CHECK(event_router); |
| 544 | |
Jinho Bang | 341ce5b0 | 2018-01-17 22:46:03 | [diff] [blame] | 545 | auto event_args = std::make_unique<base::ListValue>(); |
| 546 | auto event = std::make_unique<extensions::Event>( |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 547 | extensions::events::ACCESSIBILITY_PRIVATE_ON_TWO_FINGER_TOUCH_START, |
| 548 | extensions::api::accessibility_private::OnTwoFingerTouchStart::kEventName, |
| 549 | std::move(event_args)); |
| 550 | event_router->BroadcastEvent(std::move(event)); |
| 551 | } |
| 552 | |
| 553 | void AccessibilityManager::OnTwoFingerTouchStop() { |
dmazzoni | c613a56 | 2017-05-02 03:19:19 | [diff] [blame] | 554 | if (!profile()) |
| 555 | return; |
| 556 | |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 557 | extensions::EventRouter* event_router = |
| 558 | extensions::EventRouter::Get(profile()); |
| 559 | CHECK(event_router); |
| 560 | |
Jinho Bang | 341ce5b0 | 2018-01-17 22:46:03 | [diff] [blame] | 561 | auto event_args = std::make_unique<base::ListValue>(); |
| 562 | auto event = std::make_unique<extensions::Event>( |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 563 | extensions::events::ACCESSIBILITY_PRIVATE_ON_TWO_FINGER_TOUCH_STOP, |
| 564 | extensions::api::accessibility_private::OnTwoFingerTouchStop::kEventName, |
| 565 | std::move(event_args)); |
| 566 | event_router->BroadcastEvent(std::move(event)); |
| 567 | } |
| 568 | |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 569 | bool AccessibilityManager::ShouldToggleSpokenFeedbackViaTouch() { |
dmazzoni | 200099c | 2017-01-31 23:21:40 | [diff] [blame] | 570 | #if 1 |
| 571 | // Temporarily disabling this feature until UI feedback is fixed. |
| 572 | // http://crbug.com/662501 |
| 573 | return false; |
| 574 | #else |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 575 | policy::BrowserPolicyConnectorChromeOS* connector = |
| 576 | g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 577 | if (!connector) |
| 578 | return false; |
| 579 | |
| 580 | if (!connector->IsEnterpriseManaged()) |
| 581 | return false; |
| 582 | |
| 583 | const policy::DeviceCloudPolicyManagerChromeOS* const |
| 584 | device_cloud_policy_manager = connector->GetDeviceCloudPolicyManager(); |
| 585 | if (!device_cloud_policy_manager) |
| 586 | return false; |
| 587 | |
| 588 | if (!device_cloud_policy_manager->IsRemoraRequisition()) |
| 589 | return false; |
| 590 | |
| 591 | KioskAppManager* manager = KioskAppManager::Get(); |
| 592 | KioskAppManager::App app; |
| 593 | CHECK(manager->GetApp(manager->GetAutoLaunchApp(), &app)); |
| 594 | return app.was_auto_launched_with_zero_delay; |
dmazzoni | 200099c | 2017-01-31 23:21:40 | [diff] [blame] | 595 | #endif |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | bool AccessibilityManager::PlaySpokenFeedbackToggleCountdown(int tick_count) { |
| 599 | return media::SoundsManager::Get()->Play( |
| 600 | tick_count % 2 ? SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_HIGH |
| 601 | : SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_LOW); |
| 602 | } |
| 603 | |
Qiang Xu | 9e12fa76 | 2017-12-19 03:27:49 | [diff] [blame] | 604 | void AccessibilityManager::HandleAccessibilityGesture( |
Qiang Xu | c4b0575 | 2018-02-13 20:10:28 | [diff] [blame] | 605 | ax::mojom::Gesture gesture) { |
dmazzoni | 82ef29a | 2016-05-10 23:37:51 | [diff] [blame] | 606 | extensions::EventRouter* event_router = |
| 607 | extensions::EventRouter::Get(profile()); |
| 608 | CHECK(event_router); |
| 609 | |
| 610 | std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
Qiang Xu | c4b0575 | 2018-02-13 20:10:28 | [diff] [blame] | 611 | event_args->AppendString(ui::ToString(gesture)); |
dmazzoni | 82ef29a | 2016-05-10 23:37:51 | [diff] [blame] | 612 | std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 613 | extensions::events::ACCESSIBILITY_PRIVATE_ON_ACCESSIBILITY_GESTURE, |
| 614 | extensions::api::accessibility_private::OnAccessibilityGesture:: |
| 615 | kEventName, |
| 616 | std::move(event_args))); |
| 617 | event_router->DispatchEventWithLazyListener( |
| 618 | extension_misc::kChromeVoxExtensionId, std::move(event)); |
| 619 | } |
| 620 | |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 621 | void AccessibilityManager::SetTouchAccessibilityAnchorPoint( |
| 622 | const gfx::Point& anchor_point) { |
dmazzoni | 50f6580 | 2017-06-28 18:19:39 | [diff] [blame] | 623 | for (auto* rwc : ash::RootWindowController::root_window_controllers()) |
| 624 | rwc->SetTouchAccessibilityAnchorPoint(anchor_point); |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 625 | } |
| 626 | |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 627 | void AccessibilityManager::EnableAutoclick(bool enabled) { |
| 628 | if (!profile_) |
| 629 | return; |
| 630 | |
| 631 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 632 | pref_service->SetBoolean(ash::prefs::kAccessibilityAutoclickEnabled, enabled); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 633 | pref_service->CommitPendingWrite(); |
| 634 | } |
| 635 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 636 | bool AccessibilityManager::IsAutoclickEnabled() const { |
Qiang Xu | d0f3be2e | 2018-01-08 12:48:18 | [diff] [blame] | 637 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 638 | ash::prefs::kAccessibilityAutoclickEnabled); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 641 | void AccessibilityManager::EnableVirtualKeyboard(bool enabled) { |
| 642 | if (!profile_) |
| 643 | return; |
| 644 | |
| 645 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 646 | pref_service->SetBoolean(ash::prefs::kAccessibilityVirtualKeyboardEnabled, |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 647 | enabled); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 648 | pref_service->CommitPendingWrite(); |
| 649 | } |
| 650 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 651 | bool AccessibilityManager::IsVirtualKeyboardEnabled() const { |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 652 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 653 | ash::prefs::kAccessibilityVirtualKeyboardEnabled); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 654 | } |
| 655 | |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 656 | void AccessibilityManager::OnVirtualKeyboardChanged() { |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 657 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD, |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 658 | IsVirtualKeyboardEnabled(), |
| 659 | ash::A11Y_NOTIFICATION_NONE); |
rsadam | a1104b8 | 2014-11-03 20:50:52 | [diff] [blame] | 660 | NotifyAccessibilityStatusChanged(details); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 661 | } |
| 662 | |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 663 | void AccessibilityManager::EnableMonoAudio(bool enabled) { |
| 664 | if (!profile_) |
| 665 | return; |
| 666 | |
| 667 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 668 | pref_service->SetBoolean(ash::prefs::kAccessibilityMonoAudioEnabled, enabled); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 669 | pref_service->CommitPendingWrite(); |
| 670 | } |
| 671 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 672 | bool AccessibilityManager::IsMonoAudioEnabled() const { |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 673 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 674 | ash::prefs::kAccessibilityMonoAudioEnabled); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 675 | } |
| 676 | |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 677 | void AccessibilityManager::OnMonoAudioChanged() { |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 678 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_MONO_AUDIO, |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 679 | IsMonoAudioEnabled(), |
| 680 | ash::A11Y_NOTIFICATION_NONE); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 681 | NotifyAccessibilityStatusChanged(details); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 682 | } |
| 683 | |
Daniel Erat | 477c56d | 2017-12-13 21:42:54 | [diff] [blame] | 684 | void AccessibilityManager::SetDarkenScreen(bool darken) { |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 685 | accessibility_controller_->SetDarkenScreen(darken); |
Daniel Erat | 477c56d | 2017-12-13 21:42:54 | [diff] [blame] | 686 | } |
| 687 | |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 688 | void AccessibilityManager::SetCaretHighlightEnabled(bool enabled) { |
| 689 | if (!profile_) |
| 690 | return; |
| 691 | |
| 692 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 693 | pref_service->SetBoolean(ash::prefs::kAccessibilityCaretHighlightEnabled, |
| 694 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 695 | pref_service->CommitPendingWrite(); |
| 696 | } |
| 697 | |
| 698 | bool AccessibilityManager::IsCaretHighlightEnabled() const { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 699 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 700 | ash::prefs::kAccessibilityCaretHighlightEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 701 | } |
| 702 | |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 703 | void AccessibilityManager::OnCaretHighlightChanged() { |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 704 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_CARET_HIGHLIGHT, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 705 | IsCaretHighlightEnabled(), |
| 706 | ash::A11Y_NOTIFICATION_NONE); |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 707 | NotifyAccessibilityStatusChanged(details); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void AccessibilityManager::SetCursorHighlightEnabled(bool enabled) { |
| 711 | if (!profile_) |
| 712 | return; |
| 713 | |
| 714 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 715 | pref_service->SetBoolean(ash::prefs::kAccessibilityCursorHighlightEnabled, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 716 | enabled); |
| 717 | pref_service->CommitPendingWrite(); |
| 718 | } |
| 719 | |
| 720 | bool AccessibilityManager::IsCursorHighlightEnabled() const { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 721 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 722 | ash::prefs::kAccessibilityCursorHighlightEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 723 | } |
| 724 | |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 725 | void AccessibilityManager::OnCursorHighlightChanged() { |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 726 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_CURSOR_HIGHLIGHT, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 727 | IsCursorHighlightEnabled(), |
| 728 | ash::A11Y_NOTIFICATION_NONE); |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 729 | NotifyAccessibilityStatusChanged(details); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void AccessibilityManager::SetFocusHighlightEnabled(bool enabled) { |
| 733 | if (!profile_) |
| 734 | return; |
| 735 | |
| 736 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 737 | pref_service->SetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled, |
| 738 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 739 | pref_service->CommitPendingWrite(); |
| 740 | } |
| 741 | |
| 742 | bool AccessibilityManager::IsFocusHighlightEnabled() const { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 743 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 744 | ash::prefs::kAccessibilityFocusHighlightEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 745 | } |
| 746 | |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 747 | void AccessibilityManager::OnFocusHighlightChanged() { |
| 748 | bool enabled = IsFocusHighlightEnabled(); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 749 | |
dmazzoni | 42e4b00 | 2016-06-08 20:58:42 | [diff] [blame] | 750 | // Focus highlighting can't be on when spoken feedback is on, because |
| 751 | // ChromeVox does its own focus highlighting. |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 752 | if (IsSpokenFeedbackEnabled()) |
dmazzoni | 42e4b00 | 2016-06-08 20:58:42 | [diff] [blame] | 753 | enabled = false; |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 754 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_FOCUS_HIGHLIGHT, |
| 755 | enabled, ash::A11Y_NOTIFICATION_NONE); |
| 756 | NotifyAccessibilityStatusChanged(details); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 757 | } |
| 758 | |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 759 | void AccessibilityManager::EnableTapDragging(bool enabled) { |
| 760 | if (!profile_) |
| 761 | return; |
| 762 | |
| 763 | PrefService* pref_service = profile_->GetPrefs(); |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 764 | pref_service->SetBoolean(ash::prefs::kTapDraggingEnabled, enabled); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 765 | pref_service->CommitPendingWrite(); |
| 766 | } |
| 767 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 768 | bool AccessibilityManager::IsTapDraggingEnabled() const { |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 769 | return profile_ && |
| 770 | profile_->GetPrefs()->GetBoolean(ash::prefs::kTapDraggingEnabled); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 771 | } |
| 772 | |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 773 | void AccessibilityManager::OnTapDraggingChanged() { |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 774 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_TAP_DRAGGING, |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 775 | IsTapDraggingEnabled(), |
| 776 | ash::A11Y_NOTIFICATION_NONE); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 777 | NotifyAccessibilityStatusChanged(details); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 778 | } |
| 779 | |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 780 | void AccessibilityManager::SetSelectToSpeakEnabled(bool enabled) { |
| 781 | if (!profile_) |
| 782 | return; |
| 783 | |
| 784 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 785 | pref_service->SetBoolean(ash::prefs::kAccessibilitySelectToSpeakEnabled, |
| 786 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 787 | pref_service->CommitPendingWrite(); |
| 788 | } |
| 789 | |
| 790 | bool AccessibilityManager::IsSelectToSpeakEnabled() const { |
| 791 | return select_to_speak_enabled_; |
| 792 | } |
| 793 | |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 794 | void AccessibilityManager::OnSelectToSpeakChanged() { |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 795 | if (!profile_) |
| 796 | return; |
| 797 | |
| 798 | const bool enabled = profile_->GetPrefs()->GetBoolean( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 799 | ash::prefs::kAccessibilitySelectToSpeakEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 800 | |
| 801 | if (select_to_speak_enabled_ == enabled) |
| 802 | return; |
| 803 | select_to_speak_enabled_ = enabled; |
| 804 | |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 805 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK, |
| 806 | enabled, ash::A11Y_NOTIFICATION_NONE); |
| 807 | NotifyAccessibilityStatusChanged(details); |
| 808 | |
Katie Dektar | 0c0f3795 | 2017-12-18 18:35:33 | [diff] [blame] | 809 | if (enabled) |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 810 | select_to_speak_loader_->Load(profile_, base::Closure() /* done_cb */); |
Katie Dektar | 0c0f3795 | 2017-12-18 18:35:33 | [diff] [blame] | 811 | else |
dmazzoni | 5288b261 | 2016-09-16 23:05:39 | [diff] [blame] | 812 | select_to_speak_loader_->Unload(); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | void AccessibilityManager::SetSwitchAccessEnabled(bool enabled) { |
| 816 | if (!profile_) |
| 817 | return; |
| 818 | |
| 819 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 820 | pref_service->SetBoolean(ash::prefs::kAccessibilitySwitchAccessEnabled, |
| 821 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 822 | pref_service->CommitPendingWrite(); |
| 823 | } |
| 824 | |
| 825 | bool AccessibilityManager::IsSwitchAccessEnabled() const { |
| 826 | return switch_access_enabled_; |
| 827 | } |
| 828 | |
| 829 | void AccessibilityManager::UpdateSwitchAccessFromPref() { |
| 830 | if (!profile_) |
| 831 | return; |
| 832 | |
| 833 | const bool enabled = profile_->GetPrefs()->GetBoolean( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 834 | ash::prefs::kAccessibilitySwitchAccessEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 835 | |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 836 | // The Switch Access setting is behind a flag. Don't enable the feature |
| 837 | // even if the preference is enabled, if the flag isn't also set. |
| 838 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 839 | if (!command_line->HasSwitch( |
| 840 | chromeos::switches::kEnableExperimentalAccessibilityFeatures)) { |
| 841 | if (enabled) { |
| 842 | LOG(WARNING) << "Switch access enabled but experimental accessibility " |
| 843 | << "features flag is not set."; |
| 844 | } |
| 845 | return; |
| 846 | } |
| 847 | |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 848 | if (switch_access_enabled_ == enabled) |
| 849 | return; |
| 850 | switch_access_enabled_ = enabled; |
| 851 | |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 852 | if (enabled) { |
| 853 | switch_access_loader_->Load(profile_, base::Closure() /* done_cb */); |
elichtenberg | c4b4bf46 | 2017-02-28 20:48:10 | [diff] [blame] | 854 | switch_access_event_handler_.reset( |
| 855 | new chromeos::SwitchAccessEventHandler()); |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 856 | } else { |
| 857 | switch_access_loader_->Unload(); |
elichtenberg | c4b4bf46 | 2017-02-28 20:48:10 | [diff] [blame] | 858 | switch_access_event_handler_.reset(nullptr); |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 859 | } |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 860 | } |
| 861 | |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 862 | bool AccessibilityManager::IsBrailleDisplayConnected() const { |
| 863 | return braille_display_connected_; |
| 864 | } |
| 865 | |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 866 | void AccessibilityManager::CheckBrailleState() { |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 867 | BrailleController* braille_controller = GetBrailleController(); |
| 868 | if (!scoped_braille_observer_.IsObserving(braille_controller)) |
| 869 | scoped_braille_observer_.Add(braille_controller); |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 870 | BrowserThread::PostTaskAndReplyWithResult( |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 871 | BrowserThread::IO, FROM_HERE, |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 872 | base::Bind(&BrailleController::GetDisplayState, |
| 873 | base::Unretained(braille_controller)), |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 874 | base::Bind(&AccessibilityManager::ReceiveBrailleDisplayState, |
| 875 | weak_ptr_factory_.GetWeakPtr())); |
| 876 | } |
| 877 | |
| 878 | void AccessibilityManager::ReceiveBrailleDisplayState( |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 879 | std::unique_ptr<extensions::api::braille_display_private::DisplayState> |
| 880 | state) { |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 881 | OnBrailleDisplayStateChanged(*state); |
| 882 | } |
| 883 | |
| 884 | void AccessibilityManager::UpdateBrailleImeState() { |
| 885 | if (!profile_) |
| 886 | return; |
| 887 | PrefService* pref_service = profile_->GetPrefs(); |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 888 | std::string preload_engines_str = |
| 889 | pref_service->GetString(prefs::kLanguagePreloadEngines); |
| 890 | std::vector<base::StringPiece> preload_engines = base::SplitStringPiece( |
| 891 | preload_engines_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 892 | std::vector<base::StringPiece>::iterator it = |
| 893 | std::find(preload_engines.begin(), preload_engines.end(), |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 894 | extension_ime_util::kBrailleImeEngineId); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 895 | bool is_enabled = (it != preload_engines.end()); |
| 896 | bool should_be_enabled = |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 897 | (IsSpokenFeedbackEnabled() && braille_display_connected_); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 898 | if (is_enabled == should_be_enabled) |
| 899 | return; |
| 900 | if (should_be_enabled) |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 901 | preload_engines.push_back(extension_ime_util::kBrailleImeEngineId); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 902 | else |
| 903 | preload_engines.erase(it); |
| 904 | pref_service->SetString(prefs::kLanguagePreloadEngines, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 905 | base::JoinString(preload_engines, ",")); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 906 | braille_ime_current_ = false; |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 907 | } |
| 908 | |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 909 | // Overridden from InputMethodManager::Observer. |
| 910 | void AccessibilityManager::InputMethodChanged( |
| 911 | input_method::InputMethodManager* manager, |
alemate | f0673029 | 2015-05-12 21:36:07 | [diff] [blame] | 912 | Profile* /* profile */, |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 913 | bool show_message) { |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 914 | // Sticky keys is implemented only in ash. |
dpolukhin | 04e5b809 | 2014-09-11 02:55:05 | [diff] [blame] | 915 | // TODO(dpolukhin): support Athena, crbug.com/408733. |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 916 | if (GetAshConfig() != ash::Config::MASH) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 917 | ash::Shell::Get()->sticky_keys_controller()->SetModifiersEnabled( |
riajiang | 4b626b97 | 2016-09-13 16:12:49 | [diff] [blame] | 918 | manager->IsISOLevel5ShiftUsedByCurrentInputMethod(), |
| 919 | manager->IsAltGrUsedByCurrentInputMethod()); |
| 920 | } |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 921 | const chromeos::input_method::InputMethodDescriptor descriptor = |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 922 | manager->GetActiveIMEState()->GetCurrentInputMethod(); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 923 | braille_ime_current_ = |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 924 | (descriptor.id() == extension_ime_util::kBrailleImeEngineId); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 925 | } |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 926 | |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 927 | void AccessibilityManager::OnSessionStateChanged() { |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 928 | // Don't reload ChromeVox during shutdown. http://crrev.com/c/838180 |
| 929 | if (app_terminating_) |
| 930 | return; |
| 931 | |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 932 | if (!chromevox_panel_) |
| 933 | return; |
| 934 | if (chromevox_panel_->for_blocked_user_session() == |
| 935 | session_manager::SessionManager::Get()->IsUserSessionBlocked()) { |
| 936 | return; |
| 937 | } |
| 938 | |
| 939 | // If user session got blocked or unblocked, reload ChromeVox panel, as |
| 940 | // functionality available to the panel differs based on whether the user |
| 941 | // session is active (and unlocked) or not. |
| 942 | ReloadChromeVoxPanel(); |
| 943 | } |
| 944 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 945 | void AccessibilityManager::SetProfile(Profile* profile) { |
Yuki Awano | d59b649 | 2017-07-28 00:52:11 | [diff] [blame] | 946 | // Do nothing if this is called for the current profile. This can happen. For |
| 947 | // example, ChromeSessionManager fires both |
| 948 | // NOTIFICATION_LOGIN_USER_PROFILE_PREPARED and NOTIFICATION_SESSION_STARTED, |
| 949 | // and we are observing both events. |
| 950 | if (profile_ == profile) |
| 951 | return; |
| 952 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 953 | pref_change_registrar_.reset(); |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 954 | local_state_pref_change_registrar_.reset(); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 955 | |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 956 | // Clear all dictation state on profile change. |
| 957 | dictation_.reset(); |
| 958 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 959 | if (profile) { |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 960 | // TODO(yoshiki): Move following code to PrefHandler. |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 961 | pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 962 | pref_change_registrar_->Init(profile->GetPrefs()); |
| 963 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 964 | ash::prefs::kShouldAlwaysShowAccessibilityMenu, |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 965 | base::Bind(&AccessibilityManager::UpdateAlwaysShowMenuFromPref, |
| 966 | base::Unretained(this))); |
| 967 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 968 | ash::prefs::kAccessibilityLargeCursorEnabled, |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 969 | base::Bind(&AccessibilityManager::OnLargeCursorChanged, |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 970 | base::Unretained(this))); |
| 971 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 972 | ash::prefs::kAccessibilityLargeCursorDipSize, |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 973 | base::Bind(&AccessibilityManager::OnLargeCursorChanged, |
yawano | dc5533b3 | 2017-02-23 11:04:38 | [diff] [blame] | 974 | base::Unretained(this))); |
| 975 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 976 | ash::prefs::kAccessibilityStickyKeysEnabled, |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 977 | base::Bind(&AccessibilityManager::OnStickyKeysChanged, |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 978 | base::Unretained(this))); |
| 979 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 980 | ash::prefs::kAccessibilitySpokenFeedbackEnabled, |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 981 | base::Bind(&AccessibilityManager::OnSpokenFeedbackChanged, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 982 | base::Unretained(this))); |
| 983 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 984 | ash::prefs::kAccessibilityHighContrastEnabled, |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 985 | base::Bind(&AccessibilityManager::OnHighContrastChanged, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 986 | base::Unretained(this))); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 987 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 988 | ash::prefs::kAccessibilityVirtualKeyboardEnabled, |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 989 | base::Bind(&AccessibilityManager::OnVirtualKeyboardChanged, |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 990 | base::Unretained(this))); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 991 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 992 | ash::prefs::kAccessibilityMonoAudioEnabled, |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 993 | base::Bind(&AccessibilityManager::OnMonoAudioChanged, |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 994 | base::Unretained(this))); |
| 995 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 996 | ash::prefs::kAccessibilityCaretHighlightEnabled, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 997 | base::Bind(&AccessibilityManager::OnCaretHighlightChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 998 | base::Unretained(this))); |
| 999 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1000 | ash::prefs::kAccessibilityCursorHighlightEnabled, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 1001 | base::Bind(&AccessibilityManager::OnCursorHighlightChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1002 | base::Unretained(this))); |
| 1003 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1004 | ash::prefs::kAccessibilityFocusHighlightEnabled, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 1005 | base::Bind(&AccessibilityManager::OnFocusHighlightChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1006 | base::Unretained(this))); |
| 1007 | pref_change_registrar_->Add( |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 1008 | ash::prefs::kTapDraggingEnabled, |
| 1009 | base::Bind(&AccessibilityManager::OnTapDraggingChanged, |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 1010 | base::Unretained(this))); |
| 1011 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1012 | ash::prefs::kAccessibilitySelectToSpeakEnabled, |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 1013 | base::Bind(&AccessibilityManager::OnSelectToSpeakChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1014 | base::Unretained(this))); |
| 1015 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1016 | ash::prefs::kAccessibilitySwitchAccessEnabled, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1017 | base::Bind(&AccessibilityManager::UpdateSwitchAccessFromPref, |
| 1018 | base::Unretained(this))); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1019 | |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 1020 | local_state_pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 1021 | local_state_pref_change_registrar_->Init(g_browser_process->local_state()); |
| 1022 | local_state_pref_change_registrar_->Add( |
| 1023 | prefs::kApplicationLocale, |
[email protected] | 628b890 | 2014-03-12 05:26:41 | [diff] [blame] | 1024 | base::Bind(&AccessibilityManager::OnLocaleChanged, |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 1025 | base::Unretained(this))); |
| 1026 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1027 | content::BrowserAccessibilityState::GetInstance()->AddHistogramCallback( |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 1028 | base::Bind(&AccessibilityManager::UpdateChromeOSAccessibilityHistograms, |
| 1029 | base::Unretained(this))); |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1030 | |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1031 | extensions::ExtensionRegistry* registry = |
| 1032 | extensions::ExtensionRegistry::Get(profile); |
| 1033 | if (!extension_registry_observer_.IsObserving(registry)) |
| 1034 | extension_registry_observer_.Add(registry); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1035 | } |
| 1036 | |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 1037 | large_cursor_pref_handler_.HandleProfileChanged(profile_, profile); |
| 1038 | spoken_feedback_pref_handler_.HandleProfileChanged(profile_, profile); |
| 1039 | high_contrast_pref_handler_.HandleProfileChanged(profile_, profile); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 1040 | sticky_keys_pref_handler_.HandleProfileChanged(profile_, profile); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 1041 | autoclick_pref_handler_.HandleProfileChanged(profile_, profile); |
[email protected] | 84d652d | 2013-10-23 13:57:57 | [diff] [blame] | 1042 | autoclick_delay_pref_handler_.HandleProfileChanged(profile_, profile); |
[email protected] | 42b471f | 2014-01-31 20:31:29 | [diff] [blame] | 1043 | virtual_keyboard_pref_handler_.HandleProfileChanged(profile_, profile); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 1044 | mono_audio_pref_handler_.HandleProfileChanged(profile_, profile); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1045 | caret_highlight_pref_handler_.HandleProfileChanged(profile_, profile); |
| 1046 | cursor_highlight_pref_handler_.HandleProfileChanged(profile_, profile); |
| 1047 | focus_highlight_pref_handler_.HandleProfileChanged(profile_, profile); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 1048 | tap_dragging_pref_handler_.HandleProfileChanged(profile_, profile); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1049 | select_to_speak_pref_handler_.HandleProfileChanged(profile_, profile); |
| 1050 | switch_access_pref_handler_.HandleProfileChanged(profile_, profile); |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 1051 | |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 1052 | bool had_profile = (profile_ != NULL); |
| 1053 | profile_ = profile; |
| 1054 | |
| 1055 | if (!had_profile && profile) |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 1056 | CheckBrailleState(); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1057 | else |
| 1058 | UpdateBrailleImeState(); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 1059 | UpdateAlwaysShowMenuFromPref(); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1060 | UpdateSwitchAccessFromPref(); |
dmazzoni | 39d6d4b | 2016-03-29 22:18:00 | [diff] [blame] | 1061 | |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 1062 | // TODO(warx): reconcile to ash once the prefs registration above is moved to |
| 1063 | // ash. |
| 1064 | OnSpokenFeedbackChanged(); |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 1065 | OnSelectToSpeakChanged(); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1066 | } |
| 1067 | |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 1068 | void AccessibilityManager::ActiveUserChanged( |
| 1069 | const user_manager::User* active_user) { |
xiyuan | 8c6a411 | 2017-06-19 21:03:49 | [diff] [blame] | 1070 | if (active_user && active_user->is_profile_created()) |
| 1071 | SetProfile(ProfileManager::GetActiveUserProfile()); |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1072 | } |
| 1073 | |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 1074 | base::TimeDelta AccessibilityManager::PlayShutdownSound() { |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 1075 | if (!PlayEarcon(SOUND_SHUTDOWN, |
| 1076 | PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED)) { |
[email protected] | 4f011f1 | 2014-01-15 08:22:45 | [diff] [blame] | 1077 | return base::TimeDelta(); |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 1078 | } |
[email protected] | 4f011f1 | 2014-01-15 08:22:45 | [diff] [blame] | 1079 | return media::SoundsManager::Get()->GetDuration(SOUND_SHUTDOWN); |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 1080 | } |
| 1081 | |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 1082 | std::unique_ptr<AccessibilityStatusSubscription> |
| 1083 | AccessibilityManager::RegisterCallback(const AccessibilityStatusCallback& cb) { |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 1084 | return callback_list_.Add(cb); |
| 1085 | } |
| 1086 | |
| 1087 | void AccessibilityManager::NotifyAccessibilityStatusChanged( |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 1088 | const AccessibilityStatusEventDetails& details) { |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 1089 | callback_list_.Notify(details); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 1090 | |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 1091 | // TODO(crbug.com/594887): Fix for mash by moving pref into ash. |
| 1092 | if (GetAshConfig() == ash::Config::MASH) |
| 1093 | return; |
| 1094 | |
James Cook | ec14495 | 2017-09-01 00:05:16 | [diff] [blame] | 1095 | // Update system tray menu visibility. Prefs tracked inside ash handle their |
| 1096 | // own updates to avoid race conditions (pref updates are asynchronous between |
| 1097 | // chrome and ash). |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 1098 | if (details.notification_type == ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) { |
James Cook | 08e91dc | 2018-03-08 18:53:19 | [diff] [blame] | 1099 | ash::Shell::Get() |
| 1100 | ->accessibility_controller() |
| 1101 | ->NotifyAccessibilityStatusChanged(details.notify); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 1102 | } |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 1103 | } |
| 1104 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1105 | void AccessibilityManager::UpdateChromeOSAccessibilityHistograms() { |
| 1106 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSpokenFeedback", |
| 1107 | IsSpokenFeedbackEnabled()); |
| 1108 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosHighContrast", |
| 1109 | IsHighContrastEnabled()); |
| 1110 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosVirtualKeyboard", |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 1111 | IsVirtualKeyboardEnabled()); |
[email protected] | 7fb7ea4 | 2014-02-12 21:19:31 | [diff] [blame] | 1112 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosStickyKeys", IsStickyKeysEnabled()); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1113 | if (MagnificationManager::Get()) { |
James Cook | db81c767 | 2017-08-30 15:18:24 | [diff] [blame] | 1114 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosScreenMagnifier", |
| 1115 | MagnificationManager::Get()->IsMagnifierEnabled()); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1116 | } |
[email protected] | ca3a0a8 | 2013-06-18 06:52:12 | [diff] [blame] | 1117 | if (profile_) { |
| 1118 | const PrefService* const prefs = profile_->GetPrefs(); |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1119 | |
| 1120 | bool large_cursor_enabled = |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1121 | prefs->GetBoolean(ash::prefs::kAccessibilityLargeCursorEnabled); |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1122 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosLargeCursor", |
| 1123 | large_cursor_enabled); |
yawano | 92daff5 | 2017-04-21 06:34:28 | [diff] [blame] | 1124 | if (large_cursor_enabled) { |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1125 | UMA_HISTOGRAM_COUNTS_100( |
| 1126 | "Accessibility.CrosLargeCursorSize", |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1127 | prefs->GetInteger(ash::prefs::kAccessibilityLargeCursorDipSize)); |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1128 | } |
| 1129 | |
[email protected] | ca3a0a8 | 2013-06-18 06:52:12 | [diff] [blame] | 1130 | UMA_HISTOGRAM_BOOLEAN( |
| 1131 | "Accessibility.CrosAlwaysShowA11yMenu", |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1132 | prefs->GetBoolean(ash::prefs::kShouldAlwaysShowAccessibilityMenu)); |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1133 | |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 1134 | bool autoclick_enabled = |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1135 | prefs->GetBoolean(ash::prefs::kAccessibilityAutoclickEnabled); |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1136 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosAutoclick", autoclick_enabled); |
| 1137 | if (autoclick_enabled) { |
| 1138 | // We only want to log the autoclick delay if the user has actually |
| 1139 | // enabled autoclick. |
| 1140 | UMA_HISTOGRAM_CUSTOM_TIMES( |
| 1141 | "Accessibility.CrosAutoclickDelay", |
| 1142 | base::TimeDelta::FromMilliseconds( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1143 | prefs->GetInteger(ash::prefs::kAccessibilityAutoclickDelayMs)), |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1144 | base::TimeDelta::FromMilliseconds(1), |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1145 | base::TimeDelta::FromMilliseconds(3000), 50); |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1146 | } |
[email protected] | ca3a0a8 | 2013-06-18 06:52:12 | [diff] [blame] | 1147 | } |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1148 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosCaretHighlight", |
| 1149 | IsCaretHighlightEnabled()); |
| 1150 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosCursorHighlight", |
| 1151 | IsCursorHighlightEnabled()); |
| 1152 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosFocusHighlight", |
| 1153 | IsFocusHighlightEnabled()); |
| 1154 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSelectToSpeak", |
| 1155 | IsSelectToSpeakEnabled()); |
| 1156 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSwitchAccess", |
| 1157 | IsSwitchAccessEnabled()); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | void AccessibilityManager::Observe( |
| 1161 | int type, |
| 1162 | const content::NotificationSource& source, |
| 1163 | const content::NotificationDetails& details) { |
| 1164 | switch (type) { |
[email protected] | 093d9ba | 2013-07-23 19:26:21 | [diff] [blame] | 1165 | case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
[email protected] | 9cf54f36 | 2013-07-01 07:28:12 | [diff] [blame] | 1166 | // Update |profile_| when entering the login screen. |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1167 | Profile* profile = ProfileManager::GetActiveUserProfile(); |
[email protected] | d888cdc | 2013-06-24 17:06:20 | [diff] [blame] | 1168 | if (ProfileHelper::IsSigninProfile(profile)) |
| 1169 | SetProfile(profile); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1170 | break; |
[email protected] | d888cdc | 2013-06-24 17:06:20 | [diff] [blame] | 1171 | } |
Yuki Awano | d59b649 | 2017-07-28 00:52:11 | [diff] [blame] | 1172 | case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: |
| 1173 | // Update |profile_| when login user profile is prepared. |
| 1174 | // NOTIFICATION_SESSION_STARTED is not fired from UserSessionManager, but |
| 1175 | // profile may be changed by UserSessionManager in OOBE flow. |
| 1176 | SetProfile(ProfileManager::GetActiveUserProfile()); |
| 1177 | break; |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 1178 | case chrome::NOTIFICATION_SESSION_STARTED: |
| 1179 | // Update |profile_| when entering a session. |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1180 | SetProfile(ProfileManager::GetActiveUserProfile()); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1181 | |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1182 | // Add a session state observer to be able to monitor session changes. |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 1183 | if (!session_state_observer_.get()) |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1184 | session_state_observer_.reset( |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 1185 | new user_manager::ScopedUserSessionStateObserver(this)); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1186 | break; |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1187 | case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 1188 | // Update |profile_| when exiting a session or shutting down. |
| 1189 | Profile* profile = content::Source<Profile>(source).ptr(); |
| 1190 | if (profile_ == profile) |
| 1191 | SetProfile(NULL); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1192 | break; |
| 1193 | } |
David Tseng | 768d798 | 2017-12-21 00:20:11 | [diff] [blame] | 1194 | case chrome::NOTIFICATION_APP_TERMINATING: { |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 1195 | app_terminating_ = true; |
David Tseng | 768d798 | 2017-12-21 00:20:11 | [diff] [blame] | 1196 | break; |
| 1197 | } |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 1198 | case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { |
| 1199 | content::FocusedNodeDetails* node_details = |
| 1200 | content::Details<content::FocusedNodeDetails>(details).ptr(); |
| 1201 | accessibility_controller_->SetFocusHighlightRect( |
| 1202 | node_details->node_bounds_in_screen); |
| 1203 | break; |
| 1204 | } |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1208 | void AccessibilityManager::OnBrailleDisplayStateChanged( |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 1209 | const DisplayState& display_state) { |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 1210 | braille_display_connected_ = display_state.available; |
Qiang Xu | 797a8e7 | 2018-01-21 11:19:08 | [diff] [blame] | 1211 | accessibility_controller_->BrailleDisplayStateChanged( |
| 1212 | braille_display_connected_); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1213 | UpdateBrailleImeState(); |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 1214 | } |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1215 | |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1216 | void AccessibilityManager::OnBrailleKeyEvent(const KeyEvent& event) { |
| 1217 | // Ensure the braille IME is active on braille keyboard (dots) input. |
| 1218 | if ((event.command == |
| 1219 | extensions::api::braille_display_private::KEY_COMMAND_DOTS) && |
| 1220 | !braille_ime_current_) { |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 1221 | input_method::InputMethodManager::Get() |
| 1222 | ->GetActiveIMEState() |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 1223 | ->ChangeInputMethod(extension_ime_util::kBrailleImeEngineId, |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 1224 | false /* show_message */); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1228 | void AccessibilityManager::OnExtensionUnloaded( |
| 1229 | content::BrowserContext* browser_context, |
| 1230 | const extensions::Extension* extension, |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 1231 | extensions::UnloadedExtensionReason reason) { |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1232 | if (extension->id() == keyboard_listener_extension_id_) { |
| 1233 | keyboard_listener_extension_id_ = std::string(); |
| 1234 | keyboard_listener_capture_ = false; |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | void AccessibilityManager::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 1239 | extension_registry_observer_.Remove(registry); |
| 1240 | } |
| 1241 | |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1242 | void AccessibilityManager::PostLoadChromeVox() { |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 1243 | // In browser_tests loading the ChromeVox extension can race with shutdown. |
| 1244 | // http://crbug.com/801700 |
| 1245 | if (app_terminating_) |
| 1246 | return; |
| 1247 | |
[email protected] | ee8bbd97 | 2014-02-03 06:52:47 | [diff] [blame] | 1248 | // Do any setup work needed immediately after ChromeVox actually loads. |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 1249 | PlayEarcon(SOUND_SPOKEN_FEEDBACK_ENABLED, PlaySoundOption::ALWAYS); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1250 | |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 1251 | extensions::EventRouter* event_router = |
| 1252 | extensions::EventRouter::Get(profile_); |
| 1253 | CHECK(event_router); |
dtseng | 703a204 | 2015-01-22 17:46:51 | [diff] [blame] | 1254 | |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 1255 | std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
| 1256 | std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 1257 | extensions::events::ACCESSIBILITY_PRIVATE_ON_INTRODUCE_CHROME_VOX, |
| 1258 | extensions::api::accessibility_private::OnIntroduceChromeVox::kEventName, |
| 1259 | std::move(event_args))); |
| 1260 | event_router->DispatchEventWithLazyListener( |
| 1261 | extension_misc::kChromeVoxExtensionId, std::move(event)); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1262 | |
James Cook | 769799b | 2018-03-12 16:59:04 | [diff] [blame] | 1263 | if (!chromevox_panel_) { |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 1264 | chromevox_panel_ = new ChromeVoxPanel( |
| 1265 | profile_, |
| 1266 | session_manager::SessionManager::Get()->IsUserSessionBlocked()); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1267 | chromevox_panel_widget_observer_.reset( |
| 1268 | new ChromeVoxPanelWidgetObserver(chromevox_panel_->GetWidget(), this)); |
| 1269 | } |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 1270 | |
| 1271 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 1272 | ::switches::kEnableAudioFocus)) { |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 1273 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 1274 | ::switches::kEnableAudioFocus); |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 1275 | } |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1276 | } |
| 1277 | |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1278 | void AccessibilityManager::PostUnloadChromeVox() { |
[email protected] | 9d6c9136 | 2013-12-07 21:56:27 | [diff] [blame] | 1279 | // Do any teardown work needed immediately after ChromeVox actually unloads. |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 1280 | PlayEarcon(SOUND_SPOKEN_FEEDBACK_DISABLED, PlaySoundOption::ALWAYS); |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 1281 | |
dmazzoni | fb33d59 | 2014-10-30 19:26:54 | [diff] [blame] | 1282 | // Clear the accessibility focus ring. |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 1283 | SetFocusRing(std::vector<gfx::Rect>(), |
| 1284 | ash::mojom::FocusRingBehavior::PERSIST_FOCUS_RING); |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1285 | |
| 1286 | if (chromevox_panel_) { |
| 1287 | chromevox_panel_->Close(); |
| 1288 | chromevox_panel_ = nullptr; |
| 1289 | } |
dtseng | 3a17f21 | 2017-03-25 08:58:52 | [diff] [blame] | 1290 | |
| 1291 | // In case the user darkened the screen, undarken it now. |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 1292 | SetDarkenScreen(false); |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 1293 | |
| 1294 | // Stop speech. |
| 1295 | TtsController::GetInstance()->Stop(); |
[email protected] | 9d6c9136 | 2013-12-07 21:56:27 | [diff] [blame] | 1296 | } |
| 1297 | |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1298 | void AccessibilityManager::PostSwitchChromeVoxProfile() { |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 1299 | ReloadChromeVoxPanel(); |
| 1300 | } |
| 1301 | |
| 1302 | void AccessibilityManager::ReloadChromeVoxPanel() { |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1303 | if (chromevox_panel_) { |
James Cook | 769799b | 2018-03-12 16:59:04 | [diff] [blame] | 1304 | chromevox_panel_->CloseNow(); |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1305 | chromevox_panel_ = nullptr; |
| 1306 | } |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 1307 | chromevox_panel_ = new ChromeVoxPanel( |
| 1308 | profile_, session_manager::SessionManager::Get()->IsUserSessionBlocked()); |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1309 | chromevox_panel_widget_observer_.reset( |
| 1310 | new ChromeVoxPanelWidgetObserver(chromevox_panel_->GetWidget(), this)); |
| 1311 | } |
| 1312 | |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1313 | void AccessibilityManager::OnChromeVoxPanelClosing() { |
jamescook | 788b4fc | 2017-05-18 16:16:06 | [diff] [blame] | 1314 | chromevox_panel_widget_observer_.reset(); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1315 | chromevox_panel_ = nullptr; |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void AccessibilityManager::OnChromeVoxPanelDestroying() { |
| 1319 | chromevox_panel_widget_observer_.reset(nullptr); |
| 1320 | chromevox_panel_ = nullptr; |
| 1321 | } |
| 1322 | |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 1323 | void AccessibilityManager::PostUnloadSelectToSpeak() { |
| 1324 | // Do any teardown work needed immediately after Select-to-Speak actually |
| 1325 | // unloads. |
| 1326 | |
| 1327 | // Clear the accessibility focus ring and highlight. |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 1328 | HideFocusRing(); |
| 1329 | HideHighlights(); |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 1330 | |
| 1331 | // Stop speech. |
| 1332 | TtsController::GetInstance()->Stop(); |
| 1333 | } |
| 1334 | |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1335 | void AccessibilityManager::SetKeyboardListenerExtensionId( |
| 1336 | const std::string& id, |
| 1337 | content::BrowserContext* context) { |
| 1338 | keyboard_listener_extension_id_ = id; |
| 1339 | |
| 1340 | extensions::ExtensionRegistry* registry = |
| 1341 | extensions::ExtensionRegistry::Get(context); |
| 1342 | if (!extension_registry_observer_.IsObserving(registry) && !id.empty()) |
| 1343 | extension_registry_observer_.Add(registry); |
| 1344 | } |
| 1345 | |
elichtenberg | a108c8a | 2017-06-02 21:13:19 | [diff] [blame] | 1346 | void AccessibilityManager::SetSwitchAccessKeys(const std::set<int>& key_codes) { |
| 1347 | if (switch_access_enabled_) |
| 1348 | switch_access_event_handler_->SetKeysToCapture(key_codes); |
| 1349 | } |
| 1350 | |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 1351 | void AccessibilityManager::ToggleDictation() { |
| 1352 | if (!profile_) |
| 1353 | return; |
| 1354 | |
| 1355 | if (!dictation_.get()) |
| 1356 | dictation_ = std::make_unique<DictationChromeos>(profile_); |
| 1357 | |
| 1358 | dictation_->OnToggleDictation(); |
| 1359 | } |
| 1360 | |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 1361 | void AccessibilityManager::SetFocusRingColor(SkColor color) { |
| 1362 | accessibility_focus_ring_controller_->SetFocusRingColor(color); |
| 1363 | } |
| 1364 | |
| 1365 | void AccessibilityManager::ResetFocusRingColor() { |
| 1366 | accessibility_focus_ring_controller_->ResetFocusRingColor(); |
| 1367 | } |
| 1368 | |
| 1369 | void AccessibilityManager::SetFocusRing( |
| 1370 | const std::vector<gfx::Rect>& rects_in_screen, |
| 1371 | ash::mojom::FocusRingBehavior focus_ring_behavior) { |
| 1372 | accessibility_focus_ring_controller_->SetFocusRing(rects_in_screen, |
| 1373 | focus_ring_behavior); |
| 1374 | if (focus_ring_observer_for_test_) |
| 1375 | focus_ring_observer_for_test_.Run(); |
| 1376 | } |
| 1377 | |
| 1378 | void AccessibilityManager::HideFocusRing() { |
| 1379 | accessibility_focus_ring_controller_->HideFocusRing(); |
| 1380 | if (focus_ring_observer_for_test_) |
| 1381 | focus_ring_observer_for_test_.Run(); |
| 1382 | } |
| 1383 | |
| 1384 | void AccessibilityManager::SetHighlights( |
| 1385 | const std::vector<gfx::Rect>& rects_in_screen, |
| 1386 | SkColor color) { |
| 1387 | accessibility_focus_ring_controller_->SetHighlights(rects_in_screen, color); |
| 1388 | } |
| 1389 | |
| 1390 | void AccessibilityManager::HideHighlights() { |
| 1391 | accessibility_focus_ring_controller_->HideHighlights(); |
| 1392 | } |
| 1393 | |
Qiang Xu | 797a8e7 | 2018-01-21 11:19:08 | [diff] [blame] | 1394 | void AccessibilityManager::SetProfileForTest(Profile* profile) { |
| 1395 | SetProfile(profile); |
| 1396 | } |
| 1397 | |
| 1398 | // static |
| 1399 | void AccessibilityManager::SetBrailleControllerForTest( |
| 1400 | BrailleController* controller) { |
| 1401 | g_braille_controller_for_test = controller; |
| 1402 | } |
| 1403 | |
| 1404 | void AccessibilityManager::FlushForTesting() { |
| 1405 | accessibility_controller_.FlushForTesting(); |
| 1406 | } |
| 1407 | |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame^] | 1408 | void AccessibilityManager::SetFocusRingObserverForTest( |
| 1409 | base::RepeatingCallback<void()> observer) { |
| 1410 | focus_ring_observer_for_test_ = observer; |
| 1411 | } |
| 1412 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1413 | } // namespace chromeos |