summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-11-05 14:43:45 +0000
committerSteve Block <steveblock@google.com>2010-11-26 12:38:20 +0000
commit8a5f8b64a112f92833cd718f9b401c996918081b (patch)
treeed7a26f3d39cc987c2c98c541403af040770f725
parent20abb0328abff7ab53b49399ba3b2122c37d8249 (diff)
downloadexternal_webkit-8a5f8b64a112f92833cd718f9b401c996918081b.zip
external_webkit-8a5f8b64a112f92833cd718f9b401c996918081b.tar.gz
external_webkit-8a5f8b64a112f92833cd718f9b401c996918081b.tar.bz2
Factor out CookieManager from WebRequestContext
This is the first step in allowing us to have a WebRequestContext per WebView, which is required to allow the useragent string to be configured per WebView. Bug: 3113804 Change-Id: I9ccf07d4a277147e74e2f3e701bd6d2166954280
-rw-r--r--WebKit/Android.mk1
-rw-r--r--WebKit/android/WebCoreSupport/PlatformBridge.cpp7
-rw-r--r--WebKit/android/WebCoreSupport/WebCookieJar.cpp126
-rw-r--r--WebKit/android/WebCoreSupport/WebCookieJar.h63
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.cpp87
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.h17
-rw-r--r--WebKit/android/jni/CookieManager.cpp31
7 files changed, 235 insertions, 97 deletions
diff --git a/WebKit/Android.mk b/WebKit/Android.mk
index 844d8a5..29ff8e2 100644
--- a/WebKit/Android.mk
+++ b/WebKit/Android.mk
@@ -35,6 +35,7 @@ ifeq ($(HTTP_STACK),chrome)
LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
android/WebCoreSupport/ChromiumLogging.cpp \
android/WebCoreSupport/WebCache.cpp \
+ android/WebCoreSupport/WebCookieJar.cpp \
android/WebCoreSupport/WebUrlLoader.cpp \
android/WebCoreSupport/WebUrlLoaderClient.cpp \
android/WebCoreSupport/WebRequest.cpp \
diff --git a/WebKit/android/WebCoreSupport/PlatformBridge.cpp b/WebKit/android/WebCoreSupport/PlatformBridge.cpp
index 1b249a4..f17a73a 100644
--- a/WebKit/android/WebCoreSupport/PlatformBridge.cpp
+++ b/WebKit/android/WebCoreSupport/PlatformBridge.cpp
@@ -34,6 +34,7 @@
#include "KeyGeneratorClient.h"
#include "PluginView.h"
#include "Settings.h"
+#include "WebCookieJar.h"
#include "WebRequestContext.h"
#include "WebViewCore.h"
#include "npruntime.h"
@@ -72,7 +73,7 @@ void PlatformBridge::setCookies(const Document* document, const KURL& url, const
std::string cookieValue(value.utf8().data());
GURL cookieGurl(url.string().utf8().data());
bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
- WebRequestContext::get(isPrivateBrowsing)->cookie_store()->SetCookie(cookieGurl, cookieValue);
+ WebCookieJar::get(isPrivateBrowsing)->cookieStore()->SetCookie(cookieGurl, cookieValue);
#else
CookieClient* client = JavaSharedClient::GetCookieClient();
if (!client)
@@ -87,7 +88,7 @@ String PlatformBridge::cookies(const Document* document, const KURL& url)
#if USE(CHROME_NETWORK_STACK)
GURL cookieGurl(url.string().utf8().data());
bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
- std::string cookies = WebRequestContext::get(isPrivateBrowsing)->cookie_store()->GetCookies(cookieGurl);
+ std::string cookies = WebCookieJar::get(isPrivateBrowsing)->cookieStore()->GetCookies(cookieGurl);
String cookieString(cookies.c_str());
return cookieString;
#else
@@ -103,7 +104,7 @@ bool PlatformBridge::cookiesEnabled(const Document* document)
{
#if USE(CHROME_NETWORK_STACK)
bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
- return WebRequestContext::get(isPrivateBrowsing)->allowCookies();
+ return WebCookieJar::get(isPrivateBrowsing)->allowCookies();
#else
CookieClient* client = JavaSharedClient::GetCookieClient();
if (!client)
diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.cpp b/WebKit/android/WebCoreSupport/WebCookieJar.cpp
new file mode 100644
index 0000000..8abc3b2
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/WebCookieJar.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebCookieJar.h"
+
+#include "JNIUtility.h"
+#include "WebCoreJni.h"
+#include "WebRequestContext.h"
+#include "jni.h"
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <wtf/text/CString.h>
+
+namespace {
+static const char* const kCookiesDatabaseFilename = "/webviewCookiesChromium.db";
+static const char* const kCookiesDatabaseFilenamePrivateBrowsing = "/webviewCookiesChromiumPrivate.db";
+WTF::Mutex databaseDirectoryMutex;
+}
+
+namespace android {
+
+const std::string& databaseDirectory()
+{
+ // This method may be called on any thread, as the Java method is
+ // synchronized.
+ MutexLocker lock(databaseDirectoryMutex);
+ static std::string databaseDirectory;
+ if (databaseDirectory.empty()) {
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jclass bridgeClass = env->FindClass("android/webkit/JniUtil");
+ jmethodID method = env->GetStaticMethodID(bridgeClass, "getDatabaseDirectory", "()Ljava/lang/String;");
+ databaseDirectory = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
+ env->DeleteLocalRef(bridgeClass);
+ }
+ return databaseDirectory;
+}
+
+
+WebCookieJar* WebCookieJar::get(bool isPrivateBrowsing)
+{
+ static WebCookieJar* regularCookieManager = 0;
+ static WebCookieJar* privateCookieManager = 0;
+
+ if (isPrivateBrowsing) {
+ if (!privateCookieManager)
+ privateCookieManager = new WebCookieJar(true);
+ return privateCookieManager;
+ } else {
+ if (!regularCookieManager)
+ regularCookieManager = new WebCookieJar(false);
+ return regularCookieManager;
+ }
+}
+
+WebCookieJar::WebCookieJar(bool isPrivateBrowsing)
+ : m_allowCookies(true)
+{
+ // This is needed for the page cycler. See http://b/2944150
+ net::CookieMonster::EnableFileScheme();
+
+ m_databaseFilePath = databaseDirectory();
+ m_databaseFilePath.append(isPrivateBrowsing ? kCookiesDatabaseFilenamePrivateBrowsing : kCookiesDatabaseFilename);
+
+ FilePath cookiePath(m_databaseFilePath.c_str());
+ scoped_refptr<SQLitePersistentCookieStore> cookieDb = new SQLitePersistentCookieStore(cookiePath);
+ m_cookieStore = new net::CookieMonster(cookieDb.get(), 0);
+}
+
+bool WebCookieJar::allowCookies()
+{
+ MutexLocker lock(m_allowCookiesMutex);
+ return m_allowCookies;
+}
+
+void WebCookieJar::setAllowCookies(bool allow)
+{
+ MutexLocker lock(m_allowCookiesMutex);
+ m_allowCookies = allow;
+}
+
+void WebCookieJar::cleanupFiles()
+{
+ WebRequestContext::removeFileOrDirectory(m_databaseFilePath.c_str());
+}
+
+// From CookiePolicy in chromium
+int WebCookieJar::CanGetCookies(const GURL&, const GURL&, net::CompletionCallback*)
+{
+ MutexLocker lock(m_allowCookiesMutex);
+ return m_allowCookies ? net::OK : net::ERR_ACCESS_DENIED;
+}
+
+// From CookiePolicy in chromium
+int WebCookieJar::CanSetCookie(const GURL&, const GURL&, const std::string&, net::CompletionCallback*)
+{
+ MutexLocker lock(m_allowCookiesMutex);
+ return m_allowCookies ? net::OK : net::ERR_ACCESS_DENIED;
+}
+
+}
diff --git a/WebKit/android/WebCoreSupport/WebCookieJar.h b/WebKit/android/WebCoreSupport/WebCookieJar.h
new file mode 100644
index 0000000..adb923a
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/WebCookieJar.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebCookieJar_h
+#define WebCookieJar_h
+
+#include "ChromiumIncludes.h"
+
+#include <wtf/ThreadingPrimitives.h>
+
+namespace android {
+
+class WebCookieJar : public net::CookiePolicy {
+public:
+ static WebCookieJar* get(bool isPrivate);
+
+ // CookiePolicy implementation from external/chromium
+ virtual int CanGetCookies(const GURL& url, const GURL& first_party_for_cookies, net::CompletionCallback*);
+ virtual int CanSetCookie(const GURL& url, const GURL& first_party_for_cookies, const std::string& cookie_line, net::CompletionCallback*);
+
+ bool allowCookies();
+ void setAllowCookies(bool allow);
+ void cleanupFiles();
+
+ // 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(); }
+ net::CookiePolicy* cookiePolicy() { return this; }
+
+private:
+ WebCookieJar(bool isPrivate);
+
+ scoped_refptr<net::CookieStore> m_cookieStore;
+ bool m_allowCookies;
+ WTF::Mutex m_allowCookiesMutex;
+ std::string m_databaseFilePath;
+};
+
+}
+
+#endif
diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
index 9d8ad66..61303d9 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
@@ -29,6 +29,7 @@
#include "ChromiumIncludes.h"
#include "ChromiumLogging.h"
#include "JNIUtility.h"
+#include "WebCookieJar.h"
#include "WebCoreJni.h"
#include "WebUrlLoaderClient.h"
#include "jni.h"
@@ -48,7 +49,6 @@ std::string acceptLanguage("");
Lock userAgentLock;
Lock acceptLanguageLock;
-WTF::Mutex databaseDirectoryMutex;
WTF::Mutex cacheDirectoryMutex;
}
@@ -56,16 +56,13 @@ using namespace WTF;
namespace android {
-static const char* const kCookiesDatabaseFilename = "/webviewCookiesChromium.db";
static const char* const kCacheDirectory = "/webviewCacheChromium";
-static const char* const kCookiesDatabaseFilenamePrivate = "/webviewCookiesChromiumPrivate.db";
static const char* const kCacheDirectoryPrivate = "/webviewCacheChromiumPrivate";
static scoped_refptr<WebRequestContext> privateBrowsingContext(0);
static WTF::Mutex privateBrowsingContextMutex;
WebRequestContext::WebRequestContext()
- : m_allowCookies(true)
{
// Also hardcoded in FrameLoader.java
accept_charset_ = "utf-8, iso-8859-1, utf-16, *;q=0.7";
@@ -108,23 +105,7 @@ const std::string& WebRequestContext::GetAcceptLanguage() const
return acceptLanguage;
}
-static const std::string& getDatabaseDirectory()
-{
- // This method may be called on any thread, as the Java method is
- // synchronized.
- MutexLocker lock(databaseDirectoryMutex);
- static std::string databaseDirectory;
- if (databaseDirectory.empty()) {
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- jclass bridgeClass = env->FindClass("android/webkit/JniUtil");
- jmethodID method = env->GetStaticMethodID(bridgeClass, "getDatabaseDirectory", "()Ljava/lang/String;");
- databaseDirectory = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
- env->DeleteLocalRef(bridgeClass);
- }
- return databaseDirectory;
-}
-
-static const std::string& getCacheDirectory()
+static const std::string& cacheRootDirectory()
{
// This method may be called on any thread, as the Java method is
// synchronized.
@@ -140,14 +121,11 @@ static const std::string& getCacheDirectory()
return cacheDirectory;
}
-WebRequestContext* WebRequestContext::getContextForPath(const char* cookieFilename, const char* cacheFilename)
+WebRequestContext* WebRequestContext::getImpl(bool isPrivateBrowsing)
{
- std::string cookieString(getDatabaseDirectory());
- cookieString.append(cookieFilename);
- FilePath cookiePath(cookieString.c_str());
- std::string cacheString(getCacheDirectory());
- cacheString.append(cacheFilename);
- FilePath cachePath(cacheString.c_str());
+ static std::string path = cacheRootDirectory();
+ path.append(isPrivateBrowsing ? kCacheDirectoryPrivate : kCacheDirectory);
+ FilePath cachePath(path.c_str());
WebRequestContext* context = new WebRequestContext();
context->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0, 0);
@@ -158,13 +136,9 @@ WebRequestContext* WebRequestContext::getContextForPath(const char* cookieFilena
context->http_transaction_factory_ = new net::HttpCache(context->host_resolver(), context->dnsrr_resolver(), net::ProxyService::CreateDirect(), net::SSLConfigService::CreateSystemSSLConfigService(), net::HttpAuthHandlerFactory::CreateDefault(context->host_resolver_), 0, 0, defaultBackend);
- scoped_refptr<SQLitePersistentCookieStore> cookieDb = new SQLitePersistentCookieStore(cookiePath);
-
- // This is needed for the page cycler. See http://b/2944150
- net::CookieMonster::EnableFileScheme();
-
- context->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0);
- context->cookie_policy_ = context;
+ WebCookieJar* cookieJar = WebCookieJar::get(isPrivateBrowsing);
+ context->cookie_store_ = cookieJar->cookieStore();
+ context->cookie_policy_ = cookieJar;
return context;
}
@@ -176,7 +150,7 @@ WebRequestContext* WebRequestContext::getRegularContext()
MutexLocker lock(regularContextMutex);
if (!regularContext)
- regularContext = getContextForPath(kCookiesDatabaseFilename, kCacheDirectory);
+ regularContext = getImpl(false);
return regularContext;
}
@@ -184,11 +158,10 @@ WebRequestContext* WebRequestContext::getPrivateBrowsingContext()
{
MutexLocker lock(privateBrowsingContextMutex);
- if (!privateBrowsingContext) {
- // TODO: Where is the right place to put the temporary db? Should it be
- // kept in memory?
- privateBrowsingContext = getContextForPath(kCookiesDatabaseFilenamePrivate, kCacheDirectoryPrivate);
- }
+ // TODO: Where is the right place to put the temporary db? Should it be
+ // kept in memory?
+ if (!privateBrowsingContext)
+ privateBrowsingContext = getImpl(true);
return privateBrowsingContext;
}
@@ -200,7 +173,7 @@ WebRequestContext* WebRequestContext::get(bool isPrivateBrowsing)
return isPrivateBrowsing ? getPrivateBrowsingContext() : getRegularContext();
}
-static void removeFileOrDirectory(const char* filename)
+void WebRequestContext::removeFileOrDirectory(const char* filename)
{
struct stat filetype;
if (stat(filename, &filetype) != 0)
@@ -232,10 +205,9 @@ bool WebRequestContext::cleanupPrivateBrowsingFiles()
if (!privateBrowsingContext || privateBrowsingContext->HasOneRef()) {
privateBrowsingContext = 0;
- std::string cookiePath = getDatabaseDirectory();
- cookiePath.append(kCookiesDatabaseFilenamePrivate);
- removeFileOrDirectory(cookiePath.c_str());
- std::string cachePath = getCacheDirectory();
+ WebCookieJar::get(true)->cleanupFiles();
+
+ std::string cachePath = cacheRootDirectory();
cachePath.append(kCacheDirectoryPrivate);
removeFileOrDirectory(cachePath.c_str());
return true;
@@ -243,27 +215,4 @@ bool WebRequestContext::cleanupPrivateBrowsingFiles()
return false;
}
-int WebRequestContext::CanGetCookies(const GURL&, const GURL&, net::CompletionCallback*)
-{
- MutexLocker lock(m_allowCookiesMutex);
- return m_allowCookies ? net::OK : net::ERR_ACCESS_DENIED;
-}
-
-int WebRequestContext::CanSetCookie(const GURL&, const GURL&, const std::string&, net::CompletionCallback*)
-{
- MutexLocker lock(m_allowCookiesMutex);
- return m_allowCookies ? net::OK : net::ERR_ACCESS_DENIED;
-}
-
-bool WebRequestContext::allowCookies() {
- MutexLocker lock(m_allowCookiesMutex);
- return m_allowCookies;
-}
-
-void WebRequestContext::setAllowCookies(bool allow)
-{
- MutexLocker lock(m_allowCookiesMutex);
- m_allowCookies = allow;
-}
-
} // namespace android
diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.h b/WebKit/android/WebCoreSupport/WebRequestContext.h
index ba7dc4f..024308e 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.h
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.h
@@ -33,16 +33,12 @@
namespace android {
-class WebRequestContext : public URLRequestContext, net::CookiePolicy {
+class WebRequestContext : public URLRequestContext {
public:
// URLRequestContext overrides.
virtual const std::string& GetUserAgent(const GURL&) const;
virtual const std::string& GetAcceptLanguage() const;
- // CookiePolicy implementation.
- virtual int CanGetCookies(const GURL& url, const GURL& first_party_for_cookies, net::CompletionCallback*);
- virtual int CanSetCookie(const GURL& url, const GURL& first_party_for_cookies, const std::string& cookie_line, net::CompletionCallback*);
-
// Lazily create the relevant context. This class holds a reference.
// This may be called on any thread. The context returned, however, is not
// threadsafe, and should only be used on a single thread (the network stack
@@ -53,19 +49,20 @@ public:
static bool cleanupPrivateBrowsingFiles();
static void setUserAgent(WTF::String);
static void setAcceptLanguage(WTF::String);
- bool allowCookies();
- void setAllowCookies(bool allow);
+
+ // A helper function used by the cache and cookie managers. Should probably
+ // find a better home, but wait for the refactoring in b/3113804 to be
+ // completed.
+ static void removeFileOrDirectory(const char* filename);
private:
WebRequestContext();
~WebRequestContext();
- static WebRequestContext* getContextForPath(const char* cookieFilename, const char* cacheFilename);
+ static WebRequestContext* getImpl(bool isPrivateBrowsing);
static WebRequestContext* getRegularContext();
static WebRequestContext* getPrivateBrowsingContext();
- bool m_allowCookies;
- WTF::Mutex m_allowCookiesMutex;
};
} // namespace android
diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp
index 3a36397..972c927 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>
@@ -63,8 +64,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 +80,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 +92,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 +103,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,15 +117,15 @@ 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->IsSessionCookie())
@@ -136,8 +137,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 +148,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 +160,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
}