Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Side by Side Diff: Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp

Issue 180553004: Fix use-after-free of m_currentSpeechUtterance. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix nullptr again? Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/speech/testing/PlatformSpeechSynthesizerMock.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 24 matching lines...) Expand all
35 { 35 {
36 OwnPtr<PlatformSpeechSynthesizerMock> synthesizer = adoptPtr(new PlatformSpe echSynthesizerMock(client)); 36 OwnPtr<PlatformSpeechSynthesizerMock> synthesizer = adoptPtr(new PlatformSpe echSynthesizerMock(client));
37 synthesizer->initializeVoiceList(); 37 synthesizer->initializeVoiceList();
38 client->voicesDidChange(); 38 client->voicesDidChange();
39 return synthesizer.release(); 39 return synthesizer.release();
40 } 40 }
41 41
42 PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynth esizerClient* client) 42 PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynth esizerClient* client)
43 : PlatformSpeechSynthesizer(client) 43 : PlatformSpeechSynthesizer(client)
44 , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFini shed) 44 , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFini shed)
45 , m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakin gErrorOccurred)
45 { 46 {
46 } 47 }
47 48
48 PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock() 49 PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
49 { 50 {
50 m_speakingFinishedTimer.stop(); 51 m_speakingFinishedTimer.stop();
52 m_speakingErrorOccurredTimer.stop();
51 } 53 }
52 54
53 void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthes izerMock>*) 55 void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthes izerMock>*)
54 { 56 {
55 ASSERT(m_utterance.get()); 57 ASSERT(m_utterance.get());
56 client()->didFinishSpeaking(m_utterance); 58 client()->didFinishSpeaking(m_utterance);
57 m_utterance = nullptr; 59 m_utterance = nullptr;
58 } 60 }
59 61
62 void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSy nthesizerMock>*)
63 {
64 ASSERT(m_utterance.get());
65 client()->speakingErrorOccurred(m_utterance);
66 m_utterance = nullptr;
67 }
68
60 void PlatformSpeechSynthesizerMock::initializeVoiceList() 69 void PlatformSpeechSynthesizerMock::initializeVoiceList()
61 { 70 {
62 m_voiceList.clear(); 71 m_voiceList.clear();
63 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.b ruce"), String("bruce"), String("en-US"), true, true)); 72 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.b ruce"), String("bruce"), String("en-US"), true, true));
64 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.c lark"), String("clark"), String("en-US"), true, false)); 73 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.c lark"), String("clark"), String("en-US"), true, false));
65 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.l ogan"), String("logan"), String("fr-CA"), true, true)); 74 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.l ogan"), String("logan"), String("fr-CA"), true, true));
66 } 75 }
67 76
68 void PlatformSpeechSynthesizerMock::speak(PassRefPtr<PlatformSpeechSynthesisUtte rance> utterance) 77 void PlatformSpeechSynthesizerMock::speak(PassRefPtr<PlatformSpeechSynthesisUtte rance> utterance)
69 { 78 {
70 ASSERT(!m_utterance); 79 ASSERT(!m_utterance);
71 m_utterance = utterance; 80 m_utterance = utterance;
72 client()->didStartSpeaking(m_utterance); 81 client()->didStartSpeaking(m_utterance);
73 82
74 // Fire a fake word and then sentence boundary event. 83 // Fire a fake word and then sentence boundary event.
75 client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0); 84 client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0);
76 client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utter ance->text().length()); 85 client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utter ance->text().length());
77 86
78 // Give the fake speech job some time so that pause and other functions have time to be called. 87 // Give the fake speech job some time so that pause and other functions have time to be called.
79 m_speakingFinishedTimer.startOneShot(.1); 88 m_speakingFinishedTimer.startOneShot(.1);
80 } 89 }
81 90
82 void PlatformSpeechSynthesizerMock::cancel() 91 void PlatformSpeechSynthesizerMock::cancel()
83 { 92 {
84 if (!m_utterance) 93 if (!m_utterance)
85 return; 94 return;
86 95
87 m_speakingFinishedTimer.stop(); 96 m_speakingFinishedTimer.stop();
88 client()->speakingErrorOccurred(m_utterance); 97 m_speakingErrorOccurredTimer.startOneShot(.1);
89 m_utterance = nullptr;
90 } 98 }
91 99
92 void PlatformSpeechSynthesizerMock::pause() 100 void PlatformSpeechSynthesizerMock::pause()
93 { 101 {
94 client()->didPauseSpeaking(m_utterance); 102 client()->didPauseSpeaking(m_utterance);
95 } 103 }
96 104
97 void PlatformSpeechSynthesizerMock::resume() 105 void PlatformSpeechSynthesizerMock::resume()
98 { 106 {
99 client()->didResumeSpeaking(m_utterance); 107 client()->didResumeSpeaking(m_utterance);
100 } 108 }
101 109
102 110
103 } // namespace WebCore 111 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/speech/testing/PlatformSpeechSynthesizerMock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698