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  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
parent 5e845d41
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.
......@@ -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
......
......@@ -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
......
......@@ -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() { }
......
......@@ -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() { }
......
......@@ -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;
}
}
......
......@@ -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;
};
......
......@@ -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
......
......@@ -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)
......
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.
......
......@@ -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:
......
......@@ -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() { }
......
......@@ -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
......
......@@ -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
......
......@@ -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&
<