| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/tts_dispatcher.h" | 5 #include "chrome/renderer/tts_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/tts_messages.h" | 9 #include "chrome/common/tts_messages.h" |
| 10 #include "chrome/common/tts_utterance_request.h" | 10 #include "chrome/common/tts_utterance_request.h" |
| 11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebSpeechSynthesisU
tterance.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebSpeechSynthesisU
tterance.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebSpeechSynthesisV
oice.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebSpeechSynthesisV
oice.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
| 17 | 17 |
| 18 using content::RenderThread; | 18 using content::RenderThread; |
| 19 using WebKit::WebSpeechSynthesizerClient; | 19 using WebKit::WebSpeechSynthesizerClient; |
| 20 using WebKit::WebSpeechSynthesisUtterance; | 20 using WebKit::WebSpeechSynthesisUtterance; |
| 21 using WebKit::WebSpeechSynthesisVoice; | 21 using WebKit::WebSpeechSynthesisVoice; |
| 22 using WebKit::WebString; | 22 using WebKit::WebString; |
| 23 using WebKit::WebVector; | 23 using WebKit::WebVector; |
| 24 | 24 |
| 25 int TtsDispatcher::next_utterance_id_ = 1; | 25 int TtsDispatcher::next_utterance_id_ = 1; |
| 26 | 26 |
| 27 TtsDispatcher::TtsDispatcher(WebSpeechSynthesizerClient* client) | 27 TtsDispatcher::TtsDispatcher(WebSpeechSynthesizerClient* client) |
| 28 : synthesizer_client_(client), | 28 : synthesizer_client_(client) { |
| 29 main_loop_(base::MessageLoopProxy::current()) { | 29 RenderThread::Get()->AddObserver(this); |
| 30 RenderThread::Get()->AddFilter(this); | |
| 31 } | 30 } |
| 32 | 31 |
| 33 TtsDispatcher::~TtsDispatcher() { | 32 TtsDispatcher::~TtsDispatcher() { |
| 34 } | 33 } |
| 35 | 34 |
| 36 bool TtsDispatcher::OnMessageReceived(const IPC::Message& message) { | 35 bool TtsDispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| 37 bool handled = true; | 36 bool handled = true; |
| 38 IPC_BEGIN_MESSAGE_MAP(TtsDispatcher, message) | 37 IPC_BEGIN_MESSAGE_MAP(TtsDispatcher, message) |
| 39 IPC_MESSAGE_HANDLER(TtsMsg_SetVoiceList, OnSetVoiceList) | 38 IPC_MESSAGE_HANDLER(TtsMsg_SetVoiceList, OnSetVoiceList) |
| 40 IPC_MESSAGE_HANDLER(TtsMsg_DidStartSpeaking, OnDidStartSpeaking) | 39 IPC_MESSAGE_HANDLER(TtsMsg_DidStartSpeaking, OnDidStartSpeaking) |
| 41 IPC_MESSAGE_HANDLER(TtsMsg_DidFinishSpeaking, OnDidFinishSpeaking) | 40 IPC_MESSAGE_HANDLER(TtsMsg_DidFinishSpeaking, OnDidFinishSpeaking) |
| 42 IPC_MESSAGE_HANDLER(TtsMsg_DidPauseSpeaking, OnDidPauseSpeaking) | 41 IPC_MESSAGE_HANDLER(TtsMsg_DidPauseSpeaking, OnDidPauseSpeaking) |
| 43 IPC_MESSAGE_HANDLER(TtsMsg_DidResumeSpeaking, OnDidResumeSpeaking) | 42 IPC_MESSAGE_HANDLER(TtsMsg_DidResumeSpeaking, OnDidResumeSpeaking) |
| 44 IPC_MESSAGE_HANDLER(TtsMsg_WordBoundary, OnWordBoundary) | 43 IPC_MESSAGE_HANDLER(TtsMsg_WordBoundary, OnWordBoundary) |
| 45 IPC_MESSAGE_HANDLER(TtsMsg_SentenceBoundary, OnSentenceBoundary) | 44 IPC_MESSAGE_HANDLER(TtsMsg_SentenceBoundary, OnSentenceBoundary) |
| 46 IPC_MESSAGE_HANDLER(TtsMsg_MarkerEvent, OnMarkerEvent) | 45 IPC_MESSAGE_HANDLER(TtsMsg_MarkerEvent, OnMarkerEvent) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id, | 189 void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id, |
| 191 const std::string& error_message) { | 190 const std::string& error_message) { |
| 192 WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id); | 191 WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id); |
| 193 if (utterance.isNull()) | 192 if (utterance.isNull()) |
| 194 return; | 193 return; |
| 195 | 194 |
| 196 // The web speech API doesn't support an error message. | 195 // The web speech API doesn't support an error message. |
| 197 synthesizer_client_->speakingErrorOccurred(utterance); | 196 synthesizer_client_->speakingErrorOccurred(utterance); |
| 198 utterance_id_map_.erase(utterance_id); | 197 utterance_id_map_.erase(utterance_id); |
| 199 } | 198 } |
| OLD | NEW |