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

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: Fresh update 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..5cadffc32e830f3d658e496285d8501d6beeda1c
--- /dev/null
+++ b/content/browser/speech/tts_dispatcher_host_impl.cc
@@ -0,0 +1,152 @@
+// 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() {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TtsDispatcherHostImpl::OnInitializeVoiceList, this));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnInitializeVoiceList(this);
+}
+
+void TtsDispatcherHostImpl::OnSpeak(const TtsUtteranceRequest& utterance) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TtsDispatcherHostImpl::OnSpeak,
+ this,
+ utterance));
+ return;
+ }
+
+ if (delegate_)
+ delegate_->OnSpeak(this, 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 utterance_id) {
+ Send(new TtsMsg_DidStartSpeaking(utterance_id));
+}
+
+void TtsDispatcherHostImpl::DidFinishSpeaking(int utterance_id) {
+ Send(new TtsMsg_DidFinishSpeaking(utterance_id));
+}
+
+void TtsDispatcherHostImpl::DidPauseSpeaking(int utterance_id) {
+ Send(new TtsMsg_DidPauseSpeaking(utterance_id));
+}
+
+void TtsDispatcherHostImpl::DidResumeSpeaking(int utterance_id) {
+ Send(new TtsMsg_DidResumeSpeaking(utterance_id));
+}
+
+void TtsDispatcherHostImpl::WordBoundary(int utterance_id, int char_index) {
+ Send(new TtsMsg_WordBoundary(utterance_id, char_index));
+}
+
+void TtsDispatcherHostImpl::SentenceBoundary(
+ int utterance_id, int char_index) {
+ Send(new TtsMsg_SentenceBoundary(utterance_id, char_index));
+}
+
+void TtsDispatcherHostImpl::MarkerEvent(int utterance_id, int char_index) {
+ Send(new TtsMsg_MarkerEvent(utterance_id, char_index));
+}
+
+void TtsDispatcherHostImpl::WasInterrupted(int utterance_id) {
+ Send(new TtsMsg_WasInterrupted(utterance_id));
+}
+
+void TtsDispatcherHostImpl::WasCancelled(int utterance_id) {
+ Send(new TtsMsg_WasCancelled(utterance_id));
+}
+
+void TtsDispatcherHostImpl::SpeakingErrorOccurred(
+ int utterance_id, const std::string& error_message) {
+ Send(new TtsMsg_SpeakingErrorOccurred(
+ utterance_id, error_message));
+}
+
+void TtsDispatcherHostImpl::SendVoiceList(
+ const std::vector<content::TtsVoice>& voices) {
+ Send(new TtsMsg_SetVoiceList(voices));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698