bool getRawCookies(const Document*, const KURL& url, Vector<Cookie>& rawCookies) { rawCookies.clear(); CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); if (!cookieStorage) return false; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool sendSecureCookies = url.protocolIs("https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(cookieStorage, urlCF.get(), sendSecureCookies)); CFIndex count = CFArrayGetCount(cookiesCF.get()); rawCookies.reserveCapacity(count); for (CFIndex i = 0; i < count; i++) { CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(cookiesCF.get(), i); String name = CFHTTPCookieGetName(cookie); String value = CFHTTPCookieGetValue(cookie); String domain = CFHTTPCookieGetDomain(cookie); String path = CFHTTPCookieGetPath(cookie); double expires = (CFDateGetAbsoluteTime(CFHTTPCookieGetExpiratonDate(cookie)) + kCFAbsoluteTimeIntervalSince1970) * 1000; bool httpOnly = CFHTTPCookieIsHTTPOnly(cookie); bool secure = CFHTTPCookieIsSecure(cookie); bool session = false; // FIXME: Need API for if a cookie is a session cookie. rawCookies.uncheckedAppend(Cookie(name, value, domain, path, expires, httpOnly, secure, session)); } return true; }
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); }
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(CFHTTPCookieGetName) (JNIEnv *env, jclass that, jintLong arg0) { jintLong rc = 0; WebKit_win32_NATIVE_ENTER(env, that, CFHTTPCookieGetName_FUNC); rc = (jintLong)CFHTTPCookieGetName((CFHTTPCookieRef)arg0); WebKit_win32_NATIVE_EXIT(env, that, CFHTTPCookieGetName_FUNC); return rc; }
static RetainPtr<CFArrayRef> filterCookies(CFArrayRef unfilteredCookies) { CFIndex count = CFArrayGetCount(unfilteredCookies); RetainPtr<CFMutableArrayRef> filteredCookies(AdoptCF, CFArrayCreateMutable(0, count, &kCFTypeArrayCallBacks)); for (CFIndex i = 0; i < count; ++i) { CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(unfilteredCookies, i); // <rdar://problem/5632883> CFHTTPCookieStorage would store 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, and // there's no harm to doing this check because such a cookie is never valid. if (!CFStringGetLength(CFHTTPCookieGetName(cookie))) continue; if (CFHTTPCookieIsHTTPOnly(cookie)) continue; CFArrayAppendValue(filteredCookies.get(), cookie); } return filteredCookies; }
void deleteCookie(const Document*, const KURL& url, const String& name) { CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); if (!cookieStorage) return; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool sendSecureCookies = url.protocolIs("https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(cookieStorage, urlCF.get(), sendSecureCookies)); CFIndex count = CFArrayGetCount(cookiesCF.get()); for (CFIndex i = 0; i < count; i++) { CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(cookiesCF.get(), i); String cookieName = CFHTTPCookieGetName(cookie); if (cookieName == name) { CFHTTPCookieStorageDeleteCookie(cookieStorage, cookie); break; } } }