Changeset 151076 in webkit


Ignore:
Timestamp:
Jun 1, 2013 4:26:02 PM (11 years ago)
Author:
Darin Adler
Message:

window.speechSynthesis needs to be cheap
https://bugs.webkit.org/show_bug.cgi?id=117111
rdar://problem/14042030

Reviewed by Dean Jackson.

Add the traditional laziness to all of the speech synthesis code, wherever
it was omitted.

  • Modules/speech/SpeechSynthesis.cpp:

(WebCore::SpeechSynthesis::create): Tweaked style (took out unneeded parentheses).
(WebCore::SpeechSynthesis::SpeechSynthesis): Don't create m_platformSpeechSynthesizer.
(WebCore::SpeechSynthesis::setPlatformSynthesizer): Clear state when changing the
platform speech synthesizer. Since this code is only used to set up a mock in the
test runner, the fact that it was wrong before was harmless, but still not good.
(WebCore::SpeechSynthesis::getVoices): Create the platform speech synthesizer here
so we can get the voice list from it.
(WebCore::SpeechSynthesis::startSpeakingImmediately): Create the platform speech
synthesizer here.
(WebCore::SpeechSynthesis::cancel): Check the platform speech synthesizer for
null and do nothing if it's not present.
(WebCore::SpeechSynthesis::pause): Ditto.
(WebCore::SpeechSynthesis::resume): Ditto.

  • platform/PlatformSpeechSynthesizer.cpp:

(WebCore::PlatformSpeechSynthesizer::create): Don't call initializeVoiceList just
to create a synthesizer.
(WebCore::PlatformSpeechSynthesizer::voiceList): Do call initializeVoiceList once
when asked for a voice list.

  • platform/PlatformSpeechSynthesizer.h: The voiceList function is no longer inlined.

The unused setVoiceList function has been removed. The initializeVoiceList is now
private rather than protected. Added a new m_voiceListIsInitialized boolean.

  • platform/mac/PlatformSpeechSynthesizerMac.mm:

(WebCore::PlatformSpeechSynthesizer::PlatformSpeechSynthesizer): Initialize
m_voiceListIsInitialized to false.

  • platform/mock/PlatformSpeechSynthesizerMock.cpp:

(WebCore::PlatformSpeechSynthesizerMock::create): Don't call initializeVoiceList just
to create a synthesizer.
(WebCore::PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock):
Removed unneeded call to m_speakingFinishedTimer.stop() since timers automatically
stop when you destroy them.
(WebCore::PlatformSpeechSynthesizerMock::initializeVoiceList): Removed unneeded
call to m_voiceList.clear(), since the caller only calls this once when the
voice list is already clear.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r151072 r151076  
     12013-06-01  Darin Adler  <darin@apple.com>
     2
     3        window.speechSynthesis needs to be cheap
     4        https://bugs.webkit.org/show_bug.cgi?id=117111
     5        rdar://problem/14042030
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add the traditional laziness to all of the speech synthesis code, wherever
     10        it was omitted.
     11
     12        * Modules/speech/SpeechSynthesis.cpp:
     13        (WebCore::SpeechSynthesis::create): Tweaked style (took out unneeded parentheses).
     14        (WebCore::SpeechSynthesis::SpeechSynthesis): Don't create m_platformSpeechSynthesizer.
     15        (WebCore::SpeechSynthesis::setPlatformSynthesizer): Clear state when changing the
     16        platform speech synthesizer. Since this code is only used to set up a mock in the
     17        test runner, the fact that it was wrong before was harmless, but still not good.
     18        (WebCore::SpeechSynthesis::getVoices): Create the platform speech synthesizer here
     19        so we can get the voice list from it.
     20        (WebCore::SpeechSynthesis::startSpeakingImmediately): Create the platform speech
     21        synthesizer here.
     22        (WebCore::SpeechSynthesis::cancel): Check the platform speech synthesizer for
     23        null and do nothing if it's not present.
     24        (WebCore::SpeechSynthesis::pause): Ditto.
     25        (WebCore::SpeechSynthesis::resume): Ditto.
     26
     27        * platform/PlatformSpeechSynthesizer.cpp:
     28        (WebCore::PlatformSpeechSynthesizer::create): Don't call initializeVoiceList just
     29        to create a synthesizer.
     30        (WebCore::PlatformSpeechSynthesizer::voiceList): Do call initializeVoiceList once
     31        when asked for a voice list.
     32
     33        * platform/PlatformSpeechSynthesizer.h: The voiceList function is no longer inlined.
     34        The unused setVoiceList function has been removed. The initializeVoiceList is now
     35        private rather than protected. Added a new m_voiceListIsInitialized boolean.
     36
     37        * platform/mac/PlatformSpeechSynthesizerMac.mm:
     38        (WebCore::PlatformSpeechSynthesizer::PlatformSpeechSynthesizer): Initialize
     39        m_voiceListIsInitialized to false.
     40
     41        * platform/mock/PlatformSpeechSynthesizerMock.cpp:
     42        (WebCore::PlatformSpeechSynthesizerMock::create): Don't call initializeVoiceList just
     43        to create a synthesizer.
     44        (WebCore::PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock):
     45        Removed unneeded call to m_speakingFinishedTimer.stop() since timers automatically
     46        stop when you destroy them.
     47        (WebCore::PlatformSpeechSynthesizerMock::initializeVoiceList): Removed unneeded
     48        call to m_voiceList.clear(), since the caller only calls this once when the
     49        voice list is already clear.
     50
    1512013-06-01  Andreas Kling  <akling@apple.com>
    252
  • trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp

    r147801 r151076  
    3939PassRefPtr<SpeechSynthesis> SpeechSynthesis::create()
    4040{
    41     return adoptRef(new SpeechSynthesis());
     41    return adoptRef(new SpeechSynthesis);
    4242}
    4343   
    4444SpeechSynthesis::SpeechSynthesis()
    45     : m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this))
    46     , m_currentSpeechUtterance(0)
     45    : m_currentSpeechUtterance(0)
    4746    , m_isPaused(false)
    4847{
     
    5251{
    5352    m_platformSpeechSynthesizer = synthesizer;
     53    m_voiceList.clear();
     54    m_currentSpeechUtterance = 0;
     55    m_utteranceQueue.clear();
     56    m_isPaused = false;
    5457}
    5558   
     
    6366    if (m_voiceList.size())
    6467        return m_voiceList;
    65    
     68
     69    if (!m_platformSpeechSynthesizer)
     70        m_platformSpeechSynthesizer = PlatformSpeechSynthesizer::create(this);
     71
    6672    // If the voiceList is empty, that's the cue to get the voices from the platform again.
    6773    const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_platformSpeechSynthesizer->voiceList();
     
    98104    m_currentSpeechUtterance = utterance;
    99105    m_isPaused = false;
     106    if (!m_platformSpeechSynthesizer)
     107        m_platformSpeechSynthesizer = PlatformSpeechSynthesizer::create(this);
    100108    m_platformSpeechSynthesizer->speak(utterance->platformUtterance());
    101109}
     
    119127    RefPtr<SpeechSynthesisUtterance> current = m_currentSpeechUtterance;
    120128    m_utteranceQueue.clear();
    121     m_platformSpeechSynthesizer->cancel();
     129    if (m_platformSpeechSynthesizer)
     130        m_platformSpeechSynthesizer->cancel();
    122131    current = 0;
    123132   
     
    128137void SpeechSynthesis::pause()
    129138{
    130     if (!m_isPaused)
     139    if (!m_isPaused && m_platformSpeechSynthesizer)
    131140        m_platformSpeechSynthesizer->pause();
    132141}
     
    134143void SpeechSynthesis::resume()
    135144{
    136     if (!m_currentSpeechUtterance)
    137         return;
    138     m_platformSpeechSynthesizer->resume();
     145    if (m_currentSpeechUtterance && m_platformSpeechSynthesizer)
     146        m_platformSpeechSynthesizer->resume();
    139147}
    140148
  • trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.cpp

    r146724 r151076  
    3333PassOwnPtr<PlatformSpeechSynthesizer> PlatformSpeechSynthesizer::create(PlatformSpeechSynthesizerClient* client)
    3434{
    35     OwnPtr<PlatformSpeechSynthesizer> synthesizer = adoptPtr(new PlatformSpeechSynthesizer(client));
    36     synthesizer->initializeVoiceList();
    37     return synthesizer.release();
     35    return adoptPtr(new PlatformSpeechSynthesizer(client));
    3836}
    3937
    40 void PlatformSpeechSynthesizer::setVoiceList(Vector<RefPtr<PlatformSpeechSynthesisVoice> >& voices)
     38const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& PlatformSpeechSynthesizer::voiceList() const
    4139{
    42     m_voiceList = voices;
     40    if (!m_voiceListIsInitialized) {
     41        ASSERT(m_voiceList.isEmpty());
     42        const_cast<PlatformSpeechSynthesizer*>(this)->initializeVoiceList();
     43        const_cast<PlatformSpeechSynthesizer*>(this)->m_voiceListIsInitialized = true;
     44    }
     45    return m_voiceList;
    4346}
    44 
    4547
    4648} // namespace WebCore
  • trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h

    r147888 r151076  
    5959    virtual ~PlatformSpeechSynthesizerClient() { }
    6060};
    61    
     61
    6262class PlatformSpeechSynthesizer {
    6363public:
    6464    static PassOwnPtr<PlatformSpeechSynthesizer> create(PlatformSpeechSynthesizerClient*);
    6565
     66    // FIXME: We have multiple virtual functions just so we can support a mock for testing.
     67    // Seems wasteful. Would be nice to find a better way.
    6668    virtual ~PlatformSpeechSynthesizer();
    6769   
    68     const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& voiceList() const { return m_voiceList; }
     70    const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& voiceList() const;
    6971    virtual void speak(PassRefPtr<PlatformSpeechSynthesisUtterance>);
    7072    virtual void pause();
     
    7476    PlatformSpeechSynthesizerClient* client() const { return m_speechSynthesizerClient; }
    7577
    76     void setVoiceList(Vector<RefPtr<PlatformSpeechSynthesisVoice> >&);
     78protected:
     79    explicit PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient*);
    7780
    78 protected:
     81    Vector<RefPtr<PlatformSpeechSynthesisVoice> > m_voiceList;
     82
     83private:
    7984    virtual void initializeVoiceList();
    80     explicit PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient*);
    81     Vector<RefPtr<PlatformSpeechSynthesisVoice> > m_voiceList;
    82    
    83 private:
     85
     86    bool m_voiceListIsInitialized;
    8487    PlatformSpeechSynthesizerClient* m_speechSynthesizerClient;
    8588   
  • trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm

    r149342 r151076  
    202202
    203203PlatformSpeechSynthesizer::PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient* client)
    204     : m_speechSynthesizerClient(client)
     204    : m_voiceListIsInitialized(false)
     205    , m_speechSynthesizerClient(client)
    205206{
    206207}
  • trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp

    r146724 r151076  
    3434PassOwnPtr<PlatformSpeechSynthesizerMock> PlatformSpeechSynthesizerMock::create(PlatformSpeechSynthesizerClient* client)
    3535{
    36     OwnPtr<PlatformSpeechSynthesizerMock> synthesizer = adoptPtr(new PlatformSpeechSynthesizerMock(client));
    37     synthesizer->initializeVoiceList();
    38     return synthesizer.release();
     36    return adoptPtr(new PlatformSpeechSynthesizerMock(client));
    3937}
    4038   
     
    4745PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
    4846{
    49     m_speakingFinishedTimer.stop();
    5047}
    5148
     
    5956void PlatformSpeechSynthesizerMock::initializeVoiceList()
    6057{
    61     m_voiceList.clear();
    6258    m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.bruce"), String("bruce"), String("en-US"), true, true));
    6359    m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.clark"), String("clark"), String("en-US"), true, false));
     
    9995}
    10096
    101    
    10297} // namespace WebCore
    10398
Note: See TracChangeset for help on using the changeset viewer.