diff options
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCache.cpp | 47 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCache.h | 10 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebResponse.cpp | 31 | ||||
-rw-r--r-- | WebKit/android/jni/CookieManager.cpp | 1 |
4 files changed, 47 insertions, 42 deletions
diff --git a/WebKit/android/WebCoreSupport/WebCache.cpp b/WebKit/android/WebCoreSupport/WebCache.cpp index 778d492..c5705dd 100644 --- a/WebKit/android/WebCoreSupport/WebCache.cpp +++ b/WebKit/android/WebCoreSupport/WebCache.cpp @@ -33,18 +33,19 @@ using namespace WTF; using namespace net; +using namespace std; namespace android { static WTF::Mutex instanceMutex; -static const std::string& rootDirectory() +static const string& rootDirectory() { // This method may be called on any thread, as the Java method is // synchronized. static WTF::Mutex mutex; MutexLocker lock(mutex); - static std::string cacheDirectory; + static string cacheDirectory; if (cacheDirectory.empty()) { JNIEnv* env = JSC::Bindings::getJNIEnv(); jclass bridgeClass = env->FindClass("android/webkit/JniUtil"); @@ -55,11 +56,11 @@ static const std::string& rootDirectory() return cacheDirectory; } -static std::string storageDirectory() +static string storageDirectory() { // Private cache is currently in memory only static const char* const kDirectory = "/webviewCacheChromium"; - std::string storageDirectory = rootDirectory(); + string storageDirectory = rootDirectory(); storageDirectory.append(kDirectory); return storageDirectory; } @@ -89,8 +90,9 @@ void WebCache::cleanup(bool isPrivateBrowsing) WebCache::WebCache(bool isPrivateBrowsing) : m_doomAllEntriesCallback(this, &WebCache::doomAllEntries) - , m_doneCallback(this, &WebCache::onClearDone) + , m_onClearDoneCallback(this, &WebCache::onClearDone) , m_isClearInProgress(false) + , m_cacheBackend(0) { base::Thread* ioThread = WebUrlLoaderClient::ioThread(); scoped_refptr<base::MessageLoopProxy> cacheMessageLoopProxy = ioThread->message_loop_proxy(); @@ -119,25 +121,27 @@ WebCache::WebCache(bool isPrivateBrowsing) void WebCache::clear() { - base::Thread* thread = WebUrlLoaderClient::ioThread(); - if (thread) - thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebCache::doClear)); + base::Thread* thread = WebUrlLoaderClient::ioThread(); + if (thread) + thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebCache::clearImpl)); } -void WebCache::doClear() +void WebCache::clearImpl() { if (m_isClearInProgress) return; m_isClearInProgress = true; - int code = m_cache->GetBackend(&m_cacheBackend, &m_doomAllEntriesCallback); - // Code ERR_IO_PENDING indicates that the operation is still in progress and - // the supplied callback will be invoked when it completes. - if (code == ERR_IO_PENDING) - return; - else if (code != OK) { - m_isClearInProgress = false; - return; + if (!m_cacheBackend) { + int code = m_cache->GetBackend(&m_cacheBackend, &m_doomAllEntriesCallback); + // Code ERR_IO_PENDING indicates that the operation is still in progress and + // the supplied callback will be invoked when it completes. + if (code == ERR_IO_PENDING) + return; + else if (code != OK) { + onClearDone(0 /*unused*/); + return; + } } doomAllEntries(0 /*unused*/); } @@ -145,19 +149,14 @@ void WebCache::doClear() void WebCache::doomAllEntries(int) { if (!m_cacheBackend) { - m_isClearInProgress = false; + onClearDone(0 /*unused*/); return; } - int code = m_cacheBackend->DoomAllEntries(&m_doneCallback); // Code ERR_IO_PENDING indicates that the operation is still in progress and // the supplied callback will be invoked when it completes. - if (code == ERR_IO_PENDING) - return; - else if (code != OK) { - m_isClearInProgress = false; + if (m_cacheBackend->DoomAllEntries(&m_onClearDoneCallback) == ERR_IO_PENDING) return; - } onClearDone(0 /*unused*/); } diff --git a/WebKit/android/WebCoreSupport/WebCache.h b/WebKit/android/WebCoreSupport/WebCache.h index be6c968..d89cba7 100644 --- a/WebKit/android/WebCoreSupport/WebCache.h +++ b/WebKit/android/WebCoreSupport/WebCache.h @@ -33,14 +33,14 @@ namespace android { -// This class is not generally threadsafe. get() is not threadsafe - instances -// are created on the WebCore thread only. +// This class is not generally threadsafe. However, get() and cleanup() are +// threadsafe. class WebCache : public base::RefCountedThreadSafe<WebCache> { public: static WebCache* get(bool isPrivateBrowsing); + static void cleanup(bool isPrivateBrowsing); void clear(); - static void cleanup(bool isPrivateBrowsing); net::HostResolver* hostResolver() { return m_hostResolver.get(); } net::HttpCache* cache() { return m_cache.get(); } net::ProxyConfigServiceAndroid* proxy() { return m_proxyConfigService; } @@ -49,7 +49,7 @@ private: WebCache(bool isPrivateBrowsing); // For clear() - void doClear(); + void clearImpl(); void doomAllEntries(int); void onClearDone(int); @@ -61,7 +61,7 @@ private: // For clear() net::CompletionCallbackImpl<WebCache> m_doomAllEntriesCallback; - net::CompletionCallbackImpl<WebCache> m_doneCallback; + net::CompletionCallbackImpl<WebCache> m_onClearDoneCallback; disk_cache::Backend* m_cacheBackend; bool m_isClearInProgress; }; diff --git a/WebKit/android/WebCoreSupport/WebResponse.cpp b/WebKit/android/WebCoreSupport/WebResponse.cpp index e564215..113fb05 100644 --- a/WebKit/android/WebCoreSupport/WebResponse.cpp +++ b/WebKit/android/WebCoreSupport/WebResponse.cpp @@ -115,18 +115,25 @@ void WebResponse::setUrl(const string& url) const string& WebResponse::getMimeType() { if (!m_mime.length() && m_url.length()) { - WTF::String wtfMime(m_url.c_str(), m_url.length()); - // Need to strip fragment and/or query if present. - size_t position = wtfMime.reverseFind('#'); - if (position != WTF::notFound) - wtfMime.truncate(position); - - position = wtfMime.reverseFind('?'); - if (position != WTF::notFound) - wtfMime.truncate(position); - - wtfMime = WebCore::MIMETypeRegistry::getMIMETypeForPath(wtfMime); - m_mime = std::string(wtfMime.utf8().data(), wtfMime.length()); + // Use "text/html" as a default (matching the behaviour of the Apache + // HTTP stack -- see guessMimeType() in LoadListener.java). + m_mime = "text/html"; + + // Try to guess a better MIME type from the URL. We call + // getMIMETypeForExtension rather than getMIMETypeForPath because the + // latter defaults to "application/octet-stream" on failure. + WebCore::KURL kurl(WebCore::ParsedURLString, m_url.c_str()); + WTF::String path = kurl.path(); + size_t extensionPos = path.reverseFind('.'); + if (extensionPos != WTF::notFound) { + // We found a file extension. + path.remove(0, extensionPos + 1); + WTF::String mime = WebCore::MIMETypeRegistry::getMIMETypeForExtension(path); + if (!mime.isEmpty()) { + // Great, we found a MIME type. + m_mime = std::string(mime.utf8().data(), mime.length()); + } + } } return m_mime; diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index 8dffbe7..553dc55 100644 --- a/WebKit/android/jni/CookieManager.cpp +++ b/WebKit/android/jni/CookieManager.cpp @@ -27,7 +27,6 @@ #include "ChromiumIncludes.h" #include "WebCookieJar.h" -#include "WebRequestContext.h" #include "WebCoreJni.h" #include <JNIHelp.h> |