pub struct UrlPolicy { /* private fields */ }Expand description
Decides which URLs a UrlOpener hands to the platform.
The default, UrlPolicy::allows_by_default, lets through only absolute
http, https, and mailto URLs without control characters, so links in
untrusted content, such as Markdown from the network or a model, cannot
launch local files, scripts, or arbitrary protocol handlers. An app that
needs more registers its own check with UrlPolicy::new, or turns the
check off with UrlPolicy::allow_all.
Implementations§
Source§impl UrlPolicy
impl UrlPolicy
Sourcepub fn new(allows: impl Fn(&str) -> bool + 'static) -> Self
pub fn new(allows: impl Fn(&str) -> bool + 'static) -> Self
A policy that lets through the URLs allows returns true for. Call
Self::allows_by_default from it to extend the default instead of
replacing it:
let policy = UrlPolicy::new(|url| {
url.starts_with("myapp:") || UrlPolicy::allows_by_default(url)
});Sourcepub fn allow_all() -> Self
pub fn allow_all() -> Self
A policy that lets every URL through. Use it only when the app trusts every URL it opens.
Sourcepub fn allows_by_default(url: &str) -> bool
pub fn allows_by_default(url: &str) -> bool
The default check: whether url is an absolute http, https, or
mailto URL without control characters. Relative URLs never pass.