Commit 4713ee49 authored by Katie D's avatar Katie D Committed by Commit Bot

Refactors TtsPlatform and most platform implementations to content.

In Chrome OS and Android, the TTS platform implementation needs to
stay in chrome.

Bug: 517317
Change-Id: I09858ce1edc412dd5d0d53abc3fab645fece6a8a
Reviewed-on: https://chromium-review.googlesource.com/c/1352055Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612493}
parent c3f90d6f
......@@ -1472,17 +1472,10 @@ jumbo_split_static_library("browser") {
"speech/speech_recognizer_delegate.h",
"speech/tts_android.cc",
"speech/tts_android.h",
"speech/tts_chromeos.cc",
"speech/tts_controller.h",
"speech/tts_controller_delegate_impl.cc",
"speech/tts_controller_delegate_impl.h",
"speech/tts_mac.mm",
"speech/tts_message_filter.cc",
"speech/tts_message_filter.h",
"speech/tts_platform.h",
"speech/tts_platform_impl.cc",
"speech/tts_platform_impl.h",
"speech/tts_win.cc",
"ssl/bad_clock_blocking_page.cc",
"ssl/bad_clock_blocking_page.h",
"ssl/captive_portal_blocking_page.cc",
......@@ -3177,6 +3170,7 @@ jumbo_split_static_library("browser") {
"signin/signin_error_notifier_ash.h",
"signin/signin_error_notifier_factory_ash.cc",
"signin/signin_error_notifier_factory_ash.h",
"speech/tts_chromeos.cc",
"sync/sync_error_notifier_ash.cc",
"sync/sync_error_notifier_ash.h",
"sync/sync_error_notifier_factory_ash.cc",
......@@ -3400,11 +3394,8 @@ jumbo_split_static_library("browser") {
"platform_util_linux.cc",
"shell_integration_linux.cc",
"shell_integration_linux.h",
"speech/tts_linux.cc",
]
deps += [ "//third_party/speech-dispatcher" ]
if (enable_native_notifications) {
sources += [
"notifications/notification_platform_bridge_linux.cc",
......
......@@ -261,6 +261,7 @@
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/browser/tts_platform.h"
#include "content/public/browser/url_loader_request_interceptor.h"
#include "content/public/browser/vpn_service_proxy.h"
#include "content/public/browser/web_contents.h"
......@@ -355,6 +356,7 @@
#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "chrome/browser/speech/tts_chromeos.cc"
#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/browser/ui/browser_dialogs.h"
......@@ -382,6 +384,7 @@
#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
#include "chrome/browser/chrome_browser_main_android.h"
#include "chrome/browser/offline_pages/offline_page_auto_fetcher.h"
#include "chrome/browser/speech/tts_android.h"
#include "chrome/common/descriptors_android.h"
#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
#include "components/crash/content/browser/child_exit_observer_android.h"
......@@ -2997,6 +3000,16 @@ ChromeContentBrowserClient::GetTtsControllerDelegate() {
return delegate;
}
content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
#ifdef OS_CHROMEOS
return TtsPlatformImplChromeOs::GetInstance();
#elif defined OS_ANDROID
return TtsPlatformImplAndroid::GetInstance();
#else
return nullptr;
#endif
}
net::NetLog* ChromeContentBrowserClient::GetNetLog() {
return g_browser_process->net_log();
}
......
......@@ -316,6 +316,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
content::SpeechRecognitionManagerDelegate*
CreateSpeechRecognitionManagerDelegate() override;
content::TtsControllerDelegate* GetTtsControllerDelegate() override;
content::TtsPlatform* GetTtsPlatform() override;
net::NetLog* GetNetLog() override;
void OverrideWebkitPrefs(content::RenderViewHost* rvh,
content::WebPreferences* prefs) override;
......
......@@ -21,7 +21,7 @@ SpeechMonitor::SpeechMonitor() {
SpeechMonitor::~SpeechMonitor() {
TtsControllerDelegateImpl::GetInstance()->SetTtsPlatform(
TtsPlatform::GetInstance());
content::TtsPlatform::GetInstance());
}
std::string SpeechMonitor::GetNextUtterance() {
......
......@@ -8,7 +8,7 @@
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/speech/tts_platform.h"
#include "content/public/browser/tts_platform.h"
#include "content/public/test/test_utils.h"
// TODO(katie): This may need to move into Content as part of the TTS refactor.
......@@ -18,7 +18,7 @@ namespace chromeos {
// For testing purpose installs itself as the platform speech synthesis engine,
// allowing it to intercept all speech calls, and then provides a method to
// block until the next utterance is spoken.
class SpeechMonitor : public TtsPlatform {
class SpeechMonitor : public content::TtsPlatform {
public:
SpeechMonitor();
virtual ~SpeechMonitor();
......
......@@ -25,7 +25,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/api/automation_internal/automation_event_router.h"
#include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
#include "chrome/browser/speech/tts_platform.h"
#include "chrome/browser/ui/ash/ksv/keyboard_shortcut_viewer_util.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "chrome/browser/ui/browser.h"
......
......@@ -58,7 +58,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/speech/tts_controller_delegate_impl.h"
#include "chrome/browser/speech/tts_platform.h"
#include "chrome/browser/task_manager/mock_web_contents_task_manager.h"
#include "chrome/browser/task_manager/providers/web_contents/web_contents_tags_manager.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
......@@ -101,6 +100,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/browser/tts_platform.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/content_switches.h"
......@@ -3466,7 +3466,7 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
// When instantiated, mocks out the global text-to-speech engine with something
// that emulates speaking any phrase for the duration of 0ms.
class TtsPlatformMock : public TtsPlatform {
class TtsPlatformMock : public content::TtsPlatform {
public:
TtsPlatformMock() : speaking_requested_(false) {
TtsControllerDelegateImpl::GetInstance()->SetTtsPlatform(this);
......
......@@ -17,10 +17,10 @@
#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
#include "chrome/browser/speech/extension_api/tts_extension_api.h"
#include "chrome/browser/speech/tts_controller_delegate_impl.h"
#include "chrome/browser/speech/tts_platform.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/browser/tts_platform.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
......@@ -48,7 +48,7 @@ int g_saved_utterance_id;
namespace extensions {
class MockTtsPlatformImpl : public TtsPlatform {
class MockTtsPlatformImpl : public content::TtsPlatform {
public:
MockTtsPlatformImpl()
: should_fake_get_voices_(false),
......
......@@ -16,13 +16,7 @@
using base::android::AttachCurrentThread;
using base::android::JavaParamRef;
// static
TtsPlatform* TtsPlatform::GetInstance() {
return TtsPlatformImplAndroid::GetInstance();
}
TtsPlatformImplAndroid::TtsPlatformImplAndroid()
: utterance_id_(0) {
TtsPlatformImplAndroid::TtsPlatformImplAndroid() : utterance_id_(0) {
JNIEnv* env = AttachCurrentThread();
java_ref_.Reset(
Java_TtsPlatformImpl_create(env, reinterpret_cast<intptr_t>(this)));
......@@ -69,8 +63,7 @@ void TtsPlatformImplAndroid::Pause() {
StopSpeaking();
}
void TtsPlatformImplAndroid::Resume() {
}
void TtsPlatformImplAndroid::Resume() {}
bool TtsPlatformImplAndroid::IsSpeaking() {
return (utterance_id_ != 0);
......@@ -97,6 +90,27 @@ void TtsPlatformImplAndroid::GetVoices(
}
}
bool TtsPlatformImplAndroid::LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) {
return false;
}
void TtsPlatformImplAndroid::WillSpeakUtteranceWithVoice(
const content::Utterance* utterance,
const content::VoiceData& voice_data) {}
std::string TtsPlatformImplAndroid::GetError() {
return error_;
}
void TtsPlatformImplAndroid::ClearError() {
error_ = std::string();
}
void TtsPlatformImplAndroid::SetError(const std::string& error) {
error_ = error;
}
void TtsPlatformImplAndroid::VoicesChanged(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
content::TtsController::GetInstance()->VoicesChanged();
......
......@@ -7,12 +7,11 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/speech/tts_platform_impl.h"
#include "content/public/browser/tts_platform.h"
// TODO(katie): Move to content/browser/speech.
class TtsPlatformImplAndroid : public TtsPlatformImpl {
class TtsPlatformImplAndroid : public content::TtsPlatform {
public:
// TtsPlatformImpl implementation.
// TtsPlatform overrides.
bool PlatformImplAvailable() override;
bool Speak(int utterance_id,
const std::string& utterance,
......@@ -24,6 +23,14 @@ class TtsPlatformImplAndroid : public TtsPlatformImpl {
void Resume() override;
bool IsSpeaking() override;
void GetVoices(std::vector<content::VoiceData>* out_voices) override;
bool LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) override;
void WillSpeakUtteranceWithVoice(
const content::Utterance* utterance,
const content::VoiceData& voice_data) override;
std::string GetError() override;
void ClearError() override;
void SetError(const std::string& error) override;
// Methods called from Java via JNI.
void VoicesChanged(JNIEnv* env,
......@@ -45,12 +52,13 @@ class TtsPlatformImplAndroid : public TtsPlatformImpl {
friend struct base::DefaultSingletonTraits<TtsPlatformImplAndroid>;
TtsPlatformImplAndroid();
~TtsPlatformImplAndroid() override;
virtual ~TtsPlatformImplAndroid();
void SendFinalTtsEvent(int utterance_id,
content::TtsEventType event_type,
int char_index);
std::string error_;
base::android::ScopedJavaGlobalRef<jobject> java_ref_;
int utterance_id_;
std::string utterance_;
......
......@@ -3,15 +3,15 @@
// found in the LICENSE file.
#include "base/macros.h"
#include "chrome/browser/speech/tts_platform.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/common/tts.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/tts_platform.h"
// This class includes extension-based tts through LoadBuiltInTtsExtension and
// native tts through ARC.
class TtsPlatformImplChromeOs : public TtsPlatform {
class TtsPlatformImplChromeOs : public content::TtsPlatform {
public:
// TtsPlatform overrides:
bool PlatformImplAvailable() override {
......@@ -104,11 +104,6 @@ class TtsPlatformImplChromeOs : public TtsPlatform {
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs);
};
// static
TtsPlatform* TtsPlatform::GetInstance() {
return TtsPlatformImplChromeOs::GetInstance();
}
// static
TtsPlatformImplChromeOs*
TtsPlatformImplChromeOs::GetInstance() {
......
......@@ -302,7 +302,7 @@ void TtsControllerDelegateImpl::OnTtsEvent(int utterance_id,
void TtsControllerDelegateImpl::GetVoices(
content::BrowserContext* browser_context,
std::vector<content::VoiceData>* out_voices) {
TtsPlatform* tts_platform = GetTtsPlatform();
content::TtsPlatform* tts_platform = GetTtsPlatform();
if (tts_platform) {
// Ensure we have all built-in voices loaded. This is a no-op if already
// loaded.
......@@ -355,7 +355,8 @@ void TtsControllerDelegateImpl::ClearUtteranceQueue(bool send_events) {
}
}
void TtsControllerDelegateImpl::SetTtsPlatform(TtsPlatform* tts_platform) {
void TtsControllerDelegateImpl::SetTtsPlatform(
content::TtsPlatform* tts_platform) {
tts_platform_ = tts_platform;
}
......@@ -363,9 +364,9 @@ int TtsControllerDelegateImpl::QueueSize() {
return static_cast<int>(utterance_queue_.size());
}
TtsPlatform* TtsControllerDelegateImpl::GetTtsPlatform() {
content::TtsPlatform* TtsControllerDelegateImpl::GetTtsPlatform() {
if (!tts_platform_)
tts_platform_ = TtsPlatform::GetInstance();
tts_platform_ = content::TtsPlatform::GetInstance();
return tts_platform_;
}
......
......@@ -14,9 +14,9 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "chrome/browser/speech/tts_platform.h"
#include "components/prefs/testing_pref_service.h"
#include "content/public/browser/tts_controller_delegate.h"
#include "content/public/browser/tts_platform.h"
#include "url/gurl.h"
// Singleton class that manages text-to-speech for the TTS and TTS engine
......@@ -49,7 +49,7 @@ class TtsControllerDelegateImpl : public content::TtsControllerDelegate {
void SetTtsEngineDelegate(content::TtsEngineDelegate* delegate) override;
content::TtsEngineDelegate* GetTtsEngineDelegate() override;
void SetTtsPlatform(TtsPlatform* tts_platform);
void SetTtsPlatform(content::TtsPlatform* tts_platform);
int QueueSize();
protected:
......@@ -63,7 +63,7 @@ class TtsControllerDelegateImpl : public content::TtsControllerDelegate {
TestTtsControllerUtteranceDefaults);
// Get the platform TTS implementation (or injected mock).
TtsPlatform* GetTtsPlatform();
content::TtsPlatform* GetTtsPlatform();
// Start speaking the given utterance. Will either take ownership of
// |utterance| or delete it if there's an error. Returns true on success.
......@@ -108,7 +108,7 @@ class TtsControllerDelegateImpl : public content::TtsControllerDelegate {
// A pointer to the platform implementation of text-to-speech, for
// dependency injection.
TtsPlatform* tts_platform_;
content::TtsPlatform* tts_platform_;
// The delegate that processes TTS requests with user-installed extensions.
content::TtsEngineDelegate* tts_engine_delegate_;
......
......@@ -8,10 +8,10 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/speech/tts_controller_delegate_impl.h"
#include "chrome/browser/speech/tts_platform.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "content/public/browser/tts_platform.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
......@@ -19,7 +19,7 @@ class TtsControllerTest : public testing::Test {
};
// Platform Tts implementation that does nothing.
class DummyTtsPlatformImpl : public TtsPlatform {
class DummyTtsPlatformImpl : public content::TtsPlatform {
public:
DummyTtsPlatformImpl() {}
virtual ~DummyTtsPlatformImpl() {}
......
......@@ -5792,30 +5792,6 @@ if (!is_android && !is_fuchsia) {
}
if (is_win) {
# Note: this compiles and runs on Mac but may cause
# system instability; if you try it out, close other
# programs and then reboot afterwards. It should be
# possible to make it work on Linux if you use the
# --enable-speech-dispatcher flag.
fuzzer_test("tts_platform_fuzzer") {
sources = [
"../browser/speech/mock_tts_controller.cc",
"../browser/speech/tts_mac.mm",
"../browser/speech/tts_platform.h",
"../browser/speech/tts_platform_fuzzer.cc",
"../browser/speech/tts_platform_impl.cc",
"../browser/speech/tts_platform_impl.h",
"../browser/speech/tts_win.cc",
"../content/public/browser/tts_controller.h",
]
deps = [
"//base",
"//base/test:test_support",
"//ui/base",
]
}
fuzzer_test("safe_browsing_binary_feature_extractor_fuzzer") {
sources = [
"../common/safe_browsing/binary_feature_extractor.cc",
......
......@@ -1703,6 +1703,10 @@ jumbo_source_set("browser") {
"speech/speech_recognizer_impl_android.h",
"speech/tts_controller_impl.cc",
"speech/tts_controller_impl.h",
"speech/tts_mac.mm",
"speech/tts_platform_impl.cc",
"speech/tts_platform_impl.h",
"speech/tts_win.cc",
"ssl/ssl_client_auth_handler.cc",
"ssl/ssl_client_auth_handler.h",
"ssl/ssl_error_handler.cc",
......@@ -1891,6 +1895,11 @@ jumbo_source_set("browser") {
]
}
if (is_desktop_linux) {
sources += [ "speech/tts_linux.cc" ]
deps += [ "//third_party/speech-dispatcher" ]
}
# ChromeOS also defines linux but their memory-monitors conflict.
if (is_chromeos) {
sources += [
......
......@@ -5,16 +5,18 @@
#include "base/memory/singleton.h"
#include "content/public/browser/tts_controller.h"
content::UtteranceContinuousParameters::UtteranceContinuousParameters()
namespace content {
UtteranceContinuousParameters::UtteranceContinuousParameters()
: rate(1.0), pitch(1.0), volume(1.0) {}
content::VoiceData::VoiceData() : remote(false), native(false) {}
VoiceData::VoiceData() : remote(false), native(false) {}
content::VoiceData::VoiceData(const VoiceData& other) = default;
VoiceData::VoiceData(const VoiceData& other) = default;
content::VoiceData::~VoiceData() {}
VoiceData::~VoiceData() {}
class MockTtsController : public content::TtsController {
class MockTtsController : public TtsController {
public:
static MockTtsController* GetInstance() {
return base::Singleton<MockTtsController>::get();
......@@ -24,7 +26,7 @@ class MockTtsController : public content::TtsController {
bool IsSpeaking() override { return false; }
void SpeakOrEnqueue(content::Utterance* utterance) override {}
void SpeakOrEnqueue(Utterance* utterance) override {}
void Stop() override {}
......@@ -33,29 +35,25 @@ class MockTtsController : public content::TtsController {
void Resume() override {}
void OnTtsEvent(int utterance_id,
content::TtsEventType event_type,
TtsEventType event_type,
int char_index,
const std::string& error_message) override {}
void GetVoices(content::BrowserContext* browser_context,
std::vector<content::VoiceData>* out_voices) override {}
void GetVoices(BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) override {}
void VoicesChanged() override {}
void AddVoicesChangedDelegate(
content::VoicesChangedDelegate* delegate) override {}
void AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) override {}
void RemoveVoicesChangedDelegate(
content::VoicesChangedDelegate* delegate) override {}
void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate) override {}
void RemoveUtteranceEventDelegate(
content::UtteranceEventDelegate* delegate) override {}
void RemoveUtteranceEventDelegate(UtteranceEventDelegate* delegate) override {
}
void SetTtsEngineDelegate(content::TtsEngineDelegate* delegate) override {}
void SetTtsEngineDelegate(TtsEngineDelegate* delegate) override {}
content::TtsEngineDelegate* GetTtsEngineDelegate() override {
return nullptr;
}
TtsEngineDelegate* GetTtsEngineDelegate() override { return nullptr; }
private:
friend struct base::DefaultSingletonTraits<MockTtsController>;
......@@ -63,6 +61,8 @@ class MockTtsController : public content::TtsController {
};
// static
content::TtsController* content::TtsController::GetInstance() {
TtsController* TtsController::GetInstance() {
return MockTtsController::GetInstance();
}
} // namespace content
\ No newline at end of file
......@@ -14,13 +14,13 @@
#include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
#include "base/task/post_task.h"
#include "chrome/browser/speech/tts_platform_impl.h"
#include "content/browser/speech/tts_platform_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "library_loaders/libspeechd.h"
using content::BrowserThread;
namespace content {
namespace {
......@@ -34,20 +34,19 @@ struct SPDChromeVoice {
} // namespace
// TODO(katie): Move to content/browser/speech.
class TtsPlatformImplLinux : public TtsPlatformImpl {
public:
bool PlatformImplAvailable() override;
bool Speak(int utterance_id,
const std::string& utterance,
const std::string& lang,
const content::VoiceData& voice,
const content::UtteranceContinuousParameters& params) override;
const VoiceData& voice,
const UtteranceContinuousParameters& params) override;
bool StopSpeaking() override;
void Pause() override;
void Resume() override;
bool IsSpeaking() override;
void GetVoices(std::vector<content::VoiceData>* out_voices) override;
void GetVoices(std::vector<VoiceData>* out_voices) override;
void OnSpeechEvent(SPDNotificationType type);
......@@ -93,11 +92,9 @@ class TtsPlatformImplLinux : public TtsPlatformImpl {
};
// static
SPDNotificationType TtsPlatformImplLinux::current_notification_ =
SPD_EVENT_END;
SPDNotificationType TtsPlatformImplLinux::current_notification_ = SPD_EVENT_END;
TtsPlatformImplLinux::TtsPlatformImplLinux()
: utterance_id_(0) {
TtsPlatformImplLinux::TtsPlatformImplLinux() : utterance_id_(0) {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kEnableSpeechDispatcher))
......@@ -118,19 +115,15 @@ void TtsPlatformImplLinux::Initialize() {
// spd_open has memory leaks which are hard to suppress.
// http://crbug.com/317360
ANNOTATE_SCOPED_MEMORY_LEAK;
conn_ = libspeechd_loader_.spd_open(
"chrome", "extension_api", NULL, SPD_MODE_THREADED);
conn_ = libspeechd_loader_.spd_open("chrome", "extension_api", NULL,
SPD_MODE_THREADED);
}
if (!conn_)
return;
// Register callbacks for all events.
conn_->callback_begin =
conn_->callback_end =
conn_->callback_cancel =
conn_->callback_pause =
conn_->callback_resume =
&NotificationCallback;
conn_->callback_begin = conn_->callback_end = conn_->callback_cancel =
conn_->callback_pause = conn_->callback_resume = &NotificationCallback;
conn_->callback_im = &IndexMarkCallback;
......@@ -153,8 +146,8 @@ void TtsPlatformImplLinux::Reset() {
base::AutoLock lock(initialization_lock_);
if (conn_)
libspeechd_loader_.spd_close(conn_);
conn_ = libspeechd_loader_.spd_open(
"chrome", "extension_api", NULL, SPD_MODE_THREADED);
conn_ = libspeechd_loader_.spd_open("chrome", "extension_api", NULL,
SPD_MODE_THREADED);
}
bool TtsPlatformImplLinux::PlatformImplAvailable() {
......@@ -165,12 +158,11 @@ bool TtsPlatformImplLinux::PlatformImplAvailable() {
return result;
}
bool TtsPlatformImplLinux::Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const content::VoiceData& voice,
const content::UtteranceContinuousParameters& params) {
bool TtsPlatformImplLinux::Speak(int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) {
if (!PlatformImplAvailable()) {
error_ = kNotSupportedError;
return false;
......@@ -234,8 +226,7 @@ bool TtsPlatformImplLinux::IsSpeaking() {
return current_notification_ == SPD_EVENT_BEGIN;
}
void TtsPlatformImplLinux::GetVoices(
std::vector<content::VoiceData>* out_voices) {
void TtsPlatformImplLinux::GetVoices(std::vector<VoiceData>* out_voices) {
if (!all_native_voices_.get()) {
all_native_voices_.reset(new std::map<std::string, SPDChromeVoice>());
char** modules = libspeechd_loader_.spd_list_modules(conn_);
......@@ -269,53 +260,51 @@ void TtsPlatformImplLinux::GetVoices(
for (auto it = all_native_voices_->begin(); it != all_native_voices_->end();
++it) {
out_voices->push_back(content::VoiceData());
content::VoiceData& voice = out_voices->back();
out_voices->push_back(VoiceData());
VoiceData& voice = out_voices->back();
voice.native = true;
voice.name = it->first;
voice.events.insert(content::TTS_EVENT_START);
voice.events.insert(content::TTS_EVENT_END);
voice.events.insert(content::TTS_EVENT_CANCELLED);
voice.events.insert(content::TTS_EVENT_MARKER);
voice.events.insert(content::TTS_EVENT_PAUSE);
voice.events.insert(content::TTS_EVENT_RESUME);
voice.events.insert(TTS_EVENT_START);
voice.events.insert(TTS_EVENT_END);
voice.events.insert(TTS_EVENT_CANCELLED);
voice.events.insert(TTS_EVENT_MARKER);
voice.events.insert(TTS_EVENT_PAUSE);
voice.events.insert(TTS_EVENT_RESUME);
}
}
void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) {
// hummmmmm
content::TtsController* controller = content::TtsController::GetInstance();
TtsController* controller = TtsController::GetInstance();
switch (type) {
case SPD_EVENT_BEGIN:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_START, 0,
std::string());
break;
case SPD_EVENT_RESUME:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_RESUME, 0,
std::string());
break;
case SPD_EVENT_END:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_END,
utterance_.size(), std::string());
break;
case SPD_EVENT_PAUSE:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_PAUSE,
utterance_.size(), std::string());
break;
case SPD_EVENT_CANCEL:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_CANCELLED, 0,
std::string());
break;
case SPD_EVENT_INDEX_MARK:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_MARKER, 0,
std::string());
break;
case SPD_EVENT_BEGIN:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string());
break;
case SPD_EVENT_RESUME:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME, 0, std::string());
break;
case SPD_EVENT_END:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_END, utterance_.size(),
std::string());
break;
case SPD_EVENT_PAUSE:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_PAUSE, utterance_.size(),
std::string());
break;
case SPD_EVENT_CANCEL:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_CANCELLED, 0,
std::string());
break;
case SPD_EVENT_INDEX_MARK:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string());
break;
}
}
// static
void TtsPlatformImplLinux::NotificationCallback(
size_t msg_id, size_t client_id, SPDNotificationType type) {
void TtsPlatformImplLinux::NotificationCallback(size_t msg_id,
size_t client_id,
SPDNotificationType type) {
// We run Speech Dispatcher in threaded mode, so these callbacks should always
// be in a separate thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
......@@ -330,9 +319,9 @@ void TtsPlatformImplLinux::NotificationCallback(
// static
void TtsPlatformImplLinux::IndexMarkCallback(size_t msg_id,
size_t client_id,
SPDNotificationType state,
char* index_mark) {
size_t client_id,
SPDNotificationType state,
char* index_mark) {
// TODO(dtseng): index_mark appears to specify an index type supplied by a
// client. Need to explore how this is used before hooking it up with existing
// word, sentence events.
......@@ -356,6 +345,8 @@ TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() {
}
// static
TtsPlatform* TtsPlatform::GetInstance() {
TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
return TtsPlatformImplLinux::GetInstance();
}
} // namespace content
......@@ -9,7 +9,7 @@
#include "base/memory/singleton.h"
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/speech/tts_platform_impl.h"
#include "content/browser/speech/tts_platform_impl.h"
#include "content/public/browser/tts_controller.h"
#import <Cocoa/Cocoa.h>
......@@ -48,8 +48,7 @@ class TtsPlatformImplMac;
@end
// TODO(katie): Move to content/browser/speech.
class TtsPlatformImplMac : public TtsPlatformImpl {
class TtsPlatformImplMac : public content::TtsPlatformImpl {
public:
bool PlatformImplAvailable() override { return true; }
......@@ -96,7 +95,7 @@ class TtsPlatformImplMac : public TtsPlatformImpl {
};
// static
TtsPlatform* TtsPlatform::GetInstance() {
content::TtsPlatformImpl* content::TtsPlatformImpl::GetInstance() {
return TtsPlatformImplMac::GetInstance();
}
......@@ -120,9 +119,8 @@ bool TtsPlatformImplMac::Speak(
// apply to the current utterance or a previous utterance. In
// experimentation, the overhead of constructing and destructing a
// NSSpeechSynthesizer is minimal.
speech_synthesizer_.reset(
[[SingleUseSpeechSynthesizer alloc]
initWithUtterance:utterance_nsstring]);
speech_synthesizer_.reset([[SingleUseSpeechSynthesizer alloc]
initWithUtterance:utterance_nsstring]);
[speech_synthesizer_ setDelegate:delegate_];
if (!voice.native_voice_identifier.empty()) {
......@@ -137,9 +135,9 @@ bool TtsPlatformImplMac::Speak(
if (params.rate >= 0.0) {
// The TTS api defines rate via words per minute. Let 200 be the default.
[speech_synthesizer_
setObject:[NSNumber numberWithInt:params.rate * 200]
forProperty:NSSpeechRateProperty error:nil];
[speech_synthesizer_ setObject:[NSNumber numberWithInt:params.rate * 200]
forProperty:NSSpeechRateProperty
error:nil];
}
if (params.pitch >= 0.0) {
......@@ -151,15 +149,15 @@ bool TtsPlatformImplMac::Speak(
error:&errorCode];
int defaultPitch = defaultPitchObj ? [defaultPitchObj intValue] : 48;
int newPitch = static_cast<int>(defaultPitch * (0.5 * params.pitch + 0.5));
[speech_synthesizer_
setObject:[NSNumber numberWithInt:newPitch]
forProperty:NSSpeechPitchBaseProperty error:nil];
[speech_synthesizer_ setObject:[NSNumber numberWithInt:newPitch]
forProperty:NSSpeechPitchBaseProperty
error:nil];
}
if (params.volume >= 0.0) {
[speech_synthesizer_
setObject: [NSNumber numberWithFloat:params.volume]
forProperty:NSSpeechVolumeProperty error:nil];
[speech_synthesizer_ setObject:[NSNumber numberWithFloat:params.volume]
forProperty:NSSpeechVolumeProperty
error:nil];
}
bool success = [speech_synthesizer_ startSpeakingRetainedUtterance];
......@@ -238,8 +236,8 @@ void TtsPlatformImplMac::GetVoices(std::vector<content::VoiceData>* outVoices) {
NSString* language = [localeComponents objectForKey:NSLocaleLanguageCode];
NSString* country = [localeComponents objectForKey:NSLocaleCountryCode];
if (language && country) {
data.lang =
[[NSString stringWithFormat:@"%@-%@", language, country] UTF8String];
data.lang = base::SysNSStringToUTF8(
[NSString stringWithFormat:@"%@-%@", language, country]);
} else {
data.lang = base::SysNSStringToUTF8(language);
}
......@@ -279,8 +277,7 @@ TtsPlatformImplMac::TtsPlatformImplMac() {
delegate_.reset([[ChromeTtsDelegate alloc] initWithPlatformImplMac:this]);
}
TtsPlatformImplMac::~TtsPlatformImplMac() {
}
TtsPlatformImplMac::~TtsPlatformImplMac() {}
// static
TtsPlatformImplMac* TtsPlatformImplMac::GetInstance() {
......@@ -314,9 +311,9 @@ TtsPlatformImplMac* TtsPlatformImplMac::GetInstance() {
}
- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
didEncounterErrorAtIndex:(NSUInteger)character_index
ofString:(NSString*)string
message:(NSString*)message {
didEncounterErrorAtIndex:(NSUInteger)character_index
ofString:(NSString*)string
message:(NSString*)message {
// Ignore bogus character_index. The Mac speech synthesizer is a bit
// buggy and occasionally returns a number way out of range.
if (character_index > [string length])
......@@ -352,4 +349,4 @@ TtsPlatformImplMac* TtsPlatformImplMac::GetInstance() {
return false;
}
@end
@end
\ No newline at end of file
......@@ -5,15 +5,17 @@
#include <objbase.h>
#include "build/build_config.h"
#include "chrome/browser/speech/tts_platform.h"
#include "content/public/browser/tts_platform.h"
namespace content {
// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
int utterance_id = 0;
std::string utterance;
std::string lang;
content::VoiceData voice;
content::UtteranceContinuousParameters params;
VoiceData voice;
UtteranceContinuousParameters params;
params.pitch = 1.0;
params.rate = 1.0;
params.volume = 0.1;
......@@ -101,3 +103,5 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
return 0;
}
} // namespace content
\ No newline at end of file
......@@ -2,18 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/speech/tts_platform_impl.h"
#include "content/browser/speech/tts_platform_impl.h"
#include "build/build_config.h"
#include "content/public/browser/content_browser_client.h"
#include <string>
bool TtsPlatformImpl::LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) {
namespace content {
// static
TtsPlatform* TtsPlatform::GetInstance() {
#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
return GetContentClient()->browser()->GetTtsPlatform();
#else
return TtsPlatformImpl::GetInstance();
#endif
}
bool TtsPlatformImpl::LoadBuiltInTtsExtension(BrowserContext* browser_context) {
return false;
}
void TtsPlatformImpl::WillSpeakUtteranceWithVoice(
const content::Utterance* utterance,
const content::VoiceData& voice_data) {}
void TtsPlatformImpl::WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data) {
}
std::string TtsPlatformImpl::GetError() {
return error_;
......@@ -26,3 +39,5 @@ void TtsPlatformImpl::ClearError() {
void TtsPlatformImpl::SetError(const std::string& error) {
error_ = error;
}
} // namespace content
\ No newline at end of file
......@@ -2,25 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SPEECH_TTS_PLATFORM_IMPL_H_
#define CHROME_BROWSER_SPEECH_TTS_PLATFORM_IMPL_H_
#ifndef CONTENT_BROWSER_SPEECH_TTS_PLATFORM_IMPL_H_
#define CONTENT_BROWSER_SPEECH_TTS_PLATFORM_IMPL_H_
#include <string>
#include "base/macros.h"
#include "chrome/browser/speech/tts_platform.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/browser/tts_platform.h"
namespace content {
// Abstract platform implementation.
// TODO(katie): Move to content/browser/speech.
class TtsPlatformImpl : public TtsPlatform {
public:
static TtsPlatformImpl* GetInstance();
// TtsPlatform overrides.
bool LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) override;
void WillSpeakUtteranceWithVoice(
const content::Utterance* utterance,
const content::VoiceData& voice_data) override;
bool LoadBuiltInTtsExtension(BrowserContext* browser_context) override;
void WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data) override;
std::string GetError() override;
void ClearError() override;
void SetError(const std::string& error) override;
......@@ -37,4 +38,6 @@ class TtsPlatformImpl : public TtsPlatform {
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImpl);
};
#endif // CHROME_BROWSER_SPEECH_TTS_PLATFORM_IMPL_H_
} // namespace content
#endif // CONTENT_BROWSER_SPEECH_TTS_PLATFORM_IMPL_H_
......@@ -16,9 +16,11 @@
#include "base/values.h"
#include "base/win/scoped_co_mem.h"
#include "base/win/sphelper.h"
#include "chrome/browser/speech/tts_platform_impl.h"
#include "content/browser/speech/tts_platform_impl.h"
#include "content/public/browser/tts_controller.h"
namespace content {
namespace {
// ISpObjectToken key and value names.
......@@ -27,18 +29,15 @@ const wchar_t kLanguageValue[] = L"Language";
} // anonymous namespace.
// TODO(katie): Move to content/browser/speech.
class TtsPlatformImplWin : public TtsPlatformImpl {
public:
bool PlatformImplAvailable() override {
return true;
}
bool PlatformImplAvailable() override { return true; }
bool Speak(int utterance_id,
const std::string& utterance,
const std::string& lang,
const content::VoiceData& voice,
const content::UtteranceContinuousParameters& params) override;
const VoiceData& voice,
const UtteranceContinuousParameters& params) override;
bool StopSpeaking() override;
......@@ -48,7 +47,7 @@ class TtsPlatformImplWin : public TtsPlatformImpl {
bool IsSpeaking() override;
void GetVoices(std::vector<content::VoiceData>* out_voices) override;
void GetVoices(std::vector<VoiceData>* out_voices) override;
// Get the single instance of this class.
static TtsPlatformImplWin* GetInstance();
......@@ -80,16 +79,15 @@ class TtsPlatformImplWin : public TtsPlatformImpl {
};
// static
TtsPlatform* TtsPlatform::GetInstance() {
TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
return TtsPlatformImplWin::GetInstance();
}
bool TtsPlatformImplWin::Speak(
int utterance_id,
const std::string& src_utterance,
const std::string& lang,
const content::VoiceData& voice,
const content::UtteranceContinuousParameters& params) {
bool TtsPlatformImplWin::Speak(int utterance_id,
const std::string& src_utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) {
std::wstring prefix;
std::wstring suffix;
......@@ -130,10 +128,8 @@ bool TtsPlatformImplWin::Speak(
std::wstring merged_utterance = prefix + utterance_ + suffix;
prefix_len_ = prefix.size();
HRESULT result = speech_synthesizer_->Speak(
merged_utterance.c_str(),
SPF_ASYNC,
&stream_number_);
HRESULT result = speech_synthesizer_->Speak(merged_utterance.c_str(),
SPF_ASYNC, &stream_number_);
return (result == S_OK);
}
......@@ -159,8 +155,8 @@ void TtsPlatformImplWin::Pause() {
if (speech_synthesizer_.Get() && utterance_id_ && !paused_) {
speech_synthesizer_->Pause();
paused_ = true;
content::TtsController::GetInstance()->OnTtsEvent(
utterance_id_, content::TTS_EVENT_PAUSE, char_position_, "");
TtsController::GetInstance()->OnTtsEvent(utterance_id_, TTS_EVENT_PAUSE,
char_position_, "");
}
}
......@@ -168,8 +164,8 @@ void TtsPlatformImplWin::Resume() {
if (speech_synthesizer_.Get() && utterance_id_ && paused_) {
speech_synthesizer_->Resume();
paused_ = false;
content::TtsController::GetInstance()->OnTtsEvent(
utterance_id_, content::TTS_EVENT_RESUME, char_position_, "");
TtsController::GetInstance()->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME,
char_position_, "");
}
}
......@@ -187,8 +183,7 @@ bool TtsPlatformImplWin::IsSpeaking() {
return false;
}
void TtsPlatformImplWin::GetVoices(
std::vector<content::VoiceData>* out_voices) {
void TtsPlatformImplWin::GetVoices(std::vector<VoiceData>* out_voices) {
Microsoft::WRL::ComPtr<IEnumSpObjectTokens> voice_tokens;
unsigned long voice_count;
if (S_OK !=
......@@ -198,7 +193,7 @@ void TtsPlatformImplWin::GetVoices(
return;
for (unsigned i = 0; i < voice_count; i++) {
content::VoiceData voice;
VoiceData voice;
Microsoft::WRL::ComPtr<ISpObjectToken> voice_token;
if (S_OK != voice_tokens->Next(1, voice_token.GetAddressOf(), NULL))
......@@ -224,50 +219,50 @@ void TtsPlatformImplWin::GetVoices(
}
voice.native = true;
voice.events.insert(content::TTS_EVENT_START);
voice.events.insert(content::TTS_EVENT_END);
voice.events.insert(content::TTS_EVENT_MARKER);
voice.events.insert(content::TTS_EVENT_WORD);
voice.events.insert(content::TTS_EVENT_SENTENCE);
voice.events.insert(content::TTS_EVENT_PAUSE);
voice.events.insert(content::TTS_EVENT_RESUME);
voice.events.insert(TTS_EVENT_START);
voice.events.insert(TTS_EVENT_END);
voice.events.insert(TTS_EVENT_MARKER);
voice.events.insert(TTS_EVENT_WORD);
voice.events.insert(TTS_EVENT_SENTENCE);
voice.events.insert(TTS_EVENT_PAUSE);
voice.events.insert(TTS_EVENT_RESUME);
out_voices->push_back(voice);
}
}
void TtsPlatformImplWin::OnSpeechEvent() {
content::TtsController* controller = content::TtsController::GetInstance();
TtsController* controller = TtsController::GetInstance();
SPEVENT event;
while (S_OK == speech_synthesizer_->GetEvents(1, &event, NULL)) {
if (event.ulStreamNum != stream_number_)
continue;
switch (event.eEventId) {
case SPEI_START_INPUT_STREAM:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_START, 0,
std::string());
break;
case SPEI_END_INPUT_STREAM:
char_position_ = utterance_.size();
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_END,
char_position_, std::string());
break;
case SPEI_TTS_BOOKMARK:
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_MARKER,
char_position_, std::string());
break;
case SPEI_WORD_BOUNDARY:
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_WORD,
char_position_, std::string());
break;
case SPEI_SENTENCE_BOUNDARY:
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_SENTENCE,
char_position_, std::string());
break;
default:
break;
case SPEI_START_INPUT_STREAM:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0,
std::string());
break;
case SPEI_END_INPUT_STREAM:
char_position_ = utterance_.size();
controller->OnTtsEvent(utterance_id_, TTS_EVENT_END, char_position_,
std::string());
break;
case SPEI_TTS_BOOKMARK:
controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, char_position_,
std::string());
break;
case SPEI_WORD_BOUNDARY:
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
controller->OnTtsEvent(utterance_id_, TTS_EVENT_WORD, char_position_,
std::string());
break;
case SPEI_SENTENCE_BOUNDARY:
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
controller->OnTtsEvent(utterance_id_, TTS_EVENT_SENTENCE,
char_position_, std::string());
break;
default:
break;
}
}
}
......@@ -302,19 +297,17 @@ void TtsPlatformImplWin::SetVoiceFromName(const std::string& name) {
}
TtsPlatformImplWin::TtsPlatformImplWin()
: utterance_id_(0),
prefix_len_(0),
stream_number_(0),
char_position_(0),
paused_(false) {
: utterance_id_(0),
prefix_len_(0),
stream_number_(0),
char_position_(0),
paused_(false) {
::CoCreateInstance(CLSID_SpVoice, nullptr, CLSCTX_ALL,
IID_PPV_ARGS(&speech_synthesizer_));
if (speech_synthesizer_.Get()) {
ULONGLONG event_mask =
SPFEI(SPEI_START_INPUT_STREAM) |
SPFEI(SPEI_TTS_BOOKMARK) |
SPFEI(SPEI_WORD_BOUNDARY) |
SPFEI(SPEI_SENTENCE_BOUNDARY) |
SPFEI(SPEI_START_INPUT_STREAM) | SPFEI(SPEI_TTS_BOOKMARK) |
SPFEI(SPEI_WORD_BOUNDARY) | SPFEI(SPEI_SENTENCE_BOUNDARY) |
SPFEI(SPEI_END_INPUT_STREAM);
speech_synthesizer_->SetInterest(event_mask, event_mask);
speech_synthesizer_->SetNotifyCallbackFunction(
......@@ -329,7 +322,8 @@ TtsPlatformImplWin* TtsPlatformImplWin::GetInstance() {
}
// static
void TtsPlatformImplWin::SpeechEventCallback(
WPARAM w_param, LPARAM l_param) {
void TtsPlatformImplWin::SpeechEventCallback(WPARAM w_param, LPARAM l_param) {
GetInstance()->OnSpeechEvent();
}
} // namespace content
\ No newline at end of file
......@@ -290,6 +290,7 @@ jumbo_source_set("browser_sources") {
"tracing_delegate.h",
"tts_controller.h",
"tts_controller_delegate.h",
"tts_platform.h",
"url_data_source.cc",
"url_data_source.h",
"url_loader_request_interceptor.h",
......
......@@ -510,6 +510,10 @@ TtsControllerDelegate* ContentBrowserClient::GetTtsControllerDelegate() {
return nullptr;
}
TtsPlatform* ContentBrowserClient::GetTtsPlatform() {
return nullptr;
}
net::NetLog* ContentBrowserClient::GetNetLog() {
return nullptr;
}
......
......@@ -176,6 +176,7 @@ class SpeechRecognitionManagerDelegate;
class StoragePartition;
class TracingDelegate;
class TtsControllerDelegate;
class TtsPlatform;
class URLLoaderRequestInterceptor;
class URLLoaderThrottle;
class VpnServiceProxy;
......@@ -797,6 +798,9 @@ class CONTENT_EXPORT ContentBrowserClient {
// Allows the embedder to return a delegate for the TtsController.
virtual TtsControllerDelegate* GetTtsControllerDelegate();
// Allows the embedder to return a TTS platform implementation.
virtual TtsPlatform* GetTtsPlatform();
// Getter for the net logging object. This can be called on any thread.
virtual net::NetLog* GetNetLog();
......
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SPEECH_TTS_PLATFORM_H_
#define CHROME_BROWSER_SPEECH_TTS_PLATFORM_H_
#ifndef CONTENT_PUBLIC_BROWSER_TTS_PLATFORM_H_
#define CONTENT_PUBLIC_BROWSER_TTS_PLATFORM_H_
#include <string>
#include "base/macros.h"
#include "content/common/content_export.h"
#include "content/public/browser/tts_controller.h"
namespace content {
// Abstract class that defines the native platform TTS interface,
// subclassed by specific implementations on Win, Mac, etc.
// TODO(katie): Move to content/public/browser and most implementations into
// content/browser/speech. The tts_chromeos.cc implementation may need to remain
// in chrome/ due to ARC++ dependencies.
class TtsPlatform {
class CONTENT_EXPORT TtsPlatform {
public:
static TtsPlatform* GetInstance();
......@@ -27,8 +27,7 @@ class TtsPlatform {
// false if it's already loaded or if there's no extension to load.
// Will call TtsController::RetrySpeakingQueuedUtterances when
// the extension finishes loading.
virtual bool LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) = 0;
virtual bool LoadBuiltInTtsExtension(BrowserContext* browser_context) = 0;
// Speak the given utterance with the given parameters if possible,
// and return true on success. Utterance will always be nonempty.
......@@ -40,8 +39,8 @@ class TtsPlatform {
virtual bool Speak(int utterance_id,
const std::string& utterance,
const std::string& lang,
const content::VoiceData& voice,
const content::UtteranceContinuousParameters& params) = 0;
const VoiceData& voice,
const UtteranceContinuousParameters& params) = 0;
// Stop speaking immediately and return true on success.
virtual bool StopSpeaking() = 0;
......@@ -51,7 +50,7 @@ class TtsPlatform {
// Append information about voices provided by this platform implementation
// to |out_voices|.
virtual void GetVoices(std::vector<content::VoiceData>* out_voices) = 0;
virtual void GetVoices(std::vector<VoiceData>* out_voices) = 0;
// Pause the current utterance, if any, until a call to Resume,
// Speak, or StopSpeaking.
......@@ -62,13 +61,14 @@ class TtsPlatform {
// Allows the platform to monitor speech commands and the voices used
// for each one.
virtual void WillSpeakUtteranceWithVoice(
const content::Utterance* utterance,
const content::VoiceData& voice_data) = 0;
virtual void WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data) = 0;
virtual std::string GetError() = 0;
virtual void ClearError() = 0;
virtual void SetError(const std::string& error) = 0;
};
#endif // CHROME_BROWSER_SPEECH_TTS_PLATFORM_H_
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_TTS_PLATFORM_H_
......@@ -192,3 +192,32 @@ fuzzer_test("appcache_fuzzer") {
"//third_party/libprotobuf-mutator",
]
}
# Note: this compiles and runs on Mac but may cause
# system instability; if you try it out, close other
# programs and then reboot afterwards. It should be
# possible to make it work on Linux if you use the
# --enable-speech-dispatcher flag.
if (is_win) {
fuzzer_test("tts_platform_fuzzer") {
sources = [
"../../browser/speech/mock_tts_controller.cc",
"../../browser/speech/tts_mac.mm",
"../../browser/speech/tts_platform_fuzzer.cc",
"../../browser/speech/tts_platform_impl.cc",
"../../browser/speech/tts_platform_impl.h",
"../../browser/speech/tts_win.cc",
"../../public/browser/tts_controller.h",
"../../public/browser/tts_platform.h",
"//content/common/content_export.h",
]
deps = [
"//base",
"//base/test:test_support",
"//content/public/browser:browser_sources",
"//ui/base",
"//url:url",
]
}
}
......@@ -142,7 +142,7 @@ src:*audio/pulse/pulse_stubs.cc
src:*media/gpu/vaapi/va_stubs.cc
# Calls to auto-generated stubs by generate_library_loader.py
src:*chrome/browser/speech/tts_linux.cc
src:*content/browser/speech/tts_linux.cc
src:*device/udev_linux/udev0_loader.cc
src:*device/udev_linux/udev1_loader.cc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment