OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/speech/tts_dispatcher_host_impl.h" |
| 6 |
| 7 #include "content/public/browser/content_browser_client.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 TtsDispatcherHostImpl::TtsDispatcherHostImpl( |
| 12 int render_process_id, |
| 13 BrowserContext* browser_context) |
| 14 : render_process_id_(render_process_id), |
| 15 browser_context_(browser_context), |
| 16 delegate_( |
| 17 GetContentClient()->browser()->GetTtsDispatcherHostDelegate()) { |
| 18 } |
| 19 |
| 20 TtsDispatcherHostImpl::~TtsDispatcherHostImpl() { |
| 21 } |
| 22 |
| 23 BrowserContext* TtsDispatcherHostImpl::GetBrowserContext() { |
| 24 return browser_context_; |
| 25 } |
| 26 |
| 27 bool TtsDispatcherHostImpl::OnMessageReceived( |
| 28 const IPC::Message& message, bool* message_was_ok) { |
| 29 bool handled = true; |
| 30 IPC_BEGIN_MESSAGE_MAP_EX(TtsDispatcherHostImpl, message, |
| 31 *message_was_ok) |
| 32 IPC_MESSAGE_HANDLER(TtsHostMsg_InitializeVoiceList, OnInitializeVoiceList) |
| 33 IPC_MESSAGE_HANDLER(TtsHostMsg_Speak, OnSpeak) |
| 34 IPC_MESSAGE_HANDLER(TtsHostMsg_Pause, OnPause) |
| 35 IPC_MESSAGE_HANDLER(TtsHostMsg_Resume, OnResume) |
| 36 IPC_MESSAGE_HANDLER(TtsHostMsg_Cancel, OnCancel) |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) |
| 38 IPC_END_MESSAGE_MAP() |
| 39 return handled; |
| 40 } |
| 41 |
| 42 void TtsDispatcherHostImpl::OnInitializeVoiceList() { |
| 43 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 44 BrowserThread::PostTask( |
| 45 BrowserThread::UI, FROM_HERE, |
| 46 base::Bind(&TtsDispatcherHostImpl::OnInitializeVoiceList, this)); |
| 47 return; |
| 48 } |
| 49 |
| 50 if (delegate_) |
| 51 delegate_->OnInitializeVoiceList(this); |
| 52 } |
| 53 |
| 54 void TtsDispatcherHostImpl::OnSpeak(const TtsUtteranceRequest& utterance) { |
| 55 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 56 BrowserThread::PostTask( |
| 57 BrowserThread::UI, FROM_HERE, |
| 58 base::Bind(&TtsDispatcherHostImpl::OnSpeak, |
| 59 this, |
| 60 utterance)); |
| 61 return; |
| 62 } |
| 63 |
| 64 if (delegate_) |
| 65 delegate_->OnSpeak(this, utterance); |
| 66 } |
| 67 |
| 68 void TtsDispatcherHostImpl::OnPause() { |
| 69 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 70 BrowserThread::PostTask( |
| 71 BrowserThread::UI, FROM_HERE, |
| 72 base::Bind(&TtsDispatcherHostImpl::OnPause, this)); |
| 73 return; |
| 74 } |
| 75 |
| 76 if (delegate_) |
| 77 delegate_->OnPause(this); |
| 78 } |
| 79 |
| 80 void TtsDispatcherHostImpl::OnResume() { |
| 81 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 82 BrowserThread::PostTask( |
| 83 BrowserThread::UI, FROM_HERE, |
| 84 base::Bind(&TtsDispatcherHostImpl::OnResume, this)); |
| 85 return; |
| 86 } |
| 87 |
| 88 if (delegate_) |
| 89 delegate_->OnResume(this); |
| 90 } |
| 91 |
| 92 void TtsDispatcherHostImpl::OnCancel() { |
| 93 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 94 BrowserThread::PostTask( |
| 95 BrowserThread::UI, FROM_HERE, |
| 96 base::Bind(&TtsDispatcherHostImpl::OnCancel, this)); |
| 97 return; |
| 98 } |
| 99 |
| 100 if (delegate_) |
| 101 delegate_->OnCancel(this); |
| 102 } |
| 103 |
| 104 void TtsDispatcherHostImpl::DidStartSpeaking(int utterance_id) { |
| 105 Send(new TtsMsg_DidStartSpeaking(utterance_id)); |
| 106 } |
| 107 |
| 108 void TtsDispatcherHostImpl::DidFinishSpeaking(int utterance_id) { |
| 109 Send(new TtsMsg_DidFinishSpeaking(utterance_id)); |
| 110 } |
| 111 |
| 112 void TtsDispatcherHostImpl::DidPauseSpeaking(int utterance_id) { |
| 113 Send(new TtsMsg_DidPauseSpeaking(utterance_id)); |
| 114 } |
| 115 |
| 116 void TtsDispatcherHostImpl::DidResumeSpeaking(int utterance_id) { |
| 117 Send(new TtsMsg_DidResumeSpeaking(utterance_id)); |
| 118 } |
| 119 |
| 120 void TtsDispatcherHostImpl::WordBoundary(int utterance_id, int char_index) { |
| 121 Send(new TtsMsg_WordBoundary(utterance_id, char_index)); |
| 122 } |
| 123 |
| 124 void TtsDispatcherHostImpl::SentenceBoundary( |
| 125 int utterance_id, int char_index) { |
| 126 Send(new TtsMsg_SentenceBoundary(utterance_id, char_index)); |
| 127 } |
| 128 |
| 129 void TtsDispatcherHostImpl::MarkerEvent(int utterance_id, int char_index) { |
| 130 Send(new TtsMsg_MarkerEvent(utterance_id, char_index)); |
| 131 } |
| 132 |
| 133 void TtsDispatcherHostImpl::WasInterrupted(int utterance_id) { |
| 134 Send(new TtsMsg_WasInterrupted(utterance_id)); |
| 135 } |
| 136 |
| 137 void TtsDispatcherHostImpl::WasCancelled(int utterance_id) { |
| 138 Send(new TtsMsg_WasCancelled(utterance_id)); |
| 139 } |
| 140 |
| 141 void TtsDispatcherHostImpl::SpeakingErrorOccurred( |
| 142 int utterance_id, const std::string& error_message) { |
| 143 Send(new TtsMsg_SpeakingErrorOccurred( |
| 144 utterance_id, error_message)); |
| 145 } |
| 146 |
| 147 void TtsDispatcherHostImpl::SendVoiceList( |
| 148 const std::vector<content::TtsVoice>& voices) { |
| 149 Send(new TtsMsg_SetVoiceList(voices)); |
| 150 } |
| 151 |
| 152 } // namespace content |
OLD | NEW |