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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void UnloadChromeVoxExtension(Profile* profile) { | 201 void UnloadChromeVoxExtension(Profile* profile) { |
201 base::FilePath path = GetChromeVoxPath(); | 202 base::FilePath path = GetChromeVoxPath(); |
202 ExtensionService* extension_service = | 203 ExtensionService* extension_service = |
203 extensions::ExtensionSystem::Get(profile)->extension_service(); | 204 extensions::ExtensionSystem::Get(profile)->extension_service(); |
204 extension_service->component_loader()->Remove(path); | 205 extension_service->component_loader()->Remove(path); |
205 } | 206 } |
206 | 207 |
207 } // namespace | 208 } // namespace |
208 | 209 |
209 /////////////////////////////////////////////////////////////////////////////// | 210 /////////////////////////////////////////////////////////////////////////////// |
| 211 // ScopedSessionStateObserver |
| 212 |
| 213 ScopedSessionStateObserver::ScopedSessionStateObserver( |
| 214 ash::SessionStateObserver* observer) : observer_(observer) { |
| 215 ash::Shell::GetInstance()->session_state_delegate()-> |
| 216 AddSessionStateObserver(observer_); |
| 217 } |
| 218 |
| 219 ScopedSessionStateObserver::~ScopedSessionStateObserver() { |
| 220 ash::Shell::GetInstance()->session_state_delegate()-> |
| 221 RemoveSessionStateObserver(observer_); |
| 222 } |
| 223 |
| 224 /////////////////////////////////////////////////////////////////////////////// |
210 // AccessibilityStatusEventDetails | 225 // AccessibilityStatusEventDetails |
211 | 226 |
212 AccessibilityStatusEventDetails::AccessibilityStatusEventDetails( | 227 AccessibilityStatusEventDetails::AccessibilityStatusEventDetails( |
213 bool enabled, | 228 bool enabled, |
214 ash::AccessibilityNotificationVisibility notify) | 229 ash::AccessibilityNotificationVisibility notify) |
215 : enabled(enabled), | 230 : enabled(enabled), |
216 magnifier_type(ash::kDefaultMagnifierType), | 231 magnifier_type(ash::kDefaultMagnifierType), |
217 notify(notify) {} | 232 notify(notify) {} |
218 | 233 |
219 AccessibilityStatusEventDetails::AccessibilityStatusEventDetails( | 234 AccessibilityStatusEventDetails::AccessibilityStatusEventDetails( |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 content::NotificationService::AllSources()); | 330 content::NotificationService::AllSources()); |
316 notification_registrar_.Add(this, | 331 notification_registrar_.Add(this, |
317 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 332 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
318 content::NotificationService::AllSources()); | 333 content::NotificationService::AllSources()); |
319 notification_registrar_.Add(this, | 334 notification_registrar_.Add(this, |
320 chrome::NOTIFICATION_EXTENSION_REMOVED, | 335 chrome::NOTIFICATION_EXTENSION_REMOVED, |
321 content::NotificationService::AllSources()); | 336 content::NotificationService::AllSources()); |
322 notification_registrar_.Add(this, | 337 notification_registrar_.Add(this, |
323 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 338 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
324 content::NotificationService::AllSources()); | 339 content::NotificationService::AllSources()); |
| 340 |
325 GetBrailleController()->AddObserver(this); | 341 GetBrailleController()->AddObserver(this); |
326 | 342 |
327 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 343 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
328 media::SoundsManager* manager = media::SoundsManager::Get(); | 344 media::SoundsManager* manager = media::SoundsManager::Get(); |
329 manager->Initialize(SOUND_SHUTDOWN, | 345 manager->Initialize(SOUND_SHUTDOWN, |
330 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); | 346 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); |
331 manager->Initialize( | 347 manager->Initialize( |
332 SOUND_SPOKEN_FEEDBACK_ENABLED, | 348 SOUND_SPOKEN_FEEDBACK_ENABLED, |
333 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); | 349 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); |
334 manager->Initialize( | 350 manager->Initialize( |
335 SOUND_SPOKEN_FEEDBACK_DISABLED, | 351 SOUND_SPOKEN_FEEDBACK_DISABLED, |
336 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); | 352 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); |
337 } | 353 } |
338 | 354 |
339 AccessibilityManager::~AccessibilityManager() { | 355 AccessibilityManager::~AccessibilityManager() { |
340 CHECK(this == g_accessibility_manager); | 356 CHECK(this == g_accessibility_manager); |
341 | 357 |
342 // Component extensions don't always notify us when they're unloaded. Ensure | 358 // Component extensions don't always notify us when they're unloaded. Ensure |
343 // we clean up ChromeVox observers here. | 359 // we clean up ChromeVox observers here. |
344 if (profile_) { | 360 if (profile_) { |
345 extensions::ExtensionSystem::Get(profile_)-> | 361 extensions::ExtensionSystem::Get(profile_)-> |
346 event_router()->UnregisterObserver(this); | 362 event_router()->UnregisterObserver(this); |
347 } | 363 } |
348 } | 364 } |
349 | 365 |
| 366 bool AccessibilityManager::ShouldShowAccessibilityMenu() { |
| 367 // If any of the loaded profiles has an accessibility feature turned on - or |
| 368 // enforced to always show the menu - we return true to show the menu. |
| 369 std::vector<Profile*> profiles = |
| 370 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 371 for (std::vector<Profile*>::iterator it = profiles.begin(); |
| 372 it != profiles.end(); |
| 373 ++it) { |
| 374 PrefService* pref_service = (*it)->GetPrefs(); |
| 375 if (pref_service->GetBoolean(prefs::kStickyKeysEnabled) || |
| 376 pref_service->GetBoolean(prefs::kLargeCursorEnabled) || |
| 377 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled) || |
| 378 pref_service->GetBoolean(prefs::kHighContrastEnabled) || |
| 379 pref_service->GetBoolean(prefs::kAutoclickEnabled) || |
| 380 pref_service->GetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu) || |
| 381 pref_service->GetBoolean(prefs::kScreenMagnifierEnabled)) |
| 382 return true; |
| 383 } |
| 384 return false; |
| 385 } |
| 386 |
350 void AccessibilityManager::EnableLargeCursor(bool enabled) { | 387 void AccessibilityManager::EnableLargeCursor(bool enabled) { |
351 if (!profile_) | 388 if (!profile_) |
352 return; | 389 return; |
353 | 390 |
354 PrefService* pref_service = profile_->GetPrefs(); | 391 PrefService* pref_service = profile_->GetPrefs(); |
355 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); | 392 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); |
356 pref_service->CommitPendingWrite(); | 393 pref_service->CommitPendingWrite(); |
357 } | 394 } |
358 | 395 |
359 void AccessibilityManager::UpdateLargeCursorFromPref() { | 396 void AccessibilityManager::UpdateLargeCursorFromPref() { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 | 769 |
733 profile_ = profile; | 770 profile_ = profile; |
734 UpdateLargeCursorFromPref(); | 771 UpdateLargeCursorFromPref(); |
735 UpdateStickyKeysFromPref(); | 772 UpdateStickyKeysFromPref(); |
736 UpdateSpokenFeedbackFromPref(); | 773 UpdateSpokenFeedbackFromPref(); |
737 UpdateHighContrastFromPref(); | 774 UpdateHighContrastFromPref(); |
738 UpdateAutoclickFromPref(); | 775 UpdateAutoclickFromPref(); |
739 UpdateAutoclickDelayFromPref(); | 776 UpdateAutoclickDelayFromPref(); |
740 } | 777 } |
741 | 778 |
| 779 void AccessibilityManager::ActiveUserChanged(const std::string& user_id) { |
| 780 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 781 } |
| 782 |
742 void AccessibilityManager::SetProfileForTest(Profile* profile) { | 783 void AccessibilityManager::SetProfileForTest(Profile* profile) { |
743 SetProfile(profile); | 784 SetProfile(profile); |
744 } | 785 } |
745 | 786 |
746 void AccessibilityManager::SetBrailleControllerForTest( | 787 void AccessibilityManager::SetBrailleControllerForTest( |
747 BrailleController* controller) { | 788 BrailleController* controller) { |
748 g_braille_controller_for_test = controller; | 789 g_braille_controller_for_test = controller; |
749 } | 790 } |
750 | 791 |
751 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { | 792 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 } | 841 } |
801 } | 842 } |
802 | 843 |
803 void AccessibilityManager::Observe( | 844 void AccessibilityManager::Observe( |
804 int type, | 845 int type, |
805 const content::NotificationSource& source, | 846 const content::NotificationSource& source, |
806 const content::NotificationDetails& details) { | 847 const content::NotificationDetails& details) { |
807 switch (type) { | 848 switch (type) { |
808 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 849 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
809 // Update |profile_| when entering the login screen. | 850 // Update |profile_| when entering the login screen. |
810 Profile* profile = ProfileManager::GetDefaultProfile(); | 851 Profile* profile = ProfileManager::GetActiveUserProfile(); |
811 if (ProfileHelper::IsSigninProfile(profile)) | 852 if (ProfileHelper::IsSigninProfile(profile)) |
812 SetProfile(profile); | 853 SetProfile(profile); |
813 break; | 854 break; |
814 } | 855 } |
815 case chrome::NOTIFICATION_SESSION_STARTED: | 856 case chrome::NOTIFICATION_SESSION_STARTED: |
816 // Update |profile_| when entering a session. | 857 // Update |profile_| when entering a session. |
817 SetProfile(ProfileManager::GetDefaultProfile()); | 858 SetProfile(ProfileManager::GetActiveUserProfile()); |
818 | 859 |
819 // Ensure ChromeVox makes announcements at the start of new sessions. | 860 // Ensure ChromeVox makes announcements at the start of new sessions. |
820 should_speak_chrome_vox_announcements_on_user_screen_ = true; | 861 should_speak_chrome_vox_announcements_on_user_screen_ = true; |
| 862 |
| 863 // Add a session state observer to be able to monitor session changes. |
| 864 if (!session_state_observer_.get() && ash::Shell::HasInstance()) |
| 865 session_state_observer_.reset(new ScopedSessionStateObserver(this)); |
821 break; | 866 break; |
822 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 867 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
823 // Update |profile_| when exiting a session or shutting down. | 868 // Update |profile_| when exiting a session or shutting down. |
824 Profile* profile = content::Source<Profile>(source).ptr(); | 869 Profile* profile = content::Source<Profile>(source).ptr(); |
825 if (profile_ == profile) | 870 if (profile_ == profile) |
826 SetProfile(NULL); | 871 SetProfile(NULL); |
827 break; | 872 break; |
828 } | 873 } |
829 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { | 874 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
830 bool is_screen_locked = *content::Details<bool>(details).ptr(); | 875 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); | 967 event_router()->UnregisterObserver(this); |
923 } | 968 } |
924 } | 969 } |
925 | 970 |
926 void AccessibilityManager::PlaySound(int sound_key) const { | 971 void AccessibilityManager::PlaySound(int sound_key) const { |
927 if (system_sounds_enabled_) | 972 if (system_sounds_enabled_) |
928 media::SoundsManager::Get()->Play(sound_key); | 973 media::SoundsManager::Get()->Play(sound_key); |
929 } | 974 } |
930 | 975 |
931 } // namespace chromeos | 976 } // namespace chromeos |
OLD | NEW |