Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: refactor text-to-speech to 4-0-x #16437

Merged
merged 1 commit into from Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions atom/browser/atom_browser_client.cc
Expand Up @@ -90,6 +90,10 @@
#include "components/services/pdf_compositor/public/interfaces/pdf_compositor.mojom.h"
#endif // BUILDFLAG(ENABLE_PRINTING)

#if BUILDFLAG(ENABLE_TTS)
#include "chrome/browser/speech/tts_message_filter.h"
#endif // BUILDFLAG(ENABLE_TTS)

using content::BrowserThread;

namespace atom {
Expand Down Expand Up @@ -222,6 +226,10 @@ void AtomBrowserClient::RenderProcessWillLaunch(
process_id, host->GetBrowserContext()));
#endif

#if BUILDFLAG(ENABLE_TTS)
host->AddFilter(new TtsMessageFilter(host->GetBrowserContext()));
#endif

ProcessPreferences prefs;
auto* web_preferences =
WebContentsPreferences::From(GetWebContentsFromProcessID(process_id));
Expand Down
5 changes: 5 additions & 0 deletions atom/common/api/features.cc
Expand Up @@ -39,6 +39,10 @@ bool IsPrintingEnabled() {
return BUILDFLAG(ENABLE_PRINTING);
}

bool IsTtsEnabled() {
return BUILDFLAG(ENABLE_TTS);
}

void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
Expand All @@ -52,6 +56,7 @@ void Initialize(v8::Local<v8::Object> exports,
&IsFakeLocationProviderEnabled);
dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled);
dict.SetMethod("isPrintingEnabled", &IsPrintingEnabled);
dict.SetMethod("isTtsEnabled", &IsTtsEnabled);
}

} // namespace
Expand Down
9 changes: 8 additions & 1 deletion atom/renderer/renderer_client_base.cc
Expand Up @@ -19,7 +19,6 @@
#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "chrome/renderer/tts_dispatcher.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_frame.h"
Expand Down Expand Up @@ -56,6 +55,10 @@
#include "components/printing/renderer/print_render_frame_helper.h"
#endif // BUILDFLAG(ENABLE_PRINTING)

#if BUILDFLAG(ENABLE_TTS)
#include "chrome/renderer/tts_dispatcher.h"
#endif // BUILDFLAG(ENABLE_TTS)

namespace atom {

namespace {
Expand Down Expand Up @@ -228,7 +231,11 @@ void RendererClientBase::DidClearWindowObject(
std::unique_ptr<blink::WebSpeechSynthesizer>
RendererClientBase::OverrideSpeechSynthesizer(
blink::WebSpeechSynthesizerClient* client) {
#if BUILDFLAG(ENABLE_TTS)
return std::make_unique<TtsDispatcher>(client);
#else
return nullptr;
#endif
}

bool RendererClientBase::OverrideCreatePlugin(
Expand Down
1 change: 1 addition & 0 deletions buildflags/BUILD.gn
Expand Up @@ -15,6 +15,7 @@ buildflag_header("buildflags") {
"ENABLE_VIEW_API=$enable_view_api",
"ENABLE_PEPPER_FLASH=$enable_pepper_flash",
"ENABLE_PDF_VIEWER=$enable_pdf_viewer",
"ENABLE_TTS=$enable_tts",
"OVERRIDE_LOCATION_PROVIDER=$enable_fake_location_provider",
]
}
2 changes: 2 additions & 0 deletions buildflags/buildflags.gni
Expand Up @@ -14,6 +14,8 @@ declare_args() {

enable_pdf_viewer = false

enable_tts = true

# Provide a fake location provider for mocking
# the geolocation responses. Disable it if you
# need to test with chromium's location provider.
Expand Down
24 changes: 24 additions & 0 deletions chromium_src/BUILD.gn
Expand Up @@ -99,4 +99,28 @@ source_set("chrome") {
]
}
}

if (enable_tts) {
sources += [
"//chrome/browser/speech/tts_controller.h",
"//chrome/browser/speech/tts_controller_impl.cc",
"//chrome/browser/speech/tts_controller_impl.h",
"//chrome/browser/speech/tts_mac.mm",
"//chrome/browser/speech/tts_message_filter.cc",
"//chrome/browser/speech/tts_message_filter.h",
"//chrome/browser/speech/tts_platform.cc",
"//chrome/browser/speech/tts_platform.h",
"//chrome/browser/speech/tts_win.cc",
"//chrome/common/tts_messages.h",
"//chrome/common/tts_utterance_request.cc",
"//chrome/common/tts_utterance_request.h",
"//chrome/renderer/tts_dispatcher.cc",
"//chrome/renderer/tts_dispatcher.h",
]

if (is_linux) {
sources += [ "//chrome/browser/speech/tts_linux.cc" ]
deps += [ "//third_party/speech-dispatcher" ]
}
}
}