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
//! 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-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;
use crate::*;
/// Constants used by ``WKWebExtensionWindow`` to indicate the type of a window.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionwindowtype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct WKWebExtensionWindowType(pub NSInteger);
impl WKWebExtensionWindowType {
#[doc(alias = "WKWebExtensionWindowTypeNormal")]
pub const Normal: Self = Self(0);
#[doc(alias = "WKWebExtensionWindowTypePopup")]
pub const Popup: Self = Self(1);
}
unsafe impl Encode for WKWebExtensionWindowType {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for WKWebExtensionWindowType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Constants used by ``WKWebExtensionWindow`` to indicate possible states of a window.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionwindowstate?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct WKWebExtensionWindowState(pub NSInteger);
impl WKWebExtensionWindowState {
#[doc(alias = "WKWebExtensionWindowStateNormal")]
pub const Normal: Self = Self(0);
#[doc(alias = "WKWebExtensionWindowStateMinimized")]
pub const Minimized: Self = Self(1);
#[doc(alias = "WKWebExtensionWindowStateMaximized")]
pub const Maximized: Self = Self(2);
#[doc(alias = "WKWebExtensionWindowStateFullscreen")]
pub const Fullscreen: Self = Self(3);
}
unsafe impl Encode for WKWebExtensionWindowState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for WKWebExtensionWindowState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_protocol!(
/// A class conforming to the ``WKWebExtensionWindow`` protocol represents a window to web extensions.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionwindow?language=objc)
pub unsafe trait WKWebExtensionWindow: NSObjectProtocol + MainThreadOnly {
#[cfg(all(feature = "WKWebExtensionContext", feature = "WKWebExtensionTab"))]
/// Called when the tabs are needed for the window.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Returns: An array of tabs in the window.
///
/// Defaults to an empty array if not implemented.
#[optional]
#[unsafe(method(tabsForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn tabsForWebExtensionContext(
&self,
context: &WKWebExtensionContext,
) -> Retained<NSArray<ProtocolObject<dyn WKWebExtensionTab>>>;
#[cfg(all(feature = "WKWebExtensionContext", feature = "WKWebExtensionTab"))]
/// Called when the active tab is needed for the window.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Returns: The active tab in the window, which represents the frontmost tab currently in view.
///
/// Defaults to `nil` if not implemented.
#[optional]
#[unsafe(method(activeTabForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn activeTabForWebExtensionContext(
&self,
context: &WKWebExtensionContext,
) -> Option<Retained<ProtocolObject<dyn WKWebExtensionTab>>>;
#[cfg(feature = "WKWebExtensionContext")]
/// Called when the type of the window is needed.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Returns: The type of the window.
///
/// Defaults to``WKWebExtensionWindowTypeNormal`` if not implemented.
#[optional]
#[unsafe(method(windowTypeForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn windowTypeForWebExtensionContext(
&self,
context: &WKWebExtensionContext,
) -> WKWebExtensionWindowType;
#[cfg(feature = "WKWebExtensionContext")]
/// Called when the state of the window is needed.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Returns: The state of the window.
///
/// Defaults to``WKWebExtensionWindowStateNormal`` if not implemented.
#[optional]
#[unsafe(method(windowStateForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn windowStateForWebExtensionContext(
&self,
context: &WKWebExtensionContext,
) -> WKWebExtensionWindowState;
#[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
/// Called to set the state of the window.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Parameter `state`: The new state of the window.
///
/// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
/// which should be provided if any errors occurred.
///
/// The implementation of ``windowStateForWebExtensionContext:`` is a prerequisite.
/// Without it, this method will not be called.
///
/// See also: windowStateForWebExtensionContext:
#[optional]
#[unsafe(method(setWindowState:forWebExtensionContext:completionHandler:))]
#[unsafe(method_family = none)]
unsafe fn setWindowState_forWebExtensionContext_completionHandler(
&self,
state: WKWebExtensionWindowState,
context: &WKWebExtensionContext,
completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
);
#[cfg(feature = "WKWebExtensionContext")]
/// Called when the private state of the window is needed.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Returns: `YES` if the window is private, `NO` otherwise.
///
/// Defaults to `NO` if not implemented. This value is cached and will not change for the duration of the window or its contained tabs.
///
/// Note: To ensure proper isolation between private and non-private data, web views associated with private data must use a
/// different ``WKUserContentController``. Likewise, to be identified as a private web view and to ensure that cookies and other
/// website data is not shared, private web views must be configured to use a non-persistent ``WKWebsiteDataStore``.
#[optional]
#[unsafe(method(isPrivateForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn isPrivateForWebExtensionContext(&self, context: &WKWebExtensionContext) -> bool;
#[cfg(all(feature = "WKWebExtensionContext", feature = "objc2-core-foundation"))]
/// Called when the screen frame containing the window is needed.
///
/// Parameter `context`: The context associated with the running web extension.
///
/// Returns: The frame for the screen containing the window.
///
/// Defaults to ``CGRectNull`` if not implemented.
#[optional]
#[unsafe(method(screenFrameForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn screenFrameForWebExtensionContext(
&self,
context: &WKWebExtensionContext,
) -> CGRect;
#[cfg(all(feature = "WKWebExtensionContext", feature = "objc2-core-foundation"))]
/// Called when the frame of the window is needed.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Returns: The frame of the window, in screen coordinates
///
/// Defaults to ``CGRectNull`` if not implemented.
#[optional]
#[unsafe(method(frameForWebExtensionContext:))]
#[unsafe(method_family = none)]
unsafe fn frameForWebExtensionContext(&self, context: &WKWebExtensionContext) -> CGRect;
#[cfg(all(
feature = "WKWebExtensionContext",
feature = "block2",
feature = "objc2-core-foundation"
))]
/// Called to set the frame of the window.
///
/// Parameter `context`: The context in which the web extension is running.
///
/// Parameter `frame`: The new frame of the window, in screen coordinates.
///
/// Parameter `completionHandler`: A block that must be called upon completion. It takes a single error argument,
/// which should be provided if any errors occurred.
///
/// On macOS, the implementation of both ``frameForWebExtensionContext:`` and ``screenFrameForWebExtensionContext:``
/// are prerequisites. On iOS, iPadOS, and visionOS, only ``frameForWebExtensionContext:`` is a prerequisite. Without the respective method(s),
/// this method will not be called.
///
/// See also: frameForWebExtensionContext:
///
/// See also: screenFrameForWebExtensionContext:
#[optional]
#[unsafe(method(setFrame:forWebExtensionContext:completionHandler:))]
#[unsafe(method_family = none)]
unsafe fn setFrame_forWebExtensionContext_completionHandler(
&self,
frame: CGRect,
context: &WKWebExtensionContext,
completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
);
#[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
/// Called to focus the window.
///
/// 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(focusForWebExtensionContext:completionHandler:))]
#[unsafe(method_family = none)]
unsafe fn focusForWebExtensionContext_completionHandler(
&self,
context: &WKWebExtensionContext,
completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
);
#[cfg(all(feature = "WKWebExtensionContext", feature = "block2"))]
/// Called to close the window.
///
/// 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)>,
);
}
);