objc2_safari_services/generated/
SFSafariExtensionHandling.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
10extern_protocol!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/safariservices/sfsafariextensionhandling?language=objc)
12    pub unsafe trait SFSafariExtensionHandling: NSObjectProtocol {
13        #[cfg(feature = "SFSafariPage")]
14        /// This is called when a content script from an extension dispatches a message to the app extension.
15        ///
16        /// # Safety
17        ///
18        /// `user_info` generic should be of the correct type.
19        #[optional]
20        #[unsafe(method(messageReceivedWithName:fromPage:userInfo:))]
21        #[unsafe(method_family = none)]
22        unsafe fn messageReceivedWithName_fromPage_userInfo(
23            &self,
24            message_name: &NSString,
25            page: &SFSafariPage,
26            user_info: Option<&NSDictionary<NSString, AnyObject>>,
27        );
28
29        /// This is called when the extension's containing app dispatches a message to the app extension.
30        ///
31        /// # Safety
32        ///
33        /// `user_info` generic should be of the correct type.
34        #[optional]
35        #[unsafe(method(messageReceivedFromContainingAppWithName:userInfo:))]
36        #[unsafe(method_family = none)]
37        unsafe fn messageReceivedFromContainingAppWithName_userInfo(
38            &self,
39            message_name: &NSString,
40            user_info: Option<&NSDictionary<NSString, AnyObject>>,
41        );
42
43        #[cfg(feature = "SFSafariWindow")]
44        /// This is called when the extension's toolbar item is clicked.
45        #[optional]
46        #[unsafe(method(toolbarItemClickedInWindow:))]
47        #[unsafe(method_family = none)]
48        unsafe fn toolbarItemClickedInWindow(&self, window: &SFSafariWindow);
49
50        #[cfg(all(feature = "SFSafariWindow", feature = "block2"))]
51        /// This is called when Safari's state changed in some way that would require the extension's toolbar item to be validated again.
52        #[optional]
53        #[unsafe(method(validateToolbarItemInWindow:validationHandler:))]
54        #[unsafe(method_family = none)]
55        unsafe fn validateToolbarItemInWindow_validationHandler(
56            &self,
57            window: &SFSafariWindow,
58            validation_handler: &block2::DynBlock<dyn Fn(Bool, NonNull<NSString>)>,
59        );
60
61        #[cfg(feature = "SFSafariPage")]
62        /// This is called when one of the extension's context menu items is selected.
63        ///
64        /// # Safety
65        ///
66        /// `user_info` generic should be of the correct type.
67        #[optional]
68        #[unsafe(method(contextMenuItemSelectedWithCommand:inPage:userInfo:))]
69        #[unsafe(method_family = none)]
70        unsafe fn contextMenuItemSelectedWithCommand_inPage_userInfo(
71            &self,
72            command: &NSString,
73            page: &SFSafariPage,
74            user_info: Option<&NSDictionary<NSString, AnyObject>>,
75        );
76
77        #[cfg(all(feature = "SFSafariPage", feature = "block2"))]
78        /// This is called before context menu is shown, and provides a way to validate individual context menu items.
79        ///
80        /// # Safety
81        ///
82        /// `user_info` generic should be of the correct type.
83        #[optional]
84        #[unsafe(method(validateContextMenuItemWithCommand:inPage:userInfo:validationHandler:))]
85        #[unsafe(method_family = none)]
86        unsafe fn validateContextMenuItemWithCommand_inPage_userInfo_validationHandler(
87            &self,
88            command: &NSString,
89            page: &SFSafariPage,
90            user_info: Option<&NSDictionary<NSString, AnyObject>>,
91            validation_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSString)>,
92        );
93
94        #[cfg(feature = "SFSafariWindow")]
95        /// This is called when the extension's popover is about to be opened.
96        #[optional]
97        #[unsafe(method(popoverWillShowInWindow:))]
98        #[unsafe(method_family = none)]
99        unsafe fn popoverWillShowInWindow(&self, window: &SFSafariWindow);
100
101        #[cfg(feature = "SFSafariWindow")]
102        /// This is called after the extension's popover is closed.
103        #[optional]
104        #[unsafe(method(popoverDidCloseInWindow:))]
105        #[unsafe(method_family = none)]
106        unsafe fn popoverDidCloseInWindow(&self, window: &SFSafariWindow);
107
108        #[cfg(all(feature = "SFSafariExtensionViewController", feature = "objc2-app-kit"))]
109        #[cfg(target_os = "macos")]
110        /// Returns the extension popover's view controller.
111        #[optional]
112        #[unsafe(method(popoverViewController))]
113        #[unsafe(method_family = none)]
114        unsafe fn popoverViewController(
115            &self,
116            mtm: MainThreadMarker,
117        ) -> Retained<SFSafariExtensionViewController>;
118
119        #[cfg(feature = "block2")]
120        /// This is called when Safari is about to load a page that the extension has stated it wants to add additional headers for.
121        #[optional]
122        #[unsafe(method(additionalRequestHeadersForURL:completionHandler:))]
123        #[unsafe(method_family = none)]
124        unsafe fn additionalRequestHeadersForURL_completionHandler(
125            &self,
126            url: &NSURL,
127            completion_handler: &block2::DynBlock<dyn Fn(*mut NSDictionary<NSString, NSString>)>,
128        );
129
130        #[cfg(feature = "SFSafariPage")]
131        /// This is called when a content blocker associated with this Safari App Extension performs a blocking action.
132        #[optional]
133        #[unsafe(method(contentBlockerWithIdentifier:blockedResourcesWithURLs:onPage:))]
134        #[unsafe(method_family = none)]
135        unsafe fn contentBlockerWithIdentifier_blockedResourcesWithURLs_onPage(
136            &self,
137            content_blocker_identifier: &NSString,
138            urls: &NSArray<NSURL>,
139            page: &SFSafariPage,
140        );
141
142        #[cfg(feature = "SFSafariPage")]
143        /// This is called when a page in Safari navigates to a URL. The URL will be nil when the extension doesn't have access to it.
144        #[optional]
145        #[unsafe(method(page:willNavigateToURL:))]
146        #[unsafe(method_family = none)]
147        unsafe fn page_willNavigateToURL(&self, page: &SFSafariPage, url: Option<&NSURL>);
148    }
149);