1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef SpeechRecognition_h 27 #define SpeechRecognition_h 28 29 #include "bindings/v8/ScriptWrappable.h" 30 #include "core/dom/ActiveDOMObject.h" 31 #include "core/events/EventTarget.h" 32 #include "modules/speech/SpeechGrammarList.h" 33 #include "wtf/Compiler.h" 34 #include "wtf/PassRefPtr.h" 35 #include "wtf/RefCounted.h" 36 #include "wtf/text/WTFString.h" 37 38 namespace WebCore { 39 40 class ExceptionState; 41 class ExecutionContext; 42 class SpeechRecognitionController; 43 class SpeechRecognitionError; 44 class SpeechRecognitionResult; 45 class SpeechRecognitionResultList; 46 47 class SpeechRecognition : public RefCounted<SpeechRecognition>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData { 48 REFCOUNTED_EVENT_TARGET(SpeechRecognition); 49 public: 50 static PassRefPtr<SpeechRecognition> create(ExecutionContext*); 51 ~SpeechRecognition(); 52 53 // Attributes. grammars()54 PassRefPtr<SpeechGrammarList> grammars() { return m_grammars; } setGrammars(PassRefPtr<SpeechGrammarList> grammars)55 void setGrammars(PassRefPtr<SpeechGrammarList> grammars) { m_grammars = grammars; } lang()56 String lang() { return m_lang; } setLang(const String & lang)57 void setLang(const String& lang) { m_lang = lang; } continuous()58 bool continuous() { return m_continuous; } setContinuous(bool continuous)59 void setContinuous(bool continuous) { m_continuous = continuous; } interimResults()60 bool interimResults() { return m_interimResults; } setInterimResults(bool interimResults)61 void setInterimResults(bool interimResults) { m_interimResults = interimResults; } maxAlternatives()62 unsigned long maxAlternatives() { return m_maxAlternatives; } setMaxAlternatives(unsigned long maxAlternatives)63 void setMaxAlternatives(unsigned long maxAlternatives) { m_maxAlternatives = maxAlternatives; } 64 65 // Callable by the user. 66 void start(ExceptionState&); 67 void stopFunction(); 68 void abort(); 69 70 // Called by the SpeechRecognitionClient. 71 void didStartAudio(); 72 void didStartSound(); 73 void didStartSpeech(); 74 void didEndSpeech(); 75 void didEndSound(); 76 void didEndAudio(); 77 void didReceiveResults(const Vector<RefPtr<SpeechRecognitionResult> >& newFinalResults, const Vector<RefPtr<SpeechRecognitionResult> >& currentInterimResults); 78 void didReceiveNoMatch(PassRefPtr<SpeechRecognitionResult>); 79 void didReceiveError(PassRefPtr<SpeechRecognitionError>); 80 void didStart(); 81 void didEnd(); 82 83 // EventTarget. 84 virtual const AtomicString& interfaceName() const OVERRIDE; 85 virtual ExecutionContext* executionContext() const OVERRIDE; 86 87 // ActiveDOMObject. 88 virtual void stop() OVERRIDE; 89 90 DEFINE_ATTRIBUTE_EVENT_LISTENER(audiostart); 91 DEFINE_ATTRIBUTE_EVENT_LISTENER(soundstart); 92 DEFINE_ATTRIBUTE_EVENT_LISTENER(speechstart); 93 DEFINE_ATTRIBUTE_EVENT_LISTENER(speechend); 94 DEFINE_ATTRIBUTE_EVENT_LISTENER(soundend); 95 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioend); 96 DEFINE_ATTRIBUTE_EVENT_LISTENER(result); 97 DEFINE_ATTRIBUTE_EVENT_LISTENER(nomatch); 98 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 99 DEFINE_ATTRIBUTE_EVENT_LISTENER(start); 100 DEFINE_ATTRIBUTE_EVENT_LISTENER(end); 101 102 private: 103 friend class RefCounted<SpeechRecognition>; 104 105 explicit SpeechRecognition(ExecutionContext*); 106 107 RefPtr<SpeechGrammarList> m_grammars; 108 String m_lang; 109 bool m_continuous; 110 bool m_interimResults; 111 unsigned long m_maxAlternatives; 112 113 SpeechRecognitionController* m_controller; 114 bool m_stoppedByActiveDOMObject; 115 bool m_started; 116 bool m_stopping; 117 Vector<RefPtr<SpeechRecognitionResult> > m_finalResults; 118 }; 119 120 } // namespace WebCore 121 122 #endif // SpeechRecognition_h 123