Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
| 6 #define CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/shared_memory.h" | |
| 12 #include "base/message_loop/message_loop_proxy.h" | |
| 13 #include "base/native_sync_socket.h" | |
| 11 #include "content/public/common/speech_recognition_result.h" | 14 #include "content/public/common/speech_recognition_result.h" |
| 12 #include "content/public/renderer/render_view_observer.h" | 15 #include "content/public/renderer/render_view_observer.h" |
| 16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 13 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
| 14 #include "third_party/WebKit/public/web/WebSpeechRecognitionHandle.h" | 18 #include "third_party/WebKit/public/web/WebSpeechRecognitionHandle.h" |
| 15 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" | 19 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" |
| 16 | 20 |
| 21 namespace media { | |
| 22 class AudioParameters; | |
| 23 } | |
| 24 | |
| 17 namespace content { | 25 namespace content { |
| 18 class RenderViewImpl; | 26 class RenderViewImpl; |
| 27 class SpeechRecognitionAudioSourceProvider; | |
| 19 struct SpeechRecognitionError; | 28 struct SpeechRecognitionError; |
| 20 struct SpeechRecognitionResult; | 29 struct SpeechRecognitionResult; |
| 21 | 30 |
| 22 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for | 31 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for |
| 23 // scripted JS speech APIs. It's the complement of | 32 // scripted JS speech APIs. It's the complement of |
| 24 // SpeechRecognitionDispatcherHost (owned by RenderViewHost). | 33 // SpeechRecognitionDispatcherHost (owned by RenderViewHost). |
| 25 class SpeechRecognitionDispatcher : public RenderViewObserver, | 34 class SpeechRecognitionDispatcher : public RenderViewObserver, |
| 26 public blink::WebSpeechRecognizer { | 35 public blink::WebSpeechRecognizer { |
| 27 public: | 36 public: |
| 28 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view); | 37 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view); |
| 29 virtual ~SpeechRecognitionDispatcher(); | 38 virtual ~SpeechRecognitionDispatcher(); |
| 30 | 39 |
| 31 // Aborts all speech recognitions. | 40 // Aborts all speech recognitions. |
| 32 void AbortAllRecognitions(); | 41 void AbortAllRecognitions(); |
| 33 | 42 |
| 34 private: | 43 private: |
| 35 // RenderViewObserver implementation. | 44 // RenderViewObserver implementation. |
| 36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 37 | 46 |
| 38 // blink::WebSpeechRecognizer implementation. | 47 // blink::WebSpeechRecognizer implementation. |
| 48 virtual void attach(const blink::WebSpeechRecognitionHandle&, | |
| 49 const blink::WebMediaStreamTrack&, | |
|
tommi (sloooow) - chröme
2014/08/29 11:25:31
fix indent here and below
burnik
2014/08/29 13:26:18
Done.
| |
| 50 blink::WebSpeechRecognizerClient*) OVERRIDE; | |
| 51 virtual void detach(const blink::WebSpeechRecognitionHandle&, | |
| 52 blink::WebSpeechRecognizerClient*) OVERRIDE; | |
| 39 virtual void start(const blink::WebSpeechRecognitionHandle&, | 53 virtual void start(const blink::WebSpeechRecognitionHandle&, |
| 40 const blink::WebSpeechRecognitionParams&, | 54 const blink::WebSpeechRecognitionParams&, |
| 41 blink::WebSpeechRecognizerClient*) OVERRIDE; | 55 blink::WebSpeechRecognizerClient*) OVERRIDE; |
| 42 virtual void stop(const blink::WebSpeechRecognitionHandle&, | 56 virtual void stop(const blink::WebSpeechRecognitionHandle&, |
| 43 blink::WebSpeechRecognizerClient*) OVERRIDE; | 57 blink::WebSpeechRecognizerClient*) OVERRIDE; |
| 44 virtual void abort(const blink::WebSpeechRecognitionHandle&, | 58 virtual void abort(const blink::WebSpeechRecognitionHandle&, |
| 45 blink::WebSpeechRecognizerClient*) OVERRIDE; | 59 blink::WebSpeechRecognizerClient*) OVERRIDE; |
| 46 | 60 |
| 47 void OnRecognitionStarted(int request_id); | 61 void OnRecognitionStarted(int request_id); |
| 48 void OnAudioStarted(int request_id); | 62 void OnAudioStarted(int request_id); |
| 49 void OnSoundStarted(int request_id); | 63 void OnSoundStarted(int request_id); |
| 50 void OnSoundEnded(int request_id); | 64 void OnSoundEnded(int request_id); |
| 51 void OnAudioEnded(int request_id); | 65 void OnAudioEnded(int request_id); |
| 52 void OnErrorOccurred(int request_id, const SpeechRecognitionError& error); | 66 void OnErrorOccurred(int request_id, const SpeechRecognitionError& error); |
| 53 void OnRecognitionEnded(int request_id); | 67 void OnRecognitionEnded(int request_id); |
| 54 void OnResultsRetrieved(int request_id, | 68 void OnResultsRetrieved(int request_id, |
| 55 const SpeechRecognitionResults& result); | 69 const SpeechRecognitionResults& result); |
| 70 void OnAudioTrackReady(int session_id, | |
| 71 const media::AudioParameters& params, | |
| 72 base::SharedMemoryHandle handle, | |
| 73 base::NativeSyncSocket::Descriptor socket, | |
| 74 uint32 length); | |
| 56 | 75 |
| 57 int GetOrCreateIDForHandle(const blink::WebSpeechRecognitionHandle& handle); | 76 int GetOrCreateIDForHandle(const blink::WebSpeechRecognitionHandle& handle); |
| 58 bool HandleExists(const blink::WebSpeechRecognitionHandle& handle); | 77 bool HandleExists(const blink::WebSpeechRecognitionHandle& handle); |
| 59 const blink::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id); | 78 const blink::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id); |
| 60 | 79 |
| 61 // The WebKit client class that we use to send events back to the JS world. | 80 // The WebKit client class that we use to send events back to the JS world. |
| 62 blink::WebSpeechRecognizerClient* recognizer_client_; | 81 blink::WebSpeechRecognizerClient* recognizer_client_; |
| 63 | 82 |
| 83 // Media stream audio track that the speech recognition connects to. | |
| 84 // Accessed on the render thread. | |
| 85 blink::WebMediaStreamTrack audio_track_; | |
| 86 | |
| 87 bool audio_track_set_; | |
| 88 | |
| 89 // Used by policy on which audio sources are allowed. | |
| 90 bool is_allowed_audio_track_; | |
| 91 | |
| 92 // Audio sink used to provide audio from the track. | |
| 93 scoped_ptr<SpeechRecognitionAudioSourceProvider> audio_source_provider_; | |
| 94 | |
| 95 // For sending messages back to browser process. | |
| 96 scoped_refptr<base::MessageLoopProxy> render_loop_; | |
|
no longer working on chromium
2014/08/29 12:23:07
why do you need this?
burnik
2014/08/29 13:26:18
Don't need it anymore.
On 2014/08/29 12:23:07, xia
| |
| 97 | |
| 64 typedef std::map<int, blink::WebSpeechRecognitionHandle> HandleMap; | 98 typedef std::map<int, blink::WebSpeechRecognitionHandle> HandleMap; |
| 65 HandleMap handle_map_; | 99 HandleMap handle_map_; |
| 66 int next_id_; | 100 int next_id_; |
| 67 | 101 |
| 68 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher); | 102 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher); |
| 69 }; | 103 }; |
| 70 | 104 |
| 71 } // namespace content | 105 } // namespace content |
| 72 | 106 |
| 73 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 107 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
| OLD | NEW |