void setCookies(Document* document, const KURL& url, const String& value) { // <rdar://problem/5632883> CFHTTPCookieStorage stores an empty cookie, which would be sent as "Cookie: =". if (value.isEmpty()) return; CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); if (!cookieStorage) return; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); RetainPtr<CFURLRef> firstPartyForCookiesCF(AdoptCF, document->firstPartyForCookies().createCFURL()); // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034> // cookiesWithResponseHeaderFields doesn't parse cookies without a value String cookieString = value.contains('=') ? value : value + "="; RetainPtr<CFStringRef> cookieStringCF(AdoptCF, cookieString.createCFString()); RetainPtr<CFDictionaryRef> headerFieldsCF(AdoptCF, CFDictionaryCreate(kCFAllocatorDefault, (const void**)&s_setCookieKeyCF, (const void**)&cookieStringCF, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault, headerFieldsCF.get(), urlCF.get())); CFHTTPCookieStorageSetCookies(cookieStorage, filterCookies(cookiesCF.get()).get(), urlCF.get(), firstPartyForCookiesCF.get()); }
void setCookies(const KURL& url, const KURL& policyURL, const String& value) { #if USE(CFNETWORK) CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage(); if (!defaultCookieStorage) return; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); RetainPtr<CFURLRef> policyURLCF(AdoptCF, policyURL.createCFURL()); // <http://bugzilla.opendarwin.org/show_bug.cgi?id=6531>, <rdar://4409034> // cookiesWithResponseHeaderFields doesn't parse cookies without a value String cookieString = value.contains('=') ? value : value + "="; RetainPtr<CFStringRef> cookieStringCF(AdoptCF, cookieString.createCFString()); RetainPtr<CFDictionaryRef> headerFieldsCF(AdoptCF, CFDictionaryCreate(kCFAllocatorDefault, (const void**)&s_setCookieKeyCF, (const void**)&cookieStringCF, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault, headerFieldsCF.get(), urlCF.get())); CFHTTPCookieStorageSetCookies(defaultCookieStorage, cookiesCF.get(), urlCF.get(), policyURLCF.get()); #else // FIXME: Deal with the policy URL. DeprecatedString str = url.url(); str.append((UChar)'\0'); DeprecatedString val = value.deprecatedString(); val.append((UChar)'\0'); InternetSetCookie((UChar*)str.unicode(), 0, (UChar*)val.unicode()); #endif }