Fix CMake build.
[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 >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
124 @interface NSURLSessionTaskTransactionMetrics ()
125 @property (copy, readonly) NSString* _remoteAddressAndPort;
126 @property (copy, readonly) NSUUID* _connectionIdentifier;
127 @end
128 #endif
129
130 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000)
131 @interface NSHTTPCookie ()
132 @property (nullable, readonly, copy) NSString *_storagePartition;
133 @end
134
135 @interface NSHTTPCookieStorage ()
136 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
137 @end
138
139 @interface NSURLSessionTask ()
140 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
141 @property (copy) NSString *_storagePartitionIdentifier;
142 @end
143 #endif
144
145 #endif // defined(__OBJC__)
146
147 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
148
149 WTF_EXTERN_C_BEGIN
150
151 #if !PLATFORM(WIN)
152 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
153
154 CFURLCacheRef CFURLCacheCopySharedURLCache();
155 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
156 #if PLATFORM(COCOA)
157 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
158 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
159 #endif
160
161 void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
162
163 #if PLATFORM(COCOA)
164 CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
165 #ifdef __BLOCKS__
166 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
167 #endif
168 #endif // PLATFORM(COCOA)
169
170 extern CFStringRef const kCFHTTPCookieLocalFileDomain;
171 extern const CFStringRef kCFHTTPVersion1_1;
172 extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
173 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
174
175 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
176 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
177 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
178 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
179 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
180 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
181 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
182 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
183 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
184 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
185 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
186 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
187 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
188 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
189 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
190 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
191 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
192 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
193 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
194 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
195 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
196 CFTypeID CFURLResponseGetTypeID();
197 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
198 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
199 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
200
201 #endif // !PLATFORM(WIN)
202
203 WTF_EXTERN_C_END
204
205 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
206 enum : NSUInteger {
207     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
208 };
209
210 @interface NSCachedURLResponse ()
211 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
212 -(CFCachedURLResponseRef)_CFCachedURLResponse;
213 @end
214 #endif
215
216 WTF_EXTERN_C_BEGIN
217
218 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
219 CFDataRef _CFNetworkCopyATSContext(void);
220 Boolean _CFNetworkSetATSContext(CFDataRef);
221 #endif
222
223 #if PLATFORM(COCOA)
224 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
225 #endif
226
227 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
228 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
229 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
230 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
231 #endif
232
233 WTF_EXTERN_C_END
234
235 #if defined(__OBJC__)
236
237 @interface NSHTTPCookie ()
238 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
239 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
240 #endif
241 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
242 @end
243
244 #if !USE(APPLE_INTERNAL_SDK)
245 @interface NSHTTPCookieStorage ()
246 - (void)removeCookiesSinceDate:(NSDate *)date;
247 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
248 - (CFHTTPCookieStorageRef)_cookieStorage;
249 - (void)_saveCookies;
250 @end
251 #endif
252
253 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
254 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
255 @interface NSHTTPCookieStorage ()
256 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
257 @end
258 #endif
259 #endif // defined(__OBJC__)
260
261 #endif // CFNetworkSPI_h