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 "content/public/renderer/render_view_observer.h" | 11 #include "content/public/renderer/render_view_observer.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechRecognitionH
andle.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechRecognitionH
andle.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechRecognizer.h
" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechRecognizer.h
" |
15 | 15 |
| 16 namespace content { |
16 class RenderViewImpl; | 17 class RenderViewImpl; |
17 | |
18 namespace content { | |
19 struct SpeechRecognitionError; | 18 struct SpeechRecognitionError; |
20 struct SpeechRecognitionResult; | 19 struct SpeechRecognitionResult; |
21 } | |
22 | 20 |
23 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for | 21 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for |
24 // scripted JS speech APIs. It's the complement of | 22 // scripted JS speech APIs. It's the complement of |
25 // SpeechRecognitionDispatcherHost (owned by RenderViewHost). | 23 // SpeechRecognitionDispatcherHost (owned by RenderViewHost). |
26 class SpeechRecognitionDispatcher : public content::RenderViewObserver, | 24 class SpeechRecognitionDispatcher : public RenderViewObserver, |
27 public WebKit::WebSpeechRecognizer { | 25 public WebKit::WebSpeechRecognizer { |
28 public: | 26 public: |
29 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view); | 27 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view); |
30 virtual ~SpeechRecognitionDispatcher(); | 28 virtual ~SpeechRecognitionDispatcher(); |
31 | 29 |
32 private: | 30 private: |
33 // RenderViewObserver implementation. | 31 // RenderViewObserver implementation. |
34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 32 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
35 | 33 |
36 // WebKit::WebSpeechRecognizer implementation. | 34 // WebKit::WebSpeechRecognizer implementation. |
37 virtual void start(const WebKit::WebSpeechRecognitionHandle&, | 35 virtual void start(const WebKit::WebSpeechRecognitionHandle&, |
38 const WebKit::WebSpeechRecognitionParams&, | 36 const WebKit::WebSpeechRecognitionParams&, |
39 WebKit::WebSpeechRecognizerClient*) OVERRIDE; | 37 WebKit::WebSpeechRecognizerClient*) OVERRIDE; |
40 virtual void stop(const WebKit::WebSpeechRecognitionHandle&, | 38 virtual void stop(const WebKit::WebSpeechRecognitionHandle&, |
41 WebKit::WebSpeechRecognizerClient*) OVERRIDE; | 39 WebKit::WebSpeechRecognizerClient*) OVERRIDE; |
42 virtual void abort(const WebKit::WebSpeechRecognitionHandle&, | 40 virtual void abort(const WebKit::WebSpeechRecognitionHandle&, |
43 WebKit::WebSpeechRecognizerClient*) OVERRIDE; | 41 WebKit::WebSpeechRecognizerClient*) OVERRIDE; |
44 | 42 |
45 void OnRecognitionStarted(int request_id); | 43 void OnRecognitionStarted(int request_id); |
46 void OnAudioStarted(int request_id); | 44 void OnAudioStarted(int request_id); |
47 void OnSoundStarted(int request_id); | 45 void OnSoundStarted(int request_id); |
48 void OnSoundEnded(int request_id); | 46 void OnSoundEnded(int request_id); |
49 void OnAudioEnded(int request_id); | 47 void OnAudioEnded(int request_id); |
50 void OnErrorOccurred(int request_id, | 48 void OnErrorOccurred(int request_id, const SpeechRecognitionError& error); |
51 const content::SpeechRecognitionError& error); | |
52 void OnRecognitionEnded(int request_id); | 49 void OnRecognitionEnded(int request_id); |
53 void OnResultRetrieved(int request_id, | 50 void OnResultRetrieved(int request_id, const SpeechRecognitionResult& result); |
54 const content::SpeechRecognitionResult& result); | |
55 | 51 |
56 int GetOrCreateIDForHandle(const WebKit::WebSpeechRecognitionHandle& handle); | 52 int GetOrCreateIDForHandle(const WebKit::WebSpeechRecognitionHandle& handle); |
57 bool HandleExists(const WebKit::WebSpeechRecognitionHandle& handle); | 53 bool HandleExists(const WebKit::WebSpeechRecognitionHandle& handle); |
58 const WebKit::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id); | 54 const WebKit::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id); |
59 | 55 |
60 // The WebKit client class that we use to send events back to the JS world. | 56 // The WebKit client class that we use to send events back to the JS world. |
61 WebKit::WebSpeechRecognizerClient* recognizer_client_; | 57 WebKit::WebSpeechRecognizerClient* recognizer_client_; |
62 | 58 |
63 typedef std::map<int, WebKit::WebSpeechRecognitionHandle> HandleMap; | 59 typedef std::map<int, WebKit::WebSpeechRecognitionHandle> HandleMap; |
64 HandleMap handle_map_; | 60 HandleMap handle_map_; |
65 int next_id_; | 61 int next_id_; |
66 | 62 |
67 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher); | 63 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher); |
68 }; | 64 }; |
69 | 65 |
| 66 } // namespace content |
| 67 |
70 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 68 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
OLD | NEW |