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