Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1793)

Unified Diff: content/browser/speech/tts_dispatcher_host_impl.cc

Issue 12589005: Implement web speech synthesis. (Closed) Base URL: http://git.chromium.org/chromium/src.git@webtts
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/speech/tts_dispatcher_host_impl.cc
diff --git a/content/browser/speech/tts_dispatcher_host_impl.cc b/content/browser/speech/tts_dispatcher_host_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5e0bbc9646687c450f5b61e0c397d89249891da4
--- /dev/null
+++ b/content/browser/speech/tts_dispatcher_host_impl.cc
@@ -0,0 +1,162 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/speech/tts_dispatcher_host_impl.h"
+
+#include "content/public/browser/content_browser_client.h"
+
+namespace content {
+
+TtsDispatcherHostImpl::TtsDispatcherHostImpl(
+ int render_process_id,
+ BrowserContext* browser_context)
+ : render_process_id_(render_process_id),
+ browser_context_(browser_context),
+ delegate_(
+ GetContentClient()->browser()->GetTtsDispatcherHostDelegate()) {
+}
+
+TtsDispatcherHostImpl::~TtsDispatcherHostImpl() {
+}
+
+BrowserContext* TtsDispatcherHostImpl::GetBrowserContext() {
+ return browser_context_;
+}
+
+bool TtsDispatcherHostImpl::OnMessageReceived(
+ const IPC::Message& message, bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(TtsDispatcherHostImpl, message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER(TtsHostMsg_InitializeVoiceList, OnInitializeVoiceList)
+ IPC_MESSAGE_HANDLER(TtsHostMsg_Speak, OnSpeak)
+ IPC_MESSAGE_HANDLER(TtsHostMsg_Pause, OnPause)
+ IPC_MESSAGE_HANDLER(TtsHostMsg_Resume, OnResume)
+ IPC_MESSAGE_HANDLER(TtsHostMsg_Cancel, OnCancel)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void TtsDispatcherHostImpl::OnInitializeVoiceList(int routing_id) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
tommi (sloooow) - chröme 2013/03/07 13:04:46 out of curiosity, why do we do this on the ui thre
dmazzoni 2013/03/19 17:30:22 Currently TtsController is implemented on the UI t
tommi (sloooow) - chröme 2013/03/21 14:34:02 As is I can't tell if it's a good idea or not :) L
+ base::Bind(&TtsDispatcherHostImpl::OnInitializeVoiceList,
+ this,
+ routing_id));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnInitializeVoiceList(this, routing_id);
+}
+
+void TtsDispatcherHostImpl::OnSpeak(int routing_id,
+ const TtsUtteranceRequest& utterance) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TtsDispatcherHostImpl::OnSpeak,
+ this,
+ routing_id,
+ utterance));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnSpeak(this, routing_id, utterance);
+}
+
+void TtsDispatcherHostImpl::OnPause() {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TtsDispatcherHostImpl::OnPause, this));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnPause(this);
+}
+
+void TtsDispatcherHostImpl::OnResume() {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TtsDispatcherHostImpl::OnResume, this));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnResume(this);
+}
+
+void TtsDispatcherHostImpl::OnCancel() {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TtsDispatcherHostImpl::OnCancel, this));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnCancel(this);
+}
+
+void TtsDispatcherHostImpl::DidStartSpeaking(int routing_id, int utterance_id) {
+ Send(new TtsMsg_DidStartSpeaking(routing_id, utterance_id));
+}
+
+void TtsDispatcherHostImpl::DidFinishSpeaking(
+ int routing_id, int utterance_id) {
+ Send(new TtsMsg_DidFinishSpeaking(routing_id, utterance_id));
+}
+
+void TtsDispatcherHostImpl::DidPauseSpeaking(
+ int routing_id, int utterance_id) {
+ Send(new TtsMsg_DidPauseSpeaking(routing_id, utterance_id));
+}
+
+void TtsDispatcherHostImpl::DidResumeSpeaking(
+ int routing_id, int utterance_id) {
+ Send(new TtsMsg_DidResumeSpeaking(routing_id, utterance_id));
+}
+
+void TtsDispatcherHostImpl::WordBoundary(
+ int routing_id, int utterance_id, int char_index) {
+ Send(new TtsMsg_WordBoundary(routing_id, utterance_id, char_index));
+}
+
+void TtsDispatcherHostImpl::SentenceBoundary(
+ int routing_id, int utterance_id, int char_index) {
+ Send(new TtsMsg_SentenceBoundary(routing_id, utterance_id, char_index));
+}
+
+void TtsDispatcherHostImpl::MarkerEvent(
+ int routing_id, int utterance_id, int char_index) {
+ Send(new TtsMsg_MarkerEvent(routing_id, utterance_id, char_index));
+}
+
+void TtsDispatcherHostImpl::WasInterrupted(int routing_id, int utterance_id) {
+ Send(new TtsMsg_WasInterrupted(routing_id, utterance_id));
+}
+
+void TtsDispatcherHostImpl::WasCancelled(int routing_id, int utterance_id) {
+ Send(new TtsMsg_WasCancelled(routing_id, utterance_id));
+}
+
+void TtsDispatcherHostImpl::SpeakingErrorOccurred(
+ int routing_id, int utterance_id, const std::string& error_message) {
+ Send(new TtsMsg_SpeakingErrorOccurred(
+ routing_id, utterance_id, error_message));
+}
+
+void TtsDispatcherHostImpl::SendVoiceList(
+ int routing_id,
+ const std::vector<content::TtsVoice>& voices) {
+ Send(new TtsMsg_SetVoiceList(routing_id, voices));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698