diff options
author | Steve Block <steveblock@google.com> | 2011-02-10 13:59:04 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-02-10 13:59:04 -0800 |
commit | b4c101d6c944ea6a1a0aad52c354c281f6cdcb4a (patch) | |
tree | a661370b95b046322714c1d65708e7f966dd2bdd | |
parent | c2b6a2ab53dae1fbb596bfbfe520f80960ddc34d (diff) | |
parent | 571670f6c01cdf0e24a55c840bee7e8f6e7e9b36 (diff) | |
download | external_webkit-b4c101d6c944ea6a1a0aad52c354c281f6cdcb4a.zip external_webkit-b4c101d6c944ea6a1a0aad52c354c281f6cdcb4a.tar.gz external_webkit-b4c101d6c944ea6a1a0aad52c354c281f6cdcb4a.tar.bz2 |
Merge "Do not accept cookies for file scheme URLs by default"
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCookieJar.cpp | 27 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCookieJar.h | 6 | ||||
-rw-r--r-- | WebKit/android/jni/CookieManager.cpp | 21 |
3 files changed, 51 insertions, 3 deletions
diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.cpp b/WebKit/android/WebCoreSupport/WebCookieJar.cpp index d290b5a..9c1d7fa 100644 --- a/WebKit/android/WebCoreSupport/WebCookieJar.cpp +++ b/WebKit/android/WebCoreSupport/WebCookieJar.cpp @@ -37,6 +37,8 @@ namespace android { static WTF::Mutex instanceMutex; +static bool isFirstInstanceCreated = false; +static bool fileSchemeCookiesEnabled = false; static const std::string& databaseDirectory() { @@ -99,6 +101,9 @@ scoped_refptr<WebCookieJar>* instance(bool isPrivateBrowsing) WebCookieJar* WebCookieJar::get(bool isPrivateBrowsing) { MutexLocker lock(instanceMutex); + if (!isFirstInstanceCreated && fileSchemeCookiesEnabled) + net::CookieMonster::EnableFileScheme(); + isFirstInstanceCreated = true; scoped_refptr<WebCookieJar>* instancePtr = instance(isPrivateBrowsing); if (!instancePtr->get()) *instancePtr = new WebCookieJar(databaseDirectory(isPrivateBrowsing)); @@ -117,9 +122,6 @@ void WebCookieJar::cleanup(bool isPrivateBrowsing) WebCookieJar::WebCookieJar(const std::string& databaseFilePath) : m_allowCookies(true) { - // This is needed for the page cycler. See http://b/2944150 - net::CookieMonster::EnableFileScheme(); - // Setup the permissions for the file const char* cDatabasePath = databaseFilePath.c_str(); mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; @@ -130,6 +132,7 @@ WebCookieJar::WebCookieJar(const std::string& databaseFilePath) if (fd >= 0) close(fd); } + FilePath cookiePath(databaseFilePath.c_str()); m_cookieDb = new SQLitePersistentCookieStore(cookiePath); m_cookieStore = new net::CookieMonster(m_cookieDb.get(), 0); @@ -227,4 +230,22 @@ void WebCookieJar::flush() semaphore->Wait(2); } +bool WebCookieJar::acceptFileSchemeCookies() +{ + MutexLocker lock(instanceMutex); + return fileSchemeCookiesEnabled; +} + +void WebCookieJar::setAcceptFileSchemeCookies(bool accept) +{ + // The Chromium HTTP stack only reflects changes to this flag when creating + // a new CookieMonster instance. While we could track whether any + // CookieMonster instances currently exist, this would be complicated and is + // not required, so we only allow this flag to be changed before the first + // instance is created. + MutexLocker lock(instanceMutex); + if (!isFirstInstanceCreated) + fileSchemeCookiesEnabled = accept; +} + } diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.h b/WebKit/android/WebCoreSupport/WebCookieJar.h index 2f32e1a..1f4266c 100644 --- a/WebKit/android/WebCoreSupport/WebCookieJar.h +++ b/WebKit/android/WebCoreSupport/WebCookieJar.h @@ -49,6 +49,12 @@ public: bool allowCookies(); void setAllowCookies(bool allow); + // Getter and setter for whether we accept cookies for file scheme URLS. + // Defaults to false. Note that calls to the setter are ignored once the + // first instance of this class has been created. + static bool acceptFileSchemeCookies(); + static void setAcceptFileSchemeCookies(bool); + // Instead of this it would probably be better to add the cookie methods // here so the rest of WebKit doesn't have to know about Chromium classes net::CookieStore* cookieStore() { return m_cookieStore.get(); } diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index 87c7fa8..a9c68fd 100644 --- a/WebKit/android/jni/CookieManager.cpp +++ b/WebKit/android/jni/CookieManager.cpp @@ -155,6 +155,25 @@ static void flushCookieStore(JNIEnv*, jobject) #endif } +static bool acceptFileSchemeCookies(JNIEnv*, jobject) +{ +#if USE(CHROME_NETWORK_STACK) + return WebCookieJar::acceptFileSchemeCookies(); +#else + // File scheme cookies are always accepted with the Android HTTP stack. + return true; +#endif +} + +static void setAcceptFileSchemeCookies(JNIEnv*, jobject, jboolean accept) +{ +#if USE(CHROME_NETWORK_STACK) + WebCookieJar::setAcceptFileSchemeCookies(accept); +#else + // File scheme cookies are always accepted with the Android HTTP stack. +#endif +} + static JNINativeMethod gCookieManagerMethods[] = { { "nativeAcceptCookie", "()Z", (void*) acceptCookie }, { "nativeGetCookie", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getCookie }, @@ -165,6 +184,8 @@ static JNINativeMethod gCookieManagerMethods[] = { { "nativeSetAcceptCookie", "(Z)V", (void*) setAcceptCookie }, { "nativeSetCookie", "(Ljava/lang/String;Ljava/lang/String;)V", (void*) setCookie }, { "nativeFlushCookieStore", "()V", (void*) flushCookieStore }, + { "nativeAcceptFileSchemeCookies", "()Z", (void*) acceptFileSchemeCookies }, + { "nativeSetAcceptFileSchemeCookies", "(Z)V", (void*) setAcceptFileSchemeCookies }, }; int registerCookieManager(JNIEnv* env) |