Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changes/permission-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"tauri": "minor:feat"
"tauri-runtime": "minor:feat"
"tauri-runtime-wry": "minor:feat"
---

Expose the `wry` permission handler API through Tauri.
This includes support for permission types such as `DisplayCapture`, `Midi`, `Sensors`, `MediaKeySystemAccess`, `LocalFonts`, `WindowManagement`, `PointerLock`, `AutomaticDownloads`, `FileSystemAccess`, and `Autoplay`.
Added `PermissionResponse::{Allow, Deny, Default}` for runtime permission decisions.
121 changes: 26 additions & 95 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ mod monitor;
mod undecorated_resizing;
mod util;
mod webview;
mod webview_permissions;
mod window;

pub use webview::Webview;
Expand Down Expand Up @@ -4880,6 +4881,14 @@ You may have it installed on another user account, but it is not available for t
webview_builder.with_document_title_changed_handler(document_title_changed_handler)
}

if let Some(permission_request_handler) = pending.permission_request_handler {
webview_builder = webview_builder.with_permission_handler(move |kind| {
let kind = webview_permissions::from_wry_permission_kind(kind);
let response = permission_request_handler(kind);
webview_permissions::to_wry_permission_response(response)
});
}

let webview_bounds = if let Some(bounds) = webview_attributes.bounds {
let bounds: RectWrapper = bounds.into();
let bounds = bounds.0;
Expand Down
35 changes: 35 additions & 0 deletions crates/tauri-runtime-wry/src/webview_permissions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use tauri_runtime::webview::{PermissionKind, PermissionResponse};

pub(super) fn from_wry_permission_kind(kind: wry::PermissionKind) -> PermissionKind {
match kind {
wry::PermissionKind::Microphone => PermissionKind::Microphone,
wry::PermissionKind::Camera => PermissionKind::Camera,
wry::PermissionKind::Geolocation => PermissionKind::Geolocation,
wry::PermissionKind::Notifications => PermissionKind::Notifications,
wry::PermissionKind::ClipboardRead => PermissionKind::ClipboardRead,
wry::PermissionKind::DisplayCapture => PermissionKind::DisplayCapture,
wry::PermissionKind::Midi => PermissionKind::Midi,
wry::PermissionKind::Sensors => PermissionKind::Sensors,
wry::PermissionKind::MediaKeySystemAccess => PermissionKind::MediaKeySystemAccess,
wry::PermissionKind::LocalFonts => PermissionKind::LocalFonts,
wry::PermissionKind::WindowManagement => PermissionKind::WindowManagement,
wry::PermissionKind::PointerLock => PermissionKind::PointerLock,
wry::PermissionKind::AutomaticDownloads => PermissionKind::AutomaticDownloads,
wry::PermissionKind::FileSystemAccess => PermissionKind::FileSystemAccess,
wry::PermissionKind::Autoplay => PermissionKind::Autoplay,
wry::PermissionKind::Other => PermissionKind::Other,
_ => PermissionKind::Other,
}
}

pub(super) fn to_wry_permission_response(response: PermissionResponse) -> wry::PermissionResponse {
match response {
PermissionResponse::Allow => wry::PermissionResponse::Allow,
PermissionResponse::Deny => wry::PermissionResponse::Deny,
PermissionResponse::Default => wry::PermissionResponse::Default,
}
}
1 change: 1 addition & 0 deletions crates/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod dpi;
/// Types useful for interacting with a user's monitors.
pub mod monitor;
pub mod webview;
mod webview_permissions;
pub mod window;

use dpi::{PhysicalPosition, PhysicalSize, Position, Rect, Size};
Expand Down
6 changes: 6 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! A layer between raw [`Runtime`] webviews and Tauri.
//!
pub use crate::webview_permissions::{PermissionKind, PermissionResponse};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::window::WindowId;
use crate::{window::is_label_valid, Rect, Runtime, UserEvent};
Expand Down Expand Up @@ -41,6 +42,8 @@ type DocumentTitleChangedHandler = dyn Fn(String) + Send + 'static;

type DownloadHandler = dyn Fn(DownloadEvent) -> bool + Send + Sync;

type PermissionRequestHandler = dyn Fn(PermissionKind) -> PermissionResponse + Send + Sync;

#[cfg(any(target_os = "macos", target_os = "ios"))]
type OnWebContentProcessTerminateHandler = dyn Fn() + Send;

Expand Down Expand Up @@ -229,6 +232,8 @@ pub struct PendingWebview<T: UserEvent, R: Runtime<T>> {

pub download_handler: Option<Arc<DownloadHandler>>,

pub permission_request_handler: Option<Box<PermissionRequestHandler>>,

#[cfg(any(target_os = "macos", target_os = "ios"))]
pub on_web_content_process_terminate_handler: Option<Box<OnWebContentProcessTerminateHandler>>,
}
Expand Down Expand Up @@ -257,6 +262,7 @@ impl<T: UserEvent, R: Runtime<T>> PendingWebview<T, R> {
web_resource_request_handler: None,
on_page_load_handler: None,
download_handler: None,
permission_request_handler: None,
#[cfg(any(target_os = "macos", target_os = "ios"))]
on_web_content_process_terminate_handler: None,
})
Expand Down
Loading
Loading