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 |
| 51 using FrameDeletedCallback = base::Callback<void(int)>; |
| 52 using WebContentsDeletedCallback = base::Callback<void(WebContents*)>; |
| 53 |
| 54 class SpeechRecognitionDispatcherHost::FrameDeletedObserver |
| 55 : public WebContentsObserver { |
| 56 public: |
| 57 FrameDeletedObserver(WebContents* web_contents, |
| 58 FrameDeletedCallback frame_deleted_cb, |
| 59 WebContentsDeletedCallback web_contents_deleted_cb) |
| 60 : WebContentsObserver(web_contents) { |
| 61 } |
| 62 |
| 63 ~FrameDeletedObserver() override { |
| 64 } |
| 65 |
| 66 private: |
| 67 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override { |
| 68 frame_deleted_cb_.Run(render_frame_host->GetRoutingID()); |
| 69 } |
| 70 |
| 71 void WebContentsDestroyed() override { |
| 72 web_contents_deleted_cb_.Run(web_contents()); |
| 73 } |
| 74 |
| 75 const FrameDeletedCallback frame_deleted_cb_; |
| 76 const WebContentsDeletedCallback web_contents_deleted_cb_; |
| 77 }; |
| 78 |
23 SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( | 79 SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( |
24 int render_process_id, | 80 int render_process_id) |
25 net::URLRequestContextGetter* context_getter) | |
26 : BrowserMessageFilter(SpeechRecognitionMsgStart), | 81 : BrowserMessageFilter(SpeechRecognitionMsgStart), |
27 render_process_id_(render_process_id), | 82 render_process_id_(render_process_id), |
28 context_getter_(context_getter), | |
29 weak_factory_(this) { | 83 weak_factory_(this) { |
30 // Do not add any non-trivial initialization here, instead do it lazily when | 84 // Do not add any non-trivial initialization here, instead do it lazily when |
31 // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or | 85 // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or |
32 // add an Init() method. | 86 // add an Init() method. |
33 } | 87 } |
34 | 88 |
35 SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { | 89 SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { |
36 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderProcess( | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
37 render_process_id_); | 91 weak_factory_.InvalidateWeakPtrs(); |
| 92 |
| 93 STLDeleteContainerPairSecondPointers(frame_deleted_observers_.begin(), |
| 94 frame_deleted_observers_.end()); |
38 } | 95 } |
39 | 96 |
40 base::WeakPtr<SpeechRecognitionDispatcherHost> | 97 base::WeakPtr<SpeechRecognitionDispatcherHost> |
41 SpeechRecognitionDispatcherHost::AsWeakPtr() { | 98 SpeechRecognitionDispatcherHost::AsWeakPtr() { |
42 return weak_factory_.GetWeakPtr(); | 99 return weak_factory_.GetWeakPtr(); |
43 } | 100 } |
44 | 101 |
45 void SpeechRecognitionDispatcherHost::OnDestruct() const { | 102 void SpeechRecognitionDispatcherHost::OnDestruct() const { |
46 BrowserThread::DeleteOnIOThread::Destruct(this); | 103 BrowserThread::DeleteOnIOThread::Destruct(this); |
47 } | 104 } |
48 | 105 |
| 106 void SpeechRecognitionDispatcherHost::OnChannelClosing() { |
| 107 weak_factory_.InvalidateWeakPtrs(); |
| 108 } |
| 109 |
| 110 void SpeechRecognitionDispatcherHost::OverrideThreadForMessage( |
| 111 const IPC::Message& message, BrowserThread::ID* thread) { |
| 112 if (message.type() == SpeechRecognitionHostMsg_StartRequest::ID) |
| 113 *thread = BrowserThread::UI; |
| 114 } |
| 115 |
49 bool SpeechRecognitionDispatcherHost::OnMessageReceived( | 116 bool SpeechRecognitionDispatcherHost::OnMessageReceived( |
50 const IPC::Message& message) { | 117 const IPC::Message& message) { |
51 bool handled = true; | 118 bool handled = true; |
| 119 |
52 IPC_BEGIN_MESSAGE_MAP(SpeechRecognitionDispatcherHost, message) | 120 IPC_BEGIN_MESSAGE_MAP(SpeechRecognitionDispatcherHost, message) |
53 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StartRequest, | 121 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StartRequest, |
54 OnStartRequest) | 122 OnStartRequest) |
55 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortRequest, | 123 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortRequest, |
56 OnAbortRequest) | 124 OnAbortRequest) |
57 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StopCaptureRequest, | 125 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StopCaptureRequest, |
58 OnStopCaptureRequest) | 126 OnStopCaptureRequest) |
59 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortAllRequests, | 127 IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortAllRequests, |
60 OnAbortAllRequests) | 128 OnAbortAllRequests) |
61 IPC_MESSAGE_UNHANDLED(handled = false) | 129 IPC_MESSAGE_UNHANDLED(handled = false) |
62 IPC_END_MESSAGE_MAP() | 130 IPC_END_MESSAGE_MAP() |
| 131 |
63 return handled; | 132 return handled; |
64 } | 133 } |
65 | 134 |
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( | 135 void SpeechRecognitionDispatcherHost::OnStartRequest( |
78 const SpeechRecognitionHostMsg_StartRequest_Params& params) { | 136 const SpeechRecognitionHostMsg_StartRequest_Params& params) { |
79 SpeechRecognitionHostMsg_StartRequest_Params input_params(params); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
80 | 138 |
81 // Check that the origin specified by the renderer process is one | 139 // Check that the origin specified by the renderer process is one |
82 // that it is allowed to access. | 140 // that it is allowed to access. |
83 if (params.origin_url != "null" && | 141 if (params.origin_url != "null" && |
84 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | 142 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( |
85 render_process_id_, GURL(params.origin_url))) { | 143 render_process_id_, GURL(params.origin_url))) { |
86 LOG(ERROR) << "SRDH::OnStartRequest, disallowed origin: " | 144 LOG(ERROR) << "SRDH::OnStartRequest, disallowed origin: " |
87 << params.origin_url; | 145 << params.origin_url; |
88 return; | 146 return; |
89 } | 147 } |
90 | 148 |
91 int embedder_render_process_id = 0; | 149 int embedder_render_process_id = 0; |
92 int embedder_render_view_id = MSG_ROUTING_NONE; | 150 int embedder_render_frame_id = MSG_ROUTING_NONE; |
93 RenderViewHostImpl* render_view_host = | 151 |
94 RenderViewHostImpl::FromID(render_process_id_, params.render_view_id); | 152 WebContents* web_contents = WebContents::FromRenderFrameHost( |
95 if (!render_view_host) { | 153 RenderFrameHost::FromID(render_process_id_, params.render_frame_id)); |
96 // RVH can be null if the tab was closed while continuous mode speech | 154 DCHECK(web_contents); |
97 // recognition was running. This seems to happen on mac. | 155 |
98 LOG(WARNING) << "SRDH::OnStartRequest, RenderViewHost does not exist"; | 156 BrowserPluginGuest* guest = |
99 return; | 157 static_cast<WebContentsImpl*>(web_contents)->GetBrowserPluginGuest(); |
100 } | 158 |
101 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | |
102 WebContents::FromRenderViewHost(render_view_host)); | |
103 BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest(); | |
104 if (guest) { | 159 if (guest) { |
105 // If the speech API request was from a guest, save the context of the | 160 // If the speech API request was from a guest, save the context of the |
106 // embedder since we will use it to decide permission. | 161 // embedder since we will use it to decide permission. |
107 embedder_render_process_id = | 162 embedder_render_process_id = |
108 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); | 163 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
109 DCHECK_NE(embedder_render_process_id, 0); | 164 DCHECK_NE(embedder_render_process_id, 0); |
110 embedder_render_view_id = | 165 embedder_render_frame_id = |
111 guest->embedder_web_contents()->GetRenderViewHost()->GetRoutingID(); | 166 guest->embedder_web_contents()->GetMainFrame()->GetRoutingID(); |
112 DCHECK_NE(embedder_render_view_id, MSG_ROUTING_NONE); | 167 DCHECK_NE(embedder_render_frame_id, MSG_ROUTING_NONE); |
113 } | 168 } |
114 | 169 |
115 // TODO(lazyboy): Check if filter_profanities should use |render_process_id| | |
116 // instead of |render_process_id_|. | |
117 bool filter_profanities = | 170 bool filter_profanities = |
118 SpeechRecognitionManagerImpl::GetInstance() && | 171 SpeechRecognitionManagerImpl::GetInstance() && |
119 SpeechRecognitionManagerImpl::GetInstance()->delegate() && | 172 SpeechRecognitionManagerImpl::GetInstance()->delegate() && |
120 SpeechRecognitionManagerImpl::GetInstance()->delegate()-> | 173 SpeechRecognitionManagerImpl::GetInstance()->delegate()-> |
121 FilterProfanities(render_process_id_); | 174 FilterProfanities(render_process_id_); |
122 | 175 |
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; | 176 SpeechRecognitionSessionContext context; |
148 context.context_name = params.origin_url; | 177 context.context_name = params.origin_url; |
149 context.render_process_id = render_process_id_; | 178 context.render_process_id = render_process_id_; |
150 context.render_view_id = params.render_view_id; | 179 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; | 180 context.embedder_render_process_id = embedder_render_process_id; |
153 context.embedder_render_view_id = embedder_render_view_id; | 181 context.embedder_render_frame_id = embedder_render_frame_id; |
154 if (embedder_render_process_id) | 182 if (embedder_render_process_id) |
155 context.guest_render_view_id = params.render_view_id; | 183 context.guest_render_frame_id = params.render_frame_id; |
156 context.request_id = params.request_id; | 184 context.request_id = params.request_id; |
157 | 185 |
| 186 BrowserThread::PostTask( |
| 187 BrowserThread::IO, FROM_HERE, |
| 188 base::Bind(&SpeechRecognitionDispatcherHost::StartSession, |
| 189 base::Unretained(this), |
| 190 params, |
| 191 context, |
| 192 base::Unretained(web_contents->GetBrowserContext()-> |
| 193 GetRequestContextForRenderProcess(render_process_id_)), |
| 194 filter_profanities)); |
| 195 } |
| 196 |
| 197 void SpeechRecognitionDispatcherHost::StartSession( |
| 198 const SpeechRecognitionHostMsg_StartRequest_Params& params, |
| 199 const SpeechRecognitionSessionContext& context, |
| 200 net::URLRequestContextGetter* url_request_context_getter, |
| 201 bool filter_profanities) { |
| 202 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 203 |
158 SpeechRecognitionSessionConfig config; | 204 SpeechRecognitionSessionConfig config; |
159 config.is_legacy_api = false; | 205 config.is_legacy_api = false; |
160 config.language = params.language; | 206 config.language = params.language; |
161 config.grammars = params.grammars; | 207 config.grammars = params.grammars; |
162 config.max_hypotheses = params.max_hypotheses; | 208 config.max_hypotheses = params.max_hypotheses; |
163 config.origin_url = params.origin_url; | 209 config.origin_url = params.origin_url; |
164 config.initial_context = context; | 210 config.initial_context = context; |
165 config.url_request_context_getter = context_getter_.get(); | 211 config.url_request_context_getter = url_request_context_getter; |
166 config.filter_profanities = filter_profanities; | 212 config.filter_profanities = filter_profanities; |
167 config.continuous = params.continuous; | 213 config.continuous = params.continuous; |
168 config.interim_results = params.interim_results; | 214 config.interim_results = params.interim_results; |
169 config.event_listener = AsWeakPtr(); | 215 config.event_listener = AsWeakPtr(); |
170 | 216 |
171 int session_id = SpeechRecognitionManager::GetInstance()->CreateSession( | 217 int session_id = SpeechRecognitionManager::GetInstance()->CreateSession( |
172 config); | 218 config); |
173 DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid); | 219 DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid); |
174 SpeechRecognitionManager::GetInstance()->StartSession(session_id); | 220 SpeechRecognitionManager::GetInstance()->StartSession(session_id); |
175 } | 221 } |
176 | 222 |
177 void SpeechRecognitionDispatcherHost::OnAbortRequest(int render_view_id, | 223 void SpeechRecognitionDispatcherHost::OnAbortRequest(int render_frame_id, |
178 int request_id) { | 224 int request_id) { |
| 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 226 |
179 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( | 227 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( |
180 render_process_id_, render_view_id, request_id); | 228 render_process_id_, render_frame_id, request_id); |
181 | 229 |
182 // The renderer might provide an invalid |request_id| if the session was not | 230 // The renderer might provide an invalid |request_id| if the session was not |
183 // started as expected, e.g., due to unsatisfied security requirements. | 231 // started as expected, e.g., due to unsatisfied security requirements. |
184 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) | 232 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) |
185 SpeechRecognitionManager::GetInstance()->AbortSession(session_id); | 233 SpeechRecognitionManager::GetInstance()->AbortSession(session_id); |
186 } | 234 } |
187 | 235 |
188 void SpeechRecognitionDispatcherHost::OnAbortAllRequests(int render_view_id) { | 236 void SpeechRecognitionDispatcherHost::OnAbortAllRequests(int render_frame_id) { |
189 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderView( | 237 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
190 render_process_id_, render_view_id); | 238 |
| 239 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderFrame( |
| 240 render_process_id_, render_frame_id); |
191 } | 241 } |
192 | 242 |
193 void SpeechRecognitionDispatcherHost::OnStopCaptureRequest( | 243 void SpeechRecognitionDispatcherHost::OnStopCaptureRequest( |
194 int render_view_id, int request_id) { | 244 int render_frame_id, int request_id) { |
| 245 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 246 |
195 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( | 247 int session_id = SpeechRecognitionManager::GetInstance()->GetSession( |
196 render_process_id_, render_view_id, request_id); | 248 render_process_id_, render_frame_id, request_id); |
197 | 249 |
198 // The renderer might provide an invalid |request_id| if the session was not | 250 // The renderer might provide an invalid |request_id| if the session was not |
199 // started as expected, e.g., due to unsatisfied security requirements. | 251 // started as expected, e.g., due to unsatisfied security requirements. |
200 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) { | 252 if (session_id != SpeechRecognitionManager::kSessionIDInvalid) { |
201 SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession( | 253 SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession( |
202 session_id); | 254 session_id); |
203 } | 255 } |
204 } | 256 } |
205 | 257 |
| 258 void SpeechRecognitionDispatcherHost::CreateObserverFor( |
| 259 WebContents* web_contents) { |
| 260 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 261 |
| 262 if (frame_deleted_observers_.find(web_contents) != |
| 263 frame_deleted_observers_.end()) { |
| 264 return; |
| 265 } |
| 266 |
| 267 frame_deleted_observers_.emplace( |
| 268 web_contents, |
| 269 new FrameDeletedObserver( |
| 270 web_contents, |
| 271 base::Bind(&SpeechRecognitionDispatcherHost::AbortAllRequestsFromUI, |
| 272 AsWeakPtr()), |
| 273 base::Bind(&SpeechRecognitionDispatcherHost::RemoveObserverFor, |
| 274 AsWeakPtr()))); |
| 275 } |
| 276 |
| 277 void SpeechRecognitionDispatcherHost::RemoveObserverFor( |
| 278 WebContents* web_contents) { |
| 279 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 280 |
| 281 FrameDeletedObservers::iterator it = |
| 282 frame_deleted_observers_.find(web_contents); |
| 283 if (it == frame_deleted_observers_.end()) |
| 284 return; |
| 285 |
| 286 delete it->second; |
| 287 frame_deleted_observers_.erase(web_contents); |
| 288 } |
| 289 |
| 290 void SpeechRecognitionDispatcherHost::AbortAllRequestsFromUI( |
| 291 int render_frame_id) { |
| 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 293 |
| 294 BrowserThread::PostTask( |
| 295 BrowserThread::IO, FROM_HERE, |
| 296 base::Bind(&SpeechRecognitionDispatcherHost::OnAbortAllRequests, |
| 297 this, |
| 298 render_frame_id)); |
| 299 } |
| 300 |
206 // -------- SpeechRecognitionEventListener interface implementation ----------- | 301 // -------- SpeechRecognitionEventListener interface implementation ----------- |
207 | 302 |
208 void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) { | 303 void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) { |
209 const SpeechRecognitionSessionContext& context = | 304 const SpeechRecognitionSessionContext& context = |
210 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 305 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
211 Send(new SpeechRecognitionMsg_Started(context.render_view_id, | 306 |
212 context.request_id)); | 307 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
| 308 new SpeechRecognitionMsg_Started(context.render_frame_id, |
| 309 context.request_id)); |
213 } | 310 } |
214 | 311 |
215 void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) { | 312 void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) { |
216 const SpeechRecognitionSessionContext& context = | 313 const SpeechRecognitionSessionContext& context = |
217 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 314 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
218 Send(new SpeechRecognitionMsg_AudioStarted(context.render_view_id, | 315 |
219 context.request_id)); | 316 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
| 317 new SpeechRecognitionMsg_AudioStarted( |
| 318 context.render_frame_id, context.request_id)); |
220 } | 319 } |
221 | 320 |
222 void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) { | 321 void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) { |
223 const SpeechRecognitionSessionContext& context = | 322 const SpeechRecognitionSessionContext& context = |
224 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 323 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
225 Send(new SpeechRecognitionMsg_SoundStarted(context.render_view_id, | 324 |
226 context.request_id)); | 325 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
| 326 new SpeechRecognitionMsg_SoundStarted( |
| 327 context.render_frame_id, context.request_id)); |
227 } | 328 } |
228 | 329 |
229 void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) { | 330 void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) { |
230 const SpeechRecognitionSessionContext& context = | 331 const SpeechRecognitionSessionContext& context = |
231 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 332 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
232 Send(new SpeechRecognitionMsg_SoundEnded(context.render_view_id, | 333 |
233 context.request_id)); | 334 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
| 335 new SpeechRecognitionMsg_SoundEnded( |
| 336 context.render_frame_id, context.request_id)); |
234 } | 337 } |
235 | 338 |
236 void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) { | 339 void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) { |
237 const SpeechRecognitionSessionContext& context = | 340 const SpeechRecognitionSessionContext& context = |
238 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 341 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
239 Send(new SpeechRecognitionMsg_AudioEnded(context.render_view_id, | 342 |
240 context.request_id)); | 343 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
| 344 new SpeechRecognitionMsg_AudioEnded( |
| 345 context.render_frame_id, context.request_id)); |
241 } | 346 } |
242 | 347 |
243 void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) { | 348 void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) { |
244 const SpeechRecognitionSessionContext& context = | 349 const SpeechRecognitionSessionContext& context = |
245 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 350 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
246 Send(new SpeechRecognitionMsg_Ended(context.render_view_id, | 351 |
247 context.request_id)); | 352 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
| 353 new SpeechRecognitionMsg_Ended( |
| 354 context.render_frame_id, context.request_id)); |
248 } | 355 } |
249 | 356 |
250 void SpeechRecognitionDispatcherHost::OnRecognitionResults( | 357 void SpeechRecognitionDispatcherHost::OnRecognitionResults( |
251 int session_id, | 358 int session_id, |
252 const SpeechRecognitionResults& results) { | 359 const SpeechRecognitionResults& results) { |
253 const SpeechRecognitionSessionContext& context = | 360 const SpeechRecognitionSessionContext& context = |
254 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 361 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
255 Send(new SpeechRecognitionMsg_ResultRetrieved(context.render_view_id, | 362 |
256 context.request_id, | 363 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
257 results)); | 364 new SpeechRecognitionMsg_ResultRetrieved( |
| 365 context.render_frame_id, context.request_id, results)); |
258 } | 366 } |
259 | 367 |
260 void SpeechRecognitionDispatcherHost::OnRecognitionError( | 368 void SpeechRecognitionDispatcherHost::OnRecognitionError( |
261 int session_id, | 369 int session_id, |
262 const SpeechRecognitionError& error) { | 370 const SpeechRecognitionError& error) { |
263 const SpeechRecognitionSessionContext& context = | 371 const SpeechRecognitionSessionContext& context = |
264 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 372 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
265 Send(new SpeechRecognitionMsg_ErrorOccurred(context.render_view_id, | 373 |
266 context.request_id, | 374 SendMessageToFrame(context.render_process_id, context.render_frame_id, |
267 error)); | 375 new SpeechRecognitionMsg_ErrorOccurred( |
| 376 context.render_frame_id, context.request_id, error)); |
268 } | 377 } |
269 | 378 |
270 // The events below are currently not used by speech JS APIs implementation. | 379 // The events below are currently not used by speech JS APIs implementation. |
271 void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(int session_id, | 380 void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(int session_id, |
272 float volume, | 381 float volume, |
273 float noise_volume) { | 382 float noise_volume) { |
274 } | 383 } |
275 | 384 |
276 void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete( | 385 void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete( |
277 int session_id) { | 386 int session_id) { |
278 } | 387 } |
279 | 388 |
280 } // namespace content | 389 } // namespace content |
OLD | NEW |