objc2_web_kit/generated/
WKWebExtension.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-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9#[cfg(feature = "objc2-core-foundation")]
10use objc2_core_foundation::*;
11use objc2_foundation::*;
12
13use crate::*;
14
15extern "C" {
16    /// Indicates a ``WKWebExtension`` error.
17    ///
18    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionerrordomain?language=objc)
19    pub static WKWebExtensionErrorDomain: &'static NSErrorDomain;
20}
21
22/// Constants used by ``NSError`` to indicate errors in the ``WKWebExtension`` domain.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionerror?language=objc)
25// NS_ERROR_ENUM
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
28pub struct WKWebExtensionError(pub NSInteger);
29impl WKWebExtensionError {
30    #[doc(alias = "WKWebExtensionErrorUnknown")]
31    pub const Unknown: Self = Self(1);
32    #[doc(alias = "WKWebExtensionErrorResourceNotFound")]
33    pub const ResourceNotFound: Self = Self(2);
34    #[doc(alias = "WKWebExtensionErrorInvalidResourceCodeSignature")]
35    pub const InvalidResourceCodeSignature: Self = Self(3);
36    #[doc(alias = "WKWebExtensionErrorInvalidManifest")]
37    pub const InvalidManifest: Self = Self(4);
38    #[doc(alias = "WKWebExtensionErrorUnsupportedManifestVersion")]
39    pub const UnsupportedManifestVersion: Self = Self(5);
40    #[doc(alias = "WKWebExtensionErrorInvalidManifestEntry")]
41    pub const InvalidManifestEntry: Self = Self(6);
42    #[doc(alias = "WKWebExtensionErrorInvalidDeclarativeNetRequestEntry")]
43    pub const InvalidDeclarativeNetRequestEntry: Self = Self(7);
44    #[doc(alias = "WKWebExtensionErrorInvalidBackgroundPersistence")]
45    pub const InvalidBackgroundPersistence: Self = Self(8);
46    #[doc(alias = "WKWebExtensionErrorInvalidArchive")]
47    pub const InvalidArchive: Self = Self(9);
48}
49
50unsafe impl Encode for WKWebExtensionError {
51    const ENCODING: Encoding = NSInteger::ENCODING;
52}
53
54unsafe impl RefEncode for WKWebExtensionError {
55    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
56}
57
58extern_class!(
59    /// A ``WKWebExtension`` object encapsulates a web extension’s resources that are defined by a `manifest.json`` file.
60    ///
61    /// This class handles the reading and parsing of the manifest file along with the supporting resources like icons and localizations.
62    ///
63    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextension?language=objc)
64    #[unsafe(super(NSObject))]
65    #[thread_kind = MainThreadOnly]
66    #[derive(Debug, PartialEq, Eq, Hash)]
67    pub struct WKWebExtension;
68);
69
70extern_conformance!(
71    unsafe impl NSObjectProtocol for WKWebExtension {}
72);
73
74impl WKWebExtension {
75    extern_methods!(
76        #[unsafe(method(new))]
77        #[unsafe(method_family = new)]
78        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
79
80        #[unsafe(method(init))]
81        #[unsafe(method_family = init)]
82        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
83
84        #[cfg(feature = "block2")]
85        /// Returns a web extension initialized with a specified app extension bundle.
86        ///
87        /// Parameter `appExtensionBundle`: The bundle to use for the new web extension.
88        ///
89        /// Parameter `completionHandler`: A block to be called with an initialized web extension, or
90        /// `nil`if the object could not be initialized due to an error.
91        ///
92        /// The app extension bundle must contain a `manifest.json` file in its resources directory. If the manifest is invalid or missing,
93        /// or the bundle is otherwise improperly configured, an error will be returned.
94        #[unsafe(method(extensionWithAppExtensionBundle:completionHandler:))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn extensionWithAppExtensionBundle_completionHandler(
97            app_extension_bundle: &NSBundle,
98            completion_handler: &block2::DynBlock<dyn Fn(*mut WKWebExtension, *mut NSError)>,
99            mtm: MainThreadMarker,
100        );
101
102        #[cfg(feature = "block2")]
103        /// Returns a web extension initialized with a specified resource base URL, which can point to either a directory or a ZIP archive.
104        ///
105        /// Parameter `resourceBaseURL`: The file URL to use for the new web extension.
106        ///
107        /// Parameter `completionHandler`: A block to be called with an initialized web extension, or
108        /// `nil`if the object could not be initialized due to an error.
109        ///
110        /// The URL must be a file URL that points to either a directory with a `manifest.json` file or a ZIP archive containing a `manifest.json` file.
111        /// If the manifest is invalid or missing, or the URL points to an unsupported format or invalid archive, an error will be returned.
112        #[unsafe(method(extensionWithResourceBaseURL:completionHandler:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn extensionWithResourceBaseURL_completionHandler(
115            resource_base_url: &NSURL,
116            completion_handler: &block2::DynBlock<dyn Fn(*mut WKWebExtension, *mut NSError)>,
117            mtm: MainThreadMarker,
118        );
119
120        /// An array of all errors that occurred during the processing of the extension.
121        ///
122        /// Provides an array of all parse-time errors for the extension, with repeat errors consolidated into a single entry for the original
123        /// occurrence only. If no errors occurred, an empty array is returned.
124        ///
125        /// Note: Once the extension is loaded, use the ``errors`` property on an extension context to monitor any runtime errors, as they can occur
126        /// after the extension is loaded.
127        #[unsafe(method(errors))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn errors(&self) -> Retained<NSArray<NSError>>;
130
131        /// The parsed manifest as a dictionary.
132        #[unsafe(method(manifest))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn manifest(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
135
136        /// The parsed manifest version, or `0` if there is no version specified in the manifest.
137        ///
138        /// Note: An ``WKWebExtensionErrorUnsupportedManifestVersion`` error will be reported if the manifest version isn't specified.
139        #[unsafe(method(manifestVersion))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn manifestVersion(&self) -> c_double;
142
143        /// Checks if a manifest version is supported by the extension.
144        ///
145        /// Parameter `manifestVersion`: The version number to check.
146        ///
147        /// Returns: Returns `YES` if the extension specified a manifest version that is greater than or equal to `manifestVersion`.
148        #[unsafe(method(supportsManifestVersion:))]
149        #[unsafe(method_family = none)]
150        pub unsafe fn supportsManifestVersion(&self, manifest_version: c_double) -> bool;
151
152        /// The default locale for the extension. Returns `nil` if there was no default locale specified.
153        #[unsafe(method(defaultLocale))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn defaultLocale(&self) -> Option<Retained<NSLocale>>;
156
157        /// The localized extension name. Returns `nil` if there was no name specified.
158        #[unsafe(method(displayName))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn displayName(&self) -> Option<Retained<NSString>>;
161
162        /// The localized extension short name. Returns `nil` if there was no short name specified.
163        #[unsafe(method(displayShortName))]
164        #[unsafe(method_family = none)]
165        pub unsafe fn displayShortName(&self) -> Option<Retained<NSString>>;
166
167        /// The localized extension display version. Returns `nil` if there was no display version specified.
168        #[unsafe(method(displayVersion))]
169        #[unsafe(method_family = none)]
170        pub unsafe fn displayVersion(&self) -> Option<Retained<NSString>>;
171
172        /// The localized extension description. Returns `nil` if there was no description specified.
173        #[unsafe(method(displayDescription))]
174        #[unsafe(method_family = none)]
175        pub unsafe fn displayDescription(&self) -> Option<Retained<NSString>>;
176
177        /// The default localized extension action label. Returns `nil` if there was no default action label specified.
178        ///
179        /// This label serves as a default and should be used to represent the extension in contexts like action sheets or toolbars prior to
180        /// the extension being loaded into an extension context. Once the extension is loaded, use the ``actionForTab:`` API to get the tab-specific label.
181        #[unsafe(method(displayActionLabel))]
182        #[unsafe(method_family = none)]
183        pub unsafe fn displayActionLabel(&self) -> Option<Retained<NSString>>;
184
185        /// The extension version. Returns `nil` if there was no version specified.
186        #[unsafe(method(version))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn version(&self) -> Option<Retained<NSString>>;
189
190        #[cfg(all(feature = "objc2-app-kit", feature = "objc2-core-foundation"))]
191        #[cfg(target_os = "macos")]
192        #[unsafe(method(iconForSize:))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn iconForSize(&self, size: CGSize) -> Option<Retained<NSImage>>;
195
196        #[cfg(all(feature = "objc2-app-kit", feature = "objc2-core-foundation"))]
197        #[cfg(target_os = "macos")]
198        #[unsafe(method(actionIconForSize:))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn actionIconForSize(&self, size: CGSize) -> Option<Retained<NSImage>>;
201
202        #[cfg(feature = "WKWebExtensionPermission")]
203        /// The set of permissions that the extension requires for its base functionality.
204        #[unsafe(method(requestedPermissions))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn requestedPermissions(&self) -> Retained<NSSet<WKWebExtensionPermission>>;
207
208        #[cfg(feature = "WKWebExtensionPermission")]
209        /// The set of permissions that the extension may need for optional functionality. These permissions can be requested by the extension at a later time.
210        #[unsafe(method(optionalPermissions))]
211        #[unsafe(method_family = none)]
212        pub unsafe fn optionalPermissions(&self) -> Retained<NSSet<WKWebExtensionPermission>>;
213
214        #[cfg(feature = "WKWebExtensionMatchPattern")]
215        /// The set of websites that the extension requires access to for its base functionality.
216        #[unsafe(method(requestedPermissionMatchPatterns))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn requestedPermissionMatchPatterns(
219            &self,
220        ) -> Retained<NSSet<WKWebExtensionMatchPattern>>;
221
222        #[cfg(feature = "WKWebExtensionMatchPattern")]
223        /// The set of websites that the extension may need access to for optional functionality. These match patterns can be requested by the extension at a later time.
224        #[unsafe(method(optionalPermissionMatchPatterns))]
225        #[unsafe(method_family = none)]
226        pub unsafe fn optionalPermissionMatchPatterns(
227            &self,
228        ) -> Retained<NSSet<WKWebExtensionMatchPattern>>;
229
230        #[cfg(feature = "WKWebExtensionMatchPattern")]
231        /// The set of websites that the extension requires access to for injected content and for receiving messages from websites.
232        #[unsafe(method(allRequestedMatchPatterns))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn allRequestedMatchPatterns(
235            &self,
236        ) -> Retained<NSSet<WKWebExtensionMatchPattern>>;
237
238        /// A Boolean value indicating whether the extension has background content that can run when needed.
239        ///
240        /// If this property is `YES`, the extension can run in the background even when no webpages are open.
241        #[unsafe(method(hasBackgroundContent))]
242        #[unsafe(method_family = none)]
243        pub unsafe fn hasBackgroundContent(&self) -> bool;
244
245        /// A Boolean value indicating whether the extension has background content that stays in memory as long as the extension is loaded.
246        ///
247        /// Note: Note that extensions are only allowed to have persistent background content on macOS. An ``WKWebExtensionErrorInvalidBackgroundPersistence``
248        /// error will be reported on iOS, iPadOS, and visionOS if an attempt is made to load a persistent extension.
249        #[unsafe(method(hasPersistentBackgroundContent))]
250        #[unsafe(method_family = none)]
251        pub unsafe fn hasPersistentBackgroundContent(&self) -> bool;
252
253        /// A Boolean value indicating whether the extension has script or stylesheet content that can be injected into webpages.
254        ///
255        /// If this property is `YES`, the extension has content that can be injected by matching against the extension's requested match patterns.
256        ///
257        /// Note: Once the extension is loaded, use the ``hasInjectedContent`` property on an extension context, as the injectable content can change after the extension is loaded.
258        #[unsafe(method(hasInjectedContent))]
259        #[unsafe(method_family = none)]
260        pub unsafe fn hasInjectedContent(&self) -> bool;
261
262        /// A Boolean value indicating whether the extension has an options page.
263        ///
264        /// If this property is `YES`, the extension includes a dedicated options page where users can customize settings.
265        /// The app should provide access to this page through a user interface element, which can be accessed via ``optionsPageURL`` on an extension context.
266        #[unsafe(method(hasOptionsPage))]
267        #[unsafe(method_family = none)]
268        pub unsafe fn hasOptionsPage(&self) -> bool;
269
270        /// A Boolean value indicating whether the extension provides an alternative to the default new tab page.
271        ///
272        /// If this property is `YES`, the extension can specify a custom page that can be displayed when a new tab is opened in the app, instead of the default new tab page.
273        /// The app should prompt the user for permission to use the extension's new tab page as the default, which can be accessed via ``overrideNewTabPageURL`` on an extension context.
274        #[unsafe(method(hasOverrideNewTabPage))]
275        #[unsafe(method_family = none)]
276        pub unsafe fn hasOverrideNewTabPage(&self) -> bool;
277
278        /// A Boolean value indicating whether the extension includes commands that users can invoke.
279        ///
280        /// If this property is `YES`, the extension contains one or more commands that can be performed by the user. These commands should be accessible via keyboard shortcuts,
281        /// menu items, or other user interface elements provided by the app. The list of commands can be accessed via ``commands`` on an extension context, and invoked via ``performCommand:``.
282        #[unsafe(method(hasCommands))]
283        #[unsafe(method_family = none)]
284        pub unsafe fn hasCommands(&self) -> bool;
285
286        /// A boolean value indicating whether the extension includes rules used for content modification or blocking.
287        #[unsafe(method(hasContentModificationRules))]
288        #[unsafe(method_family = none)]
289        pub unsafe fn hasContentModificationRules(&self) -> bool;
290    );
291}