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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "ash/audio/sounds.h" | |
14 #include "ash/autoclick/autoclick_controller.h" | 13 #include "ash/autoclick/autoclick_controller.h" |
15 #include "ash/common/session/session_state_delegate.h" | 14 #include "ash/common/session/session_state_delegate.h" |
16 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
17 #include "ash/high_contrast/high_contrast_controller.h" | 16 #include "ash/high_contrast/high_contrast_controller.h" |
18 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
19 #include "ash/shelf/shelf.h" | 18 #include "ash/shelf/shelf.h" |
20 #include "ash/shelf/shelf_layout_manager.h" | 19 #include "ash/shelf/shelf_layout_manager.h" |
21 #include "ash/shell.h" | 20 #include "ash/shell.h" |
22 #include "ash/sticky_keys/sticky_keys_controller.h" | 21 #include "ash/sticky_keys/sticky_keys_controller.h" |
23 #include "base/callback.h" | 22 #include "base/callback.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 using content::RenderViewHost; | 89 using content::RenderViewHost; |
91 using extensions::api::braille_display_private::BrailleController; | 90 using extensions::api::braille_display_private::BrailleController; |
92 using extensions::api::braille_display_private::DisplayState; | 91 using extensions::api::braille_display_private::DisplayState; |
93 using extensions::api::braille_display_private::KeyEvent; | 92 using extensions::api::braille_display_private::KeyEvent; |
94 using extensions::api::braille_display_private::StubBrailleController; | 93 using extensions::api::braille_display_private::StubBrailleController; |
95 | 94 |
96 namespace chromeos { | 95 namespace chromeos { |
97 | 96 |
98 namespace { | 97 namespace { |
99 | 98 |
| 99 // When this flag is set, system sounds will not be played. |
| 100 const char kAshDisableSystemSounds[] = "ash-disable-system-sounds"; |
| 101 |
| 102 // When this flag is set, system sounds will be played whether the |
| 103 // ChromeVox is enabled or not. |
| 104 const char kAshEnableSystemSounds[] = "ash-enable-system-sounds"; |
| 105 |
100 static chromeos::AccessibilityManager* g_accessibility_manager = NULL; | 106 static chromeos::AccessibilityManager* g_accessibility_manager = NULL; |
101 | 107 |
102 static BrailleController* g_braille_controller_for_test = NULL; | 108 static BrailleController* g_braille_controller_for_test = NULL; |
103 | 109 |
104 BrailleController* GetBrailleController() { | 110 BrailleController* GetBrailleController() { |
105 if (g_braille_controller_for_test) | 111 if (g_braille_controller_for_test) |
106 return g_braille_controller_for_test; | 112 return g_braille_controller_for_test; |
107 // Don't use the real braille controller for tests to avoid automatically | 113 // Don't use the real braille controller for tests to avoid automatically |
108 // starting ChromeVox which confuses some tests. | 114 // starting ChromeVox which confuses some tests. |
109 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 115 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 if (!IsSpokenFeedbackEnabled()) | 771 if (!IsSpokenFeedbackEnabled()) |
766 return; | 772 return; |
767 | 773 |
768 // If the system locale changes and spoken feedback is enabled, | 774 // If the system locale changes and spoken feedback is enabled, |
769 // reload ChromeVox so that it switches its internal translations | 775 // reload ChromeVox so that it switches its internal translations |
770 // to the new language. | 776 // to the new language. |
771 EnableSpokenFeedback(false, ash::A11Y_NOTIFICATION_NONE); | 777 EnableSpokenFeedback(false, ash::A11Y_NOTIFICATION_NONE); |
772 EnableSpokenFeedback(true, ash::A11Y_NOTIFICATION_NONE); | 778 EnableSpokenFeedback(true, ash::A11Y_NOTIFICATION_NONE); |
773 } | 779 } |
774 | 780 |
775 void AccessibilityManager::PlayEarcon(int sound_key) { | 781 bool AccessibilityManager::PlayEarcon(int sound_key, PlaySoundOption option) { |
776 DCHECK(sound_key < chromeos::SOUND_COUNT); | 782 DCHECK(sound_key < chromeos::SOUND_COUNT); |
777 ash::PlaySystemSoundIfSpokenFeedback(sound_key); | 783 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 784 if (cl->HasSwitch(kAshDisableSystemSounds)) |
| 785 return false; |
| 786 if (option == PlaySoundOption::SPOKEN_FEEDBACK_ENABLED && |
| 787 !IsSpokenFeedbackEnabled() && !cl->HasSwitch(kAshEnableSystemSounds)) { |
| 788 return false; |
| 789 } |
| 790 return media::SoundsManager::Get()->Play(sound_key); |
778 } | 791 } |
779 | 792 |
780 void AccessibilityManager::HandleAccessibilityGesture(ui::AXGesture gesture) { | 793 void AccessibilityManager::HandleAccessibilityGesture(ui::AXGesture gesture) { |
781 extensions::EventRouter* event_router = | 794 extensions::EventRouter* event_router = |
782 extensions::EventRouter::Get(profile()); | 795 extensions::EventRouter::Get(profile()); |
783 CHECK(event_router); | 796 CHECK(event_router); |
784 | 797 |
785 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); | 798 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
786 event_args->AppendString(ui::ToString(gesture)); | 799 event_args->AppendString(ui::ToString(gesture)); |
787 std::unique_ptr<extensions::Event> event(new extensions::Event( | 800 std::unique_ptr<extensions::Event> event(new extensions::Event( |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 } | 1311 } |
1299 | 1312 |
1300 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { | 1313 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { |
1301 system_sounds_enabled_ = system_sounds_enabled; | 1314 system_sounds_enabled_ = system_sounds_enabled; |
1302 } | 1315 } |
1303 | 1316 |
1304 base::TimeDelta AccessibilityManager::PlayShutdownSound() { | 1317 base::TimeDelta AccessibilityManager::PlayShutdownSound() { |
1305 if (!system_sounds_enabled_) | 1318 if (!system_sounds_enabled_) |
1306 return base::TimeDelta(); | 1319 return base::TimeDelta(); |
1307 system_sounds_enabled_ = false; | 1320 system_sounds_enabled_ = false; |
1308 if (!ash::PlaySystemSoundIfSpokenFeedback(SOUND_SHUTDOWN)) | 1321 if (!PlayEarcon(SOUND_SHUTDOWN, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED)) |
1309 return base::TimeDelta(); | 1322 return base::TimeDelta(); |
1310 return media::SoundsManager::Get()->GetDuration(SOUND_SHUTDOWN); | 1323 return media::SoundsManager::Get()->GetDuration(SOUND_SHUTDOWN); |
1311 } | 1324 } |
1312 | 1325 |
1313 void AccessibilityManager::InjectChromeVox(RenderViewHost* render_view_host) { | 1326 void AccessibilityManager::InjectChromeVox(RenderViewHost* render_view_host) { |
1314 LoadChromeVoxExtension(profile_, render_view_host, base::Closure()); | 1327 LoadChromeVoxExtension(profile_, render_view_host, base::Closure()); |
1315 } | 1328 } |
1316 | 1329 |
1317 std::unique_ptr<AccessibilityStatusSubscription> | 1330 std::unique_ptr<AccessibilityStatusSubscription> |
1318 AccessibilityManager::RegisterCallback(const AccessibilityStatusCallback& cb) { | 1331 AccessibilityManager::RegisterCallback(const AccessibilityStatusCallback& cb) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 extensions::ExtensionRegistry::Get(browser_context)); | 1473 extensions::ExtensionRegistry::Get(browser_context)); |
1461 } | 1474 } |
1462 } | 1475 } |
1463 | 1476 |
1464 void AccessibilityManager::OnShutdown(extensions::ExtensionRegistry* registry) { | 1477 void AccessibilityManager::OnShutdown(extensions::ExtensionRegistry* registry) { |
1465 extension_registry_observer_.Remove(registry); | 1478 extension_registry_observer_.Remove(registry); |
1466 } | 1479 } |
1467 | 1480 |
1468 void AccessibilityManager::PostLoadChromeVox(Profile* profile) { | 1481 void AccessibilityManager::PostLoadChromeVox(Profile* profile) { |
1469 // Do any setup work needed immediately after ChromeVox actually loads. | 1482 // Do any setup work needed immediately after ChromeVox actually loads. |
1470 ash::PlaySystemSoundAlways(SOUND_SPOKEN_FEEDBACK_ENABLED); | 1483 PlayEarcon(SOUND_SPOKEN_FEEDBACK_ENABLED, PlaySoundOption::ALWAYS); |
1471 | 1484 |
1472 if (chrome_vox_loaded_on_lock_screen_ || | 1485 if (chrome_vox_loaded_on_lock_screen_ || |
1473 should_speak_chrome_vox_announcements_on_user_screen_) { | 1486 should_speak_chrome_vox_announcements_on_user_screen_) { |
1474 extensions::EventRouter* event_router = | 1487 extensions::EventRouter* event_router = |
1475 extensions::EventRouter::Get(profile); | 1488 extensions::EventRouter::Get(profile); |
1476 CHECK(event_router); | 1489 CHECK(event_router); |
1477 | 1490 |
1478 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); | 1491 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
1479 std::unique_ptr<extensions::Event> event(new extensions::Event( | 1492 std::unique_ptr<extensions::Event> event(new extensions::Event( |
1480 extensions::events::ACCESSIBILITY_PRIVATE_ON_INTRODUCE_CHROME_VOX, | 1493 extensions::events::ACCESSIBILITY_PRIVATE_ON_INTRODUCE_CHROME_VOX, |
1481 extensions::api::accessibility_private::OnIntroduceChromeVox:: | 1494 extensions::api::accessibility_private::OnIntroduceChromeVox:: |
1482 kEventName, | 1495 kEventName, |
1483 std::move(event_args))); | 1496 std::move(event_args))); |
1484 event_router->DispatchEventWithLazyListener( | 1497 event_router->DispatchEventWithLazyListener( |
1485 extension_misc::kChromeVoxExtensionId, std::move(event)); | 1498 extension_misc::kChromeVoxExtensionId, std::move(event)); |
1486 } | 1499 } |
1487 | 1500 |
1488 should_speak_chrome_vox_announcements_on_user_screen_ = | 1501 should_speak_chrome_vox_announcements_on_user_screen_ = |
1489 chrome_vox_loaded_on_lock_screen_; | 1502 chrome_vox_loaded_on_lock_screen_; |
1490 | 1503 |
1491 if (!chromevox_panel_) { | 1504 if (!chromevox_panel_) { |
1492 chromevox_panel_ = new ChromeVoxPanel(profile_); | 1505 chromevox_panel_ = new ChromeVoxPanel(profile_); |
1493 chromevox_panel_widget_observer_.reset( | 1506 chromevox_panel_widget_observer_.reset( |
1494 new ChromeVoxPanelWidgetObserver(chromevox_panel_->GetWidget(), this)); | 1507 new ChromeVoxPanelWidgetObserver(chromevox_panel_->GetWidget(), this)); |
1495 } | 1508 } |
1496 } | 1509 } |
1497 | 1510 |
1498 void AccessibilityManager::PostUnloadChromeVox(Profile* profile) { | 1511 void AccessibilityManager::PostUnloadChromeVox(Profile* profile) { |
1499 // Do any teardown work needed immediately after ChromeVox actually unloads. | 1512 // Do any teardown work needed immediately after ChromeVox actually unloads. |
1500 ash::PlaySystemSoundAlways(SOUND_SPOKEN_FEEDBACK_DISABLED); | 1513 PlayEarcon(SOUND_SPOKEN_FEEDBACK_DISABLED, PlaySoundOption::ALWAYS); |
1501 // Clear the accessibility focus ring. | 1514 // Clear the accessibility focus ring. |
1502 AccessibilityFocusRingController::GetInstance()->SetFocusRing( | 1515 AccessibilityFocusRingController::GetInstance()->SetFocusRing( |
1503 std::vector<gfx::Rect>(), | 1516 std::vector<gfx::Rect>(), |
1504 AccessibilityFocusRingController::PERSIST_FOCUS_RING); | 1517 AccessibilityFocusRingController::PERSIST_FOCUS_RING); |
1505 } | 1518 } |
1506 | 1519 |
1507 void AccessibilityManager::OnChromeVoxPanelClosing() { | 1520 void AccessibilityManager::OnChromeVoxPanelClosing() { |
1508 aura::Window* root_window = chromevox_panel_->GetRootWindow(); | 1521 aura::Window* root_window = chromevox_panel_->GetRootWindow(); |
1509 chromevox_panel_widget_observer_.reset(nullptr); | 1522 chromevox_panel_widget_observer_.reset(nullptr); |
1510 chromevox_panel_ = nullptr; | 1523 chromevox_panel_ = nullptr; |
(...skipping 17 matching lines...) Expand all Loading... |
1528 content::BrowserContext* context) { | 1541 content::BrowserContext* context) { |
1529 keyboard_listener_extension_id_ = id; | 1542 keyboard_listener_extension_id_ = id; |
1530 | 1543 |
1531 extensions::ExtensionRegistry* registry = | 1544 extensions::ExtensionRegistry* registry = |
1532 extensions::ExtensionRegistry::Get(context); | 1545 extensions::ExtensionRegistry::Get(context); |
1533 if (!extension_registry_observer_.IsObserving(registry) && !id.empty()) | 1546 if (!extension_registry_observer_.IsObserving(registry) && !id.empty()) |
1534 extension_registry_observer_.Add(registry); | 1547 extension_registry_observer_.Add(registry); |
1535 } | 1548 } |
1536 | 1549 |
1537 } // namespace chromeos | 1550 } // namespace chromeos |
OLD | NEW |