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
// 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

#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use crate::AuthenticationScheme;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use crate::Credential;
#[cfg(any(feature = "v2_30", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
use crate::SecurityOrigin;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use glib::object::Cast;
use glib::object::IsA;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use glib::signal::connect_raw;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use glib::signal::SignalHandlerId;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use glib::translate::*;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use std::boxed::Box as Box_;
use std::fmt;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use std::mem::transmute;

glib::wrapper! {
    /// Represents an authentication request.
    ///
    /// Whenever a client attempts to load a page protected by HTTP
    /// authentication, credentials will need to be provided to authorize access.
    /// To allow the client to decide how it wishes to handle authentication,
    /// WebKit will fire a `signal::WebView::authenticate` signal with a
    /// WebKitAuthenticationRequest object to provide client side
    /// authentication support. Credentials are exposed through the
    /// [`Credential`][crate::Credential] object.
    ///
    /// In case the client application does not wish
    /// to handle this signal WebKit will provide a default handler. To handle
    /// authentication asynchronously, simply increase the reference count of the
    /// WebKitAuthenticationRequest object.
    ///
    /// # Implements
    ///
    /// [`AuthenticationRequestExt`][trait@crate::prelude::AuthenticationRequestExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "WebKitAuthenticationRequest")]
    pub struct AuthenticationRequest(Object<ffi::WebKitAuthenticationRequest, ffi::WebKitAuthenticationRequestClass>);

    match fn {
        type_ => || ffi::webkit_authentication_request_get_type(),
    }
}

impl AuthenticationRequest {
    pub const NONE: Option<&'static AuthenticationRequest> = None;
}

/// Trait containing all [`struct@AuthenticationRequest`] methods.
///
/// # Implementors
///
/// [`AuthenticationRequest`][struct@crate::AuthenticationRequest]
pub trait AuthenticationRequestExt: 'static {
    /// Determine whether this [`AuthenticationRequest`][crate::AuthenticationRequest] should allow the storage of credentials.
    ///
    /// Determine whether the authentication method associated with this
    /// [`AuthenticationRequest`][crate::AuthenticationRequest] should allow the storage of credentials.
    /// This will return [`false`] if WebKit doesn't support credential storing,
    /// if private browsing is enabled, or if persistent credential storage has been
    /// disabled in [`WebsiteDataManager`][crate::WebsiteDataManager], unless credentials saving has been
    /// explicitly enabled with [`set_can_save_credentials()`][Self::set_can_save_credentials()].
    ///
    /// # Returns
    ///
    /// [`true`] if WebKit can store credentials or [`false`] otherwise.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_can_save_credentials")]
    fn can_save_credentials(&self) -> bool;

    /// Cancel the authentication challenge.
    ///
    /// This will also cancel the page loading and result in a
    /// `signal::WebView::load-failed` signal with a [`NetworkError`][crate::NetworkError] of type [`NetworkError::Cancelled`][crate::NetworkError::Cancelled] being emitted.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_cancel")]
    fn cancel(&self);

    /// Get the [`gio::TlsPasswordFlags`][crate::gio::TlsPasswordFlags] of the [`AuthenticationScheme::ClientCertificatePinRequested`][crate::AuthenticationScheme::ClientCertificatePinRequested] authentication challenge.
    ///
    /// # Returns
    ///
    /// a [`gio::TlsPasswordFlags`][crate::gio::TlsPasswordFlags]
    #[cfg(any(feature = "v2_34", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
    #[doc(alias = "webkit_authentication_request_get_certificate_pin_flags")]
    #[doc(alias = "get_certificate_pin_flags")]
    fn certificate_pin_flags(&self) -> gio::TlsPasswordFlags;

    /// Get the host that this authentication challenge is applicable to.
    ///
    /// # Returns
    ///
    /// The host of `self`.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_get_host")]
    #[doc(alias = "get_host")]
    fn host(&self) -> Option<glib::GString>;

    /// Get the port that this authentication challenge is applicable to.
    ///
    /// # Returns
    ///
    /// The port of `self`.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_get_port")]
    #[doc(alias = "get_port")]
    fn port(&self) -> u32;

    /// Get the [`Credential`][crate::Credential] of the proposed authentication challenge.
    ///
    /// Get the [`Credential`][crate::Credential] of the proposed authentication challenge that was
    /// stored from a previous session. The client can use this directly for
    /// authentication or construct their own [`Credential`][crate::Credential].
    ///
    /// # Returns
    ///
    /// A [`Credential`][crate::Credential] encapsulating credential details
    /// or [`None`] if there is no stored credential.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_get_proposed_credential")]
    #[doc(alias = "get_proposed_credential")]
    fn proposed_credential(&self) -> Option<Credential>;

    /// Get the realm that this authentication challenge is applicable to.
    ///
    /// # Returns
    ///
    /// The realm of `self`.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_get_realm")]
    #[doc(alias = "get_realm")]
    fn realm(&self) -> Option<glib::GString>;

    /// Get the authentication scheme of the authentication challenge.
    ///
    /// # Returns
    ///
    /// The [`AuthenticationScheme`][crate::AuthenticationScheme] of `self`.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_get_scheme")]
    #[doc(alias = "get_scheme")]
    fn scheme(&self) -> AuthenticationScheme;

    /// Get the [`SecurityOrigin`][crate::SecurityOrigin] that this authentication challenge is applicable to.
    ///
    /// # Returns
    ///
    /// a newly created [`SecurityOrigin`][crate::SecurityOrigin].
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    #[doc(alias = "webkit_authentication_request_get_security_origin")]
    #[doc(alias = "get_security_origin")]
    fn security_origin(&self) -> Option<SecurityOrigin>;

    /// Determine whether the authentication challenge is associated with a proxy server.
    ///
    /// Determine whether the authentication challenge is associated with a proxy server rather than an "origin" server.
    ///
    /// # Returns
    ///
    /// [`true`] if authentication is for a proxy or [`false`] otherwise.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_is_for_proxy")]
    fn is_for_proxy(&self) -> bool;

    /// Determine whether this this is a first attempt or a retry for this authentication challenge.
    ///
    /// # Returns
    ///
    /// [`true`] if authentication attempt is a retry or [`false`] otherwise.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_authentication_request_is_retry")]
    fn is_retry(&self) -> bool;

    /// Set whether the authentication method associated with `self`
    /// should allow the storage of credentials.
    ///
    /// Set whether the authentication method associated with `self`
    /// should allow the storage of credentials.
    /// This should be used by applications handling their own credentials
    /// storage to indicate that it should be supported even when internal
    /// credential storage is disabled or unsupported.
    /// Note that storing of credentials will not be allowed on ephemeral
    /// sessions in any case.
    /// ## `enabled`
    /// value to set
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    #[doc(alias = "webkit_authentication_request_set_can_save_credentials")]
    fn set_can_save_credentials(&self, enabled: bool);

    /// Set the [`Credential`][crate::Credential] of the proposed authentication challenge.
    ///
    /// Set the [`Credential`][crate::Credential] of the proposed authentication challenge that was
    /// stored from a previous session. This should only be used by applications handling
    /// their own credential storage. (When using the default WebKit credential storage,
    /// [`proposed_credential()`][Self::proposed_credential()] already contains previously-stored
    /// credentials.)
    /// Passing a [`None`] `credential` will clear the proposed credential.
    /// ## `credential`
    /// a [`Credential`][crate::Credential], or [`None`]
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    #[doc(alias = "webkit_authentication_request_set_proposed_credential")]
    fn set_proposed_credential(&self, credential: &mut Credential);

    /// This signal is emitted when the user authentication request succeeded.
    /// Applications handling their own credential storage should connect to
    /// this signal to save the credentials.
    /// ## `credential`
    /// the [`Credential`][crate::Credential] accepted
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    #[doc(alias = "authenticated")]
    fn connect_authenticated<F: Fn(&Self, &Credential) + 'static>(&self, f: F) -> SignalHandlerId;

    /// This signal is emitted when the user authentication request is
    /// cancelled. It allows the application to dismiss its authentication
    /// dialog in case of page load failure for example.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "cancelled")]
    fn connect_cancelled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<AuthenticationRequest>> AuthenticationRequestExt for O {
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn can_save_credentials(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_authentication_request_can_save_credentials(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn cancel(&self) {
        unsafe {
            ffi::webkit_authentication_request_cancel(self.as_ref().to_glib_none().0);
        }
    }

    #[cfg(any(feature = "v2_34", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
    fn certificate_pin_flags(&self) -> gio::TlsPasswordFlags {
        unsafe {
            from_glib(
                ffi::webkit_authentication_request_get_certificate_pin_flags(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn host(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_authentication_request_get_host(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn port(&self) -> u32 {
        unsafe { ffi::webkit_authentication_request_get_port(self.as_ref().to_glib_none().0) }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn proposed_credential(&self) -> Option<Credential> {
        unsafe {
            from_glib_full(ffi::webkit_authentication_request_get_proposed_credential(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn realm(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_authentication_request_get_realm(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn scheme(&self) -> AuthenticationScheme {
        unsafe {
            from_glib(ffi::webkit_authentication_request_get_scheme(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    fn security_origin(&self) -> Option<SecurityOrigin> {
        unsafe {
            from_glib_full(ffi::webkit_authentication_request_get_security_origin(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn is_for_proxy(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_authentication_request_is_for_proxy(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn is_retry(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_authentication_request_is_retry(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    fn set_can_save_credentials(&self, enabled: bool) {
        unsafe {
            ffi::webkit_authentication_request_set_can_save_credentials(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    fn set_proposed_credential(&self, credential: &mut Credential) {
        unsafe {
            ffi::webkit_authentication_request_set_proposed_credential(
                self.as_ref().to_glib_none().0,
                credential.to_glib_none_mut().0,
            );
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_30")))]
    fn connect_authenticated<F: Fn(&Self, &Credential) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn authenticated_trampoline<
            P: IsA<AuthenticationRequest>,
            F: Fn(&P, &Credential) + 'static,
        >(
            this: *mut ffi::WebKitAuthenticationRequest,
            credential: *mut ffi::WebKitCredential,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                AuthenticationRequest::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(credential),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"authenticated\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    authenticated_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    fn connect_cancelled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn cancelled_trampoline<
            P: IsA<AuthenticationRequest>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::WebKitAuthenticationRequest,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(AuthenticationRequest::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"cancelled\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    cancelled_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for AuthenticationRequest {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("AuthenticationRequest")
    }
}