objc2-web-kit 0.3.1

Bindings to the WebKit framework
Documentation
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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;

use crate::*;

/// Constants used by ``WKWebExtensionController
/// @
/// /link and
///
/// ```text
///  WKWebExtensionContext`` to indicate tab changes.
///  @constant WKWebExtensionTabChangedPropertiesNone  Indicates nothing changed.
///  @constant WKWebExtensionTabChangedPropertiesLoading  Indicates the loading state changed.
///  @constant WKWebExtensionTabChangedPropertiesMuted  Indicates the muted state changed.
///  @constant WKWebExtensionTabChangedPropertiesPinned  Indicates the pinned state changed.
///  @constant WKWebExtensionTabChangedPropertiesPlayingAudio Indicates the audio playback state changed.
///  @constant WKWebExtensionTabChangedPropertiesReaderMode  Indicates the reader mode state changed.
///  @constant WKWebExtensionTabChangedPropertiesSize  Indicates the size changed.
///  @constant WKWebExtensionTabChangedPropertiesTitle  Indicates the title changed.
///  @constant WKWebExtensionTabChangedPropertiesURL  Indicates the URL changed.
///  @constant WKWebExtensionTabChangedPropertiesZoomFactor  Indicates the zoom factor changed.
///  
///
/// ```
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensiontabchangedproperties?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct WKWebExtensionTabChangedProperties(pub NSUInteger);
bitflags::bitflags! {
    impl WKWebExtensionTabChangedProperties: NSUInteger {
        #[doc(alias = "WKWebExtensionTabChangedPropertiesNone")]
        const None = 0;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesLoading")]
        const Loading = 1<<1;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesMuted")]
        const Muted = 1<<2;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesPinned")]
        const Pinned = 1<<3;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesPlayingAudio")]
        const PlayingAudio = 1<<4;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesReaderMode")]
        const ReaderMode = 1<<5;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesSize")]
        const Size = 1<<6;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesTitle")]
        const Title = 1<<7;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesURL")]
        const URL = 1<<8;
        #[doc(alias = "WKWebExtensionTabChangedPropertiesZoomFactor")]
        const ZoomFactor = 1<<9;
    }
}

unsafe impl Encode for WKWebExtensionTabChangedProperties {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for WKWebExtensionTabChangedProperties {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// A class conforming to the ``WKWebExtensionTab`` protocol represents a tab to web extensions.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensiontab?language=objc)
    pub unsafe trait WKWebExtensionTab: NSObjectProtocol + MainThreadOnly {
        #[cfg(all(feature = "WKWebExtensionContext", feature = "WKWebExtensionWindow"))]
        /// Called when the window containing the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The window containing the tab.
        ///
        /// Defaults to `nil` if not implemented.
        #[optional]
        #[unsafe(method(windowForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn windowForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> Option<Retained<ProtocolObject<dyn WKWebExtensionWindow>>>;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the index of the tab in the window is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The index of the tab in the window, or ``NSNotFound`` if the tab is not currently in a window.
        ///
        /// This method should be implemented for better performance. Defaults to the window's
        /// ``tabsForWebExtensionContext:`` method to find the index if not implemented.
        #[optional]
        #[unsafe(method(indexInWindowForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn indexInWindowForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> NSUInteger;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the parent tab for the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The parent tab of the tab, if the tab was opened from another tab.
        ///
        /// Defaults to `nil` if not implemented.
        ///
        /// See also: setParentTab:forWebExtensionContext:completionHandler:
        #[optional]
        #[unsafe(method(parentTabForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn parentTabForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> Option<Retained<ProtocolObject<dyn WKWebExtensionTab>>>;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to set or clear the parent tab for the tab.
        ///
        /// Parameter `parentTab`: The tab that should be set as the parent of the tab. If
        /// `nil`is provided, the current
        /// parent tab should be cleared.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// No action is performed if not implemented.
        ///
        /// See also: parentTabForWebExtensionContext:
        #[optional]
        #[unsafe(method(setParentTab:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setParentTab_forWebExtensionContext_completionHandler(
            &self,
            parent_tab: Option<&ProtocolObject<dyn WKWebExtensionTab>>,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(
            feature = "WKWebExtensionContext",
            feature = "WKWebView",
            feature = "objc2-app-kit"
        ))]
        #[cfg(target_os = "macos")]
        /// Called when the web view for the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The web view for the tab.
        ///
        /// The web view's ``WKWebViewConfiguration`` must have its ``webExtensionController`` property set to match
        /// the controller of the given context; otherwise `nil` will be used. Defaults to `nil` if not implemented. If `nil`, some critical features
        /// will not be available for this tab, such as content injection or modification.
        #[optional]
        #[unsafe(method(webViewForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn webViewForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> Option<Retained<WKWebView>>;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the title of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The title of the tab.
        ///
        /// Defaults to ``title`` of the tab's web view if not implemented.
        #[optional]
        #[unsafe(method(titleForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn titleForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> Option<Retained<NSString>>;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the pinned state of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if the tab is pinned, `NO` otherwise.
        ///
        /// Defaults to `NO` if not implemented.
        ///
        /// See also: setPinned:forWebExtensionContext:completionHandler:
        #[optional]
        #[unsafe(method(isPinnedForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isPinnedForWebExtensionContext(&self, context: &WKWebExtensionContext) -> bool;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to set the pinned state of the tab.
        ///
        /// Parameter `pinned`: A boolean value indicating whether to pin the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// This is equivalent to the user selecting to pin or unpin the tab through a menu item. When a tab is pinned,
        /// it should be moved to the front of the tab bar and usually reduced in size. When a tab is unpinned, it should be restored
        /// to a normal size and position in the tab bar. No action is performed if not implemented.
        ///
        /// See also: isPinnedForWebExtensionContext:
        #[optional]
        #[unsafe(method(setPinned:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setPinned_forWebExtensionContext_completionHandler(
            &self,
            pinned: bool,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to check if reader mode is available for the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if reader mode is available for the tab, `NO` otherwise.
        ///
        /// Defaults to `NO` if not implemented.
        ///
        /// See also: isReaderModeActiveForWebExtensionContext:
        #[optional]
        #[unsafe(method(isReaderModeAvailableForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isReaderModeAvailableForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> bool;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to check if the tab is currently showing reader mode.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if the tab is showing reader mode, `NO` otherwise.
        ///
        /// Defaults to `NO` if not implemented.
        ///
        /// See also: isReaderModeAvailableForWebExtensionContext:
        #[optional]
        #[unsafe(method(isReaderModeActiveForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isReaderModeActiveForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> bool;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to set the reader mode for the tab.
        ///
        /// Parameter `active`: A boolean value indicating whether to activate reader mode.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// No action is performed if not implemented.
        ///
        /// See also: isReaderModeAvailableForWebExtensionContext:
        ///
        /// See also: isReaderModeActiveForWebExtensionContext:
        #[optional]
        #[unsafe(method(setReaderModeActive:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setReaderModeActive_forWebExtensionContext_completionHandler(
            &self,
            active: bool,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to check if the tab is currently playing audio.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if the tab is playing audio, `NO` otherwise.
        ///
        /// Defaults to `NO` if not implemented.
        #[optional]
        #[unsafe(method(isPlayingAudioForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isPlayingAudioForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> bool;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to check if the tab is currently muted.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if the tab is muted, `NO` otherwise.
        ///
        /// Defaults to `NO` if not implemented.
        ///
        /// See also: setMuted:forWebExtensionContext:completionHandler:
        #[optional]
        #[unsafe(method(isMutedForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isMutedForWebExtensionContext(&self, context: &WKWebExtensionContext) -> bool;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to set the mute state of the tab.
        ///
        /// Parameter `muted`: A boolean indicating whether the tab should be muted.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// No action is performed if not implemented.
        ///
        /// See also: isMutedForWebExtensionContext:
        #[optional]
        #[unsafe(method(setMuted:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setMuted_forWebExtensionContext_completionHandler(
            &self,
            muted: bool,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "objc2-core-foundation"))]
        /// Called when the size of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The size of the tab.
        ///
        /// Defaults to size of the tab's web view if not implemented.
        #[optional]
        #[unsafe(method(sizeForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn sizeForWebExtensionContext(&self, context: &WKWebExtensionContext) -> CGSize;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the zoom factor of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The zoom factor of the tab.
        ///
        /// Defaults to ``pageZoom`` of the tab's web view if not implemented.
        ///
        /// See also: setZoomFactor:forWebExtensionContext:completionHandler:
        #[optional]
        #[unsafe(method(zoomFactorForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn zoomFactorForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> c_double;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to set the zoom factor of the tab.
        ///
        /// Parameter `zoomFactor`: The desired zoom factor for the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// Sets ``pageZoom`` of the tab's web view if not implemented.
        ///
        /// See also: zoomFactorForWebExtensionContext:
        #[optional]
        #[unsafe(method(setZoomFactor:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setZoomFactor_forWebExtensionContext_completionHandler(
            &self,
            zoom_factor: c_double,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the URL of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The URL of the tab.
        ///
        /// Defaults to `URL` of the tab's web view if not implemented.
        #[optional]
        #[unsafe(method(urlForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn urlForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> Option<Retained<NSURL>>;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the pending URL of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: The pending URL of the tab.
        ///
        /// The pending URL is the URL of a page that is in the process of loading. If there is no pending URL, return `nil`.
        /// Defaults to `nil` if not implemented.
        #[optional]
        #[unsafe(method(pendingURLForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn pendingURLForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> Option<Retained<NSURL>>;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to check if the tab has finished loading.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if the tab has finished loading, `NO` otherwise.
        ///
        /// Defaults to ``isLoading`` of the tab's web view if not implemented.
        #[optional]
        #[unsafe(method(isLoadingCompleteForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isLoadingCompleteForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> bool;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to detect the locale of the webpage currently loaded in the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. The block takes two arguments:
        /// the detected locale (or
        /// `nil`if the locale is unknown) and an error, which should be provided if any errors occurred.
        ///
        /// No action is performed if not implemented.
        #[optional]
        #[unsafe(method(detectWebpageLocaleForWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn detectWebpageLocaleForWebExtensionContext_completionHandler(
            &self,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSLocale, *mut NSError)>,
        );

        #[cfg(all(
            feature = "WKSnapshotConfiguration",
            feature = "WKWebExtensionContext",
            feature = "block2",
            feature = "objc2-app-kit"
        ))]
        #[cfg(target_os = "macos")]
        #[optional]
        #[unsafe(method(takeSnapshotUsingConfiguration:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn takeSnapshotUsingConfiguration_forWebExtensionContext_completionHandler(
            &self,
            configuration: &WKSnapshotConfiguration,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSImage, *mut NSError)>,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to load a URL in the tab.
        ///
        /// Parameter `url`: The URL to be loaded in the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// If the tab is already loading a page, calling this method should stop the current page from loading and start
        /// loading the new URL. Loads the URL in the tab's web view via ``loadRequest:`` if not implemented.
        #[optional]
        #[unsafe(method(loadURL:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn loadURL_forWebExtensionContext_completionHandler(
            &self,
            url: &NSURL,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to reload the current page in the tab.
        ///
        /// Parameter `fromOrigin`: A boolean value indicating whether to reload the tab from the origin, bypassing the cache.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// Reloads the tab's web view via ``reload`` or ``reloadFromOrigin`` if not implemented.
        #[optional]
        #[unsafe(method(reloadFromOrigin:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn reloadFromOrigin_forWebExtensionContext_completionHandler(
            &self,
            from_origin: bool,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to navigate the tab to the previous page in its history.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// Navigates to the previous page in the tab's web view via ``goBack`` if not implemented.
        #[optional]
        #[unsafe(method(goBackForWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn goBackForWebExtensionContext_completionHandler(
            &self,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to navigate the tab to the next page in its history.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// Navigates to the next page in the tab's web view via ``goForward`` if not implemented.
        #[optional]
        #[unsafe(method(goForwardForWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn goForwardForWebExtensionContext_completionHandler(
            &self,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to activate the tab, making it frontmost.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// Upon activation, the tab should become the frontmost and either be the sole selected tab or
        /// be included among the selected tabs. No action is performed if not implemented.
        ///
        /// See also: setSelected:forWebExtensionContext:completionHandler:
        #[optional]
        #[unsafe(method(activateForWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn activateForWebExtensionContext_completionHandler(
            &self,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called when the selected state of the tab is needed.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if the tab is selected, `NO` otherwise.
        ///
        /// Defaults to `YES` for the active tab and `NO` for other tabs if not implemented.
        #[optional]
        #[unsafe(method(isSelectedForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn isSelectedForWebExtensionContext(&self, context: &WKWebExtensionContext) -> bool;

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to set the selected state of the tab.
        ///
        /// Parameter `selected`: A boolean value indicating whether to select the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// This is equivalent to the user command-clicking on the tab to add it to or remove it from a selection.
        /// The method should update the tab's selection state without changing the active tab. No action is performed if not implemented.
        ///
        /// See also: isSelectedForWebExtensionContext:
        #[optional]
        #[unsafe(method(setSelected:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setSelected_forWebExtensionContext_completionHandler(
            &self,
            selected: bool,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(
            feature = "WKWebExtensionContext",
            feature = "WKWebExtensionTabConfiguration",
            feature = "block2"
        ))]
        /// Called to duplicate the tab.
        ///
        /// Parameter `configuration`: The tab configuration influencing the duplicated tab's properties.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes two arguments:
        /// the duplicated tab (or
        /// `nil`if no tab was created) and an error, which should be provided if any errors occurred.
        ///
        /// This is equivalent to the user selecting to duplicate the tab through a menu item, with the specified configuration.
        /// No action is performed if not implemented.
        #[optional]
        #[unsafe(method(duplicateUsingConfiguration:forWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn duplicateUsingConfiguration_forWebExtensionContext_completionHandler(
            &self,
            configuration: &WKWebExtensionTabConfiguration,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<
                dyn Fn(*mut ProtocolObject<dyn WKWebExtensionTab>, *mut NSError),
            >,
        );

        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
        /// Called to close the tab.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
        /// which should be provided if any errors occurred.
        ///
        /// No action is performed if not implemented.
        #[optional]
        #[unsafe(method(closeForWebExtensionContext:completionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn closeForWebExtensionContext_completionHandler(
            &self,
            context: &WKWebExtensionContext,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to determine if permissions should be granted for the tab on user gesture.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` if permissions should be granted to the tab, `NO` otherwise.
        ///
        /// This method allows the app to control granting of permissions on a per-tab basis when triggered by a user
        /// gesture. Implementing this method enables the app to dynamically manage `activeTab` permissions based on the tab's
        /// current state, the content being accessed, or other custom criteria.
        #[optional]
        #[unsafe(method(shouldGrantPermissionsOnUserGestureForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn shouldGrantPermissionsOnUserGestureForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> bool;

        #[cfg(feature = "WKWebExtensionContext")]
        /// Called to determine if the tab should bypass host permission checks.
        ///
        /// Parameter `context`: The context in which the web extension is running.
        ///
        /// Returns: `YES` to bypass host permission checks, `NO` to enforce them.
        ///
        /// This method allows the app to dynamically control whether a tab can bypass standard host permission checks.
        #[optional]
        #[unsafe(method(shouldBypassPermissionsForWebExtensionContext:))]
        #[unsafe(method_family = none)]
        unsafe fn shouldBypassPermissionsForWebExtensionContext(
            &self,
            context: &WKWebExtensionContext,
        ) -> bool;
    }
);