Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 6 | 6 |
| 7 #include "ash/autoclick/autoclick_controller.h" | 7 #include "ash/autoclick/autoclick_controller.h" |
| 8 #include "ash/high_contrast/high_contrast_controller.h" | 8 #include "ash/high_contrast/high_contrast_controller.h" |
| 9 #include "ash/session_state_delegate.h" | |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
| 11 #include "ash/wm/event_rewriter_event_filter.h" | 12 #include "ash/wm/event_rewriter_event_filter.h" |
| 12 #include "ash/wm/sticky_keys.h" | 13 #include "ash/wm/sticky_keys.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_member.h" | 17 #include "base/prefs/pref_member.h" |
| 17 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 autoclick_delay_pref_handler_(prefs::kAutoclickDelayMs), | 286 autoclick_delay_pref_handler_(prefs::kAutoclickDelayMs), |
| 286 large_cursor_enabled_(false), | 287 large_cursor_enabled_(false), |
| 287 sticky_keys_enabled_(false), | 288 sticky_keys_enabled_(false), |
| 288 spoken_feedback_enabled_(false), | 289 spoken_feedback_enabled_(false), |
| 289 high_contrast_enabled_(false), | 290 high_contrast_enabled_(false), |
| 290 autoclick_enabled_(false), | 291 autoclick_enabled_(false), |
| 291 autoclick_delay_ms_(ash::AutoclickController::kDefaultAutoclickDelayMs), | 292 autoclick_delay_ms_(ash::AutoclickController::kDefaultAutoclickDelayMs), |
| 292 spoken_feedback_notification_(ash::A11Y_NOTIFICATION_NONE), | 293 spoken_feedback_notification_(ash::A11Y_NOTIFICATION_NONE), |
| 293 weak_ptr_factory_(this), | 294 weak_ptr_factory_(this), |
| 294 should_speak_chrome_vox_announcements_on_user_screen_(true), | 295 should_speak_chrome_vox_announcements_on_user_screen_(true), |
| 296 session_state_observer_installed_(false), | |
| 295 system_sounds_enabled_(false) { | 297 system_sounds_enabled_(false) { |
| 296 notification_registrar_.Add(this, | 298 notification_registrar_.Add(this, |
| 297 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 299 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 298 content::NotificationService::AllSources()); | 300 content::NotificationService::AllSources()); |
| 299 notification_registrar_.Add(this, | 301 notification_registrar_.Add(this, |
| 300 chrome::NOTIFICATION_SESSION_STARTED, | 302 chrome::NOTIFICATION_SESSION_STARTED, |
| 301 content::NotificationService::AllSources()); | 303 content::NotificationService::AllSources()); |
| 302 notification_registrar_.Add(this, | 304 notification_registrar_.Add(this, |
| 303 chrome::NOTIFICATION_PROFILE_DESTROYED, | 305 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 304 content::NotificationService::AllSources()); | 306 content::NotificationService::AllSources()); |
| 305 notification_registrar_.Add(this, | 307 notification_registrar_.Add(this, |
| 306 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 308 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 307 content::NotificationService::AllSources()); | 309 content::NotificationService::AllSources()); |
| 308 notification_registrar_.Add(this, | 310 notification_registrar_.Add(this, |
| 309 chrome::NOTIFICATION_EXTENSION_REMOVED, | 311 chrome::NOTIFICATION_EXTENSION_REMOVED, |
| 310 content::NotificationService::AllSources()); | 312 content::NotificationService::AllSources()); |
| 311 notification_registrar_.Add(this, | 313 notification_registrar_.Add(this, |
| 312 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 314 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 313 content::NotificationService::AllSources()); | 315 content::NotificationService::AllSources()); |
| 316 | |
| 317 // Sent when a chromium os user logs in. | |
| 318 // The details are a chromeos::User object. | |
|
Peter Lundblad
2013/12/12 20:53:00
Misplaced comment?
Mr4D (OOO till 08-26)
2013/12/12 21:01:31
In deed. Done.
| |
| 314 GetBrailleController()->AddObserver(this); | 319 GetBrailleController()->AddObserver(this); |
| 315 | 320 |
| 316 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 321 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 317 media::SoundsManager* manager = media::SoundsManager::Get(); | 322 media::SoundsManager* manager = media::SoundsManager::Get(); |
| 318 manager->Initialize(SOUND_SHUTDOWN, | 323 manager->Initialize(SOUND_SHUTDOWN, |
| 319 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); | 324 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); |
| 320 manager->Initialize( | 325 manager->Initialize( |
| 321 SOUND_SPOKEN_FEEDBACK_ENABLED, | 326 SOUND_SPOKEN_FEEDBACK_ENABLED, |
| 322 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); | 327 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); |
| 323 manager->Initialize( | 328 manager->Initialize( |
| 324 SOUND_SPOKEN_FEEDBACK_DISABLED, | 329 SOUND_SPOKEN_FEEDBACK_DISABLED, |
| 325 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); | 330 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); |
| 326 } | 331 } |
| 327 | 332 |
| 328 AccessibilityManager::~AccessibilityManager() { | 333 AccessibilityManager::~AccessibilityManager() { |
| 329 CHECK(this == g_accessibility_manager); | 334 CHECK(this == g_accessibility_manager); |
| 330 | 335 |
| 331 // Component extensions don't always notify us when they're unloaded. Ensure | 336 // Component extensions don't always notify us when they're unloaded. Ensure |
| 332 // we clean up ChromeVox observers here. | 337 // we clean up ChromeVox observers here. |
| 333 if (profile_) { | 338 if (profile_) { |
| 334 extensions::ExtensionSystem::Get(profile_)-> | 339 extensions::ExtensionSystem::Get(profile_)-> |
| 335 event_router()->UnregisterObserver(this); | 340 event_router()->UnregisterObserver(this); |
| 336 } | 341 } |
| 342 | |
| 343 if (session_state_observer_installed_) | |
| 344 ash::Shell::GetInstance()->session_state_delegate()-> | |
| 345 RemoveSessionStateObserver(this); | |
| 346 } | |
| 347 | |
| 348 bool AccessibilityManager::ShouldShowAccessibilityMenu() { | |
| 349 // If any of the loaded profiles has an accessibility feature turned on, we | |
| 350 // should return true to show the menu. | |
| 351 std::vector<Profile*> list = | |
|
Peter Lundblad
2013/12/12 20:53:00
nit: slightly confusing to call a vector a list:-)
Mr4D (OOO till 08-26)
2013/12/12 21:01:31
Done.
| |
| 352 g_browser_process->profile_manager()->GetLoadedProfiles(); | |
| 353 for (std::vector<Profile*>::iterator it = list.begin(); | |
| 354 it != list.end(); | |
| 355 ++it) { | |
| 356 PrefService* pref_service = (*it)->GetPrefs(); | |
| 357 if (pref_service->GetBoolean(prefs::kStickyKeysEnabled) || | |
| 358 pref_service->GetBoolean(prefs::kLargeCursorEnabled) || | |
| 359 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled) || | |
| 360 pref_service->GetBoolean(prefs::kHighContrastEnabled) || | |
| 361 pref_service->GetBoolean(prefs::kAutoclickEnabled) || | |
| 362 pref_service->GetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu) || | |
| 363 pref_service->GetBoolean(prefs::kScreenMagnifierEnabled)) | |
| 364 return true; | |
| 365 } | |
| 366 return false; | |
| 337 } | 367 } |
| 338 | 368 |
| 339 void AccessibilityManager::EnableLargeCursor(bool enabled) { | 369 void AccessibilityManager::EnableLargeCursor(bool enabled) { |
| 340 if (!profile_) | 370 if (!profile_) |
| 341 return; | 371 return; |
| 342 | 372 |
| 343 PrefService* pref_service = profile_->GetPrefs(); | 373 PrefService* pref_service = profile_->GetPrefs(); |
| 344 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); | 374 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); |
| 345 pref_service->CommitPendingWrite(); | 375 pref_service->CommitPendingWrite(); |
| 346 } | 376 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 | 747 |
| 718 profile_ = profile; | 748 profile_ = profile; |
| 719 UpdateLargeCursorFromPref(); | 749 UpdateLargeCursorFromPref(); |
| 720 UpdateStickyKeysFromPref(); | 750 UpdateStickyKeysFromPref(); |
| 721 UpdateSpokenFeedbackFromPref(); | 751 UpdateSpokenFeedbackFromPref(); |
| 722 UpdateHighContrastFromPref(); | 752 UpdateHighContrastFromPref(); |
| 723 UpdateAutoclickFromPref(); | 753 UpdateAutoclickFromPref(); |
| 724 UpdateAutoclickDelayFromPref(); | 754 UpdateAutoclickDelayFromPref(); |
| 725 } | 755 } |
| 726 | 756 |
| 757 void AccessibilityManager::ActiveUserChanged(const std::string& user_id) { | |
| 758 SetProfile(ProfileManager::GetActiveUserProfile()); | |
| 759 } | |
| 760 | |
| 727 void AccessibilityManager::SetProfileForTest(Profile* profile) { | 761 void AccessibilityManager::SetProfileForTest(Profile* profile) { |
| 728 SetProfile(profile); | 762 SetProfile(profile); |
| 729 } | 763 } |
| 730 | 764 |
| 731 void AccessibilityManager::SetBrailleControllerForTest( | 765 void AccessibilityManager::SetBrailleControllerForTest( |
| 732 BrailleController* controller) { | 766 BrailleController* controller) { |
| 733 g_braille_controller_for_test = controller; | 767 g_braille_controller_for_test = controller; |
| 734 } | 768 } |
| 735 | 769 |
| 736 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { | 770 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 } | 819 } |
| 786 } | 820 } |
| 787 | 821 |
| 788 void AccessibilityManager::Observe( | 822 void AccessibilityManager::Observe( |
| 789 int type, | 823 int type, |
| 790 const content::NotificationSource& source, | 824 const content::NotificationSource& source, |
| 791 const content::NotificationDetails& details) { | 825 const content::NotificationDetails& details) { |
| 792 switch (type) { | 826 switch (type) { |
| 793 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 827 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
| 794 // Update |profile_| when entering the login screen. | 828 // Update |profile_| when entering the login screen. |
| 795 Profile* profile = ProfileManager::GetDefaultProfile(); | 829 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 796 if (ProfileHelper::IsSigninProfile(profile)) | 830 if (ProfileHelper::IsSigninProfile(profile)) |
| 797 SetProfile(profile); | 831 SetProfile(profile); |
| 798 break; | 832 break; |
| 799 } | 833 } |
| 800 case chrome::NOTIFICATION_SESSION_STARTED: | 834 case chrome::NOTIFICATION_SESSION_STARTED: |
| 801 // Update |profile_| when entering a session. | 835 // Update |profile_| when entering a session. |
| 802 SetProfile(ProfileManager::GetDefaultProfile()); | 836 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 803 | 837 |
| 804 // Ensure ChromeVox makes announcements at the start of new sessions. | 838 // Ensure ChromeVox makes announcements at the start of new sessions. |
| 805 should_speak_chrome_vox_announcements_on_user_screen_ = true; | 839 should_speak_chrome_vox_announcements_on_user_screen_ = true; |
| 840 | |
| 841 // Add a session state observer to be able to monitor session changes. | |
| 842 if (!session_state_observer_installed_ && ash::Shell::HasInstance()) { | |
| 843 session_state_observer_installed_ = true; | |
| 844 ash::Shell::GetInstance()->session_state_delegate()-> | |
| 845 AddSessionStateObserver(this); | |
| 846 } | |
| 806 break; | 847 break; |
| 807 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 848 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 808 // Update |profile_| when exiting a session or shutting down. | 849 // Update |profile_| when exiting a session or shutting down. |
| 809 Profile* profile = content::Source<Profile>(source).ptr(); | 850 Profile* profile = content::Source<Profile>(source).ptr(); |
| 810 if (profile_ == profile) | 851 if (profile_ == profile) |
| 811 SetProfile(NULL); | 852 SetProfile(NULL); |
| 812 break; | 853 break; |
| 813 } | 854 } |
| 814 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { | 855 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
| 815 bool is_screen_locked = *content::Details<bool>(details).ptr(); | 856 bool is_screen_locked = *content::Details<bool>(details).ptr(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 event_router()->UnregisterObserver(this); | 948 event_router()->UnregisterObserver(this); |
| 908 } | 949 } |
| 909 } | 950 } |
| 910 | 951 |
| 911 void AccessibilityManager::PlaySound(int sound_key) const { | 952 void AccessibilityManager::PlaySound(int sound_key) const { |
| 912 if (system_sounds_enabled_) | 953 if (system_sounds_enabled_) |
| 913 media::SoundsManager::Get()->Play(sound_key); | 954 media::SoundsManager::Get()->Play(sound_key); |
| 914 } | 955 } |
| 915 | 956 |
| 916 } // namespace chromeos | 957 } // namespace chromeos |
| OLD | NEW |