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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// from webkit2gtk-gir-files
// DO NOT EDIT
use crate::ApplicationInfo;
use crate::WebView;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib::wrapper! {
/// Automation Session.
///
/// WebKitAutomationSession represents an automation session of a WebKitWebContext.
/// When a new session is requested, a WebKitAutomationSession is created and the signal
/// WebKitWebContext::automation-started is emitted with the WebKitAutomationSession as
/// argument. Then, the automation client can request the session to create a new
/// [`WebView`][crate::WebView] to interact with it. When this happens the signal `signal::AutomationSession::create-web-view`
/// is emitted.
///
/// # Implements
///
/// [`AutomationSessionExt`][trait@crate::prelude::AutomationSessionExt], [`trait@glib::ObjectExt`]
#[doc(alias = "WebKitAutomationSession")]
pub struct AutomationSession(Object<ffi::WebKitAutomationSession, ffi::WebKitAutomationSessionClass>);
match fn {
type_ => || ffi::webkit_automation_session_get_type(),
}
}
impl AutomationSession {
pub const NONE: Option<&'static AutomationSession> = None;
}
/// Trait containing all [`struct@AutomationSession`] methods.
///
/// # Implementors
///
/// [`AutomationSession`][struct@crate::AutomationSession]
pub trait AutomationSessionExt: 'static {
/// Get the the previously set [`AutomationSession`][crate::AutomationSession].
///
/// Get the [`AutomationSession`][crate::AutomationSession] previously set with [`set_application_info()`][Self::set_application_info()].
///
/// # Returns
///
/// the [`AutomationSession`][crate::AutomationSession] of `self`, or [`None`] if no one has been set.
#[doc(alias = "webkit_automation_session_get_application_info")]
#[doc(alias = "get_application_info")]
fn application_info(&self) -> Option<ApplicationInfo>;
/// Get the unique identifier of a [`AutomationSession`][crate::AutomationSession]
///
/// # Returns
///
/// the unique identifier of `self`
#[doc(alias = "webkit_automation_session_get_id")]
#[doc(alias = "get_id")]
fn id(&self) -> Option<glib::GString>;
/// Set the application information to `self`.
///
/// This information will be used by the driver service
/// to match the requested capabilities with the actual application information. If this information
/// is not provided to the session when a new automation session is requested, the creation might fail
/// if the client requested a specific browser name or version. This will not have any effect when called
/// after the automation session has been fully created, so this must be called in the callback of
/// `signal::WebContext::automation-started` signal.
/// ## `info`
/// a [`ApplicationInfo`][crate::ApplicationInfo]
#[doc(alias = "webkit_automation_session_set_application_info")]
fn set_application_info(&self, info: &ApplicationInfo);
/// This signal is emitted when the automation client requests a new
/// browsing context to interact with it. The callback handler should
/// return a [`WebView`][crate::WebView] created with `property::WebView::is-controlled-by-automation`
/// construct property enabled and `property::WebView::automation-presentation-type` construct
/// property set if needed.
///
/// If the signal is emitted with "tab" detail, the returned [`WebView`][crate::WebView] should be
/// a new web view added to a new tab of the current browsing context window.
/// If the signal is emitted with "window" detail, the returned [`WebView`][crate::WebView] should be
/// a new web view added to a new window.
/// When creating a new web view and there's an active browsing context, the new window
/// or tab shouldn't be focused.
///
/// # Returns
///
/// a [`WebView`][crate::WebView] widget.
#[cfg(any(feature = "v2_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_18")))]
#[doc(alias = "create-web-view")]
fn connect_create_web_view<F: Fn(&Self) -> WebView + 'static>(
&self,
detail: Option<&str>,
f: F,
) -> SignalHandlerId;
}
impl<O: IsA<AutomationSession>> AutomationSessionExt for O {
fn application_info(&self) -> Option<ApplicationInfo> {
unsafe {
from_glib_none(ffi::webkit_automation_session_get_application_info(
self.as_ref().to_glib_none().0,
))
}
}
fn id(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::webkit_automation_session_get_id(
self.as_ref().to_glib_none().0,
))
}
}
fn set_application_info(&self, info: &ApplicationInfo) {
unsafe {
ffi::webkit_automation_session_set_application_info(
self.as_ref().to_glib_none().0,
info.to_glib_none().0,
);
}
}
#[cfg(any(feature = "v2_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_18")))]
fn connect_create_web_view<F: Fn(&Self) -> WebView + 'static>(
&self,
detail: Option<&str>,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn create_web_view_trampoline<
P: IsA<AutomationSession>,
F: Fn(&P) -> WebView + 'static,
>(
this: *mut ffi::WebKitAutomationSession,
f: glib::ffi::gpointer,
) -> *mut ffi::WebKitWebView {
let f: &F = &*(f as *const F);
f(AutomationSession::from_glib_borrow(this).unsafe_cast_ref()) /*Not checked*/
.to_glib_none()
.0
}
unsafe {
let f: Box_<F> = Box_::new(f);
let detailed_signal_name = detail.map(|name| format!("create-web-view::{}\0", name));
let signal_name: &[u8] = detailed_signal_name
.as_ref()
.map_or(&b"create-web-view\0"[..], |n| n.as_bytes());
connect_raw(
self.as_ptr() as *mut _,
signal_name.as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
create_web_view_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for AutomationSession {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("AutomationSession")
}
}