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