#include "chrome/browser/media/webrtc/display_media_access_handler.h"
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/bad_message.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/media/webrtc/capture_policy_utils.h"
#include "chrome/browser/media/webrtc/desktop_capture_devices_util.h"
#include "chrome/browser/media/webrtc/desktop_media_picker_factory_impl.h"
#include "chrome/browser/media/webrtc/native_desktop_media_list.h"
#include "chrome/browser/media/webrtc/tab_desktop_media_list.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/user_interaction_observer.h"
#include "chrome/browser/ui/url_identity.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_media_id.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 "content/public/common/url_constants.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"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
#endif
BASE_FEATURE(…);
namespace {
constexpr UrlIdentity::TypeSet allowed_types = …;
constexpr UrlIdentity::FormatOptions options = …;
std::u16string GetApplicationTitle(content::WebContents* web_contents) { … }
}
DisplayMediaAccessHandler::DisplayMediaAccessHandler()
: … { … }
DisplayMediaAccessHandler::DisplayMediaAccessHandler(
std::unique_ptr<DesktopMediaPickerFactory> picker_factory,
bool display_notification)
: … { … }
DisplayMediaAccessHandler::~DisplayMediaAccessHandler() = default;
bool DisplayMediaAccessHandler::SupportsStreamType(
content::WebContents* web_contents,
const blink::mojom::MediaStreamType stream_type,
const extensions::Extension* extension) { … }
bool DisplayMediaAccessHandler::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type,
const extensions::Extension* extension) { … }
void DisplayMediaAccessHandler::HandleRequest(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
const extensions::Extension* extension) { … }
void DisplayMediaAccessHandler::UpdateMediaRequestState(
int render_process_id,
int render_frame_id,
int page_request_id,
blink::mojom::MediaStreamType stream_type,
content::MediaRequestState state) { … }
void DisplayMediaAccessHandler::ShowMediaSelectionDialog(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback) { … }
void DisplayMediaAccessHandler::BypassMediaSelectionDialog(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback) { … }
void DisplayMediaAccessHandler::ProcessChangeSourceRequest(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback) { … }
void DisplayMediaAccessHandler::ProcessQueuedAccessRequest(
const RequestsQueue& queue,
content::WebContents* web_contents) { … }
void DisplayMediaAccessHandler::ProcessQueuedPickerRequest(
const PendingAccessRequest& pending_request,
content::WebContents* web_contents,
AllowedScreenCaptureLevel capture_level,
const GURL& request_origin) { … }
void DisplayMediaAccessHandler::ProcessQueuedChangeSourceRequest(
const content::MediaStreamRequest& request,
content::WebContents* web_contents) { … }
void DisplayMediaAccessHandler::RejectRequest(
content::WebContents* web_contents,
blink::mojom::MediaStreamRequestResult result) { … }
void DisplayMediaAccessHandler::AcceptRequest(
content::WebContents* web_contents,
const content::DesktopMediaID& media_id) { … }
void DisplayMediaAccessHandler::OnDisplaySurfaceSelected(
base::WeakPtr<content::WebContents> web_contents,
content::DesktopMediaID media_id) { … }
#if BUILDFLAG(IS_CHROMEOS)
void DisplayMediaAccessHandler::OnDlpRestrictionChecked(
base::WeakPtr<content::WebContents> web_contents,
const content::DesktopMediaID& media_id,
bool is_dlp_allowed) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!web_contents) {
return;
}
if (!is_dlp_allowed) {
RejectRequest(web_contents.get(),
blink::mojom::MediaStreamRequestResult::PERMISSION_DENIED);
}
AcceptRequest(web_contents.get(), media_id);
}
#endif
void DisplayMediaAccessHandler::DeletePendingAccessRequest(
int render_process_id,
int render_frame_id,
int page_request_id) { … }
void DisplayMediaAccessHandler::WebContentsDestroyed(
content::WebContents* web_contents) { … }