objc2_web_kit/generated/
WKWebExtensionMatchPattern.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 "C" {
11    /// Indicates a ``WKWebExtensionMatchPattern`` error.
12    ///
13    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionmatchpatternerrordomain?language=objc)
14    pub static WKWebExtensionMatchPatternErrorDomain: &'static NSErrorDomain;
15}
16
17/// Constants used by ``NSError`` to indicate errors in the ``WKWebExtensionMatchPattern`` domain.
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionmatchpatternerror?language=objc)
20// NS_ERROR_ENUM
21#[repr(transparent)]
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
23pub struct WKWebExtensionMatchPatternError(pub NSInteger);
24impl WKWebExtensionMatchPatternError {
25    #[doc(alias = "WKWebExtensionMatchPatternErrorUnknown")]
26    pub const Unknown: Self = Self(1);
27    #[doc(alias = "WKWebExtensionMatchPatternErrorInvalidScheme")]
28    pub const InvalidScheme: Self = Self(2);
29    #[doc(alias = "WKWebExtensionMatchPatternErrorInvalidHost")]
30    pub const InvalidHost: Self = Self(3);
31    #[doc(alias = "WKWebExtensionMatchPatternErrorInvalidPath")]
32    pub const InvalidPath: Self = Self(4);
33}
34
35unsafe impl Encode for WKWebExtensionMatchPatternError {
36    const ENCODING: Encoding = NSInteger::ENCODING;
37}
38
39unsafe impl RefEncode for WKWebExtensionMatchPatternError {
40    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
41}
42
43/// Constants used by ``WKWebExtensionMatchPattern`` to indicate matching options.
44///
45/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionmatchpatternoptions?language=objc)
46// NS_OPTIONS
47#[repr(transparent)]
48#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
49pub struct WKWebExtensionMatchPatternOptions(pub NSUInteger);
50bitflags::bitflags! {
51    impl WKWebExtensionMatchPatternOptions: NSUInteger {
52        #[doc(alias = "WKWebExtensionMatchPatternOptionsNone")]
53        const None = 0;
54        #[doc(alias = "WKWebExtensionMatchPatternOptionsIgnoreSchemes")]
55        const IgnoreSchemes = 1<<0;
56        #[doc(alias = "WKWebExtensionMatchPatternOptionsIgnorePaths")]
57        const IgnorePaths = 1<<1;
58        #[doc(alias = "WKWebExtensionMatchPatternOptionsMatchBidirectionally")]
59        const MatchBidirectionally = 1<<2;
60    }
61}
62
63unsafe impl Encode for WKWebExtensionMatchPatternOptions {
64    const ENCODING: Encoding = NSUInteger::ENCODING;
65}
66
67unsafe impl RefEncode for WKWebExtensionMatchPatternOptions {
68    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
69}
70
71extern_class!(
72    /// A ``WKWebExtensionMatchPattern`` object represents a way to specify groups of URLs.
73    ///
74    /// All match patterns are specified as strings. Apart from the special `
75    /// <all
76    /// _urls>` pattern, match patterns
77    /// consist of three parts: scheme, host, and path.
78    ///
79    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkwebextensionmatchpattern?language=objc)
80    #[unsafe(super(NSObject))]
81    #[thread_kind = MainThreadOnly]
82    #[derive(Debug, PartialEq, Eq, Hash)]
83    pub struct WKWebExtensionMatchPattern;
84);
85
86extern_conformance!(
87    unsafe impl NSCoding for WKWebExtensionMatchPattern {}
88);
89
90extern_conformance!(
91    unsafe impl NSCopying for WKWebExtensionMatchPattern {}
92);
93
94unsafe impl CopyingHelper for WKWebExtensionMatchPattern {
95    type Result = Self;
96}
97
98extern_conformance!(
99    unsafe impl NSObjectProtocol for WKWebExtensionMatchPattern {}
100);
101
102extern_conformance!(
103    unsafe impl NSSecureCoding for WKWebExtensionMatchPattern {}
104);
105
106impl WKWebExtensionMatchPattern {
107    extern_methods!(
108        #[unsafe(method(new))]
109        #[unsafe(method_family = new)]
110        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
111
112        #[unsafe(method(init))]
113        #[unsafe(method_family = init)]
114        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
115
116        /// Registers a custom URL scheme that can be used in match patterns.
117        ///
118        /// This method should be used to register any custom URL schemes used by the app for the extension base URLs,
119        /// other than `webkit-extension`, or if extensions should have access to other supported URL schemes when using `
120        /// <all
121        /// _urls>`.
122        ///
123        /// Parameter `urlScheme`: The custom URL scheme to register.
124        #[unsafe(method(registerCustomURLScheme:))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn registerCustomURLScheme(url_scheme: &NSString, mtm: MainThreadMarker);
127
128        /// Returns a pattern object for `
129        /// <all
130        /// _urls>`.
131        #[unsafe(method(allURLsMatchPattern))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn allURLsMatchPattern(mtm: MainThreadMarker) -> Retained<Self>;
134
135        /// Returns a pattern object that has `*` for scheme, host, and path.
136        #[unsafe(method(allHostsAndSchemesMatchPattern))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn allHostsAndSchemesMatchPattern(mtm: MainThreadMarker) -> Retained<Self>;
139
140        /// Returns a pattern object for the specified pattern string.
141        ///
142        /// Returns: Returns `nil` if the pattern string is invalid.
143        ///
144        /// See also: initWithString:error:
145        #[unsafe(method(matchPatternWithString:))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn matchPatternWithString(
148            string: &NSString,
149            mtm: MainThreadMarker,
150        ) -> Option<Retained<Self>>;
151
152        /// Returns a pattern object for the specified scheme, host, and path strings.
153        ///
154        /// Returns: A pattern object, or `nil` if any of the strings are invalid.
155        ///
156        /// See also: initWithScheme:host:path:error:
157        #[unsafe(method(matchPatternWithScheme:host:path:))]
158        #[unsafe(method_family = none)]
159        pub unsafe fn matchPatternWithScheme_host_path(
160            scheme: &NSString,
161            host: &NSString,
162            path: &NSString,
163            mtm: MainThreadMarker,
164        ) -> Option<Retained<Self>>;
165
166        /// Returns a pattern object for the specified pattern string.
167        ///
168        /// Parameter `error`: Set to
169        /// `nil`or an error instance if an error occurred.
170        ///
171        /// Returns: A pattern object, or `nil` if the pattern string is invalid and an error will be set.
172        ///
173        /// See also: initWithString:
174        #[unsafe(method(initWithString:error:_))]
175        #[unsafe(method_family = init)]
176        pub unsafe fn initWithString_error(
177            this: Allocated<Self>,
178            string: &NSString,
179        ) -> Result<Retained<Self>, Retained<NSError>>;
180
181        /// Returns a pattern object for the specified scheme, host, and path strings.
182        ///
183        /// Parameter `error`: Set to
184        /// `nil`or an error instance if an error occurred.
185        ///
186        /// Returns: A pattern object, or `nil` if any of the strings are invalid and an error will be set.
187        ///
188        /// See also: initWithScheme:host:path:
189        #[unsafe(method(initWithScheme:host:path:error:_))]
190        #[unsafe(method_family = init)]
191        pub unsafe fn initWithScheme_host_path_error(
192            this: Allocated<Self>,
193            scheme: &NSString,
194            host: &NSString,
195            path: &NSString,
196        ) -> Result<Retained<Self>, Retained<NSError>>;
197
198        /// The original pattern string.
199        #[unsafe(method(string))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn string(&self) -> Retained<NSString>;
202
203        /// The scheme part of the pattern string, unless ``matchesAllURLs`` is `YES`.
204        #[unsafe(method(scheme))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn scheme(&self) -> Option<Retained<NSString>>;
207
208        /// The host part of the pattern string, unless ``matchesAllURLs`` is `YES`.
209        #[unsafe(method(host))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn host(&self) -> Option<Retained<NSString>>;
212
213        /// The path part of the pattern string, unless ``matchesAllURLs`` is `YES`.
214        #[unsafe(method(path))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn path(&self) -> Option<Retained<NSString>>;
217
218        /// If the pattern is `
219        /// <all
220        /// _urls>`.
221        #[unsafe(method(matchesAllURLs))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn matchesAllURLs(&self) -> bool;
224
225        /// If the pattern is `
226        /// <all
227        /// _urls>` or has `*` as the host.
228        #[unsafe(method(matchesAllHosts))]
229        #[unsafe(method_family = none)]
230        pub unsafe fn matchesAllHosts(&self) -> bool;
231
232        /// Matches the reciever pattern against the specified URL.
233        ///
234        /// Parameter `url`: The URL to match the against the reciever pattern.
235        ///
236        /// Returns: A Boolean value indicating if pattern matches the specified URL.
237        ///
238        /// See also: matchesURL:options:
239        #[unsafe(method(matchesURL:))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn matchesURL(&self, url: Option<&NSURL>) -> bool;
242
243        /// Matches the reciever pattern against the specified URL with options.
244        ///
245        /// Parameter `url`: The URL to match the against the reciever pattern.
246        ///
247        /// Parameter `options`: The options to use while matching.
248        ///
249        /// Returns: A Boolean value indicating if pattern matches the specified URL.
250        ///
251        /// See also: matchesURL:
252        #[unsafe(method(matchesURL:options:))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn matchesURL_options(
255            &self,
256            url: Option<&NSURL>,
257            options: WKWebExtensionMatchPatternOptions,
258        ) -> bool;
259
260        /// Matches the receiver pattern against the specified pattern.
261        ///
262        /// Parameter `pattern`: The pattern to match against the receiver pattern.
263        ///
264        /// Returns: A Boolean value indicating if receiver pattern matches the specified pattern.
265        ///
266        /// See also: matchesPattern:options:
267        #[unsafe(method(matchesPattern:))]
268        #[unsafe(method_family = none)]
269        pub unsafe fn matchesPattern(&self, pattern: Option<&WKWebExtensionMatchPattern>) -> bool;
270
271        /// Matches the receiver pattern against the specified pattern with options.
272        ///
273        /// Parameter `pattern`: The pattern to match against the receiver pattern.
274        ///
275        /// Parameter `options`: The options to use while matching.
276        ///
277        /// Returns: A Boolean value indicating if receiver pattern matches the specified pattern.
278        ///
279        /// See also: matchesPattern:
280        #[unsafe(method(matchesPattern:options:))]
281        #[unsafe(method_family = none)]
282        pub unsafe fn matchesPattern_options(
283            &self,
284            pattern: Option<&WKWebExtensionMatchPattern>,
285            options: WKWebExtensionMatchPatternOptions,
286        ) -> bool;
287    );
288}