| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 "chrome/renderer/speech_input_dispatcher.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/renderer/render_view.h" | |
| 9 #include "content/common/speech_input_messages.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechInputListene
r.h" | |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 16 | |
| 17 using WebKit::WebFrame; | |
| 18 | |
| 19 SpeechInputDispatcher::SpeechInputDispatcher( | |
| 20 RenderView* render_view, | |
| 21 WebKit::WebSpeechInputListener* listener) | |
| 22 : RenderViewObserver(render_view), | |
| 23 listener_(listener) { | |
| 24 } | |
| 25 | |
| 26 bool SpeechInputDispatcher::OnMessageReceived(const IPC::Message& message) { | |
| 27 bool handled = true; | |
| 28 IPC_BEGIN_MESSAGE_MAP(SpeechInputDispatcher, message) | |
| 29 IPC_MESSAGE_HANDLER(SpeechInputMsg_SetRecognitionResult, | |
| 30 OnSpeechRecognitionResult) | |
| 31 IPC_MESSAGE_HANDLER(SpeechInputMsg_RecordingComplete, | |
| 32 OnSpeechRecordingComplete) | |
| 33 IPC_MESSAGE_HANDLER(SpeechInputMsg_RecognitionComplete, | |
| 34 OnSpeechRecognitionComplete) | |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 36 IPC_END_MESSAGE_MAP() | |
| 37 return handled; | |
| 38 } | |
| 39 | |
| 40 bool SpeechInputDispatcher::startRecognition( | |
| 41 int request_id, | |
| 42 const WebKit::WebRect& element_rect, | |
| 43 const WebKit::WebString& language, | |
| 44 const WebKit::WebString& grammar, | |
| 45 const WebKit::WebSecurityOrigin& origin) { | |
| 46 VLOG(1) << "SpeechInputDispatcher::startRecognition enter"; | |
| 47 | |
| 48 SpeechInputHostMsg_StartRecognition_Params params; | |
| 49 params.grammar = UTF16ToUTF8(grammar); | |
| 50 params.language = UTF16ToUTF8(language); | |
| 51 params.origin_url = UTF16ToUTF8(origin.toString()); | |
| 52 params.render_view_id = routing_id(); | |
| 53 params.request_id = request_id; | |
| 54 gfx::Size scroll = render_view()->webview()->mainFrame()->scrollOffset(); | |
| 55 params.element_rect = element_rect; | |
| 56 params.element_rect.Offset(-scroll.width(), -scroll.height()); | |
| 57 | |
| 58 Send(new SpeechInputHostMsg_StartRecognition(params)); | |
| 59 VLOG(1) << "SpeechInputDispatcher::startRecognition exit"; | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 void SpeechInputDispatcher::cancelRecognition(int request_id) { | |
| 64 VLOG(1) << "SpeechInputDispatcher::cancelRecognition enter"; | |
| 65 Send(new SpeechInputHostMsg_CancelRecognition(routing_id(), request_id)); | |
| 66 VLOG(1) << "SpeechInputDispatcher::cancelRecognition exit"; | |
| 67 } | |
| 68 | |
| 69 void SpeechInputDispatcher::stopRecording(int request_id) { | |
| 70 VLOG(1) << "SpeechInputDispatcher::stopRecording enter"; | |
| 71 Send(new SpeechInputHostMsg_StopRecording(routing_id(), request_id)); | |
| 72 VLOG(1) << "SpeechInputDispatcher::stopRecording exit"; | |
| 73 } | |
| 74 | |
| 75 void SpeechInputDispatcher::OnSpeechRecognitionResult( | |
| 76 int request_id, const speech_input::SpeechInputResultArray& result) { | |
| 77 VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionResult enter"; | |
| 78 WebKit::WebSpeechInputResultArray webkit_result(result.size()); | |
| 79 for (size_t i = 0; i < result.size(); ++i) | |
| 80 webkit_result[i].set(result[i].utterance, result[i].confidence); | |
| 81 listener_->setRecognitionResult(request_id, webkit_result); | |
| 82 VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionResult exit"; | |
| 83 } | |
| 84 | |
| 85 void SpeechInputDispatcher::OnSpeechRecordingComplete(int request_id) { | |
| 86 VLOG(1) << "SpeechInputDispatcher::OnSpeechRecordingComplete enter"; | |
| 87 listener_->didCompleteRecording(request_id); | |
| 88 VLOG(1) << "SpeechInputDispatcher::OnSpeechRecordingComplete exit"; | |
| 89 } | |
| 90 | |
| 91 void SpeechInputDispatcher::OnSpeechRecognitionComplete(int request_id) { | |
| 92 VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionComplete enter"; | |
| 93 listener_->didCompleteRecognition(request_id); | |
| 94 VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionComplete exit"; | |
| 95 } | |
| OLD | NEW |