Skip to content

Handle WebView media-capture permission requests#199

Merged
mbarta merged 2 commits into
mainfrom
mb/media_permissions
May 14, 2026
Merged

Handle WebView media-capture permission requests#199
mbarta merged 2 commits into
mainfrom
mb/media_permissions

Conversation

@mbarta
Copy link
Copy Markdown
Collaborator

@mbarta mbarta commented May 11, 2026

This PR adds support for WebView-issued PermissionRequests for camera and microphone, so pages can use getUserMedia({ audio, video }) without the host app having to wire up WebChromeClient.onPermissionRequest itself.

Key Changes

WebViewPermissionDelegate — New delegate alongside the existing GeolocationPermissionDelegate. Handles RESOURCE_AUDIO_CAPTURE (requires RECORD_AUDIO + MODIFY_AUDIO_SETTINGS) and RESOURCE_VIDEO_CAPTURE (requires CAMERA). Only the runtime-level permissions are requested; MODIFY_AUDIO_SETTINGS is install-time but must still be declared, otherwise Chromium's audio pipeline fails with Unable to select communication device! even after RECORD_AUDIO is granted. If a required manifest entry is missing the whole request is denied (and a warning logged) so the page sees NotAllowedError.

activityMultiplePermissionsResultLauncher — New hook on VisitDestination / HotwireDestination, mirroring the existing single-permission hook. HotwireWebFragmentDelegate registers a RequestMultiplePermissions launcher for HOTWIRE_REQUEST_CODE_WEBVIEW_PERMISSION so a combined audio + video request can be resolved in one prompt.

Cancellation safetyHotwireWebChromeClient forwards onPermissionRequestCanceled to the delegate, which clears any matching pending state. The delegate also denies a previously-held request before storing a new one, so the WebView always gets a verdict instead of an orphaned request being silently dropped.

Host app requirements

Client apps that want to enable media capture must declare the relevant permissions in their AndroidManifest.xml:

<!-- For microphone -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />                                                                                 
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
                                                                                                                                                   
<!-- For camera -->                                             
<uses-permission android:name="android.permission.CAMERA" />

mbarta and others added 2 commits May 7, 2026 15:56
Adds WebViewPermissionDelegate alongside the existing
GeolocationPermissionDelegate. It plugs into WebChromeClient.onPermissionRequest
and supports both RESOURCE_AUDIO_CAPTURE (RECORD_AUDIO + MODIFY_AUDIO_SETTINGS)
and RESOURCE_VIDEO_CAPTURE (CAMERA), runtime-requesting only the dangerous
permissions and denying the whole request when any required manifest entry is
missing. VisitDestination and HotwireDestination get a new
activityMultiplePermissionsResultLauncher hook so a single result launcher can
return Map<String, Boolean> for combined audio + video requests; both
HotwireWebFragment and HotwireWebBottomSheetFragment route the new
HOTWIRE_REQUEST_CODE_WEBVIEW_PERMISSION code to the launcher registered in
HotwireWebFragmentDelegate via RequestMultiplePermissions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A second WebView PermissionRequest could previously orphan the first by
overwriting pendingRequest without giving the WebView a verdict, and a
canceled request could still be granted/denied later when the runtime
permission result arrived. WebViewPermissionDelegate now denies any held
request before storing a new one and exposes onCancel to clear matching
pending state. HotwireWebChromeClient forwards onPermissionRequestCanceled
to the delegate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mbarta mbarta requested review from jayohms and jhutarek May 11, 2026 12:45
@mbarta mbarta self-assigned this May 11, 2026
@leonvogt
Copy link
Copy Markdown
Contributor

Very nice feature! 🎉
This would simplify camera / microphone access by a lot!

@mbarta mbarta merged commit 27374c6 into main May 14, 2026
1 check passed
@mbarta mbarta deleted the mb/media_permissions branch May 14, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants