String cookies(const Document* /*document*/, const KURL& url) { CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); if (!cookieStorage) return String(); String cookieString; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool secure = equalIgnoringCase(url.protocol(), "https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(cookieStorage, urlCF.get(), secure)); // <rdar://problem/5632883> CFHTTPCookieStorage happily stores an empty cookie, which would be sent as "Cookie: =". // We have a workaround in setCookies() to prevent that, but we also need to avoid sending cookies that were previously stored. CFIndex count = CFArrayGetCount(cookiesCF.get()); RetainPtr<CFMutableArrayRef> cookiesForURLFilteredCopy(AdoptCF, CFArrayCreateMutable(0, count, &kCFTypeArrayCallBacks)); for (CFIndex i = 0; i < count; ++i) { CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(cookiesCF.get(), i); if (CFStringGetLength(CFHTTPCookieGetName(cookie)) != 0) CFArrayAppendValue(cookiesForURLFilteredCopy.get(), cookie); } RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesForURLFilteredCopy.get())); return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); }
String cookies(const KURL& url) { #if USE(CFNETWORK) CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage(); if (!defaultCookieStorage) return String(); String cookieString; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool secure = equalIgnoringCase(url.protocol(), "https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(defaultCookieStorage, urlCF.get(), secure)); RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get())); return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); #else DeprecatedString str = url.url(); str.append((UChar)'\0'); DWORD count = str.length(); InternetGetCookie((UChar*)str.unicode(), 0, 0, &count); if (count <= 1) // Null terminator counts as 1. return String(); UChar* buffer = new UChar[count]; InternetGetCookie((UChar*)str.unicode(), 0, buffer, &count); String& result = String(buffer, count-1); // Ignore the null terminator. delete[] buffer; return result; #endif }
String cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& /*firstParty*/, const KURL& url) { RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool secure = url.protocolIs("https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(session.cookieStorage().get(), urlCF.get(), secure)); RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get())); return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); }
String cookieRequestHeaderFieldValue(const Document* /*document*/, const KURL& url) { CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); if (!cookieStorage) return String(); RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool secure = url.protocolIs("https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(cookieStorage, urlCF.get(), secure)); RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get())); return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); }