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