diff options
| author | Steve Block <steveblock@google.com> | 2010-10-27 12:29:18 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-10-27 12:29:18 -0700 |
| commit | 91c4d4fb8652d4a7d01e3f7d6f578eb18c5b97ff (patch) | |
| tree | 83f22df5d626a524473006e07b0f44d3964efeee /WebKit/android/jni | |
| parent | 7a1cdbe26e28fbeb8a8a9f82e855c4e48b58bcdc (diff) | |
| parent | 1dddc338abb68784365d3608c5372d1b6a203706 (diff) | |
| download | external_webkit-91c4d4fb8652d4a7d01e3f7d6f578eb18c5b97ff.zip external_webkit-91c4d4fb8652d4a7d01e3f7d6f578eb18c5b97ff.tar.gz external_webkit-91c4d4fb8652d4a7d01e3f7d6f578eb18c5b97ff.tar.bz2 | |
Merge "Hook up CookieManager.getCookie() for Chromium HTTP stack"
Diffstat (limited to 'WebKit/android/jni')
| -rw-r--r-- | WebKit/android/jni/CookieManager.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index e1e139e..154dc5d 100644 --- a/WebKit/android/jni/CookieManager.cpp +++ b/WebKit/android/jni/CookieManager.cpp @@ -27,16 +27,29 @@ #include "ChromiumIncludes.h" #include "WebRequestContext.h" +#include "WebCoreJni.h" #include <JNIHelp.h> using namespace base; +using namespace net; namespace android { // JNI for android.webkit.CookieManager static const char* javaCookieManagerClass = "android/webkit/CookieManager"; -static bool useChromiumHttpStack(JNIEnv*, jobject) { +// 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. + +static bool useChromiumHttpStack(JNIEnv*, jobject) +{ #if USE(CHROME_NETWORK_STACK) return true; #else @@ -44,7 +57,8 @@ static bool useChromiumHttpStack(JNIEnv*, jobject) { #endif } -static bool acceptCookie(JNIEnv*, jobject) { +static bool acceptCookie(JNIEnv*, jobject) +{ #if USE(CHROME_NETWORK_STACK) // 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 @@ -59,14 +73,22 @@ static bool acceptCookie(JNIEnv*, jobject) { #endif } -static void removeAllCookie(JNIEnv*, jobject) { +static jstring getCookie(JNIEnv* env, jobject, jstring url) +{ +#if USE(CHROME_NETWORK_STACK) + GURL gurl(jstringToStdString(env, url)); + std::string cookies = WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->GetCookiesWithOptions(gurl, CookieOptions()); + return env->NewStringUTF(cookies.c_str()); +#else + // The Android HTTP stack is implemented Java-side. + ASSERT_NOT_REACHED(); + return jstring(); +#endif +} + +static void removeAllCookie(JNIEnv*, jobject) +{ #if USE(CHROME_NETWORK_STACK) - // Though WebRequestContext::get() is threadsafe, the context itself, in - // general, is not. The context is generally used on the HTTP stack IO - // thread, but this call is on the UI thread. However, the cookie_store() - // getter just returns a pointer which is only set when the context is first - // constructed. The CookieMonster is threadsafe, so the call below is safe - // overall. WebRequestContext::get(false)->cookie_store()->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 @@ -77,7 +99,8 @@ static void removeAllCookie(JNIEnv*, jobject) { #endif } -static void setAcceptCookie(JNIEnv*, jobject, jboolean accept) { +static void setAcceptCookie(JNIEnv*, jobject, jboolean accept) +{ #if USE(CHROME_NETWORK_STACK) // This is a static method which configures the cookie policy for all // WebViews, so we configure the contexts for both regular and private @@ -90,6 +113,7 @@ static void setAcceptCookie(JNIEnv*, jobject, jboolean accept) { static JNINativeMethod gCookieManagerMethods[] = { { "nativeUseChromiumHttpStack", "()Z", (void*) useChromiumHttpStack }, { "nativeAcceptCookie", "()Z", (void*) acceptCookie }, + { "nativeGetCookie", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getCookie }, { "nativeRemoveAllCookie", "()V", (void*) removeAllCookie }, { "nativeSetAcceptCookie", "(Z)V", (void*) setAcceptCookie }, }; |
