caption_bubble_controller.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (c) 2020 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 COMPONENTS_LIVE_CAPTION_CAPTION_BUBBLE_CONTROLLER_H_
  5. #define COMPONENTS_LIVE_CAPTION_CAPTION_BUBBLE_CONTROLLER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "components/live_caption/views/caption_bubble.h"
  9. #include "media/mojo/mojom/speech_recognition.mojom.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "ui/native_theme/caption_style.h"
  12. class PrefService;
  13. namespace content {
  14. class BrowserContext;
  15. }
  16. namespace captions {
  17. class CaptionBubbleContext;
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // Caption Bubble Controller
  20. //
  21. // The interface for the caption bubble controller. It controls the caption
  22. // bubble. It is responsible for tasks such as post-processing of the text that
  23. // might need to occur before it is displayed in the bubble, and hiding or
  24. // showing the caption bubble when captions are received. There exists one
  25. // caption bubble controller per profile.
  26. //
  27. class CaptionBubbleController {
  28. public:
  29. explicit CaptionBubbleController() = default;
  30. virtual ~CaptionBubbleController() = default;
  31. CaptionBubbleController(const CaptionBubbleController&) = delete;
  32. CaptionBubbleController& operator=(const CaptionBubbleController&) = delete;
  33. static std::unique_ptr<CaptionBubbleController> Create(
  34. PrefService* profile_prefs);
  35. // Called when a transcription is received from the service. Returns whether
  36. // the transcription result was set on the caption bubble successfully.
  37. // Transcriptions will halt if this returns false.
  38. virtual bool OnTranscription(
  39. CaptionBubbleContext* caption_bubble_context,
  40. const media::SpeechRecognitionResult& result) = 0;
  41. // Called when the speech service has an error.
  42. virtual void OnError(
  43. CaptionBubbleContext* caption_bubble_context,
  44. CaptionBubbleErrorType error_type,
  45. OnErrorClickedCallback error_clicked_callback,
  46. OnDoNotShowAgainClickedCallback error_silenced_callback) = 0;
  47. // Called when the audio stream has ended.
  48. virtual void OnAudioStreamEnd(
  49. CaptionBubbleContext* caption_bubble_context) = 0;
  50. // Called when the caption style changes.
  51. virtual void UpdateCaptionStyle(
  52. absl::optional<ui::CaptionStyle> caption_style) = 0;
  53. private:
  54. friend class LiveCaptionControllerTest;
  55. friend class LiveCaptionSpeechRecognitionHostTest;
  56. virtual bool IsWidgetVisibleForTesting() = 0;
  57. virtual std::string GetBubbleLabelTextForTesting() = 0;
  58. };
  59. } // namespace captions
  60. #endif // COMPONENTS_LIVE_CAPTION_CAPTION_BUBBLE_CONTROLLER_H_