Bug 271688 - getDisplayMedia is not showing sharing picker after delegating requestMediaCapturePermissionFor
Summary: getDisplayMedia is not showing sharing picker after delegating requestMediaCa...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Other
Hardware: Mac (Apple Silicon) macOS 14
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-03-25 21:17 PDT by jason
Modified: 2024-03-29 00:34 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jason 2024-03-25 21:17:50 PDT
- Scenario

We delegated [webView:requestMediaCapturePermissionForOrigin:initiatedByFrame:type:decisionHandler:] only and called navigator.mediaDevices.getDisplayMedia() on JavaScript. It will not show the ScreenCapture picker (SCContentSharingPicker) and deny the request.

* Reproducible example: https://gist.github.com/pewsheen/9685c2a3a77c1303d5026b7a8dd9e893
* Test page: https://webrtc.github.io/samples/src/content/getusermedia/getdisplaymedia/
* Console:

default	11:48:25.720336+0800	aa	UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(AD3DE9E20BF5B109) 116
default	11:48:25.720458+0800	aa	UserMediaPermissionRequestManagerProxy::processUserMediaPermissionRequest(AD3DE9E20BF5B109) 116, persistent access: false
default	11:48:25.720537+0800	aa	UserMediaPermissionRequestManagerProxy::processUserMediaPermissionValidRequest(AD3DE9E20BF5B109) 116, video: 0 audio: 0
default	11:48:25.720561+0800	aa	UserMediaPermissionRequestManagerProxy::processUserMediaPermissionValidRequest(AD3DE9E20BF5B109) 116, action: Prompt
default	11:48:25.720608+0800	aa	UserMediaPermissionRequestManagerProxy::denyRequest(AD3DE9E20BF5B109) 116, reason: PermissionDenied

- Expected behavior

Even if we delegated requestMediaCapturePermissionForOrigin, it should show SCContentSharingPicker when calling getDisplayMedia().


The following is my guess...

The condition here: https://github.com/WebKit/WebKit/blob/a0b7f7faeffb5ec679ddd471a0f7c68a91a37715/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm#L1273 shows that if any one of request methods delegated, then it will not perform the default action for all the request methods.

When we delegate requestMediaCapturePermissionForOrigin and call getDisplayMedia(), it will go to the line: https://github.com/WebKit/WebKit/blob/a0b7f7faeffb5ec679ddd471a0f7c68a91a37715/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm#L1281 to prompt for display capture permission, and somehow https://github.com/WebKit/WebKit/blob/a0b7f7faeffb5ec679ddd471a0f7c68a91a37715/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm#L1212 canRequestDisplayCapturePermission returns false? So that if we didn't delegate [_webView:requestDisplayCapturePermissionForOrigin:initiatedByFrame:withSystemAudio:decisionHandler:] as well, it will deny the request https://github.com/WebKit/WebKit/blob/a0b7f7faeffb5ec679ddd471a0f7c68a91a37715/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm#L1218-L1221

Also, requestDisplayCapturePermissionForOrigin isn't listed on the developer document. Is is a private API?
Comment 1 Radar WebKit Bug Importer 2024-03-29 00:34:21 PDT
<rdar://problem/125601197>