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