Skip to content

Commit 8d6e267

Browse files
Sconymagomez
authored andcommitted
Adapt speech synthesis changes from 2.28
- Add missing functions - Add proper error handling (similar to #823 with optional as in #875) for both UIProcess and WebProcess
1 parent c5801b7 commit 8d6e267

File tree

12 files changed

+43
-25
lines changed

12 files changed

+43
-25
lines changed

Source/WebCore/Headers.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,16 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
544544
Modules/reporting/TestReportBody.h
545545
Modules/reporting/ViolationReportType.h
546546

547+
Modules/speech/LocalDOMWindowSpeechSynthesis.h
548+
Modules/speech/SpeechSynthesisErrorCode.h
549+
Modules/speech/SpeechSynthesisErrorEvent.h
550+
Modules/speech/SpeechSynthesisErrorEventInit.h
551+
Modules/speech/SpeechSynthesisEvent.h
552+
Modules/speech/SpeechSynthesisEventInit.h
553+
Modules/speech/SpeechSynthesis.h
554+
Modules/speech/SpeechSynthesisUtterance.h
555+
Modules/speech/SpeechSynthesisVoice.h
556+
547557
Modules/speech/SpeechRecognitionCaptureSource.h
548558
Modules/speech/SpeechRecognitionCaptureSourceImpl.h
549559
Modules/speech/SpeechRecognitionConnection.h

Source/WebCore/Modules/speech/SpeechSynthesis.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void SpeechSynthesis::cancel()
167167
m_speechSynthesisClient->cancel();
168168
// If we wait for cancel to callback speakingErrorOccurred, then m_currentSpeechUtterance will be null
169169
// and the event won't be processed. Instead we process the error immediately.
170-
speakingErrorOccurred();
170+
speakingErrorOccurred(SpeechSynthesisErrorCode::Canceled);
171171
m_currentSpeechUtterance = nullptr;
172172
} else if (m_platformSpeechSynthesizer)
173173
m_platformSpeechSynthesizer->cancel();
@@ -195,18 +195,18 @@ void SpeechSynthesis::resume()
195195
}
196196
}
197197

198-
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, bool errorOccurred)
198+
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
199199
{
200200
ASSERT(m_currentSpeechUtterance);
201201
Ref<SpeechSynthesisUtterance> protect(utterance);
202202

203203
m_currentSpeechUtterance = nullptr;
204204

205-
if (errorOccurred)
206-
utterance.errorEventOccurred(eventNames().errorEvent, SpeechSynthesisErrorCode::Canceled);
205+
if (error)
206+
utterance.errorEventOccurred(eventNames().errorEvent, *error);
207207
else
208208
utterance.eventOccurred(eventNames().endEvent, 0, 0, String());
209-
209+
210210
if (m_utteranceQueue.size()) {
211211
Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst();
212212
ASSERT(&utterance == firstUtterance.ptr());
@@ -265,11 +265,11 @@ void SpeechSynthesis::didResumeSpeaking()
265265
didResumeSpeaking(*m_currentSpeechUtterance->platformUtterance());
266266
}
267267

268-
void SpeechSynthesis::speakingErrorOccurred()
268+
void SpeechSynthesis::speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode> error)
269269
{
270270
if (!m_currentSpeechUtterance)
271271
return;
272-
speakingErrorOccurred(*m_currentSpeechUtterance->platformUtterance());
272+
speakingErrorOccurred(*m_currentSpeechUtterance->platformUtterance(), error);
273273
}
274274

275275
void SpeechSynthesis::boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -307,13 +307,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
307307
void SpeechSynthesis::didFinishSpeaking(PlatformSpeechSynthesisUtterance& utterance)
308308
{
309309
if (utterance.client())
310-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), false);
310+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), std::nullopt);
311311
}
312312

313-
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance)
313+
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
314314
{
315315
if (utterance.client())
316-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), true);
316+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), error);
317317
}
318318

319319
} // namespace WebCore

Source/WebCore/Modules/speech/SpeechSynthesis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ class SpeechSynthesis : public PlatformSpeechSynthesizerClient, public SpeechSyn
8484
void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) override;
8585
void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) override;
8686
void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) override;
87-
void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) override;
87+
void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>) override;
8888
void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex, unsigned charLength) override;
8989

9090
// SpeechSynthesisClient override methods
9191
void didStartSpeaking() override;
9292
void didFinishSpeaking() override;
9393
void didPauseSpeaking() override;
9494
void didResumeSpeaking() override;
95-
void speakingErrorOccurred() override;
95+
void speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode>) override;
9696
void boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength) override;
9797
void voicesChanged() override;
9898

9999
void startSpeakingImmediately(SpeechSynthesisUtterance&);
100-
void handleSpeakingCompleted(SpeechSynthesisUtterance&, bool errorOccurred);
100+
void handleSpeakingCompleted(SpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>);
101101

102102
ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
103103
EventTargetInterface eventTargetInterface() const final { return SpeechSynthesisEventTargetInterfaceType; }

Source/WebCore/Modules/speech/SpeechSynthesisErrorCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
namespace WebCore {
3030

31-
enum class SpeechSynthesisErrorCode {
31+
enum class SpeechSynthesisErrorCode : uint8_t {
3232
Canceled,
3333
Interrupted,
3434
AudioBusy,

Source/WebCore/page/SpeechSynthesisClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace WebCore {
3434
class PlatformSpeechSynthesisUtterance;
3535
class SpeechSynthesisClientObserver;
3636
class PlatformSpeechSynthesisVoice;
37+
enum class SpeechSynthesisErrorCode : uint8_t;
3738

3839
class SpeechSynthesisClient : public CanMakeWeakPtr<SpeechSynthesisClient> {
3940
public:
@@ -59,7 +60,7 @@ class SpeechSynthesisClientObserver : public CanMakeWeakPtr<SpeechSynthesisClien
5960
virtual void didFinishSpeaking() = 0;
6061
virtual void didPauseSpeaking() = 0;
6162
virtual void didResumeSpeaking() = 0;
62-
virtual void speakingErrorOccurred() = 0;
63+
virtual void speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode>) = 0;
6364
virtual void boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength) = 0;
6465
virtual void voicesChanged() = 0;
6566
};

Source/WebCore/platform/PlatformSpeechSynthesizer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#if ENABLE(SPEECH_SYNTHESIS)
3030

3131
#include "PlatformSpeechSynthesisVoice.h"
32-
#include <wtf/RefPtr.h>
32+
#include "SpeechSynthesisErrorCode.h"
33+
#include <optional>
3334
#include <wtf/Vector.h>
3435

3536
#if PLATFORM(COCOA)
@@ -55,7 +56,7 @@ class PlatformSpeechSynthesizerClient {
5556
virtual void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
5657
virtual void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
5758
virtual void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
58-
virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) = 0;
59+
virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>) = 0;
5960
virtual void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex, unsigned charLength) = 0;
6061
virtual void voicesDidChange() = 0;
6162
protected:

Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void PlatformSpeechSynthesizerMock::cancel()
8181

8282
m_speakingFinishedTimer.stop();
8383
auto utterance = std::exchange(m_utterance, nullptr);
84-
client().speakingErrorOccurred(*utterance);
84+
client().speakingErrorOccurred(*utterance, SpeechSynthesisErrorCode::Canceled);
8585
}
8686

8787
void PlatformSpeechSynthesizerMock::pause()

Source/WebKit/UIProcess/WebPageProxyInternals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ struct WebPageProxy::Internals final : WebPopupMenuProxy::Client
361361
void didFinishSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
362362
void didPauseSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
363363
void didResumeSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
364-
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&) final;
364+
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode>) final;
365365
void boundaryEventOccurred(WebCore::PlatformSpeechSynthesisUtterance&, WebCore::SpeechBoundary, unsigned characterIndex, unsigned characterLength) final;
366366

367367
// PlatformSpeechSynthesizerClient

Source/WebKit/UIProcess/gstreamer/WebPageProxyGStreamer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ void WebPageProxy::Internals::didResumeSpeaking(WebCore::PlatformSpeechSynthesis
5858
handler();
5959
}
6060

61-
void WebPageProxy::Internals::speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&)
61+
void WebPageProxy::Internals::speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode> error)
6262
{
63-
page.send(Messages::WebPage::SpeakingErrorOccurred());
63+
if (!error)
64+
page.send(Messages::WebPage::SpeakingErrorOccurred(std::nullopt));
65+
else
66+
page.send(Messages::WebPage::SpeakingErrorOccurred(static_cast<uint8_t>(*error)));
6467
}
6568

6669
void WebPageProxy::Internals::boundaryEventOccurred(WebCore::PlatformSpeechSynthesisUtterance&, WebCore::SpeechBoundary speechBoundary, unsigned charIndex, unsigned charLength)

Source/WebKit/WebProcess/WebPage/WebPage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
#include <WebCore/PlatformKeyboardEvent.h>
246246
#include <WebCore/PlatformMediaSessionManager.h>
247247
#include <WebCore/PlatformMouseEvent.h>
248+
#include <WebCore/PlatformSpeechSynthesizer.h>
248249
#include <WebCore/PlatformStrategies.h>
249250
#include <WebCore/PluginDocument.h>
250251
#include <WebCore/PointerCaptureController.h>
@@ -8038,10 +8039,12 @@ void WebPage::systemPreviewActionTriggered(WebCore::SystemPreviewInfo previewInf
80388039
#endif
80398040

80408041
#if ENABLE(SPEECH_SYNTHESIS)
8041-
void WebPage::speakingErrorOccurred()
8042+
void WebPage::speakingErrorOccurred(std::optional<uint8_t> error)
80428043
{
80438044
if (auto observer = corePage()->speechSynthesisClient()->observer())
8044-
observer->speakingErrorOccurred();
8045+
observer->speakingErrorOccurred(!error
8046+
? std::nullopt
8047+
: std::make_optional(static_cast<WebCore::SpeechSynthesisErrorCode>(*error)));
80458048
}
80468049

80478050
void WebPage::boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength)

0 commit comments

Comments
 (0)