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/metrics/user_metrics_recorder.h" | 9 #include "ash/metrics/user_metrics_recorder.h" |
| 10 #include "ash/session_state_delegate.h" |
10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 12 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "ash/wm/event_rewriter_event_filter.h" | 13 #include "ash/wm/event_rewriter_event_filter.h" |
13 #include "ash/wm/sticky_keys.h" | 14 #include "ash/wm/sticky_keys.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/path_service.h" | 18 #include "base/path_service.h" |
18 #include "base/prefs/pref_member.h" | 19 #include "base/prefs/pref_member.h" |
19 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 content::NotificationService::AllSources()); | 316 content::NotificationService::AllSources()); |
316 notification_registrar_.Add(this, | 317 notification_registrar_.Add(this, |
317 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 318 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
318 content::NotificationService::AllSources()); | 319 content::NotificationService::AllSources()); |
319 notification_registrar_.Add(this, | 320 notification_registrar_.Add(this, |
320 chrome::NOTIFICATION_EXTENSION_REMOVED, | 321 chrome::NOTIFICATION_EXTENSION_REMOVED, |
321 content::NotificationService::AllSources()); | 322 content::NotificationService::AllSources()); |
322 notification_registrar_.Add(this, | 323 notification_registrar_.Add(this, |
323 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 324 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
324 content::NotificationService::AllSources()); | 325 content::NotificationService::AllSources()); |
| 326 |
325 GetBrailleController()->AddObserver(this); | 327 GetBrailleController()->AddObserver(this); |
326 | 328 |
327 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 329 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
328 media::SoundsManager* manager = media::SoundsManager::Get(); | 330 media::SoundsManager* manager = media::SoundsManager::Get(); |
329 manager->Initialize(SOUND_SHUTDOWN, | 331 manager->Initialize(SOUND_SHUTDOWN, |
330 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); | 332 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); |
331 manager->Initialize( | 333 manager->Initialize( |
332 SOUND_SPOKEN_FEEDBACK_ENABLED, | 334 SOUND_SPOKEN_FEEDBACK_ENABLED, |
333 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); | 335 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); |
334 manager->Initialize( | 336 manager->Initialize( |
335 SOUND_SPOKEN_FEEDBACK_DISABLED, | 337 SOUND_SPOKEN_FEEDBACK_DISABLED, |
336 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); | 338 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); |
337 } | 339 } |
338 | 340 |
339 AccessibilityManager::~AccessibilityManager() { | 341 AccessibilityManager::~AccessibilityManager() { |
340 CHECK(this == g_accessibility_manager); | 342 CHECK(this == g_accessibility_manager); |
341 | 343 |
342 // Component extensions don't always notify us when they're unloaded. Ensure | 344 // Component extensions don't always notify us when they're unloaded. Ensure |
343 // we clean up ChromeVox observers here. | 345 // we clean up ChromeVox observers here. |
344 if (profile_) { | 346 if (profile_) { |
345 extensions::ExtensionSystem::Get(profile_)-> | 347 extensions::ExtensionSystem::Get(profile_)-> |
346 event_router()->UnregisterObserver(this); | 348 event_router()->UnregisterObserver(this); |
347 } | 349 } |
348 } | 350 } |
349 | 351 |
| 352 bool AccessibilityManager::ShouldShowAccessibilityMenu() { |
| 353 // If any of the loaded profiles has an accessibility feature turned on - or |
| 354 // enforced to always show the menu - we return true to show the menu. |
| 355 std::vector<Profile*> profiles = |
| 356 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 357 for (std::vector<Profile*>::iterator it = profiles.begin(); |
| 358 it != profiles.end(); |
| 359 ++it) { |
| 360 PrefService* pref_service = (*it)->GetPrefs(); |
| 361 if (pref_service->GetBoolean(prefs::kStickyKeysEnabled) || |
| 362 pref_service->GetBoolean(prefs::kLargeCursorEnabled) || |
| 363 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled) || |
| 364 pref_service->GetBoolean(prefs::kHighContrastEnabled) || |
| 365 pref_service->GetBoolean(prefs::kAutoclickEnabled) || |
| 366 pref_service->GetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu) || |
| 367 pref_service->GetBoolean(prefs::kScreenMagnifierEnabled)) |
| 368 return true; |
| 369 } |
| 370 return false; |
| 371 } |
| 372 |
350 void AccessibilityManager::EnableLargeCursor(bool enabled) { | 373 void AccessibilityManager::EnableLargeCursor(bool enabled) { |
351 if (!profile_) | 374 if (!profile_) |
352 return; | 375 return; |
353 | 376 |
354 PrefService* pref_service = profile_->GetPrefs(); | 377 PrefService* pref_service = profile_->GetPrefs(); |
355 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); | 378 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); |
356 pref_service->CommitPendingWrite(); | 379 pref_service->CommitPendingWrite(); |
357 } | 380 } |
358 | 381 |
359 void AccessibilityManager::UpdateLargeCursorFromPref() { | 382 void AccessibilityManager::UpdateLargeCursorFromPref() { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 | 755 |
733 profile_ = profile; | 756 profile_ = profile; |
734 UpdateLargeCursorFromPref(); | 757 UpdateLargeCursorFromPref(); |
735 UpdateStickyKeysFromPref(); | 758 UpdateStickyKeysFromPref(); |
736 UpdateSpokenFeedbackFromPref(); | 759 UpdateSpokenFeedbackFromPref(); |
737 UpdateHighContrastFromPref(); | 760 UpdateHighContrastFromPref(); |
738 UpdateAutoclickFromPref(); | 761 UpdateAutoclickFromPref(); |
739 UpdateAutoclickDelayFromPref(); | 762 UpdateAutoclickDelayFromPref(); |
740 } | 763 } |
741 | 764 |
| 765 void AccessibilityManager::ActiveUserChanged(const std::string& user_id) { |
| 766 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 767 } |
| 768 |
742 void AccessibilityManager::SetProfileForTest(Profile* profile) { | 769 void AccessibilityManager::SetProfileForTest(Profile* profile) { |
743 SetProfile(profile); | 770 SetProfile(profile); |
744 } | 771 } |
745 | 772 |
746 void AccessibilityManager::SetBrailleControllerForTest( | 773 void AccessibilityManager::SetBrailleControllerForTest( |
747 BrailleController* controller) { | 774 BrailleController* controller) { |
748 g_braille_controller_for_test = controller; | 775 g_braille_controller_for_test = controller; |
749 } | 776 } |
750 | 777 |
751 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { | 778 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 } | 827 } |
801 } | 828 } |
802 | 829 |
803 void AccessibilityManager::Observe( | 830 void AccessibilityManager::Observe( |
804 int type, | 831 int type, |
805 const content::NotificationSource& source, | 832 const content::NotificationSource& source, |
806 const content::NotificationDetails& details) { | 833 const content::NotificationDetails& details) { |
807 switch (type) { | 834 switch (type) { |
808 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 835 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
809 // Update |profile_| when entering the login screen. | 836 // Update |profile_| when entering the login screen. |
810 Profile* profile = ProfileManager::GetDefaultProfile(); | 837 Profile* profile = ProfileManager::GetActiveUserProfile(); |
811 if (ProfileHelper::IsSigninProfile(profile)) | 838 if (ProfileHelper::IsSigninProfile(profile)) |
812 SetProfile(profile); | 839 SetProfile(profile); |
813 break; | 840 break; |
814 } | 841 } |
815 case chrome::NOTIFICATION_SESSION_STARTED: | 842 case chrome::NOTIFICATION_SESSION_STARTED: |
816 // Update |profile_| when entering a session. | 843 // Update |profile_| when entering a session. |
817 SetProfile(ProfileManager::GetDefaultProfile()); | 844 SetProfile(ProfileManager::GetActiveUserProfile()); |
818 | 845 |
819 // Ensure ChromeVox makes announcements at the start of new sessions. | 846 // Ensure ChromeVox makes announcements at the start of new sessions. |
820 should_speak_chrome_vox_announcements_on_user_screen_ = true; | 847 should_speak_chrome_vox_announcements_on_user_screen_ = true; |
| 848 |
| 849 // Add a session state observer to be able to monitor session changes. |
| 850 if (!session_state_observer_.get() && ash::Shell::HasInstance()) |
| 851 session_state_observer_.reset( |
| 852 new ash::ScopedSessionStateObserver(this)); |
821 break; | 853 break; |
822 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 854 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
823 // Update |profile_| when exiting a session or shutting down. | 855 // Update |profile_| when exiting a session or shutting down. |
824 Profile* profile = content::Source<Profile>(source).ptr(); | 856 Profile* profile = content::Source<Profile>(source).ptr(); |
825 if (profile_ == profile) | 857 if (profile_ == profile) |
826 SetProfile(NULL); | 858 SetProfile(NULL); |
827 break; | 859 break; |
828 } | 860 } |
829 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { | 861 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
830 bool is_screen_locked = *content::Details<bool>(details).ptr(); | 862 bool is_screen_locked = *content::Details<bool>(details).ptr(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 event_router()->UnregisterObserver(this); | 954 event_router()->UnregisterObserver(this); |
923 } | 955 } |
924 } | 956 } |
925 | 957 |
926 void AccessibilityManager::PlaySound(int sound_key) const { | 958 void AccessibilityManager::PlaySound(int sound_key) const { |
927 if (system_sounds_enabled_) | 959 if (system_sounds_enabled_) |
928 media::SoundsManager::Get()->Play(sound_key); | 960 media::SoundsManager::Get()->Play(sound_key); |
929 } | 961 } |
930 | 962 |
931 } // namespace chromeos | 963 } // namespace chromeos |
OLD | NEW |