OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google 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 * * Redistributions of source code must retain the above copyright | 7 * * 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 * * Redistributions in binary form must reproduce the above copyright | 9 * * 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 20 matching lines...) Expand all Loading... | |
31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
33 #include "core/page/Page.h" | 33 #include "core/page/Page.h" |
34 #include "modules/mediastream/MediaStreamTrack.h" | 34 #include "modules/mediastream/MediaStreamTrack.h" |
35 #include "modules/speech/SpeechRecognitionController.h" | 35 #include "modules/speech/SpeechRecognitionController.h" |
36 #include "modules/speech/SpeechRecognitionError.h" | 36 #include "modules/speech/SpeechRecognitionError.h" |
37 #include "modules/speech/SpeechRecognitionEvent.h" | 37 #include "modules/speech/SpeechRecognitionEvent.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 SpeechRecognition* SpeechRecognition::create(ExecutionContext* context) | 41 SpeechRecognition* SpeechRecognition::create(ExecutionContext* context, Exceptio nState& exceptionState) |
42 { | 42 { |
43 SpeechRecognition* speechRecognition = new SpeechRecognition(context); | 43 const char* notSupportedErrorMessage = "cannot create a new object for a clo sed window."; |
44 if (!context) { | |
haraken
2015/02/27 10:47:39
By calling ConstructorCallWith=ExecutionContext, c
sof
2015/02/27 10:50:36
The bindings code calls currentExecutionContext()
| |
45 exceptionState.throwDOMException(NotSupportedError, notSupportedErrorMes sage); | |
46 return nullptr; | |
47 } | |
48 ASSERT(context->isDocument()); | |
49 Document* document = toDocument(context); | |
50 ASSERT(document); | |
51 Page* page = document->page(); | |
52 if (!page) { | |
53 exceptionState.throwDOMException(NotSupportedError, notSupportedErrorMes sage); | |
54 return nullptr; | |
55 } | |
56 SpeechRecognition* speechRecognition = new SpeechRecognition(page, context); | |
44 speechRecognition->suspendIfNeeded(); | 57 speechRecognition->suspendIfNeeded(); |
45 return speechRecognition; | 58 return speechRecognition; |
46 } | 59 } |
47 | 60 |
48 void SpeechRecognition::start(ExceptionState& exceptionState) | 61 void SpeechRecognition::start(ExceptionState& exceptionState) |
49 { | 62 { |
50 ASSERT(m_controller); | 63 if (!m_controller) |
64 return; | |
65 | |
51 if (m_started) { | 66 if (m_started) { |
52 exceptionState.throwDOMException(InvalidStateError, "recognition has alr eady started."); | 67 exceptionState.throwDOMException(InvalidStateError, "recognition has alr eady started."); |
53 return; | 68 return; |
54 } | 69 } |
55 | 70 |
56 m_finalResults.clear(); | 71 m_finalResults.clear(); |
57 m_controller->start(this, m_grammars, m_lang, m_continuous, m_interimResults , m_maxAlternatives, m_audioTrack); | 72 m_controller->start(this, m_grammars, m_lang, m_continuous, m_interimResults , m_maxAlternatives, m_audioTrack); |
58 m_started = true; | 73 m_started = true; |
59 } | 74 } |
60 | 75 |
61 void SpeechRecognition::stopFunction() | 76 void SpeechRecognition::stopFunction() |
62 { | 77 { |
63 ASSERT(m_controller); | 78 if (!m_controller) |
79 return; | |
80 | |
64 if (m_started && !m_stopping) { | 81 if (m_started && !m_stopping) { |
65 m_stopping = true; | 82 m_stopping = true; |
66 m_controller->stop(this); | 83 m_controller->stop(this); |
67 } | 84 } |
68 } | 85 } |
69 | 86 |
70 void SpeechRecognition::abort() | 87 void SpeechRecognition::abort() |
71 { | 88 { |
72 ASSERT(m_controller); | 89 if (!m_controller) |
90 return; | |
91 | |
73 if (m_started && !m_stopping) { | 92 if (m_started && !m_stopping) { |
74 m_stopping = true; | 93 m_stopping = true; |
75 m_controller->abort(this); | 94 m_controller->abort(this); |
76 } | 95 } |
77 } | 96 } |
78 | 97 |
79 void SpeechRecognition::didStartAudio() | 98 void SpeechRecognition::didStartAudio() |
80 { | 99 { |
81 dispatchEvent(Event::create(EventTypeNames::audiostart)); | 100 dispatchEvent(Event::create(EventTypeNames::audiostart)); |
82 } | 101 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 m_stoppedByActiveDOMObject = true; | 178 m_stoppedByActiveDOMObject = true; |
160 if (hasPendingActivity()) | 179 if (hasPendingActivity()) |
161 abort(); | 180 abort(); |
162 } | 181 } |
163 | 182 |
164 bool SpeechRecognition::hasPendingActivity() const | 183 bool SpeechRecognition::hasPendingActivity() const |
165 { | 184 { |
166 return m_started; | 185 return m_started; |
167 } | 186 } |
168 | 187 |
169 SpeechRecognition::SpeechRecognition(ExecutionContext* context) | 188 SpeechRecognition::SpeechRecognition(Page* page, ExecutionContext* context) |
170 : ActiveDOMObject(context) | 189 : PageLifecycleObserver(page) |
190 , ActiveDOMObject(context) | |
171 , m_grammars(SpeechGrammarList::create()) // FIXME: The spec is not clear on the default value for the grammars attribute. | 191 , m_grammars(SpeechGrammarList::create()) // FIXME: The spec is not clear on the default value for the grammars attribute. |
172 , m_audioTrack(nullptr) | 192 , m_audioTrack(nullptr) |
173 , m_continuous(false) | 193 , m_continuous(false) |
174 , m_interimResults(false) | 194 , m_interimResults(false) |
175 , m_maxAlternatives(1) | 195 , m_maxAlternatives(1) |
176 , m_controller(nullptr) | 196 , m_controller(SpeechRecognitionController::from(page)) |
177 , m_stoppedByActiveDOMObject(false) | 197 , m_stoppedByActiveDOMObject(false) |
178 , m_started(false) | 198 , m_started(false) |
179 , m_stopping(false) | 199 , m_stopping(false) |
180 { | 200 { |
181 Document* document = toDocument(executionContext()); | |
182 | |
183 Page* page = document->page(); | |
184 ASSERT(page); | |
185 | |
186 m_controller = SpeechRecognitionController::from(page); | |
187 ASSERT(m_controller); | 201 ASSERT(m_controller); |
188 | |
189 // FIXME: Need to hook up with Page to get notified when the visibility chan ges. | 202 // FIXME: Need to hook up with Page to get notified when the visibility chan ges. |
190 } | 203 } |
191 | 204 |
192 SpeechRecognition::~SpeechRecognition() | 205 SpeechRecognition::~SpeechRecognition() |
193 { | 206 { |
194 } | 207 } |
195 | 208 |
209 void SpeechRecognition::contextDestroyed() | |
210 { | |
211 m_controller = nullptr; | |
212 PageLifecycleObserver::contextDestroyed(); | |
213 } | |
214 | |
196 DEFINE_TRACE(SpeechRecognition) | 215 DEFINE_TRACE(SpeechRecognition) |
197 { | 216 { |
198 visitor->trace(m_grammars); | 217 visitor->trace(m_grammars); |
199 visitor->trace(m_audioTrack); | 218 visitor->trace(m_audioTrack); |
200 #if ENABLE(OILPAN) | 219 #if ENABLE(OILPAN) |
201 visitor->trace(m_controller); | 220 visitor->trace(m_controller); |
202 #endif | 221 #endif |
203 visitor->trace(m_finalResults); | 222 visitor->trace(m_finalResults); |
204 RefCountedGarbageCollectedEventTargetWithInlineData<SpeechRecognition>::trac e(visitor); | 223 RefCountedGarbageCollectedEventTargetWithInlineData<SpeechRecognition>::trac e(visitor); |
224 PageLifecycleObserver::trace(visitor); | |
205 ActiveDOMObject::trace(visitor); | 225 ActiveDOMObject::trace(visitor); |
206 } | 226 } |
207 | 227 |
208 } // namespace blink | 228 } // namespace blink |
OLD | NEW |