OLD | NEW |
---|---|
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/browser/speech/speech_recognition_dispatcher_host.h" | 5 #include "content/browser/speech/speech_recognition_dispatcher_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 10 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
11 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | |
13 #include "content/browser/speech/speech_recognition_manager_impl.h" | 12 #include "content/browser/speech/speech_recognition_manager_impl.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/common/speech_recognition_messages.h" | 14 #include "content/common/speech_recognition_messages.h" |
15 #include "content/public/browser/browser_context.h" | |
16 #include "content/public/browser/browser_thread.h" | |
17 #include "content/public/browser/render_frame_host.h" | |
16 #include "content/public/browser/speech_recognition_manager_delegate.h" | 18 #include "content/public/browser/speech_recognition_manager_delegate.h" |
17 #include "content/public/browser/speech_recognition_session_config.h" | 19 #include "content/public/browser/speech_recognition_session_config.h" |
18 #include "content/public/browser/speech_recognition_session_context.h" | 20 #include "content/public/browser/speech_recognition_session_context.h" |
19 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/child_process_host.h" |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 | 24 |
25 namespace { | |
26 | |
27 void SendMessageToFrameOnUI(int render_process_id, | |
28 int render_frame_id, | |
29 IPC::Message* message) { | |
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
31 | |
32 RenderFrameHost* render_frame_host = | |
33 RenderFrameHost::FromID(render_process_id, render_frame_id); | |
34 if (render_frame_host) | |
35 render_frame_host->Send(message); | |
36 } | |
37 | |
38 void SendMessageToFrame(int render_process_id, | |
39 int render_frame_id, | |
40 IPC::Message* message) { | |
41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
42 | |
43 BrowserThread::PostTask( | |
44 BrowserThread::UI, FROM_HERE, | |
45 base::Bind(&SendMessageToFrameOnUI, | |
46 render_process_id, render_frame_id, message)); | |
47 } | |
48 | |
49 } // anonymous namespace | |
50 | |
23 SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( | 51 SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( |
24 int render_process_id, | 52 int render_process_id) |
25 net::URLRequestContextGetter* context_getter) | |
26 : BrowserMessageFilter(SpeechRecognitionMsgStart), | 53 : BrowserMessageFilter(SpeechRecognitionMsgStart), |
27 render_process_id_(render_process_id), | 54 weak_factory_(this), |
28 context_getter_(context_getter), | 55 render_process_id_(render_process_id) { |
29 weak_factory_(this) { | |
30 // Do not add any non-trivial initialization here, instead do it lazily when | 56 // Do not add any non-trivial initialization here, instead do it lazily when |
31 // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or | 57 // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or |
32 // add an Init() method. | 58 // add an Init() method. |
33 } | 59 } |
34 | 60 |
35 SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { | 61 SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { |
36 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderProcess( | 62 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
37 render_process_id_); | 63 weak_factory_.InvalidateWeakPtrs(); |
38 } | 64 } |
39 | 65 |
40 base::WeakPtr<SpeechRecognitionDispatcherHost> | 66 base::WeakPtr<SpeechRecognitionDispatcherHost> |
41 SpeechRecognitionDispatcherHost::AsWeakPtr() { | 67 SpeechRecognitionDispatcherHost::AsWeakPtr() { |
42 return weak_factory_.GetWeakPtr(); | 68 return weak_factory_.GetWeakPtr(); |
43 } | 69 } |
44 | 70 |
45 void SpeechRecognitionDispatcherHost::OnDestruct() const { | 71 void SpeechRecognitionDispatcherHost::OnDestruct() const { |
46 BrowserThread::DeleteOnIOThread::Destruct(this); | 72 BrowserThread::DeleteOnIOThread::Destruct(this); |
47 } | 73 } |
48 | 74 |
75 void SpeechRecognitionDispatcherHost::OnChannelClosing() { | |
76 weak_factory_.InvalidateWeakPtrs(); | |
77 } | |
78 | |
79 void SpeechRecognitionDispatcherHost::OverrideThreadForMessage( | |
80 const IPC::Message& message, BrowserThread::ID* thread) { | |
81 if (message.type() == SpeechRecognitionHostMsg_StartRequest::ID) | |
82 *thread = BrowserThread::UI; | |
83 } | |
84 | |
49 bool SpeechRecognitionDispatcherHost::OnMessageReceived( | 85 bool SpeechRecognitionDispatcherHost::OnMessageReceived( |
50 const IPC::Message& message) { | 86 const IPC::Message& message) { |
51 bool handled = true; | 87 bool handled = true; |
88 | |
52 IPC_BEGIN_MESSAGE_MAP(SpeechRecognitionDispatcherHost, message) | 89 IPC_BEGIN_MESSAGE_MAP(SpeechRecognitionDispatcherHost, message) |
53 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StartRequest, | 90 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StartRequest, |
54 OnStartRequest) | 91 OnStartRequest) |
55 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortRequest, | 92 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortRequest, |
56 OnAbortRequest) | 93 OnAbortRequest) |
57 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StopCaptureRequest, | 94 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StopCaptureRequest, |
58 OnStopCaptureRequest) | 95 OnStopCaptureRequest) |
59 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortAllRequests, | 96 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortAllRequests, |
60 OnAbortAllRequests) | 97 OnAbortAllRequests) |
61 IPC_MESSAGE_UNHANDLED(handled = false) | 98 IPC_MESSAGE_UNHANDLED(handled = false) |
62 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
100 | |
63 return handled; | 101 return handled; |
64 } | 102 } |
65 | 103 |
66 void SpeechRecognitionDispatcherHost::OverrideThreadForMessage( | |
67 const IPC::Message& message, | |
68 BrowserThread::ID* thread) { | |
69 if (message.type() == SpeechRecognitionHostMsg_StartRequest::ID) | |
70 *thread = BrowserThread::UI; | |
71 } | |
72 | |
73 void SpeechRecognitionDispatcherHost::OnChannelClosing() { | |
74 weak_factory_.InvalidateWeakPtrs(); | |
75 } | |
76 | |
77 void SpeechRecognitionDispatcherHost::OnStartRequest( | 104 void SpeechRecognitionDispatcherHost::OnStartRequest( |
78 const SpeechRecognitionHostMsg_StartRequest_Params& params) { | 105 const SpeechRecognitionHostMsg_StartRequest_Params& params) { |
79 SpeechRecognitionHostMsg_StartRequest_Params input_params(params); | 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
80 | 107 |
81 // Check that the origin specified by the renderer process is one | 108 // Check that the origin specified by the renderer process is one |
82 // that it is allowed to access. | 109 // that it is allowed to access. |
83 if (params.origin_url != "null" && | 110 if (params.origin_url != "null" && |
84 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | 111 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( |
85 render_process_id_, GURL(params.origin_url))) { | 112 render_process_id_, GURL(params.origin_url))) { |
86 LOG(ERROR) << "SRDH::OnStartRequest, disallowed origin: " | 113 LOG(ERROR) << "SRDH::OnStartRequest, disallowed origin: " |
87 << params.origin_url; | 114 << params.origin_url; |
88 return; | 115 return; |
89 } | 116 } |
90 | 117 |
91 int embedder_render_process_id = 0; | 118 int embedder_render_process_id = 0; |
92 int embedder_render_view_id = MSG_ROUTING_NONE; | 119 int embedder_render_frame_id = MSG_ROUTING_NONE; |
93 RenderViewHostImpl* render_view_host = | 120 |
94 RenderViewHostImpl::FromID(render_process_id_, params.render_view_id); | 121 WebContents* web_contents = WebContents::FromRenderFrameHost( |
95 if (!render_view_host) { | 122 RenderFrameHost::FromID(render_process_id_, params.render_frame_id)); |
96 // RVH can be null if the tab was closed while continuous mode speech | 123 DCHECK(web_contents); |
97 // recognition was running. This seems to happen on mac. | 124 |
98 LOG(WARNING) << "SRDH::OnStartRequest, RenderViewHost does not exist"; | 125 BrowserPluginGuest* guest = |
99 return; | 126 static_cast<WebContentsImpl*>(web_contents)->GetBrowserPluginGuest(); |
100 } | 127 |
101 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | |
102 WebContents::FromRenderViewHost(render_view_host)); | |
103 BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest(); | |
104 if (guest) { | 128 if (guest) { |
105 // If the speech API request was from a guest, save the context of the | 129 // If the speech API request was from a guest, save the context of the |
106 // embedder since we will use it to decide permission. | 130 // embedder since we will use it to decide permission. |
107 embedder_render_process_id = | 131 embedder_render_process_id = |
108 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); | 132 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
109 DCHECK_NE(embedder_render_process_id, 0); | 133 DCHECK_NE(embedder_render_process_id, 0); |
110 embedder_render_view_id = | 134 embedder_render_frame_id = |
111 guest->embedder_web_contents()->GetRenderViewHost()->GetRoutingID(); | 135 guest->embedder_web_contents()->GetMainFrame()->GetRoutingID(); |
112 DCHECK_NE(embedder_render_view_id, MSG_ROUTING_NONE); | 136 DCHECK_NE(embedder_render_frame_id, MSG_ROUTING_NONE); |
113 } | 137 } |
114 | 138 |
115 // TODO(lazyboy): Check if filter_profanities should use |render_process_id| | |
116 // instead of |render_process_id_|. | |
117 bool filter_profanities = | 139 bool filter_profanities = |
118 SpeechRecognitionManagerImpl::GetInstance() && | 140 SpeechRecognitionManagerImpl::GetInstance() && |
119 SpeechRecognitionManagerImpl::GetInstance()->delegate() && | 141 SpeechRecognitionManagerImpl::GetInstance()->delegate() && |
120 SpeechRecognitionManagerImpl::GetInstance()->delegate()-> | 142 SpeechRecognitionManagerImpl::GetInstance()->delegate()-> |
121 FilterProfanities(render_process_id_); | 143 FilterProfanities(render_process_id_); |
122 | 144 |
123 // TODO(miu): This is a hack to allow SpeechRecognition to operate with the | |
124 // MediaStreamManager, which partitions requests per RenderFrame, not per | |
125 // RenderView. http://crbug.com/390749 | |
126 const int params_render_frame_id = render_view_host ? | |
127 render_view_host->GetMainFrame()->GetRoutingID() : MSG_ROUTING_NONE; | |
128 | |
129 BrowserThread::PostTask( | |
130 BrowserThread::IO, | |
131 FROM_HERE, | |
132 base::Bind(&SpeechRecognitionDispatcherHost::OnStartRequestOnIO, | |
133 this, | |
134 embedder_render_process_id, | |
135 embedder_render_view_id, | |
136 input_params, | |
137 params_render_frame_id, | |
138 filter_profanities)); | |
139 } | |
140 | |
141 void SpeechRecognitionDispatcherHost::OnStartRequestOnIO( | |
142 int embedder_render_process_id, | |
143 int embedder_render_view_id, | |
144 const SpeechRecognitionHostMsg_StartRequest_Params& params, | |
145 int params_render_frame_id, | |
146 bool filter_profanities) { | |
147 SpeechRecognitionSessionContext context; | 145 SpeechRecognitionSessionContext context; |
148 context.context_name = params.origin_url; | 146 context.context_name = params.origin_url; |
149 context.render_process_id = render_process_id_; | 147 context.render_process_id = render_process_id_; |
150 context.render_view_id = params.render_view_id; | 148 context.render_frame_id = params.render_frame_id; |
151 context.render_frame_id = params_render_frame_id; | |
152 context.embedder_render_process_id = embedder_render_process_id; | 149 context.embedder_render_process_id = embedder_render_process_id; |
153 context.embedder_render_view_id = embedder_render_view_id; | 150 context.embedder_render_frame_id = embedder_render_frame_id; |
154 if (embedder_render_process_id) | 151 if (embedder_render_process_id) |
155 context.guest_render_view_id = params.render_view_id; | 152 context.guest_render_frame_id = params.render_frame_id; |
156 context.request_id = params.request_id; | 153 context.request_id = params.request_id; |
157 | 154 |
155 BrowserThread::PostTask( | |
156 BrowserThread::IO, FROM_HERE, | |
157 base::Bind(&SpeechRecognitionDispatcherHost::StartSession, | |
158 base::Unretained(this), | |
159 params, | |
160 context, | |
161 base::Unretained(web_contents->GetBrowserContext()-> | |
162 GetRequestContextForRenderProcess(render_process_id_)), | |
163 filter_profanities)); | |
164 } | |
165 | |
166 void SpeechRecognitionDispatcherHost::StartSession( | |
167 const SpeechRecognitionHostMsg_StartRequest_Params& params, | |
168 const SpeechRecognitionSessionContext& context, | |
169 net::URLRequestContextGetter* url_request_context_getter, | |
170 bool filter_profanities) { | |
171 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
172 | |
158 SpeechRecognitionSessionConfig config; | 173 SpeechRecognitionSessionConfig config; |
159 config.is_legacy_api = false; | 174 config.is_legacy_api = false; |
160 config.language = params.language; | 175 config.language = params.language; |
161 config.grammars = params.grammars; | 176 config.grammars = params.grammars; |
162 config.max_hypotheses = params.max_hypotheses; | 177 config.max_hypotheses = params.max_hypotheses; |
163 config.origin_url = params.origin_url; | 178 config.origin_url = params.origin_url; |
164 config.initial_context = context; | 179 config.initial_context = context; |
165 config.url_request_context_getter = context_getter_.get(); | 180 config.url_request_context_getter = url_request_context_getter; |
166 config.filter_profanities = filter_profanities; | 181 config.filter_profanities = filter_profanities; |
167 config.continuous = params.continuous; | 182 config.continuous = params.continuous; |
168 config.interim_results = params.interim_results; | 183 config.interim_results = params.interim_results; |
169 config.event_listener = AsWeakPtr(); | 184 config.event_listener = AsWeakPtr(); |
170 | 185 |
171 int session_id = SpeechRecognitionManager::GetInstance()->CreateSession( | 186 int session_id = SpeechRecognitionManager::GetInstance()->CreateSession( |
172 config); | 187 config); |
173 DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid); | 188 DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid); |
174 SpeechRecognitionManager::GetInstance()->StartSession(session_id); | 189 SpeechRecognitionManager::GetInstance()->StartSession(session_id); |
175 } | 190 } |
176 | 191 |
177 void SpeechRecognitionDispatcherHost::OnAbortRequest(int render_view_id, | 192 void SpeechRecognitionDispatcherHost::OnAbortRequest(int request_id, |
178 int request_id) { | 193 int render_frame_id) { |
194 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
195 | |
179 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( | 196 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( |
180 render_process_id_, render_view_id, request_id); | 197 render_process_id_, render_frame_id, request_id); |
Charlie Reis
2014/12/09 00:52:33
Here's another reason to keep the order consistent
| |
181 | 198 |
182 // The renderer might provide an invalid |request_id| if the session was not | 199 // The renderer might provide an invalid |request_id| if the session was not |
183 // started as expected, e.g., due to unsatisfied security requirements. | 200 // started as expected, e.g., due to unsatisfied security requirements. |
184 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) | 201 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) |
185 SpeechRecognitionManager::GetInstance()->AbortSession(session_id); | 202 SpeechRecognitionManager::GetInstance()->AbortSession(session_id); |
186 } | 203 } |
187 | 204 |
188 void SpeechRecognitionDispatcherHost::OnAbortAllRequests(int render_view_id) { | 205 void SpeechRecognitionDispatcherHost::OnAbortAllRequests(int render_frame_id) { |
189 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderView( | 206 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
190 render_process_id_, render_view_id); | 207 |
208 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderFrame( | |
209 render_process_id_, render_frame_id); | |
191 } | 210 } |
192 | 211 |
193 void SpeechRecognitionDispatcherHost::OnStopCaptureRequest( | 212 void SpeechRecognitionDispatcherHost::OnStopCaptureRequest( |
194 int render_view_id, int request_id) { | 213 int request_id, int render_frame_id) { |
214 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
215 | |
195 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( | 216 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( |
196 render_process_id_, render_view_id, request_id); | 217 render_process_id_, render_frame_id, request_id); |
197 | 218 |
198 // The renderer might provide an invalid |request_id| if the session was not | 219 // The renderer might provide an invalid |request_id| if the session was not |
199 // started as expected, e.g., due to unsatisfied security requirements. | 220 // started as expected, e.g., due to unsatisfied security requirements. |
200 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) { | 221 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) { |
201 SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession( | 222 SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession( |
202 session_id); | 223 session_id); |
203 } | 224 } |
204 } | 225 } |
205 | 226 |
206 // -------- SpeechRecognitionEventListener interface implementation ----------- | 227 // -------- SpeechRecognitionEventListener interface implementation ----------- |
207 | 228 |
208 void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) { | 229 void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) { |
209 const SpeechRecognitionSessionContext& context = | 230 const SpeechRecognitionSessionContext& context = |
210 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 231 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
211 Send(new SpeechRecognitionMsg_Started(context.render_view_id, | 232 |
212 context.request_id)); | 233 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
234 new SpeechRecognitionMsg_Started(context.render_frame_id, | |
235 context.request_id)); | |
213 } | 236 } |
214 | 237 |
215 void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) { | 238 void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) { |
216 const SpeechRecognitionSessionContext& context = | 239 const SpeechRecognitionSessionContext& context = |
217 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 240 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
218 Send(new SpeechRecognitionMsg_AudioStarted(context.render_view_id, | 241 |
219 context.request_id)); | 242 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
243 new SpeechRecognitionMsg_AudioStarted( | |
244 context.render_frame_id, context.request_id)); | |
220 } | 245 } |
221 | 246 |
222 void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) { | 247 void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) { |
223 const SpeechRecognitionSessionContext& context = | 248 const SpeechRecognitionSessionContext& context = |
224 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 249 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
225 Send(new SpeechRecognitionMsg_SoundStarted(context.render_view_id, | 250 |
226 context.request_id)); | 251 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
252 new SpeechRecognitionMsg_SoundStarted( | |
253 context.render_frame_id, context.request_id)); | |
227 } | 254 } |
228 | 255 |
229 void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) { | 256 void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) { |
230 const SpeechRecognitionSessionContext& context = | 257 const SpeechRecognitionSessionContext& context = |
231 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 258 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
232 Send(new SpeechRecognitionMsg_SoundEnded(context.render_view_id, | 259 |
233 context.request_id)); | 260 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
261 new SpeechRecognitionMsg_SoundEnded( | |
262 context.render_frame_id, context.request_id)); | |
234 } | 263 } |
235 | 264 |
236 void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) { | 265 void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) { |
237 const SpeechRecognitionSessionContext& context = | 266 const SpeechRecognitionSessionContext& context = |
238 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 267 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
239 Send(new SpeechRecognitionMsg_AudioEnded(context.render_view_id, | 268 |
240 context.request_id)); | 269 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
270 new SpeechRecognitionMsg_AudioEnded( | |
271 context.render_frame_id, context.request_id)); | |
241 } | 272 } |
242 | 273 |
243 void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) { | 274 void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) { |
244 const SpeechRecognitionSessionContext& context = | 275 const SpeechRecognitionSessionContext& context = |
245 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 276 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
246 Send(new SpeechRecognitionMsg_Ended(context.render_view_id, | 277 |
247 context.request_id)); | 278 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
279 new SpeechRecognitionMsg_Ended( | |
280 context.render_frame_id, context.request_id)); | |
248 } | 281 } |
249 | 282 |
250 void SpeechRecognitionDispatcherHost::OnRecognitionResults( | 283 void SpeechRecognitionDispatcherHost::OnRecognitionResults( |
251 int session_id, | 284 int session_id, |
252 const SpeechRecognitionResults& results) { | 285 const SpeechRecognitionResults& results) { |
253 const SpeechRecognitionSessionContext& context = | 286 const SpeechRecognitionSessionContext& context = |
254 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 287 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
255 Send(new SpeechRecognitionMsg_ResultRetrieved(context.render_view_id, | 288 |
256 context.request_id, | 289 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
257 results)); | 290 new SpeechRecognitionMsg_ResultRetrieved( |
291 context.render_frame_id, context.request_id, results)); | |
258 } | 292 } |
259 | 293 |
260 void SpeechRecognitionDispatcherHost::OnRecognitionError( | 294 void SpeechRecognitionDispatcherHost::OnRecognitionError( |
261 int session_id, | 295 int session_id, |
262 const SpeechRecognitionError& error) { | 296 const SpeechRecognitionError& error) { |
263 const SpeechRecognitionSessionContext& context = | 297 const SpeechRecognitionSessionContext& context = |
264 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 298 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
265 Send(new SpeechRecognitionMsg_ErrorOccurred(context.render_view_id, | 299 |
266 context.request_id, | 300 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
267 error)); | 301 new SpeechRecognitionMsg_ErrorOccurred( |
302 context.render_frame_id, context.request_id, error)); | |
268 } | 303 } |
269 | 304 |
270 // The events below are currently not used by speech JS APIs implementation. | 305 // The events below are currently not used by speech JS APIs implementation. |
271 void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(int session_id, | 306 void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(int session_id, |
272 float volume, | 307 float volume, |
273 float noise_volume) { | 308 float noise_volume) { |
274 } | 309 } |
275 | 310 |
276 void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete( | 311 void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete( |
277 int session_id) { | 312 int session_id) { |
278 } | 313 } |
279 | 314 |
280 } // namespace content | 315 } // namespace content |
OLD | NEW |