summaryrefslogtreecommitdiffstats
path: root/WebKit
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-12-06 10:43:52 +0000
committerIain Merrick <husky@google.com>2010-12-06 16:09:54 +0000
commitc65c296d5bbf1608aedeceac90179a261deb0368 (patch)
treee9178ab9aaf50ba7472a89708e5cb7e9c1921fd9 /WebKit
parentb552bd9285b27da2142b3078a06bdfe022a59410 (diff)
downloadexternal_webkit-c65c296d5bbf1608aedeceac90179a261deb0368.zip
external_webkit-c65c296d5bbf1608aedeceac90179a261deb0368.tar.gz
external_webkit-c65c296d5bbf1608aedeceac90179a261deb0368.tar.bz2
Fix CookieManager.hasCookies().
To pass the CTS test, this method needs to check the persistent database directly, ignoring any cookies that are only stored in memory. Depends on change Id498d281 in external/chromium, which adds the GetCookieCount() method. Change-Id: Ibeceaaa9942b5f4f1160fc2eeeca8b2322169a90
Diffstat (limited to 'WebKit')
-rw-r--r--WebKit/android/WebCoreSupport/WebCookieJar.cpp9
-rw-r--r--WebKit/android/WebCoreSupport/WebCookieJar.h5
-rw-r--r--WebKit/android/jni/CookieManager.cpp6
3 files changed, 17 insertions, 3 deletions
diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.cpp b/WebKit/android/WebCoreSupport/WebCookieJar.cpp
index 6a81ff1..afa87c2 100644
--- a/WebKit/android/WebCoreSupport/WebCookieJar.cpp
+++ b/WebKit/android/WebCoreSupport/WebCookieJar.cpp
@@ -95,8 +95,8 @@ WebCookieJar::WebCookieJar(const std::string& databaseFilePath)
net::CookieMonster::EnableFileScheme();
FilePath cookiePath(databaseFilePath.c_str());
- scoped_refptr<SQLitePersistentCookieStore> cookieDb = new SQLitePersistentCookieStore(cookiePath);
- m_cookieStore = new net::CookieMonster(cookieDb.get(), 0);
+ m_cookieDb = new SQLitePersistentCookieStore(cookiePath);
+ m_cookieStore = new net::CookieMonster(m_cookieDb.get(), 0);
}
bool WebCookieJar::allowCookies()
@@ -111,6 +111,11 @@ void WebCookieJar::setAllowCookies(bool allow)
m_allowCookies = allow;
}
+int WebCookieJar::getNumCookiesInDatabase()
+{
+ return m_cookieDb ? m_cookieDb->GetCookieCount() : 0;
+}
+
// From CookiePolicy in chromium
int WebCookieJar::CanGetCookies(const GURL&, const GURL&, net::CompletionCallback*)
{
diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.h b/WebKit/android/WebCoreSupport/WebCookieJar.h
index 1372064..2f32e1a 100644
--- a/WebKit/android/WebCoreSupport/WebCookieJar.h
+++ b/WebKit/android/WebCoreSupport/WebCookieJar.h
@@ -54,9 +54,14 @@ public:
net::CookieStore* cookieStore() { return m_cookieStore.get(); }
net::CookiePolicy* cookiePolicy() { return this; }
+ // Get the number of cookies that have actually been saved to flash.
+ // (This is used to implement CookieManager.hasCookies() in the Java framework.)
+ int getNumCookiesInDatabase();
+
private:
WebCookieJar(const std::string& databaseFilePath);
+ scoped_refptr<SQLitePersistentCookieStore> m_cookieDb;
scoped_refptr<net::CookieStore> m_cookieStore;
bool m_allowCookies;
WTF::Mutex m_allowCookiesMutex;
diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp
index 5532f6a..0ba767c 100644
--- a/WebKit/android/jni/CookieManager.cpp
+++ b/WebKit/android/jni/CookieManager.cpp
@@ -83,7 +83,7 @@ static jstring getCookie(JNIEnv* env, jobject, jstring url)
static bool hasCookies(JNIEnv*, jobject)
{
#if USE(CHROME_NETWORK_STACK)
- return !WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->GetAllCookies().empty();
+ return WebCookieJar::get(false)->getNumCookiesInDatabase() > 0;
#else
// The Android HTTP stack is implemented Java-side.
ASSERT_NOT_REACHED();
@@ -101,6 +101,10 @@ static void removeAllCookie(JNIEnv*, jobject)
// TODO: Consider adding an optimisation to not create the context if it
// doesn't already exist.
WebCookieJar::get(true)->cookieStore()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true);
+
+ // The Java code removes cookies directly from the backing database, so we do the same,
+ // but with a NULL callback so it's asynchronous.
+ WebCookieJar::get(true)->cookieStore()->GetCookieMonster()->FlushStore(NULL);
#endif
}