use crate::{PolicyDecision, URIRequest, URIResponse, ffi};
use glib::{
prelude::*,
signal::{SignalHandlerId, connect_raw},
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 {
#[doc(alias = "webkit_response_policy_decision_get_request")]
#[doc(alias = "get_request")]
pub fn request(&self) -> Option<URIRequest> {
unsafe {
from_glib_none(ffi::webkit_response_policy_decision_get_request(
self.to_glib_none().0,
))
}
}
#[doc(alias = "webkit_response_policy_decision_get_response")]
#[doc(alias = "get_response")]
pub fn response(&self) -> Option<URIResponse> {
unsafe {
from_glib_none(ffi::webkit_response_policy_decision_get_response(
self.to_glib_none().0,
))
}
}
#[doc(alias = "webkit_response_policy_decision_is_main_frame_main_resource")]
pub fn is_main_frame_main_resource(&self) -> bool {
unsafe {
from_glib(
ffi::webkit_response_policy_decision_is_main_frame_main_resource(
self.to_glib_none().0,
),
)
}
}
#[doc(alias = "webkit_response_policy_decision_is_mime_type_supported")]
pub fn is_mime_type_supported(&self) -> bool {
unsafe {
from_glib(ffi::webkit_response_policy_decision_is_mime_type_supported(
self.to_glib_none().0,
))
}
}
#[doc(alias = "request")]
pub fn connect_request_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_request_trampoline<F: Fn(&ResponsePolicyDecision) + 'static>(
this: *mut ffi::WebKitResponsePolicyDecision,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::request".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_request_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "response")]
pub fn connect_response_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_response_trampoline<
F: Fn(&ResponsePolicyDecision) + 'static,
>(
this: *mut ffi::WebKitResponsePolicyDecision,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::response".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_response_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}