diff options
author | Steve Block <steveblock@google.com> | 2010-10-28 15:35:47 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-10-29 14:24:46 +0100 |
commit | 126a2dcc3b8ba5809023675c7ec4dfd97e9e9bb1 (patch) | |
tree | 65107b9a49534bc22632f35df13b7c0c29e6263d /WebKit/android/jni/CookieManager.cpp | |
parent | e7a75b7848b8ad8fa825770872bbc4c2c0726b65 (diff) | |
download | external_webkit-126a2dcc3b8ba5809023675c7ec4dfd97e9e9bb1.zip external_webkit-126a2dcc3b8ba5809023675c7ec4dfd97e9e9bb1.tar.gz external_webkit-126a2dcc3b8ba5809023675c7ec4dfd97e9e9bb1.tar.bz2 |
Hook up remaining CookieManager methods
hasCookies(), removeExpiredCookie(), removeSessionCookie() and setCookie()
Requires a change to frameworks/base ...
https://android-git.corp.google.com/g/76898
Bug: 3116410
Change-Id: I6b881465f78e090ed29b215785c4018119ccc5d8
Diffstat (limited to 'WebKit/android/jni/CookieManager.cpp')
-rw-r--r-- | WebKit/android/jni/CookieManager.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index f686b7f..3264458 100644 --- a/WebKit/android/jni/CookieManager.cpp +++ b/WebKit/android/jni/CookieManager.cpp @@ -88,6 +88,17 @@ static jstring getCookie(JNIEnv* env, jobject, jstring url) #endif } +static bool hasCookies(JNIEnv*, jobject) +{ +#if USE(CHROME_NETWORK_STACK) + return !WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->GetAllCookies().empty(); +#else + // The Android HTTP stack is implemented Java-side. + ASSERT_NOT_REACHED(); + return false; +#endif +} + static void removeAllCookie(JNIEnv*, jobject) { #if USE(CHROME_NETWORK_STACK) @@ -101,6 +112,35 @@ static void removeAllCookie(JNIEnv*, jobject) #endif } +static void removeExpiredCookie(JNIEnv*, jobject) +{ +#if USE(CHROME_NETWORK_STACK) + // This simply forces a GC. The getters delete expired cookies so won't return expired cookies anyway. + WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->GetAllCookies(); + WebRequestContext::get(true)->cookie_store()->GetCookieMonster()->GetAllCookies(); +#endif +} + +static void removeSessionCookies(WebRequestContext* context) +{ +#if USE(CHROME_NETWORK_STACK) + CookieMonster* cookieMonster = context->cookie_store()->GetCookieMonster(); + CookieMonster::CookieList cookies = cookieMonster->GetAllCookies(); + for (CookieMonster::CookieList::const_iterator iter = cookies.begin(); iter != cookies.end(); ++iter) { + if (!iter->IsPersistent()) + cookieMonster->DeleteCanonicalCookie(*iter); + } +#endif +} + +static void removeSessionCookie(JNIEnv*, jobject) +{ +#if USE(CHROME_NETWORK_STACK) + removeSessionCookies(WebRequestContext::get(false)); + removeSessionCookies(WebRequestContext::get(true)); +#endif +} + static void setAcceptCookie(JNIEnv*, jobject, jboolean accept) { #if USE(CHROME_NETWORK_STACK) @@ -112,12 +152,27 @@ static void setAcceptCookie(JNIEnv*, jobject, jboolean accept) #endif } +static void setCookie(JNIEnv* env, jobject, jstring url, jstring value) +{ +#if USE(CHROME_NETWORK_STACK) + GURL gurl(jstringToStdString(env, url)); + std::string line(jstringToStdString(env, value)); + CookieOptions options; + options.set_include_httponly(); + WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->SetCookieWithOptions(gurl, line, options); +#endif +} + static JNINativeMethod gCookieManagerMethods[] = { { "nativeUseChromiumHttpStack", "()Z", (void*) useChromiumHttpStack }, { "nativeAcceptCookie", "()Z", (void*) acceptCookie }, { "nativeGetCookie", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getCookie }, + { "nativeHasCookies", "()Z", (void*) hasCookies }, { "nativeRemoveAllCookie", "()V", (void*) removeAllCookie }, + { "nativeRemoveExpiredCookie", "()V", (void*) removeExpiredCookie }, + { "nativeRemoveSessionCookie", "()V", (void*) removeSessionCookie }, { "nativeSetAcceptCookie", "(Z)V", (void*) setAcceptCookie }, + { "nativeSetCookie", "(Ljava/lang/String;Ljava/lang/String;)V", (void*) setCookie }, }; int registerCookieManager(JNIEnv* env) |