webkit6/auto/response_policy_decision.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from webkit-gir-files
4// DO NOT EDIT
5
6use crate::{PolicyDecision, URIRequest, URIResponse, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// A policy decision for resource responses.
16 ///
17 /// WebKitResponsePolicyDecision represents a policy decision for a
18 /// resource response, whether from the network or the local system.
19 /// A very common use case for these types of decision is deciding
20 /// whether or not to download a particular resource or to load it
21 /// normally.
22 ///
23 /// ## Properties
24 ///
25 ///
26 /// #### `request`
27 /// This property contains the [`URIRequest`][crate::URIRequest] associated with this
28 /// policy decision.
29 ///
30 /// Readable
31 ///
32 ///
33 /// #### `response`
34 /// This property contains the [`URIResponse`][crate::URIResponse] associated with this
35 /// policy decision.
36 ///
37 /// Readable
38 ///
39 /// # Implements
40 ///
41 /// [`PolicyDecisionExt`][trait@crate::prelude::PolicyDecisionExt]
42 #[doc(alias = "WebKitResponsePolicyDecision")]
43 pub struct ResponsePolicyDecision(Object<ffi::WebKitResponsePolicyDecision, ffi::WebKitResponsePolicyDecisionClass>) @extends PolicyDecision;
44
45 match fn {
46 type_ => || ffi::webkit_response_policy_decision_get_type(),
47 }
48}
49
50impl ResponsePolicyDecision {
51 /// Return the [`URIRequest`][crate::URIRequest] associated with the response decision.
52 ///
53 /// Modifications to the returned object are `<emphasis>`not`</emphasis>` taken
54 /// into account when the request is sent over the network, and is intended
55 /// only to aid in evaluating whether a response decision should be taken or
56 /// not. To modify requests before they are sent over the network the
57 /// `WebKitPage::send-request` signal can be used instead.
58 ///
59 /// # Returns
60 ///
61 /// The URI request that is associated with this policy decision.
62 #[doc(alias = "webkit_response_policy_decision_get_request")]
63 #[doc(alias = "get_request")]
64 pub fn request(&self) -> Option<URIRequest> {
65 unsafe {
66 from_glib_none(ffi::webkit_response_policy_decision_get_request(
67 self.to_glib_none().0,
68 ))
69 }
70 }
71
72 /// Gets the value of the [`response`][struct@crate::ResponsePolicyDecision#response] property.
73 ///
74 /// # Returns
75 ///
76 /// The URI response that is associated with this policy decision.
77 #[doc(alias = "webkit_response_policy_decision_get_response")]
78 #[doc(alias = "get_response")]
79 pub fn response(&self) -> Option<URIResponse> {
80 unsafe {
81 from_glib_none(ffi::webkit_response_policy_decision_get_response(
82 self.to_glib_none().0,
83 ))
84 }
85 }
86
87 /// Gets whether the request is the main frame main resource
88 ///
89 /// # Returns
90 ///
91 /// [`true`] if the request is the main frame main resouce or [`false`] otherwise
92 #[doc(alias = "webkit_response_policy_decision_is_main_frame_main_resource")]
93 pub fn is_main_frame_main_resource(&self) -> bool {
94 unsafe {
95 from_glib(
96 ffi::webkit_response_policy_decision_is_main_frame_main_resource(
97 self.to_glib_none().0,
98 ),
99 )
100 }
101 }
102
103 /// Gets whether the MIME type of the response can be displayed in the [`WebView`][crate::WebView].
104 ///
105 /// Gets whether the MIME type of the response can be displayed in the [`WebView`][crate::WebView]
106 /// that triggered this policy decision request. See also [`WebViewExt::can_show_mime_type()`][crate::prelude::WebViewExt::can_show_mime_type()].
107 ///
108 /// # Returns
109 ///
110 /// [`true`] if the MIME type of the response is supported or [`false`] otherwise
111 #[doc(alias = "webkit_response_policy_decision_is_mime_type_supported")]
112 pub fn is_mime_type_supported(&self) -> bool {
113 unsafe {
114 from_glib(ffi::webkit_response_policy_decision_is_mime_type_supported(
115 self.to_glib_none().0,
116 ))
117 }
118 }
119
120 #[doc(alias = "request")]
121 pub fn connect_request_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
122 unsafe extern "C" fn notify_request_trampoline<F: Fn(&ResponsePolicyDecision) + 'static>(
123 this: *mut ffi::WebKitResponsePolicyDecision,
124 _param_spec: glib::ffi::gpointer,
125 f: glib::ffi::gpointer,
126 ) {
127 unsafe {
128 let f: &F = &*(f as *const F);
129 f(&from_glib_borrow(this))
130 }
131 }
132 unsafe {
133 let f: Box_<F> = Box_::new(f);
134 connect_raw(
135 self.as_ptr() as *mut _,
136 c"notify::request".as_ptr(),
137 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
138 notify_request_trampoline::<F> as *const (),
139 )),
140 Box_::into_raw(f),
141 )
142 }
143 }
144
145 #[doc(alias = "response")]
146 pub fn connect_response_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
147 unsafe extern "C" fn notify_response_trampoline<
148 F: Fn(&ResponsePolicyDecision) + 'static,
149 >(
150 this: *mut ffi::WebKitResponsePolicyDecision,
151 _param_spec: glib::ffi::gpointer,
152 f: glib::ffi::gpointer,
153 ) {
154 unsafe {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this))
157 }
158 }
159 unsafe {
160 let f: Box_<F> = Box_::new(f);
161 connect_raw(
162 self.as_ptr() as *mut _,
163 c"notify::response".as_ptr(),
164 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165 notify_response_trampoline::<F> as *const (),
166 )),
167 Box_::into_raw(f),
168 )
169 }
170 }
171}