-
-
Notifications
You must be signed in to change notification settings - Fork 472
feat: add permission handler API across webview backends #1654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f884930
feat: add permission handler API - implement cross-platform permissio…
F0RLE 33e6332
fix(wkwebview): remove leftover PermissionObserver from UIDelegate si…
F0RLE 2013b25
Fix `permission_handler` example on linux
Legend-Master 2c44f16
Use type instead of string check
Legend-Master f213859
Add more platform specific notes
Legend-Master a0133a8
Move permissions to a file
Legend-Master 09814aa
Add notice about prompt not supported on linux
Legend-Master 84e01f4
fix(webkitgtk): handle combined audio+video permissions and use is_fo…
F0RLE 110a347
chore: merge upstream dev and resolve conflicts
F0RLE 911de41
fix: reorder module declarations for rustfmt
F0RLE 47afa95
fix(android): scope permission handler per webview
F0RLE b9d86ef
fix(android): honor permission handler for geolocation
F0RLE e25436d
fix(android): avoid overgranting mixed permission requests
F0RLE 954e3e6
fix(android): scope permission callbacks by webview
F0RLE 88472ae
fix(android): pass existing webview id string
F0RLE 26ca4b5
Merge branch 'dev' into feat/permission-handler
Legend-Master f00e365
Migrate `PACKAGE.get().unwrap()`
Legend-Master 059df14
Fix `web_chrome_client`
Legend-Master 1cadf91
small refactor on permissionLauncher
Legend-Master fe9806d
Add `PermissionResponse::Default` docs for all platforms
Legend-Master cced03c
fix(android): simplify permission JNI response
F0RLE 342d4f1
document allow is not supported on android
Legend-Master 30aa70f
refactor: simplify permission responses
F0RLE 7f8a188
fix: update permission handler example
F0RLE dc2766c
fix(android): pass unknown permissions to handler
F0RLE f91f672
fix(android): allow explicit unknown permissions
F0RLE 373ca8a
onPermissionRequestNative will not return other values
Legend-Master e7c84dc
Send individual permissions to rust side
Legend-Master File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "wry": minor | ||
| --- | ||
|
|
||
| Add an expanded permission handling API for WebView2, WKWebView, WebKitGTK, and Android. | ||
| This includes: | ||
| - `PermissionKind` expansion: `DisplayCapture`, `Midi`, `Sensors`, `MediaKeySystemAccess`, `LocalFonts`, `WindowManagement`, `PointerLock`, `AutomaticDownloads`, `FileSystemAccess`, `Autoplay`. | ||
| - Support for `PermissionResponse::Prompt` to trigger native system dialogs. | ||
| - Android support via JNI bridge (`onPermissionRequest` in `RustWebChromeClient`). | ||
| - macOS: Split camera/microphone requests; `CameraAndMicrophone` resolved from individual responses. | ||
| - Linux: `DisplayCapture` detection for WebKitGTK < 2.42 (getDisplayMedia fix). | ||
| - Windows: Full coverage of all 12 `COREWEBVIEW2_PERMISSION_KIND` values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2020-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| //! Example demonstrating the permission handler API. | ||
| //! | ||
| //! Run: cargo run --example permission_handler | ||
| //! Then click the buttons and watch the terminal output. | ||
|
|
||
| fn main() -> wry::Result<()> { | ||
| use tao::{ | ||
| event::{Event, WindowEvent}, | ||
| event_loop::{ControlFlow, EventLoop}, | ||
| window::WindowBuilder, | ||
| }; | ||
| use wry::{PermissionKind, PermissionResponse, WebViewBuilder}; | ||
|
|
||
| let event_loop = EventLoop::new(); | ||
| let window = WindowBuilder::new() | ||
| .with_title("Permission Handler Example") | ||
| .with_inner_size(tao::dpi::LogicalSize::new(800, 600)) | ||
| .build(&event_loop) | ||
| .unwrap(); | ||
|
|
||
| let builder = WebViewBuilder::new() | ||
| .with_url("https://permission.site/") | ||
| .with_permission_handler(|kind| { | ||
| let response = match kind { | ||
| PermissionKind::Geolocation => PermissionResponse::Default, | ||
| _ => PermissionResponse::Allow, | ||
| }; | ||
| println!("[permission] {kind} → {response}"); | ||
| response | ||
| }); | ||
|
|
||
| #[cfg(any( | ||
| target_os = "windows", | ||
| target_os = "macos", | ||
| target_os = "ios", | ||
| target_os = "android" | ||
| ))] | ||
| let _webview = builder.build(&window)?; | ||
| #[cfg(not(any( | ||
| target_os = "windows", | ||
| target_os = "macos", | ||
| target_os = "ios", | ||
| target_os = "android" | ||
| )))] | ||
| let _webview = { | ||
| use tao::platform::unix::WindowExtUnix; | ||
| use wry::WebViewBuilderExtUnix; | ||
| let vbox = window.default_vbox().unwrap(); | ||
| builder.build_gtk(vbox)? | ||
| }; | ||
|
|
||
| event_loop.run(move |event, _, control_flow| { | ||
| *control_flow = ControlFlow::Wait; | ||
| if let Event::WindowEvent { | ||
| event: WindowEvent::CloseRequested, | ||
| .. | ||
| } = event | ||
| { | ||
| *control_flow = ControlFlow::Exit; | ||
| } | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.