diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/browser/speech/extension_api/tts_engine_extension_api.cc | 16 | ||||
-rw-r--r-- | chrome/browser/speech/extension_api/tts_engine_extension_api.h | 39 | ||||
-rw-r--r-- | chrome/browser/speech/tts_controller.cc | 33 | ||||
-rw-r--r-- | chrome/browser/speech/tts_controller.h | 30 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 5 |
6 files changed, 80 insertions, 44 deletions
@@ -103,6 +103,7 @@ Francois Kritzinger <francoisk777@gmail.com> Frédéric Wang <fred.wang@free.fr> Gaetano Mendola <mendola@gmail.com> Gajendra Singh <wxjg68@motorola.com> +Gao Chun <chun.gao@intel.com> Gao Chun <gaochun.dev@gmail.com> George Liaskos <geo.liaskos@gmail.com> Giuseppe Iuculano <giuseppe@iuculano.it> diff --git a/chrome/browser/speech/extension_api/tts_engine_extension_api.cc b/chrome/browser/speech/extension_api/tts_engine_extension_api.cc index f80b6bd..0588d9f 100644 --- a/chrome/browser/speech/extension_api/tts_engine_extension_api.cc +++ b/chrome/browser/speech/extension_api/tts_engine_extension_api.cc @@ -60,7 +60,12 @@ void WarnIfMissingPauseOrResumeListener( }; } // anonymous namespace -void GetExtensionVoices(Profile* profile, std::vector<VoiceData>* out_voices) { +TtsExtensionEngine* TtsExtensionEngine::GetInstance() { + return Singleton<TtsExtensionEngine>::get(); +} + +void TtsExtensionEngine::GetVoices(Profile* profile, + std::vector<VoiceData>* out_voices) { ExtensionService* service = profile->GetExtensionService(); DCHECK(service); EventRouter* event_router = @@ -127,7 +132,8 @@ void GetExtensionVoices(Profile* profile, std::vector<VoiceData>* out_voices) { } } -void ExtensionTtsEngineSpeak(Utterance* utterance, const VoiceData& voice) { +void TtsExtensionEngine::Speak(Utterance* utterance, + const VoiceData& voice) { // See if the engine supports the "end" event; if so, we can keep the // utterance around and track it. If not, we're finished with this // utterance now. @@ -171,7 +177,7 @@ void ExtensionTtsEngineSpeak(Utterance* utterance, const VoiceData& voice) { DispatchEventToExtension(utterance->extension_id(), event.Pass()); } -void ExtensionTtsEngineStop(Utterance* utterance) { +void TtsExtensionEngine::Stop(Utterance* utterance) { scoped_ptr<base::ListValue> args(new base::ListValue()); scoped_ptr<extensions::Event> event(new extensions::Event( tts_engine_events::kOnStop, args.Pass())); @@ -180,7 +186,7 @@ void ExtensionTtsEngineStop(Utterance* utterance) { DispatchEventToExtension(utterance->extension_id(), event.Pass()); } -void ExtensionTtsEnginePause(Utterance* utterance) { +void TtsExtensionEngine::Pause(Utterance* utterance) { scoped_ptr<base::ListValue> args(new base::ListValue()); scoped_ptr<extensions::Event> event(new extensions::Event( tts_engine_events::kOnPause, args.Pass())); @@ -192,7 +198,7 @@ void ExtensionTtsEnginePause(Utterance* utterance) { WarnIfMissingPauseOrResumeListener(profile, event_router, id); } -void ExtensionTtsEngineResume(Utterance* utterance) { +void TtsExtensionEngine::Resume(Utterance* utterance) { scoped_ptr<base::ListValue> args(new base::ListValue()); scoped_ptr<extensions::Event> event(new extensions::Event( tts_engine_events::kOnResume, args.Pass())); diff --git a/chrome/browser/speech/extension_api/tts_engine_extension_api.h b/chrome/browser/speech/extension_api/tts_engine_extension_api.h index 1a2c25b..fdee2b9 100644 --- a/chrome/browser/speech/extension_api/tts_engine_extension_api.h +++ b/chrome/browser/speech/extension_api/tts_engine_extension_api.h @@ -28,32 +28,19 @@ extern const char kOnPause[]; extern const char kOnResume[]; } -// Return a list of all available voices registered by extensions. -void GetExtensionVoices(Profile* profile, std::vector<VoiceData>* out_voices); - -// Find the first extension with a tts_voices in its -// manifest that matches the speech parameters of this utterance. -// If found, store a pointer to the extension in |matching_extension| and -// the index of the voice within the extension in |voice_index| and -// return true. -bool GetMatchingExtensionVoice(Utterance* utterance, - const extensions::Extension** matching_extension, - size_t* voice_index); - -// Speak the given utterance by sending an event to the given TTS engine -// extension voice. -void ExtensionTtsEngineSpeak(Utterance* utterance, - const VoiceData& voice); - -// Stop speaking the given utterance by sending an event to the extension -// associated with this utterance. -void ExtensionTtsEngineStop(Utterance* utterance); - -// Pause in the middle of speaking this utterance. -void ExtensionTtsEnginePause(Utterance* utterance); - -// Resume speaking this utterance. -void ExtensionTtsEngineResume(Utterance* utterance); +// TtsEngineDelegate implementation used by TtsController. +class TtsExtensionEngine : public TtsEngineDelegate { + public: + static TtsExtensionEngine* GetInstance(); + + // Overridden from TtsEngineDelegate: + virtual void GetVoices(Profile* profile, + std::vector<VoiceData>* out_voices) OVERRIDE; + virtual void Speak(Utterance* utterance, const VoiceData& voice) OVERRIDE; + virtual void Stop(Utterance* utterance) OVERRIDE; + virtual void Pause(Utterance* utterance) OVERRIDE; + virtual void Resume(Utterance* utterance) OVERRIDE; +}; // Hidden/internal extension function used to allow TTS engine extensions // to send events back to the client that's calling tts.speak(). diff --git a/chrome/browser/speech/tts_controller.cc b/chrome/browser/speech/tts_controller.cc index 6d749f3..75d75be 100644 --- a/chrome/browser/speech/tts_controller.cc +++ b/chrome/browser/speech/tts_controller.cc @@ -10,13 +10,7 @@ #include "base/float_util.h" #include "base/values.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" -#include "chrome/browser/speech/extension_api/tts_extension_api.h" #include "chrome/browser/speech/tts_platform.h" -#include "chrome/common/extensions/api/speech/tts_engine_manifest_handler.h" -#include "extensions/browser/extension_system.h" -#include "extensions/common/extension.h" namespace { // A value to be used to indicate that there is no char index available. @@ -120,7 +114,8 @@ TtsController* TtsController::GetInstance() { TtsController::TtsController() : current_utterance_(NULL), paused_(false), - platform_impl_(NULL) { + platform_impl_(NULL), + tts_engine_delegate_(NULL) { } TtsController::~TtsController() { @@ -172,6 +167,9 @@ void TtsController::SpeakNow(Utterance* utterance) { if (native_voices.empty() && !voices.empty()) { // TODO(dtseng): Notify extension caller of an error. utterance->set_voice_name(""); + // TODO(gaochun): Replace the global variable g_browser_process with + // GetContentClient()->browser() to eliminate the dependency of browser + // once TTS implementation was moved to content. utterance->set_lang(g_browser_process->GetApplicationLocale()); index = GetMatchingVoice(utterance, voices); @@ -192,7 +190,8 @@ void TtsController::SpeakNow(Utterance* utterance) { DCHECK(!voice.extension_id.empty()); current_utterance_ = utterance; utterance->set_extension_id(voice.extension_id); - ExtensionTtsEngineSpeak(utterance, voice); + if (tts_engine_delegate_) + tts_engine_delegate_->Speak(utterance, voice); bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end(); if (!sends_end_event) { @@ -237,7 +236,8 @@ void TtsController::Stop() { paused_ = false; if (current_utterance_ && !current_utterance_->extension_id().empty()) { #if !defined(OS_ANDROID) - ExtensionTtsEngineStop(current_utterance_); + if (tts_engine_delegate_) + tts_engine_delegate_->Stop(current_utterance_); #endif } else { GetPlatformImpl()->clear_error(); @@ -255,7 +255,8 @@ void TtsController::Pause() { paused_ = true; if (current_utterance_ && !current_utterance_->extension_id().empty()) { #if !defined(OS_ANDROID) - ExtensionTtsEnginePause(current_utterance_); + if (tts_engine_delegate_) + tts_engine_delegate_->Pause(current_utterance_); #endif } else if (current_utterance_) { GetPlatformImpl()->clear_error(); @@ -267,7 +268,8 @@ void TtsController::Resume() { paused_ = false; if (current_utterance_ && !current_utterance_->extension_id().empty()) { #if !defined(OS_ANDROID) - ExtensionTtsEngineResume(current_utterance_); + if (tts_engine_delegate_) + tts_engine_delegate_->Resume(current_utterance_); #endif } else if (current_utterance_) { GetPlatformImpl()->clear_error(); @@ -298,8 +300,8 @@ void TtsController::OnTtsEvent(int utterance_id, void TtsController::GetVoices(Profile* profile, std::vector<VoiceData>* out_voices) { #if !defined(OS_ANDROID) - if (profile) - GetExtensionVoices(profile, out_voices); + if (profile && tts_engine_delegate_) + tts_engine_delegate_->GetVoices(profile, out_voices); #endif TtsPlatformImpl* platform_impl = GetPlatformImpl(); @@ -441,3 +443,8 @@ void TtsController::RemoveVoicesChangedDelegate( VoicesChangedDelegate* delegate) { voices_changed_delegates_.erase(delegate); } + +void TtsController::SetTtsEngineDelegate( + TtsEngineDelegate* delegate) { + tts_engine_delegate_ = delegate; +} diff --git a/chrome/browser/speech/tts_controller.h b/chrome/browser/speech/tts_controller.h index c8d1c10..0962f67 100644 --- a/chrome/browser/speech/tts_controller.h +++ b/chrome/browser/speech/tts_controller.h @@ -77,6 +77,29 @@ struct VoiceData { std::string native_voice_identifier; }; +// Interface that delegates TTS requests to user-installed extensions. +class TtsEngineDelegate { + public: + virtual ~TtsEngineDelegate() {} + + // Return a list of all available voices registered. + virtual void GetVoices(Profile* profile, + std::vector<VoiceData>* out_voices) = 0; + + // Speak the given utterance by sending an event to the given TTS engine. + virtual void Speak(Utterance* utterance, const VoiceData& voice) = 0; + + // Stop speaking the given utterance by sending an event to the target + // associated with this utterance. + virtual void Stop(Utterance* utterance) = 0; + + // Pause in the middle of speaking this utterance. + virtual void Pause(Utterance* utterance) = 0; + + // Resume speaking this utterance. + virtual void Resume(Utterance* utterance) = 0; +}; + // Class that wants to receive events on utterances. class UtteranceEventDelegate { public: @@ -297,6 +320,10 @@ class TtsController { // Remove delegate that wants to be notified when the set of voices changes. void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate); + // Set the delegate that processes TTS requests with user-installed + // extensions. + void SetTtsEngineDelegate(TtsEngineDelegate* delegate); + // For unit testing. void SetPlatformImpl(TtsPlatformImpl* platform_impl); int QueueSize(); @@ -346,6 +373,9 @@ class TtsController { // dependency injection. TtsPlatformImpl* platform_impl_; + // The delegate that processes TTS requests with user-installed extensions. + TtsEngineDelegate* tts_engine_delegate_; + DISALLOW_COPY_AND_ASSIGN(TtsController); }; diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index da8a18a..9f30e87 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -77,6 +77,8 @@ #include "chrome/browser/sessions/session_types.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sessions/tab_restore_service_factory.h" +#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" +#include "chrome/browser/speech/tts_controller.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/sync_ui_util.h" @@ -443,6 +445,9 @@ Browser::Browser(const CreateParams& params) } fullscreen_controller_.reset(new FullscreenController(this)); + + TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); + TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine); } Browser::~Browser() { |