summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-10-25 12:20:52 +0100
committerSteve Block <steveblock@google.com>2010-10-27 19:46:29 +0100
commit965d128a2f803da81a8a6d04c3d79382ff827bb9 (patch)
treed5912955a57cbfd3d43229c4c9848f9bd525862e
parent43d943757c6b39710fa65034351bc2e84946e8ce (diff)
downloadexternal_webkit-965d128a2f803da81a8a6d04c3d79382ff827bb9.zip
external_webkit-965d128a2f803da81a8a6d04c3d79382ff827bb9.tar.gz
external_webkit-965d128a2f803da81a8a6d04c3d79382ff827bb9.tar.bz2
Hook up CookieManager.acceptCookie() and setAcceptCookie() for the Chromium HTTP stack
We also update PlatformBridge::cookiesEnabled() to query the Chromium HTTP stack directly. This avoids calling CookieClient::cookiesEnabled(), which calls the Java CookieManager::acceptCookie() which in turns calls back to native code. Also requires a change to frameworks/base ... https://android-git.corp.google.com/g/76065 Bug: 3116410 Change-Id: Id853463f3bcef76b220e8c44dd2b30c0d6752624
-rw-r--r--WebKit/android/WebCoreSupport/ChromiumIncludes.h1
-rw-r--r--WebKit/android/WebCoreSupport/PlatformBridge.cpp5
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.cpp26
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.h13
-rw-r--r--WebKit/android/jni/CookieManager.cpp27
5 files changed, 70 insertions, 2 deletions
diff --git a/WebKit/android/WebCoreSupport/ChromiumIncludes.h b/WebKit/android/WebCoreSupport/ChromiumIncludes.h
index ad93179..377aa22 100644
--- a/WebKit/android/WebCoreSupport/ChromiumIncludes.h
+++ b/WebKit/android/WebCoreSupport/ChromiumIncludes.h
@@ -57,6 +57,7 @@
#include <chrome/browser/net/sqlite_persistent_cookie_store.h>
#include <net/base/auth.h>
#include <net/base/cookie_monster.h>
+#include <net/base/cookie_policy.h>
#include <net/base/data_url.h>
#include <net/base/host_resolver.h>
#include <net/base/io_buffer.h>
diff --git a/WebKit/android/WebCoreSupport/PlatformBridge.cpp b/WebKit/android/WebCoreSupport/PlatformBridge.cpp
index 03a7912..092676b 100644
--- a/WebKit/android/WebCoreSupport/PlatformBridge.cpp
+++ b/WebKit/android/WebCoreSupport/PlatformBridge.cpp
@@ -101,11 +101,16 @@ String PlatformBridge::cookies(const Document* document, const KURL& url)
bool PlatformBridge::cookiesEnabled(const Document* document)
{
+#if USE(CHROME_NETWORK_STACK)
+ bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
+ return WebRequestContext::get(isPrivateBrowsing)->allowCookies();
+#else
CookieClient* client = JavaSharedClient::GetCookieClient();
if (!client)
return false;
return client->cookiesEnabled();
+#endif
}
NPObject* PlatformBridge::pluginScriptableObject(Widget* widget)
diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
index 2ff3ae8..aa5311f 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
@@ -37,7 +37,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include <wtf/text/CString.h>
-#include <wtf/Threading.h>
namespace {
// TODO: The userAgent should not be a static, as it can be set per WebView.
@@ -65,6 +64,7 @@ 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";
@@ -163,6 +163,7 @@ WebRequestContext* WebRequestContext::getContextForPath(const char* cookieFilena
net::CookieMonster::EnableFileScheme();
context->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0);
+ context->cookie_policy_ = context;
return context;
}
@@ -238,4 +239,27 @@ bool WebRequestContext::cleanupPrivateBrowsingFiles(const std::string& databaseD
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 788998e..f4a579c 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.h
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.h
@@ -29,14 +29,20 @@
#include "ChromiumIncludes.h"
#include "PlatformString.h"
+#include <wtf/ThreadingPrimitives.h>
+
namespace android {
-class WebRequestContext : public URLRequestContext {
+class WebRequestContext : public URLRequestContext, net::CookiePolicy {
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
@@ -47,6 +53,8 @@ public:
static bool cleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory);
static void setUserAgent(WTF::String);
static void setAcceptLanguage(WTF::String);
+ bool allowCookies();
+ void setAllowCookies(bool allow);
private:
WebRequestContext();
@@ -55,6 +63,9 @@ private:
static WebRequestContext* getContextForPath(const char* cookieFilename, const char* cacheFilename);
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 7139286..e1e139e 100644
--- a/WebKit/android/jni/CookieManager.cpp
+++ b/WebKit/android/jni/CookieManager.cpp
@@ -44,6 +44,21 @@ static bool useChromiumHttpStack(JNIEnv*, jobject) {
#endif
}
+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
+ // private browsing, so expect the same result here.
+ bool regularAcceptCookies = WebRequestContext::get(false)->allowCookies();
+ ASSERT(regularAcceptCookies == WebRequestContext::get(true)->allowCookies());
+ return regularAcceptCookies;
+#else
+ // The Android HTTP stack is implemented Java-side.
+ ASSERT_NOT_REACHED();
+ return false;
+#endif
+}
+
static void removeAllCookie(JNIEnv*, jobject) {
#if USE(CHROME_NETWORK_STACK)
// Though WebRequestContext::get() is threadsafe, the context itself, in
@@ -62,9 +77,21 @@ static void removeAllCookie(JNIEnv*, jobject) {
#endif
}
+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
+ // browsing.
+ WebRequestContext::get(false)->setAllowCookies(accept);
+ WebRequestContext::get(true)->setAllowCookies(accept);
+#endif
+}
+
static JNINativeMethod gCookieManagerMethods[] = {
{ "nativeUseChromiumHttpStack", "()Z", (void*) useChromiumHttpStack },
+ { "nativeAcceptCookie", "()Z", (void*) acceptCookie },
{ "nativeRemoveAllCookie", "()V", (void*) removeAllCookie },
+ { "nativeSetAcceptCookie", "(Z)V", (void*) setAcceptCookie },
};
int registerCookieManager(JNIEnv* env)