aw_speech_recognition_manager_delegate.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2018 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. #ifndef ANDROID_WEBVIEW_BROWSER_AW_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
  5. #define ANDROID_WEBVIEW_BROWSER_AW_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
  6. #include "base/compiler_specific.h"
  7. #include "content/public/browser/speech_recognition_event_listener.h"
  8. #include "content/public/browser/speech_recognition_manager_delegate.h"
  9. #include "content/public/browser/speech_recognition_session_config.h"
  10. namespace android_webview {
  11. // Android WebView implementation of the SpeechRecognitionManagerDelgate
  12. // interface.
  13. class AwSpeechRecognitionManagerDelegate
  14. : public content::SpeechRecognitionManagerDelegate,
  15. public content::SpeechRecognitionEventListener {
  16. public:
  17. AwSpeechRecognitionManagerDelegate();
  18. AwSpeechRecognitionManagerDelegate(
  19. const AwSpeechRecognitionManagerDelegate&) = delete;
  20. AwSpeechRecognitionManagerDelegate& operator=(
  21. const AwSpeechRecognitionManagerDelegate&) = delete;
  22. ~AwSpeechRecognitionManagerDelegate() override;
  23. protected:
  24. // SpeechRecognitionEventListener methods.
  25. void OnRecognitionStart(int session_id) override;
  26. void OnAudioStart(int session_id) override;
  27. void OnEnvironmentEstimationComplete(int session_id) override;
  28. void OnSoundStart(int session_id) override;
  29. void OnSoundEnd(int session_id) override;
  30. void OnAudioEnd(int session_id) override;
  31. void OnRecognitionEnd(int session_id) override;
  32. void OnRecognitionResults(
  33. int session_id,
  34. const std::vector<blink::mojom::SpeechRecognitionResultPtr>& result)
  35. override;
  36. void OnRecognitionError(
  37. int session_id,
  38. const blink::mojom::SpeechRecognitionError& error) override;
  39. void OnAudioLevelsChange(int session_id,
  40. float volume,
  41. float noise_volume) override;
  42. // SpeechRecognitionManagerDelegate methods.
  43. void CheckRecognitionIsAllowed(
  44. int session_id,
  45. base::OnceCallback<void(bool ask_user, bool is_allowed)> callback)
  46. override;
  47. content::SpeechRecognitionEventListener* GetEventListener() override;
  48. bool FilterProfanities(int render_process_id) override;
  49. private:
  50. // Checks for mojom::ViewType::kTabContents host in the UI thread and notifies
  51. // back the result in the IO thread through |callback|.
  52. static void CheckRenderFrameType(
  53. base::OnceCallback<void(bool ask_user, bool is_allowed)> callback,
  54. int render_process_id,
  55. int render_frame_id);
  56. };
  57. } // namespace android_webview
  58. #endif // ANDROID_WEBVIEW_BROWSER_AW_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_