use crate::{PolicyDecision, URIRequest, URIResponse};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "WebKitResponsePolicyDecision")]
pub struct ResponsePolicyDecision(Object<ffi::WebKitResponsePolicyDecision, ffi::WebKitResponsePolicyDecisionClass>) @extends PolicyDecision;
match fn {
type_ => || ffi::webkit_response_policy_decision_get_type(),
}
}
impl ResponsePolicyDecision {
pub const NONE: Option<&'static ResponsePolicyDecision> = None;
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::ResponsePolicyDecision>> Sealed for T {}
}
pub trait ResponsePolicyDecisionExt:
IsA<ResponsePolicyDecision> + sealed::Sealed + 'static
{
#[doc(alias = "webkit_response_policy_decision_get_request")]
#[doc(alias = "get_request")]
fn request(&self) -> Option<URIRequest> {
unsafe {
from_glib_none(ffi::webkit_response_policy_decision_get_request(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "webkit_response_policy_decision_get_response")]
#[doc(alias = "get_response")]
fn response(&self) -> Option<URIResponse> {
unsafe {
from_glib_none(ffi::webkit_response_policy_decision_get_response(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(feature = "v2_40")]
#[cfg_attr(docsrs, doc(cfg(feature = "v2_40")))]
#[doc(alias = "webkit_response_policy_decision_is_main_frame_main_resource")]
fn is_main_frame_main_resource(&self) -> bool {
unsafe {
from_glib(
ffi::webkit_response_policy_decision_is_main_frame_main_resource(
self.as_ref().to_glib_none().0,
),
)
}
}
#[cfg(feature = "v2_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v2_4")))]
#[doc(alias = "webkit_response_policy_decision_is_mime_type_supported")]
fn is_mime_type_supported(&self) -> bool {
unsafe {
from_glib(ffi::webkit_response_policy_decision_is_mime_type_supported(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "request")]
fn connect_request_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_request_trampoline<
P: IsA<ResponsePolicyDecision>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::WebKitResponsePolicyDecision,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ResponsePolicyDecision::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::request\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_request_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "response")]
fn connect_response_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_response_trampoline<
P: IsA<ResponsePolicyDecision>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::WebKitResponsePolicyDecision,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ResponsePolicyDecision::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::response\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_response_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<ResponsePolicyDecision>> ResponsePolicyDecisionExt for O {}