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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::{
    ffi, AutomationSession, CacheModel, GeolocationManager, MemoryPressureSettings, NetworkSession,
    SecurityManager, SecurityOrigin, URISchemeRequest, UserMessage,
};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Manages aspects common to all #WebKitWebView<!-- -->s
    ///
    /// The #WebKitWebContext manages all aspects common to all
    /// #WebKitWebView<!-- -->s.
    ///
    /// You can define the #WebKitCacheModel with
    /// webkit_web_context_set_cache_model(), depending on the needs of
    /// your application. You can access the #WebKitSecurityManager to specify
    /// the behaviour of your application regarding security using
    /// webkit_web_context_get_security_manager().
    ///
    /// It is also possible to change your preferred language or enable
    /// spell checking, using webkit_web_context_set_preferred_languages(),
    /// webkit_web_context_set_spell_checking_languages() and
    /// webkit_web_context_set_spell_checking_enabled().
    ///
    /// You can use webkit_web_context_register_uri_scheme() to register
    /// custom URI schemes, and manage several other settings.
    ///
    /// TLS certificate validation failure is now treated as a transport
    /// error by default. To handle TLS failures differently, you can
    /// connect to #WebKitWebView::load-failed-with-tls-errors.
    /// Alternatively, you can use webkit_web_context_set_tls_errors_policy()
    /// to set the policy [`TLSErrorsPolicy::Ignore`][crate::TLSErrorsPolicy::Ignore]; however, this is
    /// not appropriate for Internet applications.
    ///
    /// ## Properties
    ///
    ///
    /// #### `memory-pressure-settings`
    ///  The #WebKitMemoryPressureSettings applied to the web processes created by this context.
    ///
    /// Writeable | Construct Only
    ///
    ///
    /// #### `time-zone-override`
    ///  The timezone override for this web context. Setting this property provides a better
    /// alternative to configure the timezone information for all webviews managed by the WebContext.
    /// The other, less optimal, approach is to globally set the TZ environment variable in the
    /// process before creating the context. However this approach might not be very convenient and
    /// can have side-effects in your application.
    ///
    /// The expected values for this property are defined in the IANA timezone database. See this
    /// wikipedia page for instance, https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// ## Signals
    ///
    ///
    /// #### `automation-started`
    ///  This signal is emitted when a new automation request is made.
    /// Note that it will never be emitted if automation is not enabled in @context,
    /// see webkit_web_context_set_automation_allowed() for more details.
    ///
    ///
    ///
    ///
    /// #### `initialize-notification-permissions`
    ///  This signal is emitted when a #WebKitWebContext needs to set
    /// initial notification permissions for a web process. It is emitted
    /// when a new web process is about to be launched, and signals the
    /// most appropriate moment to use
    /// webkit_web_context_initialize_notification_permissions(). If no
    /// notification permissions have changed since the last time this
    /// signal was emitted, then there is no need to call
    /// webkit_web_context_initialize_notification_permissions() again.
    ///
    ///
    ///
    ///
    /// #### `initialize-web-process-extensions`
    ///  This signal is emitted when a new web process is about to be
    /// launched. It signals the most appropriate moment to use
    /// webkit_web_context_set_web_process_extensions_initialization_user_data()
    /// and webkit_web_context_set_web_process_extensions_directory().
    ///
    ///
    ///
    ///
    /// #### `user-message-received`
    ///  This signal is emitted when a #WebKitUserMessage is received from a
    /// web process extension. You can reply to the message using
    /// webkit_user_message_send_reply().
    ///
    /// You can handle the user message asynchronously by calling g_object_ref() on
    /// @message and returning [`true`].
    ///
    ///
    #[doc(alias = "WebKitWebContext")]
    pub struct WebContext(Object<ffi::WebKitWebContext, ffi::WebKitWebContextClass>);

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

impl WebContext {
    /// Create a new #WebKitWebContext.
    ///
    /// # Returns
    ///
    /// a newly created #WebKitWebContext
    #[doc(alias = "webkit_web_context_new")]
    pub fn new() -> WebContext {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::webkit_web_context_new()) }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`WebContext`] objects.
    ///
    /// This method returns an instance of [`WebContextBuilder`](crate::builders::WebContextBuilder) which can be used to create [`WebContext`] objects.
    pub fn builder() -> WebContextBuilder {
        WebContextBuilder::new()
    }

    /// Adds a path to be mounted in the sandbox.
    ///
    /// @path must exist before any web process has been created; otherwise,
    /// it will be silently ignored. It is a fatal error to add paths after
    /// a web process has been spawned.
    ///
    /// Paths under `/sys`, `/proc`, and `/dev` are invalid. Attempting to
    /// add all of `/` is not valid. Since 2.40, adding the user's entire
    /// home directory or /home is also not valid.
    ///
    /// See also webkit_web_context_set_sandbox_enabled()
    /// ## `path`
    /// an absolute path to mount in the sandbox
    /// ## `read_only`
    /// if [`true`] the path will be read-only
    #[doc(alias = "webkit_web_context_add_path_to_sandbox")]
    pub fn add_path_to_sandbox(&self, path: impl AsRef<std::path::Path>, read_only: bool) {
        unsafe {
            ffi::webkit_web_context_add_path_to_sandbox(
                self.to_glib_none().0,
                path.as_ref().to_glib_none().0,
                read_only.into_glib(),
            );
        }
    }

    /// Returns the current cache model.
    ///
    /// For more information about this
    /// value check the documentation of the function
    /// webkit_web_context_set_cache_model().
    ///
    /// # Returns
    ///
    /// the current #WebKitCacheModel
    #[doc(alias = "webkit_web_context_get_cache_model")]
    #[doc(alias = "get_cache_model")]
    pub fn cache_model(&self) -> CacheModel {
        unsafe {
            from_glib(ffi::webkit_web_context_get_cache_model(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the #WebKitGeolocationManager of @self.
    ///
    /// # Returns
    ///
    /// the #WebKitGeolocationManager of @self.
    #[doc(alias = "webkit_web_context_get_geolocation_manager")]
    #[doc(alias = "get_geolocation_manager")]
    pub fn geolocation_manager(&self) -> Option<GeolocationManager> {
        unsafe {
            from_glib_none(ffi::webkit_web_context_get_geolocation_manager(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the #WebKitNetworkSession used for automation sessions started in @self.
    ///
    /// # Returns
    ///
    /// a #WebKitNetworkSession, or [`None`] if automation is not enabled
    #[doc(alias = "webkit_web_context_get_network_session_for_automation")]
    #[doc(alias = "get_network_session_for_automation")]
    pub fn network_session_for_automation(&self) -> Option<NetworkSession> {
        unsafe {
            from_glib_none(ffi::webkit_web_context_get_network_session_for_automation(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the #WebKitSecurityManager of @self.
    ///
    /// # Returns
    ///
    /// the #WebKitSecurityManager of @self.
    #[doc(alias = "webkit_web_context_get_security_manager")]
    #[doc(alias = "get_security_manager")]
    pub fn security_manager(&self) -> Option<SecurityManager> {
        unsafe {
            from_glib_none(ffi::webkit_web_context_get_security_manager(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get whether spell checking feature is currently enabled.
    ///
    /// # Returns
    ///
    /// [`true`] If spell checking is enabled, or [`false`] otherwise.
    #[doc(alias = "webkit_web_context_get_spell_checking_enabled")]
    #[doc(alias = "get_spell_checking_enabled")]
    pub fn is_spell_checking_enabled(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_web_context_get_spell_checking_enabled(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the the list of spell checking languages.
    ///
    /// Get the the list of spell checking languages associated with
    /// @self, or [`None`] if no languages have been previously set.
    ///
    /// See webkit_web_context_set_spell_checking_languages() for more
    /// details on the format of the languages in the list.
    ///
    /// # Returns
    ///
    /// A [`None`]-terminated
    ///    array of languages if available, or [`None`] otherwise.
    #[doc(alias = "webkit_web_context_get_spell_checking_languages")]
    #[doc(alias = "get_spell_checking_languages")]
    pub fn spell_checking_languages(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(
                ffi::webkit_web_context_get_spell_checking_languages(self.to_glib_none().0),
            )
        }
    }

    /// Get the #WebKitWebContext:time-zone-override property.
    #[doc(alias = "webkit_web_context_get_time_zone_override")]
    #[doc(alias = "get_time_zone_override")]
    #[doc(alias = "time-zone-override")]
    pub fn time_zone_override(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_web_context_get_time_zone_override(
                self.to_glib_none().0,
            ))
        }
    }

    /// Sets initial desktop notification permissions for the @self.
    ///
    /// @allowed_origins and @disallowed_origins must each be #GList of
    /// #WebKitSecurityOrigin objects representing origins that will,
    /// respectively, either always or never have permission to show desktop
    /// notifications. No #WebKitNotificationPermissionRequest will ever be
    /// generated for any of the security origins represented in
    /// @allowed_origins or @disallowed_origins. This function is necessary
    /// because some webpages proactively check whether they have permission
    /// to display notifications without ever creating a permission request.
    ///
    /// This function only affects web processes that have not already been
    /// created. The best time to call it is when handling
    /// #WebKitWebContext::initialize-notification-permissions so as to
    /// ensure that new web processes receive the most recent set of
    /// permissions.
    /// ## `allowed_origins`
    /// a #GList of security origins
    /// ## `disallowed_origins`
    /// a #GList of security origins
    #[doc(alias = "webkit_web_context_initialize_notification_permissions")]
    pub fn initialize_notification_permissions(
        &self,
        allowed_origins: &[&SecurityOrigin],
        disallowed_origins: &[&SecurityOrigin],
    ) {
        unsafe {
            ffi::webkit_web_context_initialize_notification_permissions(
                self.to_glib_none().0,
                allowed_origins.to_glib_none().0,
                disallowed_origins.to_glib_none().0,
            );
        }
    }

    /// Get whether automation is allowed in @self.
    ///
    /// See also webkit_web_context_set_automation_allowed().
    ///
    /// # Returns
    ///
    /// [`true`] if automation is allowed or [`false`] otherwise.
    #[doc(alias = "webkit_web_context_is_automation_allowed")]
    pub fn is_automation_allowed(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_web_context_is_automation_allowed(
                self.to_glib_none().0,
            ))
        }
    }

    /// Register @scheme in @self.
    ///
    /// Register @scheme in @self, so that when an URI request with @scheme is made in the
    /// #WebKitWebContext, the #WebKitURISchemeRequestCallback registered will be called with a
    /// #WebKitURISchemeRequest.
    /// It is possible to handle URI scheme requests asynchronously, by calling g_object_ref() on the
    /// #WebKitURISchemeRequest and calling webkit_uri_scheme_request_finish() later
    /// when the data of the request is available or
    /// webkit_uri_scheme_request_finish_error() in case of error.
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// about_uri_scheme_request_cb (WebKitURISchemeRequest *request,
    ///                              gpointer                user_data)
    /// {
    ///     GInputStream *stream;
    ///     gsize         stream_length;
    ///     const gchar  *path = webkit_uri_scheme_request_get_path (request);
    ///
    ///     if (!g_strcmp0 (path, "memory")) {
    ///         // Create a GInputStream with the contents of memory about page, and set its length to stream_length
    ///     } else if (!g_strcmp0 (path, "applications")) {
    ///         // Create a GInputStream with the contents of applications about page, and set its length to stream_length
    ///     } else if (!g_strcmp0 (path, "example")) {
    ///         gchar *contents = g_strdup_printf ("<html><body><p>Example about page</p></body></html>");
    ///         stream_length = strlen (contents);
    ///         stream = g_memory_input_stream_new_from_data (contents, stream_length, g_free);
    ///     } else {
    ///         GError *error = g_error_new (ABOUT_HANDLER_ERROR, ABOUT_HANDLER_ERROR_INVALID, "Invalid about:%s page.", path);
    ///         webkit_uri_scheme_request_finish_error (request, error);
    ///         g_error_free (error);
    ///         return;
    ///     }
    ///     webkit_uri_scheme_request_finish (request, stream, stream_length, "text/html");
    ///     g_object_unref (stream);
    /// }
    /// ```
    /// ## `scheme`
    /// the network scheme to register
    /// ## `callback`
    /// a #WebKitURISchemeRequestCallback
    /// ## `user_data_destroy_func`
    /// destroy notify for @user_data
    #[doc(alias = "webkit_web_context_register_uri_scheme")]
    pub 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 ffi::WebKitURISchemeRequest,
            user_data: glib::ffi::gpointer,
        ) {
            let request = from_glib_borrow(request);
            let callback = &*(user_data as *mut P);
            (*callback)(&request)
        }
        let callback = Some(callback_func::<P> as _);
        unsafe extern "C" fn user_data_destroy_func_func<P: Fn(&URISchemeRequest) + 'static>(
            data: glib::ffi::gpointer,
        ) {
            let _callback = Box_::from_raw(data as *mut P);
        }
        let destroy_call4 = Some(user_data_destroy_func_func::<P> as _);
        let super_callback0: Box_<P> = callback_data;
        unsafe {
            ffi::webkit_web_context_register_uri_scheme(
                self.to_glib_none().0,
                scheme.to_glib_none().0,
                callback,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call4,
            );
        }
    }

    /// Send @message to all web process extensions associated to @self.
    ///
    /// If @message is floating, it's consumed.
    /// ## `message`
    /// a #WebKitUserMessage
    #[doc(alias = "webkit_web_context_send_message_to_all_extensions")]
    pub fn send_message_to_all_extensions(&self, message: &UserMessage) {
        unsafe {
            ffi::webkit_web_context_send_message_to_all_extensions(
                self.to_glib_none().0,
                message.to_glib_none().0,
            );
        }
    }

    /// Set whether automation is allowed in @self.
    ///
    /// When automation is enabled the browser could
    /// be controlled by another process by requesting an automation session. When a new automation
    /// session is requested the signal #WebKitWebContext::automation-started is emitted.
    /// Automation is disabled by default, so you need to explicitly call this method passing [`true`]
    /// to enable it.
    ///
    /// Note that only one #WebKitWebContext can have automation enabled, so this will do nothing
    /// if there's another #WebKitWebContext with automation already enabled.
    /// ## `allowed`
    /// value to set
    #[doc(alias = "webkit_web_context_set_automation_allowed")]
    pub fn set_automation_allowed(&self, allowed: bool) {
        unsafe {
            ffi::webkit_web_context_set_automation_allowed(
                self.to_glib_none().0,
                allowed.into_glib(),
            );
        }
    }

    /// Specifies a usage model for WebViews.
    ///
    /// Specifies a usage model for WebViews, which WebKit will use to
    /// determine its caching behavior. All web views follow the cache
    /// model. This cache model determines the RAM and disk space to use
    /// for caching previously viewed content .
    ///
    /// Research indicates that users tend to browse within clusters of
    /// documents that hold resources in common, and to revisit previously
    /// visited documents. WebKit and the frameworks below it include
    /// built-in caches that take advantage of these patterns,
    /// substantially improving document load speed in browsing
    /// situations. The WebKit cache model controls the behaviors of all of
    /// these caches, including various WebCore caches.
    ///
    /// Browsers can improve document load speed substantially by
    /// specifying [`CacheModel::WebBrowser`][crate::CacheModel::WebBrowser]. Applications without a
    /// browsing interface can reduce memory usage substantially by
    /// specifying [`CacheModel::DocumentViewer`][crate::CacheModel::DocumentViewer]. The default value is
    /// [`CacheModel::WebBrowser`][crate::CacheModel::WebBrowser].
    /// ## `cache_model`
    /// a #WebKitCacheModel
    #[doc(alias = "webkit_web_context_set_cache_model")]
    pub fn set_cache_model(&self, cache_model: CacheModel) {
        unsafe {
            ffi::webkit_web_context_set_cache_model(self.to_glib_none().0, cache_model.into_glib());
        }
    }

    /// Set the list of preferred languages.
    ///
    /// Set the list of preferred languages, sorted from most desirable
    /// to least desirable. The list will be used in the following ways:
    ///
    /// - Determining how to build the `Accept-Language` HTTP header that will be
    ///   included in the network requests started by the #WebKitWebContext.
    /// - Setting the values of `navigator.language` and `navigator.languages`.
    /// - The first item in the list sets the default locale for JavaScript
    ///   `Intl` functions.
    /// ## `languages`
    /// a [`None`]-terminated list of language identifiers
    #[doc(alias = "webkit_web_context_set_preferred_languages")]
    pub fn set_preferred_languages(&self, languages: &[&str]) {
        unsafe {
            ffi::webkit_web_context_set_preferred_languages(
                self.to_glib_none().0,
                languages.to_glib_none().0,
            );
        }
    }

    /// Enable or disable the spell checking feature.
    /// ## `enabled`
    /// Value to be set
    #[doc(alias = "webkit_web_context_set_spell_checking_enabled")]
    pub fn set_spell_checking_enabled(&self, enabled: bool) {
        unsafe {
            ffi::webkit_web_context_set_spell_checking_enabled(
                self.to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    /// Set the list of spell checking languages to be used for spell
    /// checking.
    ///
    /// The locale string typically is in the form lang_COUNTRY, where lang
    /// is an ISO-639 language code, and COUNTRY is an ISO-3166 country code.
    /// For instance, sv_FI for Swedish as written in Finland or pt_BR
    /// for Portuguese as written in Brazil.
    ///
    /// You need to call this function with a valid list of languages at
    /// least once in order to properly enable the spell checking feature
    /// in WebKit.
    /// ## `languages`
    /// a [`None`]-terminated list of spell checking languages
    #[doc(alias = "webkit_web_context_set_spell_checking_languages")]
    pub fn set_spell_checking_languages(&self, languages: &[&str]) {
        unsafe {
            ffi::webkit_web_context_set_spell_checking_languages(
                self.to_glib_none().0,
                languages.to_glib_none().0,
            );
        }
    }

    /// Set the directory where WebKit will look for web process extensions.
    ///
    /// This method must be called before loading anything in this context,
    /// otherwise it will not have any effect. You can connect to
    /// #WebKitWebContext::initialize-web-process-extensions to call this method
    /// before anything is loaded.
    /// ## `directory`
    /// the directory to add
    #[doc(alias = "webkit_web_context_set_web_process_extensions_directory")]
    pub fn set_web_process_extensions_directory(&self, directory: &str) {
        unsafe {
            ffi::webkit_web_context_set_web_process_extensions_directory(
                self.to_glib_none().0,
                directory.to_glib_none().0,
            );
        }
    }

    /// Set user data to be passed to Web Extensions on initialization.
    ///
    /// The data will be passed to the
    /// #WebKitWebProcessExtensionInitializeWithUserDataFunction.
    /// This method must be called before loading anything in this context,
    /// otherwise it will not have any effect. You can connect to
    /// #WebKitWebContext::initialize-web-process-extensions to call this method
    /// before anything is loaded.
    #[doc(alias = "webkit_web_context_set_web_process_extensions_initialization_user_data")]
    pub fn set_web_process_extensions_initialization_user_data(&self, user_data: &glib::Variant) {
        unsafe {
            ffi::webkit_web_context_set_web_process_extensions_initialization_user_data(
                self.to_glib_none().0,
                user_data.to_glib_none().0,
            );
        }
    }

    /// Gets the default web context.
    ///
    /// # Returns
    ///
    /// a #WebKitWebContext
    #[doc(alias = "webkit_web_context_get_default")]
    #[doc(alias = "get_default")]
    #[allow(clippy::should_implement_trait)]
    pub fn default() -> Option<WebContext> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::webkit_web_context_get_default()) }
    }

    /// This signal is emitted when a new automation request is made.
    /// Note that it will never be emitted if automation is not enabled in @context,
    /// see webkit_web_context_set_automation_allowed() for more details.
    /// ## `session`
    /// the #WebKitAutomationSession associated with this event
    #[doc(alias = "automation-started")]
    pub fn connect_automation_started<F: Fn(&Self, &AutomationSession) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn automation_started_trampoline<
            F: Fn(&WebContext, &AutomationSession) + 'static,
        >(
            this: *mut ffi::WebKitWebContext,
            session: *mut ffi::WebKitAutomationSession,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &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(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    automation_started_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// This signal is emitted when a #WebKitWebContext needs to set
    /// initial notification permissions for a web process. It is emitted
    /// when a new web process is about to be launched, and signals the
    /// most appropriate moment to use
    /// webkit_web_context_initialize_notification_permissions(). If no
    /// notification permissions have changed since the last time this
    /// signal was emitted, then there is no need to call
    /// webkit_web_context_initialize_notification_permissions() again.
    #[doc(alias = "initialize-notification-permissions")]
    pub fn connect_initialize_notification_permissions<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn initialize_notification_permissions_trampoline<
            F: Fn(&WebContext) + 'static,
        >(
            this: *mut ffi::WebKitWebContext,
            f: glib::ffi::gpointer,
        ) {
            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 _,
                b"initialize-notification-permissions\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    initialize_notification_permissions_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// This signal is emitted when a new web process is about to be
    /// launched. It signals the most appropriate moment to use
    /// webkit_web_context_set_web_process_extensions_initialization_user_data()
    /// and webkit_web_context_set_web_process_extensions_directory().
    #[doc(alias = "initialize-web-process-extensions")]
    pub fn connect_initialize_web_process_extensions<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn initialize_web_process_extensions_trampoline<
            F: Fn(&WebContext) + 'static,
        >(
            this: *mut ffi::WebKitWebContext,
            f: glib::ffi::gpointer,
        ) {
            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 _,
                b"initialize-web-process-extensions\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    initialize_web_process_extensions_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// This signal is emitted when a #WebKitUserMessage is received from a
    /// web process extension. You can reply to the message using
    /// webkit_user_message_send_reply().
    ///
    /// You can handle the user message asynchronously by calling g_object_ref() on
    /// @message and returning [`true`].
    /// ## `message`
    /// the #WebKitUserMessage received
    ///
    /// # Returns
    ///
    /// [`true`] if the message was handled, or [`false`] otherwise.
    #[doc(alias = "user-message-received")]
    pub fn connect_user_message_received<F: Fn(&Self, &UserMessage) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn user_message_received_trampoline<
            F: Fn(&WebContext, &UserMessage) -> bool + 'static,
        >(
            this: *mut ffi::WebKitWebContext,
            message: *mut ffi::WebKitUserMessage,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(message)).into_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(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    user_message_received_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for WebContext {
    fn default() -> Self {
        Self::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`WebContext`] 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 WebContextBuilder {
    builder: glib::object::ObjectBuilder<'static, WebContext>,
}

impl WebContextBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// The #WebKitMemoryPressureSettings applied to the web processes created by this context.
    pub fn memory_pressure_settings(
        self,
        memory_pressure_settings: &MemoryPressureSettings,
    ) -> Self {
        Self {
            builder: self
                .builder
                .property("memory-pressure-settings", memory_pressure_settings),
        }
    }

    /// The timezone override for this web context. Setting this property provides a better
    /// alternative to configure the timezone information for all webviews managed by the WebContext.
    /// The other, less optimal, approach is to globally set the TZ environment variable in the
    /// process before creating the context. However this approach might not be very convenient and
    /// can have side-effects in your application.
    ///
    /// The expected values for this property are defined in the IANA timezone database. See this
    /// wikipedia page for instance, https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
    pub fn time_zone_override(self, time_zone_override: impl Into<glib::GString>) -> Self {
        Self {
            builder: self
                .builder
                .property("time-zone-override", time_zone_override.into()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`WebContext`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> WebContext {
        self.builder.build()
    }
}