Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 return handled; | 52 return handled; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SpeechRecognitionDispatcher::start( | 55 void SpeechRecognitionDispatcher::start( |
| 56 const WebSpeechRecognitionHandle& handle, | 56 const WebSpeechRecognitionHandle& handle, |
| 57 const WebSpeechRecognitionParams& params, | 57 const WebSpeechRecognitionParams& params, |
| 58 WebSpeechRecognizerClient* recognizer_client) { | 58 WebSpeechRecognizerClient* recognizer_client) { |
| 59 DCHECK(!recognizer_client_ || recognizer_client_ == recognizer_client); | 59 DCHECK(!recognizer_client_ || recognizer_client_ == recognizer_client); |
| 60 recognizer_client_ = recognizer_client; | 60 recognizer_client_ = recognizer_client; |
| 61 | 61 |
| 62 // TODO(primiano): Should return false in order to communicate the failure | |
|
Satish
2012/09/12 06:15:09
Is this being removed because a different change a
hans
2012/09/12 09:46:58
Yes, it's handled in WebKit.
| |
| 63 // and let WebKit throw an exception (need a hans@ patch to do that). | |
| 64 if (HandleExists(handle)) | |
| 65 return; | |
| 66 | |
| 67 SpeechRecognitionHostMsg_StartRequest_Params msg_params; | 62 SpeechRecognitionHostMsg_StartRequest_Params msg_params; |
| 68 for (size_t i = 0; i < params.grammars().size(); ++i) { | 63 for (size_t i = 0; i < params.grammars().size(); ++i) { |
| 69 const WebSpeechGrammar& grammar = params.grammars()[i]; | 64 const WebSpeechGrammar& grammar = params.grammars()[i]; |
| 70 msg_params.grammars.push_back( | 65 msg_params.grammars.push_back( |
| 71 content::SpeechRecognitionGrammar(grammar.src().spec(), | 66 content::SpeechRecognitionGrammar(grammar.src().spec(), |
| 72 grammar.weight())); | 67 grammar.weight())); |
| 73 } | 68 } |
| 74 msg_params.language = UTF16ToUTF8(params.language()); | 69 msg_params.language = UTF16ToUTF8(params.language()); |
| 75 msg_params.is_one_shot = !params.continuous(); | 70 msg_params.is_one_shot = !params.continuous(); |
| 76 msg_params.max_hypotheses = static_cast<uint32>(params.maxAlternatives()); | 71 msg_params.max_hypotheses = static_cast<uint32>(params.maxAlternatives()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 switch (e) { | 121 switch (e) { |
| 127 case content::SPEECH_RECOGNITION_ERROR_NONE: | 122 case content::SPEECH_RECOGNITION_ERROR_NONE: |
| 128 NOTREACHED(); | 123 NOTREACHED(); |
| 129 return WebSpeechRecognizerClient::OtherError; | 124 return WebSpeechRecognizerClient::OtherError; |
| 130 case content::SPEECH_RECOGNITION_ERROR_ABORTED: | 125 case content::SPEECH_RECOGNITION_ERROR_ABORTED: |
| 131 return WebSpeechRecognizerClient::AbortedError; | 126 return WebSpeechRecognizerClient::AbortedError; |
| 132 case content::SPEECH_RECOGNITION_ERROR_AUDIO: | 127 case content::SPEECH_RECOGNITION_ERROR_AUDIO: |
| 133 return WebSpeechRecognizerClient::AudioCaptureError; | 128 return WebSpeechRecognizerClient::AudioCaptureError; |
| 134 case content::SPEECH_RECOGNITION_ERROR_NETWORK: | 129 case content::SPEECH_RECOGNITION_ERROR_NETWORK: |
| 135 return WebSpeechRecognizerClient::NetworkError; | 130 return WebSpeechRecognizerClient::NetworkError; |
| 131 case content::SPEECH_RECOGNITION_ERROR_NOT_ALLOWED: | |
| 132 return WebSpeechRecognizerClient::NotAllowedError; | |
| 136 case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH: | 133 case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH: |
| 137 return WebSpeechRecognizerClient::NoSpeechError; | 134 return WebSpeechRecognizerClient::NoSpeechError; |
| 138 case content::SPEECH_RECOGNITION_ERROR_NO_MATCH: | 135 case content::SPEECH_RECOGNITION_ERROR_NO_MATCH: |
| 139 NOTREACHED(); | 136 NOTREACHED(); |
| 140 return WebSpeechRecognizerClient::OtherError; | 137 return WebSpeechRecognizerClient::OtherError; |
| 141 case content::SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR: | 138 case content::SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR: |
| 142 return WebSpeechRecognizerClient::BadGrammarError; | 139 return WebSpeechRecognizerClient::BadGrammarError; |
| 143 } | 140 } |
| 144 NOTREACHED(); | 141 NOTREACHED(); |
| 145 return WebSpeechRecognizerClient::OtherError; | 142 return WebSpeechRecognizerClient::OtherError; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 205 } |
| 209 return false; | 206 return false; |
| 210 } | 207 } |
| 211 | 208 |
| 212 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( | 209 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( |
| 213 int request_id) { | 210 int request_id) { |
| 214 HandleMap::iterator iter = handle_map_.find(request_id); | 211 HandleMap::iterator iter = handle_map_.find(request_id); |
| 215 DCHECK(iter != handle_map_.end()); | 212 DCHECK(iter != handle_map_.end()); |
| 216 return iter->second; | 213 return iter->second; |
| 217 } | 214 } |
| OLD | NEW |