#include "content/browser/media/media_web_contents_observer.h"
#include <memory>
#include <tuple>
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "content/browser/media/audible_metrics.h"
#include "content/browser/media/media_devices_util.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/device/public/mojom/wake_lock_context.mojom.h"
#include "services/media_session/public/cpp/media_position.h"
#include "third_party/blink/public/common/mediastream/media_devices.h"
#include "third_party/blink/public/platform/web_fullscreen_video_status.h"
#include "ui/gfx/geometry/size.h"
namespace content {
namespace {
AudibleMetrics* GetAudibleMetrics() { … }
}
class MediaWebContentsObserver::PlayerInfo { … };
MediaWebContentsObserver::MediaWebContentsObserver(
WebContentsImpl* web_contents)
: … { … }
MediaWebContentsObserver::~MediaWebContentsObserver() = default;
void MediaWebContentsObserver::WebContentsDestroyed() { … }
void MediaWebContentsObserver::RenderFrameDeleted(
RenderFrameHost* render_frame_host) { … }
void MediaWebContentsObserver::MaybeUpdateAudibleState() { … }
bool MediaWebContentsObserver::HasActiveEffectivelyFullscreenVideo() const { … }
bool MediaWebContentsObserver::IsPictureInPictureAllowedForFullscreenVideo()
const { … }
const std::optional<MediaPlayerId>&
MediaWebContentsObserver::GetFullscreenVideoMediaPlayerId() const { … }
void MediaWebContentsObserver::MediaPictureInPictureChanged(
bool is_picture_in_picture) { … }
void MediaWebContentsObserver::DidUpdateAudioMutingState(bool muted) { … }
void MediaWebContentsObserver::GetHasPlayedBefore(
GetHasPlayedBeforeCallback callback) { … }
void MediaWebContentsObserver::BindMediaPlayerObserverClient(
mojo::PendingReceiver<media::mojom::MediaPlayerObserverClient>
pending_receiver) { … }
void MediaWebContentsObserver::RequestPersistentVideo(bool value) { … }
bool MediaWebContentsObserver::IsPlayerActive(
const MediaPlayerId& player_id) const { … }
MediaWebContentsObserver::MediaPlayerHostImpl::MediaPlayerHostImpl(
GlobalRenderFrameHostId frame_routing_id,
MediaWebContentsObserver* media_web_contents_observer)
: … { … }
MediaWebContentsObserver::MediaPlayerHostImpl::~MediaPlayerHostImpl() = default;
void MediaWebContentsObserver::MediaPlayerHostImpl::AddMediaPlayerHostReceiver(
mojo::PendingAssociatedReceiver<media::mojom::MediaPlayerHost> receiver) { … }
void MediaWebContentsObserver::MediaPlayerHostImpl::OnMediaPlayerAdded(
mojo::PendingAssociatedRemote<media::mojom::MediaPlayer> media_player,
mojo::PendingAssociatedReceiver<media::mojom::MediaPlayerObserver>
media_player_observer,
int32_t player_id) { … }
MediaWebContentsObserver::MediaPlayerObserverHostImpl::
MediaPlayerObserverHostImpl(
const MediaPlayerId& media_player_id,
MediaWebContentsObserver* media_web_contents_observer)
: … { … }
MediaWebContentsObserver::MediaPlayerObserverHostImpl::
~MediaPlayerObserverHostImpl() = default;
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
BindMediaPlayerObserverReceiver(
mojo::PendingAssociatedReceiver<media::mojom::MediaPlayerObserver>
media_player_observer) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnMutedStatusChanged(bool muted) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnMediaMetadataChanged(bool has_audio,
bool has_video,
media::MediaContentType media_content_type) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnMediaPositionStateChanged(
const media_session::MediaPosition& media_position) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnMediaEffectivelyFullscreenChanged(
blink::WebFullscreenVideoStatus status) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::OnMediaSizeChanged(
const ::gfx::Size& size) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnPictureInPictureAvailabilityChanged(bool available) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnAudioOutputSinkChanged(const std::string& hashed_device_id) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnReceivedTranslatedDeviceId(
const std::optional<std::string>& translated_id) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnUseAudioServiceChanged(bool uses_audio_service) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnAudioOutputSinkChangingDisabled() { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnRemotePlaybackMetadataChange(
media_session::mojom::RemotePlaybackMetadataPtr
remote_playback_metadata) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::OnMediaPlaying() { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::OnMediaPaused(
bool stream_ended) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
NotifyAudioStreamMonitorIfNeeded() { … }
MediaWebContentsObserver::PlayerInfo*
MediaWebContentsObserver::MediaPlayerObserverHostImpl::GetPlayerInfo() { … }
MediaWebContentsObserver::PlayerInfo* MediaWebContentsObserver::GetPlayerInfo(
const MediaPlayerId& id) const { … }
void MediaWebContentsObserver::OnMediaMetadataChanged(
const MediaPlayerId& player_id,
bool has_audio,
bool has_video,
media::MediaContentType media_content_type) { … }
void MediaWebContentsObserver::OnMediaEffectivelyFullscreenChanged(
const MediaPlayerId& player_id,
blink::WebFullscreenVideoStatus fullscreen_status) { … }
void MediaWebContentsObserver::OnMediaPlaying() { … }
void MediaWebContentsObserver::OnAudioOutputSinkChangedWithRawDeviceId(
const MediaPlayerId& player_id,
const std::string& raw_device_id) { … }
void MediaWebContentsObserver::OnRemotePlaybackMetadataChange(
const MediaPlayerId& player_id,
media_session::mojom::RemotePlaybackMetadataPtr remote_playback_metadata) { … }
void MediaWebContentsObserver::MediaPlayerObserverHostImpl::
OnVideoVisibilityChanged(bool meets_visibility_threshold) { … }
bool MediaWebContentsObserver::IsMediaPlayerRemoteAvailable(
const MediaPlayerId& player_id) { … }
mojo::AssociatedRemote<media::mojom::MediaPlayer>&
MediaWebContentsObserver::GetMediaPlayerRemote(const MediaPlayerId& player_id) { … }
void MediaWebContentsObserver::OnMediaPlayerObserverDisconnected(
const MediaPlayerId& player_id) { … }
device::mojom::WakeLock* MediaWebContentsObserver::GetAudioWakeLock() { … }
void MediaWebContentsObserver::LockAudio() { … }
void MediaWebContentsObserver::CancelAudioLock() { … }
WebContentsImpl* MediaWebContentsObserver::web_contents_impl() const { … }
void MediaWebContentsObserver::BindMediaPlayerHost(
GlobalRenderFrameHostId frame_routing_id,
mojo::PendingAssociatedReceiver<media::mojom::MediaPlayerHost>
player_receiver) { … }
void MediaWebContentsObserver::OnMediaPlayerAdded(
mojo::PendingAssociatedRemote<media::mojom::MediaPlayer> player_remote,
mojo::PendingAssociatedReceiver<media::mojom::MediaPlayerObserver>
media_player_observer,
MediaPlayerId player_id) { … }
void MediaWebContentsObserver::SuspendAllMediaPlayers() { … }
void MediaWebContentsObserver::OnExperimentStateChanged(MediaPlayerId id,
bool is_starting) { … }
base::WeakPtr<MediaWebContentsObserver>
MediaWebContentsObserver::GetWeakPtrForFrame(
RenderFrameHost* render_frame_host) { … }
}