Skip to content

Commit 4da5387

Browse files
Sconypgorszkowski-igalia
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 04464f3 commit 4da5387

File tree

12 files changed

+44
-26
lines changed

12 files changed

+44
-26
lines changed

Source/WebCore/Headers.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,16 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
550550
Modules/reporting/TestReportBody.h
551551
Modules/reporting/ViolationReportType.h
552552

553+
Modules/speech/LocalDOMWindowSpeechSynthesis.h
554+
Modules/speech/SpeechSynthesisErrorCode.h
555+
Modules/speech/SpeechSynthesisErrorEvent.h
556+
Modules/speech/SpeechSynthesisErrorEventInit.h
557+
Modules/speech/SpeechSynthesisEvent.h
558+
Modules/speech/SpeechSynthesisEventInit.h
559+
Modules/speech/SpeechSynthesis.h
560+
Modules/speech/SpeechSynthesisUtterance.h
561+
Modules/speech/SpeechSynthesisVoice.h
562+
553563
Modules/speech/SpeechRecognitionCaptureSource.h
554564
Modules/speech/SpeechRecognitionCaptureSourceImpl.h
555565
Modules/speech/SpeechRecognitionConnection.h

Source/WebCore/Modules/speech/SpeechSynthesis.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void SpeechSynthesis::setPlatformSynthesizer(Ref<PlatformSpeechSynthesizer>&& sy
8383
m_voiceList = std::nullopt;
8484
m_utteranceQueue.clear();
8585
// Finish current utterance.
86-
speakingErrorOccurred();
86+
speakingErrorOccurred(SpeechSynthesisErrorCode::Canceled);
8787
m_isPaused = false;
8888
m_speechSynthesisClient = nullptr;
8989
}
@@ -174,7 +174,7 @@ void SpeechSynthesis::cancel()
174174
m_speechSynthesisClient->cancel();
175175
// If we wait for cancel to callback speakingErrorOccurred, then m_currentSpeechUtterance will be null
176176
// and the event won't be processed. Instead we process the error immediately.
177-
speakingErrorOccurred();
177+
speakingErrorOccurred(SpeechSynthesisErrorCode::Canceled);
178178
m_currentSpeechUtterance = nullptr;
179179
} else if (m_platformSpeechSynthesizer)
180180
m_platformSpeechSynthesizer->cancel();
@@ -202,18 +202,18 @@ void SpeechSynthesis::resumeSynthesis()
202202
}
203203
}
204204

205-
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, bool errorOccurred)
205+
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
206206
{
207207
ASSERT(m_currentSpeechUtterance);
208208
Ref<SpeechSynthesisUtterance> protect(utterance);
209209

210210
m_currentSpeechUtterance = nullptr;
211211

212-
if (errorOccurred)
213-
utterance.errorEventOccurred(eventNames().errorEvent, SpeechSynthesisErrorCode::Canceled);
212+
if (error)
213+
utterance.errorEventOccurred(eventNames().errorEvent, *error);
214214
else
215215
utterance.eventOccurred(eventNames().endEvent, 0, 0, String());
216-
216+
217217
if (m_utteranceQueue.size()) {
218218
Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst();
219219
ASSERT(&utterance == firstUtterance.ptr());
@@ -272,11 +272,11 @@ void SpeechSynthesis::didResumeSpeaking()
272272
didResumeSpeaking(*protectedCurrentSpeechUtterance()->platformUtterance());
273273
}
274274

275-
void SpeechSynthesis::speakingErrorOccurred()
275+
void SpeechSynthesis::speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode> error)
276276
{
277277
if (!m_currentSpeechUtterance)
278278
return;
279-
speakingErrorOccurred(*protectedCurrentSpeechUtterance()->platformUtterance());
279+
speakingErrorOccurred(*protectedCurrentSpeechUtterance()->platformUtterance(), error);
280280
}
281281

282282
void SpeechSynthesis::boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -314,13 +314,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
314314
void SpeechSynthesis::didFinishSpeaking(PlatformSpeechSynthesisUtterance& utterance)
315315
{
316316
if (utterance.client())
317-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), false);
317+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), std::nullopt);
318318
}
319319

320-
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance)
320+
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
321321
{
322322
if (utterance.client())
323-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), true);
323+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), error);
324324
}
325325

326326
RefPtr<SpeechSynthesisUtterance> SpeechSynthesis::protectedCurrentSpeechUtterance()

Source/WebCore/Modules/speech/SpeechSynthesis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ class SpeechSynthesis : public PlatformSpeechSynthesizerClient, public SpeechSyn
8686
void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) override;
8787
void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) override;
8888
void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) override;
89-
void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) override;
89+
void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>) override;
9090
void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex, unsigned charLength) override;
9191

9292
// SpeechSynthesisClientObserver
9393
void didStartSpeaking() override;
9494
void didFinishSpeaking() override;
9595
void didPauseSpeaking() override;
9696
void didResumeSpeaking() override;
97-
void speakingErrorOccurred() override;
97+
void speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode>) override;
9898
void boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength) override;
9999
void voicesChanged() override;
100100

@@ -103,7 +103,7 @@ class SpeechSynthesis : public PlatformSpeechSynthesizerClient, public SpeechSyn
103103
bool virtualHasPendingActivity() const final;
104104

105105
void startSpeakingImmediately(SpeechSynthesisUtterance&);
106-
void handleSpeakingCompleted(SpeechSynthesisUtterance&, bool errorOccurred);
106+
void handleSpeakingCompleted(SpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>);
107107

108108
// EventTarget
109109
ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }

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
@@ -363,7 +363,7 @@ struct WebPageProxy::Internals final : WebPopupMenuProxy::Client
363363
void didFinishSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
364364
void didPauseSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
365365
void didResumeSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
366-
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&) final;
366+
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode>) final;
367367
void boundaryEventOccurred(WebCore::PlatformSpeechSynthesisUtterance&, WebCore::SpeechBoundary, unsigned characterIndex, unsigned characterLength) final;
368368

369369
// 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
@@ -249,6 +249,7 @@
249249
#include <WebCore/PlatformKeyboardEvent.h>
250250
#include <WebCore/PlatformMediaSessionManager.h>
251251
#include <WebCore/PlatformMouseEvent.h>
252+
#include <WebCore/PlatformSpeechSynthesizer.h>
252253
#include <WebCore/PlatformStrategies.h>
253254
#include <WebCore/PluginDocument.h>
254255
#include <WebCore/PointerCaptureController.h>
@@ -8302,10 +8303,12 @@ void WebPage::systemPreviewActionTriggered(WebCore::SystemPreviewInfo previewInf
83028303
#endif
83038304

83048305
#if ENABLE(SPEECH_SYNTHESIS)
8305-
void WebPage::speakingErrorOccurred()
8306+
void WebPage::speakingErrorOccurred(std::optional<uint8_t> error)
83068307
{
83078308
if (auto observer = corePage()->speechSynthesisClient()->observer())
8308-
observer->speakingErrorOccurred();
8309+
observer->speakingErrorOccurred(!error
8310+
? std::nullopt
8311+
: std::make_optional(static_cast<WebCore::SpeechSynthesisErrorCode>(*error)));
83098312
}
83108313

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

0 commit comments

Comments
 (0)