diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-06 20:36:43 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-06 20:36:43 +0000 |
commit | 96fd9e0e732f69917a6037b195081c3cbd614421 (patch) | |
tree | 496fdfca8f2b8c45bd96bfb10f3cf4c4dbfcb7f8 /chrome/browser | |
parent | 609387ae10880c332c705b6065c664b7f7e00966 (diff) | |
download | chromium_src-96fd9e0e732f69917a6037b195081c3cbd614421.zip chromium_src-96fd9e0e732f69917a6037b195081c3cbd614421.tar.gz chromium_src-96fd9e0e732f69917a6037b195081c3cbd614421.tar.bz2 |
If speech input is disabled and we receive IPC calls, terminate the renderer.
BUG=68666
TEST=none
Review URL: http://codereview.chromium.org/6128001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 53 insertions, 28 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index f09fd57..d901a77 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -65,6 +65,7 @@ #include "chrome/browser/safe_browsing/client_side_detection_service.h" #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" #include "chrome/browser/speech/speech_input_dispatcher_host.h" +#include "chrome/browser/speech/speech_input_manager.h" #include "chrome/browser/spellcheck_host.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/visitedlink/visitedlink_master.h" @@ -788,23 +789,8 @@ void BrowserRenderProcessHost::InitExtensions() { } void BrowserRenderProcessHost::InitSpeechInput() { - bool enabled = true; - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - - if (command_line.HasSwitch(switches::kDisableSpeechInput)) { - enabled = false; -#if defined(GOOGLE_CHROME_BUILD) - } else if (!command_line.HasSwitch(switches::kEnableSpeechInput)) { - // We need to evaluate whether IO is OK here. http://crbug.com/63335. - base::ThreadRestrictions::ScopedAllowIO allow_io; - // Official Chrome builds have speech input enabled by default only in the - // dev channel. - std::string channel = platform_util::GetVersionStringModifier(); - enabled = (channel == "dev"); -#endif - } - - Send(new ViewMsg_SpeechInput_SetFeatureEnabled(enabled)); + Send(new ViewMsg_SpeechInput_SetFeatureEnabled( + speech_input::SpeechInputManager::IsFeatureEnabled())); } void BrowserRenderProcessHost::SendUserScriptsUpdate( diff --git a/chrome/browser/speech/speech_input_dispatcher_host.cc b/chrome/browser/speech/speech_input_dispatcher_host.cc index f1abebf..50b9aec 100644 --- a/chrome/browser/speech/speech_input_dispatcher_host.cc +++ b/chrome/browser/speech/speech_input_dispatcher_host.cc @@ -121,17 +121,29 @@ SpeechInputManager* SpeechInputDispatcherHost::manager() { bool SpeechInputDispatcherHost::OnMessageReceived( const IPC::Message& message, bool* message_was_ok) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, *message_was_ok) - IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, - OnStartRecognition) - IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, - OnCancelRecognition) - IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, - OnStopRecording) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; + + uint32 message_type = message.type(); + if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID || + message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID || + message_type == ViewHostMsg_SpeechInput_StopRecording::ID) { + if (!SpeechInputManager::IsFeatureEnabled()) { + *message_was_ok = false; + return true; + } + + IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, + *message_was_ok) + IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition, + OnStartRecognition) + IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition, + OnCancelRecognition) + IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording, + OnStopRecording) + IPC_END_MESSAGE_MAP() + return true; + } + + return false; } void SpeechInputDispatcherHost::OnStartRecognition( diff --git a/chrome/browser/speech/speech_input_manager.cc b/chrome/browser/speech/speech_input_manager.cc index b370da4..ef7a758 100644 --- a/chrome/browser/speech/speech_input_manager.cc +++ b/chrome/browser/speech/speech_input_manager.cc @@ -8,11 +8,14 @@ #include <string> #include "app/l10n_util.h" +#include "base/command_line.h" #include "base/lock.h" #include "base/ref_counted.h" #include "base/lazy_instance.h" +#include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" +#include "chrome/common/chrome_switches.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/speech/speech_input_bubble_controller.h" #include "chrome/browser/speech/speech_recognizer.h" @@ -150,6 +153,26 @@ SpeechInputManager* SpeechInputManager::Get() { return g_speech_input_manager_impl.Pointer(); } +bool SpeechInputManager::IsFeatureEnabled() { + bool enabled = true; + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + + if (command_line.HasSwitch(switches::kDisableSpeechInput)) { + enabled = false; +#if defined(GOOGLE_CHROME_BUILD) + } else if (!command_line.HasSwitch(switches::kEnableSpeechInput)) { + // We need to evaluate whether IO is OK here. http://crbug.com/63335. + base::ThreadRestrictions::ScopedAllowIO allow_io; + // Official Chrome builds have speech input enabled by default only in the + // dev channel. + std::string channel = platform_util::GetVersionStringModifier(); + enabled = (channel == "dev"); +#endif + } + + return enabled; +} + SpeechInputManagerImpl::SpeechInputManagerImpl() : recording_caller_id_(0), bubble_controller_(new SpeechInputBubbleController( diff --git a/chrome/browser/speech/speech_input_manager.h b/chrome/browser/speech/speech_input_manager.h index be9779f..ffeaba0 100644 --- a/chrome/browser/speech/speech_input_manager.h +++ b/chrome/browser/speech/speech_input_manager.h @@ -32,6 +32,10 @@ class SpeechInputManager { virtual ~Delegate() {} }; + // Whether the speech input feature is enabled, based on the browser channel + // information and command line flags. + static bool IsFeatureEnabled(); + // Factory method to access the singleton. We have this method here instead of // using Singleton<> directly in the calling code to aid tests in injection // mocks. |