Skip to content

Commit b8c428d

Browse files
SconyPawel Lampe
authored andcommitted
Adapt speech synthesis changes from 2.28
- Add missing functions - Add proper error handling (similar to WebPlatformForEmbedded#823 with optional as in WebPlatformForEmbedded#875) for both UIProcess and WebProcess
1 parent 3c3b028 commit b8c428d

12 files changed

Lines changed: 79 additions & 21 deletions

File tree

Source/WebCore/Headers.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
321321
Modules/push-api/PushSubscriptionData.h
322322
Modules/push-api/PushSubscriptionIdentifier.h
323323

324+
Modules/speech/DOMWindowSpeechSynthesis.h
325+
Modules/speech/SpeechSynthesisErrorCode.h
326+
Modules/speech/SpeechSynthesisErrorEvent.h
327+
Modules/speech/SpeechSynthesisErrorEventInit.h
328+
Modules/speech/SpeechSynthesisEvent.h
329+
Modules/speech/SpeechSynthesisEventInit.h
330+
Modules/speech/SpeechSynthesis.h
331+
Modules/speech/SpeechSynthesisUtterance.h
332+
Modules/speech/SpeechSynthesisVoice.h
324333
Modules/speech/SpeechRecognitionCaptureSource.h
325334
Modules/speech/SpeechRecognitionCaptureSourceImpl.h
326335
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();
@@ -207,17 +207,17 @@ void SpeechSynthesis::fireErrorEvent(const AtomString& type, SpeechSynthesisUtte
207207
utterance.dispatchEvent(SpeechSynthesisErrorEvent::create(type, { { &utterance, 0, 0, static_cast<float>((MonotonicTime::now() - utterance.startTime()).seconds()), { } }, errorCode }));
208208
}
209209

210-
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, bool errorOccurred)
210+
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
211211
{
212212
ASSERT(m_currentSpeechUtterance);
213213
Ref<SpeechSynthesisUtterance> protect(utterance);
214214

215215
m_currentSpeechUtterance = nullptr;
216216

217-
if (errorOccurred)
218-
fireErrorEvent(eventNames().errorEvent, utterance, SpeechSynthesisErrorCode::Canceled);
219-
else
217+
if (!error)
220218
fireEvent(eventNames().endEvent, utterance, 0, 0, String());
219+
else
220+
fireErrorEvent(eventNames().errorEvent, utterance, *error);
221221

222222
if (m_utteranceQueue.size()) {
223223
Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst();
@@ -276,11 +276,11 @@ void SpeechSynthesis::didResumeSpeaking()
276276
didResumeSpeaking(*m_currentSpeechUtterance->platformUtterance());
277277
}
278278

279-
void SpeechSynthesis::speakingErrorOccurred()
279+
void SpeechSynthesis::speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode> error)
280280
{
281281
if (!m_currentSpeechUtterance)
282282
return;
283-
speakingErrorOccurred(*m_currentSpeechUtterance->platformUtterance());
283+
speakingErrorOccurred(*m_currentSpeechUtterance->platformUtterance(), error);
284284
}
285285

286286
void SpeechSynthesis::boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -318,13 +318,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
318318
void SpeechSynthesis::didFinishSpeaking(PlatformSpeechSynthesisUtterance& utterance)
319319
{
320320
if (utterance.client())
321-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), false);
321+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), std::nullopt);
322322
}
323323

324-
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance)
324+
void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error)
325325
{
326326
if (utterance.client())
327-
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), true);
327+
handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), error);
328328
}
329329

330330
} // namespace WebCore

Source/WebCore/Modules/speech/SpeechSynthesis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ class SpeechSynthesis : public PlatformSpeechSynthesizerClient, public SpeechSyn
7474
void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) override;
7575
void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) override;
7676
void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) override;
77-
void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) override;
77+
void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>) override;
7878
void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex, unsigned charLength) override;
7979

8080
// SpeechSynthesisClient override methods
8181
void didStartSpeaking() override;
8282
void didFinishSpeaking() override;
8383
void didPauseSpeaking() override;
8484
void didResumeSpeaking() override;
85-
void speakingErrorOccurred() override;
85+
void speakingErrorOccurred(std::optional<SpeechSynthesisErrorCode>) override;
8686
void boundaryEventOccurred(bool wordBoundary, unsigned charIndex, unsigned charLength) override;
8787
void voicesChanged() override;
8888

8989
void startSpeakingImmediately(SpeechSynthesisUtterance&);
90-
void handleSpeakingCompleted(SpeechSynthesisUtterance&, bool errorOccurred);
90+
void handleSpeakingCompleted(SpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>);
9191
void fireEvent(const AtomString& type, SpeechSynthesisUtterance&, unsigned long charIndex, unsigned long charLength, const String& name) const;
9292
void fireErrorEvent(const AtomString& type, SpeechSynthesisUtterance&, SpeechSynthesisErrorCode) const;
9393

Source/WebCore/Modules/speech/SpeechSynthesisErrorEventInit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#if ENABLE(SPEECH_SYNTHESIS)
2929

3030
#include "SpeechSynthesisEventInit.h"
31+
#include "SpeechSynthesisErrorCode.h"
3132

3233
namespace WebCore {
3334

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;
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#if ENABLE(SPEECH_SYNTHESIS)
3030

3131
#include "PlatformSpeechSynthesisVoice.h"
32+
#include "SpeechSynthesisErrorCode.h"
33+
#include <optional>
3234
#include <wtf/Vector.h>
3335

3436
#if PLATFORM(COCOA)
@@ -51,7 +53,7 @@ class PlatformSpeechSynthesizerClient {
5153
virtual void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
5254
virtual void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
5355
virtual void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) = 0;
54-
virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) = 0;
56+
virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&, std::optional<SpeechSynthesisErrorCode>) = 0;
5557
virtual void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex, unsigned charLength) = 0;
5658
virtual void voicesDidChange() = 0;
5759
protected:

Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void PlatformSpeechSynthesizerMock::cancel()
7575
return;
7676

7777
m_speakingFinishedTimer.stop();
78-
client()->speakingErrorOccurred(*m_utterance);
78+
client()->speakingErrorOccurred(*m_utterance, SpeechSynthesisErrorCode::Canceled);
7979
m_utterance = nullptr;
8080
}
8181

Source/WebKit/UIProcess/WebPageProxy.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11032,6 +11032,48 @@ void WebPageProxy::speechSynthesisResume(CompletionHandler<void()>&& completionH
1103211032
speechSynthesisData().speakingResumedCompletionHandler = WTFMove(completionHandler);
1103311033
speechSynthesisData().synthesizer->resume();
1103411034
}
11035+
11036+
void WebPageProxy::didStartSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
11037+
{
11038+
if (speechSynthesisData().speakingStartedCompletionHandler)
11039+
speechSynthesisData().speakingStartedCompletionHandler();
11040+
}
11041+
11042+
void WebPageProxy::didFinishSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
11043+
{
11044+
if (speechSynthesisData().speakingFinishedCompletionHandler)
11045+
speechSynthesisData().speakingFinishedCompletionHandler();
11046+
}
11047+
11048+
void WebPageProxy::didPauseSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
11049+
{
11050+
if (speechSynthesisData().speakingPausedCompletionHandler)
11051+
speechSynthesisData().speakingPausedCompletionHandler();
11052+
}
11053+
11054+
void WebPageProxy::didResumeSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
11055+
{
11056+
if (speechSynthesisData().speakingResumedCompletionHandler)
11057+
speechSynthesisData().speakingResumedCompletionHandler();
11058+
}
11059+
11060+
void WebPageProxy::speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode> error)
11061+
{
11062+
if (!error)
11063+
send(Messages::WebPage::SpeakingErrorOccurred(std::numeric_limits<uint8_t>::max()));
11064+
else
11065+
send(Messages::WebPage::SpeakingErrorOccurred(static_cast<uint8_t>(*error)));
11066+
}
11067+
11068+
void WebPageProxy::boundaryEventOccurred(WebCore::PlatformSpeechSynthesisUtterance&, WebCore::SpeechBoundary speechBoundary, unsigned charIndex, unsigned charLength)
11069+
{
11070+
send(Messages::WebPage::BoundaryEventOccurred(speechBoundary == WebCore::SpeechBoundary::SpeechWordBoundary, charIndex, charLength));
11071+
}
11072+
11073+
void WebPageProxy::voicesDidChange()
11074+
{
11075+
send(Messages::WebPage::VoicesDidChange());
11076+
}
1103511077
#endif // ENABLE(SPEECH_SYNTHESIS)
1103611078

1103711079
#if !PLATFORM(IOS_FAMILY)

Source/WebKit/UIProcess/WebPageProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
26622662
void didFinishSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
26632663
void didPauseSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
26642664
void didResumeSpeaking(WebCore::PlatformSpeechSynthesisUtterance&) final;
2665-
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&) final;
2665+
void speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&, std::optional<WebCore::SpeechSynthesisErrorCode>) final;
26662666
void boundaryEventOccurred(WebCore::PlatformSpeechSynthesisUtterance&, WebCore::SpeechBoundary, unsigned charIndex, unsigned charLength) final;
26672667
void voicesDidChange() final;
26682668

Source/WebKit/WebProcess/WebPage/WebPage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
#include <WebCore/PingLoader.h>
222222
#include <WebCore/PlatformKeyboardEvent.h>
223223
#include <WebCore/PlatformMediaSessionManager.h>
224+
#include <WebCore/PlatformSpeechSynthesizer.h>
224225
#include <WebCore/PlatformStrategies.h>
225226
#include <WebCore/PluginDocument.h>
226227
#include <WebCore/PointerCaptureController.h>
@@ -7481,10 +7482,12 @@ void WebPage::systemPreviewActionTriggered(WebCore::SystemPreviewInfo previewInf
74817482
#endif
74827483

74837484
#if ENABLE(SPEECH_SYNTHESIS)
7484-
void WebPage::speakingErrorOccurred()
7485+
void WebPage::speakingErrorOccurred(uint8_t error)
74857486
{
74867487
if (auto observer = corePage()->speechSynthesisClient()->observer())
7487-
observer->speakingErrorOccurred();
7488+
observer->speakingErrorOccurred(error == std::numeric_limits<uint8_t>::max()
7489+
? std::nullopt
7490+
: std::make_optional(static_cast<WebCore::SpeechSynthesisErrorCode>(error)));
74887491
}
74897492

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

0 commit comments

Comments
 (0)