15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2012 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  * Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  * Redistributions in binary form must reproduce the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/speech/SpeechRecognitionError.h"
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
30c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
32926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)static String ErrorCodeToString(SpeechRecognitionError::ErrorCode code)
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
34926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    switch (code) {
35926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeOther:
363c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "other";
37926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeNoSpeech:
383c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "no-speech";
39926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeAborted:
403c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "aborted";
41926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeAudioCapture:
423c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "audio-capture";
43926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeNetwork:
443c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "network";
45926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeNotAllowed:
463c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "not-allowed";
47926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeServiceNotAllowed:
483c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "service-not-allowed";
49926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeBadGrammar:
503c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "bad-grammar";
51926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case SpeechRecognitionError::ErrorCodeLanguageNotSupported:
523c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        return "language-not-supported";
53926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
54926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
55926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    ASSERT_NOT_REACHED();
56926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return String();
57926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
58926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
5907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochPassRefPtrWillBeRawPtr<SpeechRecognitionError> SpeechRecognitionError::create(ErrorCode code, const String& message)
60926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
61a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    return adoptRefWillBeNoop(new SpeechRecognitionError(ErrorCodeToString(code), message));
62926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
63926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
6407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochPassRefPtrWillBeRawPtr<SpeechRecognitionError> SpeechRecognitionError::create()
65926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
66a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    return adoptRefWillBeNoop(new SpeechRecognitionError(emptyString(), emptyString()));
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochPassRefPtrWillBeRawPtr<SpeechRecognitionError> SpeechRecognitionError::create(const AtomicString& eventName, const SpeechRecognitionErrorInit& initializer)
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
71a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    return adoptRefWillBeNoop(new SpeechRecognitionError(eventName, initializer));
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
74926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)SpeechRecognitionError::SpeechRecognitionError(const String& error, const String& message)
751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    : Event(EventTypeNames::error, /*canBubble=*/false, /*cancelable=*/false)
76926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_error(error)
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_message(message)
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)SpeechRecognitionError::SpeechRecognitionError(const AtomicString& eventName, const SpeechRecognitionErrorInit& initializer)
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    : Event(eventName, initializer)
83926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_error(initializer.error)
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_message(initializer.message)
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)const AtomicString& SpeechRecognitionError::interfaceName() const
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return EventNames::SpeechRecognitionError;
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)SpeechRecognitionErrorInit::SpeechRecognitionErrorInit()
945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
97c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
98