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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{Cookie, CookieJarAcceptPolicy, SessionFeature};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// Automatic cookie handling for SoupSession.
///
/// A #SoupCookieJar stores [`Cookie`][crate::Cookie]s and arrange for them to be sent with
/// the appropriate [`Message`][crate::Message]s. #SoupCookieJar implements
/// [`SessionFeature`][crate::SessionFeature], so you can add a cookie jar to a session with
/// [`SessionExt::add_feature()`][crate::prelude::SessionExt::add_feature()] or [`SessionExt::add_feature_by_type()`][crate::prelude::SessionExt::add_feature_by_type()].
///
/// Note that the base #SoupCookieJar class does not support any form
/// of long-term cookie persistence.
///
/// ## Properties
///
///
/// #### `accept-policy`
/// The policy the jar should follow to accept or reject cookies.
///
/// Readable | Writeable
///
///
/// #### `read-only`
/// Whether or not the cookie jar is read-only.
///
/// Readable | Writeable | Construct Only
///
/// ## Signals
///
///
/// #### `changed`
/// Emitted when @jar changes.
///
/// If a cookie has been added,
/// @new_cookie will contain the newly-added cookie and
/// @old_cookie will be [`None`]. If a cookie has been deleted,
/// @old_cookie will contain the to-be-deleted cookie and
/// @new_cookie will be [`None`]. If a cookie has been changed,
/// @old_cookie will contain its old value, and @new_cookie its
/// new value.
///
///
///
/// # Implements
///
/// [`CookieJarExt`][trait@crate::prelude::CookieJarExt], [`trait@glib::ObjectExt`], [`SessionFeatureExt`][trait@crate::prelude::SessionFeatureExt], [`CookieJarExtManual`][trait@crate::prelude::CookieJarExtManual]
#[doc(alias = "SoupCookieJar")]
pub struct CookieJar(Object<ffi::SoupCookieJar, ffi::SoupCookieJarClass>) @implements SessionFeature;
match fn {
type_ => || ffi::soup_cookie_jar_get_type(),
}
}
impl CookieJar {
pub const NONE: Option<&'static CookieJar> = None;
/// Creates a new #SoupCookieJar.
///
/// The base #SoupCookieJar class does not support persistent storage of cookies;
/// use a subclass for that.
///
/// # Returns
///
/// a new #SoupCookieJar
#[doc(alias = "soup_cookie_jar_new")]
pub fn new() -> CookieJar {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::soup_cookie_jar_new()) }
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`CookieJar`] objects.
///
/// This method returns an instance of [`CookieJarBuilder`](crate::builders::CookieJarBuilder) which can be used to create [`CookieJar`] objects.
pub fn builder() -> CookieJarBuilder {
CookieJarBuilder::new()
}
}
impl Default for CookieJar {
fn default() -> Self {
Self::new()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`CookieJar`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct CookieJarBuilder {
builder: glib::object::ObjectBuilder<'static, CookieJar>,
}
impl CookieJarBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// The policy the jar should follow to accept or reject cookies.
pub fn accept_policy(self, accept_policy: CookieJarAcceptPolicy) -> Self {
Self {
builder: self.builder.property("accept-policy", accept_policy),
}
}
/// Whether or not the cookie jar is read-only.
pub fn read_only(self, read_only: bool) -> Self {
Self {
builder: self.builder.property("read-only", read_only),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`CookieJar`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> CookieJar {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::CookieJar>> Sealed for T {}
}
/// Trait containing all [`struct@CookieJar`] methods.
///
/// # Implementors
///
/// [`CookieJarDB`][struct@crate::CookieJarDB], [`CookieJarText`][struct@crate::CookieJarText], [`CookieJar`][struct@crate::CookieJar]
pub trait CookieJarExt: IsA<CookieJar> + sealed::Sealed + 'static {
/// Constructs a [`glib::List`][crate::glib::List] with every cookie inside the @self.
///
/// The cookies in the list are a copy of the original, so
/// you have to free them when you are done with them.
///
/// # Returns
///
/// a #GSList
/// with all the cookies in the @self.
#[doc(alias = "soup_cookie_jar_all_cookies")]
fn all_cookies(&self) -> Vec<Cookie> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::soup_cookie_jar_all_cookies(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets @self's [`CookieJarAcceptPolicy`][crate::CookieJarAcceptPolicy].
///
/// # Returns
///
/// the #SoupCookieJarAcceptPolicy set in the @self
#[doc(alias = "soup_cookie_jar_get_accept_policy")]
#[doc(alias = "get_accept_policy")]
fn accept_policy(&self) -> CookieJarAcceptPolicy {
unsafe {
from_glib(ffi::soup_cookie_jar_get_accept_policy(
self.as_ref().to_glib_none().0,
))
}
}
/// Retrieves the list of cookies that would be sent with a request to @uri
/// as a [`glib::List`][crate::glib::List] of #SoupCookie objects.
///
/// If @for_http is [`true`], the return value will include cookies marked
/// "HttpOnly" (that is, cookies that the server wishes to keep hidden
/// from client-side scripting operations such as the JavaScript
/// document.cookies property). Since #SoupCookieJar sets the Cookie
/// header itself when making the actual HTTP request, you should
/// almost certainly be setting @for_http to [`false`] if you are calling
/// this.
/// ## `uri`
/// a #GUri
/// ## `for_http`
/// whether or not the return value is being passed directly
/// to an HTTP operation
///
/// # Returns
///
/// a #GSList
/// with the cookies in the @self that would be sent with a request to @uri.
#[doc(alias = "soup_cookie_jar_get_cookie_list")]
#[doc(alias = "get_cookie_list")]
fn cookie_list(&self, uri: &glib::Uri, for_http: bool) -> Vec<Cookie> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::soup_cookie_jar_get_cookie_list(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
for_http.into_glib(),
))
}
}
/// This is an extended version of [`cookie_list()`][Self::cookie_list()] that
/// provides more information required to use SameSite cookies.
///
/// See the [SameSite cookies
/// spec](https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00) for
/// more detailed information.
/// ## `uri`
/// a #GUri
/// ## `top_level`
/// a #GUri for the top level document
/// ## `site_for_cookies`
/// a #GUri indicating the origin to get cookies for
/// ## `for_http`
/// whether or not the return value is being passed directly
/// to an HTTP operation
/// ## `is_safe_method`
/// if the HTTP method is safe, as defined by RFC 7231, ignored when @for_http is [`false`]
/// ## `is_top_level_navigation`
/// whether or not the HTTP request is part of
/// top level navigation
///
/// # Returns
///
/// a #GSList
/// with the cookies in the @self that would be sent with a request to @uri.
#[doc(alias = "soup_cookie_jar_get_cookie_list_with_same_site_info")]
#[doc(alias = "get_cookie_list_with_same_site_info")]
fn cookie_list_with_same_site_info(
&self,
uri: &glib::Uri,
top_level: Option<&glib::Uri>,
site_for_cookies: Option<&glib::Uri>,
for_http: bool,
is_safe_method: bool,
is_top_level_navigation: bool,
) -> Vec<Cookie> {
unsafe {
FromGlibPtrContainer::from_glib_full(
ffi::soup_cookie_jar_get_cookie_list_with_same_site_info(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
top_level.to_glib_none().0,
site_for_cookies.to_glib_none().0,
for_http.into_glib(),
is_safe_method.into_glib(),
is_top_level_navigation.into_glib(),
),
)
}
}
/// Retrieves (in Cookie-header form) the list of cookies that would
/// be sent with a request to @uri.
///
/// If @for_http is [`true`], the return value will include cookies marked
/// "HttpOnly" (that is, cookies that the server wishes to keep hidden
/// from client-side scripting operations such as the JavaScript
/// document.cookies property). Since #SoupCookieJar sets the Cookie
/// header itself when making the actual HTTP request, you should
/// almost certainly be setting @for_http to [`false`] if you are calling
/// this.
/// ## `uri`
/// a #GUri
/// ## `for_http`
/// whether or not the return value is being passed directly
/// to an HTTP operation
///
/// # Returns
///
/// the cookies, in string form, or [`None`] if
/// there are no cookies for @uri.
#[doc(alias = "soup_cookie_jar_get_cookies")]
#[doc(alias = "get_cookies")]
fn cookies(&self, uri: &glib::Uri, for_http: bool) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::soup_cookie_jar_get_cookies(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
for_http.into_glib(),
))
}
}
/// Gets whether @self stores cookies persistenly.
///
/// # Returns
///
/// [`true`] if @self storage is persistent or [`false`] otherwise.
#[doc(alias = "soup_cookie_jar_is_persistent")]
fn is_persistent(&self) -> bool {
unsafe {
from_glib(ffi::soup_cookie_jar_is_persistent(
self.as_ref().to_glib_none().0,
))
}
}
/// Sets @policy as the cookie acceptance policy for @self.
/// ## `policy`
/// a #SoupCookieJarAcceptPolicy
#[doc(alias = "soup_cookie_jar_set_accept_policy")]
fn set_accept_policy(&self, policy: CookieJarAcceptPolicy) {
unsafe {
ffi::soup_cookie_jar_set_accept_policy(
self.as_ref().to_glib_none().0,
policy.into_glib(),
);
}
}
/// Adds @cookie to @self, exactly as though it had appeared in a
/// Set-Cookie header returned from a request to @uri.
///
/// Keep in mind that if the [`CookieJarAcceptPolicy`][crate::CookieJarAcceptPolicy] set is either
/// [`CookieJarAcceptPolicy::NoThirdParty`][crate::CookieJarAcceptPolicy::NoThirdParty] or
/// [`CookieJarAcceptPolicy::GrandfatheredThirdParty`][crate::CookieJarAcceptPolicy::GrandfatheredThirdParty] you'll need to use
/// [`set_cookie_with_first_party()`][Self::set_cookie_with_first_party()], otherwise the jar
/// will have no way of knowing if the cookie is being set by a third
/// party or not.
/// ## `uri`
/// the URI setting the cookie
/// ## `cookie`
/// the stringified cookie to set
#[doc(alias = "soup_cookie_jar_set_cookie")]
fn set_cookie(&self, uri: &glib::Uri, cookie: &str) {
unsafe {
ffi::soup_cookie_jar_set_cookie(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
cookie.to_glib_none().0,
);
}
}
/// Adds @cookie to @self, exactly as though it had appeared in a
/// Set-Cookie header returned from a request to @uri.
///
/// @first_party will be used to reject cookies coming from third party resources
/// in case such a security policy is set in the @self.
/// ## `uri`
/// the URI setting the cookie
/// ## `first_party`
/// the URI for the main document
/// ## `cookie`
/// the stringified cookie to set
#[doc(alias = "soup_cookie_jar_set_cookie_with_first_party")]
fn set_cookie_with_first_party(&self, uri: &glib::Uri, first_party: &glib::Uri, cookie: &str) {
unsafe {
ffi::soup_cookie_jar_set_cookie_with_first_party(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
first_party.to_glib_none().0,
cookie.to_glib_none().0,
);
}
}
/// Whether or not the cookie jar is read-only.
#[doc(alias = "read-only")]
fn is_read_only(&self) -> bool {
ObjectExt::property(self.as_ref(), "read-only")
}
/// Emitted when @jar changes.
///
/// If a cookie has been added,
/// @new_cookie will contain the newly-added cookie and
/// @old_cookie will be [`None`]. If a cookie has been deleted,
/// @old_cookie will contain the to-be-deleted cookie and
/// @new_cookie will be [`None`]. If a cookie has been changed,
/// @old_cookie will contain its old value, and @new_cookie its
/// new value.
/// ## `old_cookie`
/// the old #SoupCookie value
/// ## `new_cookie`
/// the new #SoupCookie value
#[doc(alias = "changed")]
fn connect_changed<F: Fn(&Self, &Cookie, &Cookie) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn changed_trampoline<
P: IsA<CookieJar>,
F: Fn(&P, &Cookie, &Cookie) + 'static,
>(
this: *mut ffi::SoupCookieJar,
old_cookie: *mut ffi::SoupCookie,
new_cookie: *mut ffi::SoupCookie,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
CookieJar::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(old_cookie),
&from_glib_borrow(new_cookie),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"changed\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
changed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "accept-policy")]
fn connect_accept_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_accept_policy_trampoline<
P: IsA<CookieJar>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupCookieJar,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(CookieJar::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accept-policy\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_accept_policy_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<CookieJar>> CookieJarExt for O {}