Roll ANGLE bc75f36:ef9d63e
[chromium-blink-merge.git] / content / renderer / speech_recognition_dispatcher.h
blobbae0e5d92a484cbd706533010a8ffd28e3f9e5fa
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_
6 #define CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "content/public/common/speech_recognition_result.h"
12 #include "content/public/renderer/render_view_observer.h"
13 #include "third_party/WebKit/public/platform/WebVector.h"
14 #include "third_party/WebKit/public/web/WebSpeechRecognitionHandle.h"
15 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
17 namespace content {
18 class RenderViewImpl;
19 struct SpeechRecognitionError;
20 struct SpeechRecognitionResult;
22 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for
23 // scripted JS speech APIs. It's the complement of
24 // SpeechRecognitionDispatcherHost (owned by RenderViewHost).
25 class SpeechRecognitionDispatcher : public RenderViewObserver,
26 public blink::WebSpeechRecognizer {
27 public:
28 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view);
29 virtual ~SpeechRecognitionDispatcher();
31 // Aborts all speech recognitions.
32 void AbortAllRecognitions();
34 private:
35 // RenderViewObserver implementation.
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
38 // blink::WebSpeechRecognizer implementation.
39 virtual void start(const blink::WebSpeechRecognitionHandle&,
40 const blink::WebSpeechRecognitionParams&,
41 blink::WebSpeechRecognizerClient*) OVERRIDE;
42 virtual void stop(const blink::WebSpeechRecognitionHandle&,
43 blink::WebSpeechRecognizerClient*) OVERRIDE;
44 virtual void abort(const blink::WebSpeechRecognitionHandle&,
45 blink::WebSpeechRecognizerClient*) OVERRIDE;
47 void OnRecognitionStarted(int request_id);
48 void OnAudioStarted(int request_id);
49 void OnSoundStarted(int request_id);
50 void OnSoundEnded(int request_id);
51 void OnAudioEnded(int request_id);
52 void OnErrorOccurred(int request_id, const SpeechRecognitionError& error);
53 void OnRecognitionEnded(int request_id);
54 void OnResultsRetrieved(int request_id,
55 const SpeechRecognitionResults& result);
57 int GetOrCreateIDForHandle(const blink::WebSpeechRecognitionHandle& handle);
58 bool HandleExists(const blink::WebSpeechRecognitionHandle& handle);
59 const blink::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id);
61 // The WebKit client class that we use to send events back to the JS world.
62 blink::WebSpeechRecognizerClient* recognizer_client_;
64 typedef std::map<int, blink::WebSpeechRecognitionHandle> HandleMap;
65 HandleMap handle_map_;
66 int next_id_;
68 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher);
71 } // namespace content
73 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_