2010-08-13 Satish Sampath <satish@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Aug 2010 16:49:30 +0000 (16:49 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Aug 2010 16:49:30 +0000 (16:49 +0000)
        Reviewed by Jeremy Orlow.

        Support for multiple speech enabled elements in same page.
        https://bugs.webkit.org/show_bug.cgi?id=43922

        * page/SpeechInput.cpp: Generates request ids as necessary when each speech enabled input element gets
        created/destroyed and multiplexes the listener callbacks to the appropriate input element based on the request id.
        (WebCore::SpeechInput::SpeechInput):
        (WebCore::SpeechInput::~SpeechInput):
        (WebCore::SpeechInput::registerListener):
        (WebCore::SpeechInput::unregisterListener):
        (WebCore::SpeechInput::didCompleteRecording):
        (WebCore::SpeechInput::didCompleteRecognition):
        (WebCore::SpeechInput::setRecognitionResult):
        (WebCore::SpeechInput::startRecognition):
        (WebCore::SpeechInput::stopRecording):
        (WebCore::SpeechInput::cancelRecognition):
        * page/SpeechInput.h:
        * page/SpeechInputClient.h: Now requires a one time set for the WebCore::SpeechInputListener and
        takes in a 'requestId' for all calls.
        * page/SpeechInputListener.h: Now returns the above mentioned requestId in all the listener callbacks for
        identifying which input element the event goes to.
        * platform/mock/SpeechInputClientMock.cpp:
        (WebCore::SpeechInputClientMock::SpeechInputClientMock):
        (WebCore::SpeechInputClientMock::setListener):
        (WebCore::SpeechInputClientMock::startRecognition):
        (WebCore::SpeechInputClientMock::stopRecording):
        (WebCore::SpeechInputClientMock::cancelRecognition):
        (WebCore::SpeechInputClientMock::timerFired):
        * platform/mock/SpeechInputClientMock.h:
        * rendering/TextControlInnerElements.cpp:
        (WebCore::InputFieldSpeechButtonElement::InputFieldSpeechButtonElement):
        (WebCore::InputFieldSpeechButtonElement::~InputFieldSpeechButtonElement):
        (WebCore::InputFieldSpeechButtonElement::defaultEventHandler):
        (WebCore::InputFieldSpeechButtonElement::speechInput):
        (WebCore::InputFieldSpeechButtonElement::didCompleteRecording):
        (WebCore::InputFieldSpeechButtonElement::didCompleteRecognition):
        (WebCore::InputFieldSpeechButtonElement::setRecognitionResult):
        * rendering/TextControlInnerElements.h:
2010-08-13  Satish Sampath  <satish@chromium.org>

        Reviewed by Jeremy Orlow.

        Support for multiple speech enabled elements in same page.
        https://bugs.webkit.org/show_bug.cgi?id=43922

        * public/WebSpeechInputController.h: Bubbles up the requestId given by webcore to the embedder.
        (WebKit::WebSpeechInputController::startRecognition):
        (WebKit::WebSpeechInputController::cancelRecognition):
        (WebKit::WebSpeechInputController::stopRecording):
        * public/WebSpeechInputListener.h: Passes down the requestId given by embedder to webcore.
        (WebKit::WebSpeechInputListener::didCompleteRecording):
        (WebKit::WebSpeechInputListener::setRecognitionResult):
        (WebKit::WebSpeechInputListener::didCompleteRecognition):
        * src/SpeechInputClientImpl.cpp:
        (WebKit::SpeechInputClientImpl::setListener):
        (WebKit::SpeechInputClientImpl::startRecognition):
        (WebKit::SpeechInputClientImpl::stopRecording):
        (WebKit::SpeechInputClientImpl::cancelRecognition):
        (WebKit::SpeechInputClientImpl::didCompleteRecording):
        (WebKit::SpeechInputClientImpl::didCompleteRecognition):
        (WebKit::SpeechInputClientImpl::setRecognitionResult):
        * src/SpeechInputClientImpl.h:
        * src/WebSpeechInputControllerMockImpl.cpp:
        (WebKit::WebSpeechInputControllerMockImpl::WebSpeechInputControllerMockImpl):
        (WebKit::WebSpeechInputControllerMockImpl::~WebSpeechInputControllerMockImpl):
        (WebKit::WebSpeechInputControllerMockImpl::didCompleteRecording):
        (WebKit::WebSpeechInputControllerMockImpl::didCompleteRecognition):
        (WebKit::WebSpeechInputControllerMockImpl::setRecognitionResult):
        (WebKit::WebSpeechInputControllerMockImpl::startRecognition):
        (WebKit::WebSpeechInputControllerMockImpl::cancelRecognition):
        (WebKit::WebSpeechInputControllerMockImpl::stopRecording):
        * src/WebSpeechInputControllerMockImpl.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65327 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
WebCore/ChangeLog
WebCore/page/SpeechInput.cpp
WebCore/page/SpeechInput.h
WebCore/page/SpeechInputClient.h
WebCore/page/SpeechInputListener.h
WebCore/platform/mock/SpeechInputClientMock.cpp
WebCore/platform/mock/SpeechInputClientMock.h
WebCore/rendering/TextControlInnerElements.cpp
WebCore/rendering/TextControlInnerElements.h
WebKit/chromium/ChangeLog
WebKit/chromium/public/WebSpeechInputController.h
WebKit/chromium/public/WebSpeechInputListener.h
WebKit/chromium/src/SpeechInputClientImpl.cpp
WebKit/chromium/src/SpeechInputClientImpl.h
WebKit/chromium/src/WebSpeechInputControllerMockImpl.cpp
WebKit/chromium/src/WebSpeechInputControllerMockImpl.h

index 0d459eb398b0812aa183775c17ea5883f6689756..ddadf7cdc656e79502c32ff996569e20f5291848 100644 (file)
@@ -1,3 +1,45 @@
+2010-08-13  Satish Sampath  <satish@chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        Support for multiple speech enabled elements in same page.
+        https://bugs.webkit.org/show_bug.cgi?id=43922
+
+        * page/SpeechInput.cpp: Generates request ids as necessary when each speech enabled input element gets
+        created/destroyed and multiplexes the listener callbacks to the appropriate input element based on the request id.
+        (WebCore::SpeechInput::SpeechInput):
+        (WebCore::SpeechInput::~SpeechInput):
+        (WebCore::SpeechInput::registerListener):
+        (WebCore::SpeechInput::unregisterListener):
+        (WebCore::SpeechInput::didCompleteRecording):
+        (WebCore::SpeechInput::didCompleteRecognition):
+        (WebCore::SpeechInput::setRecognitionResult):
+        (WebCore::SpeechInput::startRecognition):
+        (WebCore::SpeechInput::stopRecording):
+        (WebCore::SpeechInput::cancelRecognition):
+        * page/SpeechInput.h:
+        * page/SpeechInputClient.h: Now requires a one time set for the WebCore::SpeechInputListener and
+        takes in a 'requestId' for all calls.
+        * page/SpeechInputListener.h: Now returns the above mentioned requestId in all the listener callbacks for
+        identifying which input element the event goes to.
+        * platform/mock/SpeechInputClientMock.cpp:
+        (WebCore::SpeechInputClientMock::SpeechInputClientMock):
+        (WebCore::SpeechInputClientMock::setListener):
+        (WebCore::SpeechInputClientMock::startRecognition):
+        (WebCore::SpeechInputClientMock::stopRecording):
+        (WebCore::SpeechInputClientMock::cancelRecognition):
+        (WebCore::SpeechInputClientMock::timerFired):
+        * platform/mock/SpeechInputClientMock.h:
+        * rendering/TextControlInnerElements.cpp:
+        (WebCore::InputFieldSpeechButtonElement::InputFieldSpeechButtonElement):
+        (WebCore::InputFieldSpeechButtonElement::~InputFieldSpeechButtonElement):
+        (WebCore::InputFieldSpeechButtonElement::defaultEventHandler):
+        (WebCore::InputFieldSpeechButtonElement::speechInput):
+        (WebCore::InputFieldSpeechButtonElement::didCompleteRecording):
+        (WebCore::InputFieldSpeechButtonElement::didCompleteRecognition):
+        (WebCore::InputFieldSpeechButtonElement::setRecognitionResult):
+        * rendering/TextControlInnerElements.h:
+
 2010-08-13  Eric Carlson  <eric.carlson@apple.com>
 
         Reviewed by David Kilzer.
index 4f379889619ae3c3ee90e06020ba4a5b228800e5..24b52d2a7fff389b1d3c9ca185e3e974d8eb3452 100644 (file)
@@ -41,46 +41,74 @@ namespace WebCore {
 
 SpeechInput::SpeechInput(SpeechInputClient* client)
     : m_client(client)
-    , m_listener(0)
+    , m_nextListenerId(1)
 {
+    m_client->setListener(this);
 }
 
-void SpeechInput::didCompleteRecording()
+SpeechInput::~SpeechInput()
 {
-    ASSERT(m_listener);
-    m_listener->didCompleteRecording();
+    m_client->setListener(0);
 }
 
-void SpeechInput::didCompleteRecognition()
+int SpeechInput::registerListener(SpeechInputListener* listener)
 {
-    ASSERT(m_listener);
-    m_listener->didCompleteRecognition();
-    m_listener = 0;
+#if defined(DEBUG)
+    // Check if already present.
+    for (HashMap<int, SpeechInputListener*>::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
+      ASSERT(it->second != listener);
+#endif
+
+    m_listeners.add(m_nextListenerId, listener);
+    return m_nextListenerId++;
+}
+
+void SpeechInput::unregisterListener(int listenerId)
+{
+    if (m_listeners.contains(listenerId))
+        m_listeners.remove(listenerId);
+}
+
+void SpeechInput::didCompleteRecording(int listenerId)
+{
+    // Don't assert if not present as the element might have been removed by the page while
+    // this event was on the way.
+    if (m_listeners.contains(listenerId))
+        m_listeners.get(listenerId)->didCompleteRecording(listenerId);
+}
+
+void SpeechInput::didCompleteRecognition(int listenerId)
+{
+    // Don't assert if not present as the element might have been removed by the page while
+    // this event was on the way.
+    if (m_listeners.contains(listenerId))
+        m_listeners.get(listenerId)->didCompleteRecognition(listenerId);
+}
+
+void SpeechInput::setRecognitionResult(int listenerId, const String& result)
+{
+    // Don't assert if not present as the element might have been removed by the page while
+    // this event was on the way.
+    if (m_listeners.contains(listenerId))
+        m_listeners.get(listenerId)->setRecognitionResult(listenerId, result);
 }
 
-void SpeechInput::setRecognitionResult(const String& result)
+bool SpeechInput::startRecognition(int listenerId)
 {
-    ASSERT(m_listener);
-    m_listener->setRecognitionResult(result);
+    ASSERT(m_listeners.contains(listenerId));
+    return m_client->startRecognition(listenerId);
 }
 
-bool SpeechInput::startRecognition(SpeechInputListener* listener)
+void SpeechInput::stopRecording(int listenerId)
 {
-    // Cancel any ongoing recognition first.
-    if (m_listener) {
-        m_listener->didCompleteRecognition();
-        m_listener = 0;
-        m_client->cancelRecognition();
-    }
-
-    m_listener = listener;
-    return m_client->startRecognition(this);
+    ASSERT(m_listeners.contains(listenerId));
+    m_client->stopRecording(listenerId);
 }
 
-void SpeechInput::stopRecording()
+void SpeechInput::cancelRecognition(int listenerId)
 {
-    ASSERT(m_listener);
-    m_client->stopRecording();
+    ASSERT(m_listeners.contains(listenerId));
+    m_client->cancelRecognition(listenerId);
 }
 
 } // namespace WebCore
index 58f4efedc152bdc14066745492682be078ad5bc7..f36194ca3c7acc1aecf16988ebd34b5caba7f802 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "SpeechInputListener.h"
 #include <wtf/Forward.h>
+#include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
 
 namespace WebCore {
@@ -48,20 +49,30 @@ class SpeechInputListener;
 class SpeechInput : public Noncopyable, public SpeechInputListener {
 public:
     SpeechInput(SpeechInputClient*);
-    virtual ~SpeechInput() { }
+    virtual ~SpeechInput();
+
+    // Generates a unique ID for the given listener to be used for speech requests.
+    // This should be the first call made by listeners before anything else.
+    int registerListener(SpeechInputListener*);
+
+    // Invoked when the listener is done with recording or getting destroyed.
+    // Failure to unregister may result in crashes if there were any pending speech events.
+    void unregisterListener(int);
 
     // Methods invoked by the input elements.
-    bool startRecognition(SpeechInputListener* listener);
-    void stopRecording();
+    bool startRecognition(int);
+    void stopRecording(int);
+    void cancelRecognition(int);
 
     // SpeechInputListener methods.
-    virtual void didCompleteRecording();
-    virtual void didCompleteRecognition();
-    virtual void setRecognitionResult(const String&);
+    virtual void didCompleteRecording(int);
+    virtual void didCompleteRecognition(int);
+    virtual void setRecognitionResult(int, const String&);
 
 private:
     SpeechInputClient* m_client;
-    SpeechInputListener* m_listener;
+    HashMap<int, SpeechInputListener*> m_listeners;
+    int m_nextListenerId;
 };
 
 } // namespace WebCore
index f6c61cf40b02900fdf4b31ce56732c01d5842b80..87ff7b9394cbed4b1e44417a10c2f88249f9000a 100644 (file)
@@ -40,15 +40,22 @@ class SpeechInputListener;
 // Provides an interface for SpeechInput to call into the embedder.
 class SpeechInputClient {
 public:
-    virtual bool startRecognition(SpeechInputListener* listener) = 0;
+    // This is the first call made by a listener, registering itself for future callbacks.
+    // When the listener no longer needs speech input (for e.g. when it gets destroyed),
+    // it should set a null listener to stop receiving callbacks.
+    // The client does not take ownership of the pointer.
+    virtual void setListener(SpeechInputListener*) = 0;
+
+    // Starts speech recognition and audio recording.
+    virtual bool startRecognition(int requestId) = 0;
 
     // Stops audio recording and performs recognition with the audio recorded until now
     // (does not discard audio).
-    virtual void stopRecording() = 0;
+    virtual void stopRecording(int requestId) = 0;
 
     // Cancels an ongoing recognition and discards any audio recorded so far. No partial
     // recognition results are returned to the listener.
-    virtual void cancelRecognition() = 0;
+    virtual void cancelRecognition(int requestId) = 0;
 
 protected:
     virtual ~SpeechInputClient() { }
index 143984dc75a75e56c14754404b145e2adc2dc686..36060fcdefbde29ac973a18e5019efb9d64a2fc1 100644 (file)
@@ -41,19 +41,19 @@ namespace WebCore {
 class SpeechInputListener {
 public:
     // Informs that audio recording has completed and recognition is underway.
-    virtual void didCompleteRecording() = 0;
+    virtual void didCompleteRecording(int requestId) = 0;
 
     // Informs that speech recognition has completed. This gets invoked irrespective of whether
     // recognition was succesful or not, whether setRecognitionResult() was invoked or not. The
     // handler typically frees up any temporary resources allocated and waits for the next speech
     // recognition request.
-    virtual void didCompleteRecognition() = 0;
+    virtual void didCompleteRecognition(int requestId) = 0;
 
     // Gives results from speech recognition, either partial or the final results.
     // This method can potentially get called multiple times if there are partial results
     // available as the user keeps speaking. If the speech could not be recognized properly
     // or if there was any other errors in the process, this method may never be called.
-    virtual void setRecognitionResult(const String& result) = 0;
+    virtual void setRecognitionResult(int requestId, const String& result) = 0;
 
 protected:
     virtual ~SpeechInputListener() { }
index 74a3151cb64221f9a89d6811bbd3e30f64218738..c3d74d1928f5e723b0208ddaf302efde69e806bf 100644 (file)
@@ -41,34 +41,42 @@ SpeechInputClientMock::SpeechInputClientMock()
     : m_recording(false)
     , m_timer(this, &SpeechInputClientMock::timerFired)
     , m_listener(0)
+    , m_requestId(0)
 {
 }
 
-bool SpeechInputClientMock::startRecognition(SpeechInputListener* listener)
+void SpeechInputClientMock::setListener(SpeechInputListener* listener)
+{
+    m_listener = listener;
+}
+
+bool SpeechInputClientMock::startRecognition(int requestId)
 {
     if (m_timer.isActive())
         return false;
-    m_listener = listener;
+    m_requestId = requestId;
     m_recording = true;
     m_timer.startOneShot(0);
     return true;
 }
 
-void SpeechInputClientMock::stopRecording()
+void SpeechInputClientMock::stopRecording(int requestId)
 {
+    ASSERT(requestId == m_requestId);
     if (m_timer.isActive() && m_recording) {
         m_timer.stop();
         timerFired(&m_timer);
     }
 }
 
-void SpeechInputClientMock::cancelRecognition()
+void SpeechInputClientMock::cancelRecognition(int requestId)
 {
+    ASSERT(requestId == m_requestId);
     if (m_timer.isActive()) {
         m_timer.stop();
         m_recording = false;
-        m_listener->didCompleteRecognition();
-        m_listener = 0;
+        m_listener->didCompleteRecognition(m_requestId);
+        m_requestId = 0;
     }
 }
 
@@ -81,12 +89,12 @@ void SpeechInputClientMock::timerFired(WebCore::Timer<SpeechInputClientMock>*)
 {
     if (m_recording) {
         m_recording = false;
-        m_listener->didCompleteRecording();
+        m_listener->didCompleteRecording(m_requestId);
         m_timer.startOneShot(0);
     } else {
-        m_listener->setRecognitionResult(m_recognitionResult);
-        m_listener->didCompleteRecognition();
-        m_listener = 0;
+        m_listener->setRecognitionResult(m_requestId, m_recognitionResult);
+        m_listener->didCompleteRecognition(m_requestId);
+        m_requestId = 0;
     }
 }
 
index faca444037b8248e493c3eb8ce867372209d5dbe..7d5fda2c24c497e32b772f227d3ea62ba2713c33 100644 (file)
@@ -49,9 +49,10 @@ public:
     void setRecognitionResult(const String& result);
 
     // SpeechInputClient methods.
-    bool startRecognition(SpeechInputListener*);
-    void stopRecording();
-    void cancelRecognition();
+    void setListener(SpeechInputListener*);
+    bool startRecognition(int);
+    void stopRecording(int);
+    void cancelRecognition(int);
 
 private:
     void timerFired(Timer<SpeechInputClientMock>*);
@@ -59,6 +60,7 @@ private:
     bool m_recording;
     Timer<SpeechInputClientMock> m_timer;
     SpeechInputListener* m_listener;
+    int m_requestId;
     String m_recognitionResult;
 };
 
index f532101299952f44d936287508fffdf0647d0af5..9852aa6d61da07c360f2eb5a2bc10244a84d0c0d 100644 (file)
@@ -346,9 +346,20 @@ inline InputFieldSpeechButtonElement::InputFieldSpeechButtonElement(Node* shadow
     : TextControlInnerElement(shadowParent->document(), shadowParent)
     , m_capturing(false)
     , m_state(Idle)
+    , m_listenerId(document()->page()->speechInput()->registerListener(this))
 {
 }
 
+InputFieldSpeechButtonElement::~InputFieldSpeechButtonElement()
+{
+    SpeechInput* speech = speechInput();
+    if (speech)  { // Could be null when page is unloading.
+        if (m_state != Idle)
+            speech->cancelRecognition(m_listenerId);
+        speech->unregisterListener(m_listenerId);
+    }
+}
+
 PassRefPtr<InputFieldSpeechButtonElement> InputFieldSpeechButtonElement::create(Node* shadowParent)
 {
     return adoptRef(new InputFieldSpeechButtonElement(shadowParent));
@@ -386,11 +397,11 @@ void InputFieldSpeechButtonElement::defaultEventHandler(Event* event)
     if (event->type() == eventNames().clickEvent) {
         switch (m_state) {
         case Idle:
-            if (speechInput()->startRecognition(this))
+            if (speechInput()->startRecognition(m_listenerId))
                 setState(Recording);
             break;
         case Recording:
-            speechInput()->stopRecording();
+            speechInput()->stopRecording(m_listenerId);
             break;
         case Recognizing:
             // Nothing to do here, we will continue to wait for results.
@@ -413,20 +424,20 @@ void InputFieldSpeechButtonElement::setState(SpeechInputState state)
 
 SpeechInput* InputFieldSpeechButtonElement::speechInput()
 {
-    return document()->page()->speechInput();
+    return document()->page() ? document()->page()->speechInput() : 0;
 }
 
-void InputFieldSpeechButtonElement::didCompleteRecording()
+void InputFieldSpeechButtonElement::didCompleteRecording(int)
 {
     setState(Recognizing);
 }
 
-void InputFieldSpeechButtonElement::didCompleteRecognition()
+void InputFieldSpeechButtonElement::didCompleteRecognition(int)
 {
     setState(Idle);
 }
 
-void InputFieldSpeechButtonElement::setRecognitionResult(const String& result)
+void InputFieldSpeechButtonElement::setRecognitionResult(int, const String& result)
 {
     HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
     // The call to setValue() below dispatches an event, and an event handler in the page might
index e7ee98f515bad9e6aba3662b369ab92a036f65cc..3fbc9c8f9c87d238421d1b58632f7db6da2e5602 100644 (file)
@@ -126,15 +126,16 @@ public:
     };
 
     static PassRefPtr<InputFieldSpeechButtonElement> create(Node*);
+    virtual ~InputFieldSpeechButtonElement();
 
     virtual void detach();
     virtual void defaultEventHandler(Event*);
     SpeechInputState state() const { return m_state; }
 
     // SpeechInputListener methods.
-    void didCompleteRecording();
-    void didCompleteRecognition();
-    void setRecognitionResult(const String& result);
+    void didCompleteRecording(int);
+    void didCompleteRecognition(int);
+    void setRecognitionResult(int, const String& result);
 
 private:
     InputFieldSpeechButtonElement(Node*);
@@ -143,6 +144,7 @@ private:
 
     bool m_capturing;
     SpeechInputState m_state;
+    int m_listenerId;
 };
 
 #endif // ENABLE(INPUT_SPEECH)
index 2ad136b1f18a5f7a27d28c7e8b805d080ea5a4fd..a43139f9f208cad6b370d82865c7b20a468e7f96 100644 (file)
@@ -1,3 +1,38 @@
+2010-08-13  Satish Sampath  <satish@chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        Support for multiple speech enabled elements in same page.
+        https://bugs.webkit.org/show_bug.cgi?id=43922
+
+        * public/WebSpeechInputController.h: Bubbles up the requestId given by webcore to the embedder.
+        (WebKit::WebSpeechInputController::startRecognition):
+        (WebKit::WebSpeechInputController::cancelRecognition):
+        (WebKit::WebSpeechInputController::stopRecording):
+        * public/WebSpeechInputListener.h: Passes down the requestId given by embedder to webcore.
+        (WebKit::WebSpeechInputListener::didCompleteRecording):
+        (WebKit::WebSpeechInputListener::setRecognitionResult):
+        (WebKit::WebSpeechInputListener::didCompleteRecognition):
+        * src/SpeechInputClientImpl.cpp:
+        (WebKit::SpeechInputClientImpl::setListener):
+        (WebKit::SpeechInputClientImpl::startRecognition):
+        (WebKit::SpeechInputClientImpl::stopRecording):
+        (WebKit::SpeechInputClientImpl::cancelRecognition):
+        (WebKit::SpeechInputClientImpl::didCompleteRecording):
+        (WebKit::SpeechInputClientImpl::didCompleteRecognition):
+        (WebKit::SpeechInputClientImpl::setRecognitionResult):
+        * src/SpeechInputClientImpl.h:
+        * src/WebSpeechInputControllerMockImpl.cpp:
+        (WebKit::WebSpeechInputControllerMockImpl::WebSpeechInputControllerMockImpl):
+        (WebKit::WebSpeechInputControllerMockImpl::~WebSpeechInputControllerMockImpl):
+        (WebKit::WebSpeechInputControllerMockImpl::didCompleteRecording):
+        (WebKit::WebSpeechInputControllerMockImpl::didCompleteRecognition):
+        (WebKit::WebSpeechInputControllerMockImpl::setRecognitionResult):
+        (WebKit::WebSpeechInputControllerMockImpl::startRecognition):
+        (WebKit::WebSpeechInputControllerMockImpl::cancelRecognition):
+        (WebKit::WebSpeechInputControllerMockImpl::stopRecording):
+        * src/WebSpeechInputControllerMockImpl.h:
+
 2010-08-12  Yury Semikhatsky  <yurys@chromium.org>
 
         Reviewed by Pavel Feldman.
index 3dba5fb6bb1e2dd1d4ab093d193ee1cdad6dd813..b85fde67fcbfb745656553f0ac21db99bdcff20c 100644 (file)
@@ -41,14 +41,21 @@ public:
     // Starts speech recognition. Speech will get recorded until the endpointer detects silence,
     // runs to the limit or stopRecording is called. Progress indications and the recognized
     // text are returned via the listener interface.
+    virtual bool startRecognition(int)
+    {
+        return startRecognition();
+    }
+    // FIXME: Remove this once chromium has picked up this change.
     virtual bool startRecognition()
     {
-         WEBKIT_ASSERT_NOT_REACHED();
-         return false;
+        WEBKIT_ASSERT_NOT_REACHED();
+        return false;
     }
 
     // Cancels an ongoing recognition and discards any audio recorded so far. No partial
     // recognition results are returned to the listener.
+    virtual void cancelRecognition(int) { cancelRecognition(); }
+    // FIXME: Remove this once chromium has picked up this change.
     virtual void cancelRecognition() { WEBKIT_ASSERT_NOT_REACHED(); }
 
     // Stops audio recording and performs recognition with the audio recorded until now
@@ -56,6 +63,8 @@ public:
     // wants to stop recording audio as soon as they finished speaking. Otherwise, the speech
     // recording 'endpointer' should detect silence in the input and stop recording automatically.
     // Call startRecognition() to record audio and recognize speech again.
+    virtual void stopRecording(int) { stopRecording(); }
+    // FIXME: Remove this once chromium has picked up this change.
     virtual void stopRecording() { WEBKIT_ASSERT_NOT_REACHED(); }
 
 protected:
index f1756af1e9994007eaf81dfe4293f64ea2ecde06..e779c3a79d31abe01db000302307dfe358d15815 100644 (file)
@@ -47,19 +47,34 @@ public:
     // WebSpeechInputController::stopRecording() was called.
     // Typically after this call the listener would update the UI to reflect that recognition is
     // in progress.
-    virtual void didCompleteRecording() = 0;
+    virtual void didCompleteRecording(int) = 0;
+    // FIXME: Remove this once chromium has picked up this change.
+    virtual void didCompleteRecording()
+    {
+        didCompleteRecording(1);
+    }
 
     // Gives results from speech recognition, either partial or the final results.
     // This method can potentially get called multiple times if there are partial results
     // available as the user keeps speaking. If the speech could not be recognized properly
     // or if there was any other errors in the process, this method may never be called.
-    virtual void setRecognitionResult(const WebString&) = 0;
+    virtual void setRecognitionResult(int, const WebString&) = 0;
+    // FIXME: Remove this once chromium has picked up this change.
+    virtual void setRecognitionResult(const WebString& result)
+    {
+        setRecognitionResult(1, result);
+    }
 
     // Informs that speech recognition has completed. This gets invoked irrespective of whether
     // recognition was succesful or not, whether setRecognitionResult() was invoked or not. The
     // handler typically frees up any temporary resources allocated and waits for the next speech
     // recognition request.
-    virtual void didCompleteRecognition() = 0;
+    virtual void didCompleteRecognition(int) = 0;
+    // FIXME: Remove this once chromium has picked up this change.
+    virtual void didCompleteRecognition()
+    {
+        didCompleteRecognition(1);
+    }
 
 protected:
     ~WebSpeechInputListener() { }
index 66525e34e9b59f3796bddb2faf8b3008437e45db..9c59bae1312959d179699cb4178f8fcdf13d33a1 100644 (file)
@@ -51,41 +51,45 @@ SpeechInputClientImpl::~SpeechInputClientImpl()
 {
 }
 
-bool SpeechInputClientImpl::startRecognition(WebCore::SpeechInputListener* listener)
+void SpeechInputClientImpl::setListener(WebCore::SpeechInputListener* listener)
 {
     m_listener = listener;
-    return m_controller->startRecognition();
 }
 
-void SpeechInputClientImpl::stopRecording()
+bool SpeechInputClientImpl::startRecognition(int requestId)
 {
     ASSERT(m_listener);
-    m_controller->stopRecording();
+    return m_controller->startRecognition(requestId);
 }
 
-void SpeechInputClientImpl::cancelRecognition()
+void SpeechInputClientImpl::stopRecording(int requestId)
 {
     ASSERT(m_listener);
-    m_controller->cancelRecognition();
+    m_controller->stopRecording(requestId);
 }
 
-void SpeechInputClientImpl::didCompleteRecording()
+void SpeechInputClientImpl::cancelRecognition(int requestId)
 {
     ASSERT(m_listener);
-    m_listener->didCompleteRecording();
+    m_controller->cancelRecognition(requestId);
 }
 
-void SpeechInputClientImpl::didCompleteRecognition()
+void SpeechInputClientImpl::didCompleteRecording(int requestId)
 {
     ASSERT(m_listener);
-    m_listener->didCompleteRecognition();
-    m_listener = 0;
+    m_listener->didCompleteRecording(requestId);
 }
 
-void SpeechInputClientImpl::setRecognitionResult(const WebString& result)
+void SpeechInputClientImpl::didCompleteRecognition(int requestId)
 {
     ASSERT(m_listener);
-    m_listener->setRecognitionResult(result);
+    m_listener->didCompleteRecognition(requestId);
+}
+
+void SpeechInputClientImpl::setRecognitionResult(int requestId, const WebString& result)
+{
+    ASSERT(m_listener);
+    m_listener->setRecognitionResult(requestId, result);
 }
 
 } // namespace WebKit
index 5762da87e9f0ae9fa611a22d4f6ae017dab572bb..0ab54c1cac6a62cd49f8cbf7adc2552350c06bf9 100644 (file)
@@ -53,18 +53,19 @@ public:
     virtual ~SpeechInputClientImpl();
 
     // SpeechInputClient methods.
-    bool startRecognition(WebCore::SpeechInputListener*);
-    void stopRecording();
-    void cancelRecognition();
+    void setListener(WebCore::SpeechInputListener*);
+    bool startRecognition(int);
+    void stopRecording(int);
+    void cancelRecognition(int);
 
     // WebSpeechInputListener methods.
-    void didCompleteRecording();
-    void setRecognitionResult(const WebString&);
-    void didCompleteRecognition();
+    void didCompleteRecording(int);
+    void setRecognitionResult(int, const WebString&);
+    void didCompleteRecognition(int);
 
 private:
     WebSpeechInputController* m_controller; // To call into the embedder.
-    WebCore::SpeechInputListener* m_listener; // Valid when recognition is in progress.
+    WebCore::SpeechInputListener* m_listener;
 };
 
 } // namespace WebKit
index 6b043205ebfcf1260f40c8a48805a2ce318b6f2e..57e36353e70dcc490bc10d98eebdeb4b2bb619da 100644 (file)
@@ -46,6 +46,12 @@ WebSpeechInputControllerMockImpl::WebSpeechInputControllerMockImpl(
     : m_webcoreMock(new WebCore::SpeechInputClientMock())
     , m_listener(listener)
 {
+    m_webcoreMock->setListener(this);
+}
+
+WebSpeechInputControllerMockImpl::~WebSpeechInputControllerMockImpl()
+{
+    m_webcoreMock->setListener(0);
 }
 
 void WebSpeechInputControllerMockImpl::setMockRecognitionResult(const WebString& result)
@@ -53,34 +59,34 @@ void WebSpeechInputControllerMockImpl::setMockRecognitionResult(const WebString&
     m_webcoreMock->setRecognitionResult(result);
 }
 
-void WebSpeechInputControllerMockImpl::didCompleteRecording()
+void WebSpeechInputControllerMockImpl::didCompleteRecording(int requestId)
 {
-    m_listener->didCompleteRecording();
+    m_listener->didCompleteRecording(requestId);
 }
 
-void WebSpeechInputControllerMockImpl::didCompleteRecognition()
+void WebSpeechInputControllerMockImpl::didCompleteRecognition(int requestId)
 {
-    m_listener->didCompleteRecognition();
+    m_listener->didCompleteRecognition(requestId);
 }
 
-void WebSpeechInputControllerMockImpl::setRecognitionResult(const WTF::String& result)
+void WebSpeechInputControllerMockImpl::setRecognitionResult(int requestId, const WTF::String& result)
 {
-    m_listener->setRecognitionResult(result);
+    m_listener->setRecognitionResult(requestId, result);
 }
 
-bool WebSpeechInputControllerMockImpl::startRecognition()
+bool WebSpeechInputControllerMockImpl::startRecognition(int requestId)
 {
-    return m_webcoreMock->startRecognition(this);
+    return m_webcoreMock->startRecognition(requestId);
 }
 
-void WebSpeechInputControllerMockImpl::cancelRecognition()
+void WebSpeechInputControllerMockImpl::cancelRecognition(int requestId)
 {
-    m_webcoreMock->cancelRecognition();
+    m_webcoreMock->cancelRecognition(requestId);
 }
 
-void WebSpeechInputControllerMockImpl::stopRecording()
+void WebSpeechInputControllerMockImpl::stopRecording(int requestId)
 {
-    m_webcoreMock->stopRecording();
+    m_webcoreMock->stopRecording(requestId);
 }
 
 } // namespace WebKit
index 046abf3e1f838d36ecfbadd0efa8ca19ea0e5d58..38a15dfe7b3fdfe983f49b5aab260f37e9bd8598 100644 (file)
@@ -47,16 +47,17 @@ class WebSpeechInputControllerMockImpl : public WebCore::SpeechInputListener
                                        , public WebSpeechInputControllerMock {
 public:
     WebSpeechInputControllerMockImpl(WebSpeechInputListener*);
+    virtual ~WebSpeechInputControllerMockImpl();
 
     // WebCore::SpeechInputListener methods.
-    void didCompleteRecording();
-    void didCompleteRecognition();
-    void setRecognitionResult(const WTF::String& result);
+    void didCompleteRecording(int requestId);
+    void didCompleteRecognition(int requestId);
+    void setRecognitionResult(int requestId, const WTF::String& result);
 
     // WebSpeechInputController methods.
-    bool startRecognition();
-    void cancelRecognition();
-    void stopRecording();
+    bool startRecognition(int requestId);
+    void cancelRecognition(int requestId);
+    void stopRecording(int requestId);
 
     // WebSpeechInputControllerMock methods.
     void setMockRecognitionResult(const WebString& result);