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