961a4dd9d9338caf30c23901444aa8bb3f8eefbd
[WebKit-https.git] / Source / WebCore / platform / spi / cf / CFNetworkSPI.h
1 /*
2  * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma clang system_header
27
28 #ifndef CFNetworkSPI_h
29 #define CFNetworkSPI_h
30
31 #include "CFNetworkConnectionCacheSPI.h"
32 #include <CFNetwork/CFNetwork.h>
33
34 #if PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
35
36 #include <CFNetwork/CFHTTPCookiesPriv.h>
37 #include <CFNetwork/CFProxySupportPriv.h>
38 #include <CFNetwork/CFURLCachePriv.h>
39 #include <CFNetwork/CFURLConnectionPriv.h>
40 #include <CFNetwork/CFURLCredentialStorage.h>
41 #include <CFNetwork/CFURLProtocolPriv.h>
42 #include <CFNetwork/CFURLRequestPriv.h>
43 #include <CFNetwork/CFURLResponsePriv.h>
44 #include <CFNetwork/CFURLStorageSession.h>
45
46 // FIXME: Remove the defined(__OBJC__)-guard once we fix <rdar://problem/19033610>.
47 #if defined(__OBJC__) && PLATFORM(COCOA)
48 #import <CFNetwork/CFNSURLConnection.h>
49 #endif // defined(__OBJC__) && PLATFORM(COCOA)
50
51 #else // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
52
53 typedef CF_ENUM(int64_t, _TimingDataOptions)
54 {
55     _TimingDataOptionsEnableW3CNavigationTiming = (1 << 0)
56 };
57
58 enum CFURLCacheStoragePolicy {
59     kCFURLCacheStorageAllowed = 0,
60     kCFURLCacheStorageAllowedInMemoryOnly = 1,
61     kCFURLCacheStorageNotAllowed = 2
62 };
63 typedef enum CFURLCacheStoragePolicy CFURLCacheStoragePolicy;
64
65 typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
66 typedef const struct _CFURLCache* CFURLCacheRef;
67 typedef const struct _CFURLCredential* CFURLCredentialRef;
68 typedef const struct _CFURLRequest* CFURLRequestRef;
69 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
70 typedef const struct __CFData* CFDataRef;
71 typedef const struct OpaqueCFHTTPCookie* CFHTTPCookieRef;
72 typedef struct _CFURLConnection* CFURLConnectionRef;
73 typedef struct _CFURLCredentialStorage* CFURLCredentialStorageRef;
74 typedef struct _CFURLProtectionSpace* CFURLProtectionSpaceRef;
75 typedef struct _CFURLRequest* CFMutableURLRequestRef;
76 typedef struct _CFURLResponse* CFURLResponseRef;
77 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
78 typedef CFIndex CFURLRequestPriority;
79 typedef int CFHTTPCookieStorageAcceptPolicy;
80
81 #ifdef __BLOCKS__
82 typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
83 #endif
84
85 #if defined(__OBJC__)
86 @interface NSURLCache ()
87 -(instancetype)_initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity relativePath:(NSString *)path;
88 - (CFURLCacheRef)_CFURLCache;
89 @end
90
91 @interface NSURLRequest ()
92 + (NSArray *)allowsSpecificHTTPSCertificateForHost:(NSString *)host;
93 + (void)setAllowsSpecificHTTPSCertificate:(NSArray *)allow forHost:(NSString *)host;
94 - (void)_setProperty:(id)value forKey:(NSString *)key;
95 @end
96
97 @interface NSURLResponse ()
98 + (NSURLResponse *)_responseWithCFURLResponse:(CFURLResponseRef)response;
99 - (CFURLResponseRef)_CFURLResponse;
100 - (NSDate *)_lastModifiedDate;
101 @end
102
103 @interface NSURLSessionTask (TimingData)
104 - (NSDictionary *)_timingData;
105 @end
106
107 @interface NSHTTPCookie ()
108 - (CFHTTPCookieRef)_CFHTTPCookie;
109 @end
110
111 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000)
112 @interface NSURLSessionConfiguration ()
113 @property (assign) _TimingDataOptions _timingDataOptions;
114 @property (copy) NSData *_sourceApplicationAuditTokenData;
115 @property (nullable, copy) NSString *_sourceApplicationBundleIdentifier;
116 @property (nullable, copy) NSString *_sourceApplicationSecondaryIdentifier;
117 #if PLATFORM(IOS)
118 @property (nullable, copy) NSString *_CTDataConnectionServiceType;
119 #endif
120 @end
121 #endif
122
123 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000)
124 @interface NSHTTPCookie ()
125 @property (nullable, readonly, copy) NSString *_storagePartition;
126 @end
127
128 @interface NSHTTPCookieStorage ()
129 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
130 @end
131
132 @interface NSURLSessionTask ()
133 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
134 @property (copy) NSString *_storagePartitionIdentifier;
135 @end
136 #endif
137
138 #endif // defined(__OBJC__)
139
140 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
141
142 WTF_EXTERN_C_BEGIN
143
144 #if !PLATFORM(WIN)
145 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
146
147 CFURLCacheRef CFURLCacheCopySharedURLCache();
148 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
149 #if PLATFORM(COCOA)
150 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
151 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
152 #endif
153
154 void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
155
156 #if PLATFORM(COCOA)
157 CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
158 #ifdef __BLOCKS__
159 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
160 #endif
161 #endif // PLATFORM(COCOA)
162
163 extern CFStringRef const kCFHTTPCookieLocalFileDomain;
164 extern const CFStringRef kCFHTTPVersion1_1;
165 extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
166 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
167
168 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
169 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
170 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
171 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
172 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
173 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
174 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
175 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
176 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
177 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
178 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
179 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
180 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
181 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
182 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
183 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
184 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
185 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
186 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
187 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
188 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
189 CFTypeID CFURLResponseGetTypeID();
190 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
191 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
192 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
193
194 #endif // !PLATFORM(WIN)
195
196 WTF_EXTERN_C_END
197
198 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
199 enum : NSUInteger {
200     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
201 };
202
203 @interface NSCachedURLResponse ()
204 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
205 -(CFCachedURLResponseRef)_CFCachedURLResponse;
206 @end
207 #endif
208
209 WTF_EXTERN_C_BEGIN
210
211 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
212 CFDataRef _CFNetworkCopyATSContext(void);
213 Boolean _CFNetworkSetATSContext(CFDataRef);
214 #endif
215
216 #if PLATFORM(COCOA)
217 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
218 #endif
219
220 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
221 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
222 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
223 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
224 #endif
225
226 WTF_EXTERN_C_END
227
228 #if defined(__OBJC__)
229
230 @interface NSHTTPCookie ()
231 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
232 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
233 #endif
234 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
235 @end
236
237 #if !USE(APPLE_INTERNAL_SDK)
238 @interface NSHTTPCookieStorage ()
239 - (void)removeCookiesSinceDate:(NSDate *)date;
240 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
241 - (CFHTTPCookieStorageRef)_cookieStorage;
242 - (void)_saveCookies;
243 @end
244 #endif
245
246 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
247 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
248 @interface NSHTTPCookieStorage ()
249 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
250 @end
251 #endif
252 #endif // defined(__OBJC__)
253
254 #endif // CFNetworkSPI_h