1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/// Permission types that can be requested by the webview.
///
/// See [`crate::WebViewBuilder::with_permission_handler`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PermissionKind {
/// Microphone access permission.
Microphone,
/// Camera access permission.
Camera,
/// Geolocation access permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_GEOLOCATION`.
/// - **Linux**: Supported via `GeolocationPermissionRequest`.
/// - **Android**: Supported via `WebChromeClient.onGeolocationPermissionsShowPrompt`.
/// - **macOS / iOS**: Not yet supported by platform backends.
Geolocation,
/// Notifications permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_NOTIFICATIONS`.
/// - **Linux**: Supported via `NotificationPermissionRequest`.
/// - **macOS / Android / iOS**: Not yet supported by platform backends.
Notifications,
/// Clipboard read permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_CLIPBOARD_READ`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
ClipboardRead,
/// Display capture permission (for getDisplayMedia).
DisplayCapture,
/// Midi access permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_MIDI_SYSTEM_EXCLUSIVE_MESSAGES`.
/// - **Android**: Supported via `android.webkit.resource.MIDI_SYSEX`.
/// - **macOS / Linux / iOS**: Not yet supported by platform backends.
Midi,
/// Sensors (accelerometer, gyroscope, etc.) access permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_OTHER_SENSORS`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
Sensors,
/// Media key system access permission.
///
/// ## Platform-specific
///
/// - **Android**: Supported via `android.webkit.resource.PROTECTED_MEDIA_ID`.
/// - **Windows / macOS / Linux / iOS**: Not yet supported by platform backends.
MediaKeySystemAccess,
/// Local fonts access permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_LOCAL_FONTS`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
LocalFonts,
/// Window management permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_WINDOW_MANAGEMENT`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
WindowManagement,
/// Pointer lock permission.
///
/// ## Platform-specific
///
/// - **Linux**: Supported via `PointerLockPermissionRequest`.
/// - **Windows / macOS / Android / iOS**: Not yet supported by platform backends.
PointerLock,
/// Automatic downloads permission (multiple downloads without user interaction).
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_MULTIPLE_AUTOMATIC_DOWNLOADS`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
AutomaticDownloads,
/// File system access permission (read/write via File System Access API).
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_FILE_READ_WRITE`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
FileSystemAccess,
/// Media autoplay permission.
///
/// ## Platform-specific
///
/// - **Windows**: Supported via `COREWEBVIEW2_PERMISSION_KIND_AUTOPLAY`.
/// - **macOS / Linux / Android / iOS**: Not yet supported by platform backends.
Autoplay,
/// Other unrecognized permission type.
Other,
}
impl std::fmt::Display for PermissionKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Microphone => write!(f, "microphone"),
Self::Camera => write!(f, "camera"),
Self::Geolocation => write!(f, "geolocation"),
Self::Notifications => write!(f, "notifications"),
Self::ClipboardRead => write!(f, "clipboard-read"),
Self::DisplayCapture => write!(f, "display-capture"),
Self::Midi => write!(f, "midi"),
Self::Sensors => write!(f, "sensors"),
Self::MediaKeySystemAccess => write!(f, "media-key-system-access"),
Self::LocalFonts => write!(f, "local-fonts"),
Self::WindowManagement => write!(f, "window-management"),
Self::PointerLock => write!(f, "pointer-lock"),
Self::AutomaticDownloads => write!(f, "automatic-downloads"),
Self::FileSystemAccess => write!(f, "file-system-access"),
Self::Autoplay => write!(f, "autoplay"),
Self::Other => write!(f, "other"),
}
}
}
/// Response for permission requests.
///
/// See [`crate::WebViewBuilder::with_permission_handler`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum PermissionResponse {
/// Grant the permission.
///
/// ## Platform-specific
///
/// - **Android**: Not supported for runtime permissions; the normal Android
/// permission flow is used instead.
Allow,
/// Deny the permission.
Deny,
/// Use the platform or browser default behavior.
///
/// ## Platform-specific
///
/// - **Windows / macOS / Android**: The default behavior is to continue the
/// platform or browser permission flow.
/// - **Linux**: The default behavior is [`Self::Deny`]
#[default]
Default,
}
impl std::fmt::Display for PermissionResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Allow => write!(f, "allow"),
Self::Deny => write!(f, "deny"),
Self::Default => write!(f, "default"),
}
}
}