diff options
Diffstat (limited to 'WebKit/android/jni/CookieManager.cpp')
-rw-r--r-- | WebKit/android/jni/CookieManager.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index b38cc3a..821d28d 100644 --- a/WebKit/android/jni/CookieManager.cpp +++ b/WebKit/android/jni/CookieManager.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "ChromiumIncludes.h" +#include "WebCookieJar.h" #include "WebRequestContext.h" #include "WebCoreJni.h" #include <JNIHelp.h> @@ -38,16 +39,7 @@ namespace android { // JNI for android.webkit.CookieManager static const char* javaCookieManagerClass = "android/webkit/CookieManager"; -// Though WebRequestContext::get() is threadsafe, the context itself, in -// general, is not. The context is generally used on the HTTP stack IO -// thread, but calls to the methods of this class are made on the UI thread. -// We ensure thread safety as follows ... -// - The cookie_store() getter just returns a pointer which is only set when the -// context is first constructed. The CookieMonster itself is threadsafe, so -// using it from the UI thread is safe. -// - Calls to the other WebRequestContext methods used here are explicitly -// threadsafe. - +// WebCookieJar is threadsafe, as is CookieMonster. static bool useChromiumHttpStack(JNIEnv*, jobject) { #if USE(CHROME_NETWORK_STACK) @@ -63,8 +55,8 @@ static bool acceptCookie(JNIEnv*, jobject) // This is a static method which gets the cookie policy for all WebViews. We // always apply the same configuration to the contexts for both regular and // private browsing, so expect the same result here. - bool regularAcceptCookies = WebRequestContext::get(false)->allowCookies(); - ASSERT(regularAcceptCookies == WebRequestContext::get(true)->allowCookies()); + bool regularAcceptCookies = WebCookieJar::get(false)->allowCookies(); + ASSERT(regularAcceptCookies == WebCookieJar::get(true)->allowCookies()); return regularAcceptCookies; #else // The Android HTTP stack is implemented Java-side. @@ -79,7 +71,7 @@ static jstring getCookie(JNIEnv* env, jobject, jstring url) GURL gurl(jstringToStdString(env, url)); CookieOptions options; options.set_include_httponly(); - std::string cookies = WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->GetCookiesWithOptions(gurl, options); + std::string cookies = WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->GetCookiesWithOptions(gurl, options); return cookies.empty() ? 0 : env->NewStringUTF(cookies.c_str()); #else // The Android HTTP stack is implemented Java-side. @@ -91,7 +83,7 @@ static jstring getCookie(JNIEnv* env, jobject, jstring url) static bool hasCookies(JNIEnv*, jobject) { #if USE(CHROME_NETWORK_STACK) - return !WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->GetAllCookies().empty(); + return !WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->GetAllCookies().empty(); #else // The Android HTTP stack is implemented Java-side. ASSERT_NOT_REACHED(); @@ -102,13 +94,13 @@ static bool hasCookies(JNIEnv*, jobject) static void removeAllCookie(JNIEnv*, jobject) { #if USE(CHROME_NETWORK_STACK) - WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true); + WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true); // This will lazily create a new private browsing context. However, if the // context doesn't already exist, there's no need to create it, as cookies // for such contexts are cleared up when we're done with them. // TODO: Consider adding an optimisation to not create the context if it // doesn't already exist. - WebRequestContext::get(true)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true); + WebCookieJar::get(true)->cookieStore()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true); #endif } @@ -116,18 +108,18 @@ 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(); + WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->GetAllCookies(); + WebCookieJar::get(true)->cookieStore()->GetCookieMonster()->GetAllCookies(); #endif } -static void removeSessionCookies(WebRequestContext* context) +static void removeSessionCookies(WebCookieJar* cookieJar) { #if USE(CHROME_NETWORK_STACK) - CookieMonster* cookieMonster = context->cookie_store()->GetCookieMonster(); + CookieMonster* cookieMonster = cookieJar->cookieStore()->GetCookieMonster(); CookieMonster::CookieList cookies = cookieMonster->GetAllCookies(); for (CookieMonster::CookieList::const_iterator iter = cookies.begin(); iter != cookies.end(); ++iter) { - if (!iter->IsPersistent()) + if (iter->IsSessionCookie()) cookieMonster->DeleteCanonicalCookie(*iter); } #endif @@ -136,8 +128,8 @@ static void removeSessionCookies(WebRequestContext* context) static void removeSessionCookie(JNIEnv*, jobject) { #if USE(CHROME_NETWORK_STACK) - removeSessionCookies(WebRequestContext::get(false)); - removeSessionCookies(WebRequestContext::get(true)); + removeSessionCookies(WebCookieJar::get(false)); + removeSessionCookies(WebCookieJar::get(true)); #endif } @@ -147,8 +139,8 @@ static void setAcceptCookie(JNIEnv*, jobject, jboolean accept) // This is a static method which configures the cookie policy for all // WebViews, so we configure the contexts for both regular and private // browsing. - WebRequestContext::get(false)->setAllowCookies(accept); - WebRequestContext::get(true)->setAllowCookies(accept); + WebCookieJar::get(false)->setAllowCookies(accept); + WebCookieJar::get(true)->setAllowCookies(accept); #endif } @@ -159,7 +151,7 @@ static void setCookie(JNIEnv* env, jobject, jstring url, jstring value) std::string line(jstringToStdString(env, value)); CookieOptions options; options.set_include_httponly(); - WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->SetCookieWithOptions(gurl, line, options); + WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->SetCookieWithOptions(gurl, line, options); #endif } |