summaryrefslogtreecommitdiffstats
path: root/WebKit
diff options
context:
space:
mode:
authorElliott Slaughter <eds@google.com>2010-08-23 18:24:00 -0700
committerElliott Slaughter <eds@google.com>2010-09-01 11:14:22 -0700
commit0b84ecf50c01e0fbf7307ca7cae55ab3043c75a3 (patch)
tree1c7c21b2d83a8af7f5da652a7ce7971d75b1d0f1 /WebKit
parente7a439253f03e258c35f31fed37bf8e460f95158 (diff)
downloadexternal_webkit-0b84ecf50c01e0fbf7307ca7cae55ab3043c75a3.zip
external_webkit-0b84ecf50c01e0fbf7307ca7cae55ab3043c75a3.tar.gz
external_webkit-0b84ecf50c01e0fbf7307ca7cae55ab3043c75a3.tar.bz2
Cleanup temporary incognito mode files after last tab closes.
Change-Id: Ib55ef570b181afc99991afb55b6880b7a13f69a7
Diffstat (limited to 'WebKit')
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.cpp6
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.cpp76
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.h7
-rw-r--r--WebKit/android/nav/WebView.cpp16
4 files changed, 90 insertions, 15 deletions
diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp
index a5ff85d..74a37c7 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequest.cpp
@@ -136,10 +136,12 @@ void WebRequest::start(bool isPrivateBrowsing)
if (m_request->url().SchemeIs("browser"))
return handleBrowserURL(m_request->url());
+ scoped_refptr<WebRequestContext> context;
if (!isPrivateBrowsing)
- m_request->set_context(WebRequestContext::GetAndroidContext());
+ context = WebRequestContext::GetAndroidContext();
else
- m_request->set_context(WebRequestContext::GetAndroidPrivateBrowsingContext());
+ context = WebRequestContext::GetAndroidPrivateBrowsingContext();
+ m_request->set_context(context);
m_request->Start();
}
diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
index 83e97fe..dc9feae 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
@@ -29,7 +29,12 @@
#include "JNIUtility.h"
#include "jni.h"
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <wtf/text/CString.h>
+#include <wtf/Threading.h>
namespace {
std::string userAgent("Mozilla/5.0 (Linux; U; Android 2.1; en-gb; Nexus One Build/ERE21) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
@@ -41,6 +46,15 @@ Lock acceptLanguageLock;
namespace android {
+static const char* const kNormalCookies = "/chromecookies.db";
+static const char* const kNormalCache = "/chromecache";
+static const char* const kPrivateCookies = "/chromecookies_private.db";
+static const char* const kPrivateCache = "/chromecache_private";
+
+static scoped_refptr<WebRequestContext> androidContext(0);
+static scoped_refptr<WebRequestContext> androidPrivateBrowsingContext(0);
+static WTF::Mutex androidPrivateBrowsingContextMutex;
+
std::string* WebRequestContext::s_dataDirectory(0);
WebRequestContext::WebRequestContext()
@@ -96,7 +110,7 @@ const std::string* WebRequestContext::GetDataDirectory()
return s_dataDirectory;
}
-WebRequestContext* WebRequestContext::GetAndroidContextForPath(const char* cookieFilename, const char* cacheFilename)
+scoped_refptr<WebRequestContext> WebRequestContext::GetAndroidContextForPath(const char* cookieFilename, const char* cacheFilename)
{
std::string cookieString(*GetDataDirectory());
cookieString.append(cookieFilename);
@@ -119,26 +133,68 @@ WebRequestContext* WebRequestContext::GetAndroidContextForPath(const char* cooki
androidContext->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0);
- return androidContext.release();
+ return androidContext;
}
-WebRequestContext* WebRequestContext::GetAndroidContext()
+scoped_refptr<WebRequestContext> WebRequestContext::GetAndroidContext()
{
- static scoped_refptr<WebRequestContext> androidContext(0);
if (!androidContext)
- androidContext = GetAndroidContextForPath("/chromecookies.db", "/chromecache");
+ androidContext = GetAndroidContextForPath(kNormalCookies, kNormalCache);
return androidContext;
}
-WebRequestContext* WebRequestContext::GetAndroidPrivateBrowsingContext()
+scoped_refptr<WebRequestContext> WebRequestContext::GetAndroidPrivateBrowsingContext()
{
- static scoped_refptr<WebRequestContext> androidContext(0);
- if (!androidContext) {
+ WTF::MutexLocker lock(androidPrivateBrowsingContextMutex);
+
+ if (!androidPrivateBrowsingContext) {
// TODO: Where is the right place to put the temporary db? Should it be
// kept in memory?
- androidContext = GetAndroidContextForPath("/chromecookies_private.db", "/chromecache_private");
+ androidPrivateBrowsingContext = GetAndroidContextForPath(kPrivateCookies, kPrivateCache);
}
- return androidContext;
+ return androidPrivateBrowsingContext;
+}
+
+static void removeFileOrDirectory(const char* filename)
+{
+ struct stat filetype;
+ if (stat(filename, &filetype) != 0)
+ return;
+ if (S_ISDIR(filetype.st_mode)) {
+ DIR* directory = opendir(filename);
+ if (directory) {
+ while (struct dirent* entry = readdir(directory)) {
+ if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
+ continue;
+ std::string entryName(filename);
+ entryName.append("/");
+ entryName.append(entry->d_name);
+ removeFileOrDirectory(entryName.c_str());
+ }
+ closedir(directory);
+ rmdir(filename);
+ }
+ return;
+ }
+ unlink(filename);
+}
+
+bool WebRequestContext::CleanupAndroidPrivateBrowsingFiles(std::string dataDirectory)
+{
+ WTF::MutexLocker lock(androidPrivateBrowsingContextMutex);
+
+ if (!androidPrivateBrowsingContext || androidPrivateBrowsingContext->HasOneRef()) {
+ androidPrivateBrowsingContext = 0;
+
+ std::string cookiePath(dataDirectory);
+ cookiePath.append(kPrivateCookies);
+ removeFileOrDirectory(cookiePath.c_str());
+ std::string cachePath(dataDirectory);
+ cachePath.append(kPrivateCache);
+ removeFileOrDirectory(cachePath.c_str());
+ return true;
+ }
+ return false;
}
} // namespace android
diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.h b/WebKit/android/WebCoreSupport/WebRequestContext.h
index e35d0ba..5e6a84e 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.h
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.h
@@ -40,15 +40,16 @@ class WebRequestContext : public URLRequestContext {
public:
virtual const std::string& GetUserAgent(const GURL& url) const;
virtual const std::string& GetAcceptLanguage() const;
- static WebRequestContext* GetAndroidContext();
- static WebRequestContext* GetAndroidPrivateBrowsingContext();
+ static scoped_refptr<WebRequestContext> GetAndroidContext();
+ static scoped_refptr<WebRequestContext> GetAndroidPrivateBrowsingContext();
+ static bool CleanupAndroidPrivateBrowsingFiles(std::string dataDirectory);
static void SetUserAgent(WTF::String);
static void SetAcceptLanguage(WTF::String);
private:
static const std::string* GetDataDirectory();
- static WebRequestContext* GetAndroidContextForPath(const char* cookiePath, const char* cachePath);
+ static scoped_refptr<WebRequestContext> GetAndroidContextForPath(const char* cookiePath, const char* cachePath);
WebRequestContext();
~WebRequestContext();
diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp
index c034e4e..e95eee0 100644
--- a/WebKit/android/nav/WebView.cpp
+++ b/WebKit/android/nav/WebView.cpp
@@ -54,6 +54,7 @@
#include "TimeCounter.h"
#endif
#include "WebCoreJni.h"
+#include "WebRequestContext.h"
#include "WebViewCore.h"
#include "android_graphics.h"
@@ -1964,6 +1965,19 @@ static void nativeMoveSelection(JNIEnv *env, jobject obj, int x, int y)
GET_NATIVE_VIEW(env, obj)->moveSelection(x, y);
}
+static jboolean nativeCleanupPrivateBrowsingFiles(JNIEnv *env, jobject obj, jstring dataDirectory) {
+#if USE(CHROME_NETWORK_STACK)
+ jboolean isCopy;
+ const char* nativeString = env->GetStringUTFChars(dataDirectory, &isCopy);
+ std::string nativeDataDirectory(nativeString);
+ if (isCopy == JNI_TRUE)
+ env->ReleaseStringUTFChars(dataDirectory, nativeString);
+ return WebRequestContext::CleanupAndroidPrivateBrowsingFiles(nativeDataDirectory);
+#else
+ return JNI_FALSE;
+#endif
+}
+
static void nativeResetSelection(JNIEnv *env, jobject obj)
{
return GET_NATIVE_VIEW(env, obj)->resetSelection();
@@ -2214,6 +2228,8 @@ static JNINativeMethod gJavaWebViewMethods[] = {
(void*) nativeMoveGeneration },
{ "nativeMoveSelection", "(II)V",
(void*) nativeMoveSelection },
+ { "nativeCleanupPrivateBrowsingFiles", "(Ljava/lang/String;)Z",
+ (void*) nativeCleanupPrivateBrowsingFiles },
{ "nativePointInNavCache", "(III)Z",
(void*) nativePointInNavCache },
{ "nativeRecordButtons", "(ZZZ)V",