1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct WKNavigationActionPolicy(pub NSInteger);
18impl WKNavigationActionPolicy {
19 #[doc(alias = "WKNavigationActionPolicyCancel")]
20 pub const Cancel: Self = Self(0);
21 #[doc(alias = "WKNavigationActionPolicyAllow")]
22 pub const Allow: Self = Self(1);
23 #[doc(alias = "WKNavigationActionPolicyDownload")]
24 pub const Download: Self = Self(2);
25}
26
27unsafe impl Encode for WKNavigationActionPolicy {
28 const ENCODING: Encoding = NSInteger::ENCODING;
29}
30
31unsafe impl RefEncode for WKNavigationActionPolicy {
32 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35#[repr(transparent)]
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41pub struct WKNavigationResponsePolicy(pub NSInteger);
42impl WKNavigationResponsePolicy {
43 #[doc(alias = "WKNavigationResponsePolicyCancel")]
44 pub const Cancel: Self = Self(0);
45 #[doc(alias = "WKNavigationResponsePolicyAllow")]
46 pub const Allow: Self = Self(1);
47 #[doc(alias = "WKNavigationResponsePolicyDownload")]
48 pub const Download: Self = Self(2);
49}
50
51unsafe impl Encode for WKNavigationResponsePolicy {
52 const ENCODING: Encoding = NSInteger::ENCODING;
53}
54
55unsafe impl RefEncode for WKNavigationResponsePolicy {
56 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
57}
58
59extern_protocol!(
60 pub unsafe trait WKNavigationDelegate: NSObjectProtocol + MainThreadOnly {
66 #[cfg(all(
67 feature = "WKNavigationAction",
68 feature = "WKWebView",
69 feature = "block2",
70 feature = "objc2-app-kit"
71 ))]
72 #[cfg(target_os = "macos")]
73 #[optional]
85 #[unsafe(method(webView:decidePolicyForNavigationAction:decisionHandler:))]
86 #[unsafe(method_family = none)]
87 unsafe fn webView_decidePolicyForNavigationAction_decisionHandler(
88 &self,
89 web_view: &WKWebView,
90 navigation_action: &WKNavigationAction,
91 decision_handler: &block2::DynBlock<dyn Fn(WKNavigationActionPolicy)>,
92 );
93
94 #[cfg(all(
95 feature = "WKNavigationAction",
96 feature = "WKWebView",
97 feature = "WKWebpagePreferences",
98 feature = "block2",
99 feature = "objc2-app-kit"
100 ))]
101 #[cfg(target_os = "macos")]
102 #[optional]
119 #[unsafe(method(webView:decidePolicyForNavigationAction:preferences:decisionHandler:))]
120 #[unsafe(method_family = none)]
121 unsafe fn webView_decidePolicyForNavigationAction_preferences_decisionHandler(
122 &self,
123 web_view: &WKWebView,
124 navigation_action: &WKNavigationAction,
125 preferences: &WKWebpagePreferences,
126 decision_handler: &block2::DynBlock<
127 dyn Fn(WKNavigationActionPolicy, NonNull<WKWebpagePreferences>),
128 >,
129 );
130
131 #[cfg(all(
132 feature = "WKNavigationResponse",
133 feature = "WKWebView",
134 feature = "block2",
135 feature = "objc2-app-kit"
136 ))]
137 #[cfg(target_os = "macos")]
138 #[optional]
151 #[unsafe(method(webView:decidePolicyForNavigationResponse:decisionHandler:))]
152 #[unsafe(method_family = none)]
153 unsafe fn webView_decidePolicyForNavigationResponse_decisionHandler(
154 &self,
155 web_view: &WKWebView,
156 navigation_response: &WKNavigationResponse,
157 decision_handler: &block2::DynBlock<dyn Fn(WKNavigationResponsePolicy)>,
158 );
159
160 #[cfg(all(
161 feature = "WKNavigation",
162 feature = "WKWebView",
163 feature = "objc2-app-kit"
164 ))]
165 #[cfg(target_os = "macos")]
166 #[optional]
172 #[unsafe(method(webView:didStartProvisionalNavigation:))]
173 #[unsafe(method_family = none)]
174 unsafe fn webView_didStartProvisionalNavigation(
175 &self,
176 web_view: &WKWebView,
177 navigation: Option<&WKNavigation>,
178 );
179
180 #[cfg(all(
181 feature = "WKNavigation",
182 feature = "WKWebView",
183 feature = "objc2-app-kit"
184 ))]
185 #[cfg(target_os = "macos")]
186 #[optional]
193 #[unsafe(method(webView:didReceiveServerRedirectForProvisionalNavigation:))]
194 #[unsafe(method_family = none)]
195 unsafe fn webView_didReceiveServerRedirectForProvisionalNavigation(
196 &self,
197 web_view: &WKWebView,
198 navigation: Option<&WKNavigation>,
199 );
200
201 #[cfg(all(
202 feature = "WKNavigation",
203 feature = "WKWebView",
204 feature = "objc2-app-kit"
205 ))]
206 #[cfg(target_os = "macos")]
207 #[optional]
216 #[unsafe(method(webView:didFailProvisionalNavigation:withError:))]
217 #[unsafe(method_family = none)]
218 unsafe fn webView_didFailProvisionalNavigation_withError(
219 &self,
220 web_view: &WKWebView,
221 navigation: Option<&WKNavigation>,
222 error: &NSError,
223 );
224
225 #[cfg(all(
226 feature = "WKNavigation",
227 feature = "WKWebView",
228 feature = "objc2-app-kit"
229 ))]
230 #[cfg(target_os = "macos")]
231 #[optional]
237 #[unsafe(method(webView:didCommitNavigation:))]
238 #[unsafe(method_family = none)]
239 unsafe fn webView_didCommitNavigation(
240 &self,
241 web_view: &WKWebView,
242 navigation: Option<&WKNavigation>,
243 );
244
245 #[cfg(all(
246 feature = "WKNavigation",
247 feature = "WKWebView",
248 feature = "objc2-app-kit"
249 ))]
250 #[cfg(target_os = "macos")]
251 #[optional]
257 #[unsafe(method(webView:didFinishNavigation:))]
258 #[unsafe(method_family = none)]
259 unsafe fn webView_didFinishNavigation(
260 &self,
261 web_view: &WKWebView,
262 navigation: Option<&WKNavigation>,
263 );
264
265 #[cfg(all(
266 feature = "WKNavigation",
267 feature = "WKWebView",
268 feature = "objc2-app-kit"
269 ))]
270 #[cfg(target_os = "macos")]
271 #[optional]
280 #[unsafe(method(webView:didFailNavigation:withError:))]
281 #[unsafe(method_family = none)]
282 unsafe fn webView_didFailNavigation_withError(
283 &self,
284 web_view: &WKWebView,
285 navigation: Option<&WKNavigation>,
286 error: &NSError,
287 );
288
289 #[cfg(all(feature = "WKWebView", feature = "block2", feature = "objc2-app-kit"))]
290 #[cfg(target_os = "macos")]
291 #[optional]
305 #[unsafe(method(webView:didReceiveAuthenticationChallenge:completionHandler:))]
306 #[unsafe(method_family = none)]
307 unsafe fn webView_didReceiveAuthenticationChallenge_completionHandler(
308 &self,
309 web_view: &WKWebView,
310 challenge: &NSURLAuthenticationChallenge,
311 completion_handler: &block2::DynBlock<
312 dyn Fn(NSURLSessionAuthChallengeDisposition, *mut NSURLCredential),
313 >,
314 );
315
316 #[cfg(all(feature = "WKWebView", feature = "objc2-app-kit"))]
317 #[cfg(target_os = "macos")]
318 #[optional]
322 #[unsafe(method(webViewWebContentProcessDidTerminate:))]
323 #[unsafe(method_family = none)]
324 unsafe fn webViewWebContentProcessDidTerminate(&self, web_view: &WKWebView);
325
326 #[cfg(all(feature = "WKWebView", feature = "block2", feature = "objc2-app-kit"))]
327 #[cfg(target_os = "macos")]
328 #[optional]
336 #[unsafe(method(webView:authenticationChallenge:shouldAllowDeprecatedTLS:))]
337 #[unsafe(method_family = none)]
338 unsafe fn webView_authenticationChallenge_shouldAllowDeprecatedTLS(
339 &self,
340 web_view: &WKWebView,
341 challenge: &NSURLAuthenticationChallenge,
342 decision_handler: &block2::DynBlock<dyn Fn(Bool)>,
343 );
344
345 #[cfg(all(
346 feature = "WKDownload",
347 feature = "WKNavigationAction",
348 feature = "WKWebView",
349 feature = "objc2-app-kit"
350 ))]
351 #[cfg(target_os = "macos")]
352 #[optional]
353 #[unsafe(method(webView:navigationAction:didBecomeDownload:))]
354 #[unsafe(method_family = none)]
355 unsafe fn webView_navigationAction_didBecomeDownload(
356 &self,
357 web_view: &WKWebView,
358 navigation_action: &WKNavigationAction,
359 download: &WKDownload,
360 );
361
362 #[cfg(all(
363 feature = "WKDownload",
364 feature = "WKNavigationResponse",
365 feature = "WKWebView",
366 feature = "objc2-app-kit"
367 ))]
368 #[cfg(target_os = "macos")]
369 #[optional]
370 #[unsafe(method(webView:navigationResponse:didBecomeDownload:))]
371 #[unsafe(method_family = none)]
372 unsafe fn webView_navigationResponse_didBecomeDownload(
373 &self,
374 web_view: &WKWebView,
375 navigation_response: &WKNavigationResponse,
376 download: &WKDownload,
377 );
378
379 #[cfg(all(
380 feature = "WKBackForwardListItem",
381 feature = "WKWebView",
382 feature = "block2",
383 feature = "objc2-app-kit"
384 ))]
385 #[cfg(target_os = "macos")]
386 #[optional]
387 #[unsafe(method(webView:shouldGoToBackForwardListItem:willUseInstantBack:completionHandler:))]
388 #[unsafe(method_family = none)]
389 unsafe fn webView_shouldGoToBackForwardListItem_willUseInstantBack_completionHandler(
390 &self,
391 web_view: &WKWebView,
392 back_forward_list_item: &WKBackForwardListItem,
393 will_use_instant_back: bool,
394 completion_handler: &block2::DynBlock<dyn Fn(Bool)>,
395 );
396 }
397);