Bug 1225928 - Fix hang on linux when sending an empty string to speech synth. r=smaug

This commit is contained in:
Eitan Isaacson 2015-11-30 18:59:01 -08:00
parent f010e62608
commit 9f7f51dcaa

View File

@ -493,14 +493,26 @@ SpeechDispatcherService::Speak(const nsAString& aText, const nsAString& aUri,
return rv;
}
int msg_id = spd_say(mSpeechdClient, SPD_MESSAGE, NS_ConvertUTF16toUTF8(aText).get());
if (aText.Length()) {
int msg_id = spd_say(
mSpeechdClient, SPD_MESSAGE, NS_ConvertUTF16toUTF8(aText).get());
if (msg_id < 0) {
return NS_ERROR_FAILURE;
if (msg_id < 0) {
return NS_ERROR_FAILURE;
}
mCallbacks.Put(msg_id, callback);
} else {
// Speech dispatcher does not work well with empty strings.
// In that case, don't send empty string to speechd,
// and just emulate a speechd start and end event.
NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs<SPDNotificationType>(
callback, &SpeechDispatcherCallback::OnSpeechEvent, SPD_EVENT_BEGIN));
NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs<SPDNotificationType>(
callback, &SpeechDispatcherCallback::OnSpeechEvent, SPD_EVENT_END));
}
mCallbacks.Put(msg_id, callback);
return NS_OK;
}