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
54extern_conformance!(
55    unsafe impl NSObjectProtocol for NSHTTPCookieStorage {}
56);
57
58impl NSHTTPCookieStorage {
59    extern_methods!(
60        /// Get the shared cookie storage in the default location.
61        ///
62        /// Returns: The shared cookie storage
63        ///
64        /// Starting in OS X 10.11, each app has its own sharedHTTPCookieStorage singleton,
65        /// which will not be shared with other applications.
66        #[unsafe(method(sharedHTTPCookieStorage))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn sharedHTTPCookieStorage() -> Retained<NSHTTPCookieStorage>;
69
70        #[cfg(feature = "NSString")]
71        /// Get the cookie storage for the container associated with the specified application group identifier
72        ///
73        /// Parameter `identifier`: The application group identifier
74        ///
75        /// Returns: A cookie storage with a persistent store in the application group container
76        ///
77        /// By default, applications and associated app extensions have different data containers, which means
78        /// that the sharedHTTPCookieStorage singleton will refer to different persistent cookie stores in an application and
79        /// any app extensions that it contains. This method allows clients to create a persistent cookie storage that can be
80        /// shared among all applications and extensions with access to the same application group. Subsequent calls to this
81        /// method with the same identifier will return the same cookie storage instance.
82        #[unsafe(method(sharedCookieStorageForGroupContainerIdentifier:))]
83        #[unsafe(method_family = none)]
84        pub unsafe fn sharedCookieStorageForGroupContainerIdentifier(
85            identifier: &NSString,
86        ) -> Retained<NSHTTPCookieStorage>;
87
88        #[cfg(all(feature = "NSArray", feature = "NSHTTPCookie"))]
89        /// Get all the cookies
90        ///
91        /// Returns: An NSArray of NSHTTPCookies
92        #[unsafe(method(cookies))]
93        #[unsafe(method_family = none)]
94        pub unsafe fn cookies(&self) -> Option<Retained<NSArray<NSHTTPCookie>>>;
95
96        #[cfg(feature = "NSHTTPCookie")]
97        /// Set a cookie
98        ///
99        /// The cookie will override an existing cookie with the
100        /// same name, domain and path, if any.
101        #[unsafe(method(setCookie:))]
102        #[unsafe(method_family = none)]
103        pub unsafe fn setCookie(&self, cookie: &NSHTTPCookie);
104
105        #[cfg(feature = "NSHTTPCookie")]
106        /// Delete the specified cookie
107        #[unsafe(method(deleteCookie:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn deleteCookie(&self, cookie: &NSHTTPCookie);
110
111        #[cfg(feature = "NSDate")]
112        /// Delete all cookies from the cookie storage since the provided date.
113        #[unsafe(method(removeCookiesSinceDate:))]
114        #[unsafe(method_family = none)]
115        pub unsafe fn removeCookiesSinceDate(&self, date: &NSDate);
116
117        #[cfg(all(feature = "NSArray", feature = "NSHTTPCookie", feature = "NSURL"))]
118        /// Returns an array of cookies to send to the given URL.
119        ///
120        /// Parameter `URL`: The URL for which to get cookies.
121        ///
122        /// Returns: an NSArray of NSHTTPCookie objects.
123        ///
124        /// The cookie manager examines the cookies it stores and
125        /// includes those which should be sent to the given URL. You can use
126        /// <tt>
127        /// +[NSCookie requestHeaderFieldsWithCookies:]
128        /// </tt>
129        /// to turn this array
130        /// into a set of header fields to add to a request.
131        #[unsafe(method(cookiesForURL:))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn cookiesForURL(&self, url: &NSURL) -> Option<Retained<NSArray<NSHTTPCookie>>>;
134
135        #[cfg(all(feature = "NSArray", feature = "NSHTTPCookie", feature = "NSURL"))]
136        /// Adds an array cookies to the cookie store, following the
137        /// cookie accept policy.
138        ///
139        /// Parameter `cookies`: The cookies to set.
140        ///
141        /// Parameter `URL`: The URL from which the cookies were sent.
142        ///
143        /// Parameter `mainDocumentURL`: The main document URL to be used as a base for the "same
144        /// domain as main document" policy.
145        ///
146        /// For mainDocumentURL, the caller should pass the URL for
147        /// an appropriate main document, if known. For example, when loading
148        /// a web page, the URL of the main html document for the top-level
149        /// frame should be passed. To save cookies based on a set of response
150        /// headers, you can use
151        /// <tt>
152        /// +[NSCookie
153        /// cookiesWithResponseHeaderFields:forURL:]
154        /// </tt>
155        /// on a header field
156        /// dictionary and then use this method to store the resulting cookies
157        /// in accordance with policy settings.
158        #[unsafe(method(setCookies:forURL:mainDocumentURL:))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn setCookies_forURL_mainDocumentURL(
161            &self,
162            cookies: &NSArray<NSHTTPCookie>,
163            url: Option<&NSURL>,
164            main_document_url: Option<&NSURL>,
165        );
166
167        /// The cookie accept policy preference of the
168        /// receiver.
169        #[unsafe(method(cookieAcceptPolicy))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn cookieAcceptPolicy(&self) -> NSHTTPCookieAcceptPolicy;
172
173        /// Setter for [`cookieAcceptPolicy`][Self::cookieAcceptPolicy].
174        #[unsafe(method(setCookieAcceptPolicy:))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn setCookieAcceptPolicy(&self, cookie_accept_policy: NSHTTPCookieAcceptPolicy);
177
178        #[cfg(all(
179            feature = "NSArray",
180            feature = "NSHTTPCookie",
181            feature = "NSSortDescriptor"
182        ))]
183        /// 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.
184        ///
185        /// Parameter `sortOrder`: an array of NSSortDescriptors which represent the preferred sort order of the resulting array.
186        ///
187        /// 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.
188        #[unsafe(method(sortedCookiesUsingDescriptors:))]
189        #[unsafe(method_family = none)]
190        pub unsafe fn sortedCookiesUsingDescriptors(
191            &self,
192            sort_order: &NSArray<NSSortDescriptor>,
193        ) -> Retained<NSArray<NSHTTPCookie>>;
194    );
195}
196
197/// Methods declared on superclass `NSObject`.
198impl NSHTTPCookieStorage {
199    extern_methods!(
200        #[unsafe(method(init))]
201        #[unsafe(method_family = init)]
202        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
203
204        #[unsafe(method(new))]
205        #[unsafe(method_family = new)]
206        pub unsafe fn new() -> Retained<Self>;
207    );
208}
209
210/// NSURLSessionTaskAdditions.
211impl NSHTTPCookieStorage {
212    extern_methods!(
213        #[cfg(all(
214            feature = "NSArray",
215            feature = "NSHTTPCookie",
216            feature = "NSURLSession"
217        ))]
218        #[unsafe(method(storeCookies:forTask:))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn storeCookies_forTask(
221            &self,
222            cookies: &NSArray<NSHTTPCookie>,
223            task: &NSURLSessionTask,
224        );
225
226        #[cfg(all(
227            feature = "NSArray",
228            feature = "NSHTTPCookie",
229            feature = "NSURLSession",
230            feature = "block2"
231        ))]
232        #[unsafe(method(getCookiesForTask:completionHandler:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn getCookiesForTask_completionHandler(
235            &self,
236            task: &NSURLSessionTask,
237            completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<NSHTTPCookie>)>,
238        );
239    );
240}
241
242extern "C" {
243    /// Name of notification that should be posted to the
244    /// distributed notification center whenever the accept cookies
245    /// preference is changed
246    ///
247    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpcookiemanageracceptpolicychangednotification?language=objc)
248    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
249    pub static NSHTTPCookieManagerAcceptPolicyChangedNotification: &'static NSNotificationName;
250}
251
252extern "C" {
253    /// Notification sent when the set of cookies changes
254    ///
255    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpcookiemanagercookieschangednotification?language=objc)
256    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
257    pub static NSHTTPCookieManagerCookiesChangedNotification: &'static NSNotificationName;
258}