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