objc2_web_kit/generated/
WKNavigationDelegate.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// The policy to pass back to the decision handler from the
11/// webView:decidePolicyForNavigationAction:decisionHandler: method.
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc)
14// NS_ENUM
15#[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/// The policy to pass back to the decision handler from the webView:decidePolicyForNavigationResponse:decisionHandler: method.
36///
37/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy?language=objc)
38// NS_ENUM
39#[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    /// A class conforming to the WKNavigationDelegate protocol can provide
61    /// methods for tracking progress for main frame navigations and for deciding
62    /// policy for main frame and subframe navigations.
63    ///
64    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc)
65    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        /// Decides whether to allow or cancel a navigation.
74        ///
75        /// Parameter `webView`: The web view invoking the delegate method.
76        ///
77        /// Parameter `navigationAction`: Descriptive information about the action
78        /// triggering the navigation request.
79        ///
80        /// Parameter `decisionHandler`: The decision handler to call to allow or cancel the
81        /// navigation. The argument is one of the constants of the enumerated type WKNavigationActionPolicy.
82        ///
83        /// If you do not implement this method, the web view will load the request or, if appropriate, forward it to another application.
84        #[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        /// Decides whether to allow or cancel a navigation.
103        ///
104        /// Parameter `webView`: The web view invoking the delegate method.
105        ///
106        /// Parameter `navigationAction`: Descriptive information about the action
107        /// triggering the navigation request.
108        ///
109        /// Parameter `preferences`: The default set of webpage preferences. This may be
110        /// changed by setting defaultWebpagePreferences on WKWebViewConfiguration.
111        ///
112        /// Parameter `decisionHandler`: The policy decision handler to call to allow or cancel
113        /// the navigation. The arguments are one of the constants of the enumerated type
114        /// WKNavigationActionPolicy, as well as an instance of WKWebpagePreferences.
115        ///
116        /// If you implement this method,
117        /// -webView:decidePolicyForNavigationAction:decisionHandler: will not be called.
118        #[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        /// Decides whether to allow or cancel a navigation after its
139        /// response is known.
140        ///
141        /// Parameter `webView`: The web view invoking the delegate method.
142        ///
143        /// Parameter `navigationResponse`: Descriptive information about the navigation
144        /// response.
145        ///
146        /// Parameter `decisionHandler`: The decision handler to call to allow or cancel the
147        /// navigation. The argument is one of the constants of the enumerated type WKNavigationResponsePolicy.
148        ///
149        /// If you do not implement this method, the web view will allow the response, if the web view can show it.
150        #[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        /// Invoked when a main frame navigation starts.
167        ///
168        /// Parameter `webView`: The web view invoking the delegate method.
169        ///
170        /// Parameter `navigation`: The navigation.
171        ///
172        /// # Safety
173        ///
174        /// `navigation` might not allow `None`.
175        #[optional]
176        #[unsafe(method(webView:didStartProvisionalNavigation:))]
177        #[unsafe(method_family = none)]
178        unsafe fn webView_didStartProvisionalNavigation(
179            &self,
180            web_view: &WKWebView,
181            navigation: Option<&WKNavigation>,
182        );
183
184        #[cfg(all(
185            feature = "WKNavigation",
186            feature = "WKWebView",
187            feature = "objc2-app-kit"
188        ))]
189        #[cfg(target_os = "macos")]
190        /// Invoked when a server redirect is received for the main
191        /// frame.
192        ///
193        /// Parameter `webView`: The web view invoking the delegate method.
194        ///
195        /// Parameter `navigation`: The navigation.
196        ///
197        /// # Safety
198        ///
199        /// `navigation` might not allow `None`.
200        #[optional]
201        #[unsafe(method(webView:didReceiveServerRedirectForProvisionalNavigation:))]
202        #[unsafe(method_family = none)]
203        unsafe fn webView_didReceiveServerRedirectForProvisionalNavigation(
204            &self,
205            web_view: &WKWebView,
206            navigation: Option<&WKNavigation>,
207        );
208
209        #[cfg(all(
210            feature = "WKNavigation",
211            feature = "WKWebView",
212            feature = "objc2-app-kit"
213        ))]
214        #[cfg(target_os = "macos")]
215        /// Invoked when an error occurs while starting to load data for
216        /// the main frame.
217        ///
218        /// Parameter `webView`: The web view invoking the delegate method.
219        ///
220        /// Parameter `navigation`: The navigation.
221        ///
222        /// Parameter `error`: The error that occurred.
223        ///
224        /// # Safety
225        ///
226        /// `navigation` might not allow `None`.
227        #[optional]
228        #[unsafe(method(webView:didFailProvisionalNavigation:withError:))]
229        #[unsafe(method_family = none)]
230        unsafe fn webView_didFailProvisionalNavigation_withError(
231            &self,
232            web_view: &WKWebView,
233            navigation: Option<&WKNavigation>,
234            error: &NSError,
235        );
236
237        #[cfg(all(
238            feature = "WKNavigation",
239            feature = "WKWebView",
240            feature = "objc2-app-kit"
241        ))]
242        #[cfg(target_os = "macos")]
243        /// Invoked when content starts arriving for the main frame.
244        ///
245        /// Parameter `webView`: The web view invoking the delegate method.
246        ///
247        /// Parameter `navigation`: The navigation.
248        ///
249        /// # Safety
250        ///
251        /// `navigation` might not allow `None`.
252        #[optional]
253        #[unsafe(method(webView:didCommitNavigation:))]
254        #[unsafe(method_family = none)]
255        unsafe fn webView_didCommitNavigation(
256            &self,
257            web_view: &WKWebView,
258            navigation: Option<&WKNavigation>,
259        );
260
261        #[cfg(all(
262            feature = "WKNavigation",
263            feature = "WKWebView",
264            feature = "objc2-app-kit"
265        ))]
266        #[cfg(target_os = "macos")]
267        /// Invoked when a main frame navigation completes.
268        ///
269        /// Parameter `webView`: The web view invoking the delegate method.
270        ///
271        /// Parameter `navigation`: The navigation.
272        ///
273        /// # Safety
274        ///
275        /// `navigation` might not allow `None`.
276        #[optional]
277        #[unsafe(method(webView:didFinishNavigation:))]
278        #[unsafe(method_family = none)]
279        unsafe fn webView_didFinishNavigation(
280            &self,
281            web_view: &WKWebView,
282            navigation: Option<&WKNavigation>,
283        );
284
285        #[cfg(all(
286            feature = "WKNavigation",
287            feature = "WKWebView",
288            feature = "objc2-app-kit"
289        ))]
290        #[cfg(target_os = "macos")]
291        /// Invoked when an error occurs during a committed main frame
292        /// navigation.
293        ///
294        /// Parameter `webView`: The web view invoking the delegate method.
295        ///
296        /// Parameter `navigation`: The navigation.
297        ///
298        /// Parameter `error`: The error that occurred.
299        ///
300        /// # Safety
301        ///
302        /// `navigation` might not allow `None`.
303        #[optional]
304        #[unsafe(method(webView:didFailNavigation:withError:))]
305        #[unsafe(method_family = none)]
306        unsafe fn webView_didFailNavigation_withError(
307            &self,
308            web_view: &WKWebView,
309            navigation: Option<&WKNavigation>,
310            error: &NSError,
311        );
312
313        #[cfg(all(feature = "WKWebView", feature = "block2", feature = "objc2-app-kit"))]
314        #[cfg(target_os = "macos")]
315        /// Invoked when the web view needs to respond to an authentication challenge.
316        ///
317        /// Parameter `webView`: The web view that received the authentication challenge.
318        ///
319        /// Parameter `challenge`: The authentication challenge.
320        ///
321        /// Parameter `completionHandler`: The completion handler you must invoke to respond to the challenge. The
322        /// disposition argument is one of the constants of the enumerated type
323        /// NSURLSessionAuthChallengeDisposition. When disposition is NSURLSessionAuthChallengeUseCredential,
324        /// the credential argument is the credential to use, or nil to indicate continuing without a
325        /// credential.
326        ///
327        /// If you do not implement this method, the web view will respond to the authentication challenge with the NSURLSessionAuthChallengeRejectProtectionSpace disposition.
328        #[optional]
329        #[unsafe(method(webView:didReceiveAuthenticationChallenge:completionHandler:))]
330        #[unsafe(method_family = none)]
331        unsafe fn webView_didReceiveAuthenticationChallenge_completionHandler(
332            &self,
333            web_view: &WKWebView,
334            challenge: &NSURLAuthenticationChallenge,
335            completion_handler: &block2::DynBlock<
336                dyn Fn(NSURLSessionAuthChallengeDisposition, *mut NSURLCredential),
337            >,
338        );
339
340        #[cfg(all(feature = "WKWebView", feature = "objc2-app-kit"))]
341        #[cfg(target_os = "macos")]
342        /// Invoked when the web view's web content process is terminated.
343        ///
344        /// Parameter `webView`: The web view whose underlying web content process was terminated.
345        #[optional]
346        #[unsafe(method(webViewWebContentProcessDidTerminate:))]
347        #[unsafe(method_family = none)]
348        unsafe fn webViewWebContentProcessDidTerminate(&self, web_view: &WKWebView);
349
350        #[cfg(all(feature = "WKWebView", feature = "block2", feature = "objc2-app-kit"))]
351        #[cfg(target_os = "macos")]
352        /// Invoked when the web view is establishing a network connection using a deprecated version of TLS.
353        ///
354        /// Parameter `webView`: The web view initiating the connection.
355        ///
356        /// Parameter `challenge`: The authentication challenge.
357        ///
358        /// Parameter `decisionHandler`: The decision handler you must invoke to respond to indicate whether or not to continue with the connection establishment.
359        #[optional]
360        #[unsafe(method(webView:authenticationChallenge:shouldAllowDeprecatedTLS:))]
361        #[unsafe(method_family = none)]
362        unsafe fn webView_authenticationChallenge_shouldAllowDeprecatedTLS(
363            &self,
364            web_view: &WKWebView,
365            challenge: &NSURLAuthenticationChallenge,
366            decision_handler: &block2::DynBlock<dyn Fn(Bool)>,
367        );
368
369        #[cfg(all(
370            feature = "WKDownload",
371            feature = "WKNavigationAction",
372            feature = "WKWebView",
373            feature = "objc2-app-kit"
374        ))]
375        #[cfg(target_os = "macos")]
376        #[optional]
377        #[unsafe(method(webView:navigationAction:didBecomeDownload:))]
378        #[unsafe(method_family = none)]
379        unsafe fn webView_navigationAction_didBecomeDownload(
380            &self,
381            web_view: &WKWebView,
382            navigation_action: &WKNavigationAction,
383            download: &WKDownload,
384        );
385
386        #[cfg(all(
387            feature = "WKDownload",
388            feature = "WKNavigationResponse",
389            feature = "WKWebView",
390            feature = "objc2-app-kit"
391        ))]
392        #[cfg(target_os = "macos")]
393        #[optional]
394        #[unsafe(method(webView:navigationResponse:didBecomeDownload:))]
395        #[unsafe(method_family = none)]
396        unsafe fn webView_navigationResponse_didBecomeDownload(
397            &self,
398            web_view: &WKWebView,
399            navigation_response: &WKNavigationResponse,
400            download: &WKDownload,
401        );
402
403        #[cfg(all(
404            feature = "WKBackForwardListItem",
405            feature = "WKWebView",
406            feature = "block2",
407            feature = "objc2-app-kit"
408        ))]
409        #[cfg(target_os = "macos")]
410        #[optional]
411        #[unsafe(method(webView:shouldGoToBackForwardListItem:willUseInstantBack:completionHandler:))]
412        #[unsafe(method_family = none)]
413        unsafe fn webView_shouldGoToBackForwardListItem_willUseInstantBack_completionHandler(
414            &self,
415            web_view: &WKWebView,
416            back_forward_list_item: &WKBackForwardListItem,
417            will_use_instant_back: bool,
418            completion_handler: &block2::DynBlock<dyn Fn(Bool)>,
419        );
420    }
421);