OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/speech_recognition_dispatcher.h" | 5 #include "content/renderer/speech_recognition_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 "content/common/speech_recognition_messages.h" | 9 #include "content/common/speech_recognition_messages.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 } | 114 } |
115 | 115 |
116 void SpeechRecognitionDispatcher::OnSoundEnded(int request_id) { | 116 void SpeechRecognitionDispatcher::OnSoundEnded(int request_id) { |
117 recognizer_client_->didEndSound(GetHandleFromID(request_id)); | 117 recognizer_client_->didEndSound(GetHandleFromID(request_id)); |
118 } | 118 } |
119 | 119 |
120 void SpeechRecognitionDispatcher::OnAudioEnded(int request_id) { | 120 void SpeechRecognitionDispatcher::OnAudioEnded(int request_id) { |
121 recognizer_client_->didEndAudio(GetHandleFromID(request_id)); | 121 recognizer_client_->didEndAudio(GetHandleFromID(request_id)); |
122 } | 122 } |
123 | 123 |
124 static WebSpeechRecognizerClient::ErrorCode WebKitErrorCode( | |
125 content::SpeechRecognitionErrorCode e) { | |
126 switch (e) { | |
127 case content::SPEECH_RECOGNITION_ERROR_NONE: | |
128 NOTREACHED(); | |
129 return WebSpeechRecognitionHandle::OtherError; | |
130 case content::SPEECH_RECOGNITION_ERROR_ABORTED: | |
131 return WebSpeechRecognitionHandle::AbortedError; | |
132 case content::SPEECH_RECOGNITION_ERROR_AUDIO: | |
133 return WebSpeechRecognitionHandle::AudioCaptureError; | |
134 case content::SPEECH_RECOGNITION_ERROR_NETWORK: | |
135 return WebSpeechRecognitionHandle::NetworkError; | |
136 case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH: | |
137 return WebSpeechRecognitionHandle::NoSpeechError; | |
138 case content::SPEECH_RECOGNITION_ERROR_NO_MATCH: | |
Satish
2012/08/01 13:30:33
looks like this canbeb removed (as it is handledi
hans
2012/08/01 14:46:21
The reason I kept the impossible cases (ERROR_NONE
| |
139 NOTREACHED(); | |
140 return WebSpeechRecognitionHandle::OtherError; | |
141 case content::SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR: | |
142 return WebSpeechRecognitionHandle::BadGrammarError; | |
143 } | |
144 NOTREACHED(); | |
145 } | |
146 | |
124 void SpeechRecognitionDispatcher::OnErrorOccurred( | 147 void SpeechRecognitionDispatcher::OnErrorOccurred( |
125 int request_id, const SpeechRecognitionError& error) { | 148 int request_id, const SpeechRecognitionError& error) { |
126 if (error.code == content::SPEECH_RECOGNITION_ERROR_NO_MATCH) { | 149 if (error.code == content::SPEECH_RECOGNITION_ERROR_NO_MATCH) { |
127 recognizer_client_->didReceiveNoMatch(GetHandleFromID(request_id), | 150 recognizer_client_->didReceiveNoMatch(GetHandleFromID(request_id), |
128 WebSpeechRecognitionResult()); | 151 WebSpeechRecognitionResult()); |
129 } else { | 152 } else { |
130 // TODO(primiano): speech_recognition_error.h must be updated to match the | |
Satish
2012/08/01 13:30:33
is this not the intention anymore?
hans
2012/08/01 14:46:21
No, I think it's better that the enum in speech_re
| |
131 // new enums defined in the the API specs (thus removing the code below). | |
132 WebSpeechRecognizerClient::ErrorCode wk_error_code; | |
133 switch (error.code) { | |
134 case content::SPEECH_RECOGNITION_ERROR_ABORTED: | |
135 wk_error_code = WebSpeechRecognizerClient::AbortedError; | |
136 break; | |
137 case content::SPEECH_RECOGNITION_ERROR_AUDIO: | |
138 wk_error_code = WebSpeechRecognizerClient::AudioCaptureError; | |
139 break; | |
140 case content::SPEECH_RECOGNITION_ERROR_NETWORK: | |
141 wk_error_code = WebSpeechRecognizerClient::NetworkError; | |
142 break; | |
143 case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH: | |
144 wk_error_code = WebSpeechRecognizerClient::NoSpeechError; | |
145 break; | |
146 case content::SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR: | |
147 wk_error_code = WebSpeechRecognizerClient::BadGrammarError; | |
148 break; | |
149 default: | |
150 NOTREACHED(); | |
151 wk_error_code = WebSpeechRecognizerClient::OtherError; | |
152 } | |
153 recognizer_client_->didReceiveError(GetHandleFromID(request_id), | 153 recognizer_client_->didReceiveError(GetHandleFromID(request_id), |
154 WebString(), // TODO(primiano): message? | 154 WebString(), // TODO(primiano): message? |
155 wk_error_code); | 155 WebKitErrorCode(error.code)); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 void SpeechRecognitionDispatcher::OnRecognitionEnded(int request_id) { | 159 void SpeechRecognitionDispatcher::OnRecognitionEnded(int request_id) { |
160 recognizer_client_->didEnd(GetHandleFromID(request_id)); | 160 recognizer_client_->didEnd(GetHandleFromID(request_id)); |
161 handle_map_.erase(request_id); | 161 handle_map_.erase(request_id); |
162 } | 162 } |
163 | 163 |
164 void SpeechRecognitionDispatcher::OnResultRetrieved( | 164 void SpeechRecognitionDispatcher::OnResultRetrieved( |
165 int request_id, const SpeechRecognitionResult& result) { | 165 int request_id, const SpeechRecognitionResult& result) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 } | 207 } |
208 return false; | 208 return false; |
209 } | 209 } |
210 | 210 |
211 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( | 211 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( |
212 int request_id) { | 212 int request_id) { |
213 HandleMap::iterator iter = handle_map_.find(request_id); | 213 HandleMap::iterator iter = handle_map_.find(request_id); |
214 DCHECK(iter != handle_map_.end()); | 214 DCHECK(iter != handle_map_.end()); |
215 return iter->second; | 215 return iter->second; |
216 } | 216 } |
OLD | NEW |