1 // Copyright 2018 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 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_TTS_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_TTS_HANDLER_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" 10 #include "content/public/browser/tts_controller.h" 11 12 namespace settings { 13 14 // Chrome "/manageAccessibility/tts/*" settings page UI handler. 15 class TtsHandler : public SettingsPageUIHandler, 16 public content::VoicesChangedDelegate, 17 public content::UtteranceEventDelegate { 18 public: 19 TtsHandler(); 20 ~TtsHandler() override; 21 22 void HandleGetAllTtsVoiceData(const base::ListValue* args); 23 void HandleGetTtsExtensions(const base::ListValue* args); 24 void HandlePreviewTtsVoice(const base::ListValue* args); 25 26 // SettingsPageUIHandler implementation. 27 void RegisterMessages() override; 28 void OnJavascriptAllowed() override; 29 void OnJavascriptDisallowed() override; 30 31 // VoicesChangedDelegate implementation. 32 void OnVoicesChanged() override; 33 34 // UtteranceEventDelegate implementation. 35 void OnTtsEvent(content::TtsUtterance* utterance, 36 content::TtsEventType event_type, 37 int char_index, 38 int length, 39 const std::string& error_message) override; 40 41 private: 42 void WakeTtsEngine(const base::ListValue* args); 43 void OnTtsEngineAwake(bool success); 44 int GetVoiceLangMatchScore(const content::VoiceData* voice, 45 const std::string& app_locale); 46 void RemoveTtsControllerDelegates(); 47 48 base::WeakPtrFactory<TtsHandler> weak_factory_{this}; 49 50 DISALLOW_COPY_AND_ASSIGN(TtsHandler); 51 }; 52 53 } // namespace settings 54 55 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_TTS_HANDLER_H_ 56