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" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/browser/speech/speech_recognition_manager_impl.h" | 13 #include "content/browser/speech/speech_recognition_manager_impl.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/common/speech_recognition_messages.h" | 15 #include "content/common/speech_recognition_messages.h" |
16 #include "content/public/browser/speech_recognition_manager_delegate.h" | 16 #include "content/public/browser/speech_recognition_manager_delegate.h" |
17 #include "content/public/browser/speech_recognition_session_config.h" | 17 #include "content/public/browser/speech_recognition_session_config.h" |
18 #include "content/public/browser/speech_recognition_session_context.h" | 18 #include "content/public/browser/speech_recognition_session_context.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( | 23 SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( |
24 bool is_guest, | |
25 int render_process_id, | 24 int render_process_id, |
26 net::URLRequestContextGetter* context_getter) | 25 net::URLRequestContextGetter* context_getter) |
27 : BrowserMessageFilter(SpeechRecognitionMsgStart), | 26 : BrowserMessageFilter(SpeechRecognitionMsgStart), |
28 is_guest_(is_guest), | |
29 render_process_id_(render_process_id), | 27 render_process_id_(render_process_id), |
30 context_getter_(context_getter), | 28 context_getter_(context_getter), |
31 weak_factory_(this) { | 29 weak_factory_(this) { |
32 // Do not add any non-trivial initialization here, instead do it lazily when | 30 // Do not add any non-trivial initialization here, instead do it lazily when |
33 // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or | 31 // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or |
34 // add an Init() method. | 32 // add an Init() method. |
35 } | 33 } |
36 | 34 |
37 SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { | 35 SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { |
38 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderProcess( | 36 SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderProcess( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (params.origin_url != "null" && | 77 if (params.origin_url != "null" && |
80 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | 78 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( |
81 render_process_id_, GURL(params.origin_url))) { | 79 render_process_id_, GURL(params.origin_url))) { |
82 LOG(ERROR) << "SRDH::OnStartRequest, disallowed origin: " | 80 LOG(ERROR) << "SRDH::OnStartRequest, disallowed origin: " |
83 << params.origin_url; | 81 << params.origin_url; |
84 return; | 82 return; |
85 } | 83 } |
86 | 84 |
87 int embedder_render_process_id = 0; | 85 int embedder_render_process_id = 0; |
88 int embedder_render_view_id = MSG_ROUTING_NONE; | 86 int embedder_render_view_id = MSG_ROUTING_NONE; |
89 if (is_guest_) { | 87 RenderViewHostImpl* render_view_host = |
| 88 RenderViewHostImpl::FromID(render_process_id_, params.render_view_id); |
| 89 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 90 WebContents::FromRenderViewHost(render_view_host)); |
| 91 BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest(); |
| 92 if (guest) { |
90 // If the speech API request was from a guest, save the context of the | 93 // If the speech API request was from a guest, save the context of the |
91 // embedder since we will use it to decide permission. | 94 // embedder since we will use it to decide permission. |
92 RenderViewHostImpl* render_view_host = | |
93 RenderViewHostImpl::FromID(render_process_id_, params.render_view_id); | |
94 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | |
95 WebContents::FromRenderViewHost(render_view_host)); | |
96 BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest(); | |
97 | |
98 embedder_render_process_id = | 95 embedder_render_process_id = |
99 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); | 96 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
100 DCHECK_NE(embedder_render_process_id, 0); | 97 DCHECK_NE(embedder_render_process_id, 0); |
101 embedder_render_view_id = | 98 embedder_render_view_id = |
102 guest->embedder_web_contents()->GetRenderViewHost()->GetRoutingID(); | 99 guest->embedder_web_contents()->GetRenderViewHost()->GetRoutingID(); |
103 DCHECK_NE(embedder_render_view_id, MSG_ROUTING_NONE); | 100 DCHECK_NE(embedder_render_view_id, MSG_ROUTING_NONE); |
104 } | 101 } |
105 | 102 |
106 // TODO(lazyboy): Check if filter_profanities should use |render_process_id| | 103 // TODO(lazyboy): Check if filter_profanities should use |render_process_id| |
107 // instead of |render_process_id_|. | 104 // instead of |render_process_id_|. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(int session_id, | 245 void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(int session_id, |
249 float volume, | 246 float volume, |
250 float noise_volume) { | 247 float noise_volume) { |
251 } | 248 } |
252 | 249 |
253 void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete( | 250 void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete( |
254 int session_id) { | 251 int session_id) { |
255 } | 252 } |
256 | 253 |
257 } // namespace content | 254 } // namespace content |
OLD | NEW |