2014-10-07 13:18:44 +00:00
|
|
|
// Copyright (c) 2013 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 CHROME_RENDERER_TTS_DISPATCHER_H_
|
|
|
|
#define CHROME_RENDERER_TTS_DISPATCHER_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/containers/hash_tables.h"
|
2016-07-04 06:08:55 +00:00
|
|
|
#include "content/public/renderer/render_thread_observer.h"
|
2018-07-20 16:08:18 +00:00
|
|
|
#include "third_party/blink/public/platform/web_speech_synthesizer.h"
|
|
|
|
#include "third_party/blink/public/platform/web_speech_synthesizer_client.h"
|
2014-10-07 13:18:44 +00:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
class Message;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TtsVoice;
|
|
|
|
|
|
|
|
// TtsDispatcher is a delegate for methods used by Blink for speech synthesis
|
|
|
|
// APIs. It's the complement of TtsDispatcherHost (owned by RenderViewHost).
|
|
|
|
// Each TtsDispatcher is owned by the WebSpeechSynthesizerClient in Blink;
|
|
|
|
// it registers itself to listen to IPC upon construction and unregisters
|
|
|
|
// itself when deleted. There can be multiple TtsDispatchers alive at once,
|
|
|
|
// so each one routes IPC messages to its WebSpeechSynthesizerClient only if
|
|
|
|
// the utterance id (which is globally unique) matches.
|
2018-04-18 01:47:44 +00:00
|
|
|
class TtsDispatcher : public blink::WebSpeechSynthesizer,
|
|
|
|
public content::RenderThreadObserver {
|
2014-10-07 13:18:44 +00:00
|
|
|
public:
|
|
|
|
explicit TtsDispatcher(blink::WebSpeechSynthesizerClient* client);
|
2018-04-17 23:03:51 +00:00
|
|
|
~TtsDispatcher() override;
|
2014-10-07 13:18:44 +00:00
|
|
|
|
2017-08-04 17:41:34 +00:00
|
|
|
private:
|
2014-10-07 13:18:44 +00:00
|
|
|
// RenderProcessObserver override.
|
2018-04-17 23:03:51 +00:00
|
|
|
bool OnControlMessageReceived(const IPC::Message& message) override;
|
2014-10-07 13:18:44 +00:00
|
|
|
|
|
|
|
// blink::WebSpeechSynthesizer implementation.
|
2018-04-17 23:03:51 +00:00
|
|
|
void UpdateVoiceList() override;
|
2018-09-19 11:10:26 +00:00
|
|
|
void Speak(const blink::WebSpeechSynthesisUtterance& utterance) override;
|
2018-04-17 23:03:51 +00:00
|
|
|
void Pause() override;
|
|
|
|
void Resume() override;
|
|
|
|
void Cancel() override;
|
2014-10-07 13:18:44 +00:00
|
|
|
|
|
|
|
blink::WebSpeechSynthesisUtterance FindUtterance(int utterance_id);
|
|
|
|
|
|
|
|
void OnSetVoiceList(const std::vector<TtsVoice>& voices);
|
|
|
|
void OnDidStartSpeaking(int utterance_id);
|
|
|
|
void OnDidFinishSpeaking(int utterance_id);
|
|
|
|
void OnDidPauseSpeaking(int utterance_id);
|
|
|
|
void OnDidResumeSpeaking(int utterance_id);
|
|
|
|
void OnWordBoundary(int utterance_id, int char_index);
|
|
|
|
void OnSentenceBoundary(int utterance_id, int char_index);
|
|
|
|
void OnMarkerEvent(int utterance_id, int char_index);
|
|
|
|
void OnWasInterrupted(int utterance_id);
|
|
|
|
void OnWasCancelled(int utterance_id);
|
|
|
|
void OnSpeakingErrorOccurred(int utterance_id,
|
|
|
|
const std::string& error_message);
|
|
|
|
|
|
|
|
// The WebKit client class that we use to send events back to the JS world.
|
|
|
|
// Weak reference, this will be valid as long as this object exists.
|
|
|
|
blink::WebSpeechSynthesizerClient* synthesizer_client_;
|
|
|
|
|
|
|
|
// Next utterance id, used to map response IPCs to utterance objects.
|
|
|
|
static int next_utterance_id_;
|
|
|
|
|
|
|
|
// Map from id to utterance objects.
|
|
|
|
base::hash_map<int, blink::WebSpeechSynthesisUtterance> utterance_id_map_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TtsDispatcher);
|
|
|
|
};
|
|
|
|
|
2016-03-08 14:28:53 +00:00
|
|
|
#endif // CHROME_RENDERER_TTS_DISPATCHER_H_
|