feat(android): add scoped WebView permission handler for getUserMedia - #5855
feat(android): add scoped WebView permission handler for getUserMedia#5855mortenolsrud wants to merge 2 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAndroid WebView support now includes console logging, local camera and microphone permission handling, and HTML file selection. The manifest declares microphone access. MainActivity resolves runtime permission results and returns selected file URIs. ChangesAndroid WebView access
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant WebView
participant WebChromeClient
participant MainActivity
participant AndroidRuntimePermissions
WebView->>WebChromeClient: Request camera or microphone access
WebChromeClient->>MainActivity: Request unresolved Android permissions
MainActivity->>AndroidRuntimePermissions: Start runtime permission request
AndroidRuntimePermissions-->>MainActivity: Return permission results
MainActivity->>WebView: Grant or deny WebView resources
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@v3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/MainActivity.java`:
- Around line 260-268: Before assigning the new request in the
runtime-permission branch of onPermissionRequest, check whether
pendingWebViewPermissionRequest is non-null and call its deny() method. Then
replace it with the new request and continue requesting permissions, preserving
the existing immediate-grant path.
- Around line 242-262: Build a separate list of grantable resources while
iterating through request.getResources() in the permission-mapping loop, adding
each validated resource (like RESOURCE_VIDEO_CAPTURE or RESOURCE_AUDIO_CAPTURE)
to this grantable list alongside the Android permissions. In the anchor location
at lines 242-262, replace the request.grant(request.getResources()) call with
request.grant() passing only the validated grantable resources. Apply the same
fix at the sibling location lines 341-359 in onRequestPermissionsResult: build
and pass only the grantable resources list instead of passing all original
resources.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9e6b39da-7b38-465d-be1f-fd0facbe0796
📒 Files selected for processing (2)
v3/internal/commands/build_assets/android/app/src/main/AndroidManifest.xmlv3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/MainActivity.java
33a120c to
acd1098
Compare
|
Both findings addressed in the force-pushed commit: 1. Resource whitelist (L262): 2. Deny-before-overwrite (L268): If |
…5781) HTML <input type="file"> elements did nothing on Android because the generated MainActivity set only a WebViewClient and never a WebChromeClient, so the WebView had no onShowFileChooser handler to open the system document picker. Add a WebChromeClient whose onShowFileChooser launches the intent from FileChooserParams and delivers the selected URIs back via FileChooserParams.parseResult in onActivityResult. This also enables JS dialogs, console logging and in-page permission prompts that require a WebChromeClient.
cbd6fa2 to
a9a8459
Compare
The WebChromeClient had no onPermissionRequest override, so in-page permission prompts (navigator.getUserMedia for camera/mic, WebRTC) were silently auto-denied by the default implementation. Add an onPermissionRequest handler that: - Only grants for the local Wails origin (wails.localhost); requests from any other origin are unconditionally denied (security gate) - Maps WebView resources (VIDEO_CAPTURE, AUDIO_CAPTURE) to Android runtime permissions (CAMERA, RECORD_AUDIO) - Requests runtime permissions before granting, holding the PermissionRequest until onRequestPermissionsResult delivers the verdict - Grants RESOURCE_PROTECTED_MEDIA_ID and RESOURCE_MIDI_SYSEX implicitly (no runtime permission required) Also adds RECORD_AUDIO to the manifest (CAMERA was already declared).
a9a8459 to
ed72c7f
Compare
Description
The
WebChromeClient(added in #5807) had noonPermissionRequestoverride, so in-page permission prompts —navigator.getUserMediafor camera/mic, WebRTC — were silently auto-denied by the WebView's default implementation. Any web app feature relying on in-page media capture simply didn't work on Android.This adds a scoped
onPermissionRequesthandler that:wails.localhost) is granted permissions. Requests from any other origin (if the WebView were ever navigated away) are unconditionally denied. This is a security gate that prevents remote content from accessing the camera/mic.RESOURCE_VIDEO_CAPTURE→android.permission.CAMERA,RESOURCE_AUDIO_CAPTURE→android.permission.RECORD_AUDIO.PermissionRequestuntilonRequestPermissionsResultdelivers the user's verdict, then grants or denies accordingly.RESOURCE_PROTECTED_MEDIA_IDandRESOURCE_MIDI_SYSEXrequire no runtime permission — they pass through.Also adds
RECORD_AUDIOto the Android manifest (CAMERAwas already declared).Type of change
How Has This Been Tested?
Verified end-to-end on an Android emulator (Pixel 7, API 35, x86_64, headless/swiftshader):
wails3 initproject with agetUserMedia({video:true, audio:true})button was built from this branch's templates.onPermissionRequest→ the Android camera permission dialog appeared ("Allow Wails App to take pictures and record video?").getUserMedia({video:true})returned SUCCESS: 1 track (video:camera2 0, facing front) from the emulator's virtual camera.NotReadableError: Could not start audio source— this is expected when the emulator runs with-no-audio(no hardware audio device); the permission itself was correctly granted.Also:
Java compiled via gradle (
./gradlew compileDebugJavaWithJavac) — BUILD SUCCESSFUL, no warnings.Host-side command/template test suite (
go test ./internal/commands/...) — passes.Windows
macOS
Linux
Linux: Ubuntu 24.04.4 LTS (build host). Target: Android.
Test Configuration
Checklist:
website/src/pages/changelog.mdxwith details of this PRNotes on unchecked boxes:
Summary by CodeRabbit