diff options
Diffstat (limited to 'content')
51 files changed, 656 insertions, 627 deletions
diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index 0de277c..395ade5 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -251,8 +251,8 @@ std::string MockContentBrowserClient::GetWorkerProcessTitle( void MockContentBrowserClient::ResourceDispatcherHostCreated() { } -SpeechInputManagerDelegate* - MockContentBrowserClient::GetSpeechInputManagerDelegate() { +SpeechRecognitionManagerDelegate* + MockContentBrowserClient::GetSpeechRecognitionManagerDelegate() { return NULL; } diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index e1a523c..e6fe8cb 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -139,7 +139,8 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual std::string GetWorkerProcessTitle(const GURL& url, ResourceContext* context) OVERRIDE; virtual void ResourceDispatcherHostCreated() OVERRIDE; - virtual SpeechInputManagerDelegate* GetSpeechInputManagerDelegate() OVERRIDE; + virtual SpeechRecognitionManagerDelegate* + GetSpeechRecognitionManagerDelegate() OVERRIDE; virtual ui::Clipboard* GetClipboard() OVERRIDE; virtual net::NetLog* GetNetLog() OVERRIDE; virtual AccessTokenStore* CreateAccessTokenStore() OVERRIDE; diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index f02f5b1..ed47da7 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -114,7 +114,7 @@ #endif #if defined(ENABLE_INPUT_SPEECH) -#include "content/browser/speech/speech_input_dispatcher_host.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" #endif #include "third_party/skia/include/core/SkBitmap.h" @@ -493,9 +493,9 @@ void RenderProcessHostImpl::CreateMessageFilters() { channel_->AddFilter(new PepperMessageFilter(PepperMessageFilter::RENDERER, GetID(), resource_context)); #if defined(ENABLE_INPUT_SPEECH) - channel_->AddFilter(new speech_input::SpeechInputDispatcherHost( + channel_->AddFilter(new speech::InputTagSpeechDispatcherHost( GetID(), browser_context->GetRequestContext(), - browser_context->GetSpeechInputPreferences(), + browser_context->GetSpeechRecognitionPreferences(), content::BrowserMainLoop::GetAudioManager())); #endif channel_->AddFilter(new FileAPIMessageFilter( diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 12d5e04..faf2a96 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -28,7 +28,7 @@ #include "content/common/accessibility_messages.h" #include "content/common/desktop_notification_messages.h" #include "content/common/drag_messages.h" -#include "content/common/speech_input_messages.h" +#include "content/common/speech_recognition_messages.h" #include "content/common/swapped_out_messages.h" #include "content/common/view_messages.h" #include "content/port/browser/render_widget_host_view_port.h" @@ -1405,7 +1405,7 @@ void RenderViewHostImpl::DidCancelPopupMenu() { #endif void RenderViewHostImpl::ToggleSpeechInput() { - Send(new SpeechInputMsg_ToggleSpeechInput(GetRoutingID())); + Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID())); } void RenderViewHostImpl::FilterURL(ChildProcessSecurityPolicyImpl* policy, diff --git a/content/browser/speech/audio_encoder.cc b/content/browser/speech/audio_encoder.cc index 683ec0e..83e0475 100644 --- a/content/browser/speech/audio_encoder.cc +++ b/content/browser/speech/audio_encoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,7 +21,7 @@ namespace { const char* const kContentTypeFLAC = "audio/x-flac; rate="; const int kFLACCompressionLevel = 0; // 0 for speed -class FLACEncoder : public speech_input::AudioEncoder { +class FLACEncoder : public speech::AudioEncoder { public: FLACEncoder(int sampling_rate, int bits_per_sample); virtual ~FLACEncoder(); @@ -107,7 +107,7 @@ const int kMaxSpeexFrameLength = 110; // (44kbps rate sampled at 32kHz). // make sure it is within the byte range. COMPILE_ASSERT(kMaxSpeexFrameLength <= 0xFF, invalidLength); -class SpeexEncoder : public speech_input::AudioEncoder { +class SpeexEncoder : public speech::AudioEncoder { public: explicit SpeexEncoder(int sampling_rate); virtual ~SpeexEncoder(); @@ -163,7 +163,7 @@ void SpeexEncoder::Encode(const short* samples, int num_samples) { } // namespace -namespace speech_input { +namespace speech { AudioEncoder* AudioEncoder::Create(Codec codec, int sampling_rate, @@ -205,4 +205,4 @@ void AudioEncoder::AppendToBuffer(std::string* item) { audio_buffers_.push_back(item); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/audio_encoder.h b/content/browser/speech/audio_encoder.h index 7b0a246..92bc645 100644 --- a/content/browser/speech/audio_encoder.h +++ b/content/browser/speech/audio_encoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,7 +10,7 @@ #include "base/basictypes.h" -namespace speech_input { +namespace speech { // Provides a simple interface to encode raw audio using the various speech // codecs. @@ -54,6 +54,6 @@ class AudioEncoder { DISALLOW_COPY_AND_ASSIGN(AudioEncoder); }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_ diff --git a/content/browser/speech/endpointer/endpointer.cc b/content/browser/speech/endpointer/endpointer.cc index 69c79a6..fe3e0bf 100644 --- a/content/browser/speech/endpointer/endpointer.cc +++ b/content/browser/speech/endpointer/endpointer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,7 +12,7 @@ namespace { static const int kFrameRate = 50; // 1 frame = 20ms of audio. } -namespace speech_input { +namespace speech { Endpointer::Endpointer(int sample_rate) : speech_input_possibly_complete_silence_length_us_(-1), diff --git a/content/browser/speech/endpointer/endpointer.h b/content/browser/speech/endpointer/endpointer.h index 2d74839..9ba2018 100644 --- a/content/browser/speech/endpointer/endpointer.h +++ b/content/browser/speech/endpointer/endpointer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,7 +11,7 @@ class EpStatus; -namespace speech_input { +namespace speech { // A simple interface to the underlying energy-endpointer implementation, this // class lets callers provide audio as being recorded and let them poll to find @@ -147,6 +147,6 @@ class CONTENT_EXPORT Endpointer { int32 frame_size_; }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_ENDPOINTER_ENDPOINTER_H_ diff --git a/content/browser/speech/endpointer/endpointer_unittest.cc b/content/browser/speech/endpointer/endpointer_unittest.cc index b71c01a..240e5dc 100644 --- a/content/browser/speech/endpointer/endpointer_unittest.cc +++ b/content/browser/speech/endpointer/endpointer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,7 +15,7 @@ const int kFrameSize = kSampleRate / kFrameRate; // 160 samples. COMPILE_ASSERT(kFrameSize == 160, invalid_frame_size); } -namespace speech_input { +namespace speech { class FrameProcessor { public: @@ -142,4 +142,4 @@ TEST(EndpointerTest, TestEmbeddedEndpointerEvents) { endpointer.EndSession(); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/endpointer/energy_endpointer.cc b/content/browser/speech/endpointer/energy_endpointer.cc index 39cf617..b88d7a3 100644 --- a/content/browser/speech/endpointer/energy_endpointer.cc +++ b/content/browser/speech/endpointer/energy_endpointer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -41,7 +41,7 @@ float GetDecibel(float value) { } // namespace -namespace speech_input { +namespace speech { // Stores threshold-crossing histories for making decisions about the speech // state. diff --git a/content/browser/speech/endpointer/energy_endpointer.h b/content/browser/speech/endpointer/energy_endpointer.h index b440c4d..9db927a 100644 --- a/content/browser/speech/endpointer/energy_endpointer.h +++ b/content/browser/speech/endpointer/energy_endpointer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,7 +44,7 @@ #include "content/browser/speech/endpointer/energy_endpointer_params.h" #include "content/common/content_export.h" -namespace speech_input { +namespace speech { // Endpointer status codes enum EpStatus { @@ -150,6 +150,6 @@ class CONTENT_EXPORT EnergyEndpointer { DISALLOW_COPY_AND_ASSIGN(EnergyEndpointer); }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_ENDPOINTER_ENERGY_ENDPOINTER_H_ diff --git a/content/browser/speech/endpointer/energy_endpointer_params.cc b/content/browser/speech/endpointer/energy_endpointer_params.cc index e110b24..89852f1 100644 --- a/content/browser/speech/endpointer/energy_endpointer_params.cc +++ b/content/browser/speech/endpointer/energy_endpointer_params.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "content/browser/speech/endpointer/energy_endpointer_params.h" -namespace speech_input { +namespace speech { EnergyEndpointerParams::EnergyEndpointerParams() { SetDefaults(); @@ -50,4 +50,4 @@ void EnergyEndpointerParams::operator=(const EnergyEndpointerParams& source) { contamination_rejection_period_ = source.contamination_rejection_period(); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/endpointer/energy_endpointer_params.h b/content/browser/speech/endpointer/energy_endpointer_params.h index 5a3ea42..9641d9d 100644 --- a/content/browser/speech/endpointer/energy_endpointer_params.h +++ b/content/browser/speech/endpointer/energy_endpointer_params.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "content/common/content_export.h" -namespace speech_input { +namespace speech { // Input parameters for the EnergyEndpointer class. class CONTENT_EXPORT EnergyEndpointerParams { @@ -133,6 +133,6 @@ class CONTENT_EXPORT EnergyEndpointerParams { float contamination_rejection_period_; }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_ENDPOINTER_ENERGY_ENDPOINTER_PARAMS_H_ diff --git a/content/browser/speech/speech_input_dispatcher_host.cc b/content/browser/speech/input_tag_speech_dispatcher_host.cc index 3883969..7c10270 100644 --- a/content/browser/speech/speech_input_dispatcher_host.cc +++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc @@ -2,24 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/speech/speech_input_dispatcher_host.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" #include "base/lazy_instance.h" -#include "content/browser/speech/speech_input_manager_impl.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "content/browser/speech/speech_recognizer_impl.h" -#include "content/common/speech_input_messages.h" -#include "content/public/browser/speech_input_preferences.h" +#include "content/common/speech_recognition_messages.h" +#include "content/public/browser/speech_recognition_preferences.h" using content::BrowserThread; -namespace speech_input { +namespace speech { -//----------------------------- SpeechInputCallers ----------------------------- +//----------------------------- Callers ----------------------------- // A singleton class to map the tuple // (render-process-id, render-view-id, requestid) to a single ID which is passed // through rest of the speech code. -class SpeechInputDispatcherHost::SpeechInputCallers { +class InputTagSpeechDispatcherHost::Callers { public: // Creates a new ID for a given tuple. int CreateId(int render_process_id, int render_view_id, int request_id); @@ -41,24 +41,24 @@ class SpeechInputDispatcherHost::SpeechInputCallers { int render_view_id; int request_id; }; - friend struct base::DefaultLazyInstanceTraits<SpeechInputCallers>; + friend struct base::DefaultLazyInstanceTraits<Callers>; - SpeechInputCallers(); + Callers(); std::map<int, CallerInfo> callers_; int next_id_; }; -static base::LazyInstance<SpeechInputDispatcherHost::SpeechInputCallers> - g_speech_input_callers = LAZY_INSTANCE_INITIALIZER; +static base::LazyInstance<InputTagSpeechDispatcherHost::Callers> + g_callers = LAZY_INSTANCE_INITIALIZER; -SpeechInputDispatcherHost::SpeechInputCallers::SpeechInputCallers() +InputTagSpeechDispatcherHost::Callers::Callers() : next_id_(1) { } -int SpeechInputDispatcherHost::SpeechInputCallers::GetId(int render_process_id, - int render_view_id, - int request_id) { +int InputTagSpeechDispatcherHost::Callers::GetId(int render_process_id, + int render_view_id, + int request_id) { for (std::map<int, CallerInfo>::iterator it = callers_.begin(); it != callers_.end(); it++) { const CallerInfo& item = it->second; @@ -76,10 +76,9 @@ int SpeechInputDispatcherHost::SpeechInputCallers::GetId(int render_process_id, return 0; } -int SpeechInputDispatcherHost::SpeechInputCallers::CreateId( - int render_process_id, - int render_view_id, - int request_id) { +int InputTagSpeechDispatcherHost::Callers::CreateId(int render_process_id, + int render_view_id, + int request_id) { CallerInfo info; info.render_process_id = render_process_id; info.render_view_id = render_view_id; @@ -88,46 +87,49 @@ int SpeechInputDispatcherHost::SpeechInputCallers::CreateId( return next_id_++; } -void SpeechInputDispatcherHost::SpeechInputCallers::RemoveId(int id) { +void InputTagSpeechDispatcherHost::Callers::RemoveId(int id) { callers_.erase(id); } -int SpeechInputDispatcherHost::SpeechInputCallers::render_process_id(int id) { +int InputTagSpeechDispatcherHost::Callers::render_process_id( + int id) { return callers_[id].render_process_id; } -int SpeechInputDispatcherHost::SpeechInputCallers::render_view_id(int id) { +int InputTagSpeechDispatcherHost::Callers::render_view_id( + int id) { return callers_[id].render_view_id; } -int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) { +int InputTagSpeechDispatcherHost::Callers::request_id(int id) { return callers_[id].request_id; } -//-------------------------- SpeechInputDispatcherHost ------------------------- +//----------------------- InputTagSpeechDispatcherHost ---------------------- -SpeechInputManagerImpl* SpeechInputDispatcherHost::manager_; +SpeechRecognitionManagerImpl* InputTagSpeechDispatcherHost::manager_; -void SpeechInputDispatcherHost::set_manager(SpeechInputManagerImpl* manager) { +void InputTagSpeechDispatcherHost::set_manager( + SpeechRecognitionManagerImpl* manager) { manager_ = manager; } -SpeechInputDispatcherHost::SpeechInputDispatcherHost( +InputTagSpeechDispatcherHost::InputTagSpeechDispatcherHost( int render_process_id, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_preferences, + content::SpeechRecognitionPreferences* recognition_preferences, AudioManager* audio_manager) : render_process_id_(render_process_id), may_have_pending_requests_(false), context_getter_(context_getter), - speech_input_preferences_(speech_input_preferences), + recognition_preferences_(recognition_preferences), audio_manager_(audio_manager) { // This is initialized by Browser. Do not add any non-trivial // initialization here, instead do it lazily when required (e.g. see the // method |manager()|) or add an Init() method. } -SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { +InputTagSpeechDispatcherHost::~InputTagSpeechDispatcherHost() { // If the renderer crashed for some reason or if we didn't receive a proper // Cancel/Stop call for an existing session, cancel such active sessions now. // We first check if this dispatcher received any speech IPC requst so that @@ -137,27 +139,27 @@ SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { manager()->CancelAllRequestsWithDelegate(this); } -SpeechInputManagerImpl* SpeechInputDispatcherHost::manager() { +SpeechRecognitionManagerImpl* InputTagSpeechDispatcherHost::manager() { if (manager_) return manager_; #if defined(ENABLE_INPUT_SPEECH) - return SpeechInputManagerImpl::GetInstance(); + return SpeechRecognitionManagerImpl::GetInstance(); #else return NULL; #endif } -bool SpeechInputDispatcherHost::OnMessageReceived( +bool InputTagSpeechDispatcherHost::OnMessageReceived( const IPC::Message& message, bool* message_was_ok) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, + IPC_BEGIN_MESSAGE_MAP_EX(InputTagSpeechDispatcherHost, message, *message_was_ok) - IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition, + IPC_MESSAGE_HANDLER(InputTagSpeechHostMsg_StartRecognition, OnStartRecognition) - IPC_MESSAGE_HANDLER(SpeechInputHostMsg_CancelRecognition, + IPC_MESSAGE_HANDLER(InputTagSpeechHostMsg_CancelRecognition, OnCancelRecognition) - IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording, + IPC_MESSAGE_HANDLER(InputTagSpeechHostMsg_StopRecording, OnStopRecording) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -166,10 +168,10 @@ bool SpeechInputDispatcherHost::OnMessageReceived( return handled; } -void SpeechInputDispatcherHost::OnStartRecognition( - const SpeechInputHostMsg_StartRecognition_Params ¶ms) { +void InputTagSpeechDispatcherHost::OnStartRecognition( + const InputTagSpeechHostMsg_StartRecognition_Params ¶ms) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_id = g_speech_input_callers.Get().CreateId( + int caller_id = g_callers.Get().CreateId( render_process_id_, params.render_view_id, params.request_id); manager()->StartRecognition(this, caller_id, render_process_id_, @@ -177,63 +179,61 @@ void SpeechInputDispatcherHost::OnStartRecognition( params.language, params.grammar, params.origin_url, context_getter_.get(), - speech_input_preferences_.get()); + recognition_preferences_.get()); } -void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, - int request_id) { - int caller_id = g_speech_input_callers.Get().GetId( +void InputTagSpeechDispatcherHost::OnCancelRecognition(int render_view_id, + int request_id) { + int caller_id = g_callers.Get().GetId( render_process_id_, render_view_id, request_id); if (caller_id) { manager()->CancelRecognition(caller_id); // Request sequence ended so remove mapping. - g_speech_input_callers.Get().RemoveId(caller_id); + g_callers.Get().RemoveId(caller_id); } } -void SpeechInputDispatcherHost::OnStopRecording(int render_view_id, - int request_id) { - int caller_id = g_speech_input_callers.Get().GetId( +void InputTagSpeechDispatcherHost::OnStopRecording(int render_view_id, + int request_id) { + int caller_id = g_callers.Get().GetId( render_process_id_, render_view_id, request_id); if (caller_id) manager()->StopRecording(caller_id); } -void SpeechInputDispatcherHost::SetRecognitionResult( - int caller_id, const content::SpeechInputResult& result) { - VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult enter"; +void InputTagSpeechDispatcherHost::SetRecognitionResult( + int caller_id, const content::SpeechRecognitionResult& result) { + VLOG(1) << "InputTagSpeechDispatcherHost::SetRecognitionResult enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = - g_speech_input_callers.Get().render_view_id(caller_id); - int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); - Send(new SpeechInputMsg_SetRecognitionResult(caller_render_view_id, - caller_request_id, - result)); - VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult exit"; + int caller_render_view_id = g_callers.Get().render_view_id(caller_id); + int caller_request_id = g_callers.Get().request_id(caller_id); + Send(new InputTagSpeechMsg_SetRecognitionResult(caller_render_view_id, + caller_request_id, + result)); + VLOG(1) << "InputTagSpeechDispatcherHost::SetRecognitionResult exit"; } -void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) { - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording enter"; +void InputTagSpeechDispatcherHost::DidCompleteRecording(int caller_id) { + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecording enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = - g_speech_input_callers.Get().render_view_id(caller_id); - int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); - Send(new SpeechInputMsg_RecordingComplete(caller_render_view_id, - caller_request_id)); - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording exit"; + int caller_render_view_id = g_callers.Get().render_view_id(caller_id); + int caller_request_id = g_callers.Get().request_id(caller_id); + Send(new InputTagSpeechMsg_RecordingComplete(caller_render_view_id, + caller_request_id)); + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecording exit"; } -void SpeechInputDispatcherHost::DidCompleteRecognition(int caller_id) { - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition enter"; +void InputTagSpeechDispatcherHost::DidCompleteRecognition(int caller_id) { + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecognition enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); int caller_render_view_id = - g_speech_input_callers.Get().render_view_id(caller_id); - int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); - Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, - caller_request_id)); + g_callers.Get().render_view_id(caller_id); + int caller_request_id = g_callers.Get().request_id(caller_id); + Send(new InputTagSpeechMsg_RecognitionComplete(caller_render_view_id, + caller_request_id)); // Request sequence ended, so remove mapping. - g_speech_input_callers.Get().RemoveId(caller_id); - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; + g_callers.Get().RemoveId(caller_id); + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecognition exit"; } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.h b/content/browser/speech/input_tag_speech_dispatcher_host.h new file mode 100644 index 0000000..61d68b0 --- /dev/null +++ b/content/browser/speech/input_tag_speech_dispatcher_host.h @@ -0,0 +1,78 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ +#define CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "content/public/browser/browser_message_filter.h" +#include "net/url_request/url_request_context_getter.h" + +class AudioManager; +struct InputTagSpeechHostMsg_StartRecognition_Params; + +namespace content { +class SpeechRecognitionPreferences; +struct SpeechRecognitionResult; +} + +namespace speech { + +class SpeechRecognitionManagerImpl; + +// InputTagSpeechDispatcherHost is a delegate for Speech API messages used by +// RenderMessageFilter. +// It's the complement of InputTagSpeechDispatcher (owned by RenderView). +class CONTENT_EXPORT InputTagSpeechDispatcherHost + : public content::BrowserMessageFilter { + public: + class Callers; + + InputTagSpeechDispatcherHost( + int render_process_id, + net::URLRequestContextGetter* context_getter, + content::SpeechRecognitionPreferences* recognition_preferences, + AudioManager* audio_manager); + + // Methods called by SpeechRecognitionManagerImpl. + void SetRecognitionResult(int caller_id, + const content::SpeechRecognitionResult& result); + void DidCompleteRecording(int caller_id); + void DidCompleteRecognition(int caller_id); + + // content::BrowserMessageFilter implementation. + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) OVERRIDE; + + // Singleton manager setter useful for tests. + static void set_manager(SpeechRecognitionManagerImpl* manager); + + private: + virtual ~InputTagSpeechDispatcherHost(); + + void OnStartRecognition( + const InputTagSpeechHostMsg_StartRecognition_Params ¶ms); + void OnCancelRecognition(int render_view_id, int request_id); + void OnStopRecording(int render_view_id, int request_id); + + // Returns the speech recognition manager to forward events to, creating one + // if needed. + SpeechRecognitionManagerImpl* manager(); + + int render_process_id_; + bool may_have_pending_requests_; // Set if we received any speech IPC request + + scoped_refptr<net::URLRequestContextGetter> context_getter_; + scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_; + AudioManager* audio_manager_; + + static SpeechRecognitionManagerImpl* manager_; + + DISALLOW_COPY_AND_ASSIGN(InputTagSpeechDispatcherHost); +}; + +} // namespace speech + +#endif // CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ diff --git a/content/browser/speech/speech_input_dispatcher_host.h b/content/browser/speech/speech_input_dispatcher_host.h deleted file mode 100644 index 5e38f37..0000000 --- a/content/browser/speech/speech_input_dispatcher_host.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ -#define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ - -#include "base/memory/scoped_ptr.h" -#include "content/common/content_export.h" -#include "content/public/browser/browser_message_filter.h" -#include "net/url_request/url_request_context_getter.h" - -class AudioManager; -struct SpeechInputHostMsg_StartRecognition_Params; - -namespace content { -class SpeechInputPreferences; -struct SpeechInputResult; -} - -namespace speech_input { - -class SpeechInputManagerImpl; - -// SpeechInputDispatcherHost is a delegate for Speech API messages used by -// RenderMessageFilter. -// It's the complement of SpeechInputDispatcher (owned by RenderView). -class CONTENT_EXPORT SpeechInputDispatcherHost - : public content::BrowserMessageFilter { - public: - class SpeechInputCallers; - - SpeechInputDispatcherHost( - int render_process_id, - net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_preferences, - AudioManager* audio_manager); - - // Methods called by SpeechInputManagerImpl. - void SetRecognitionResult(int caller_id, - const content::SpeechInputResult& result); - void DidCompleteRecording(int caller_id); - void DidCompleteRecognition(int caller_id); - - // content::BrowserMessageFilter implementation. - virtual bool OnMessageReceived(const IPC::Message& message, - bool* message_was_ok) OVERRIDE; - - // Singleton manager setter useful for tests. - static void set_manager(SpeechInputManagerImpl* manager); - - private: - virtual ~SpeechInputDispatcherHost(); - - void OnStartRecognition( - const SpeechInputHostMsg_StartRecognition_Params ¶ms); - void OnCancelRecognition(int render_view_id, int request_id); - void OnStopRecording(int render_view_id, int request_id); - - // Returns the speech input manager to forward events to, creating one if - // needed. - SpeechInputManagerImpl* manager(); - - int render_process_id_; - bool may_have_pending_requests_; // Set if we received any speech IPC request - - scoped_refptr<net::URLRequestContextGetter> context_getter_; - scoped_refptr<content::SpeechInputPreferences> speech_input_preferences_; - AudioManager* audio_manager_; - - static SpeechInputManagerImpl* manager_; - - DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcherHost); -}; - -} // namespace speech_input - -#endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ diff --git a/content/browser/speech/speech_input_browsertest.cc b/content/browser/speech/speech_recognition_browsertest.cc index 6083ca0..0b56226 100644 --- a/content/browser/speech/speech_input_browsertest.cc +++ b/content/browser/speech/speech_recognition_browsertest.cc @@ -12,28 +12,28 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/speech/speech_input_dispatcher_host.h" -#include "content/browser/speech/speech_input_manager_impl.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/public/browser/notification_types.h" #include "content/public/common/content_switches.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" using content::NavigationController; using content::WebContents; -namespace speech_input { -class FakeSpeechInputManager; +namespace speech { +class FakeSpeechRecognitionManager; } -namespace speech_input { +namespace speech { const char kTestResult[] = "Pictures of the moon"; -class FakeSpeechInputManager : public SpeechInputManagerImpl { +class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { public: - FakeSpeechInputManager() + FakeSpeechRecognitionManager() : caller_id_(0), delegate_(NULL), did_cancel_all_(false), @@ -61,9 +61,9 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { return recognition_started_event_; } - // SpeechInputManager methods. + // SpeechRecognitionManager methods. virtual void StartRecognition( - SpeechInputDispatcherHost* delegate, + InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -72,7 +72,7 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs) OVERRIDE { + content::SpeechRecognitionPreferences* recognition_prefs) OVERRIDE { VLOG(1) << "StartRecognition invoked."; EXPECT_EQ(0, caller_id_); EXPECT_EQ(NULL, delegate_); @@ -82,7 +82,7 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { if (should_send_fake_response_) { // Give the fake result in a short while. MessageLoop::current()->PostTask(FROM_HERE, base::Bind( - &FakeSpeechInputManager::SetFakeRecognitionResult, + &FakeSpeechRecognitionManager::SetFakeRecognitionResult, // This class does not need to be refcounted (typically done by // PostTask) since it will outlive the test and gets released only // when the test shuts down. Disabling refcounting here saves a bit @@ -104,7 +104,7 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { // Nothing to do here since we aren't really recording. } virtual void CancelAllRequestsWithDelegate( - SpeechInputDispatcherHost* delegate) OVERRIDE { + InputTagSpeechDispatcherHost* delegate) OVERRIDE { VLOG(1) << "CancelAllRequestsWithDelegate invoked."; // delegate_ is set to NULL if a fake result was received (see below), so // check that delegate_ matches the incoming parameter only when there is @@ -118,8 +118,8 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { if (caller_id_) { // Do a check in case we were cancelled.. VLOG(1) << "Setting fake recognition result."; delegate_->DidCompleteRecording(caller_id_); - content::SpeechInputResult results; - results.hypotheses.push_back(content::SpeechInputHypothesis( + content::SpeechRecognitionResult results; + results.hypotheses.push_back(content::SpeechRecognitionHypothesis( ASCIIToUTF16(kTestResult), 1.0)); delegate_->SetRecognitionResult(caller_id_, results); delegate_->DidCompleteRecognition(caller_id_); @@ -130,14 +130,14 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { } int caller_id_; - SpeechInputDispatcherHost* delegate_; + InputTagSpeechDispatcherHost* delegate_; std::string grammar_; bool did_cancel_all_; bool should_send_fake_response_; base::WaitableEvent recognition_started_event_; }; -class SpeechInputBrowserTest : public InProcessBrowserTest { +class SpeechRecognitionBrowserTest : public InProcessBrowserTest { public: // InProcessBrowserTest methods virtual void SetUpCommandLine(CommandLine* command_line) { @@ -150,7 +150,7 @@ class SpeechInputBrowserTest : public InProcessBrowserTest { } protected: - void LoadAndStartSpeechInputTest(const FilePath::CharType* filename) { + void LoadAndStartSpeechRecognitionTest(const FilePath::CharType* filename) { // The test page calculates the speech button's coordinate in the page on // load & sets that coordinate in the URL fragment. We send mouse down & up // events at that coordinate to trigger speech recognition. @@ -171,46 +171,47 @@ class SpeechInputBrowserTest : public InProcessBrowserTest { web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); mouse_event.type = WebKit::WebInputEvent::MouseUp; web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); - fake_speech_input_manager_.recognition_started_event().Wait(); + fake_speech_recognition_manager_.recognition_started_event().Wait(); // We should wait for a navigation event, raised by the test page JS code // upon the onwebkitspeechchange event, in all cases except when the // speech response is inhibited. - if (fake_speech_input_manager_.should_send_fake_response()) + if (fake_speech_recognition_manager_.should_send_fake_response()) observer.Wait(); } - void RunSpeechInputTest(const FilePath::CharType* filename) { + void RunSpeechRecognitionTest(const FilePath::CharType* filename) { // The fake speech input manager would receive the speech input // request and return the test string as recognition result. The test page // then sets the URL fragment as 'pass' if it received the expected string. - LoadAndStartSpeechInputTest(filename); + LoadAndStartSpeechRecognitionTest(filename); EXPECT_EQ("pass", browser()->GetSelectedWebContents()->GetURL().ref()); } // InProcessBrowserTest methods. virtual void SetUpInProcessBrowserTestFixture() { - fake_speech_input_manager_.set_should_send_fake_response(true); - speech_input_manager_ = &fake_speech_input_manager_; + fake_speech_recognition_manager_.set_should_send_fake_response(true); + speech_recognition_manager_ = &fake_speech_recognition_manager_; // Inject the fake manager factory so that the test result is returned to // the web page. - SpeechInputDispatcherHost::set_manager(speech_input_manager_); + InputTagSpeechDispatcherHost::set_manager(speech_recognition_manager_); } virtual void TearDownInProcessBrowserTestFixture() { - speech_input_manager_ = NULL; + speech_recognition_manager_ = NULL; } - FakeSpeechInputManager fake_speech_input_manager_; + FakeSpeechRecognitionManager fake_speech_recognition_manager_; // This is used by the static |fakeManager|, and it is a pointer rather than a // direct instance per the style guide. - static SpeechInputManagerImpl* speech_input_manager_; + static SpeechRecognitionManagerImpl* speech_recognition_manager_; }; -SpeechInputManagerImpl* SpeechInputBrowserTest::speech_input_manager_ = NULL; +SpeechRecognitionManagerImpl* + SpeechRecognitionBrowserTest::speech_recognition_manager_ = NULL; // TODO(satish): Once this flakiness has been fixed, add a second test here to // check for sending many clicks in succession to the speech button and verify @@ -220,33 +221,34 @@ SpeechInputManagerImpl* SpeechInputBrowserTest::speech_input_manager_ = NULL; // TODO(satish): Similar to above, once this flakiness has been fixed add // another test here to check that when speech recognition is in progress and // a renderer crashes, we get a call to -// SpeechInputManager::CancelAllRequestsWithDelegate. -IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, TestBasicRecognition) { - RunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); - EXPECT_TRUE(fake_speech_input_manager_.grammar().empty()); +// SpeechRecognitionManager::CancelAllRequestsWithDelegate. +IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestBasicRecognition) { + RunSpeechRecognitionTest(FILE_PATH_LITERAL("basic_recognition.html")); + EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty()); } -IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, GrammarAttribute) { - RunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html")); +IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, GrammarAttribute) { + RunSpeechRecognitionTest(FILE_PATH_LITERAL("grammar_attribute.html")); EXPECT_EQ("http://example.com/grammar.xml", - fake_speech_input_manager_.grammar()); + fake_speech_recognition_manager_.grammar()); } -IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, TestCancelAll) { +IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) { // The test checks that the cancel-all callback gets issued when a session // is pending, so don't send a fake response. // We are not expecting a navigation event being raised from the JS of the // test page JavaScript in this case. - fake_speech_input_manager_.set_should_send_fake_response(false); + fake_speech_recognition_manager_.set_should_send_fake_response(false); - LoadAndStartSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); + LoadAndStartSpeechRecognitionTest( + FILE_PATH_LITERAL("basic_recognition.html")); - // Make the renderer crash. This should trigger SpeechInputDispatcherHost to - // cancel all pending sessions. + // Make the renderer crash. This should trigger + // InputTagSpeechDispatcherHost to cancel all pending sessions. GURL test_url("about:crash"); ui_test_utils::NavigateToURL(browser(), test_url); - EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); + EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all()); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_input_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc index 6df0b3d..9ced53f 100644 --- a/content/browser/speech/speech_input_manager_impl.cc +++ b/content/browser/speech/speech_recognition_manager_impl.cc @@ -2,33 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/speech/speech_input_manager_impl.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "base/bind.h" #include "content/browser/browser_main_loop.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/speech/speech_input_dispatcher_host.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" #include "content/browser/speech/speech_recognizer_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/render_view_host_delegate.h" #include "content/public/browser/resource_context.h" -#include "content/public/browser/speech_input_manager_delegate.h" -#include "content/public/browser/speech_input_preferences.h" +#include "content/public/browser/speech_recognition_manager_delegate.h" +#include "content/public/browser/speech_recognition_preferences.h" #include "content/public/common/view_type.h" using content::BrowserMainLoop; using content::BrowserThread; -using content::SpeechInputManagerDelegate; +using content::SpeechRecognitionManager; +using content::SpeechRecognitionManagerDelegate; -content::SpeechInputManager* content::SpeechInputManager::GetInstance() { - return speech_input::SpeechInputManagerImpl::GetInstance(); +SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { + return speech::SpeechRecognitionManagerImpl::GetInstance(); } -namespace speech_input { +namespace speech { -struct SpeechInputManagerImpl::SpeechInputParams { - SpeechInputParams(SpeechInputDispatcherHost* delegate, +struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { + SpeechRecognitionParams(InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -37,7 +38,7 @@ struct SpeechInputManagerImpl::SpeechInputParams { const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs) + content::SpeechRecognitionPreferences* recognition_prefs) : delegate(delegate), caller_id(caller_id), render_process_id(render_process_id), @@ -47,10 +48,10 @@ struct SpeechInputManagerImpl::SpeechInputParams { grammar(grammar), origin_url(origin_url), context_getter(context_getter), - speech_input_prefs(speech_input_prefs) { + recognition_prefs(recognition_prefs) { } - SpeechInputDispatcherHost* delegate; + InputTagSpeechDispatcherHost* delegate; int caller_id; int render_process_id; int render_view_id; @@ -59,53 +60,53 @@ struct SpeechInputManagerImpl::SpeechInputParams { std::string grammar; std::string origin_url; net::URLRequestContextGetter* context_getter; - content::SpeechInputPreferences* speech_input_prefs; + content::SpeechRecognitionPreferences* recognition_prefs; }; -SpeechInputManagerImpl* SpeechInputManagerImpl::GetInstance() { - return Singleton<SpeechInputManagerImpl>::get(); +SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { + return Singleton<SpeechRecognitionManagerImpl>::get(); } -SpeechInputManagerImpl::SpeechInputManagerImpl() +SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() : can_report_metrics_(false), recording_caller_id_(0) { - delegate_ = - content::GetContentClient()->browser()->GetSpeechInputManagerDelegate(); + delegate_ = content::GetContentClient()->browser()-> + GetSpeechRecognitionManagerDelegate(); } -SpeechInputManagerImpl::~SpeechInputManagerImpl() { +SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { while (requests_.begin() != requests_.end()) CancelRecognition(requests_.begin()->first); } -bool SpeechInputManagerImpl::HasAudioInputDevices() { +bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); } -bool SpeechInputManagerImpl::IsRecordingInProcess() { +bool SpeechRecognitionManagerImpl::IsCapturingAudio() { return BrowserMainLoop::GetAudioManager()->IsRecordingInProcess(); } -string16 SpeechInputManagerImpl::GetAudioInputDeviceModel() { +string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); } -bool SpeechInputManagerImpl::HasPendingRequest(int caller_id) const { +bool SpeechRecognitionManagerImpl::HasPendingRequest(int caller_id) const { return requests_.find(caller_id) != requests_.end(); } -SpeechInputDispatcherHost* SpeechInputManagerImpl::GetDelegate( +InputTagSpeechDispatcherHost* SpeechRecognitionManagerImpl::GetDelegate( int caller_id) const { return requests_.find(caller_id)->second.delegate; } -void SpeechInputManagerImpl::ShowAudioInputSettings() { +void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { // Since AudioManager::ShowAudioInputSettings can potentially launch external // processes, do that in the FILE thread to not block the calling threads. if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - base::Bind(&SpeechInputManagerImpl::ShowAudioInputSettings, + base::Bind(&SpeechRecognitionManagerImpl::ShowAudioInputSettings, base::Unretained(this))); return; } @@ -116,8 +117,8 @@ void SpeechInputManagerImpl::ShowAudioInputSettings() { audio_manager->ShowAudioInputSettings(); } -void SpeechInputManagerImpl::StartRecognition( - SpeechInputDispatcherHost* delegate, +void SpeechRecognitionManagerImpl::StartRecognition( + InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -126,21 +127,21 @@ void SpeechInputManagerImpl::StartRecognition( const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs) { + content::SpeechRecognitionPreferences* recognition_prefs) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind( - &SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition, + &SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition, base::Unretained(this), - SpeechInputParams( + SpeechRecognitionParams( delegate, caller_id, render_process_id, render_view_id, element_rect, language, grammar, origin_url, context_getter, - speech_input_prefs))); + recognition_prefs))); } -void SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition( - const SpeechInputParams& params) { +void SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition( + const SpeechRecognitionParams& params) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); RenderViewHostImpl* render_view_host = RenderViewHostImpl::FromID( @@ -158,13 +159,13 @@ void SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition( content::VIEW_TYPE_TAB_CONTENTS) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - base::Bind(&SpeechInputManagerImpl::ProceedStartingRecognition, + base::Bind(&SpeechRecognitionManagerImpl::ProceedStartingRecognition, base::Unretained(this), params)); } } -void SpeechInputManagerImpl::ProceedStartingRecognition( - const SpeechInputParams& params) { +void SpeechRecognitionManagerImpl::ProceedStartingRecognition( + const SpeechRecognitionParams& params) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(!HasPendingRequest(params.caller_id)); @@ -175,18 +176,18 @@ void SpeechInputManagerImpl::ProceedStartingRecognition( delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); } - SpeechInputRequest* request = &requests_[params.caller_id]; + Request* request = &requests_[params.caller_id]; request->delegate = params.delegate; request->recognizer = new SpeechRecognizerImpl( this, params.caller_id, params.language, params.grammar, - params.context_getter, params.speech_input_prefs->FilterProfanities(), + params.context_getter, params.recognition_prefs->FilterProfanities(), request_info_, can_report_metrics_ ? params.origin_url : ""); request->is_active = false; StartRecognitionForRequest(params.caller_id); } -void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int caller_id) { SpeechRecognizerMap::iterator request = requests_.find(caller_id); if (request == requests_.end()) { NOTREACHED(); @@ -202,13 +203,13 @@ void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { if (!HasAudioInputDevices()) { if (delegate_) { - delegate_->ShowMicError( - caller_id, SpeechInputManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); + delegate_->ShowMicError(caller_id, + SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); } - } else if (IsRecordingInProcess()) { + } else if (IsCapturingAudio()) { if (delegate_) { delegate_->ShowMicError( - caller_id, SpeechInputManagerDelegate::MIC_ERROR_DEVICE_IN_USE); + caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); } } else { recording_caller_id_ = caller_id; @@ -219,7 +220,7 @@ void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { } } -void SpeechInputManagerImpl::CancelRecognitionForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { // Ignore if the caller id was not in our active recognizers list because the // user might have clicked more than once, or recognition could have been // ended due to other reasons before the user click was processed. @@ -229,7 +230,7 @@ void SpeechInputManagerImpl::CancelRecognitionForRequest(int caller_id) { CancelRecognitionAndInformDelegate(caller_id); } -void SpeechInputManagerImpl::FocusLostForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::FocusLostForRequest(int caller_id) { // See above comment. if (!HasPendingRequest(caller_id)) return; @@ -242,7 +243,7 @@ void SpeechInputManagerImpl::FocusLostForRequest(int caller_id) { CancelRecognitionAndInformDelegate(caller_id); } -void SpeechInputManagerImpl::CancelRecognition(int caller_id) { +void SpeechRecognitionManagerImpl::CancelRecognition(int caller_id) { DCHECK(HasPendingRequest(caller_id)); if (requests_[caller_id].is_active) requests_[caller_id].recognizer->CancelRecognition(); @@ -253,8 +254,8 @@ void SpeechInputManagerImpl::CancelRecognition(int caller_id) { delegate_->DoClose(caller_id); } -void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( - SpeechInputDispatcherHost* delegate) { +void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( + InputTagSpeechDispatcherHost* delegate) { SpeechRecognizerMap::iterator it = requests_.begin(); while (it != requests_.end()) { if (it->second.delegate == delegate) { @@ -267,7 +268,7 @@ void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( } } -void SpeechInputManagerImpl::StopRecording(int caller_id) { +void SpeechRecognitionManagerImpl::StopRecording(int caller_id) { // No pending requests on extension popups. if (!HasPendingRequest(caller_id)) return; @@ -275,13 +276,13 @@ void SpeechInputManagerImpl::StopRecording(int caller_id) { requests_[caller_id].recognizer->StopRecording(); } -void SpeechInputManagerImpl::SetRecognitionResult( - int caller_id, const content::SpeechInputResult& result) { +void SpeechRecognitionManagerImpl::SetRecognitionResult( + int caller_id, const content::SpeechRecognitionResult& result) { DCHECK(HasPendingRequest(caller_id)); GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); } -void SpeechInputManagerImpl::DidCompleteRecording(int caller_id) { +void SpeechRecognitionManagerImpl::DidCompleteRecording(int caller_id) { DCHECK(recording_caller_id_ == caller_id); DCHECK(HasPendingRequest(caller_id)); recording_caller_id_ = 0; @@ -290,21 +291,21 @@ void SpeechInputManagerImpl::DidCompleteRecording(int caller_id) { delegate_->ShowRecognizing(caller_id); } -void SpeechInputManagerImpl::DidCompleteRecognition(int caller_id) { +void SpeechRecognitionManagerImpl::DidCompleteRecognition(int caller_id) { GetDelegate(caller_id)->DidCompleteRecognition(caller_id); requests_.erase(caller_id); if (delegate_) delegate_->DoClose(caller_id); } -void SpeechInputManagerImpl::DidStartReceivingSpeech(int caller_id) { +void SpeechRecognitionManagerImpl::DidStartReceivingSpeech(int caller_id) { } -void SpeechInputManagerImpl::DidStopReceivingSpeech(int caller_id) { +void SpeechRecognitionManagerImpl::DidStopReceivingSpeech(int caller_id) { } -void SpeechInputManagerImpl::OnRecognizerError( - int caller_id, content::SpeechInputError error) { +void SpeechRecognitionManagerImpl::OnRecognizerError( + int caller_id, content::SpeechRecognitionErrorCode error) { if (caller_id == recording_caller_id_) recording_caller_id_ = 0; requests_[caller_id].is_active = false; @@ -312,40 +313,41 @@ void SpeechInputManagerImpl::OnRecognizerError( delegate_->ShowRecognizerError(caller_id, error); } -void SpeechInputManagerImpl::DidStartReceivingAudio(int caller_id) { +void SpeechRecognitionManagerImpl::DidStartReceivingAudio(int caller_id) { DCHECK(HasPendingRequest(caller_id)); DCHECK(recording_caller_id_ == caller_id); if (delegate_) delegate_->ShowRecording(caller_id); } -void SpeechInputManagerImpl::DidCompleteEnvironmentEstimation(int caller_id) { +void SpeechRecognitionManagerImpl::DidCompleteEnvironmentEstimation( + int caller_id) { DCHECK(HasPendingRequest(caller_id)); DCHECK(recording_caller_id_ == caller_id); } -void SpeechInputManagerImpl::SetInputVolume(int caller_id, float volume, - float noise_volume) { +void SpeechRecognitionManagerImpl::SetInputVolume(int caller_id, float volume, + float noise_volume) { DCHECK(HasPendingRequest(caller_id)); DCHECK_EQ(recording_caller_id_, caller_id); if (delegate_) delegate_->ShowInputVolume(caller_id, volume, noise_volume); } -void SpeechInputManagerImpl::CancelRecognitionAndInformDelegate( +void SpeechRecognitionManagerImpl::CancelRecognitionAndInformDelegate( int caller_id) { - SpeechInputDispatcherHost* cur_delegate = GetDelegate(caller_id); + InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(caller_id); CancelRecognition(caller_id); cur_delegate->DidCompleteRecording(caller_id); cur_delegate->DidCompleteRecognition(caller_id); } -SpeechInputManagerImpl::SpeechInputRequest::SpeechInputRequest() +SpeechRecognitionManagerImpl::Request::Request() : delegate(NULL), is_active(false) { } -SpeechInputManagerImpl::SpeechInputRequest::~SpeechInputRequest() { +SpeechRecognitionManagerImpl::Request::~Request() { } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_input_manager_impl.h b/content/browser/speech/speech_recognition_manager_impl.h index 6675fb8..8b91029 100644 --- a/content/browser/speech/speech_input_manager_impl.h +++ b/content/browser/speech/speech_recognition_manager_impl.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ -#define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ +#ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ +#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ #include <map> #include <string> @@ -12,7 +12,7 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/singleton.h" -#include "content/public/browser/speech_input_manager.h" +#include "content/public/browser/speech_recognition_manager.h" #include "content/public/browser/speech_recognizer_delegate.h" #include "ui/gfx/rect.h" @@ -20,32 +20,32 @@ class AudioManager; namespace content { class ResourceContext; -class SpeechInputManagerDelegate; -class SpeechInputPreferences; -struct SpeechInputResult; +class SpeechRecognitionManagerDelegate; +class SpeechRecognitionPreferences; +struct SpeechRecognitionResult; } namespace net { class URLRequestContextGetter; } -namespace speech_input { +namespace speech { -class SpeechInputDispatcherHost; +class InputTagSpeechDispatcherHost; class SpeechRecognizerImpl; -class CONTENT_EXPORT SpeechInputManagerImpl - : NON_EXPORTED_BASE(public content::SpeechInputManager), +class CONTENT_EXPORT SpeechRecognitionManagerImpl + : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), NON_EXPORTED_BASE(public content::SpeechRecognizerDelegate) { public: - static SpeechInputManagerImpl* GetInstance(); + static SpeechRecognitionManagerImpl* GetInstance(); - // SpeechInputManager implementation: + // SpeechRecognitionManager implementation: virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; virtual void FocusLostForRequest(int caller_id) OVERRIDE; virtual bool HasAudioInputDevices() OVERRIDE; - virtual bool IsRecordingInProcess() OVERRIDE; + virtual bool IsCapturingAudio() OVERRIDE; virtual string16 GetAudioInputDeviceModel() OVERRIDE; virtual void ShowAudioInputSettings() OVERRIDE; @@ -58,7 +58,7 @@ class CONTENT_EXPORT SpeechInputManagerImpl // |element_rect| is the display bounds of the html element requesting speech // input (in page coordinates). virtual void StartRecognition( - SpeechInputDispatcherHost* delegate, + InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -67,63 +67,63 @@ class CONTENT_EXPORT SpeechInputManagerImpl const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs); + content::SpeechRecognitionPreferences* speech_recognition_prefs); virtual void CancelRecognition(int caller_id); virtual void CancelAllRequestsWithDelegate( - SpeechInputDispatcherHost* delegate); + InputTagSpeechDispatcherHost* delegate); virtual void StopRecording(int caller_id); // Overridden from content::SpeechRecognizerDelegate: virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; virtual void SetRecognitionResult( - int caller_id, - const content::SpeechInputResult& result) OVERRIDE; + int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; virtual void DidCompleteRecording(int caller_id) OVERRIDE; virtual void DidCompleteRecognition(int caller_id) OVERRIDE; virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; - virtual void OnRecognizerError(int caller_id, - content::SpeechInputError error) OVERRIDE; + virtual void OnRecognizerError( + int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE; virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; virtual void SetInputVolume(int caller_id, float volume, float noise_volume) OVERRIDE; protected: // Private constructor to enforce singleton. - friend struct DefaultSingletonTraits<SpeechInputManagerImpl>; - SpeechInputManagerImpl(); - virtual ~SpeechInputManagerImpl(); + friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; + SpeechRecognitionManagerImpl(); + virtual ~SpeechRecognitionManagerImpl(); bool HasPendingRequest(int caller_id) const; private: - struct SpeechInputRequest { - SpeechInputRequest(); - ~SpeechInputRequest(); + struct Request { + Request(); + ~Request(); - SpeechInputDispatcherHost* delegate; + InputTagSpeechDispatcherHost* delegate; scoped_refptr<SpeechRecognizerImpl> recognizer; bool is_active; // Set to true when recording or recognition is going on. }; - struct SpeechInputParams; + struct SpeechRecognitionParams; - SpeechInputDispatcherHost* GetDelegate(int caller_id) const; + InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; - void CheckRenderViewTypeAndStartRecognition(const SpeechInputParams& params); - void ProceedStartingRecognition(const SpeechInputParams& params); + void CheckRenderViewTypeAndStartRecognition( + const SpeechRecognitionParams& params); + void ProceedStartingRecognition(const SpeechRecognitionParams& params); void CancelRecognitionAndInformDelegate(int caller_id); - typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; + typedef std::map<int, Request> SpeechRecognizerMap; SpeechRecognizerMap requests_; std::string request_info_; bool can_report_metrics_; int recording_caller_id_; - content::SpeechInputManagerDelegate* delegate_; + content::SpeechRecognitionManagerDelegate* delegate_; }; -} // namespace speech_input +} // namespace speech -#endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ +#endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ diff --git a/content/browser/speech/speech_recognition_request.cc b/content/browser/speech/speech_recognition_request.cc index 8176128..89dde84 100644 --- a/content/browser/speech/speech_recognition_request.cc +++ b/content/browser/speech/speech_recognition_request.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,7 +11,7 @@ #include "base/string_util.h" #include "base/values.h" #include "content/common/net/url_fetcher_impl.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "net/base/escape.h" #include "net/base/load_flags.h" #include "net/url_request/url_request_context.h" @@ -32,7 +32,7 @@ const char* const kConfidenceString = "confidence"; const int kMaxResults = 6; bool ParseServerResponse(const std::string& response_body, - content::SpeechInputResult* result) { + content::SpeechRecognitionResult* result) { if (response_body.empty()) { LOG(WARNING) << "ParseServerResponse: Response was empty."; return false; @@ -66,9 +66,9 @@ bool ParseServerResponse(const std::string& response_body, // Process the status. switch (status) { - case content::SPEECH_INPUT_ERROR_NONE: - case content::SPEECH_INPUT_ERROR_NO_SPEECH: - case content::SPEECH_INPUT_ERROR_NO_MATCH: + case content::SPEECH_RECOGNITION_ERROR_NONE: + case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH: + case content::SPEECH_RECOGNITION_ERROR_NO_MATCH: break; default: @@ -77,7 +77,7 @@ bool ParseServerResponse(const std::string& response_body, return false; } - result->error = static_cast<content::SpeechInputError>(status); + result->error = static_cast<content::SpeechRecognitionErrorCode>(status); // Get the hypotheses. Value* hypotheses_value = NULL; @@ -121,7 +121,7 @@ bool ParseServerResponse(const std::string& response_body, double confidence = 0.0; hypothesis_value->GetDouble(kConfidenceString, &confidence); - result->hypotheses.push_back(content::SpeechInputHypothesis( + result->hypotheses.push_back(content::SpeechRecognitionHypothesis( utterance, confidence)); } @@ -135,7 +135,7 @@ bool ParseServerResponse(const std::string& response_body, } // namespace -namespace speech_input { +namespace speech { int SpeechRecognitionRequest::url_fetcher_id_for_tests = 0; @@ -211,12 +211,12 @@ void SpeechRecognitionRequest::OnURLFetchComplete( const content::URLFetcher* source) { DCHECK_EQ(url_fetcher_.get(), source); - content::SpeechInputResult result; + content::SpeechRecognitionResult result; std::string data; if (!source->GetStatus().is_success() || source->GetResponseCode() != 200 || !source->GetResponseAsString(&data) || !ParseServerResponse(data, &result)) { - result.error = content::SPEECH_INPUT_ERROR_NETWORK; + result.error = content::SPEECH_RECOGNITION_ERROR_NETWORK; } DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; @@ -224,4 +224,4 @@ void SpeechRecognitionRequest::OnURLFetchComplete( delegate_->SetRecognitionResult(result); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_recognition_request.h b/content/browser/speech/speech_recognition_request.h index 65a9733..b6ce077 100644 --- a/content/browser/speech/speech_recognition_request.h +++ b/content/browser/speech/speech_recognition_request.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,14 +18,14 @@ class URLFetcher; namespace content { -struct SpeechInputResult; +struct SpeechRecognitionResult; } namespace net { class URLRequestContextGetter; } -namespace speech_input { +namespace speech { // Provides a simple interface for sending recorded speech data to the server // and get back recognition results. @@ -38,7 +38,7 @@ class SpeechRecognitionRequest : public content::URLFetcherDelegate { class CONTENT_EXPORT Delegate { public: virtual void SetRecognitionResult( - const content::SpeechInputResult& result) = 0; + const content::SpeechRecognitionResult& result) = 0; protected: virtual ~Delegate() {} @@ -83,6 +83,6 @@ class SpeechRecognitionRequest : public content::URLFetcherDelegate { // the workaround was not needed for my machine). typedef SpeechRecognitionRequest::Delegate SpeechRecognitionRequestDelegate; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_REQUEST_H_ diff --git a/content/browser/speech/speech_recognition_request_unittest.cc b/content/browser/speech/speech_recognition_request_unittest.cc index 9221085..37b82f8 100644 --- a/content/browser/speech/speech_recognition_request_unittest.cc +++ b/content/browser/speech/speech_recognition_request_unittest.cc @@ -1,17 +1,17 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "content/browser/speech/speech_recognition_request.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" -namespace speech_input { +namespace speech { class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, public testing::Test { @@ -24,14 +24,14 @@ class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, // SpeechRecognitionRequestDelegate methods. virtual void SetRecognitionResult( - const content::SpeechInputResult& result) OVERRIDE { + const content::SpeechRecognitionResult& result) OVERRIDE { result_ = result; } protected: MessageLoop message_loop_; TestURLFetcherFactory url_fetcher_factory_; - content::SpeechInputResult result_; + content::SpeechRecognitionResult result_; }; void SpeechRecognitionRequestTest::CreateAndTestRequest( @@ -60,7 +60,7 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" "[{\"utterance\":\"123456\",\"confidence\":0.9}]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NONE); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); EXPECT_EQ(1U, result_.hypotheses.size()); EXPECT_EQ(ASCIIToUTF16("123456"), result_.hypotheses[0].utterance); EXPECT_EQ(0.9, result_.hypotheses[0].confidence); @@ -70,7 +70,7 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { "{\"status\":0,\"hypotheses\":[" "{\"utterance\":\"hello\",\"confidence\":0.9}," "{\"utterance\":\"123456\",\"confidence\":0.5}]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NONE); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); EXPECT_EQ(2u, result_.hypotheses.size()); EXPECT_EQ(ASCIIToUTF16("hello"), result_.hypotheses[0].utterance); EXPECT_EQ(0.9, result_.hypotheses[0].confidence); @@ -79,29 +79,29 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { // Zero results. CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":[]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NONE); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); EXPECT_EQ(0U, result_.hypotheses.size()); // Http failure case. CreateAndTestRequest(false, ""); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); // Invalid status case. CreateAndTestRequest(true, "{\"status\":\"invalid\",\"hypotheses\":[]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); // Server-side error case. CreateAndTestRequest(true, "{\"status\":1,\"hypotheses\":[]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); // Malformed JSON case. CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" "[{\"unknownkey\":\"hello\"}]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_recognizer_impl.cc b/content/browser/speech/speech_recognizer_impl.cc index 9d4ed1c..bbcfbd2 100644 --- a/content/browser/speech/speech_recognizer_impl.cc +++ b/content/browser/speech/speech_recognizer_impl.cc @@ -9,7 +9,7 @@ #include "content/browser/browser_main_loop.h" #include "content/public/browser/speech_recognizer_delegate.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "net/url_request/url_request_context_getter.h" using content::BrowserMainLoop; @@ -61,12 +61,12 @@ SpeechRecognizer* SpeechRecognizer::Create( bool filter_profanities, const std::string& hardware_info, const std::string& origin_url) { - return new speech_input::SpeechRecognizerImpl( + return new speech::SpeechRecognizerImpl( delegate, caller_id, language, grammar, context_getter, filter_profanities, hardware_info, origin_url); } -namespace speech_input { +namespace speech { const int SpeechRecognizerImpl::kAudioSampleRate = 16000; const int SpeechRecognizerImpl::kAudioPacketIntervalMs = 100; @@ -208,7 +208,7 @@ void SpeechRecognizerImpl::HandleOnError(int error_code) { if (!audio_controller_.get()) return; - InformErrorAndCancelRecognition(content::SPEECH_INPUT_ERROR_AUDIO); + InformErrorAndCancelRecognition(content::SPEECH_RECOGNITION_ERROR_AUDIO); } void SpeechRecognizerImpl::OnData(AudioInputController* controller, @@ -272,7 +272,8 @@ void SpeechRecognizerImpl::HandleOnData(string* data) { bool speech_was_heard_after_packet = endpointer_.DidStartReceivingSpeech(); if (!speech_was_heard_after_packet && num_samples_recorded_ >= kNoSpeechTimeoutSec * kAudioSampleRate) { - InformErrorAndCancelRecognition(content::SPEECH_INPUT_ERROR_NO_SPEECH); + InformErrorAndCancelRecognition( + content::SPEECH_RECOGNITION_ERROR_NO_SPEECH); return; } @@ -303,8 +304,8 @@ void SpeechRecognizerImpl::HandleOnData(string* data) { } void SpeechRecognizerImpl::SetRecognitionResult( - const content::SpeechInputResult& result) { - if (result.error != content::SPEECH_INPUT_ERROR_NONE) { + const content::SpeechRecognitionResult& result) { + if (result.error != content::SPEECH_RECOGNITION_ERROR_NONE) { InformErrorAndCancelRecognition(result.error); return; } @@ -316,8 +317,8 @@ void SpeechRecognizerImpl::SetRecognitionResult( } void SpeechRecognizerImpl::InformErrorAndCancelRecognition( - content::SpeechInputError error) { - DCHECK_NE(error, content::SPEECH_INPUT_ERROR_NONE); + content::SpeechRecognitionErrorCode error) { + DCHECK_NE(error, content::SPEECH_RECOGNITION_ERROR_NONE); CancelRecognition(); // Guard against the delegate freeing us until we finish our job. @@ -343,4 +344,4 @@ void SpeechRecognizerImpl::SetAudioManagerForTesting( audio_manager_ = audio_manager; } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_recognizer_impl.h b/content/browser/speech/speech_recognizer_impl.h index 0273ccb..25e0c0c 100644 --- a/content/browser/speech/speech_recognizer_impl.h +++ b/content/browser/speech/speech_recognizer_impl.h @@ -14,12 +14,12 @@ #include "content/browser/speech/endpointer/endpointer.h" #include "content/browser/speech/speech_recognition_request.h" #include "content/public/browser/speech_recognizer.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "media/audio/audio_input_controller.h" class AudioManager; -namespace speech_input { +namespace speech { // Records audio, sends recorded audio to server and translates server response // to recognition result. @@ -47,8 +47,8 @@ class CONTENT_EXPORT SpeechRecognizerImpl void StopRecording(); // AudioInputController::EventHandler methods. - virtual void OnCreated(media::AudioInputController* controller) OVERRIDE { } - virtual void OnRecording(media::AudioInputController* controller) OVERRIDE { } + virtual void OnCreated(media::AudioInputController* controller) OVERRIDE {} + virtual void OnRecording(media::AudioInputController* controller) OVERRIDE {} virtual void OnError(media::AudioInputController* controller, int error_code) OVERRIDE; virtual void OnData(media::AudioInputController* controller, @@ -57,7 +57,7 @@ class CONTENT_EXPORT SpeechRecognizerImpl // SpeechRecognitionRequest::Delegate methods. virtual void SetRecognitionResult( - const content::SpeechInputResult& result) OVERRIDE; + const content::SpeechRecognitionResult& result) OVERRIDE; static const int kAudioSampleRate; static const int kAudioPacketIntervalMs; // Duration of each audio packet. @@ -69,7 +69,8 @@ class CONTENT_EXPORT SpeechRecognizerImpl private: friend class SpeechRecognizerTest; - void InformErrorAndCancelRecognition(content::SpeechInputError error); + void InformErrorAndCancelRecognition( + content::SpeechRecognitionErrorCode error); void SendRecordedAudioToServer(); void HandleOnError(int error_code); // Handles OnError in the IO thread. @@ -103,6 +104,6 @@ class CONTENT_EXPORT SpeechRecognizerImpl DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ diff --git a/content/browser/speech/speech_recognizer_impl_unittest.cc b/content/browser/speech/speech_recognizer_impl_unittest.cc index 7388914..cfd2c33 100644 --- a/content/browser/speech/speech_recognizer_impl_unittest.cc +++ b/content/browser/speech/speech_recognizer_impl_unittest.cc @@ -20,7 +20,7 @@ using media::AudioInputController; using media::TestAudioInputController; using media::TestAudioInputControllerFactory; -namespace speech_input { +namespace speech { class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, public testing::Test { @@ -32,7 +32,7 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, recognition_complete_(false), result_received_(false), audio_received_(false), - error_(content::SPEECH_INPUT_ERROR_NONE), + error_(content::SPEECH_RECOGNITION_ERROR_NONE), volume_(-1.0f) { recognizer_ = new SpeechRecognizerImpl( this, 1, std::string(), std::string(), NULL, false, std::string(), @@ -49,7 +49,7 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, // Overridden from content::SpeechRecognizerDelegate: virtual void SetRecognitionResult( int caller_id, - const content::SpeechInputResult& result) OVERRIDE { + const content::SpeechRecognitionResult& result) OVERRIDE { result_received_ = true; } @@ -74,8 +74,8 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE { } - virtual void OnRecognizerError(int caller_id, - content::SpeechInputError error) OVERRIDE { + virtual void OnRecognizerError( + int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE { error_ = error; } @@ -119,7 +119,7 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, bool recognition_complete_; bool result_received_; bool audio_received_; - content::SpeechInputError error_; + content::SpeechRecognitionErrorCode error_; TestURLFetcherFactory url_fetcher_factory_; TestAudioInputControllerFactory audio_input_controller_factory_; std::vector<uint8> audio_packet_; @@ -135,7 +135,7 @@ TEST_F(SpeechRecognizerTest, StopNoData) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); EXPECT_FALSE(audio_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, CancelNoData) { @@ -147,7 +147,7 @@ TEST_F(SpeechRecognizerTest, CancelNoData) { EXPECT_TRUE(recognition_complete_); EXPECT_FALSE(result_received_); EXPECT_FALSE(audio_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, StopWithData) { @@ -177,7 +177,7 @@ TEST_F(SpeechRecognizerTest, StopWithData) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); // Issue the network callback to complete the process. TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); @@ -194,7 +194,7 @@ TEST_F(SpeechRecognizerTest, StopWithData) { EXPECT_TRUE(recognition_complete_); EXPECT_TRUE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, CancelWithData) { @@ -213,7 +213,7 @@ TEST_F(SpeechRecognizerTest, CancelWithData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, ConnectionError) { @@ -234,7 +234,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); // Issue the network callback to complete the process. fetcher->set_url(fetcher->GetOriginalURL()); @@ -248,7 +248,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NETWORK, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NETWORK, error_); } TEST_F(SpeechRecognizerTest, ServerError) { @@ -269,7 +269,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); // Issue the network callback to complete the process. fetcher->set_url(fetcher->GetOriginalURL()); @@ -282,7 +282,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NETWORK, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NETWORK, error_); } TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { @@ -297,7 +297,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_AUDIO, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_AUDIO, error_); } TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { @@ -316,7 +316,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_AUDIO, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_AUDIO, error_); } TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { @@ -341,7 +341,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NO_SPEECH, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_); } TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { @@ -372,7 +372,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { } MessageLoop::current()->RunAllPending(); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); @@ -415,10 +415,10 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) { EXPECT_FLOAT_EQ(0.89926866f, volume_); EXPECT_FLOAT_EQ(0.75071919f, noise_volume_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); recognizer_->CancelRecognition(); } -} // namespace speech_input +} // namespace speech diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h index 1e6f3c5..9ef7371 100644 --- a/content/common/content_message_generator.h +++ b/content/common/content_message_generator.h @@ -35,7 +35,7 @@ #include "content/common/quota_messages.h" #include "content/common/resource_messages.h" #include "content/common/socket_stream_messages.h" -#include "content/common/speech_input_messages.h" +#include "content/common/speech_recognition_messages.h" #include "content/common/text_input_client_messages.h" #include "content/common/utility_messages.h" #include "content/common/view_messages.h" diff --git a/content/common/speech_input_messages.h b/content/common/speech_recognition_messages.h index f50e057..7ab76c1 100644 --- a/content/common/speech_input_messages.h +++ b/content/common/speech_recognition_messages.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,27 +6,27 @@ #include <string> -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_param_traits.h" #include "ui/gfx/rect.h" -#define IPC_MESSAGE_START SpeechInputMsgStart +#define IPC_MESSAGE_START SpeechRecognitionMsgStart -IPC_ENUM_TRAITS(content::SpeechInputError) +IPC_ENUM_TRAITS(content::SpeechRecognitionErrorCode) -IPC_STRUCT_TRAITS_BEGIN(content::SpeechInputHypothesis) +IPC_STRUCT_TRAITS_BEGIN(content::SpeechRecognitionHypothesis) IPC_STRUCT_TRAITS_MEMBER(utterance) IPC_STRUCT_TRAITS_MEMBER(confidence) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(content::SpeechInputResult) +IPC_STRUCT_TRAITS_BEGIN(content::SpeechRecognitionResult) IPC_STRUCT_TRAITS_MEMBER(error) IPC_STRUCT_TRAITS_MEMBER(hypotheses) IPC_STRUCT_TRAITS_END() // Used to start a speech recognition session. -IPC_STRUCT_BEGIN(SpeechInputHostMsg_StartRecognition_Params) +IPC_STRUCT_BEGIN(InputTagSpeechHostMsg_StartRecognition_Params) // The render view requesting speech recognition. IPC_STRUCT_MEMBER(int, render_view_id) // Request ID used within the render view. @@ -35,53 +35,52 @@ IPC_STRUCT_BEGIN(SpeechInputHostMsg_StartRecognition_Params) IPC_STRUCT_MEMBER(gfx::Rect, element_rect) // Language to use for speech recognition. IPC_STRUCT_MEMBER(std::string, language) - // Speech grammar given by the speech input element. + // Speech grammar given by the speech recognition element. IPC_STRUCT_MEMBER(std::string, grammar) // URL of the page (or iframe if applicable). IPC_STRUCT_MEMBER(std::string, origin_url) IPC_STRUCT_END() -// Speech input messages sent from the renderer to the browser. +// Speech recognition messages sent from the renderer to the browser. -// Requests the speech input service to start speech recognition on behalf of -// the given |render_view_id|. -IPC_MESSAGE_CONTROL1(SpeechInputHostMsg_StartRecognition, - SpeechInputHostMsg_StartRecognition_Params) +// Requests the speech recognition service to start speech recognition on behalf +// of the given |render_view_id|. +IPC_MESSAGE_CONTROL1(InputTagSpeechHostMsg_StartRecognition, + InputTagSpeechHostMsg_StartRecognition_Params) -// Requests the speech input service to cancel speech recognition on behalf of -// the given |render_view_id|. If speech recognition is not happening or -// is happening on behalf of some other render view, this call does nothing. -IPC_MESSAGE_CONTROL2(SpeechInputHostMsg_CancelRecognition, +// Requests the speech recognition service to cancel speech recognition on +// behalf of the given |render_view_id|. If speech recognition is not happening +// or is happening on behalf of some other render view, this call does nothing. +IPC_MESSAGE_CONTROL2(InputTagSpeechHostMsg_CancelRecognition, int /* render_view_id */, int /* request_id */) -// Requests the speech input service to stop audio recording on behalf of +// Requests the speech recognition service to stop audio recording on behalf of // the given |render_view_id|. Any audio recorded so far will be fed to the // speech recognizer. If speech recognition is not happening nor or is // happening on behalf of some other render view, this call does nothing. -IPC_MESSAGE_CONTROL2(SpeechInputHostMsg_StopRecording, +IPC_MESSAGE_CONTROL2(InputTagSpeechHostMsg_StopRecording, int /* render_view_id */, int /* request_id */) -// Speech input messages sent from the browser to the renderer. +// Speech recognition messages sent from the browser to the renderer. // Relay a speech recognition result, either partial or final. -IPC_MESSAGE_ROUTED2(SpeechInputMsg_SetRecognitionResult, +IPC_MESSAGE_ROUTED2(InputTagSpeechMsg_SetRecognitionResult, int /* request_id */, - content::SpeechInputResult /* result */) + content::SpeechRecognitionResult /* result */) // Indicate that speech recognizer has stopped recording and started // recognition. -IPC_MESSAGE_ROUTED1(SpeechInputMsg_RecordingComplete, +IPC_MESSAGE_ROUTED1(InputTagSpeechMsg_RecordingComplete, int /* request_id */) -// Indicate that speech recognizer has completed recognition. This will be -// the last message sent in response to a -// ViewHostMsg_SpeechInput_StartRecognition. -IPC_MESSAGE_ROUTED1(SpeechInputMsg_RecognitionComplete, +// Indicate that speech recognizer has completed recognition. This will be the +// last message sent in response to a InputTagSpeechHostMsg_StartRecognition. +IPC_MESSAGE_ROUTED1(InputTagSpeechMsg_RecognitionComplete, int /* request_id */) -// Toggle speech input on or off on the speech input control for the +// Toggle speech recognition on or off on the speech input control for the // current focused element. Has no effect if the current element doesn't -// support speech input. -IPC_MESSAGE_ROUTED0(SpeechInputMsg_ToggleSpeechInput) +// support speech recognition. +IPC_MESSAGE_ROUTED0(InputTagSpeechMsg_ToggleSpeechInput) diff --git a/content/content_browser.gypi b/content/content_browser.gypi index a6a81d8f..e2acdde 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -115,9 +115,9 @@ 'public/browser/sensors_provider.h', 'public/browser/session_storage_namespace.h', 'public/browser/site_instance.h', - 'public/browser/speech_input_manager.h', - 'public/browser/speech_input_manager_delegate.h', - 'public/browser/speech_input_preferences.h', + 'public/browser/speech_recognition_manager.h', + 'public/browser/speech_recognition_manager_delegate.h', + 'public/browser/speech_recognition_preferences.h', 'public/browser/speech_recognizer.h', 'public/browser/speech_recognizer_delegate.h', 'public/browser/user_metrics.h', @@ -605,10 +605,10 @@ 'browser/speech/endpointer/energy_endpointer.h', 'browser/speech/endpointer/energy_endpointer_params.cc', 'browser/speech/endpointer/energy_endpointer_params.h', - 'browser/speech/speech_input_dispatcher_host.cc', - 'browser/speech/speech_input_dispatcher_host.h', - 'browser/speech/speech_input_manager_impl.cc', - 'browser/speech/speech_input_manager_impl.h', + 'browser/speech/input_tag_speech_dispatcher_host.cc', + 'browser/speech/input_tag_speech_dispatcher_host.h', + 'browser/speech/speech_recognition_manager_impl.cc', + 'browser/speech/speech_recognition_manager_impl.h', 'browser/speech/speech_recognition_request.cc', 'browser/speech/speech_recognition_request.h', 'browser/speech/speech_recognizer_impl.cc', diff --git a/content/content_common.gypi b/content/content_common.gypi index 4889f2c..e93daf8 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -74,8 +74,8 @@ 'public/common/serialized_script_value.h', 'public/common/show_desktop_notification_params.cc', 'public/common/show_desktop_notification_params.h', - 'public/common/speech_input_result.cc', - 'public/common/speech_input_result.h', + 'public/common/speech_recognition_result.h', + 'public/common/speech_recognition_result.cc', 'public/common/ssl_status.cc', 'public/common/ssl_status.h', 'public/common/stop_find_action.h', @@ -286,7 +286,7 @@ 'common/socket_stream_dispatcher.cc', 'common/socket_stream_dispatcher.h', 'common/socket_stream_messages.h', - 'common/speech_input_messages.h', + 'common/speech_recognition_messages.h', 'common/ssl_status_serialization.cc', 'common/ssl_status_serialization.h', 'common/swapped_out_messages.cc', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 7c484a6..c67a3a3 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -64,6 +64,8 @@ 'renderer/gpu/input_event_filter.h', 'renderer/idle_user_detector.cc', 'renderer/idle_user_detector.h', + 'renderer/input_tag_speech_dispatcher.cc', + 'renderer/input_tag_speech_dispatcher.h', 'renderer/java/java_bridge_channel.cc', 'renderer/java/java_bridge_channel.h', 'renderer/java/java_bridge_dispatcher.cc', @@ -172,8 +174,6 @@ 'renderer/renderer_webstoragearea_impl.h', 'renderer/renderer_webstoragenamespace_impl.cc', 'renderer/renderer_webstoragenamespace_impl.h', - 'renderer/speech_input_dispatcher.cc', - 'renderer/speech_input_dispatcher.h', 'renderer/text_input_client_observer.cc', 'renderer/text_input_client_observer.h', 'renderer/v8_value_converter_impl.cc', @@ -217,8 +217,8 @@ }], ['input_speech==0', { 'sources!': [ - 'renderer/speech_input_dispatcher.cc', - 'renderer/speech_input_dispatcher.h', + 'renderer/input_tag_speech_dispatcher.cc', + 'renderer/input_tag_speech_dispatcher.h', ] }], ['notifications==0', { diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index 60786dcf..7a4577e 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -40,7 +40,7 @@ class DownloadManager; class GeolocationPermissionContext; class IndexedDBContext; class ResourceContext; -class SpeechInputPreferences; +class SpeechRecognitionPreferences; // This class holds the context needed for a browsing session. // It lives on the UI thread. @@ -110,9 +110,9 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { // Returns the geolocation permission context for this context. virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0; - // Returns the speech input preferences. SpeechInputPreferences is a + // Returns the speech input preferences. SpeechRecognitionPreferences is a // ref counted class, so callers should take a reference if needed. - virtual SpeechInputPreferences* GetSpeechInputPreferences() = 0; + virtual SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() = 0; // Returns true if the last time this context was open it was exited cleanly. // This doesn't belong here; http://crbug.com/90737 diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 19eb3b3..cca6ae2 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -26,6 +26,18 @@ class ResourceDispatcherHost; class SkBitmap; struct WebPreferences; +namespace content { +class AccessTokenStore; +class BrowserMainParts; +class RenderProcessHost; +class SiteInstance; +class SpeechRecognitionManagerDelegate; +class WebContents; +class WebContentsView; +struct MainFunctionParams; +struct ShowDesktopNotificationHostMsgParams; +} + namespace crypto { class CryptoModuleBlockingPasswordDelegate; } @@ -322,9 +334,10 @@ class ContentBrowserClient { // This is when it can optionally add a delegate or ResourceQueueDelegates. virtual void ResourceDispatcherHostCreated() = 0; - // Allows the embedder to return a delegate for the SpeechInputManager. The - // delegate will be owned by the manager. It's valid to return NULL. - virtual SpeechInputManagerDelegate* GetSpeechInputManagerDelegate() = 0; + // Allows the embedder to return a delegate for the SpeechRecognitionManager. + // The delegate will be owned by the manager. It's valid to return NULL. + virtual SpeechRecognitionManagerDelegate* + GetSpeechRecognitionManagerDelegate() = 0; // Getters for common objects. virtual ui::Clipboard* GetClipboard() = 0; diff --git a/content/public/browser/speech_input_manager.h b/content/public/browser/speech_recognition_manager.h index 409d5dc..89651c1 100644 --- a/content/public/browser/speech_input_manager.h +++ b/content/public/browser/speech_recognition_manager.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_MANAGER_H_ -#define CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_MANAGER_H_ +#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ +#define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ #include "base/string16.h" #include "content/common/content_export.h" @@ -14,10 +14,10 @@ namespace content { // handles requests received from various render views and makes sure only one // of them can use speech recognition at a time. It also sends recognition // results and status events to the render views when required. -class SpeechInputManager { +class SpeechRecognitionManager { public: // Returns the singleton instance. - CONTENT_EXPORT static SpeechInputManager* GetInstance(); + CONTENT_EXPORT static SpeechRecognitionManager* GetInstance(); // Starts/restarts recognition for an existing request. virtual void StartRecognitionForRequest(int caller_id) = 0; @@ -33,7 +33,7 @@ class SpeechInputManager { virtual bool HasAudioInputDevices() = 0; // Used to determine if something else is currently making use of audio input. - virtual bool IsRecordingInProcess() = 0; + virtual bool IsCapturingAudio() = 0; // Returns a human readable string for the model/make of the active audio // input device for this computer. @@ -44,9 +44,9 @@ class SpeechInputManager { virtual void ShowAudioInputSettings() = 0; protected: - virtual ~SpeechInputManager() {} + virtual ~SpeechRecognitionManager() {} }; } // namespace content -#endif // CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_MANAGER_H_ +#endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ diff --git a/content/public/browser/speech_input_manager_delegate.h b/content/public/browser/speech_recognition_manager_delegate.h index 348bfbe..dfe04c7 100644 --- a/content/public/browser/speech_input_manager_delegate.h +++ b/content/public/browser/speech_recognition_manager_delegate.h @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_MANAGER_DELEGATE_H_ -#define CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_MANAGER_DELEGATE_H_ +#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_ +#define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_ #pragma once #include <string> -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" namespace gfx { class Rect; @@ -16,11 +16,11 @@ class Rect; namespace content { -struct SpeechInputResult; +struct SpeechRecognitionResult; // Allows embedders to display the current state of recognition, for getting the // user's permission and for fetching optional request information. -class SpeechInputManagerDelegate { +class SpeechRecognitionManagerDelegate { public: // Describes the microphone errors that are reported via ShowMicError. enum MicError { @@ -28,7 +28,7 @@ class SpeechInputManagerDelegate { MIC_ERROR_DEVICE_IN_USE }; - virtual ~SpeechInputManagerDelegate() {} + virtual ~SpeechRecognitionManagerDelegate() {} // Get the optional request information if available. virtual void GetRequestInfo(bool* can_report_metrics, @@ -62,7 +62,7 @@ class SpeechInputManagerDelegate { // Called when there has been a error with the recognition. virtual void ShowRecognizerError(int caller_id, - SpeechInputError error) = 0; + SpeechRecognitionErrorCode error) = 0; // Called when recognition has ended or has been canceled. virtual void DoClose(int caller_id) = 0; @@ -70,4 +70,4 @@ class SpeechInputManagerDelegate { } // namespace content -#endif // CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_MANAGER_DELEGATE_H_ +#endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_ diff --git a/content/public/browser/speech_input_preferences.h b/content/public/browser/speech_recognition_preferences.h index e5a9420..c5682e2 100644 --- a/content/public/browser/speech_input_preferences.h +++ b/content/public/browser/speech_recognition_preferences.h @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_PREFERENCES_H_ -#define CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_PREFERENCES_H_ +#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_PREFERENCES_H_ +#define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_PREFERENCES_H_ #pragma once #include "base/memory/ref_counted.h" namespace content { -class SpeechInputPreferences - : public base::RefCountedThreadSafe<SpeechInputPreferences> { +class SpeechRecognitionPreferences + : public base::RefCountedThreadSafe<SpeechRecognitionPreferences> { public: // Only to be called on the IO thread. virtual bool FilterProfanities() const = 0; @@ -19,12 +19,12 @@ class SpeechInputPreferences virtual void SetFilterProfanities(bool filter_profanities) = 0; protected: - virtual ~SpeechInputPreferences() {} + virtual ~SpeechRecognitionPreferences() {} private: - friend class base::RefCountedThreadSafe<SpeechInputPreferences>; + friend class base::RefCountedThreadSafe<SpeechRecognitionPreferences>; }; } // namespace content -#endif // CONTENT_PUBLIC_BROWSER_SPEECH_INPUT_PREFERENCES_H_ +#endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_PREFERENCES_H_ diff --git a/content/public/browser/speech_recognizer.h b/content/public/browser/speech_recognizer.h index 32a8069..50c5c31 100644 --- a/content/public/browser/speech_recognizer.h +++ b/content/public/browser/speech_recognizer.h @@ -46,6 +46,6 @@ class SpeechRecognizer : public base::RefCountedThreadSafe<SpeechRecognizer> { virtual void CancelRecognition() = 0; }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_H_ diff --git a/content/public/browser/speech_recognizer_delegate.h b/content/public/browser/speech_recognizer_delegate.h index daf482a..14be404 100644 --- a/content/public/browser/speech_recognizer_delegate.h +++ b/content/public/browser/speech_recognizer_delegate.h @@ -6,7 +6,7 @@ #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ #pragma once -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" namespace content { @@ -15,7 +15,7 @@ namespace content { class SpeechRecognizerDelegate { public: virtual void SetRecognitionResult(int caller_id, - const SpeechInputResult& result) = 0; + const SpeechRecognitionResult& result) = 0; // Invoked when the first audio packet was received from the audio capture // device. @@ -41,7 +41,8 @@ class SpeechRecognizerDelegate { // session has already been cancelled when this call is made and the DidXxxx // callbacks will not be issued. It is safe to destroy/release the // |SpeechRecognizer| object while processing this call. - virtual void OnRecognizerError(int caller_id, SpeechInputError error) = 0; + virtual void OnRecognizerError(int caller_id, + SpeechRecognitionErrorCode error) = 0; // At the start of recognition, a short amount of audio is recorded to // estimate the environment/background noise and this callback is issued diff --git a/content/public/common/speech_input_result.cc b/content/public/common/speech_input_result.cc deleted file mode 100644 index 3c9e1f3..0000000 --- a/content/public/common/speech_input_result.cc +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/public/common/speech_input_result.h" - -namespace content { - -SpeechInputResult::SpeechInputResult() - : error(SPEECH_INPUT_ERROR_NONE) { -} - -SpeechInputResult::~SpeechInputResult() { -} - -} // namespace content diff --git a/content/public/common/speech_input_result.h b/content/public/common/speech_input_result.h deleted file mode 100644 index 1e494c7..0000000 --- a/content/public/common/speech_input_result.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_PUBLIC_COMMON_SPEECH_INPUT_RESULT_H_ -#define CONTENT_PUBLIC_COMMON_SPEECH_INPUT_RESULT_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/string16.h" -#include "content/common/content_export.h" - -namespace content { - -struct SpeechInputHypothesis { - string16 utterance; - double confidence; - - SpeechInputHypothesis() : confidence(0.0) {} - - SpeechInputHypothesis(const string16 utterance_value, double confidence_value) - : utterance(utterance_value), - confidence(confidence_value) { - } -}; - -typedef std::vector<SpeechInputHypothesis> SpeechInputHypothesisArray; - -// This enumeration follows the values described here: -// http://www.w3.org/2005/Incubator/htmlspeech/2010/10/google-api-draft.html#speech-input-error -enum SpeechInputError { - // There was no error. - SPEECH_INPUT_ERROR_NONE = 0, - // The user or a script aborted speech input. - SPEECH_INPUT_ERROR_ABORTED, - // There was an error with recording audio. - SPEECH_INPUT_ERROR_AUDIO, - // There was a network error. - SPEECH_INPUT_ERROR_NETWORK, - // No speech heard before timeout. - SPEECH_INPUT_ERROR_NO_SPEECH, - // Speech was heard, but could not be interpreted. - SPEECH_INPUT_ERROR_NO_MATCH, - // There was an error in the speech recognition grammar. - SPEECH_INPUT_ERROR_BAD_GRAMMAR, -}; - -struct CONTENT_EXPORT SpeechInputResult { - SpeechInputError error; - SpeechInputHypothesisArray hypotheses; - - SpeechInputResult(); - ~SpeechInputResult(); -}; - -} // namespace content - -#endif // CONTENT_PUBLIC_COMMON_SPEECH_INPUT_RESULT_H_ diff --git a/content/public/common/speech_recognition_result.cc b/content/public/common/speech_recognition_result.cc new file mode 100644 index 0000000..198b88e --- /dev/null +++ b/content/public/common/speech_recognition_result.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/common/speech_recognition_result.h" + +namespace content { + +SpeechRecognitionResult::SpeechRecognitionResult() + : error(SPEECH_RECOGNITION_ERROR_NONE) { +} + +SpeechRecognitionResult::~SpeechRecognitionResult() { +} + +} diff --git a/content/public/common/speech_recognition_result.h b/content/public/common/speech_recognition_result.h new file mode 100644 index 0000000..e5efe5b --- /dev/null +++ b/content/public/common/speech_recognition_result.h @@ -0,0 +1,61 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_COMMON_SPEECH_RECOGNITION_RESULT_H_ +#define CONTENT_PUBLIC_COMMON_SPEECH_RECOGNITION_RESULT_H_ + +#include <vector> + +#include "base/basictypes.h" +#include "base/string16.h" +#include "content/common/content_export.h" + +namespace content { + +struct SpeechRecognitionHypothesis { + string16 utterance; + double confidence; + + SpeechRecognitionHypothesis() : confidence(0.0) {} + + SpeechRecognitionHypothesis(const string16 utterance_value, + double confidence_value) + : utterance(utterance_value), + confidence(confidence_value) { + } +}; + +typedef std::vector<SpeechRecognitionHypothesis> + SpeechRecognitionHypothesisArray; + +// This enumeration follows the values described here: +// http://www.w3.org/2005/Incubator/htmlspeech/2010/10/google-api-draft.html#speech-input-error +enum SpeechRecognitionErrorCode { + // There was no error. + SPEECH_RECOGNITION_ERROR_NONE = 0, + // The user or a script aborted speech input. + SPEECH_RECOGNITION_ERROR_ABORTED, + // There was an error with recording audio. + SPEECH_RECOGNITION_ERROR_AUDIO, + // There was a network error. + SPEECH_RECOGNITION_ERROR_NETWORK, + // No speech heard before timeout. + SPEECH_RECOGNITION_ERROR_NO_SPEECH, + // Speech was heard, but could not be interpreted. + SPEECH_RECOGNITION_ERROR_NO_MATCH, + // There was an error in the speech recognition grammar. + SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR, +}; + +struct CONTENT_EXPORT SpeechRecognitionResult { + SpeechRecognitionErrorCode error; + SpeechRecognitionHypothesisArray hypotheses; + + SpeechRecognitionResult(); + ~SpeechRecognitionResult(); +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_COMMON_SPEECH_RECOGNITION_RESULT_H_ diff --git a/content/renderer/speech_input_dispatcher.cc b/content/renderer/input_tag_speech_dispatcher.cc index 8ffc69e..7aa6d9f 100644 --- a/content/renderer/speech_input_dispatcher.cc +++ b/content/renderer/input_tag_speech_dispatcher.cc @@ -1,11 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/speech_input_dispatcher.h" +#include "content/renderer/input_tag_speech_dispatcher.h" #include "base/utf_string_conversions.h" -#include "content/common/speech_input_messages.h" +#include "content/common/speech_recognition_messages.h" #include "content/renderer/render_view_impl.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" @@ -25,38 +25,39 @@ using WebKit::WebInputElement; using WebKit::WebNode; using WebKit::WebView; -SpeechInputDispatcher::SpeechInputDispatcher( +InputTagSpeechDispatcher::InputTagSpeechDispatcher( RenderViewImpl* render_view, WebKit::WebSpeechInputListener* listener) : content::RenderViewObserver(render_view), listener_(listener) { } -bool SpeechInputDispatcher::OnMessageReceived(const IPC::Message& message) { +bool InputTagSpeechDispatcher::OnMessageReceived( + const IPC::Message& message) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP(SpeechInputDispatcher, message) - IPC_MESSAGE_HANDLER(SpeechInputMsg_SetRecognitionResult, + IPC_BEGIN_MESSAGE_MAP(InputTagSpeechDispatcher, message) + IPC_MESSAGE_HANDLER(InputTagSpeechMsg_SetRecognitionResult, OnSpeechRecognitionResult) - IPC_MESSAGE_HANDLER(SpeechInputMsg_RecordingComplete, + IPC_MESSAGE_HANDLER(InputTagSpeechMsg_RecordingComplete, OnSpeechRecordingComplete) - IPC_MESSAGE_HANDLER(SpeechInputMsg_RecognitionComplete, + IPC_MESSAGE_HANDLER(InputTagSpeechMsg_RecognitionComplete, OnSpeechRecognitionComplete) - IPC_MESSAGE_HANDLER(SpeechInputMsg_ToggleSpeechInput, + IPC_MESSAGE_HANDLER(InputTagSpeechMsg_ToggleSpeechInput, OnSpeechRecognitionToggleSpeechInput) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; } -bool SpeechInputDispatcher::startRecognition( +bool InputTagSpeechDispatcher::startRecognition( int request_id, const WebKit::WebRect& element_rect, const WebKit::WebString& language, const WebKit::WebString& grammar, const WebKit::WebSecurityOrigin& origin) { - VLOG(1) << "SpeechInputDispatcher::startRecognition enter"; + VLOG(1) << "InputTagSpeechDispatcher::startRecognition enter"; - SpeechInputHostMsg_StartRecognition_Params params; + InputTagSpeechHostMsg_StartRecognition_Params params; params.grammar = UTF16ToUTF8(grammar); params.language = UTF16ToUTF8(language); params.origin_url = UTF16ToUTF8(origin.toString()); @@ -66,50 +67,51 @@ bool SpeechInputDispatcher::startRecognition( params.element_rect = element_rect; params.element_rect.Offset(-scroll.width(), -scroll.height()); - Send(new SpeechInputHostMsg_StartRecognition(params)); - VLOG(1) << "SpeechInputDispatcher::startRecognition exit"; + Send(new InputTagSpeechHostMsg_StartRecognition(params)); + VLOG(1) << "InputTagSpeechDispatcher::startRecognition exit"; return true; } -void SpeechInputDispatcher::cancelRecognition(int request_id) { - VLOG(1) << "SpeechInputDispatcher::cancelRecognition enter"; - Send(new SpeechInputHostMsg_CancelRecognition(routing_id(), request_id)); - VLOG(1) << "SpeechInputDispatcher::cancelRecognition exit"; +void InputTagSpeechDispatcher::cancelRecognition(int request_id) { + VLOG(1) << "InputTagSpeechDispatcher::cancelRecognition enter"; + Send(new InputTagSpeechHostMsg_CancelRecognition(routing_id(), request_id)); + VLOG(1) << "InputTagSpeechDispatcher::cancelRecognition exit"; } -void SpeechInputDispatcher::stopRecording(int request_id) { - VLOG(1) << "SpeechInputDispatcher::stopRecording enter"; - Send(new SpeechInputHostMsg_StopRecording(routing_id(), request_id)); - VLOG(1) << "SpeechInputDispatcher::stopRecording exit"; +void InputTagSpeechDispatcher::stopRecording(int request_id) { + VLOG(1) << "InputTagSpeechDispatcher::stopRecording enter"; + Send(new InputTagSpeechHostMsg_StopRecording(routing_id(), + request_id)); + VLOG(1) << "InputTagSpeechDispatcher::stopRecording exit"; } -void SpeechInputDispatcher::OnSpeechRecognitionResult( +void InputTagSpeechDispatcher::OnSpeechRecognitionResult( int request_id, - const content::SpeechInputResult& result) { - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionResult enter"; + const content::SpeechRecognitionResult& result) { + VLOG(1) << "InputTagSpeechDispatcher::OnSpeechRecognitionResult enter"; WebKit::WebSpeechInputResultArray webkit_result(result.hypotheses.size()); for (size_t i = 0; i < result.hypotheses.size(); ++i) { webkit_result[i].assign(result.hypotheses[i].utterance, result.hypotheses[i].confidence); } listener_->setRecognitionResult(request_id, webkit_result); - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionResult exit"; + VLOG(1) << "InputTagSpeechDispatcher::OnSpeechRecognitionResult exit"; } -void SpeechInputDispatcher::OnSpeechRecordingComplete(int request_id) { - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecordingComplete enter"; +void InputTagSpeechDispatcher::OnSpeechRecordingComplete(int request_id) { + VLOG(1) << "InputTagSpeechDispatcher::OnSpeechRecordingComplete enter"; listener_->didCompleteRecording(request_id); - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecordingComplete exit"; + VLOG(1) << "InputTagSpeechDispatcher::OnSpeechRecordingComplete exit"; } -void SpeechInputDispatcher::OnSpeechRecognitionComplete(int request_id) { - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionComplete enter"; +void InputTagSpeechDispatcher::OnSpeechRecognitionComplete(int request_id) { + VLOG(1) << "InputTagSpeechDispatcher::OnSpeechRecognitionComplete enter"; listener_->didCompleteRecognition(request_id); - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionComplete exit"; + VLOG(1) << "InputTagSpeechDispatcher::OnSpeechRecognitionComplete exit"; } -void SpeechInputDispatcher::OnSpeechRecognitionToggleSpeechInput() { - VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionToggleSpeechInput"; +void InputTagSpeechDispatcher::OnSpeechRecognitionToggleSpeechInput() { + VLOG(1) <<"InputTagSpeechDispatcher::OnSpeechRecognitionToggleSpeechInput"; WebView* web_view = render_view()->GetWebView(); diff --git a/content/renderer/speech_input_dispatcher.h b/content/renderer/input_tag_speech_dispatcher.h index 174dd6a..dca92ab 100644 --- a/content/renderer/speech_input_dispatcher.h +++ b/content/renderer/input_tag_speech_dispatcher.h @@ -1,9 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_RENDERER_SPEECH_INPUT_DISPATCHER_H_ -#define CONTENT_RENDERER_SPEECH_INPUT_DISPATCHER_H_ +#ifndef CONTENT_RENDERER_INPUT_TAG_SPEECH_DISPATCHER_H_ +#define CONTENT_RENDERER_INPUT_TAG_SPEECH_DISPATCHER_H_ #include "base/basictypes.h" #include "content/public/renderer/render_view_observer.h" @@ -12,20 +12,20 @@ class RenderViewImpl; namespace content { -struct SpeechInputResult; +struct SpeechRecognitionResult; } namespace WebKit { class WebSpeechInputListener; } -// SpeechInputDispatcher is a delegate for speech input messages used by WebKit. -// It's the complement of SpeechInputDispatcherHost (owned by RenderViewHost). -class SpeechInputDispatcher : public content::RenderViewObserver, - public WebKit::WebSpeechInputController { +// InputTagSpeechDispatcher is a delegate for messages used by WebKit. It's +// the complement of InputTagSpeechDispatcherHost (owned by RenderViewHost). +class InputTagSpeechDispatcher : public content::RenderViewObserver, + public WebKit::WebSpeechInputController { public: - SpeechInputDispatcher(RenderViewImpl* render_view, - WebKit::WebSpeechInputListener* listener); + InputTagSpeechDispatcher(RenderViewImpl* render_view, + WebKit::WebSpeechInputListener* listener); private: // RenderView::Observer implementation. @@ -41,15 +41,15 @@ class SpeechInputDispatcher : public content::RenderViewObserver, virtual void cancelRecognition(int request_id); virtual void stopRecording(int request_id); - void OnSpeechRecognitionResult(int request_id, - const content::SpeechInputResult& result); + void OnSpeechRecognitionResult( + int request_id, const content::SpeechRecognitionResult& result); void OnSpeechRecordingComplete(int request_id); void OnSpeechRecognitionComplete(int request_id); void OnSpeechRecognitionToggleSpeechInput(); WebKit::WebSpeechInputListener* listener_; - DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcher); + DISALLOW_COPY_AND_ASSIGN(InputTagSpeechDispatcher); }; -#endif // CHROME_RENDERER_SPEECH_INPUT_DISPATCHER_H_ +#endif // CONTENT_RENDERER_INPUT_TAG_SPEECH_DISPATCHER_H_ diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 9f34b6c..fcd507d 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -56,6 +56,7 @@ #include "content/renderer/external_popup_menu.h" #include "content/renderer/geolocation_dispatcher.h" #include "content/renderer/idle_user_detector.h" +#include "content/renderer/input_tag_speech_dispatcher.h" #include "content/renderer/web_intents_host.h" #include "content/renderer/java/java_bridge_dispatcher.h" #include "content/renderer/load_progress_tracker.h" @@ -78,7 +79,6 @@ #include "content/renderer/renderer_accessibility.h" #include "content/renderer/renderer_webapplicationcachehost_impl.h" #include "content/renderer/renderer_webstoragenamespace_impl.h" -#include "content/renderer/speech_input_dispatcher.h" #include "content/renderer/text_input_client_observer.h" #include "content/renderer/v8_value_converter_impl.h" #include "content/renderer/web_ui_bindings.h" @@ -444,7 +444,7 @@ RenderViewImpl::RenderViewImpl( queried_for_swapbuffers_complete_callback_(false), ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), geolocation_dispatcher_(NULL), - speech_input_dispatcher_(NULL), + input_tag_speech_dispatcher_(NULL), device_orientation_dispatcher_(NULL), media_stream_dispatcher_(NULL), p2p_socket_dispatcher_(NULL), @@ -4910,10 +4910,11 @@ WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( WebKit::WebSpeechInputListener* listener) { #if defined(ENABLE_INPUT_SPEECH) - if (!speech_input_dispatcher_) - speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener); + if (!input_tag_speech_dispatcher_) + input_tag_speech_dispatcher_ = + new InputTagSpeechDispatcher(this, listener); #endif - return speech_input_dispatcher_; + return input_tag_speech_dispatcher_; } WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index a7c893b..b253f53 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -76,7 +76,7 @@ struct PP_NetAddress_Private; class RenderWidgetFullscreenPepper; class RendererAccessibility; class SkBitmap; -class SpeechInputDispatcher; +class InputTagSpeechDispatcher; struct ViewMsg_Navigate_Params; struct ViewMsg_StopFinding_Params; struct ViewMsg_SwapOut_Params; @@ -1179,7 +1179,7 @@ class RenderViewImpl : public RenderWidget, WebIntentsHost* intents_host_; // The speech dispatcher attached to this view, lazily initialized. - SpeechInputDispatcher* speech_input_dispatcher_; + InputTagSpeechDispatcher* input_tag_speech_dispatcher_; // Device orientation dispatcher attached to this view; lazily initialized. DeviceOrientationDispatcher* device_orientation_dispatcher_; diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index f617b23..4872dc6 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -13,7 +13,7 @@ #include "content/browser/download/download_manager_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/geolocation_permission_context.h" -#include "content/public/browser/speech_input_preferences.h" +#include "content/public/browser/speech_recognition_preferences.h" #include "content/shell/shell_browser_main.h" #include "content/shell/shell_download_manager_delegate.h" #include "content/shell/shell_resource_context.h" @@ -63,12 +63,12 @@ class ShellGeolocationPermissionContext : public GeolocationPermissionContext { DISALLOW_COPY_AND_ASSIGN(ShellGeolocationPermissionContext); }; -class ShellSpeechInputPreferences : public SpeechInputPreferences { +class ShellSpeechRecognitionPreferences : public SpeechRecognitionPreferences { public: - ShellSpeechInputPreferences() { + ShellSpeechRecognitionPreferences() { } - // Overridden from SpeechInputPreferences: + // Overridden from SpeechRecognitionPreferences: virtual bool FilterProfanities() const OVERRIDE { return false; } @@ -77,7 +77,7 @@ class ShellSpeechInputPreferences : public SpeechInputPreferences { } private: - DISALLOW_COPY_AND_ASSIGN(ShellSpeechInputPreferences); + DISALLOW_COPY_AND_ASSIGN(ShellSpeechRecognitionPreferences); }; } // namespace @@ -170,10 +170,11 @@ GeolocationPermissionContext* return geolocation_permission_context_; } -SpeechInputPreferences* ShellBrowserContext::GetSpeechInputPreferences() { - if (!speech_input_preferences_.get()) - speech_input_preferences_ = new ShellSpeechInputPreferences(); - return speech_input_preferences_.get(); +SpeechRecognitionPreferences* + ShellBrowserContext::GetSpeechRecognitionPreferences() { + if (!speech_recognition_preferences_.get()) + speech_recognition_preferences_ = new ShellSpeechRecognitionPreferences(); + return speech_recognition_preferences_.get(); } bool ShellBrowserContext::DidLastSessionExitCleanly() { diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index 9fbccab..581febb 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -37,7 +37,8 @@ class ShellBrowserContext : public BrowserContext { virtual ResourceContext* GetResourceContext() OVERRIDE; virtual GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; - virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; + virtual SpeechRecognitionPreferences* + GetSpeechRecognitionPreferences() OVERRIDE; virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; @@ -49,7 +50,7 @@ class ShellBrowserContext : public BrowserContext { scoped_refptr<DownloadManager> download_manager_; scoped_refptr<net::URLRequestContextGetter> url_request_getter_; scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; - scoped_refptr<SpeechInputPreferences> speech_input_preferences_; + scoped_refptr<SpeechRecognitionPreferences> speech_recognition_preferences_; ShellBrowserMainParts* shell_main_parts_; diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index d29b4ec..dfc7344 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -283,8 +283,8 @@ std::string ShellContentBrowserClient::GetWorkerProcessTitle( void ShellContentBrowserClient::ResourceDispatcherHostCreated() { } -SpeechInputManagerDelegate* - ShellContentBrowserClient::GetSpeechInputManagerDelegate() { +SpeechRecognitionManagerDelegate* + ShellContentBrowserClient::GetSpeechRecognitionManagerDelegate() { return NULL; } diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 08eaa71..5db7a3b 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -146,7 +146,8 @@ class ShellContentBrowserClient : public ContentBrowserClient { virtual std::string GetWorkerProcessTitle( const GURL& url, content::ResourceContext* context) OVERRIDE; virtual void ResourceDispatcherHostCreated() OVERRIDE; - virtual SpeechInputManagerDelegate* GetSpeechInputManagerDelegate() OVERRIDE; + virtual SpeechRecognitionManagerDelegate* + GetSpeechRecognitionManagerDelegate() OVERRIDE; virtual ui::Clipboard* GetClipboard() OVERRIDE; virtual net::NetLog* GetNetLog() OVERRIDE; virtual AccessTokenStore* CreateAccessTokenStore() OVERRIDE; diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc index 8510603..9943ac0 100644 --- a/content/test/test_browser_context.cc +++ b/content/test/test_browser_context.cc @@ -64,8 +64,8 @@ TestBrowserContext::GetGeolocationPermissionContext() { return NULL; } -content::SpeechInputPreferences* -TestBrowserContext::GetSpeechInputPreferences() { +content::SpeechRecognitionPreferences* +TestBrowserContext::GetSpeechRecognitionPreferences() { return NULL; } diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h index f522fa5..4002320 100644 --- a/content/test/test_browser_context.h +++ b/content/test/test_browser_context.h @@ -39,7 +39,8 @@ class TestBrowserContext : public content::BrowserContext { virtual content::ResourceContext* GetResourceContext() OVERRIDE; virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; - virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; + virtual content::SpeechRecognitionPreferences* + GetSpeechRecognitionPreferences() OVERRIDE; virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; |