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; }
bool getRawCookies(const NetworkStorageSession& session, const KURL& /*firstParty*/, const KURL& url, Vector<Cookie>& rawCookies) { rawCookies.clear(); RetainPtr<CFURLRef> urlCF = adoptCF(url.createCFURL()); bool sendSecureCookies = url.protocolIs("https"); RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookiesForURL(session.cookieStorage().get(), 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 = cookieName(cookie).get(); String value = cookieValue(cookie).get(); String domain = cookieDomain(cookie).get(); String path = cookiePath(cookie).get(); double expires = (cookieExpirationTime(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); }
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 }
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(CFHTTPCookieStorageCopyCookiesForURL) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jboolean arg2) { jintLong rc = 0; WebKit_win32_NATIVE_ENTER(env, that, CFHTTPCookieStorageCopyCookiesForURL_FUNC); rc = (jintLong)CFHTTPCookieStorageCopyCookiesForURL((CFHTTPCookieStorageRef)arg0, (CFURLRef)arg1, (Boolean)arg2); WebKit_win32_NATIVE_EXIT(env, that, CFHTTPCookieStorageCopyCookiesForURL_FUNC); return rc; }
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); }
static RetainPtr<CFArrayRef> copyCookiesForURLWithFirstPartyURL(const NetworkStorageSession& session, const URL& firstParty, const URL& url) { bool secure = url.protocolIs("https"); #if PLATFORM(COCOA) return adoptCF(_CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(session.cookieStorage().get(), url.createCFURL().get(), firstParty.createCFURL().get(), secure)); #else // _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL is not available on other platforms. UNUSED_PARAM(firstParty); return adoptCF(CFHTTPCookieStorageCopyCookiesForURL(session.cookieStorage().get(), url.createCFURL().get(), secure)); #endif }
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); }
static bool shouldRelaxThirdPartyCookiePolicy(NetworkingContext* context, const KURL& url) { // If a URL already has cookies, then we'll relax the 3rd party cookie policy and accept new cookies. RetainPtr<CFHTTPCookieStorageRef> cfCookieStorage = currentCFHTTPCookieStorage(context); CFHTTPCookieStorageAcceptPolicy cookieAcceptPolicy = CFHTTPCookieStorageGetCookieAcceptPolicy(cfCookieStorage.get()); if (cookieAcceptPolicy != CFHTTPCookieStorageAcceptPolicyOnlyFromMainDocumentDomain) return false; RetainPtr<CFURLRef> cfURL = adoptCF(url.createCFURL()); RetainPtr<CFArrayRef> cookies = adoptCF(CFHTTPCookieStorageCopyCookiesForURL(cfCookieStorage.get(), cfURL.get(), false)); return CFArrayGetCount(cookies.get()); }
void deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& name) { RetainPtr<CFHTTPCookieStorageRef> cookieStorage = session.cookieStorage(); RetainPtr<CFURLRef> urlCF = adoptCF(url.createCFURL()); bool sendSecureCookies = url.protocolIs("https"); RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookiesForURL(cookieStorage.get(), urlCF.get(), sendSecureCookies)); CFIndex count = CFArrayGetCount(cookiesCF.get()); for (CFIndex i = 0; i < count; i++) { CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(cookiesCF.get(), i); if (String(cookieName(cookie).get()) == name) { CFHTTPCookieStorageDeleteCookie(cookieStorage.get(), cookie); break; } } }
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); if (String(cookieName(cookie).get()) == name) { CFHTTPCookieStorageDeleteCookie(cookieStorage, cookie); break; } } }