Skip to content

Commit 78d7d65

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 4538b59 commit 78d7d65

File tree

12 files changed

+42
-25
lines changed

12 files changed

+42
-25
lines changed

Source/WebCore/Headers.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,16 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
607607
Modules/reporting/TestReportBody.h
608608
Modules/reporting/ViolationReportType.h
609609

610+
Modules/speech/LocalDOMWindowSpeechSynthesis.h
611+
Modules/speech/SpeechSynthesisErrorCode.h
612+
Modules/speech/SpeechSynthesisErrorEvent.h
613+
Modules/speech/SpeechSynthesisErrorEventInit.h
614+
Modules/speech/SpeechSynthesisEvent.h
615+
Modules/speech/SpeechSynthesisEventInit.h
616+
Modules/speech/SpeechSynthesis.h
617+
Modules/speech/SpeechSynthesisUtterance.h
618+
Modules/speech/SpeechSynthesisVoice.h
619+
610620
Modules/speech/SpeechRecognitionCaptureSource.h
611621
Modules/speech/SpeechRecognitionCaptureSourceImpl.h
612622
Modules/speech/SpeechRecognitionConnection.h

Source/WebCore/Modules/speech/SpeechSynthesis.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void SpeechSynthesis::setPlatformSynthesizer(Ref<PlatformSpeechSynthesizer>&& sy
8787
m_voiceList = std::nullopt;
8888
m_utteranceQueue.clear();
8989
// Finish current utterance.
90-
speakingErrorOccurred();
90+
speakingErrorOccurred(SpeechSynthesisErrorCode::Canceled);
9191
m_isPaused = false;
9292
m_speechSynthesisClient = nullptr;
9393
}
@@ -193,7 +193,7 @@ void SpeechSynthesis::cancel()
193193
speechSynthesisClient->cancel();
194194
// If we wait for cancel to callback speakingErrorOccurred, then m_currentSpeechUtterance will be null
195195
// and the event won't be processed. Instead we process the error immediately.
196-
speakingErrorOccurred();
196+
speakingErrorOccurred(SpeechSynthesisErrorCode::Canceled);
197197
m_currentSpeechUtterance = nullptr;
198198
} else if (RefPtr platformSpeechSynthesizer = m_platformSpeechSynthesizer)
199199
platformSpeechSynthesizer->cancel();
@@ -229,18 +229,18 @@ void SpeechSynthesis::resumeSynthesis()
229229
}
230230
}
231231

232-
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, bool errorOccurred)
232+
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
233233
{
234234
ASSERT(m_currentSpeechUtterance);
235235
Ref<SpeechSynthesisUtterance> protect(utterance);
236236

237237
m_currentSpeechUtterance = nullptr;
238238

239-
if (errorOccurred)
240-
utterance.errorEventOccurred(eventNames().errorEvent, SpeechSynthesisErrorCode::Canceled);
239+
if (error)
240+
utterance.errorEventOccurred(eventNames().errorEvent, *error);
241241
else
242242
utterance.eventOccurred(eventNames().endEvent, 0, 0, String());
243-
243+
244244
if (m_utteranceQueue.size()) {
245245
Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst();
246246
ASSERT(&utterance == firstUtterance.ptr());
@@ -299,11 +299,11 @@ void SpeechSynthesis::didResumeSpeaking()
299299
didResumeSpeaking(protectedCurrentSpeechUtterance()->platformUtterance());
300300
}
301301

302-
void SpeechSynthesis::speakingErrorOccurred()
302+
void SpeechSynthesis::speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode> error)
303303
{
304304
if (!m_currentSpeechUtterance)
305305
return;
306-
speakingErrorOccurred(protectedCurrentSpeechUtterance()->platformUtterance());
306+
speakingErrorOccurred(protectedCurrentSpeechUtterance()->platformUtterance(), error);
307307
}
308308

309309
void SpeechSynthesis::boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -341,13 +341,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
341341
void SpeechSynthesis::didFinishSpeaking(PlatformSpeechSynthesisUtterance& utterance)
342342
{
343343
if (utterance.client())
344-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), false);
344+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), std::nullopt);
345345
}
346346

347-
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance)
347+
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
348348
{
349349
if (utterance.client())
350-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), true);
350+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), error);
351351
}
352352

353353
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,23 +86,23 @@ 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

101101
// ActiveDOMObject
102102
bool virtualHasPendingActivity() const final;
103103

104104
void startSpeakingImmediately(SpeechSynthesisUtterance&);
105-
void handleSpeakingCompleted(SpeechSynthesisUtterance&, bool errorOccurred);
105+
void handleSpeakingCompleted(SpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>);
106106

107107
// EventTarget
108108
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 AbstractRefCountedAndCanMakeWeakPtr<SpeechSynthesisClient> {
3940
public:
@@ -59,7 +60,7 @@ class SpeechSynthesisClientObserver : public AbstractRefCountedAndCanMakeWeakPtr
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#if ENABLE(SPEECH_SYNTHESIS)
2929

3030
#include "PlatformSpeechSynthesisVoice.h"
31+
#include "SpeechSynthesisErrorCode.h"
32+
#include <optional>
3133
#include <wtf/RefCountedAndCanMakeWeakPtr.h>
3234
#include <wtf/RefPtr.h>
3335
#include <wtf/TZoneMalloc.h>
@@ -60,7 +62,7 @@ class PlatformSpeechSynthesizerClient {
6062
virtual void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
6163
virtual void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
6264
virtual void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
63-
virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) = 0;
65+
virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>) = 0;
6466
virtual void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex, unsigned charLength) = 0;
6567
virtual void voicesDidChange() = 0;
6668
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
RefPtr 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
@@ -527,7 +527,7 @@ struct WebPageProxy::Internals final : WebPopupMenuProxy::Client
527527
void didFinishSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
528528
void didPauseSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
529529
void didResumeSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
530-
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&) final;
530+
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode>) final;
531531
void boundaryEventOccurred(WebCore::PlatformSpeechSynthesisUtterance&, WebCore::SpeechBoundary, unsigned characterIndex, unsigned characterLength) final;
532532

533533
// PlatformSpeechSynthesizerClient

Source/WebKit/UIProcess/gstreamer/WebPageProxyGStreamer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ void WebPageProxy::Internals::didResumeSpeaking(WebCore::PlatformSpeechSynthesis
5959
handler();
6060
}
6161

62-
void WebPageProxy::Internals::speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&)
62+
void WebPageProxy::Internals::speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode> error)
6363
{
6464
Ref protectedPage = page.get();
65-
protectedPage->protectedLegacyMainFrameProcess()->send(Messages::WebPage::SpeakingErrorOccurred(), protectedPage->webPageIDInMainFrameProcess());
65+
if (!error)
66+
protectedPage.legacyMainFrameProcess().send(Messages::WebPage::SpeakingErrorOccurred(std::nullopt), protectedPage.webPageIDInMainFrameProcess());
67+
else
68+
protectedPage.legacyMainFrameProcess().send(Messages::WebPage::SpeakingErrorOccurred(static_cast<uint8_t>(*error)), protectedPage.webPageIDInMainFrameProcess());
6669
}
6770

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

Source/WebKit/WebProcess/WebPage/WebPage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
#include <WebCore/PlatformKeyboardEvent.h>
266266
#include <WebCore/PlatformMediaSessionManager.h>
267267
#include <WebCore/PlatformMouseEvent.h>
268+
#include <WebCore/PlatformSpeechSynthesizer.h>
268269
#include <WebCore/PlatformStrategies.h>
269270
#include <WebCore/PluginDocument.h>
270271
#include <WebCore/PointerCaptureController.h>
@@ -8810,10 +8811,10 @@ void WebPage::systemPreviewActionTriggered(WebCore::SystemPreviewInfo previewInf
88108811
#endif
88118812

88128813
#if ENABLE(SPEECH_SYNTHESIS)
8813-
void WebPage::speakingErrorOccurred()
8814+
void WebPage::speakingErrorOccurred(std::optional<uint8_t> error)
88148815
{
88158816
if (auto observer = protectedCorePage()->speechSynthesisClient()->observer())
8816-
observer->speakingErrorOccurred();
8817+
observer->speakingErrorOccurred(!error ? std::nullopt : std::make_optional(static_cast<WebCore::SpeechSynthesisErrorCode>(*error)));
88178818
}
88188819

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

0 commit comments

Comments
 (0)