objc2_web_kit/generated/
WKWebExtensionWindow.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// Constants used by ``WKWebExtensionWindow`` to indicate the type of a window.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionwindowtype?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct WKWebExtensionWindowType(pub NSInteger);
19impl WKWebExtensionWindowType {
20    #[doc(alias = "WKWebExtensionWindowTypeNormal")]
21    pub const Normal: Self = Self(0);
22    #[doc(alias = "WKWebExtensionWindowTypePopup")]
23    pub const Popup: Self = Self(1);
24}
25
26unsafe impl Encode for WKWebExtensionWindowType {
27    const ENCODING: Encoding = NSInteger::ENCODING;
28}
29
30unsafe impl RefEncode for WKWebExtensionWindowType {
31    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34/// Constants used by ``WKWebExtensionWindow`` to indicate possible states of a window.
35///
36/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionwindowstate?language=objc)
37// NS_ENUM
38#[repr(transparent)]
39#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
40pub struct WKWebExtensionWindowState(pub NSInteger);
41impl WKWebExtensionWindowState {
42    #[doc(alias = "WKWebExtensionWindowStateNormal")]
43    pub const Normal: Self = Self(0);
44    #[doc(alias = "WKWebExtensionWindowStateMinimized")]
45    pub const Minimized: Self = Self(1);
46    #[doc(alias = "WKWebExtensionWindowStateMaximized")]
47    pub const Maximized: Self = Self(2);
48    #[doc(alias = "WKWebExtensionWindowStateFullscreen")]
49    pub const Fullscreen: Self = Self(3);
50}
51
52unsafe impl Encode for WKWebExtensionWindowState {
53    const ENCODING: Encoding = NSInteger::ENCODING;
54}
55
56unsafe impl RefEncode for WKWebExtensionWindowState {
57    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
58}
59
60extern_protocol!(
61    /// A class conforming to the ``WKWebExtensionWindow`` protocol represents a window to web extensions.
62    ///
63    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionwindow?language=objc)
64    pub unsafe trait WKWebExtensionWindow: NSObjectProtocol + MainThreadOnly {
65        #[cfg(all(feature = "WKWebExtensionContext", feature = "WKWebExtensionTab"))]
66        /// Called when the tabs are needed for the window.
67        ///
68        /// Parameter `context`: The context in which the web extension is running.
69        ///
70        /// Returns: An array of tabs in the window.
71        ///
72        /// Defaults to an empty array if not implemented.
73        #[optional]
74        #[unsafe(method(tabsForWebExtensionContext:))]
75        #[unsafe(method_family = none)]
76        unsafe fn tabsForWebExtensionContext(
77            &self,
78            context: &WKWebExtensionContext,
79        ) -> Retained<NSArray<ProtocolObject<dyn WKWebExtensionTab>>>;
80
81        #[cfg(all(feature = "WKWebExtensionContext", feature = "WKWebExtensionTab"))]
82        /// Called when the active tab is needed for the window.
83        ///
84        /// Parameter `context`: The context in which the web extension is running.
85        ///
86        /// Returns: The active tab in the window, which represents the frontmost tab currently in view.
87        ///
88        /// Defaults to `nil` if not implemented.
89        #[optional]
90        #[unsafe(method(activeTabForWebExtensionContext:))]
91        #[unsafe(method_family = none)]
92        unsafe fn activeTabForWebExtensionContext(
93            &self,
94            context: &WKWebExtensionContext,
95        ) -> Option<Retained<ProtocolObject<dyn WKWebExtensionTab>>>;
96
97        #[cfg(feature = "WKWebExtensionContext")]
98        /// Called when the type of the window is needed.
99        ///
100        /// Parameter `context`: The context in which the web extension is running.
101        ///
102        /// Returns: The type of the window.
103        ///
104        /// Defaults to``WKWebExtensionWindowTypeNormal`` if not implemented.
105        #[optional]
106        #[unsafe(method(windowTypeForWebExtensionContext:))]
107        #[unsafe(method_family = none)]
108        unsafe fn windowTypeForWebExtensionContext(
109            &self,
110            context: &WKWebExtensionContext,
111        ) -> WKWebExtensionWindowType;
112
113        #[cfg(feature = "WKWebExtensionContext")]
114        /// Called when the state of the window is needed.
115        ///
116        /// Parameter `context`: The context in which the web extension is running.
117        ///
118        /// Returns: The state of the window.
119        ///
120        /// Defaults to``WKWebExtensionWindowStateNormal`` if not implemented.
121        #[optional]
122        #[unsafe(method(windowStateForWebExtensionContext:))]
123        #[unsafe(method_family = none)]
124        unsafe fn windowStateForWebExtensionContext(
125            &self,
126            context: &WKWebExtensionContext,
127        ) -> WKWebExtensionWindowState;
128
129        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
130        /// Called to set the state of the window.
131        ///
132        /// Parameter `context`: The context in which the web extension is running.
133        ///
134        /// Parameter `state`: The new state of the window.
135        ///
136        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
137        /// which should be provided if any errors occurred.
138        ///
139        /// The implementation of ``windowStateForWebExtensionContext:`` is a prerequisite.
140        /// Without it, this method will not be called.
141        ///
142        /// See also: windowStateForWebExtensionContext:
143        #[optional]
144        #[unsafe(method(setWindowState:forWebExtensionContext:completionHandler:))]
145        #[unsafe(method_family = none)]
146        unsafe fn setWindowState_forWebExtensionContext_completionHandler(
147            &self,
148            state: WKWebExtensionWindowState,
149            context: &WKWebExtensionContext,
150            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
151        );
152
153        #[cfg(feature = "WKWebExtensionContext")]
154        /// Called when the private state of the window is needed.
155        ///
156        /// Parameter `context`: The context in which the web extension is running.
157        ///
158        /// Returns: `YES` if the window is private, `NO` otherwise.
159        ///
160        /// Defaults to `NO` if not implemented. This value is cached and will not change for the duration of the window or its contained tabs.
161        ///
162        /// Note: To ensure proper isolation between private and non-private data, web views associated with private data must use a
163        /// different ``WKUserContentController``. Likewise, to be identified as a private web view and to ensure that cookies and other
164        /// website data is not shared, private web views must be configured to use a non-persistent ``WKWebsiteDataStore``.
165        #[optional]
166        #[unsafe(method(isPrivateForWebExtensionContext:))]
167        #[unsafe(method_family = none)]
168        unsafe fn isPrivateForWebExtensionContext(&self, context: &WKWebExtensionContext) -> bool;
169
170        #[cfg(all(feature = "WKWebExtensionContext", feature = "objc2-core-foundation"))]
171        /// Called when the screen frame containing the window is needed.
172        ///
173        /// Parameter `context`: The context associated with the running web extension.
174        ///
175        /// Returns: The frame for the screen containing the window.
176        ///
177        /// Defaults to ``CGRectNull`` if not implemented.
178        #[optional]
179        #[unsafe(method(screenFrameForWebExtensionContext:))]
180        #[unsafe(method_family = none)]
181        unsafe fn screenFrameForWebExtensionContext(
182            &self,
183            context: &WKWebExtensionContext,
184        ) -> CGRect;
185
186        #[cfg(all(feature = "WKWebExtensionContext", feature = "objc2-core-foundation"))]
187        /// Called when the frame of the window is needed.
188        ///
189        /// Parameter `context`: The context in which the web extension is running.
190        ///
191        /// Returns: The frame of the window, in screen coordinates
192        ///
193        /// Defaults to ``CGRectNull`` if not implemented.
194        #[optional]
195        #[unsafe(method(frameForWebExtensionContext:))]
196        #[unsafe(method_family = none)]
197        unsafe fn frameForWebExtensionContext(&self, context: &WKWebExtensionContext) -> CGRect;
198
199        #[cfg(all(
200            feature = "WKWebExtensionContext",
201            feature = "block2",
202            feature = "objc2-core-foundation"
203        ))]
204        /// Called to set the frame of the window.
205        ///
206        /// Parameter `context`: The context in which the web extension is running.
207        ///
208        /// Parameter `frame`: The new frame of the window, in screen coordinates.
209        ///
210        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
211        /// which should be provided if any errors occurred.
212        ///
213        /// On macOS, the implementation of both ``frameForWebExtensionContext:`` and ``screenFrameForWebExtensionContext:``
214        /// are prerequisites. On iOS, iPadOS, and visionOS, only ``frameForWebExtensionContext:`` is a prerequisite. Without the respective method(s),
215        /// this method will not be called.
216        ///
217        /// See also: frameForWebExtensionContext:
218        ///
219        /// See also: screenFrameForWebExtensionContext:
220        #[optional]
221        #[unsafe(method(setFrame:forWebExtensionContext:completionHandler:))]
222        #[unsafe(method_family = none)]
223        unsafe fn setFrame_forWebExtensionContext_completionHandler(
224            &self,
225            frame: CGRect,
226            context: &WKWebExtensionContext,
227            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
228        );
229
230        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
231        /// Called to focus the window.
232        ///
233        /// Parameter `context`: The context in which the web extension is running.
234        ///
235        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
236        /// which should be provided if any errors occurred.
237        ///
238        /// No action is performed if not implemented.
239        #[optional]
240        #[unsafe(method(focusForWebExtensionContext:completionHandler:))]
241        #[unsafe(method_family = none)]
242        unsafe fn focusForWebExtensionContext_completionHandler(
243            &self,
244            context: &WKWebExtensionContext,
245            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
246        );
247
248        #[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
249        /// Called to close the window.
250        ///
251        /// Parameter `context`: The context in which the web extension is running.
252        ///
253        /// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
254        /// which should be provided if any errors occurred.
255        ///
256        /// No action is performed if not implemented.
257        #[optional]
258        #[unsafe(method(closeForWebExtensionContext:completionHandler:))]
259        #[unsafe(method_family = none)]
260        unsafe fn closeForWebExtensionContext_completionHandler(
261            &self,
262            context: &WKWebExtensionContext,
263            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
264        );
265    }
266);