Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 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) |
| 42 { | 42 { |
| 43 SpeechRecognition* speechRecognition = new SpeechRecognition(context); | 43 ASSERT(context && context->isDocument()); |
| 44 Document* document = toDocument(context); | |
| 45 ASSERT(document); | |
| 46 LocalFrame* frame = document->frame(); | |
|
haraken
2015/02/27 08:23:32
Just to confirm: A frame is guaranteed to exist he
sof
2015/02/27 10:12:21
Not in the general case, SpeechRecognition was vul
| |
| 47 ASSERT(frame); | |
| 48 SpeechRecognition* speechRecognition = new SpeechRecognition(frame, context) ; | |
| 44 speechRecognition->suspendIfNeeded(); | 49 speechRecognition->suspendIfNeeded(); |
| 45 return speechRecognition; | 50 return speechRecognition; |
| 46 } | 51 } |
| 47 | 52 |
| 48 void SpeechRecognition::start(ExceptionState& exceptionState) | 53 void SpeechRecognition::start(ExceptionState& exceptionState) |
| 49 { | 54 { |
| 50 ASSERT(m_controller); | 55 if (!m_controller) |
| 56 return; | |
| 57 | |
| 51 if (m_started) { | 58 if (m_started) { |
| 52 exceptionState.throwDOMException(InvalidStateError, "recognition has alr eady started."); | 59 exceptionState.throwDOMException(InvalidStateError, "recognition has alr eady started."); |
| 53 return; | 60 return; |
| 54 } | 61 } |
| 55 | 62 |
| 56 m_finalResults.clear(); | 63 m_finalResults.clear(); |
| 57 m_controller->start(this, m_grammars, m_lang, m_continuous, m_interimResults , m_maxAlternatives, m_audioTrack); | 64 m_controller->start(this, m_grammars, m_lang, m_continuous, m_interimResults , m_maxAlternatives, m_audioTrack); |
| 58 m_started = true; | 65 m_started = true; |
| 59 } | 66 } |
| 60 | 67 |
| 61 void SpeechRecognition::stopFunction() | 68 void SpeechRecognition::stopFunction() |
| 62 { | 69 { |
| 63 ASSERT(m_controller); | 70 if (!m_controller) |
| 71 return; | |
| 72 | |
| 64 if (m_started && !m_stopping) { | 73 if (m_started && !m_stopping) { |
| 65 m_stopping = true; | 74 m_stopping = true; |
| 66 m_controller->stop(this); | 75 m_controller->stop(this); |
| 67 } | 76 } |
| 68 } | 77 } |
| 69 | 78 |
| 70 void SpeechRecognition::abort() | 79 void SpeechRecognition::abort() |
| 71 { | 80 { |
| 72 ASSERT(m_controller); | 81 if (!m_controller) |
| 82 return; | |
| 83 | |
| 73 if (m_started && !m_stopping) { | 84 if (m_started && !m_stopping) { |
| 74 m_stopping = true; | 85 m_stopping = true; |
| 75 m_controller->abort(this); | 86 m_controller->abort(this); |
| 76 } | 87 } |
| 77 } | 88 } |
| 78 | 89 |
| 79 void SpeechRecognition::didStartAudio() | 90 void SpeechRecognition::didStartAudio() |
| 80 { | 91 { |
| 81 dispatchEvent(Event::create(EventTypeNames::audiostart)); | 92 dispatchEvent(Event::create(EventTypeNames::audiostart)); |
| 82 } | 93 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 m_stoppedByActiveDOMObject = true; | 170 m_stoppedByActiveDOMObject = true; |
| 160 if (hasPendingActivity()) | 171 if (hasPendingActivity()) |
| 161 abort(); | 172 abort(); |
| 162 } | 173 } |
| 163 | 174 |
| 164 bool SpeechRecognition::hasPendingActivity() const | 175 bool SpeechRecognition::hasPendingActivity() const |
| 165 { | 176 { |
| 166 return m_started; | 177 return m_started; |
| 167 } | 178 } |
| 168 | 179 |
| 169 SpeechRecognition::SpeechRecognition(ExecutionContext* context) | 180 SpeechRecognition::SpeechRecognition(LocalFrame *frame, ExecutionContext* contex t) |
| 170 : ActiveDOMObject(context) | 181 : FrameDestructionObserver(frame) |
| 182 , ActiveDOMObject(context) | |
| 171 , m_grammars(SpeechGrammarList::create()) // FIXME: The spec is not clear on the default value for the grammars attribute. | 183 , m_grammars(SpeechGrammarList::create()) // FIXME: The spec is not clear on the default value for the grammars attribute. |
| 172 , m_audioTrack(nullptr) | 184 , m_audioTrack(nullptr) |
| 173 , m_continuous(false) | 185 , m_continuous(false) |
| 174 , m_interimResults(false) | 186 , m_interimResults(false) |
| 175 , m_maxAlternatives(1) | 187 , m_maxAlternatives(1) |
| 176 , m_controller(nullptr) | 188 , m_controller(nullptr) |
| 177 , m_stoppedByActiveDOMObject(false) | 189 , m_stoppedByActiveDOMObject(false) |
| 178 , m_started(false) | 190 , m_started(false) |
| 179 , m_stopping(false) | 191 , m_stopping(false) |
| 180 { | 192 { |
| 181 Document* document = toDocument(executionContext()); | 193 ASSERT(frame); |
| 182 | 194 ASSERT(frame->page()); |
| 183 Page* page = document->page(); | 195 m_controller = SpeechRecognitionController::from(frame->page()); |
| 184 ASSERT(page); | |
| 185 | |
| 186 m_controller = SpeechRecognitionController::from(page); | |
| 187 ASSERT(m_controller); | 196 ASSERT(m_controller); |
| 188 | |
| 189 // FIXME: Need to hook up with Page to get notified when the visibility chan ges. | 197 // FIXME: Need to hook up with Page to get notified when the visibility chan ges. |
| 190 } | 198 } |
| 191 | 199 |
| 192 SpeechRecognition::~SpeechRecognition() | 200 SpeechRecognition::~SpeechRecognition() |
| 193 { | 201 { |
| 194 } | 202 } |
| 195 | 203 |
| 204 void SpeechRecognition::frameDestroyed() | |
| 205 { | |
| 206 m_controller = nullptr; | |
| 207 FrameDestructionObserver::frameDestroyed(); | |
| 208 } | |
| 209 | |
| 196 DEFINE_TRACE(SpeechRecognition) | 210 DEFINE_TRACE(SpeechRecognition) |
| 197 { | 211 { |
| 198 visitor->trace(m_grammars); | 212 visitor->trace(m_grammars); |
| 199 visitor->trace(m_audioTrack); | 213 visitor->trace(m_audioTrack); |
| 200 #if ENABLE(OILPAN) | 214 #if ENABLE(OILPAN) |
| 201 visitor->trace(m_controller); | 215 visitor->trace(m_controller); |
| 202 #endif | 216 #endif |
| 203 visitor->trace(m_finalResults); | 217 visitor->trace(m_finalResults); |
| 204 RefCountedGarbageCollectedEventTargetWithInlineData<SpeechRecognition>::trac e(visitor); | 218 RefCountedGarbageCollectedEventTargetWithInlineData<SpeechRecognition>::trac e(visitor); |
| 219 FrameDestructionObserver::trace(visitor); | |
| 205 ActiveDOMObject::trace(visitor); | 220 ActiveDOMObject::trace(visitor); |
| 206 } | 221 } |
| 207 | 222 |
| 208 } // namespace blink | 223 } // namespace blink |
| OLD | NEW |