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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::{ffi, PermissionState, SecurityOrigin};
use glib::translate::*;

glib::wrapper! {
    /// This query represents a user's choice to allow or deny access to "powerful features" of the
    /// platform, as specified in the [Permissions W3C
    /// Specification](https://w3c.github.io/permissions/).
    ///
    /// When signalled by the #WebKitWebView through the `query-permission-state` signal, the application
    /// has to eventually respond, via `webkit_permission_state_query_finish()`, whether it grants,
    /// denies or requests a dedicated permission prompt for the given query.
    ///
    /// When a #WebKitPermissionStateQuery is not handled by the user, the user-agent is instructed to
    /// `prompt` the user for the given permission.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct PermissionStateQuery(Shared<ffi::WebKitPermissionStateQuery>);

    match fn {
        ref => |ptr| ffi::webkit_permission_state_query_ref(ptr),
        unref => |ptr| ffi::webkit_permission_state_query_unref(ptr),
        type_ => || ffi::webkit_permission_state_query_get_type(),
    }
}

impl PermissionStateQuery {
    /// Notify the web-engine of the selected permission state for the given query. This function should
    /// only be called as a response to the `WebKitWebView::query-permission-state` signal.
    /// ## `state`
    /// a #WebKitPermissionState
    #[doc(alias = "webkit_permission_state_query_finish")]
    pub fn finish(&self, state: PermissionState) {
        unsafe {
            ffi::webkit_permission_state_query_finish(self.to_glib_none().0, state.into_glib());
        }
    }

    /// Get the permission name for which access is being queried.
    ///
    /// # Returns
    ///
    /// the permission name for @self
    #[doc(alias = "webkit_permission_state_query_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_permission_state_query_get_name(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the permission origin for which access is being queried.
    ///
    /// # Returns
    ///
    /// A #WebKitSecurityOrigin representing the origin from which the
    /// @self was emitted.
    #[doc(alias = "webkit_permission_state_query_get_security_origin")]
    #[doc(alias = "get_security_origin")]
    pub fn security_origin(&self) -> Option<SecurityOrigin> {
        unsafe {
            from_glib_none(ffi::webkit_permission_state_query_get_security_origin(
                self.to_glib_none().0,
            ))
        }
    }
}