| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 void SpeechRecognitionDispatcher::OnAudioEnded(int request_id) { | 157 void SpeechRecognitionDispatcher::OnAudioEnded(int request_id) { |
| 158 recognizer_client_->didEndAudio(GetHandleFromID(request_id)); | 158 recognizer_client_->didEndAudio(GetHandleFromID(request_id)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 static WebSpeechRecognizerClient::ErrorCode WebKitErrorCode( | 161 static WebSpeechRecognizerClient::ErrorCode WebKitErrorCode( |
| 162 SpeechRecognitionErrorCode e) { | 162 SpeechRecognitionErrorCode e) { |
| 163 switch (e) { | 163 switch (e) { |
| 164 case SPEECH_RECOGNITION_ERROR_NONE: | 164 case SPEECH_RECOGNITION_ERROR_NONE: |
| 165 NOTREACHED(); | 165 NOTREACHED(); |
| 166 return WebSpeechRecognizerClient::OtherError; | 166 return WebSpeechRecognizerClient::OtherError; |
| 167 case SPEECH_RECOGNITION_ERROR_NO_SPEECH: |
| 168 return WebSpeechRecognizerClient::NoSpeechError; |
| 167 case SPEECH_RECOGNITION_ERROR_ABORTED: | 169 case SPEECH_RECOGNITION_ERROR_ABORTED: |
| 168 return WebSpeechRecognizerClient::AbortedError; | 170 return WebSpeechRecognizerClient::AbortedError; |
| 169 case SPEECH_RECOGNITION_ERROR_AUDIO: | 171 case SPEECH_RECOGNITION_ERROR_AUDIO: |
| 170 return WebSpeechRecognizerClient::AudioCaptureError; | 172 return WebSpeechRecognizerClient::AudioCaptureError; |
| 171 case SPEECH_RECOGNITION_ERROR_NETWORK: | 173 case SPEECH_RECOGNITION_ERROR_NETWORK: |
| 172 return WebSpeechRecognizerClient::NetworkError; | 174 return WebSpeechRecognizerClient::NetworkError; |
| 173 case SPEECH_RECOGNITION_ERROR_NOT_ALLOWED: | 175 case SPEECH_RECOGNITION_ERROR_NOT_ALLOWED: |
| 174 return WebSpeechRecognizerClient::NotAllowedError; | 176 return WebSpeechRecognizerClient::NotAllowedError; |
| 175 case SPEECH_RECOGNITION_ERROR_NO_SPEECH: | 177 case SPEECH_RECOGNITION_ERROR_SERVICE_NOT_ALLOWED: |
| 176 return WebSpeechRecognizerClient::NoSpeechError; | 178 return WebSpeechRecognizerClient::ServiceNotAllowedError; |
| 179 case SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR: |
| 180 return WebSpeechRecognizerClient::BadGrammarError; |
| 181 case SPEECH_RECOGNITION_ERROR_LANGUAGE_NOT_SUPPORTED: |
| 182 return WebSpeechRecognizerClient::LanguageNotSupportedError; |
| 177 case SPEECH_RECOGNITION_ERROR_NO_MATCH: | 183 case SPEECH_RECOGNITION_ERROR_NO_MATCH: |
| 178 NOTREACHED(); | 184 NOTREACHED(); |
| 179 return WebSpeechRecognizerClient::OtherError; | 185 return WebSpeechRecognizerClient::OtherError; |
| 180 case SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR: | |
| 181 return WebSpeechRecognizerClient::BadGrammarError; | |
| 182 } | 186 } |
| 183 NOTREACHED(); | 187 NOTREACHED(); |
| 184 return WebSpeechRecognizerClient::OtherError; | 188 return WebSpeechRecognizerClient::OtherError; |
| 185 } | 189 } |
| 186 | 190 |
| 187 void SpeechRecognitionDispatcher::OnErrorOccurred( | 191 void SpeechRecognitionDispatcher::OnErrorOccurred( |
| 188 int request_id, const SpeechRecognitionError& error) { | 192 int request_id, const SpeechRecognitionError& error) { |
| 189 if (error.code == SPEECH_RECOGNITION_ERROR_NO_MATCH) { | 193 if (error.code == SPEECH_RECOGNITION_ERROR_NO_MATCH) { |
| 190 recognizer_client_->didReceiveNoMatch(GetHandleFromID(request_id), | 194 recognizer_client_->didReceiveNoMatch(GetHandleFromID(request_id), |
| 191 WebSpeechRecognitionResult()); | 195 WebSpeechRecognitionResult()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 311 } |
| 308 | 312 |
| 309 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( | 313 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( |
| 310 int request_id) { | 314 int request_id) { |
| 311 HandleMap::iterator iter = handle_map_.find(request_id); | 315 HandleMap::iterator iter = handle_map_.find(request_id); |
| 312 DCHECK(iter != handle_map_.end()); | 316 DCHECK(iter != handle_map_.end()); |
| 313 return iter->second; | 317 return iter->second; |
| 314 } | 318 } |
| 315 | 319 |
| 316 } // namespace content | 320 } // namespace content |
| OLD | NEW |