Changeset 239724 in webkit
- Timestamp:
- Jan 8, 2019, 7:18:49 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r239723 r239724 1 2019-01-08 Alex Christensen <achristensen@webkit.org> 2 3 Move Windows-specific code from NetworkStorageSessionCFNet.cpp to its own file 4 https://bugs.webkit.org/show_bug.cgi?id=192958 5 6 Reviewed by Yusuke Suzuki. 7 8 This makes it easier to reason about what code is used where. 9 10 * PlatformAppleWin.cmake: 11 * platform/network/cf/NetworkStorageSessionCFNet.cpp: 12 (WebCore::createPrivateStorageSession): Deleted. 13 (WebCore::cookieDomain): Deleted. 14 (WebCore::canonicalCookieTime): Deleted. 15 (WebCore::cookieCreatedTime): Deleted. 16 (WebCore::cookieExpirationTime): Deleted. 17 (WebCore::cookieName): Deleted. 18 (WebCore::cookiePath): Deleted. 19 (WebCore::cookieValue): Deleted. 20 (WebCore::filterCookies): Deleted. 21 (WebCore::copyCookiesForURLWithFirstPartyURL): Deleted. 22 (WebCore::createCookies): Deleted. 23 (WebCore::NetworkStorageSession::setCookiesFromDOM const): Deleted. 24 (WebCore::containsSecureCookies): Deleted. 25 (WebCore::NetworkStorageSession::cookiesForDOM const): Deleted. 26 (WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const): Deleted. 27 (WebCore::NetworkStorageSession::cookiesEnabled const): Deleted. 28 (WebCore::NetworkStorageSession::getRawCookies const): Deleted. 29 (WebCore::NetworkStorageSession::deleteCookie const): Deleted. 30 (WebCore::NetworkStorageSession::getHostnamesWithCookies): Deleted. 31 (WebCore::NetworkStorageSession::deleteAllCookies): Deleted. 32 (WebCore::NetworkStorageSession::deleteCookiesForHostnames): Deleted. 33 (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince): Deleted. 34 * platform/network/cf/NetworkStorageSessionCFNetWin.cpp: Added. 35 (WebCore::createPrivateStorageSession): 36 (WebCore::NetworkStorageSession::setCookies): 37 (WebCore::cookieDomain): 38 (WebCore::canonicalCookieTime): 39 (WebCore::cookieCreatedTime): 40 (WebCore::cookieExpirationTime): 41 (WebCore::cookieName): 42 (WebCore::cookiePath): 43 (WebCore::cookieValue): 44 (WebCore::filterCookies): 45 (WebCore::copyCookiesForURLWithFirstPartyURL): 46 (WebCore::createCookies): 47 (WebCore::NetworkStorageSession::setCookiesFromDOM const): 48 (WebCore::containsSecureCookies): 49 (WebCore::NetworkStorageSession::cookiesForDOM const): 50 (WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const): 51 (WebCore::NetworkStorageSession::cookiesEnabled const): 52 (WebCore::NetworkStorageSession::getRawCookies const): 53 (WebCore::NetworkStorageSession::deleteCookie const): 54 (WebCore::NetworkStorageSession::getHostnamesWithCookies): 55 (WebCore::NetworkStorageSession::deleteAllCookies): 56 (WebCore::NetworkStorageSession::deleteCookiesForHostnames): 57 (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince): 58 1 59 2018-12-19 Antoine Quint <graouts@apple.com> 2 60 -
trunk/Source/WebCore/PlatformAppleWin.cmake
r238122 r239724 55 55 platform/network/cf/LoaderRunLoopCF.cpp 56 56 platform/network/cf/NetworkStorageSessionCFNet.cpp 57 platform/network/cf/NetworkStorageSessionCFNetWin.cpp 57 58 platform/network/cf/ProtectionSpaceCFNet.cpp 58 59 platform/network/cf/ProxyServerCFNet.cpp -
trunk/Source/WebCore/platform/network/NetworkStorageSession.h
r239427 r239724 211 211 #if PLATFORM(COCOA) 212 212 WEBCORE_EXPORT CFURLStorageSessionRef createPrivateStorageSession(CFStringRef identifier); 213 #elif USE(CFURLCONNECTION) 214 CFURLStorageSessionRef createPrivateStorageSession(CFStringRef identifier, CFURLStorageSessionRef defaultStorageSession); 213 215 #endif 214 216 -
trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
r239427 r239724 35 35 #include "PublicSuffix.h" 36 36 #include "ResourceRequest.h" 37 #endif38 #if USE(CFURLCONNECTION)39 #include "Cookie.h"40 #include "CookieRequestHeaderFieldProxy.h"41 #include "CookiesStrategy.h"42 #include "NotImplemented.h"43 #include <CFNetwork/CFHTTPCookiesPriv.h>44 #include <CoreFoundation/CoreFoundation.h>45 #include <pal/spi/cf/CFNetworkSPI.h>46 #include <windows.h>47 #include <wtf/SoftLinking.h>48 #include <wtf/URL.h>49 #include <wtf/cf/TypeCastsCF.h>50 #include <wtf/text/WTFString.h>51 52 enum {53 CFHTTPCookieStorageAcceptPolicyExclusivelyFromMainDocumentDomain = 354 };55 56 namespace WTF {57 58 #define DECLARE_CF_TYPE_TRAIT(ClassName) \59 template <> \60 struct CFTypeTrait<ClassName##Ref> { \61 static inline CFTypeID typeID() { return ClassName##GetTypeID(); } \62 };63 64 #if COMPILER(CLANG)65 ALLOW_DEPRECATED_DECLARATIONS_BEGIN66 #endif67 DECLARE_CF_TYPE_TRAIT(CFHTTPCookie);68 #if COMPILER(CLANG)69 ALLOW_DEPRECATED_DECLARATIONS_END70 #endif71 72 #undef DECLARE_CF_TYPE_TRAIT73 } // namespace WTF74 75 37 #endif 76 38 … … 131 93 return session; 132 94 } 133 134 #if !PLATFORM(COCOA)135 static CFURLStorageSessionRef createPrivateStorageSession(CFStringRef identifier, CFURLStorageSessionRef defaultStorageSession)136 {137 const void* sessionPropertyKeys[] = { _kCFURLStorageSessionIsPrivate };138 const void* sessionPropertyValues[] = { kCFBooleanTrue };139 CFDictionaryRef sessionProperties = CFDictionaryCreate(kCFAllocatorDefault, sessionPropertyKeys, sessionPropertyValues, sizeof(sessionPropertyKeys) / sizeof(*sessionPropertyKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);140 CFURLStorageSessionRef storageSession = _CFURLStorageSessionCreate(kCFAllocatorDefault, identifier, sessionProperties);141 142 // The private storage session should have the same properties as the default storage session,143 // with the exception that it should be in-memory only storage.144 CFURLCacheRef cache = _CFURLStorageSessionCopyCache(kCFAllocatorDefault, storageSession);145 CFURLCacheSetDiskCapacity(cache, 0);146 CFURLCacheRef defaultCache;147 if (defaultStorageSession)148 defaultCache = _CFURLStorageSessionCopyCache(kCFAllocatorDefault, defaultStorageSession);149 else150 defaultCache = CFURLCacheCopySharedURLCache();151 CFURLCacheSetMemoryCapacity(cache, CFURLCacheMemoryCapacity(defaultCache));152 CFRelease(defaultCache);153 CFRelease(cache);154 155 CFHTTPCookieStorageRef cookieStorage = _CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession);156 CFHTTPCookieStorageRef defaultCookieStorage;157 if (defaultStorageSession)158 defaultCookieStorage = _CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, defaultStorageSession);159 else160 defaultCookieStorage = _CFHTTPCookieStorageGetDefault(kCFAllocatorDefault);161 CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage, CFHTTPCookieStorageGetCookieAcceptPolicy(defaultCookieStorage));162 if (defaultStorageSession)163 CFRelease(defaultCookieStorage);164 CFRelease(cookieStorage);165 166 return storageSession;167 }168 #endif169 95 170 96 void NetworkStorageSession::switchToNewTestingSession() … … 255 181 } 256 182 257 #if !PLATFORM(COCOA)258 void NetworkStorageSession::setCookies(const Vector<Cookie>&, const URL&, const URL&)259 {260 // FIXME: Implement this. <https://webkit.org/b/156298>261 }262 #endif263 264 183 } // namespace WebCore 265 266 #if USE(CFURLCONNECTION)267 268 namespace WebCore {269 270 static const CFStringRef s_setCookieKeyCF = CFSTR("Set-Cookie");271 static const CFStringRef s_cookieCF = CFSTR("Cookie");272 static const CFStringRef s_createdCF = CFSTR("Created");273 274 static inline RetainPtr<CFStringRef> cookieDomain(CFHTTPCookieRef cookie)275 {276 return adoptCF(CFHTTPCookieCopyDomain(cookie));277 }278 279 static double canonicalCookieTime(double time)280 {281 if (!time)282 return time;283 284 return (time + kCFAbsoluteTimeIntervalSince1970) * 1000;285 }286 287 static double cookieCreatedTime(CFHTTPCookieRef cookie)288 {289 RetainPtr<CFDictionaryRef> props = adoptCF(CFHTTPCookieCopyProperties(cookie));290 auto value = CFDictionaryGetValue(props.get(), s_createdCF);291 292 auto asNumber = dynamic_cf_cast<CFNumberRef>(value);293 if (asNumber) {294 double asDouble;295 if (CFNumberGetValue(asNumber, kCFNumberFloat64Type, &asDouble))296 return canonicalCookieTime(asDouble);297 return 0.0;298 }299 300 auto asString = dynamic_cf_cast<CFStringRef>(value);301 if (asString)302 return canonicalCookieTime(CFStringGetDoubleValue(asString));303 304 return 0.0;305 }306 307 static inline CFAbsoluteTime cookieExpirationTime(CFHTTPCookieRef cookie)308 {309 return canonicalCookieTime(CFHTTPCookieGetExpirationTime(cookie));310 }311 312 static inline RetainPtr<CFStringRef> cookieName(CFHTTPCookieRef cookie)313 {314 return adoptCF(CFHTTPCookieCopyName(cookie));315 }316 317 static inline RetainPtr<CFStringRef> cookiePath(CFHTTPCookieRef cookie)318 {319 return adoptCF(CFHTTPCookieCopyPath(cookie));320 }321 322 static inline RetainPtr<CFStringRef> cookieValue(CFHTTPCookieRef cookie)323 {324 return adoptCF(CFHTTPCookieCopyValue(cookie));325 }326 327 static RetainPtr<CFArrayRef> filterCookies(CFArrayRef unfilteredCookies)328 {329 ASSERT(unfilteredCookies);330 CFIndex count = CFArrayGetCount(unfilteredCookies);331 RetainPtr<CFMutableArrayRef> filteredCookies = adoptCF(CFArrayCreateMutable(0, count, &kCFTypeArrayCallBacks));332 for (CFIndex i = 0; i < count; ++i) {333 CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(unfilteredCookies, i);334 335 // <rdar://problem/5632883> CFHTTPCookieStorage would store an empty cookie,336 // which would be sent as "Cookie: =". We have a workaround in setCookies() to prevent337 // that, but we also need to avoid sending cookies that were previously stored, and338 // there's no harm to doing this check because such a cookie is never valid.339 if (!CFStringGetLength(cookieName(cookie).get()))340 continue;341 342 if (CFHTTPCookieIsHTTPOnly(cookie))343 continue;344 345 CFArrayAppendValue(filteredCookies.get(), cookie);346 }347 return filteredCookies;348 }349 350 static RetainPtr<CFArrayRef> copyCookiesForURLWithFirstPartyURL(const NetworkStorageSession& session, const URL& firstParty, const URL& url, IncludeSecureCookies includeSecureCookies)351 {352 bool secure = includeSecureCookies == IncludeSecureCookies::Yes;353 354 ASSERT(!secure || (secure && url.protocolIs("https")));355 356 UNUSED_PARAM(firstParty);357 return adoptCF(CFHTTPCookieStorageCopyCookiesForURL(session.cookieStorage().get(), url.createCFURL().get(), secure));358 }359 360 static CFArrayRef createCookies(CFDictionaryRef headerFields, CFURLRef url)361 {362 CFArrayRef parsedCookies = CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault, headerFields, url);363 if (!parsedCookies)364 parsedCookies = CFArrayCreate(kCFAllocatorDefault, 0, 0, &kCFTypeArrayCallBacks);365 366 return parsedCookies;367 }368 369 void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo&, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, const String& value) const370 {371 UNUSED_PARAM(frameID);372 UNUSED_PARAM(pageID);373 // <rdar://problem/5632883> CFHTTPCookieStorage stores an empty cookie, which would be sent as "Cookie: =".374 if (value.isEmpty())375 return;376 377 RetainPtr<CFURLRef> urlCF = url.createCFURL();378 RetainPtr<CFURLRef> firstPartyForCookiesCF = firstParty.createCFURL();379 380 // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>381 // cookiesWithResponseHeaderFields doesn't parse cookies without a value382 String cookieString = value.contains('=') ? value : value + "=";383 384 RetainPtr<CFStringRef> cookieStringCF = cookieString.createCFString();385 auto cookieStringCFPtr = cookieStringCF.get();386 RetainPtr<CFDictionaryRef> headerFieldsCF = adoptCF(CFDictionaryCreate(kCFAllocatorDefault,387 (const void**)&s_setCookieKeyCF, (const void**)&cookieStringCFPtr, 1,388 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));389 390 RetainPtr<CFArrayRef> unfilteredCookies = adoptCF(createCookies(headerFieldsCF.get(), urlCF.get()));391 CFHTTPCookieStorageSetCookies(cookieStorage().get(), filterCookies(unfilteredCookies.get()).get(), urlCF.get(), firstPartyForCookiesCF.get());392 }393 394 static bool containsSecureCookies(CFArrayRef cookies)395 {396 CFIndex cookieCount = CFArrayGetCount(cookies);397 while (cookieCount--) {398 if (CFHTTPCookieIsSecure(checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookies, cookieCount))))399 return true;400 }401 402 return false;403 }404 405 std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty, const SameSiteInfo&, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const406 {407 UNUSED_PARAM(frameID);408 UNUSED_PARAM(pageID);409 RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(*this, firstParty, url, includeSecureCookies);410 411 auto filteredCookies = filterCookies(cookiesCF.get());412 413 bool didAccessSecureCookies = containsSecureCookies(filteredCookies.get());414 415 RetainPtr<CFDictionaryRef> headerCF = adoptCF(CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, filteredCookies.get()));416 String cookieString = checked_cf_cast<CFStringRef>(CFDictionaryGetValue(headerCF.get(), s_cookieCF));417 return { cookieString, didAccessSecureCookies };418 }419 420 std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo&, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const421 {422 UNUSED_PARAM(frameID);423 UNUSED_PARAM(pageID);424 RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(*this, firstParty, url, includeSecureCookies);425 426 bool didAccessSecureCookies = containsSecureCookies(cookiesCF.get());427 428 RetainPtr<CFDictionaryRef> headerCF = adoptCF(CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get()));429 String cookieString = checked_cf_cast<CFStringRef>(CFDictionaryGetValue(headerCF.get(), s_cookieCF));430 return { cookieString, didAccessSecureCookies };431 }432 433 std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const434 {435 return cookieRequestHeaderFieldValue(headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);436 }437 438 bool NetworkStorageSession::cookiesEnabled() const439 {440 CFHTTPCookieStorageAcceptPolicy policy = CFHTTPCookieStorageGetCookieAcceptPolicy(cookieStorage().get());441 return policy == CFHTTPCookieStorageAcceptPolicyOnlyFromMainDocumentDomain || policy == CFHTTPCookieStorageAcceptPolicyExclusivelyFromMainDocumentDomain || policy == CFHTTPCookieStorageAcceptPolicyAlways;442 }443 444 bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, Vector<Cookie>& rawCookies) const445 {446 UNUSED_PARAM(frameID);447 UNUSED_PARAM(pageID);448 rawCookies.clear();449 450 auto includeSecureCookies = url.protocolIs("https") ? IncludeSecureCookies::Yes : IncludeSecureCookies::No;451 452 RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(*this, firstParty, url, includeSecureCookies);453 454 CFIndex count = CFArrayGetCount(cookiesCF.get());455 rawCookies.reserveCapacity(count);456 457 for (CFIndex i = 0; i < count; i++) {458 CFHTTPCookieRef cfCookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));459 Cookie cookie;460 cookie.name = cookieName(cfCookie).get();461 cookie.value = cookieValue(cfCookie).get();462 cookie.domain = cookieDomain(cfCookie).get();463 cookie.path = cookiePath(cfCookie).get();464 cookie.created = cookieCreatedTime(cfCookie);465 cookie.expires = cookieExpirationTime(cfCookie);466 cookie.httpOnly = CFHTTPCookieIsHTTPOnly(cfCookie);467 cookie.secure = CFHTTPCookieIsSecure(cfCookie);468 cookie.session = false; // FIXME: Need API for if a cookie is a session cookie.469 rawCookies.uncheckedAppend(WTFMove(cookie));470 }471 472 return true;473 }474 475 void NetworkStorageSession::deleteCookie(const URL& url, const String& name) const476 {477 RetainPtr<CFHTTPCookieStorageRef> cookieStorage = this->cookieStorage();478 479 RetainPtr<CFURLRef> urlCF = url.createCFURL();480 481 bool sendSecureCookies = url.protocolIs("https");482 RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookiesForURL(cookieStorage.get(), urlCF.get(), sendSecureCookies));483 484 CFIndex count = CFArrayGetCount(cookiesCF.get());485 for (CFIndex i = 0; i < count; i++) {486 CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));487 if (String(cookieName(cookie).get()) == name) {488 CFHTTPCookieStorageDeleteCookie(cookieStorage.get(), cookie);489 break;490 }491 }492 }493 494 void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)495 {496 RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookies(cookieStorage().get()));497 if (!cookiesCF)498 return;499 500 CFIndex count = CFArrayGetCount(cookiesCF.get());501 for (CFIndex i = 0; i < count; ++i) {502 CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));503 RetainPtr<CFStringRef> domain = cookieDomain(cookie);504 hostnames.add(domain.get());505 }506 }507 508 void NetworkStorageSession::deleteAllCookies()509 {510 CFHTTPCookieStorageDeleteAllCookies(cookieStorage().get());511 }512 513 void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& hostnames)514 {515 }516 517 void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime)518 {519 }520 521 } // namespace WebCore522 523 #endif // USE(CFURLCONNECTION)
Note:
See TracChangeset
for help on using the changeset viewer.