// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use gio;
use gio_sys;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::StaticType;
use glib::ToValue;
#[cfg(any(feature = "v2_8", feature = "dox"))]
use glib::Value;
use glib_sys;
use gobject_sys;
#[cfg(any(feature = "v2_26", feature = "dox"))]
use std;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use std::pin::Pin;
use std::ptr;
use webkit2_sys;
#[cfg(any(feature = "v2_18", feature = "dox"))]
use AutomationSession;
use CacheModel;
use CookieManager;
use Download;
use FaviconDatabase;
#[cfg(any(feature = "v2_26", feature = "dox"))]
use GeolocationManager;
use Plugin;
#[cfg(any(feature = "v2_4", feature = "dox"))]
use ProcessModel;
use SecurityManager;
#[cfg(any(feature = "v2_16", feature = "dox"))]
use SecurityOrigin;
use TLSErrorsPolicy;
use URISchemeRequest;
#[cfg(any(feature = "v2_28", feature = "dox"))]
use UserMessage;
#[cfg(any(feature = "v2_10", feature = "dox"))]
use WebsiteDataManager;

glib_wrapper! {
    pub struct WebContext(Object<webkit2_sys::WebKitWebContext, webkit2_sys::WebKitWebContextClass, WebContextClass>);

    match fn {
        get_type => || webkit2_sys::webkit_web_context_get_type(),
    }
}

impl WebContext {
    #[cfg(any(feature = "v2_8", feature = "dox"))]
    pub fn new() -> WebContext {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(webkit2_sys::webkit_web_context_new()) }
    }

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    pub fn new_ephemeral() -> WebContext {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(webkit2_sys::webkit_web_context_new_ephemeral()) }
    }

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    pub fn with_website_data_manager<P: IsA<WebsiteDataManager>>(manager: &P) -> WebContext {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(
                webkit2_sys::webkit_web_context_new_with_website_data_manager(
                    manager.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    pub fn get_default() -> Option<WebContext> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(webkit2_sys::webkit_web_context_get_default()) }
    }
}

#[cfg(any(feature = "v2_8", feature = "dox"))]
impl Default for WebContext {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Clone, Default)]
pub struct WebContextBuilder {
    #[cfg(any(feature = "v2_8", feature = "dox"))]
    local_storage_directory: Option<String>,
    #[cfg(any(feature = "v2_28", feature = "dox"))]
    process_swap_on_cross_site_navigation_enabled: Option<bool>,
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    use_system_appearance_for_scrollbars: Option<bool>,
    #[cfg(any(feature = "v2_10", feature = "dox"))]
    website_data_manager: Option<WebsiteDataManager>,
}

impl WebContextBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn build(self) -> WebContext {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        #[cfg(any(feature = "v2_8", feature = "dox"))]
        {
            if let Some(ref local_storage_directory) = self.local_storage_directory {
                properties.push(("local-storage-directory", local_storage_directory));
            }
        }
        #[cfg(any(feature = "v2_28", feature = "dox"))]
        {
            if let Some(ref process_swap_on_cross_site_navigation_enabled) =
                self.process_swap_on_cross_site_navigation_enabled
            {
                properties.push((
                    "process-swap-on-cross-site-navigation-enabled",
                    process_swap_on_cross_site_navigation_enabled,
                ));
            }
        }
        #[cfg(any(feature = "v2_30", feature = "dox"))]
        {
            if let Some(ref use_system_appearance_for_scrollbars) =
                self.use_system_appearance_for_scrollbars
            {
                properties.push((
                    "use-system-appearance-for-scrollbars",
                    use_system_appearance_for_scrollbars,
                ));
            }
        }
        #[cfg(any(feature = "v2_10", feature = "dox"))]
        {
            if let Some(ref website_data_manager) = self.website_data_manager {
                properties.push(("website-data-manager", website_data_manager));
            }
        }
        let ret = glib::Object::new(WebContext::static_type(), &properties)
            .expect("object new")
            .downcast::<WebContext>()
            .expect("downcast");
        ret
    }

    #[cfg(any(feature = "v2_8", feature = "dox"))]
    pub fn local_storage_directory(mut self, local_storage_directory: &str) -> Self {
        self.local_storage_directory = Some(local_storage_directory.to_string());
        self
    }

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    pub fn process_swap_on_cross_site_navigation_enabled(
        mut self,
        process_swap_on_cross_site_navigation_enabled: bool,
    ) -> Self {
        self.process_swap_on_cross_site_navigation_enabled =
            Some(process_swap_on_cross_site_navigation_enabled);
        self
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    pub fn use_system_appearance_for_scrollbars(
        mut self,
        use_system_appearance_for_scrollbars: bool,
    ) -> Self {
        self.use_system_appearance_for_scrollbars = Some(use_system_appearance_for_scrollbars);
        self
    }

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    pub fn website_data_manager<P: IsA<WebsiteDataManager>>(
        mut self,
        website_data_manager: &P,
    ) -> Self {
        self.website_data_manager = Some(website_data_manager.clone().upcast());
        self
    }
}

pub const NONE_WEB_CONTEXT: Option<&WebContext> = None;

pub trait WebContextExt: 'static {
    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn add_path_to_sandbox<P: AsRef<std::path::Path>>(&self, path: P, read_only: bool);

    #[cfg(any(feature = "v2_6", feature = "dox"))]
    fn allow_tls_certificate_for_host<P: IsA<gio::TlsCertificate>>(
        &self,
        certificate: &P,
        host: &str,
    );

    fn clear_cache(&self);

    fn download_uri(&self, uri: &str) -> Option<Download>;

    fn get_cache_model(&self) -> CacheModel;

    fn get_cookie_manager(&self) -> Option<CookieManager>;

    fn get_favicon_database(&self) -> Option<FaviconDatabase>;

    fn get_favicon_database_directory(&self) -> Option<GString>;

    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn get_geolocation_manager(&self) -> Option<GeolocationManager>;

    fn get_plugins<
        P: IsA<gio::Cancellable>,
        Q: FnOnce(Result<Vec<Plugin>, glib::Error>) + Send + 'static,
    >(
        &self,
        cancellable: Option<&P>,
        callback: Q,
    );

    fn get_plugins_future(
        &self,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<Plugin>, glib::Error>> + 'static>>;

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn get_process_model(&self) -> ProcessModel;

    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn get_sandbox_enabled(&self) -> bool;

    fn get_security_manager(&self) -> Option<SecurityManager>;

    fn get_spell_checking_enabled(&self) -> bool;

    fn get_spell_checking_languages(&self) -> Vec<GString>;

    fn get_tls_errors_policy(&self) -> TLSErrorsPolicy;

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn get_use_system_appearance_for_scrollbars(&self) -> bool;

    #[cfg_attr(feature = "v2_26", deprecated)]
    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn get_web_process_count_limit(&self) -> u32;

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn get_website_data_manager(&self) -> Option<WebsiteDataManager>;

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    fn initialize_notification_permissions(
        &self,
        allowed_origins: &[&SecurityOrigin],
        disallowed_origins: &[&SecurityOrigin],
    );

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn is_automation_allowed(&self) -> bool;

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    fn is_ephemeral(&self) -> bool;

    fn prefetch_dns(&self, hostname: &str);

    fn register_uri_scheme<P: Fn(&URISchemeRequest) + 'static>(&self, scheme: &str, callback: P);

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    fn send_message_to_all_extensions<P: IsA<UserMessage>>(&self, message: &P);

    fn set_additional_plugins_directory(&self, directory: &str);

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn set_automation_allowed(&self, allowed: bool);

    fn set_cache_model(&self, cache_model: CacheModel);

    #[cfg_attr(feature = "v2_10", deprecated)]
    fn set_disk_cache_directory(&self, directory: &str);

    fn set_favicon_database_directory(&self, path: Option<&str>);

    fn set_preferred_languages(&self, languages: &[&str]);

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn set_process_model(&self, process_model: ProcessModel);

    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn set_sandbox_enabled(&self, enabled: bool);

    fn set_spell_checking_enabled(&self, enabled: bool);

    fn set_spell_checking_languages(&self, languages: &[&str]);

    fn set_tls_errors_policy(&self, policy: TLSErrorsPolicy);

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn set_use_system_appearance_for_scrollbars(&self, enabled: bool);

    fn set_web_extensions_directory(&self, directory: &str);

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn set_web_extensions_initialization_user_data(&self, user_data: &glib::Variant);

    #[cfg_attr(feature = "v2_26", deprecated)]
    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn set_web_process_count_limit(&self, limit: u32);

    #[cfg_attr(feature = "v2_10", deprecated)]
    #[cfg(any(feature = "v2_8", feature = "dox"))]
    fn get_property_local_storage_directory(&self) -> Option<GString>;

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    fn get_property_process_swap_on_cross_site_navigation_enabled(&self) -> bool;

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn connect_automation_started<F: Fn(&Self, &AutomationSession) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    fn connect_download_started<F: Fn(&Self, &Download) + 'static>(&self, f: F) -> SignalHandlerId;

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    fn connect_initialize_notification_permissions<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn connect_initialize_web_extensions<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    fn connect_user_message_received<F: Fn(&Self, &UserMessage) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn connect_property_use_system_appearance_for_scrollbars_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;
}

impl<O: IsA<WebContext>> WebContextExt for O {
    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn add_path_to_sandbox<P: AsRef<std::path::Path>>(&self, path: P, read_only: bool) {
        unsafe {
            webkit2_sys::webkit_web_context_add_path_to_sandbox(
                self.as_ref().to_glib_none().0,
                path.as_ref().to_glib_none().0,
                read_only.to_glib(),
            );
        }
    }

    #[cfg(any(feature = "v2_6", feature = "dox"))]
    fn allow_tls_certificate_for_host<P: IsA<gio::TlsCertificate>>(
        &self,
        certificate: &P,
        host: &str,
    ) {
        unsafe {
            webkit2_sys::webkit_web_context_allow_tls_certificate_for_host(
                self.as_ref().to_glib_none().0,
                certificate.as_ref().to_glib_none().0,
                host.to_glib_none().0,
            );
        }
    }

    fn clear_cache(&self) {
        unsafe {
            webkit2_sys::webkit_web_context_clear_cache(self.as_ref().to_glib_none().0);
        }
    }

    fn download_uri(&self, uri: &str) -> Option<Download> {
        unsafe {
            from_glib_full(webkit2_sys::webkit_web_context_download_uri(
                self.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
            ))
        }
    }

    fn get_cache_model(&self) -> CacheModel {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_get_cache_model(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_cookie_manager(&self) -> Option<CookieManager> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_web_context_get_cookie_manager(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_favicon_database(&self) -> Option<FaviconDatabase> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_web_context_get_favicon_database(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_favicon_database_directory(&self) -> Option<GString> {
        unsafe {
            from_glib_none(
                webkit2_sys::webkit_web_context_get_favicon_database_directory(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn get_geolocation_manager(&self) -> Option<GeolocationManager> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_web_context_get_geolocation_manager(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_plugins<
        P: IsA<gio::Cancellable>,
        Q: FnOnce(Result<Vec<Plugin>, glib::Error>) + Send + 'static,
    >(
        &self,
        cancellable: Option<&P>,
        callback: Q,
    ) {
        let user_data: Box_<Q> = Box_::new(callback);
        unsafe extern "C" fn get_plugins_trampoline<
            Q: FnOnce(Result<Vec<Plugin>, glib::Error>) + Send + 'static,
        >(
            _source_object: *mut gobject_sys::GObject,
            res: *mut gio_sys::GAsyncResult,
            user_data: glib_sys::gpointer,
        ) {
            let mut error = ptr::null_mut();
            let ret = webkit2_sys::webkit_web_context_get_plugins_finish(
                _source_object as *mut _,
                res,
                &mut error,
            );
            let result = if error.is_null() {
                Ok(FromGlibPtrContainer::from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
            callback(result);
        }
        let callback = get_plugins_trampoline::<Q>;
        unsafe {
            webkit2_sys::webkit_web_context_get_plugins(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn get_plugins_future(
        &self,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<Plugin>, glib::Error>> + 'static>>
    {
        Box_::pin(gio::GioFuture::new(self, move |obj, send| {
            let cancellable = gio::Cancellable::new();
            obj.get_plugins(Some(&cancellable), move |res| {
                send.resolve(res);
            });

            cancellable
        }))
    }

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn get_process_model(&self) -> ProcessModel {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_get_process_model(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn get_sandbox_enabled(&self) -> bool {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_get_sandbox_enabled(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_security_manager(&self) -> Option<SecurityManager> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_web_context_get_security_manager(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_spell_checking_enabled(&self) -> bool {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_get_spell_checking_enabled(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_spell_checking_languages(&self) -> Vec<GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(
                webkit2_sys::webkit_web_context_get_spell_checking_languages(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_tls_errors_policy(&self) -> TLSErrorsPolicy {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_get_tls_errors_policy(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn get_use_system_appearance_for_scrollbars(&self) -> bool {
        unsafe {
            from_glib(
                webkit2_sys::webkit_web_context_get_use_system_appearance_for_scrollbars(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn get_web_process_count_limit(&self) -> u32 {
        unsafe {
            webkit2_sys::webkit_web_context_get_web_process_count_limit(
                self.as_ref().to_glib_none().0,
            )
        }
    }

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn get_website_data_manager(&self) -> Option<WebsiteDataManager> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_web_context_get_website_data_manager(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    fn initialize_notification_permissions(
        &self,
        allowed_origins: &[&SecurityOrigin],
        disallowed_origins: &[&SecurityOrigin],
    ) {
        unsafe {
            webkit2_sys::webkit_web_context_initialize_notification_permissions(
                self.as_ref().to_glib_none().0,
                allowed_origins.to_glib_none().0,
                disallowed_origins.to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn is_automation_allowed(&self) -> bool {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_is_automation_allowed(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    fn is_ephemeral(&self) -> bool {
        unsafe {
            from_glib(webkit2_sys::webkit_web_context_is_ephemeral(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn prefetch_dns(&self, hostname: &str) {
        unsafe {
            webkit2_sys::webkit_web_context_prefetch_dns(
                self.as_ref().to_glib_none().0,
                hostname.to_glib_none().0,
            );
        }
    }

    fn register_uri_scheme<P: Fn(&URISchemeRequest) + 'static>(&self, scheme: &str, callback: P) {
        let callback_data: Box_<P> = Box_::new(callback);
        unsafe extern "C" fn callback_func<P: Fn(&URISchemeRequest) + 'static>(
            request: *mut webkit2_sys::WebKitURISchemeRequest,
            user_data: glib_sys::gpointer,
        ) {
            let request = from_glib_borrow(request);
            let callback: &P = &*(user_data as *mut _);
            (*callback)(&request);
        }
        let callback = Some(callback_func::<P> as _);
        unsafe extern "C" fn user_data_destroy_func_func<P: Fn(&URISchemeRequest) + 'static>(
            data: glib_sys::gpointer,
        ) {
            let _callback: Box_<P> = Box_::from_raw(data as *mut _);
        }
        let destroy_call4 = Some(user_data_destroy_func_func::<P> as _);
        let super_callback0: Box_<P> = callback_data;
        unsafe {
            webkit2_sys::webkit_web_context_register_uri_scheme(
                self.as_ref().to_glib_none().0,
                scheme.to_glib_none().0,
                callback,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call4,
            );
        }
    }

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    fn send_message_to_all_extensions<P: IsA<UserMessage>>(&self, message: &P) {
        unsafe {
            webkit2_sys::webkit_web_context_send_message_to_all_extensions(
                self.as_ref().to_glib_none().0,
                message.as_ref().to_glib_none().0,
            );
        }
    }

    fn set_additional_plugins_directory(&self, directory: &str) {
        unsafe {
            webkit2_sys::webkit_web_context_set_additional_plugins_directory(
                self.as_ref().to_glib_none().0,
                directory.to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn set_automation_allowed(&self, allowed: bool) {
        unsafe {
            webkit2_sys::webkit_web_context_set_automation_allowed(
                self.as_ref().to_glib_none().0,
                allowed.to_glib(),
            );
        }
    }

    fn set_cache_model(&self, cache_model: CacheModel) {
        unsafe {
            webkit2_sys::webkit_web_context_set_cache_model(
                self.as_ref().to_glib_none().0,
                cache_model.to_glib(),
            );
        }
    }

    fn set_disk_cache_directory(&self, directory: &str) {
        unsafe {
            webkit2_sys::webkit_web_context_set_disk_cache_directory(
                self.as_ref().to_glib_none().0,
                directory.to_glib_none().0,
            );
        }
    }

    fn set_favicon_database_directory(&self, path: Option<&str>) {
        unsafe {
            webkit2_sys::webkit_web_context_set_favicon_database_directory(
                self.as_ref().to_glib_none().0,
                path.to_glib_none().0,
            );
        }
    }

    fn set_preferred_languages(&self, languages: &[&str]) {
        unsafe {
            webkit2_sys::webkit_web_context_set_preferred_languages(
                self.as_ref().to_glib_none().0,
                languages.to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn set_process_model(&self, process_model: ProcessModel) {
        unsafe {
            webkit2_sys::webkit_web_context_set_process_model(
                self.as_ref().to_glib_none().0,
                process_model.to_glib(),
            );
        }
    }

    #[cfg(any(feature = "v2_26", feature = "dox"))]
    fn set_sandbox_enabled(&self, enabled: bool) {
        unsafe {
            webkit2_sys::webkit_web_context_set_sandbox_enabled(
                self.as_ref().to_glib_none().0,
                enabled.to_glib(),
            );
        }
    }

    fn set_spell_checking_enabled(&self, enabled: bool) {
        unsafe {
            webkit2_sys::webkit_web_context_set_spell_checking_enabled(
                self.as_ref().to_glib_none().0,
                enabled.to_glib(),
            );
        }
    }

    fn set_spell_checking_languages(&self, languages: &[&str]) {
        unsafe {
            webkit2_sys::webkit_web_context_set_spell_checking_languages(
                self.as_ref().to_glib_none().0,
                languages.to_glib_none().0,
            );
        }
    }

    fn set_tls_errors_policy(&self, policy: TLSErrorsPolicy) {
        unsafe {
            webkit2_sys::webkit_web_context_set_tls_errors_policy(
                self.as_ref().to_glib_none().0,
                policy.to_glib(),
            );
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn set_use_system_appearance_for_scrollbars(&self, enabled: bool) {
        unsafe {
            webkit2_sys::webkit_web_context_set_use_system_appearance_for_scrollbars(
                self.as_ref().to_glib_none().0,
                enabled.to_glib(),
            );
        }
    }

    fn set_web_extensions_directory(&self, directory: &str) {
        unsafe {
            webkit2_sys::webkit_web_context_set_web_extensions_directory(
                self.as_ref().to_glib_none().0,
                directory.to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn set_web_extensions_initialization_user_data(&self, user_data: &glib::Variant) {
        unsafe {
            webkit2_sys::webkit_web_context_set_web_extensions_initialization_user_data(
                self.as_ref().to_glib_none().0,
                user_data.to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn set_web_process_count_limit(&self, limit: u32) {
        unsafe {
            webkit2_sys::webkit_web_context_set_web_process_count_limit(
                self.as_ref().to_glib_none().0,
                limit,
            );
        }
    }

    #[cfg(any(feature = "v2_8", feature = "dox"))]
    fn get_property_local_storage_directory(&self) -> Option<GString> {
        unsafe {
            let mut value = Value::from_type(<GString as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"local-storage-directory\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `local-storage-directory` getter")
        }
    }

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    fn get_property_process_swap_on_cross_site_navigation_enabled(&self) -> bool {
        unsafe {
            let mut value = Value::from_type(<bool as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"process-swap-on-cross-site-navigation-enabled\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value.get().expect("Return Value for property `process-swap-on-cross-site-navigation-enabled` getter").unwrap()
        }
    }

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn connect_automation_started<F: Fn(&Self, &AutomationSession) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn automation_started_trampoline<
            P,
            F: Fn(&P, &AutomationSession) + 'static,
        >(
            this: *mut webkit2_sys::WebKitWebContext,
            session: *mut webkit2_sys::WebKitAutomationSession,
            f: glib_sys::gpointer,
        ) where
            P: IsA<WebContext>,
        {
            let f: &F = &*(f as *const F);
            f(
                &WebContext::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(session),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"automation-started\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    automation_started_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_download_started<F: Fn(&Self, &Download) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn download_started_trampoline<P, F: Fn(&P, &Download) + 'static>(
            this: *mut webkit2_sys::WebKitWebContext,
            download: *mut webkit2_sys::WebKitDownload,
            f: glib_sys::gpointer,
        ) where
            P: IsA<WebContext>,
        {
            let f: &F = &*(f as *const F);
            f(
                &WebContext::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(download),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"download-started\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    download_started_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v2_16", feature = "dox"))]
    fn connect_initialize_notification_permissions<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn initialize_notification_permissions_trampoline<
            P,
            F: Fn(&P) + 'static,
        >(
            this: *mut webkit2_sys::WebKitWebContext,
            f: glib_sys::gpointer,
        ) where
            P: IsA<WebContext>,
        {
            let f: &F = &*(f as *const F);
            f(&WebContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"initialize-notification-permissions\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    initialize_notification_permissions_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v2_4", feature = "dox"))]
    fn connect_initialize_web_extensions<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn initialize_web_extensions_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_sys::WebKitWebContext,
            f: glib_sys::gpointer,
        ) where
            P: IsA<WebContext>,
        {
            let f: &F = &*(f as *const F);
            f(&WebContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"initialize-web-extensions\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    initialize_web_extensions_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v2_28", feature = "dox"))]
    fn connect_user_message_received<F: Fn(&Self, &UserMessage) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn user_message_received_trampoline<
            P,
            F: Fn(&P, &UserMessage) -> bool + 'static,
        >(
            this: *mut webkit2_sys::WebKitWebContext,
            message: *mut webkit2_sys::WebKitUserMessage,
            f: glib_sys::gpointer,
        ) -> glib_sys::gboolean
        where
            P: IsA<WebContext>,
        {
            let f: &F = &*(f as *const F);
            f(
                &WebContext::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(message),
            )
            .to_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"user-message-received\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    user_message_received_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn connect_property_use_system_appearance_for_scrollbars_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_use_system_appearance_for_scrollbars_trampoline<
            P,
            F: Fn(&P) + 'static,
        >(
            this: *mut webkit2_sys::WebKitWebContext,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<WebContext>,
        {
            let f: &F = &*(f as *const F);
            f(&WebContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::use-system-appearance-for-scrollbars\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_use_system_appearance_for_scrollbars_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for WebContext {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "WebContext")
    }
}
