#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include <memory>
#include <utility>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/media/media_access_handler.h"
#include "chrome/browser/media/prefs/capture_device_ranking.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/user_prefs/user_prefs.h"
#include "components/webrtc/media_stream_devices_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/media_capture_devices.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/buildflags/buildflags.h"
#include "media/base/media_switches.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#if BUILDFLAG(IS_ANDROID)
#include "content/public/common/content_features.h"
#else
#include "chrome/browser/media/webrtc/display_media_access_handler.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/media/chromeos_login_and_lock_media_access_handler.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/controlled_frame/controlled_frame_media_access_handler.h"
#include "chrome/browser/media/extension_media_access_handler.h"
#include "chrome/browser/media/webrtc/desktop_capture_access_handler.h"
#include "chrome/browser/media/webrtc/tab_capture_access_handler.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/permissions/permissions_data.h"
#endif
MediaStreamDevices;
BrowserThread;
MediaCaptureDevices;
namespace {
content::WebContents* WebContentsFromIds(int render_process_id,
int render_frame_id) { … }
}
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { … }
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
: … { … }
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() { … }
void MediaCaptureDevicesDispatcher::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
void MediaCaptureDevicesDispatcher::AddObserver(Observer* observer) { … }
void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* observer) { … }
void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
const extensions::Extension* extension) { … }
bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type) { … }
bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type,
const extensions::Extension* extension) { … }
void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() { … }
const MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() const { … }
const MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() const { … }
const std::optional<blink::MediaStreamDevice>
MediaCaptureDevicesDispatcher::GetPreferredAudioDeviceForBrowserContext(
content::BrowserContext* context,
const std::vector<std::string>& eligible_device_ids) const { … }
const std::optional<blink::MediaStreamDevice>
MediaCaptureDevicesDispatcher::GetPreferredVideoDeviceForBrowserContext(
content::BrowserContext* context,
const std::vector<std::string>& eligible_device_ids) const { … }
scoped_refptr<MediaStreamCaptureIndicator>
MediaCaptureDevicesDispatcher::GetMediaStreamCaptureIndicator() { … }
void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() { … }
void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() { … }
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
int render_process_id,
int render_frame_id,
int page_request_id,
const GURL& security_origin,
blink::mojom::MediaStreamType stream_type,
content::MediaRequestState state) { … }
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(int render_process_id,
int render_frame_id) { … }
void MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread() { … }
void MediaCaptureDevicesDispatcher::NotifyVideoDevicesChangedOnUIThread() { … }
void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
int render_process_id,
int render_frame_id,
int page_request_id,
blink::mojom::MediaStreamType stream_type,
content::MediaRequestState state) { … }
void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread(
int render_process_id,
int render_frame_id) { … }
bool MediaCaptureDevicesDispatcher::IsInsecureCapturingInProgress(
int render_process_id,
int render_frame_id) { … }
void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices(
const MediaStreamDevices& devices) { … }
void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices(
const MediaStreamDevices& devices) { … }
void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
int render_process_id,
int render_frame_id,
int page_request_id,
blink::mojom::MediaStreamType stream_type,
bool is_secure) { … }
void MediaCaptureDevicesDispatcher::UpdateVideoScreenCaptureStatus(
int render_process_id,
int render_frame_id,
int page_request_id,
blink::mojom::MediaStreamType stream_type,
bool is_secure) { … }