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