objc2_foundation/generated/NSHTTPCookieStorage.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
7use crate::*;
8
9/// Values for the different cookie accept policies
10///
11///
12///
13/// only from the main document domain
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpcookieacceptpolicy?language=objc)
16// NS_ENUM
17#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct NSHTTPCookieAcceptPolicy(pub NSUInteger);
20impl NSHTTPCookieAcceptPolicy {
21 #[doc(alias = "NSHTTPCookieAcceptPolicyAlways")]
22 pub const Always: Self = Self(0);
23 #[doc(alias = "NSHTTPCookieAcceptPolicyNever")]
24 pub const Never: Self = Self(1);
25 #[doc(alias = "NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain")]
26 pub const OnlyFromMainDocumentDomain: Self = Self(2);
27}
28
29unsafe impl Encode for NSHTTPCookieAcceptPolicy {
30 const ENCODING: Encoding = NSUInteger::ENCODING;
31}
32
33unsafe impl RefEncode for NSHTTPCookieAcceptPolicy {
34 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
35}
36
37extern_class!(
38 /// NSHTTPCookieStorage implements a singleton object (shared
39 /// instance) which manages the shared cookie store. It has methods
40 /// to allow clients to set and remove cookies, and get the current
41 /// set of cookies. It also has convenience methods to parse and
42 /// generate cookie-related HTTP header fields.
43 ///
44 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpcookiestorage?language=objc)
45 #[unsafe(super(NSObject))]
46 #[derive(Debug, PartialEq, Eq, Hash)]
47 pub struct NSHTTPCookieStorage;
48);
49
50unsafe impl Send for NSHTTPCookieStorage {}
51
52unsafe impl Sync for NSHTTPCookieStorage {}
53
54unsafe impl NSObjectProtocol for NSHTTPCookieStorage {}
55
56impl NSHTTPCookieStorage {
57 extern_methods!(
58 /// Get the shared cookie storage in the default location.
59 ///
60 /// Returns: The shared cookie storage
61 ///
62 /// Starting in OS X 10.11, each app has its own sharedHTTPCookieStorage singleton,
63 /// which will not be shared with other applications.
64 #[unsafe(method(sharedHTTPCookieStorage))]
65 #[unsafe(method_family = none)]
66 pub unsafe fn sharedHTTPCookieStorage() -> Retained<NSHTTPCookieStorage>;
67
68 #[cfg(feature = "NSString")]
69 /// Get the cookie storage for the container associated with the specified application group identifier
70 ///
71 /// Parameter `identifier`: The application group identifier
72 ///
73 /// Returns: A cookie storage with a persistent store in the application group container
74 ///
75 /// By default, applications and associated app extensions have different data containers, which means
76 /// that the sharedHTTPCookieStorage singleton will refer to different persistent cookie stores in an application and
77 /// any app extensions that it contains. This method allows clients to create a persistent cookie storage that can be
78 /// shared among all applications and extensions with access to the same application group. Subsequent calls to this
79 /// method with the same identifier will return the same cookie storage instance.
80 #[unsafe(method(sharedCookieStorageForGroupContainerIdentifier:))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn sharedCookieStorageForGroupContainerIdentifier(
83 identifier: &NSString,
84 ) -> Retained<NSHTTPCookieStorage>;
85
86 #[cfg(all(feature = "NSArray", feature = "NSHTTPCookie"))]
87 /// Get all the cookies
88 ///
89 /// Returns: An NSArray of NSHTTPCookies
90 #[unsafe(method(cookies))]
91 #[unsafe(method_family = none)]
92 pub unsafe fn cookies(&self) -> Option<Retained<NSArray<NSHTTPCookie>>>;
93
94 #[cfg(feature = "NSHTTPCookie")]
95 /// Set a cookie
96 ///
97 /// The cookie will override an existing cookie with the
98 /// same name, domain and path, if any.
99 #[unsafe(method(setCookie:))]
100 #[unsafe(method_family = none)]
101 pub unsafe fn setCookie(&self, cookie: &NSHTTPCookie);
102
103 #[cfg(feature = "NSHTTPCookie")]
104 /// Delete the specified cookie
105 #[unsafe(method(deleteCookie:))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn deleteCookie(&self, cookie: &NSHTTPCookie);
108
109 #[cfg(feature = "NSDate")]
110 /// Delete all cookies from the cookie storage since the provided date.
111 #[unsafe(method(removeCookiesSinceDate:))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn removeCookiesSinceDate(&self, date: &NSDate);
114
115 #[cfg(all(feature = "NSArray", feature = "NSHTTPCookie", feature = "NSURL"))]
116 /// Returns an array of cookies to send to the given URL.
117 ///
118 /// Parameter `URL`: The URL for which to get cookies.
119 ///
120 /// Returns: an NSArray of NSHTTPCookie objects.
121 ///
122 /// The cookie manager examines the cookies it stores and
123 /// includes those which should be sent to the given URL. You can use
124 /// <tt>
125 /// +[NSCookie requestHeaderFieldsWithCookies:]
126 /// </tt>
127 /// to turn this array
128 /// into a set of header fields to add to a request.
129 #[unsafe(method(cookiesForURL:))]
130 #[unsafe(method_family = none)]
131 pub unsafe fn cookiesForURL(&self, url: &NSURL) -> Option<Retained<NSArray<NSHTTPCookie>>>;
132
133 #[cfg(all(feature = "NSArray", feature = "NSHTTPCookie", feature = "NSURL"))]
134 /// Adds an array cookies to the cookie store, following the
135 /// cookie accept policy.
136 ///
137 /// Parameter `cookies`: The cookies to set.
138 ///
139 /// Parameter `URL`: The URL from which the cookies were sent.
140 ///
141 /// Parameter `mainDocumentURL`: The main document URL to be used as a base for the "same
142 /// domain as main document" policy.
143 ///
144 /// For mainDocumentURL, the caller should pass the URL for
145 /// an appropriate main document, if known. For example, when loading
146 /// a web page, the URL of the main html document for the top-level
147 /// frame should be passed. To save cookies based on a set of response
148 /// headers, you can use
149 /// <tt>
150 /// +[NSCookie
151 /// cookiesWithResponseHeaderFields:forURL:]
152 /// </tt>
153 /// on a header field
154 /// dictionary and then use this method to store the resulting cookies
155 /// in accordance with policy settings.
156 #[unsafe(method(setCookies:forURL:mainDocumentURL:))]
157 #[unsafe(method_family = none)]
158 pub unsafe fn setCookies_forURL_mainDocumentURL(
159 &self,
160 cookies: &NSArray<NSHTTPCookie>,
161 url: Option<&NSURL>,
162 main_document_url: Option<&NSURL>,
163 );
164
165 /// The cookie accept policy preference of the
166 /// receiver.
167 #[unsafe(method(cookieAcceptPolicy))]
168 #[unsafe(method_family = none)]
169 pub unsafe fn cookieAcceptPolicy(&self) -> NSHTTPCookieAcceptPolicy;
170
171 /// Setter for [`cookieAcceptPolicy`][Self::cookieAcceptPolicy].
172 #[unsafe(method(setCookieAcceptPolicy:))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn setCookieAcceptPolicy(&self, cookie_accept_policy: NSHTTPCookieAcceptPolicy);
175
176 #[cfg(all(
177 feature = "NSArray",
178 feature = "NSHTTPCookie",
179 feature = "NSSortDescriptor"
180 ))]
181 /// Returns an array of all cookies in the store, sorted according to the key value and sorting direction of the NSSortDescriptors specified in the parameter.
182 ///
183 /// Parameter `sortOrder`: an array of NSSortDescriptors which represent the preferred sort order of the resulting array.
184 ///
185 /// proper sorting of cookies may require extensive string conversion, which can be avoided by allowing the system to perform the sorting. This API is to be preferred over the more generic -[NSHTTPCookieStorage cookies] API, if sorting is going to be performed.
186 #[unsafe(method(sortedCookiesUsingDescriptors:))]
187 #[unsafe(method_family = none)]
188 pub unsafe fn sortedCookiesUsingDescriptors(
189 &self,
190 sort_order: &NSArray<NSSortDescriptor>,
191 ) -> Retained<NSArray<NSHTTPCookie>>;
192 );
193}
194
195/// Methods declared on superclass `NSObject`.
196impl NSHTTPCookieStorage {
197 extern_methods!(
198 #[unsafe(method(init))]
199 #[unsafe(method_family = init)]
200 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
201
202 #[unsafe(method(new))]
203 #[unsafe(method_family = new)]
204 pub unsafe fn new() -> Retained<Self>;
205 );
206}
207
208/// NSURLSessionTaskAdditions.
209impl NSHTTPCookieStorage {
210 extern_methods!(
211 #[cfg(all(
212 feature = "NSArray",
213 feature = "NSHTTPCookie",
214 feature = "NSURLSession"
215 ))]
216 #[unsafe(method(storeCookies:forTask:))]
217 #[unsafe(method_family = none)]
218 pub unsafe fn storeCookies_forTask(
219 &self,
220 cookies: &NSArray<NSHTTPCookie>,
221 task: &NSURLSessionTask,
222 );
223
224 #[cfg(all(
225 feature = "NSArray",
226 feature = "NSHTTPCookie",
227 feature = "NSURLSession",
228 feature = "block2"
229 ))]
230 #[unsafe(method(getCookiesForTask:completionHandler:))]
231 #[unsafe(method_family = none)]
232 pub unsafe fn getCookiesForTask_completionHandler(
233 &self,
234 task: &NSURLSessionTask,
235 completion_handler: &block2::Block<dyn Fn(*mut NSArray<NSHTTPCookie>)>,
236 );
237 );
238}
239
240extern "C" {
241 /// Name of notification that should be posted to the
242 /// distributed notification center whenever the accept cookies
243 /// preference is changed
244 ///
245 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpcookiemanageracceptpolicychangednotification?language=objc)
246 #[cfg(all(feature = "NSNotification", feature = "NSString"))]
247 pub static NSHTTPCookieManagerAcceptPolicyChangedNotification: &'static NSNotificationName;
248}
249
250extern "C" {
251 /// Notification sent when the set of cookies changes
252 ///
253 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpcookiemanagercookieschangednotification?language=objc)
254 #[cfg(all(feature = "NSNotification", feature = "NSString"))]
255 pub static NSHTTPCookieManagerCookiesChangedNotification: &'static NSNotificationName;
256}