Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc

Issue 10933018: Speech JavaScript API: Use the MediaStreamManager to ask for user permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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*

Powered by Google App Engine
This is Rietveld 408576698