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