From c65c296d5bbf1608aedeceac90179a261deb0368 Mon Sep 17 00:00:00 2001 From: Iain Merrick Date: Mon, 6 Dec 2010 10:43:52 +0000 Subject: [PATCH] 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 --- WebKit/android/WebCoreSupport/WebCookieJar.cpp | 9 +++++++-- WebKit/android/WebCoreSupport/WebCookieJar.h | 5 +++++ WebKit/android/jni/CookieManager.cpp | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.cpp b/WebKit/android/WebCoreSupport/WebCookieJar.cpp index 6a81ff19e..afa87c27d 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 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 13720649f..2f32e1a61 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 m_cookieDb; scoped_refptr m_cookieStore; bool m_allowCookies; WTF::Mutex m_allowCookiesMutex; diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index 5532f6ab3..0ba767c92 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 } -- 2.11.0