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

Side by Side Diff: Source/modules/speech/SpeechSynthesis.cpp

Issue 163493003: Revert of Move speech module over to Oilpan. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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/SpeechSynthesis.h ('k') | Source/modules/speech/SpeechSynthesis.idl » ('j') | 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 Inc. All rights reserved. 2 * Copyright (C) 2013 Apple 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 16 matching lines...) Expand all
27 #include "modules/speech/SpeechSynthesis.h" 27 #include "modules/speech/SpeechSynthesis.h"
28 28
29 #include "bindings/v8/ExceptionState.h" 29 #include "bindings/v8/ExceptionState.h"
30 #include "core/dom/ExecutionContext.h" 30 #include "core/dom/ExecutionContext.h"
31 #include "modules/speech/SpeechSynthesisEvent.h" 31 #include "modules/speech/SpeechSynthesisEvent.h"
32 #include "platform/speech/PlatformSpeechSynthesisVoice.h" 32 #include "platform/speech/PlatformSpeechSynthesisVoice.h"
33 #include "wtf/CurrentTime.h" 33 #include "wtf/CurrentTime.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 DEFINE_GC_INFO(SpeechSynthesis); 37 PassRefPtr<SpeechSynthesis> SpeechSynthesis::create(ExecutionContext* context)
38
39 PassRefPtrWillBeRawPtr<SpeechSynthesis> SpeechSynthesis::create(ExecutionContext * context)
40 { 38 {
41 return adoptRefCountedWillBeRefCountedGarbageCollected(new SpeechSynthesis(c ontext)); 39 return adoptRef(new SpeechSynthesis(context));
42 } 40 }
43 41
44 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context) 42 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context)
45 : ContextLifecycleObserver(context) 43 : ContextLifecycleObserver(context)
46 , m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)) 44 , m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this))
47 , m_currentSpeechUtterance(0) 45 , m_currentSpeechUtterance(0)
48 , m_isPaused(false) 46 , m_isPaused(false)
49 { 47 {
50 ScriptWrappable::init(this); 48 ScriptWrappable::init(this);
51 } 49 }
52 50
53 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize r> synthesizer) 51 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize r> synthesizer)
54 { 52 {
55 m_platformSpeechSynthesizer = synthesizer; 53 m_platformSpeechSynthesizer = synthesizer;
56 } 54 }
57 55
58 ExecutionContext* SpeechSynthesis::executionContext() const 56 ExecutionContext* SpeechSynthesis::executionContext() const
59 { 57 {
60 return ContextLifecycleObserver::executionContext(); 58 return ContextLifecycleObserver::executionContext();
61 } 59 }
62 60
63 void SpeechSynthesis::voicesDidChange() 61 void SpeechSynthesis::voicesDidChange()
64 { 62 {
65 m_voiceList.clear(); 63 m_voiceList.clear();
66 if (!executionContext()->activeDOMObjectsAreStopped()) 64 if (!executionContext()->activeDOMObjectsAreStopped())
67 dispatchEvent(Event::create(EventTypeNames::voiceschanged)); 65 dispatchEvent(Event::create(EventTypeNames::voiceschanged));
68 } 66 }
69 67
70 const WillBeHeapVector<RefPtrWillBeMember<SpeechSynthesisVoice> >& SpeechSynthes is::getVoices() 68 const Vector<RefPtr<SpeechSynthesisVoice> >& SpeechSynthesis::getVoices()
71 { 69 {
72 if (m_voiceList.size()) 70 if (m_voiceList.size())
73 return m_voiceList; 71 return m_voiceList;
74 72
75 // If the voiceList is empty, that's the cue to get the voices from the plat form again. 73 // If the voiceList is empty, that's the cue to get the voices from the plat form again.
76 const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_plat formSpeechSynthesizer->voiceList(); 74 const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_plat formSpeechSynthesizer->voiceList();
77 size_t voiceCount = platformVoices.size(); 75 size_t voiceCount = platformVoices.size();
78 for (size_t k = 0; k < voiceCount; k++) 76 for (size_t k = 0; k < voiceCount; k++)
79 m_voiceList.append(SpeechSynthesisVoice::create(platformVoices[k])); 77 m_voiceList.append(SpeechSynthesisVoice::create(platformVoices[k]));
80 78
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 118
121 // If the queue was empty, speak this immediately and add it to the queue. 119 // If the queue was empty, speak this immediately and add it to the queue.
122 if (m_utteranceQueue.size() == 1) 120 if (m_utteranceQueue.size() == 1)
123 startSpeakingImmediately(utterance); 121 startSpeakingImmediately(utterance);
124 } 122 }
125 123
126 void SpeechSynthesis::cancel() 124 void SpeechSynthesis::cancel()
127 { 125 {
128 // Remove all the items from the utterance queue. 126 // Remove all the items from the utterance queue.
129 // Hold on to the current utterance so the platform synthesizer can have a c hance to clean up. 127 // Hold on to the current utterance so the platform synthesizer can have a c hance to clean up.
130 RefPtrWillBeMember<SpeechSynthesisUtterance> current = m_currentSpeechUttera nce; 128 RefPtr<SpeechSynthesisUtterance> current = m_currentSpeechUtterance;
131 m_utteranceQueue.clear(); 129 m_utteranceQueue.clear();
132 m_platformSpeechSynthesizer->cancel(); 130 m_platformSpeechSynthesizer->cancel();
133 current = 0; 131 current = 0;
134 132
135 // The platform should have called back immediately and cleared the current utterance. 133 // The platform should have called back immediately and cleared the current utterance.
136 ASSERT(!m_currentSpeechUtterance); 134 ASSERT(!m_currentSpeechUtterance);
137 } 135 }
138 136
139 void SpeechSynthesis::pause() 137 void SpeechSynthesis::pause()
140 { 138 {
(...skipping 16 matching lines...) Expand all
157 155
158 void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utteranc e, bool errorOccurred) 156 void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utteranc e, bool errorOccurred)
159 { 157 {
160 ASSERT(utterance); 158 ASSERT(utterance);
161 ASSERT(m_currentSpeechUtterance); 159 ASSERT(m_currentSpeechUtterance);
162 m_currentSpeechUtterance = 0; 160 m_currentSpeechUtterance = 0;
163 161
164 fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utter ance, 0, String()); 162 fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utter ance, 0, String());
165 163
166 if (m_utteranceQueue.size()) { 164 if (m_utteranceQueue.size()) {
167 RefPtrWillBeMember<SpeechSynthesisUtterance> firstUtterance = m_utteranc eQueue.first(); 165 RefPtr<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.first ();
168 ASSERT(firstUtterance == utterance); 166 ASSERT(firstUtterance == utterance);
169 if (firstUtterance == utterance) 167 if (firstUtterance == utterance)
170 m_utteranceQueue.removeFirst(); 168 m_utteranceQueue.removeFirst();
171 169
172 // Start the next job if there is one pending. 170 // Start the next job if there is one pending.
173 if (!m_utteranceQueue.isEmpty()) 171 if (!m_utteranceQueue.isEmpty())
174 startSpeakingImmediately(m_utteranceQueue.first().get()); 172 startSpeakingImmediately(m_utteranceQueue.first().get());
175 } 173 }
176 } 174 }
177 175
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 { 220 {
223 if (utterance->client()) 221 if (utterance->client())
224 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance ->client()), true); 222 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance ->client()), true);
225 } 223 }
226 224
227 const AtomicString& SpeechSynthesis::interfaceName() const 225 const AtomicString& SpeechSynthesis::interfaceName() const
228 { 226 {
229 return EventTargetNames::SpeechSynthesisUtterance; 227 return EventTargetNames::SpeechSynthesisUtterance;
230 } 228 }
231 229
232 void SpeechSynthesis::trace(Visitor* visitor)
233 {
234 visitor->trace(m_voiceList);
235 visitor->trace(m_currentSpeechUtterance);
236 visitor->trace(m_utteranceQueue);
237 }
238
239 } // namespace WebCore 230 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/speech/SpeechSynthesis.h ('k') | Source/modules/speech/SpeechSynthesis.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698