Title: [247755] trunk/Source
Revision
247755
Author
[email protected]
Date
2019-07-23 16:24:58 -0700 (Tue, 23 Jul 2019)

Log Message

AX: CrashTracer: com.apple.WebKit.WebContent at WebKit: WebKit::WebSpeechSynthesisClient::speak
https://bugs.webkit.org/show_bug.cgi?id=199988

Reviewed by Per Arne Vollan.

Source/WebCore:

Implement the reset state to cancel current speech jobs.

* Modules/speech/SpeechSynthesis.cpp:
(WebCore::SpeechSynthesis::startSpeakingImmediately):
(WebCore::SpeechSynthesis::cancel):
* platform/PlatformSpeechSynthesizer.h:
* platform/ios/PlatformSpeechSynthesizerIOS.mm:
(WebCore::PlatformSpeechSynthesizer::resetState):
* platform/mac/PlatformSpeechSynthesizerMac.mm:
(WebCore::PlatformSpeechSynthesizer::resetState):

Source/WebKit:

Improvements to WebSpeechSynthesis to avoid crashing and improve correctness.
- Reset and cancel speech jobs on page close or reload (otherwise the synthesizer keeps talking after your page is gone)
- Have a separate speech finish callback mechanism, use the start speaking callback when the synthesizer tells us.
- Move an assert on utterance state to only apply when we use the in process synthesizer.

* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::didStartSpeaking):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::reload):
(WebKit::WebPageProxy::resetState):
(WebKit::WebPageProxy::resetSpeechSynthesizer):
(WebKit::WebPageProxy::speechSynthesisSetFinishedCallback):
(WebKit::WebPageProxy::speechSynthesisSpeak):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebSpeechSynthesisClient.cpp:
(WebKit::WebSpeechSynthesisClient::speak):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (247754 => 247755)


--- trunk/Source/WebCore/ChangeLog	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebCore/ChangeLog	2019-07-23 23:24:58 UTC (rev 247755)
@@ -1,3 +1,21 @@
+2019-07-23  Chris Fleizach  <[email protected]>
+
+        AX: CrashTracer: com.apple.WebKit.WebContent at WebKit: WebKit::WebSpeechSynthesisClient::speak
+        https://bugs.webkit.org/show_bug.cgi?id=199988
+
+        Reviewed by Per Arne Vollan.
+
+        Implement the reset state to cancel current speech jobs.
+
+        * Modules/speech/SpeechSynthesis.cpp:
+        (WebCore::SpeechSynthesis::startSpeakingImmediately):
+        (WebCore::SpeechSynthesis::cancel):
+        * platform/PlatformSpeechSynthesizer.h:
+        * platform/ios/PlatformSpeechSynthesizerIOS.mm:
+        (WebCore::PlatformSpeechSynthesizer::resetState):
+        * platform/mac/PlatformSpeechSynthesizerMac.mm:
+        (WebCore::PlatformSpeechSynthesizer::resetState):
+
 2019-07-23  Zalan Bujtas  <[email protected]>
 
         [iOS] Tapping the search field on a search results page on zillow.com shows and immediately dismisses the keyboard

Modified: trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp (247754 => 247755)


--- trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp	2019-07-23 23:24:58 UTC (rev 247755)
@@ -110,7 +110,6 @@
 
 void SpeechSynthesis::startSpeakingImmediately(SpeechSynthesisUtterance& utterance)
 {
-    ASSERT(!m_currentSpeechUtterance);
     utterance.setStartTime(MonotonicTime::now());
     m_currentSpeechUtterance = &utterance;
     m_isPaused = false;
@@ -152,12 +151,12 @@
     m_utteranceQueue.clear();
     if (m_speechSynthesisClient)
         m_speechSynthesisClient->cancel();
-    else if (m_platformSpeechSynthesizer)
+    else if (m_platformSpeechSynthesizer) {
         m_platformSpeechSynthesizer->cancel();
+        // The platform should have called back immediately and cleared the current utterance.
+        ASSERT(!m_currentSpeechUtterance);
+    }
     current = nullptr;
-
-    // The platform should have called back immediately and cleared the current utterance.
-    ASSERT(!m_currentSpeechUtterance);
 }
 
 void SpeechSynthesis::pause()

Modified: trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h (247754 => 247755)


--- trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h	2019-07-23 23:24:58 UTC (rev 247755)
@@ -73,6 +73,7 @@
     virtual void resume();
     virtual void cancel();
 
+    void resetState();
     PlatformSpeechSynthesizerClient* client() const { return m_speechSynthesizerClient; }
 
 protected:

Modified: trunk/Source/WebCore/platform/ios/PlatformSpeechSynthesizerIOS.mm (247754 => 247755)


--- trunk/Source/WebCore/platform/ios/PlatformSpeechSynthesizerIOS.mm	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebCore/platform/ios/PlatformSpeechSynthesizerIOS.mm	2019-07-23 23:24:58 UTC (rev 247755)
@@ -291,6 +291,11 @@
     [m_platformSpeechWrapper.get() cancel];
 }
 
+void PlatformSpeechSynthesizer::resetState()
+{
+    [m_platformSpeechWrapper.get() cancel];
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SPEECH_SYNTHESIS) && PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm (247754 => 247755)


--- trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm	2019-07-23 23:24:58 UTC (rev 247755)
@@ -277,6 +277,11 @@
     [m_platformSpeechWrapper.get() cancel];
 }
 
+void PlatformSpeechSynthesizer::resetState()
+{
+    [m_platformSpeechWrapper.get() cancel];
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SPEECH_SYNTHESIS) && PLATFORM(MAC)

Modified: trunk/Source/WebKit/ChangeLog (247754 => 247755)


--- trunk/Source/WebKit/ChangeLog	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebKit/ChangeLog	2019-07-23 23:24:58 UTC (rev 247755)
@@ -1,3 +1,28 @@
+2019-07-23  Chris Fleizach  <[email protected]>
+
+        AX: CrashTracer: com.apple.WebKit.WebContent at WebKit: WebKit::WebSpeechSynthesisClient::speak
+        https://bugs.webkit.org/show_bug.cgi?id=199988
+
+        Reviewed by Per Arne Vollan.
+
+        Improvements to WebSpeechSynthesis to avoid crashing and improve correctness.
+        - Reset and cancel speech jobs on page close or reload (otherwise the synthesizer keeps talking after your page is gone)
+        - Have a separate speech finish callback mechanism, use the start speaking callback when the synthesizer tells us.
+        - Move an assert on utterance state to only apply when we use the in process synthesizer.
+
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::didStartSpeaking):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::reload):
+        (WebKit::WebPageProxy::resetState):
+        (WebKit::WebPageProxy::resetSpeechSynthesizer):
+        (WebKit::WebPageProxy::speechSynthesisSetFinishedCallback):
+        (WebKit::WebPageProxy::speechSynthesisSpeak):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebSpeechSynthesisClient.cpp:
+        (WebKit::WebSpeechSynthesisClient::speak):
+
 2019-07-23  Chris Dumez  <[email protected]>
 
         Get rid of unnecessary callback aggregators in WebResourceLoadStatisticsStore

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (247754 => 247755)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2019-07-23 23:24:58 UTC (rev 247755)
@@ -258,21 +258,26 @@
 #if ENABLE(SPEECH_SYNTHESIS)
 void WebPageProxy::didStartSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
 {
+    if (speechSynthesisData().speakingStartedCompletionHandler)
+        speechSynthesisData().speakingStartedCompletionHandler();
 }
 
 void WebPageProxy::didFinishSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
 {
-    m_speechSynthesisData->speakingFinishedCompletionHandler();
+    if (speechSynthesisData().speakingFinishedCompletionHandler)
+        speechSynthesisData().speakingFinishedCompletionHandler();
 }
 
 void WebPageProxy::didPauseSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
 {
-    m_speechSynthesisData->speakingPausedCompletionHandler();
+    if (speechSynthesisData().speakingPausedCompletionHandler)
+        speechSynthesisData().speakingPausedCompletionHandler();
 }
 
 void WebPageProxy::didResumeSpeaking(WebCore::PlatformSpeechSynthesisUtterance&)
 {
-    m_speechSynthesisData->speakingResumedCompletionHandler();
+    if (speechSynthesisData().speakingResumedCompletionHandler)
+        speechSynthesisData().speakingResumedCompletionHandler();
 }
 
 void WebPageProxy::speakingErrorOccurred(WebCore::PlatformSpeechSynthesisUtterance&)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (247754 => 247755)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-07-23 23:24:58 UTC (rev 247755)
@@ -1359,6 +1359,10 @@
     m_process->send(Messages::WebPage::Reload(navigation->navigationID(), options.toRaw(), sandboxExtensionHandle), m_pageID);
     m_process->responsivenessTimer().start();
 
+#if ENABLE(SPEECH_SYNTHESIS)
+    resetSpeechSynthesizer();
+#endif
+
     return navigation;
 }
 
@@ -7053,6 +7057,10 @@
 #if ENABLE(POINTER_LOCK)
     requestPointerUnlock();
 #endif
+    
+#if ENABLE(SPEECH_SYNTHESIS)
+    resetSpeechSynthesizer();
+#endif
 }
 
 void WebPageProxy::resetStateAfterProcessExited(ProcessTerminationReason terminationReason)
@@ -9126,10 +9134,25 @@
 }
 
 #if ENABLE(SPEECH_SYNTHESIS)
+
+void WebPageProxy::resetSpeechSynthesizer()
+{
+    if (!m_speechSynthesisData)
+        return;
+    
+    auto& synthesisData = speechSynthesisData();
+    synthesisData.speakingFinishedCompletionHandler = nullptr;
+    synthesisData.speakingStartedCompletionHandler = nullptr;
+    synthesisData.speakingPausedCompletionHandler = nullptr;
+    synthesisData.speakingResumedCompletionHandler = nullptr;
+    if (synthesisData.synthesizer)
+        synthesisData.synthesizer->resetState();
+}
+
 WebPageProxy::SpeechSynthesisData& WebPageProxy::speechSynthesisData()
 {
     if (!m_speechSynthesisData)
-        m_speechSynthesisData = SpeechSynthesisData { std::make_unique<PlatformSpeechSynthesizer>(this), nullptr, nullptr, nullptr, nullptr };
+        m_speechSynthesisData = SpeechSynthesisData { std::make_unique<PlatformSpeechSynthesizer>(this), nullptr, nullptr, nullptr, nullptr, nullptr };
     return *m_speechSynthesisData;
 }
 
@@ -9143,6 +9166,11 @@
     completionHandler(WTFMove(result));
 }
 
+void WebPageProxy::speechSynthesisSetFinishedCallback(CompletionHandler<void()>&& completionHandler)
+{
+    speechSynthesisData().speakingFinishedCompletionHandler = WTFMove(completionHandler);
+}
+
 void WebPageProxy::speechSynthesisSpeak(const String& text, const String& lang, float volume, float rate, float pitch, MonotonicTime startTime, const String& voiceURI, const String& voiceName, const String& voiceLang, bool localService, bool defaultVoice, CompletionHandler<void()>&& completionHandler)
 {
     auto voice = WebCore::PlatformSpeechSynthesisVoice::create(voiceURI, voiceName, voiceLang, localService, defaultVoice);
@@ -9154,8 +9182,8 @@
     utterance->setPitch(pitch);
     utterance->setVoice(&voice.get());
 
+    speechSynthesisData().speakingStartedCompletionHandler = WTFMove(completionHandler);
     speechSynthesisData().utterance = WTFMove(utterance);
-    speechSynthesisData().speakingFinishedCompletionHandler = WTFMove(completionHandler);
     speechSynthesisData().synthesizer->speak(m_speechSynthesisData->utterance.get());
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (247754 => 247755)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2019-07-23 23:24:58 UTC (rev 247755)
@@ -1533,6 +1533,7 @@
 #if ENABLE(SPEECH_SYNTHESIS)
     void speechSynthesisVoiceList(CompletionHandler<void(Vector<WebSpeechSynthesisVoice>&&)>&&);
     void speechSynthesisSpeak(const String&, const String&, float volume, float rate, float pitch, MonotonicTime startTime, const String& voiceURI, const String& voiceName, const String& voiceLang, bool localService, bool defaultVoice, CompletionHandler<void()>&&);
+    void speechSynthesisSetFinishedCallback(CompletionHandler<void()>&&);
     void speechSynthesisCancel();
     void speechSynthesisPause(CompletionHandler<void()>&&);
     void speechSynthesisResume(CompletionHandler<void()>&&);
@@ -2096,6 +2097,7 @@
 
     struct SpeechSynthesisData;
     SpeechSynthesisData& speechSynthesisData();
+    void resetSpeechSynthesizer();
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -2533,6 +2535,7 @@
     struct SpeechSynthesisData {
         std::unique_ptr<WebCore::PlatformSpeechSynthesizer> synthesizer;
         RefPtr<WebCore::PlatformSpeechSynthesisUtterance> utterance;
+        CompletionHandler<void()> speakingStartedCompletionHandler;
         CompletionHandler<void()> speakingFinishedCompletionHandler;
         CompletionHandler<void()> speakingPausedCompletionHandler;
         CompletionHandler<void()> speakingResumedCompletionHandler;

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (247754 => 247755)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2019-07-23 23:24:58 UTC (rev 247755)
@@ -558,6 +558,7 @@
 #if ENABLE(SPEECH_SYNTHESIS)
     SpeechSynthesisVoiceList() -> (Vector<WebKit::WebSpeechSynthesisVoice> voiceList) Synchronous
     SpeechSynthesisSpeak(String text, String lang, float volume, float rate, float pitch, MonotonicTime startTime, String voiceURI, String voiceName, String voiceLang, bool localService, bool defaultVoice) -> () Async
+    SpeechSynthesisSetFinishedCallback() -> () Async
     SpeechSynthesisCancel()
     SpeechSynthesisPause() -> () Async
     SpeechSynthesisResume() -> () Async

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebSpeechSynthesisClient.cpp (247754 => 247755)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebSpeechSynthesisClient.cpp	2019-07-23 23:01:26 UTC (rev 247754)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebSpeechSynthesisClient.cpp	2019-07-23 23:24:58 UTC (rev 247755)
@@ -57,10 +57,17 @@
 
 void WebSpeechSynthesisClient::speak(RefPtr<WebCore::PlatformSpeechSynthesisUtterance> utterance)
 {
-    WTF::CompletionHandler<void()> completionHandler = [this, weakThis = makeWeakPtr(*this)]() mutable {
+    WTF::CompletionHandler<void()> startedCompletionHandler = [this, weakThis = makeWeakPtr(*this)]() mutable {
         if (!weakThis)
             return;
         if (auto observer = corePageObserver())
+            observer->didStartSpeaking();
+    };
+
+    WTF::CompletionHandler<void()> finishedCompletionHandler = [this, weakThis = makeWeakPtr(*this)]() mutable {
+        if (!weakThis)
+            return;
+        if (auto observer = corePageObserver())
             observer->didFinishSpeaking();
     };
 
@@ -70,10 +77,9 @@
     auto lang = voice ? voice->lang() : "";
     auto localService = voice ? voice->localService() : false;
     auto isDefault = voice ? voice->isDefault() : false;
-
-    m_page.sendWithAsyncReply(Messages::WebPageProxy::SpeechSynthesisSpeak(utterance->text(), utterance->lang(), utterance->volume(), utterance->rate(), utterance->pitch(), utterance->startTime(), voiceURI, name, lang, localService, isDefault), WTFMove(completionHandler));
-    if (auto observer = corePageObserver())
-        observer->didStartSpeaking();
+    
+    m_page.sendWithAsyncReply(Messages::WebPageProxy::SpeechSynthesisSetFinishedCallback(), WTFMove(finishedCompletionHandler));
+    m_page.sendWithAsyncReply(Messages::WebPageProxy::SpeechSynthesisSpeak(utterance->text(), utterance->lang(), utterance->volume(), utterance->rate(), utterance->pitch(), utterance->startTime(), voiceURI, name, lang, localService, isDefault), WTFMove(startedCompletionHandler));
 }
 
 void WebSpeechSynthesisClient::cancel()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to