Chromium Code Reviews| Index: chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
| diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
| index 24fe3e9a16db1a421e1a96dc7131063eacd7974a..12373bf66d7da33ed7a17ae6dda87ddad84e277f 100644 |
| --- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
| +++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
| @@ -57,6 +57,7 @@ bool RequiresBubble(int session_id) { |
| bool RequiresTrayIcon(int session_id) { |
| return !RequiresBubble(session_id); |
| } |
| + |
| } // namespace |
| namespace speech { |
| @@ -467,7 +468,7 @@ void ChromeSpeechRecognitionManagerDelegate::GetDiagnosticInformation( |
| void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( |
| int session_id, |
| - base::Callback<void(int session_id, bool is_allowed)> callback) { |
| + base::Callback<void(bool ask_user, bool is_allowed)> callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| const content::SpeechRecognitionSessionContext& context = |
| @@ -478,23 +479,28 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( |
| // ChromeSpeechRecognitionPreferences associated to their profile. |
| DCHECK_NE(context.render_process_id, 0); |
| - // We don't need any particular check for sessions not using a bubble. In such |
| - // cases, we just notify it to the manager (calling-back synchronously, since |
| - // we remain in the IO thread). |
| if (RequiresTrayIcon(session_id)) { |
| - callback.Run(session_id, true /* is_allowed */); |
| + // Check that the render view type is appropriate, and whether or not we |
| + // need to request permission from the user. |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&CheckRenderViewTypeForTrayIcon, |
| + session_id, |
| + callback, |
| + context.render_process_id, |
| + context.render_view_id)); |
| + return; |
| + } else { |
| + // Sessions not requiring permission need to check the renderer view type. |
| + // The check must be performed in the UI thread. We defer it posting to |
| + // CheckRenderViewType, which will issue the callback on our behalf. |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&CheckRenderViewTypeForBubble, |
| + session_id, |
| + callback, |
| + context.render_process_id, |
| + context.render_view_id)); |
| return; |
| } |
| - |
| - // Sessions using bubbles, conversely, need a check on the renderer view type. |
| - // The check must be performed in the UI thread. We defer it posting to |
| - // CheckRenderViewType, which will issue the callback on our behalf. |
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| - base::Bind(&CheckRenderViewType, |
| - session_id, |
| - callback, |
| - context.render_process_id, |
| - context.render_view_id)); |
| } |
| content::SpeechRecognitionEventListener* |
| @@ -535,9 +541,9 @@ void ChromeSpeechRecognitionManagerDelegate::ShowTrayIconOnUIThread( |
| tray_icon_controller->Show(initiator_name, show_notification); |
| } |
| -void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( |
| +void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewTypeForBubble( |
| int session_id, |
| - base::Callback<void(int session_id, bool is_allowed)> callback, |
| + base::Callback<void(bool ask_user, bool is_allowed)> callback, |
| int render_process_id, |
| int render_view_id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -558,7 +564,37 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( |
| allowed = true; |
| } |
| BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| - base::Bind(callback, session_id, allowed)); |
| + base::Bind(callback, false, allowed)); |
| +} |
| + |
| +void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewTypeForTrayIcon( |
|
Satish
2012/09/12 06:15:09
there is a lot of shared code between this and the
hans
2012/09/12 09:46:58
Done.
|
| + int session_id, |
| + base::Callback<void(bool ask_user, bool is_allowed)> callback, |
| + int render_process_id, |
| + int render_view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + const content::RenderViewHost* render_view_host = |
| + content::RenderViewHost::FromID(render_process_id, render_view_id); |
| + if (!render_view_host) { |
| + // This happens for extensions. Manifest should be checked for permission. |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(callback, false, true)); |
| + return; |
| + } |
| + |
| + WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| + chrome::ViewType view_type = chrome::GetViewType(web_contents); |
| + if (view_type != chrome::VIEW_TYPE_TAB_CONTENTS) { |
| + // If there is no tab we don't allow, because we wouldn't be able to show an |
| + // infobar. |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(callback, false, false)); |
| + return; |
| + } |
| + |
| + // Call back saying that we need to ask the user for permission. |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(callback, true, true)); |
| } |
| SpeechRecognitionBubbleController* |