| 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 17 matching lines...) Expand all Loading... |
| 28 #include "modules/speech/SpeechRecognition.h" | 28 #include "modules/speech/SpeechRecognition.h" |
| 29 | 29 |
| 30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
| 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 #include "platform/weborigin/KURL.h" |
| 38 | 39 |
| 39 namespace blink { | 40 namespace blink { |
| 40 | 41 |
| 41 SpeechRecognition* SpeechRecognition::create(ExecutionContext* context) | 42 SpeechRecognition* SpeechRecognition::create(ExecutionContext* context) |
| 42 { | 43 { |
| 43 ASSERT(context && context->isDocument()); | 44 ASSERT(context && context->isDocument()); |
| 44 Document* document = toDocument(context); | 45 Document* document = toDocument(context); |
| 45 ASSERT(document); | 46 ASSERT(document); |
| 46 SpeechRecognition* speechRecognition = new SpeechRecognition(document->page(
), context); | 47 SpeechRecognition* speechRecognition = new SpeechRecognition(document->page(
), context); |
| 47 speechRecognition->suspendIfNeeded(); | 48 speechRecognition->suspendIfNeeded(); |
| 48 return speechRecognition; | 49 return speechRecognition; |
| 49 } | 50 } |
| 50 | 51 |
| 51 void SpeechRecognition::start(ExceptionState& exceptionState) | 52 void SpeechRecognition::start(ExceptionState& exceptionState) |
| 52 { | 53 { |
| 53 if (!m_controller) | 54 if (!m_controller) |
| 54 return; | 55 return; |
| 55 | 56 |
| 56 if (m_started) { | 57 if (m_started) { |
| 57 exceptionState.throwDOMException(InvalidStateError, "recognition has alr
eady started."); | 58 exceptionState.throwDOMException(InvalidStateError, "recognition has alr
eady started."); |
| 58 return; | 59 return; |
| 59 } | 60 } |
| 60 | 61 |
| 62 // Prepend chromium to the client param to tag requests coming from the brow
ser. |
| 63 std::size_t pos; |
| 64 KURL serviceURI; |
| 65 KURL kurl(ParsedURLString, m_serviceURI); |
| 66 String query = kurl.query(); |
| 67 if (kurl.isValid() && !query.isEmpty() && ((pos = query.find("client=")) !=
std::string::npos)) { |
| 68 query.replace(pos, 7, "client=chromium/"); |
| 69 serviceURI = kurl; |
| 70 } |
| 71 |
| 61 m_finalResults.clear(); | 72 m_finalResults.clear(); |
| 62 m_controller->start(this, m_grammars, m_lang, m_serviceURI, m_continuous, m_
interimResults, m_maxAlternatives, m_audioTrack); | 73 m_controller->start(this, m_grammars, m_lang, serviceURI, m_continuous, m_in
terimResults, m_maxAlternatives, m_audioTrack); |
| 63 m_started = true; | 74 m_started = true; |
| 64 } | 75 } |
| 65 | 76 |
| 66 void SpeechRecognition::stopFunction() | 77 void SpeechRecognition::stopFunction() |
| 67 { | 78 { |
| 68 if (!m_controller) | 79 if (!m_controller) |
| 69 return; | 80 return; |
| 70 | 81 |
| 71 if (m_started && !m_stopping) { | 82 if (m_started && !m_stopping) { |
| 72 m_stopping = true; | 83 m_stopping = true; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 #if ENABLE(OILPAN) | 219 #if ENABLE(OILPAN) |
| 209 visitor->trace(m_controller); | 220 visitor->trace(m_controller); |
| 210 #endif | 221 #endif |
| 211 visitor->trace(m_finalResults); | 222 visitor->trace(m_finalResults); |
| 212 RefCountedGarbageCollectedEventTargetWithInlineData<SpeechRecognition>::trac
e(visitor); | 223 RefCountedGarbageCollectedEventTargetWithInlineData<SpeechRecognition>::trac
e(visitor); |
| 213 PageLifecycleObserver::trace(visitor); | 224 PageLifecycleObserver::trace(visitor); |
| 214 ActiveDOMObject::trace(visitor); | 225 ActiveDOMObject::trace(visitor); |
| 215 } | 226 } |
| 216 | 227 |
| 217 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |