Changeset 227077 in webkit
- Timestamp:
- Jan 17, 2018 11:35:21 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r227076 r227077 1 2018-01-17 Per Arne Vollan <pvollan@apple.com> 2 3 [Win] Use switch when converting from ResourceRequestCachePolicy to platform cache policy. 4 https://bugs.webkit.org/show_bug.cgi?id=181686 5 6 Reviewed by Alex Christensen. 7 8 No new tests, covered by existing tests. 9 10 A switch will make the function easier on the eyes. Also, use the function in places where the ResourceRequestCachePolicy 11 is just casted to a platform cache policy. 12 13 * platform/network/cf/ResourceRequestCFNet.cpp: 14 (WebCore::toPlatformRequestCachePolicy): 15 1 16 2018-01-17 John Wilander <wilander@apple.com> 2 17 -
trunk/Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp
r224267 r227077 133 133 } 134 134 135 static inline CFURLRequestCachePolicy toPlatformRequestCachePolicy(ResourceRequestCachePolicy policy) 136 { 137 switch (policy) { 138 case UseProtocolCachePolicy: 139 return kCFURLRequestCachePolicyProtocolDefault; 140 case ReturnCacheDataElseLoad: 141 return kCFURLRequestCachePolicyReturnCacheDataElseLoad; 142 case ReturnCacheDataDontLoad: 143 return kCFURLRequestCachePolicyReturnCacheDataDontLoad; 144 case ReloadIgnoringCacheData: 145 case DoNotUseAnyCache: 146 case RefreshAnyCacheData: 147 return kCFURLRequestCachePolicyReloadIgnoringCache; 148 } 149 150 ASSERT_NOT_REACHED(); 151 return kCFURLRequestCachePolicyReloadIgnoringCache; 152 } 153 135 154 void ResourceRequest::doUpdatePlatformRequest() 136 {137 CFMutableURLRequestRef cfRequest;138 139 RetainPtr<CFURLRef> url = ResourceRequest::url().createCFURL();140 RetainPtr<CFURLRef> firstPartyForCookies = ResourceRequest::firstPartyForCookies().createCFURL();141 double timeoutInterval = ResourceRequestBase::timeoutInterval() ? ResourceRequestBase::timeoutInterval() : ResourceRequestBase::defaultTimeoutInterval();142 if (m_cfRequest) {143 cfRequest = CFURLRequestCreateMutableCopy(0, m_cfRequest.get());144 CFURLRequestSetURL(cfRequest, url.get());145 CFURLRequestSetMainDocumentURL(cfRequest, firstPartyForCookies.get());146 CFURLRequestSetCachePolicy(cfRequest, (CFURLRequestCachePolicy)cachePolicy());147 CFURLRequestSetTimeoutInterval(cfRequest, timeoutInterval);148 } else149 cfRequest = CFURLRequestCreateMutable(0, url.get(), (CFURLRequestCachePolicy)cachePolicy(), timeoutInterval, firstPartyForCookies.get());150 151 CFURLRequestSetHTTPRequestMethod(cfRequest, httpMethod().createCFString().get());152 153 if (httpPipeliningEnabled())154 CFURLRequestSetShouldPipelineHTTP(cfRequest, true, true);155 156 if (resourcePrioritiesEnabled())157 CFURLRequestSetRequestPriority(cfRequest, toPlatformRequestPriority(priority()));158 159 #if !PLATFORM(WIN)160 _CFURLRequestSetProtocolProperty(cfRequest, kCFURLRequestAllowAllPOSTCaching, kCFBooleanTrue);161 #endif162 163 setHeaderFields(cfRequest, httpHeaderFields());164 165 CFURLRequestSetShouldHandleHTTPCookies(cfRequest, allowCookies());166 167 unsigned fallbackCount = m_responseContentDispositionEncodingFallbackArray.size();168 RetainPtr<CFMutableArrayRef> encodingFallbacks = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, fallbackCount, 0));169 for (unsigned i = 0; i != fallbackCount; ++i) {170 RetainPtr<CFStringRef> encodingName = m_responseContentDispositionEncodingFallbackArray[i].createCFString();171 CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding(encodingName.get());172 if (encoding != kCFStringEncodingInvalidId)173 CFArrayAppendValue(encodingFallbacks.get(), reinterpret_cast<const void*>(encoding));174 }175 setContentDispositionEncodingFallbackArray(cfRequest, encodingFallbacks.get());176 177 #if ENABLE(CACHE_PARTITIONING)178 String partition = cachePartition();179 if (!partition.isNull() && !partition.isEmpty()) {180 CString utf8String = partition.utf8();181 RetainPtr<CFStringRef> partitionValue = adoptCF(CFStringCreateWithBytes(0, reinterpret_cast<const UInt8*>(utf8String.data()), utf8String.length(), kCFStringEncodingUTF8, false));182 _CFURLRequestSetProtocolProperty(cfRequest, _kCFURLCachePartitionKey, partitionValue.get());183 }184 #endif185 186 m_cfRequest = adoptCF(cfRequest);187 #if PLATFORM(COCOA)188 clearOrUpdateNSURLRequest();189 #endif190 }191 192 // FIXME: We should use a switch based on ResourceRequestCachePolicy parameter193 static inline CFURLRequestCachePolicy toPlatformRequestCachePolicy(ResourceRequestCachePolicy policy)194 {195 return static_cast<CFURLRequestCachePolicy>((policy <= ReturnCacheDataDontLoad) ? policy : ReloadIgnoringCacheData);196 }197 198 void ResourceRequest::doUpdatePlatformHTTPBody()199 155 { 200 156 CFMutableURLRequestRef cfRequest; … … 210 166 CFURLRequestSetTimeoutInterval(cfRequest, timeoutInterval); 211 167 } else 212 cfRequest = CFURLRequestCreateMutable(0, url.get(), (CFURLRequestCachePolicy)cachePolicy(), timeoutInterval, firstPartyForCookies.get()); 168 cfRequest = CFURLRequestCreateMutable(0, url.get(), toPlatformRequestCachePolicy(cachePolicy()), timeoutInterval, firstPartyForCookies.get()); 169 170 CFURLRequestSetHTTPRequestMethod(cfRequest, httpMethod().createCFString().get()); 171 172 if (httpPipeliningEnabled()) 173 CFURLRequestSetShouldPipelineHTTP(cfRequest, true, true); 174 175 if (resourcePrioritiesEnabled()) 176 CFURLRequestSetRequestPriority(cfRequest, toPlatformRequestPriority(priority())); 177 178 #if !PLATFORM(WIN) 179 _CFURLRequestSetProtocolProperty(cfRequest, kCFURLRequestAllowAllPOSTCaching, kCFBooleanTrue); 180 #endif 181 182 setHeaderFields(cfRequest, httpHeaderFields()); 183 184 CFURLRequestSetShouldHandleHTTPCookies(cfRequest, allowCookies()); 185 186 unsigned fallbackCount = m_responseContentDispositionEncodingFallbackArray.size(); 187 RetainPtr<CFMutableArrayRef> encodingFallbacks = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, fallbackCount, 0)); 188 for (unsigned i = 0; i != fallbackCount; ++i) { 189 RetainPtr<CFStringRef> encodingName = m_responseContentDispositionEncodingFallbackArray[i].createCFString(); 190 CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding(encodingName.get()); 191 if (encoding != kCFStringEncodingInvalidId) 192 CFArrayAppendValue(encodingFallbacks.get(), reinterpret_cast<const void*>(encoding)); 193 } 194 setContentDispositionEncodingFallbackArray(cfRequest, encodingFallbacks.get()); 195 196 #if ENABLE(CACHE_PARTITIONING) 197 String partition = cachePartition(); 198 if (!partition.isNull() && !partition.isEmpty()) { 199 CString utf8String = partition.utf8(); 200 RetainPtr<CFStringRef> partitionValue = adoptCF(CFStringCreateWithBytes(0, reinterpret_cast<const UInt8*>(utf8String.data()), utf8String.length(), kCFStringEncodingUTF8, false)); 201 _CFURLRequestSetProtocolProperty(cfRequest, _kCFURLCachePartitionKey, partitionValue.get()); 202 } 203 #endif 204 205 m_cfRequest = adoptCF(cfRequest); 206 #if PLATFORM(COCOA) 207 clearOrUpdateNSURLRequest(); 208 #endif 209 } 210 211 void ResourceRequest::doUpdatePlatformHTTPBody() 212 { 213 CFMutableURLRequestRef cfRequest; 214 215 RetainPtr<CFURLRef> url = ResourceRequest::url().createCFURL(); 216 RetainPtr<CFURLRef> firstPartyForCookies = ResourceRequest::firstPartyForCookies().createCFURL(); 217 double timeoutInterval = ResourceRequestBase::timeoutInterval() ? ResourceRequestBase::timeoutInterval() : ResourceRequestBase::defaultTimeoutInterval(); 218 if (m_cfRequest) { 219 cfRequest = CFURLRequestCreateMutableCopy(0, m_cfRequest.get()); 220 CFURLRequestSetURL(cfRequest, url.get()); 221 CFURLRequestSetMainDocumentURL(cfRequest, firstPartyForCookies.get()); 222 CFURLRequestSetCachePolicy(cfRequest, toPlatformRequestCachePolicy(cachePolicy())); 223 CFURLRequestSetTimeoutInterval(cfRequest, timeoutInterval); 224 } else 225 cfRequest = CFURLRequestCreateMutable(0, url.get(), toPlatformRequestCachePolicy(cachePolicy()), timeoutInterval, firstPartyForCookies.get()); 213 226 214 227 FormData* formData = httpBody();
Note: See TracChangeset
for help on using the changeset viewer.