2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef SpeechRecognition_h
27 #define SpeechRecognition_h
29 #include "bindings/v8/ScriptWrappable.h"
30 #include "core/dom/ActiveDOMObject.h"
31 #include "core/events/EventTarget.h"
32 #include "heap/Handle.h"
33 #include "modules/speech/SpeechGrammarList.h"
34 #include "modules/speech/SpeechRecognitionResult.h"
35 #include "wtf/Compiler.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/RefCounted.h"
38 #include "wtf/text/WTFString.h"
43 class ExecutionContext;
44 class SpeechRecognitionController;
45 class SpeechRecognitionError;
47 class SpeechRecognition FINAL : public RefCountedWillBeRefCountedGarbageCollected<SpeechRecognition>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData {
49 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<SpeechRecognition>);
51 static PassRefPtrWillBeRawPtr<SpeechRecognition> create(ExecutionContext*);
52 virtual ~SpeechRecognition();
55 SpeechGrammarList* grammars() { return m_grammars.get(); }
56 void setGrammars(PassRefPtrWillBeRawPtr<SpeechGrammarList> grammars) { m_grammars = grammars; }
57 String lang() { return m_lang; }
58 void setLang(const String& lang) { m_lang = lang; }
59 bool continuous() { return m_continuous; }
60 void setContinuous(bool continuous) { m_continuous = continuous; }
61 bool interimResults() { return m_interimResults; }
62 void setInterimResults(bool interimResults) { m_interimResults = interimResults; }
63 unsigned long maxAlternatives() { return m_maxAlternatives; }
64 void setMaxAlternatives(unsigned long maxAlternatives) { m_maxAlternatives = maxAlternatives; }
66 // Callable by the user.
67 void start(ExceptionState&);
71 // Called by the SpeechRecognitionClient.
74 void didStartSpeech();
78 void didReceiveResults(const Vector<RefPtr<SpeechRecognitionResult> >& newFinalResults, const Vector<RefPtr<SpeechRecognitionResult> >& currentInterimResults);
79 void didReceiveNoMatch(PassRefPtr<SpeechRecognitionResult>);
80 void didReceiveError(PassRefPtr<SpeechRecognitionError>);
85 virtual const AtomicString& interfaceName() const OVERRIDE;
86 virtual ExecutionContext* executionContext() const OVERRIDE;
89 virtual void stop() OVERRIDE;
91 DEFINE_ATTRIBUTE_EVENT_LISTENER(audiostart);
92 DEFINE_ATTRIBUTE_EVENT_LISTENER(soundstart);
93 DEFINE_ATTRIBUTE_EVENT_LISTENER(speechstart);
94 DEFINE_ATTRIBUTE_EVENT_LISTENER(speechend);
95 DEFINE_ATTRIBUTE_EVENT_LISTENER(soundend);
96 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioend);
97 DEFINE_ATTRIBUTE_EVENT_LISTENER(result);
98 DEFINE_ATTRIBUTE_EVENT_LISTENER(nomatch);
99 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
100 DEFINE_ATTRIBUTE_EVENT_LISTENER(start);
101 DEFINE_ATTRIBUTE_EVENT_LISTENER(end);
103 void trace(Visitor*);
106 friend class RefCounted<SpeechRecognition>;
108 explicit SpeechRecognition(ExecutionContext*);
110 RefPtrWillBeMember<SpeechGrammarList> m_grammars;
113 bool m_interimResults;
114 unsigned long m_maxAlternatives;
116 SpeechRecognitionController* m_controller;
117 bool m_stoppedByActiveDOMObject;
120 Vector<RefPtr<SpeechRecognitionResult> > m_finalResults;
123 } // namespace WebCore
125 #endif // SpeechRecognition_h