Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(721)

Side by Side Diff: content/renderer/speech_recognition_dispatcher.cc

Issue 2656043002: Use explicit WebString conversions in remaining content files (Closed)
Patch Set: build fix Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ResetAudioSink(); 101 ResetAudioSink();
102 #endif 102 #endif
103 103
104 SpeechRecognitionHostMsg_StartRequest_Params msg_params; 104 SpeechRecognitionHostMsg_StartRequest_Params msg_params;
105 for (size_t i = 0; i < params.grammars().size(); ++i) { 105 for (size_t i = 0; i < params.grammars().size(); ++i) {
106 const WebSpeechGrammar& grammar = params.grammars()[i]; 106 const WebSpeechGrammar& grammar = params.grammars()[i];
107 msg_params.grammars.push_back( 107 msg_params.grammars.push_back(
108 SpeechRecognitionGrammar(grammar.src().string().utf8(), 108 SpeechRecognitionGrammar(grammar.src().string().utf8(),
109 grammar.weight())); 109 grammar.weight()));
110 } 110 }
111 msg_params.language = 111 msg_params.language = params.language().utf8();
112 base::UTF16ToUTF8(base::StringPiece16(params.language()));
113 msg_params.max_hypotheses = static_cast<uint32_t>(params.maxAlternatives()); 112 msg_params.max_hypotheses = static_cast<uint32_t>(params.maxAlternatives());
114 msg_params.continuous = params.continuous(); 113 msg_params.continuous = params.continuous();
115 msg_params.interim_results = params.interimResults(); 114 msg_params.interim_results = params.interimResults();
116 msg_params.origin_url = params.origin().toString().utf8(); 115 msg_params.origin_url = params.origin().toString().utf8();
117 msg_params.render_view_id = routing_id(); 116 msg_params.render_view_id = routing_id();
118 msg_params.request_id = GetOrCreateIDForHandle(handle); 117 msg_params.request_id = GetOrCreateIDForHandle(handle);
119 #if BUILDFLAG(ENABLE_WEBRTC) 118 #if BUILDFLAG(ENABLE_WEBRTC)
120 // Fall back to default input when the track is not allowed. 119 // Fall back to default input when the track is not allowed.
121 msg_params.using_audio_track = !audio_track_.isNull(); 120 msg_params.using_audio_track = !audio_track_.isNull();
122 #else 121 #else
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 int provisional_index = 0, final_index = 0; 245 int provisional_index = 0, final_index = 0;
247 for (it = results.begin(); it != results.end(); ++it) { 246 for (it = results.begin(); it != results.end(); ++it) {
248 const SpeechRecognitionResult& result = (*it); 247 const SpeechRecognitionResult& result = (*it);
249 WebSpeechRecognitionResult* webkit_result = result.is_provisional ? 248 WebSpeechRecognitionResult* webkit_result = result.is_provisional ?
250 &provisional[provisional_index++] : &final[final_index++]; 249 &provisional[provisional_index++] : &final[final_index++];
251 250
252 const size_t num_hypotheses = result.hypotheses.size(); 251 const size_t num_hypotheses = result.hypotheses.size();
253 WebVector<WebString> transcripts(num_hypotheses); 252 WebVector<WebString> transcripts(num_hypotheses);
254 WebVector<float> confidences(num_hypotheses); 253 WebVector<float> confidences(num_hypotheses);
255 for (size_t i = 0; i < num_hypotheses; ++i) { 254 for (size_t i = 0; i < num_hypotheses; ++i) {
256 transcripts[i] = result.hypotheses[i].utterance; 255 transcripts[i] = WebString::fromUTF16(result.hypotheses[i].utterance);
257 confidences[i] = static_cast<float>(result.hypotheses[i].confidence); 256 confidences[i] = static_cast<float>(result.hypotheses[i].confidence);
258 } 257 }
259 webkit_result->assign(transcripts, confidences, !result.is_provisional); 258 webkit_result->assign(transcripts, confidences, !result.is_provisional);
260 } 259 }
261 260
262 recognizer_client_->didReceiveResults( 261 recognizer_client_->didReceiveResults(
263 GetHandleFromID(request_id), final, provisional); 262 GetHandleFromID(request_id), final, provisional);
264 } 263 }
265 264
266 void SpeechRecognitionDispatcher::OnAudioReceiverReady( 265 void SpeechRecognitionDispatcher::OnAudioReceiverReady(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 320 }
322 321
323 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID( 322 const WebSpeechRecognitionHandle& SpeechRecognitionDispatcher::GetHandleFromID(
324 int request_id) { 323 int request_id) {
325 HandleMap::iterator iter = handle_map_.find(request_id); 324 HandleMap::iterator iter = handle_map_.find(request_id);
326 CHECK(iter != handle_map_.end()); 325 CHECK(iter != handle_map_.end());
327 return iter->second; 326 return iter->second;
328 } 327 }
329 328
330 } // namespace content 329 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698