| 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 b771ac744b6b8dc03fc48d4e21545fd75db60823..32713b5552a8781be6f5afca079aeb5bcc15bcb9 100644
|
| --- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc
|
| +++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc
|
| @@ -13,11 +13,13 @@
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
|
| #include "chrome/browser/speech/speech_recognition_tray_icon_controller.h"
|
| #include "chrome/browser/tab_contents/tab_util.h"
|
| #include "chrome/browser/view_type_utils.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/resource_context.h"
|
| #include "content/public/browser/speech_recognition_manager.h"
|
| @@ -36,8 +38,8 @@
|
|
|
| using content::BrowserThread;
|
| using content::SpeechRecognitionManager;
|
| -using content::WebContents;
|
| using content::SpeechRecognitionSessionContext;
|
| +using content::WebContents;
|
|
|
| namespace {
|
| const int kNoActiveBubble =
|
| @@ -210,10 +212,17 @@ void ChromeSpeechRecognitionManagerDelegate::OnAudioStart(int session_id) {
|
| if (RequiresBubble(session_id)) {
|
| GetBubbleController()->SetBubbleRecordingMode(session_id);
|
| } else if (RequiresTrayIcon(session_id)) {
|
| + // We post the action to the UI thread for sessions requiring a tray icon,
|
| + // since ChromeSpeechRecognitionPreferences (which requires UI thread) is
|
| + // involved for determining whether a security alert balloon is required.
|
| const content::SpeechRecognitionSessionContext& context =
|
| SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
|
| - GetTrayIconController()->Show(context.context_name,
|
| - context.is_first_request_for_context);
|
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
|
| + &ChromeSpeechRecognitionManagerDelegate::ShowTrayIconOnUIThread,
|
| + context.context_name,
|
| + context.render_process_id,
|
| + scoped_refptr<SpeechRecognitionTrayIconController>(
|
| + GetTrayIconController())));
|
| }
|
| }
|
|
|
| @@ -335,6 +344,14 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
|
| base::Callback<void(int session_id, bool is_allowed)> callback) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
|
| + const content::SpeechRecognitionSessionContext& context =
|
| + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
|
| +
|
| + // Make sure that initiators (extensions/web pages) properly set the
|
| + // |render_process_id| field, which is needed later to retrieve the
|
| + // 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).
|
| @@ -346,8 +363,6 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
|
| // 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.
|
| - const content::SpeechRecognitionSessionContext& context =
|
| - SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| base::Bind(&CheckRenderViewType,
|
| session_id,
|
| @@ -361,6 +376,25 @@ ChromeSpeechRecognitionManagerDelegate::GetEventListener() {
|
| return this;
|
| }
|
|
|
| +void ChromeSpeechRecognitionManagerDelegate::ShowTrayIconOnUIThread(
|
| + const std::string& context_name,
|
| + int render_process_id,
|
| + scoped_refptr<SpeechRecognitionTrayIconController> tray_icon_controller) {
|
| + content::RenderProcessHost* render_process_host =
|
| + content::RenderProcessHost::FromID(render_process_id);
|
| + DCHECK(render_process_host);
|
| + content::BrowserContext* browser_context =
|
| + render_process_host->GetBrowserContext();
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + scoped_refptr<ChromeSpeechRecognitionPreferences> pref =
|
| + ChromeSpeechRecognitionPreferences::GetForProfile(profile);
|
| + bool show_notification = pref->ShouldShowSecurityNotification(context_name);
|
| +
|
| + tray_icon_controller->Show(ASCIIToUTF16(context_name), show_notification);
|
| + if (show_notification)
|
| + pref->SetHasShownSecurityNotification(context_name);
|
| +}
|
| +
|
| void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
|
| int session_id,
|
| base::Callback<void(int session_id, bool is_allowed)> callback,
|
|
|