1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ACCESSIBILITY_LIVE_CAPTION_LIVE_CAPTION_UNAVAILABILITY_NOTIFIER_H_
#define CHROME_BROWSER_ACCESSIBILITY_LIVE_CAPTION_LIVE_CAPTION_UNAVAILABILITY_NOTIFIER_H_
#include <memory>
#include "base/memory/weak_ptr.h"
#include "components/live_caption/views/caption_bubble_model.h"
#include "content/public/browser/document_service.h"
#include "content/public/browser/web_contents_observer.h"
#include "media/mojo/mojom/renderer_extensions.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
class PrefChangeRegistrar;
class PrefService;
namespace content {
class RenderFrameHost;
}
namespace captions {
class CaptionBubbleContextBrowser;
class LiveCaptionController;
// Used to notify the browser that the renderer does not support Live Caption.
class LiveCaptionUnavailabilityNotifier
: public content::DocumentService<
media::mojom::MediaFoundationRendererNotifier>,
public media::mojom::MediaFoundationRendererObserver {
public:
LiveCaptionUnavailabilityNotifier(const LiveCaptionUnavailabilityNotifier&) =
delete;
LiveCaptionUnavailabilityNotifier& operator=(
const LiveCaptionUnavailabilityNotifier&) = delete;
// static
static void Create(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<media::mojom::MediaFoundationRendererNotifier>
receiver);
// media::mojom::MediaFoundationRendererNotifier:
void MediaFoundationRendererCreated(
mojo::PendingReceiver<media::mojom::MediaFoundationRendererObserver>
observer) override;
private:
LiveCaptionUnavailabilityNotifier(
content::RenderFrameHost& frame_host,
mojo::PendingReceiver<media::mojom::MediaFoundationRendererNotifier>
pending_receiver);
~LiveCaptionUnavailabilityNotifier() override;
friend class LiveCaptionUnavailabilityNotifierTest;
content::WebContents* GetWebContents();
// Returns the LiveCaptionController for frame_host_. Returns nullptr if it
// does not exist.
LiveCaptionController* GetLiveCaptionController();
bool ShouldDisplayMediaFoundationRendererError();
bool ErrorSilencedForOrigin();
void DisplayMediaFoundationRendererError();
void OnMediaFoundationRendererErrorDoNotShowAgainCheckboxClicked(
CaptionBubbleErrorType error_type,
bool checked);
void OnMediaFoundationRendererErrorClicked();
void OnSpeechRecognitionAvailabilityChanged();
mojo::ReceiverSet<media::mojom::MediaFoundationRendererObserver> observers_;
std::unique_ptr<CaptionBubbleContextBrowser> context_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
raw_ptr<PrefService> profile_prefs_;
base::WeakPtrFactory<LiveCaptionUnavailabilityNotifier> weak_factory_{this};
};
} // namespace captions
#endif // CHROME_BROWSER_ACCESSIBILITY_LIVE_CAPTION_LIVE_CAPTION_UNAVAILABILITY_NOTIFIER_H_
|