feat: add permission handler API across webview backends#1654
Conversation
Package Changes Through 954e3e6There are 1 changes which include wry with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
56cc0d1 to
755877e
Compare
pewsheen
left a comment
There was a problem hiding this comment.
I currently only have a MacBook, so I'll share some thoughts about the macOS implementation here. For WebView2, maybe @Legend-Master can give some advice?
Personally, I tend not to loosen permission controls, to avoid them being used for malicious purposes.
Legend-Master
left a comment
There was a problem hiding this comment.
Looks good for the webview2 implementation at least at a glance, awesome work!
Could you also add a change file?
https://github.com/tauri-apps/wry/blob/dev/.changes/readme.md
Legend-Master
left a comment
There was a problem hiding this comment.
The webview2 code looks good to me and works well when tested on my computer, just a few small nitpicks, you might need to wait for other members to give some feedbacks on other platforms though
Also, you'll need to sign your commits before we can merge them
6a52c11 to
7aae5c4
Compare
pewsheen
left a comment
There was a problem hiding this comment.
macOS implementation looks good to me. Only a nit that I think we can improve.
Legend-Master
left a comment
There was a problem hiding this comment.
And you'll need to sign your commits
https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
28c368b to
bad81dd
Compare
Done. The commit is now digitally signed with an SSH key. |
bad81dd to
2f0df9e
Compare
fa4bba7 to
8ccc02e
Compare
pewsheen
left a comment
There was a problem hiding this comment.
wkwebview looks good to me 👍 . Let's see if there's something that needs to be discussed in other platform.
…n handler API, fix combined camera and microphone logic on macOS, update documentation to clarify NFC and Bluetooth support, and simplify permission_handler example using permission.site
8ccc02e to
f884930
Compare
Legend-Master
left a comment
There was a problem hiding this comment.
Looking good for the webview2 part and general APIs, I'll take a look at the webkitgtk implementation later when I got time. The Android implementation will need someone who's more familiar with the mobile part to review though
Thanks for the patience and awesome work!
Also please don't force push to a single commit on every change, it makes it hard to follow what's changed between each reviews, we will squash merge at the end
Legend-Master
left a comment
There was a problem hiding this comment.
I have gone ahead and did some adjustments, hope you don't mind
The Windows and Linux implementations are looking good to me, waiting for a reviewer who's more familiar with the mobile implementations to take a final look before merging
|
Thanks for the review and for the adjustments as well! They look good. Let me know if there's anything else for the Android or webkitgtk implementation. |
…r_display_device on v2_42
There was a problem hiding this comment.
Thanks for the review @FabianLars! Addressed your comments in the latest commit:
-
Combined audio+video on webkitgtk — fixed. Now each permission (mic/camera) is checked individually via
is_for_audio_device()/is_for_video_device(). If either is denied, the whole request is denied. -
WebKitGTK >2.42 —
is_for_display_device()is gated behind thev2_42feature flag. For older versions we fall back to!is_audio && !is_videoas a heuristic for display capture. -
CameraAndMicrophone — on both webkitgtk and macOS/iOS the combined request is now handled by checking
PermissionKind::MicrophoneandPermissionKind::Cameraseparately, so the handler can grant one and deny the other independently. I think keeping them separate is cleaner than adding a combined variant.
33d810e to
b9d86ef
Compare
Description
This PR adds a unified Permission Handler API for intercepting webview permission requests across WebView2, WKWebView, WebKitGTK, and Android.
The API lets applications decide how to handle permission requests at runtime by returning
Allow,Deny,Default, orPromptfrom a newWebViewBuilder::with_permission_handlercallback.Key Changes
WebViewBuilder::with_permission_handler.PermissionKindfor webview permission categories such as camera, microphone, geolocation, notifications, display capture, MIDI, local fonts, file system access, autoplay, and more.PermissionResponsewithAllow,Deny,Default, andPrompt.permission_handlerexample using permission.site.Platform Implementations
Windows (WebView2)
PermissionRequestedevents.PermissionKind.AllowandDeny;DefaultandPromptleave WebView2 default handling in place.macOS / iOS (WKWebView)
requestMediaCapturePermission.PermissionKind.CameraAndMicrophonerequests by checking camera and microphone separately, with deny taking precedence.Linux (WebKitGTK)
permission-requestsignal.is_for_display_device()with thev2_42feature and falls back to display-capture detection for older WebKitGTK versions.Android
WebChromeClient.onPermissionRequestand geolocation permission prompts through JNI.Example