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
//! Rust-owned WebView2 events.
use std::fmt;
/// A WebView2 capability request observed by the host.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum WebViewPermission {
/// Microphone capture.
Microphone,
/// Camera capture.
Camera,
/// Geolocation.
Geolocation,
/// Browser notifications.
Notifications,
/// Ambient or other sensors.
OtherSensors,
/// Clipboard read access.
ClipboardRead,
/// Multiple automatic downloads.
MultipleAutomaticDownloads,
/// File read/write access.
FileReadWrite,
/// Media autoplay.
Autoplay,
/// Local font access.
LocalFonts,
/// MIDI system-exclusive messages.
MidiSystemExclusiveMessages,
/// Window-management access.
WindowManagement,
/// A permission kind introduced by a newer WebView2 runtime.
Unknown(i32),
}
impl WebViewPermission {
pub(super) const fn from_raw(kind: i32) -> Self {
match kind {
1 => Self::Microphone,
2 => Self::Camera,
3 => Self::Geolocation,
4 => Self::Notifications,
5 => Self::OtherSensors,
6 => Self::ClipboardRead,
7 => Self::MultipleAutomaticDownloads,
8 => Self::FileReadWrite,
9 => Self::Autoplay,
10 => Self::LocalFonts,
11 => Self::MidiSystemExclusiveMessages,
12 => Self::WindowManagement,
value => Self::Unknown(value),
}
}
}
impl fmt::Display for WebViewPermission {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let label = match self {
Self::Microphone => "microphone",
Self::Camera => "camera",
Self::Geolocation => "geolocation",
Self::Notifications => "notifications",
Self::OtherSensors => "other sensors",
Self::ClipboardRead => "clipboard read",
Self::MultipleAutomaticDownloads => "multiple automatic downloads",
Self::FileReadWrite => "file read/write",
Self::Autoplay => "autoplay",
Self::LocalFonts => "local fonts",
Self::MidiSystemExclusiveMessages => "MIDI system-exclusive messages",
Self::WindowManagement => "window management",
Self::Unknown(kind) => return write!(formatter, "unknown ({kind})"),
};
formatter.write_str(label)
}
}
/// Event delivered by one WebView2 host.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum WebViewEvent {
/// A capability request was synchronously denied by the host policy.
///
/// The runtime raises no request while the document is hidden: a page
/// in a hidden host keeps its request pending, with neither this event
/// nor the page's failure callback delivered.
PermissionDenied {
/// URI that requested the capability.
uri: String,
/// Requested WebView2 capability.
permission: WebViewPermission,
/// Whether WebView2 marked the request as user initiated.
user_initiated: bool,
},
/// A navigation was requested, with the resource policy result.
NavigationStarting {
/// Requested URI.
uri: String,
/// Whether the request was allowed to continue.
allowed: bool,
},
/// A navigation completed.
NavigationCompleted {
/// Completed URI.
uri: String,
/// Whether WebView2 reported success.
success: bool,
},
/// A new-window request was denied by policy.
NewWindowDenied {
/// Requested URI.
uri: String,
},
/// A bounded JSON message received from the page.
Message {
/// Source URI reported by WebView2.
source: String,
/// JSON payload.
json: String,
},
/// A message from a disallowed source was rejected.
MessageRejected {
/// Source URI reported by WebView2.
source: String,
},
}
/// Event returned by a WebView2 host's combined native pump.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WebViewHostEvent {
/// Event translated by the parent Win32 window.
Window(super::super::window::WindowEvent),
/// Event produced by the WebView2 controller.
WebView(WebViewEvent),
}