diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/content/browser/speech/tts_controller_impl.h | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-c30a6232df03e1efbd9f3b226777b07e087a1122.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/content/browser/speech/tts_controller_impl.h')
-rw-r--r-- | chromium/content/browser/speech/tts_controller_impl.h | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/chromium/content/browser/speech/tts_controller_impl.h b/chromium/content/browser/speech/tts_controller_impl.h index 052a8841be9..638c3691d6d 100644 --- a/chromium/content/browser/speech/tts_controller_impl.h +++ b/chromium/content/browser/speech/tts_controller_impl.h @@ -5,9 +5,8 @@ #ifndef CONTENT_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ #define CONTENT_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ -#include <deque> +#include <list> #include <memory> -#include <set> #include <string> #include <vector> @@ -22,18 +21,23 @@ #include "build/build_config.h" #include "content/common/content_export.h" #include "content/public/browser/tts_controller.h" -#include "content/public/browser/tts_controller_delegate.h" #include "content/public/browser/tts_platform.h" +#include "content/public/browser/web_contents_observer.h" #include "services/data_decoder/public/cpp/data_decoder.h" #include "url/gurl.h" namespace content { class BrowserContext; +#if defined(OS_CHROMEOS) +class TtsControllerDelegate; +#endif + // Singleton class that manages text-to-speech for all TTS engines and // APIs, maintaining a queue of pending utterances and keeping // track of all state. -class CONTENT_EXPORT TtsControllerImpl : public TtsController { +class CONTENT_EXPORT TtsControllerImpl : public TtsController, + public WebContentsObserver { public: // Get the single instance of this class. static TtsControllerImpl* GetInstance(); @@ -58,6 +62,7 @@ class CONTENT_EXPORT TtsControllerImpl : public TtsController { void RemoveUtteranceEventDelegate(UtteranceEventDelegate* delegate) override; void SetTtsEngineDelegate(TtsEngineDelegate* delegate) override; TtsEngineDelegate* GetTtsEngineDelegate() override; + void SetStopSpeakingWhenHidden(bool value) override; // Called directly by ~BrowserContext, because a raw BrowserContext pointer // is stored in an Utterance. @@ -77,6 +82,7 @@ class CONTENT_EXPORT TtsControllerImpl : public TtsController { ~TtsControllerImpl() override; private: + friend class TtsControllerTestHelper; FRIEND_TEST_ALL_PREFIXES(TtsControllerTest, TestTtsControllerShutdown); FRIEND_TEST_ALL_PREFIXES(TtsControllerTest, TestGetMatchingVoice); FRIEND_TEST_ALL_PREFIXES(TtsControllerTest, @@ -92,7 +98,13 @@ class CONTENT_EXPORT TtsControllerImpl : public TtsController { // |utterance| or delete it if there's an error. Returns true on success. void SpeakNow(std::unique_ptr<TtsUtterance> utterance); - void StopInternal(const GURL& source_url); + // If the current utterance matches |source_url|, it is stopped and the + // utterance queue cleared. + void StopAndClearQueue(const GURL& source_url); + + // Stops the current utterance if it matches |source_url|. Returns true on + // success, false if the current utterance does not match |source_url|. + bool StopCurrentUtteranceIfMatches(const GURL& source_url); // Clear the utterance queue. If send_events is true, will send // TTS_EVENT_CANCELLED events on each one. @@ -120,9 +132,31 @@ class CONTENT_EXPORT TtsControllerImpl : public TtsController { static void PopulateParsedText(std::string* parsed_text, const base::Value* element); + int GetMatchingVoice(TtsUtterance* utterance, + const std::vector<VoiceData>& voices); + + // Called internally to set |current_utterance_|. + void SetCurrentUtterance(std::unique_ptr<TtsUtterance> utterance); + + // Used when the WebContents of the current utterance is destroyed/hidden. + void StopCurrentUtteranceAndRemoveUtterancesMatching(WebContents* wc); + + // Returns true if the utterance should be spoken. + bool ShouldSpeakUtterance(TtsUtterance* utterance); + + // WebContentsObserver methods + void WebContentsDestroyed() override; + void OnVisibilityChanged(Visibility visibility) override; + +#if defined(OS_CHROMEOS) TtsControllerDelegate* GetTtsControllerDelegate(); - TtsControllerDelegate* delegate_; + TtsControllerDelegate* delegate_ = nullptr; +#endif + + TtsEngineDelegate* engine_delegate_ = nullptr; + + bool stop_speaking_when_hidden_ = false; // A set of delegates that want to be notified when the voices change. base::ObserverList<VoicesChangedDelegate> voices_changed_delegates_; @@ -131,14 +165,14 @@ class CONTENT_EXPORT TtsControllerImpl : public TtsController { std::unique_ptr<TtsUtterance> current_utterance_; // Whether the queue is paused or not. - bool paused_; + bool paused_ = false; // A pointer to the platform implementation of text-to-speech, for // dependency injection. - TtsPlatform* tts_platform_; + TtsPlatform* tts_platform_ = nullptr; // A queue of utterances to speak after the current one finishes. - std::deque<std::unique_ptr<TtsUtterance>> utterance_deque_; + std::list<std::unique_ptr<TtsUtterance>> utterance_list_; DISALLOW_COPY_AND_ASSIGN(TtsControllerImpl); }; |