Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / renderer / tts_dispatcher.h
blob8dea4c062f891a615205aafc4efe944e48793a7a
1 // Copyright (c) 2013 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 CHROME_RENDERER_TTS_DISPATCHER_H_
6 #define CHROME_RENDERER_TTS_DISPATCHER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h"
13 #include "content/public/renderer/render_process_observer.h"
14 #include "third_party/WebKit/public/platform/WebSpeechSynthesizer.h"
15 #include "third_party/WebKit/public/platform/WebSpeechSynthesizerClient.h"
17 namespace IPC {
18 class Message;
21 struct TtsVoice;
23 // TtsDispatcher is a delegate for methods used by Blink for speech synthesis
24 // APIs. It's the complement of TtsDispatcherHost (owned by RenderViewHost).
25 // Each TtsDispatcher is owned by the WebSpeechSynthesizerClient in Blink;
26 // it registers itself to listen to IPC upon construction and unregisters
27 // itself when deleted. There can be multiple TtsDispatchers alive at once,
28 // so each one routes IPC messages to its WebSpeechSynthesizerClient only if
29 // the utterance id (which is globally unique) matches.
30 class TtsDispatcher
31 : public blink::WebSpeechSynthesizer,
32 public content::RenderProcessObserver {
33 public:
34 explicit TtsDispatcher(blink::WebSpeechSynthesizerClient* client);
36 private:
37 ~TtsDispatcher() override;
39 // RenderProcessObserver override.
40 bool OnControlMessageReceived(const IPC::Message& message) override;
42 // blink::WebSpeechSynthesizer implementation.
43 void updateVoiceList() override;
44 void speak(const blink::WebSpeechSynthesisUtterance& utterance) override;
45 void pause() override;
46 void resume() override;
47 void cancel() override;
49 blink::WebSpeechSynthesisUtterance FindUtterance(int utterance_id);
51 void OnSetVoiceList(const std::vector<TtsVoice>& voices);
52 void OnDidStartSpeaking(int utterance_id);
53 void OnDidFinishSpeaking(int utterance_id);
54 void OnDidPauseSpeaking(int utterance_id);
55 void OnDidResumeSpeaking(int utterance_id);
56 void OnWordBoundary(int utterance_id, int char_index);
57 void OnSentenceBoundary(int utterance_id, int char_index);
58 void OnMarkerEvent(int utterance_id, int char_index);
59 void OnWasInterrupted(int utterance_id);
60 void OnWasCancelled(int utterance_id);
61 void OnSpeakingErrorOccurred(int utterance_id,
62 const std::string& error_message);
64 // The WebKit client class that we use to send events back to the JS world.
65 // Weak reference, this will be valid as long as this object exists.
66 blink::WebSpeechSynthesizerClient* synthesizer_client_;
68 // Next utterance id, used to map response IPCs to utterance objects.
69 static int next_utterance_id_;
71 // Map from id to utterance objects.
72 base::hash_map<int, blink::WebSpeechSynthesisUtterance> utterance_id_map_;
74 DISALLOW_COPY_AND_ASSIGN(TtsDispatcher);
77 #endif // CHROME_RENDERER_TTS_DISPATCHER_H_