e062fed259a830c90bff6ad74638996ac13d088e
[WebKit-https.git] / Source / WebCore / platform / spi / cf / CFNetworkSPI.h
1 /*
2  * Copyright (C) 2014 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 #ifndef CFNetworkSPI_h
27 #define CFNetworkSPI_h
28
29 #include "CFNetworkConnectionCacheSPI.h"
30 #include <CFNetwork/CFNetwork.h>
31
32 #if PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
33
34 #include <CFNetwork/CFHTTPCookiesPriv.h>
35 #include <CFNetwork/CFProxySupportPriv.h>
36 #include <CFNetwork/CFURLCachePriv.h>
37 #include <CFNetwork/CFURLConnectionPriv.h>
38 #include <CFNetwork/CFURLCredentialStorage.h>
39 #include <CFNetwork/CFURLProtocolPriv.h>
40 #include <CFNetwork/CFURLRequestPriv.h>
41 #include <CFNetwork/CFURLResponsePriv.h>
42 #include <CFNetwork/CFURLStorageSession.h>
43
44 // FIXME: Remove the defined(__OBJC__)-guard once we fix <rdar://problem/19033610>.
45 #if defined(__OBJC__) && PLATFORM(COCOA)
46 // FIXME: As a workaround for <rdar://problem/18337182>, we conditionally enclose the header
47 // in an extern "C" linkage block to make it suitable for C++ use.
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 #import <CFNetwork/CFNSURLConnection.h>
53
54 #ifdef __cplusplus
55 }
56 #endif
57 #endif // defined(__OBJC__) && PLATFORM(COCOA)
58
59 #else // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
60
61 typedef CF_ENUM(int64_t, _TimingDataOptions)
62 {
63     _TimingDataOptionsEnableW3CNavigationTiming = (1 << 0)
64 };
65
66 typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
67 typedef const struct _CFURLCache* CFURLCacheRef;
68 typedef const struct _CFURLCredential* CFURLCredentialRef;
69 typedef const struct _CFURLRequest* CFURLRequestRef;
70 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
71 typedef const struct __CFData* CFDataRef;
72 typedef const struct OpaqueCFHTTPCookie* CFHTTPCookieRef;
73 typedef struct _CFURLConnection* CFURLConnectionRef;
74 typedef struct _CFURLCredentialStorage* CFURLCredentialStorageRef;
75 typedef struct _CFURLProtectionSpace* CFURLProtectionSpaceRef;
76 typedef struct _CFURLRequest* CFMutableURLRequestRef;
77 typedef struct _CFURLResponse* CFURLResponseRef;
78 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
79 typedef CFIndex CFURLRequestPriority;
80 typedef int CFHTTPCookieStorageAcceptPolicy;
81
82 #ifdef __BLOCKS__
83 typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
84 #endif
85
86 #if defined(__OBJC__)
87 @interface NSURLRequest ()
88 - (void)_setProperty:(id)value forKey:(NSString *)key;
89 @end
90
91 @interface NSURLResponse ()
92 + (NSURLResponse *)_responseWithCFURLResponse:(CFURLResponseRef)response;
93 - (CFURLResponseRef)_CFURLResponse;
94 - (NSDate *)_lastModifiedDate;
95 @end
96
97 @interface NSURLSessionTask (TimingData)
98 - (NSDictionary *)_timingData;
99 @end
100
101 @interface NSHTTPCookie ()
102 - (CFHTTPCookieRef)_CFHTTPCookie;
103 @end
104
105 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000)
106 @interface NSURLSessionConfiguration ()
107 @property (assign) _TimingDataOptions _timingDataOptions;
108 @property (copy) NSData *_sourceApplicationAuditTokenData;
109 @property (copy) NSString *_sourceApplicationBundleIdentifier;
110 @end
111 #endif
112
113 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000)
114 @interface NSHTTPCookie ()
115 @property (nullable, readonly, copy) NSString *_storagePartition;
116 @end
117
118 @interface NSHTTPCookieStorage ()
119 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
120 @end
121
122 @interface NSURLSessionTask ()
123 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
124 @property (copy) NSString *_storagePartitionIdentifier;
125 @end
126 #endif
127
128 #endif // defined(__OBJC__)
129
130 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
131
132 EXTERN_C void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
133
134 EXTERN_C CFURLCacheRef CFURLCacheCopySharedURLCache();
135 EXTERN_C void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
136 #if PLATFORM(COCOA)
137 EXTERN_C Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
138 EXTERN_C void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
139 #endif
140
141 EXTERN_C void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
142
143 #if PLATFORM(COCOA)
144 EXTERN_C CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
145 #ifdef __BLOCKS__
146 EXTERN_C void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
147 #endif
148 #endif // PLATFORM(COCOA)
149
150 EXTERN_C void CFURLConnectionInvalidateConnectionCache();
151
152 EXTERN_C CFStringRef const kCFHTTPCookieLocalFileDomain;
153 EXTERN_C const CFStringRef kCFURLRequestAllowAllPOSTCaching;
154
155 #if !PLATFORM(WIN)
156 EXTERN_C const CFStringRef _kCFURLConnectionPropertyShouldSniff;
157 #endif
158
159 EXTERN_C CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
160 EXTERN_C void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
161 EXTERN_C void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
162 EXTERN_C void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
163 EXTERN_C CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
164 EXTERN_C CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
165 EXTERN_C CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
166 EXTERN_C void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
167 EXTERN_C void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
168 EXTERN_C void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
169 EXTERN_C void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
170 EXTERN_C CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
171 EXTERN_C CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
172 EXTERN_C CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
173 EXTERN_C CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
174 EXTERN_C CFURLRef CFURLResponseGetURL(CFURLResponseRef);
175 EXTERN_C void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
176 EXTERN_C CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
177
178 // FIXME: We should only forward declare this SPI when building for iOS without the Apple Internal SDK.
179 // As a workaround for <rdar://problem/19025016>, we must forward declare this SPI regardless of whether
180 // we are building with the Apple Internal SDK.
181 #if defined(__OBJC__) && PLATFORM(IOS)
182 @interface NSURLCache ()
183 -(id)_initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity relativePath:(NSString *)path;
184 @end
185 #endif
186
187 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
188 enum : NSUInteger {
189     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
190 };
191
192 @interface NSCachedURLResponse ()
193 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
194 -(CFCachedURLResponseRef)_CFCachedURLResponse;
195 @end
196 #endif
197
198 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
199 EXTERN_C CFDataRef _CFNetworkCopyATSContext(void);
200 EXTERN_C Boolean _CFNetworkSetATSContext(CFDataRef);
201 #endif
202
203 #if PLATFORM(COCOA)
204 EXTERN_C void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
205 #endif
206
207 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
208 EXTERN_C CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
209 EXTERN_C CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
210 EXTERN_C CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
211 #endif
212
213 #if defined(__OBJC__)
214
215 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
216 @interface NSHTTPCookie ()
217 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
218 @end
219 #endif
220
221 #if !USE(APPLE_INTERNAL_SDK)
222 @interface NSHTTPCookieStorage ()
223 - (void)removeCookiesSinceDate:(NSDate *)date;
224 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
225 - (CFHTTPCookieStorageRef)_cookieStorage;
226 - (void)_saveCookies;
227 @end
228 #endif
229
230 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
231 #if TARGET_OS_IPHONE || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
232 @interface NSHTTPCookieStorage ()
233 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
234 @end
235 #endif
236 #endif // defined(__OBJC__)
237
238 #endif // CFNetworkSPI_h