Skip to content

Commit

Permalink
refactor: move text-to-speech out of chromium_src (#15024)
Browse files Browse the repository at this point in the history
* chore: add tts patch and buildflag, makes tts work again

* chore: add tts patch and buildflag, makes tts work again

* fix: make things compile

* build: add relevant tts files for linux

* fix: update patch and patch description, should now compile on mac

* build: move chrome specific sources under chromium_src:chrome target

* build: enable_extensions again

We are depending on them, check `//electron/chromium_src:chrome` target
for more info.

* fix: update tts.patch to receive notifications about browser context destruction

* fix: extend browser process from chrome layer

The global state g_browser_process is shared between //chrome
and //electron.

* spec: add basic speech synthesis test

* spec: skip speech tests on ci

* build: fix compilation on windows
  • Loading branch information
adill committed Jan 17, 2019
1 parent 9be7ca0 commit 870e89c
Show file tree
Hide file tree
Showing 27 changed files with 250 additions and 2,954 deletions.
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" ]
}
}
}

0 comments on commit 870e89c

Please sign in to comment.