forked from uazo/cromite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisable-speechSynthesis-getVoices-API.patch
185 lines (173 loc) · 9.02 KB
/
Disable-speechSynthesis-getVoices-API.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
From: uazo <[email protected]>
Date: Thu, 20 Apr 2023 15:03:13 +0000
Subject: Disable speechSynthesis getVoices API
Adds flag disable-speechsynthesis-voice-list to disable
SpeechSynthesis.getVoices() call.
If not active the user must also set the system timezone override
to enable it.
Disable LiveCaption
Require: Timezone-customization.patch
License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
---
.../renderer/chrome_content_renderer_client.cc | 2 +-
.../renderer/content_settings_agent_impl.cc | 9 ++++++++-
.../renderer/content_settings_agent_impl.h | 2 ++
content/browser/speech/tts_android.cc | 2 +-
content/browser/speech/tts_win.cc | 2 +-
.../Disable-speechSynthesis-getVoices-API.inc | 8 ++++++++
.../Disable-speechSynthesis-getVoices-API.inc | 2 ++
.../Disable-speechSynthesis-getVoices-API.inc | 3 +++
.../Disable-speechSynthesis-getVoices-API.inc | 1 +
.../platform/web_content_settings_client.h | 2 ++
.../renderer/modules/speech/speech_synthesis.cc | 17 ++++++++++++++---
11 files changed, 43 insertions(+), 7 deletions(-)
create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Disable-speechSynthesis-getVoices-API.inc
create mode 100644 cromite_flags/media/base/media_switches_cc/Disable-speechSynthesis-getVoices-API.inc
create mode 100644 cromite_flags/third_party/blink/common/features_cc/Disable-speechSynthesis-getVoices-API.inc
create mode 100644 cromite_flags/third_party/blink/common/features_h/Disable-speechSynthesis-getVoices-API.inc
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -1625,7 +1625,7 @@ ChromeContentRendererClient::CreateWorkerContentSettingsClient(
std::unique_ptr<media::SpeechRecognitionClient>
ChromeContentRendererClient::CreateSpeechRecognitionClient(
content::RenderFrame* render_frame) {
- return std::make_unique<ChromeSpeechRecognitionClient>(render_frame);
+ return nullptr;
}
#endif // BUILDFLAG(ENABLE_SPEECH_SERVICE)
diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc
--- a/components/content_settings/renderer/content_settings_agent_impl.cc
+++ b/components/content_settings/renderer/content_settings_agent_impl.cc
@@ -473,6 +473,14 @@ bool ContentSettingsAgentImpl::IsAllowlistedForContentSettings() const {
return false;
}
+bool ContentSettingsAgentImpl::IsTimezoneChanged() {
+ if (!content_setting_rules_)
+ return false;
+ // CONTENT_SETTING_ALLOW = use system time
+ return CONTENT_SETTING_ALLOW != GetContentSetting(
+ ContentSettingsType::TIMEZONE_OVERRIDE, CONTENT_SETTING_ALLOW);
+}
+
bool ContentSettingsAgentImpl::UpdateOverrides() {
// Evaluate the content setting rules
ContentSetting setting = CONTENT_SETTING_ALLOW;
@@ -483,7 +491,6 @@ bool ContentSettingsAgentImpl::UpdateOverrides() {
}
return UpdateTimeZoneOverride(
setting, content_setting_rules_->timezone_override_value);
- //&& UpdateLocaleOverride(setting);
}
bool ContentSettingsAgentImpl::UpdateTimeZoneOverride(
diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h
--- a/components/content_settings/renderer/content_settings_agent_impl.h
+++ b/components/content_settings/renderer/content_settings_agent_impl.h
@@ -117,6 +117,8 @@ class ContentSettingsAgentImpl
void SetRendererContentSettingRulesForTest(
const RendererContentSettingRules& rules);
+ bool IsTimezoneChanged() override;
+
protected:
// Allow this to be overridden by tests.
virtual void BindContentSettingsManager(
diff --git a/content/browser/speech/tts_android.cc b/content/browser/speech/tts_android.cc
--- a/content/browser/speech/tts_android.cc
+++ b/content/browser/speech/tts_android.cc
@@ -42,7 +42,7 @@ TtsPlatformImplAndroid::~TtsPlatformImplAndroid() {
}
bool TtsPlatformImplAndroid::PlatformImplSupported() {
- return true;
+ return false;
}
bool TtsPlatformImplAndroid::PlatformImplInitialized() {
diff --git a/content/browser/speech/tts_win.cc b/content/browser/speech/tts_win.cc
--- a/content/browser/speech/tts_win.cc
+++ b/content/browser/speech/tts_win.cc
@@ -155,7 +155,7 @@ class TtsPlatformImplWin : public TtsPlatformImpl {
TtsPlatformImplWin(const TtsPlatformImplWin&) = delete;
TtsPlatformImplWin& operator=(const TtsPlatformImplWin&) = delete;
- bool PlatformImplSupported() override { return true; }
+ bool PlatformImplSupported() override { return false; }
bool PlatformImplInitialized() override;
void Speak(int utterance_id,
diff --git a/cromite_flags/chrome/browser/about_flags_cc/Disable-speechSynthesis-getVoices-API.inc b/cromite_flags/chrome/browser/about_flags_cc/Disable-speechSynthesis-getVoices-API.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/chrome/browser/about_flags_cc/Disable-speechSynthesis-getVoices-API.inc
@@ -0,0 +1,8 @@
+#ifdef FLAG_SECTION
+
+ {"disable-speechsynthesis-voice-list",
+ "Disable speechSynthesis.getVoices()",
+ "Disables access to the list of items installed on the device", kOsAll,
+ FEATURE_VALUE_TYPE(blink::features::kDisableSpeechSynthesisVoiceList)},
+
+#endif
diff --git a/cromite_flags/media/base/media_switches_cc/Disable-speechSynthesis-getVoices-API.inc b/cromite_flags/media/base/media_switches_cc/Disable-speechSynthesis-getVoices-API.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/media/base/media_switches_cc/Disable-speechSynthesis-getVoices-API.inc
@@ -0,0 +1,2 @@
+SET_CROMITE_FEATURE_DISABLED(kLiveCaption);
+SET_CROMITE_FEATURE_DISABLED(kLiveCaptionWebAudio);
diff --git a/cromite_flags/third_party/blink/common/features_cc/Disable-speechSynthesis-getVoices-API.inc b/cromite_flags/third_party/blink/common/features_cc/Disable-speechSynthesis-getVoices-API.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/third_party/blink/common/features_cc/Disable-speechSynthesis-getVoices-API.inc
@@ -0,0 +1,3 @@
+CROMITE_FEATURE(kDisableSpeechSynthesisVoiceList,
+ "DisableSpeechSynthesisVoiceList",
+ base::FEATURE_ENABLED_BY_DEFAULT);
diff --git a/cromite_flags/third_party/blink/common/features_h/Disable-speechSynthesis-getVoices-API.inc b/cromite_flags/third_party/blink/common/features_h/Disable-speechSynthesis-getVoices-API.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/third_party/blink/common/features_h/Disable-speechSynthesis-getVoices-API.inc
@@ -0,0 +1 @@
+BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kDisableSpeechSynthesisVoiceList);
diff --git a/third_party/blink/public/platform/web_content_settings_client.h b/third_party/blink/public/platform/web_content_settings_client.h
--- a/third_party/blink/public/platform/web_content_settings_client.h
+++ b/third_party/blink/public/platform/web_content_settings_client.h
@@ -111,6 +111,8 @@ class WebContentSettingsClient {
// frame.
virtual bool ShouldAutoupgradeMixedContent() { return true; }
+ virtual bool IsTimezoneChanged() { return false; }
+
// Controls whether the ViewTransition callback needs to be larger than
// default.
virtual bool IncreaseViewTransitionCallbackTimeout() const { return false; }
diff --git a/third_party/blink/renderer/modules/speech/speech_synthesis.cc b/third_party/blink/renderer/modules/speech/speech_synthesis.cc
--- a/third_party/blink/renderer/modules/speech/speech_synthesis.cc
+++ b/third_party/blink/renderer/modules/speech/speech_synthesis.cc
@@ -35,6 +35,7 @@
#include "third_party/blink/public/common/privacy_budget/identifiable_token_builder.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
+#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_speech_synthesis_error_event_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_speech_synthesis_event_init.h"
#include "third_party/blink/renderer/core/dom/document.h"
@@ -93,9 +94,19 @@ SpeechSynthesis::SpeechSynthesis(LocalDOMWindow& window)
void SpeechSynthesis::OnSetVoiceList(
Vector<mojom::blink::SpeechSynthesisVoicePtr> mojom_voices) {
voice_list_.clear();
- for (auto& mojom_voice : mojom_voices) {
- voice_list_.push_back(
- MakeGarbageCollected<SpeechSynthesisVoice>(std::move(mojom_voice)));
+ bool allowed = !base::FeatureList::IsEnabled(features::kDisableSpeechSynthesisVoiceList);
+ if (allowed) {
+ auto* frame = GetSupplementable()->GetFrame();
+ if (frame) {
+ blink::WebContentSettingsClient* settings = frame->GetContentSettingsClient();
+ if (settings) allowed = !settings->IsTimezoneChanged();
+ }
+ }
+ if (allowed) {
+ for (auto& mojom_voice : mojom_voices) {
+ voice_list_.push_back(
+ MakeGarbageCollected<SpeechSynthesisVoice>(std::move(mojom_voice)));
+ }
}
VoicesDidChange();
}
--