2022-07-20 08:09:14 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jeremy Rose <japthorp@slack-corp.com>
|
|
|
|
Date: Tue, 12 Jul 2022 16:51:43 -0700
|
|
|
|
Subject: short-circuit permissions checks in MediaStreamDevicesController
|
|
|
|
|
|
|
|
The //components/permissions architecture is complicated and not that
|
|
|
|
widely used in Chromium, and mostly oriented around showing permissions
|
|
|
|
UI and/or remembering per-site permissions, which we're not interested
|
|
|
|
in.
|
|
|
|
|
|
|
|
Since we do a permissions check prior to invoking the
|
|
|
|
MediaStreamDevicesController, and don't (yet) provide the ability to set
|
|
|
|
granular permissions (e.g. allow video but not audio), just
|
|
|
|
short-circuit all the permissions checks in MSDC for now to allow us to
|
|
|
|
unduplicate this code.
|
|
|
|
|
|
|
|
diff --git a/components/webrtc/media_stream_devices_controller.cc b/components/webrtc/media_stream_devices_controller.cc
|
2024-05-10 15:21:10 +00:00
|
|
|
index fd5f81970957d970b7d234f45c4948395a461a7a..386599be509389c9bf850c330e76e449dd685318 100644
|
2022-07-20 08:09:14 +00:00
|
|
|
--- a/components/webrtc/media_stream_devices_controller.cc
|
|
|
|
+++ b/components/webrtc/media_stream_devices_controller.cc
|
2023-03-10 16:07:42 +00:00
|
|
|
@@ -57,7 +57,8 @@ bool PermissionIsRequested(blink::PermissionType permission,
|
2023-01-11 10:55:31 +00:00
|
|
|
void MediaStreamDevicesController::RequestPermissions(
|
|
|
|
const content::MediaStreamRequest& request,
|
|
|
|
MediaStreamDeviceEnumerator* enumerator,
|
|
|
|
- ResultCallback callback) {
|
|
|
|
+ ResultCallback callback,
|
|
|
|
+ bool previously_approved) {
|
|
|
|
content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
|
|
|
|
request.render_process_id, request.render_frame_id);
|
|
|
|
// The RFH may have been destroyed by the time the request is processed.
|
2024-01-25 17:46:30 +00:00
|
|
|
@@ -92,7 +93,7 @@ void MediaStreamDevicesController::RequestPermissions(
|
|
|
|
std::move(callback)));
|
2022-07-20 08:09:14 +00:00
|
|
|
|
|
|
|
std::vector<blink::PermissionType> permission_types;
|
2024-01-25 17:46:30 +00:00
|
|
|
-
|
2022-07-20 08:09:14 +00:00
|
|
|
+#if 0
|
2022-09-07 07:46:37 +00:00
|
|
|
content::PermissionController* permission_controller =
|
|
|
|
web_contents->GetBrowserContext()->GetPermissionController();
|
2022-07-20 08:09:14 +00:00
|
|
|
|
2024-01-25 17:46:30 +00:00
|
|
|
@@ -165,19 +166,26 @@ void MediaStreamDevicesController::RequestPermissions(
|
|
|
|
requested_audio_capture_device_ids;
|
|
|
|
permission_request_description.requested_video_capture_device_ids =
|
|
|
|
requested_video_capture_device_ids;
|
|
|
|
-
|
2022-07-20 08:09:14 +00:00
|
|
|
+#endif
|
2023-01-11 10:55:31 +00:00
|
|
|
// It is OK to ignore `request.security_origin` because it will be calculated
|
|
|
|
// from `render_frame_host` and we always ignore `requesting_origin` for
|
|
|
|
// `AUDIO_CAPTURE` and `VIDEO_CAPTURE`.
|
|
|
|
// `render_frame_host->GetMainFrame()->GetLastCommittedOrigin()` will be used
|
|
|
|
// instead.
|
|
|
|
- rfh->GetBrowserContext()
|
|
|
|
- ->GetPermissionController()
|
|
|
|
- ->RequestPermissionsFromCurrentDocument(
|
2024-01-25 17:46:30 +00:00
|
|
|
- rfh, permission_request_description,
|
2023-01-11 10:55:31 +00:00
|
|
|
- base::BindOnce(
|
|
|
|
- &MediaStreamDevicesController::PromptAnsweredGroupedRequest,
|
|
|
|
- std::move(controller)));
|
|
|
|
+ if (previously_approved) {
|
|
|
|
+ controller->PromptAnsweredGroupedRequest({blink::mojom::PermissionStatus::GRANTED /*audio*/,
|
|
|
|
+ blink::mojom::PermissionStatus::GRANTED /*video*/});
|
|
|
|
+ } else {
|
|
|
|
+ rfh->GetBrowserContext()
|
2023-09-06 01:17:56 +00:00
|
|
|
+ ->GetPermissionController()
|
|
|
|
+ ->RequestPermissionsFromCurrentDocument(
|
|
|
|
+ rfh,
|
|
|
|
+ content::PermissionRequestDescription(permission_types,
|
|
|
|
+ request.user_gesture),
|
|
|
|
+ base::BindOnce(
|
|
|
|
+ &MediaStreamDevicesController::PromptAnsweredGroupedRequest,
|
|
|
|
+ std::move(controller)));
|
2023-01-11 10:55:31 +00:00
|
|
|
+ }
|
|
|
|
}
|
2022-07-20 08:09:14 +00:00
|
|
|
|
2023-01-11 10:55:31 +00:00
|
|
|
MediaStreamDevicesController::~MediaStreamDevicesController() {
|
2024-02-29 09:31:13 +00:00
|
|
|
@@ -429,6 +437,7 @@ bool MediaStreamDevicesController::PermissionIsBlockedForReason(
|
2022-07-20 08:09:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-09-07 07:46:37 +00:00
|
|
|
|
2022-07-20 08:09:14 +00:00
|
|
|
+#if 0
|
2022-09-07 07:46:37 +00:00
|
|
|
// TODO(raymes): This function wouldn't be needed if
|
|
|
|
// PermissionManager::RequestPermissions returned a denial reason.
|
|
|
|
content::PermissionResult result =
|
2024-02-29 09:31:13 +00:00
|
|
|
@@ -439,6 +448,7 @@ bool MediaStreamDevicesController::PermissionIsBlockedForReason(
|
2022-09-07 07:46:37 +00:00
|
|
|
DCHECK_EQ(blink::mojom::PermissionStatus::DENIED, result.status);
|
2022-07-20 08:09:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
+#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-01-11 10:55:31 +00:00
|
|
|
diff --git a/components/webrtc/media_stream_devices_controller.h b/components/webrtc/media_stream_devices_controller.h
|
2024-02-14 17:33:32 +00:00
|
|
|
index 4d3bf184243a4c1296f41070e934730a3bd2620e..78610ff9fb93cfa1c9aae898d6f8c83520fc860a 100644
|
2023-01-11 10:55:31 +00:00
|
|
|
--- a/components/webrtc/media_stream_devices_controller.h
|
|
|
|
+++ b/components/webrtc/media_stream_devices_controller.h
|
|
|
|
@@ -48,7 +48,8 @@ class MediaStreamDevicesController {
|
|
|
|
// synchronously or asynchronously returned via |callback|.
|
|
|
|
static void RequestPermissions(const content::MediaStreamRequest& request,
|
|
|
|
MediaStreamDeviceEnumerator* enumerator,
|
|
|
|
- ResultCallback callback);
|
|
|
|
+ ResultCallback callback,
|
|
|
|
+ bool previously_approved = false);
|
|
|
|
|
|
|
|
~MediaStreamDevicesController();
|
|
|
|
|