| 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..179a18fb8e0d1e628ba92fcbfd3ea78027bc349a 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,14 @@ 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 */);
|
| - 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.
|
| + // 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(&CheckRenderViewType,
|
| - session_id,
|
| callback,
|
| context.render_process_id,
|
| - context.render_view_id));
|
| + context.render_view_id,
|
| + RequiresTrayIcon(session_id)));
|
| }
|
|
|
| content::SpeechRecognitionEventListener*
|
| @@ -536,29 +528,47 @@ void ChromeSpeechRecognitionManagerDelegate::ShowTrayIconOnUIThread(
|
| }
|
|
|
| void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
|
| - 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) {
|
| + int render_view_id,
|
| + bool js_api) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| const content::RenderViewHost* render_view_host =
|
| content::RenderViewHost::FromID(render_process_id, render_view_id);
|
| +
|
| bool allowed = false;
|
| - if (render_view_host) {
|
| - // For host delegates other than VIEW_TYPE_TAB_CONTENTS we can't reliably
|
| - // show a popup, including the speech input bubble. In these cases for
|
| - // privacy reasons we don't want to start recording if the user can't be
|
| - // properly notified. An example of this is trying to show the speech input
|
| - // bubble within an extension popup: http://crbug.com/92083. In these
|
| - // situations the speech input extension API should be used instead.
|
| - WebContents* web_contents =
|
| - WebContents::FromRenderViewHost(render_view_host);
|
| - chrome::ViewType view_type = chrome::GetViewType(web_contents);
|
| - if (view_type == chrome::VIEW_TYPE_TAB_CONTENTS)
|
| + bool ask_permission = false;
|
| +
|
| + if (!render_view_host) {
|
| + if (!js_api) {
|
| + // If there is no render view, we cannot show the speech bubble, so this
|
| + // is not allowed.
|
| + allowed = false;
|
| + ask_permission = false;
|
| + } else {
|
| + // This happens for extensions. Manifest should be checked for permission.
|
| allowed = true;
|
| + ask_permission = false;
|
| + }
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(callback, ask_permission, allowed));
|
| + 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 it is a tab, we can show the speech input bubble or ask for
|
| + // permission.
|
| +
|
| + allowed = true;
|
| + if (js_api)
|
| + ask_permission = true;
|
| }
|
| +
|
| BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| - base::Bind(callback, session_id, allowed));
|
| + base::Bind(callback, ask_permission, allowed));
|
| }
|
|
|
| SpeechRecognitionBubbleController*
|
|
|