Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / speech / chrome_speech_recognition_manager_delegate_bubble_ui.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_MANAGER_DELEGATE_BUBBLE_UI_H_
6 #define CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_MANAGER_DELEGATE_BUBBLE_UI_H_
7
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
10 #include "chrome/browser/speech/speech_recognition_bubble_controller.h"
11
12 namespace speech {
13
14 // This class extends ChromeSpeechRecognitionManagerDelegate to add the behavior
15 // required to handle the (bubble) UI for speech recognition sessions initiated
16 // by input elements with a x-webkit-speech attribute. This extended behavior is
17 // achieved by means of overriding some SpeechRecognitionEventListener methods
18 // and intercepting the calls required to show, animate and hide the bubble UI.
19 class ChromeSpeechRecognitionManagerDelegateBubbleUI
20     : public ChromeSpeechRecognitionManagerDelegate,
21       public SpeechRecognitionBubbleControllerDelegate {
22  public:
23   ChromeSpeechRecognitionManagerDelegateBubbleUI();
24   virtual ~ChromeSpeechRecognitionManagerDelegateBubbleUI();
25
26  protected:
27   // SpeechRecognitionBubbleControllerDelegate methods.
28   virtual void InfoBubbleButtonClicked(
29       int session_id, SpeechRecognitionBubble::Button button) OVERRIDE;
30   virtual void InfoBubbleFocusChanged(int session_id) OVERRIDE;
31
32   // Overridden base class SpeechRecognitionEventListener methods.
33   virtual void OnRecognitionStart(int session_id) OVERRIDE;
34   virtual void OnAudioStart(int session_id) OVERRIDE;
35   virtual void OnAudioEnd(int session_id) OVERRIDE;
36   virtual void OnRecognitionEnd(int session_id) OVERRIDE;
37   virtual void OnRecognitionError(
38       int session_id, const content::SpeechRecognitionError& error) OVERRIDE;
39   virtual void OnAudioLevelsChange(
40       int session_id, float volume, float noise_volume) OVERRIDE;
41
42   // Starts a new recognition session, using the config of the last one
43   // (which is copied into |last_session_config_|). Used for "try again".
44   void RestartLastSession();
45
46   // Called on the UI thread by the base class when tab closure was detected.
47   virtual void TabClosedCallback(
48       int render_process_id, int render_view_id) OVERRIDE;
49
50  private:
51   // Lazy initializer for bubble controller.
52   SpeechRecognitionBubbleController* GetBubbleController();
53
54   scoped_refptr<SpeechRecognitionBubbleController> bubble_controller_;
55   scoped_ptr<content::SpeechRecognitionSessionConfig> last_session_config_;
56
57   DISALLOW_COPY_AND_ASSIGN(ChromeSpeechRecognitionManagerDelegateBubbleUI);
58 };
59
60 }  // namespace speech
61
62 #endif  // CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_MANAGER_DELEGATE_BUBBLE_UI_H_