diff options
Diffstat (limited to 'WebKit/android/WebCoreSupport')
-rw-r--r-- | WebKit/android/WebCoreSupport/PlatformBridge.cpp | 4 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCache.cpp | 2 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequest.cpp | 2 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequestContext.cpp | 75 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequestContext.h | 24 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp | 6 |
6 files changed, 61 insertions, 52 deletions
diff --git a/WebKit/android/WebCoreSupport/PlatformBridge.cpp b/WebKit/android/WebCoreSupport/PlatformBridge.cpp index 7a5369a..03a7912 100644 --- a/WebKit/android/WebCoreSupport/PlatformBridge.cpp +++ b/WebKit/android/WebCoreSupport/PlatformBridge.cpp @@ -72,7 +72,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::GetContext(isPrivateBrowsing)->cookie_store()->SetCookie(cookieGurl, cookieValue); + WebRequestContext::get(isPrivateBrowsing)->cookie_store()->SetCookie(cookieGurl, cookieValue); #else CookieClient* client = JavaSharedClient::GetCookieClient(); if (!client) @@ -87,7 +87,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::GetContext(isPrivateBrowsing)->cookie_store()->GetCookies(cookieGurl); + std::string cookies = WebRequestContext::get(isPrivateBrowsing)->cookie_store()->GetCookies(cookieGurl); String cookieString(cookies.c_str()); return cookieString; #else diff --git a/WebKit/android/WebCoreSupport/WebCache.cpp b/WebKit/android/WebCoreSupport/WebCache.cpp index b46e180..69ede65 100644 --- a/WebKit/android/WebCoreSupport/WebCache.cpp +++ b/WebKit/android/WebCoreSupport/WebCache.cpp @@ -59,7 +59,7 @@ void WebCache::doClear() if (m_isClearInProgress) return; m_isClearInProgress = true; - URLRequestContext* context = WebRequestContext::GetContext(false /* isPrivateBrowsing */); + URLRequestContext* context = WebRequestContext::get(false /* isPrivateBrowsing */); net::HttpTransactionFactory* factory = context->http_transaction_factory(); int code = factory->GetCache()->GetBackend(&m_cacheBackend, &m_doomAllEntriesCallback); // Code ERR_IO_PENDING indicates that the operation is still in progress and diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp index b584796..ec6dce1 100644 --- a/WebKit/android/WebCoreSupport/WebRequest.cpp +++ b/WebKit/android/WebCoreSupport/WebRequest.cpp @@ -140,7 +140,7 @@ void WebRequest::start(bool isPrivateBrowsing) if (m_request->url().SchemeIs("browser")) return handleBrowserURL(m_request->url()); - URLRequestContext* context = WebRequestContext::GetContext(isPrivateBrowsing); + URLRequestContext* context = WebRequestContext::get(isPrivateBrowsing); m_request->set_context(context); m_request->Start(); diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp index 729a2eb..87b6893 100644 --- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp +++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp @@ -24,13 +24,13 @@ */ #include "config.h" - #include "WebRequestContext.h" #include "ChromiumIncludes.h" #include "JNIUtility.h" #include "WebUrlLoaderClient.h" #include "jni.h" + #include <dirent.h> #include <sys/types.h> #include <sys/stat.h> @@ -48,6 +48,8 @@ Lock userAgentLock; Lock acceptLanguageLock; } +using namespace WTF; + namespace android { static const char* const kCookiesDatabaseFilename = "/webviewCookiesChromium.db"; @@ -55,8 +57,8 @@ static const char* const kCacheDirectory = "/webviewCacheChromium"; static const char* const kCookiesDatabaseFilenamePrivate = "/webviewCookiesChromiumPrivate.db"; static const char* const kCacheDirectoryPrivate = "/webviewCacheChromiumPrivate"; -static scoped_refptr<URLRequestContext> androidPrivateBrowsingContext(0); -static WTF::Mutex androidPrivateBrowsingContextMutex; +static scoped_refptr<WebRequestContext> privateBrowsingContext(0); +static WTF::Mutex privateBrowsingContextMutex; WebRequestContext::WebRequestContext() { @@ -68,32 +70,40 @@ WebRequestContext::~WebRequestContext() { } -void WebRequestContext::SetUserAgent(WTF::String string) +void WebRequestContext::setUserAgent(String string) { + // The useragent is set on the WebCore thread and read on the network + // stack's IO thread. AutoLock aLock(userAgentLock); userAgent = string.utf8().data(); } const std::string& WebRequestContext::GetUserAgent(const GURL& url) const { + // The useragent is set on the WebCore thread and read on the network + // stack's IO thread. AutoLock aLock(userAgentLock); ASSERT(userAgent != ""); return userAgent; } -void WebRequestContext::SetAcceptLanguage(WTF::String string) +void WebRequestContext::setAcceptLanguage(String string) { + // The accept language is set on the WebCore thread and read on the network + // stack's IO thread. AutoLock aLock(acceptLanguageLock); acceptLanguage = string.utf8().data(); } const std::string& WebRequestContext::GetAcceptLanguage() const { + // The accept language is set on the WebCore thread and read on the network + // stack's IO thread. AutoLock aLock(acceptLanguageLock); return acceptLanguage; } -const std::string& WebRequestContext::GetDatabaseDirectory() +static const std::string& getDatabaseDirectory() { static std::string databaseDirectory; if (databaseDirectory.empty()) { @@ -112,7 +122,7 @@ const std::string& WebRequestContext::GetDatabaseDirectory() return databaseDirectory; } -const std::string& WebRequestContext::GetCacheDirectory() +static const std::string& getCacheDirectory() { static std::string cacheDirectory; if (cacheDirectory.empty()) { @@ -131,57 +141,57 @@ const std::string& WebRequestContext::GetCacheDirectory() return cacheDirectory; } -WebRequestContext* WebRequestContext::GetAndroidContextForPath(const char* cookieFilename, const char* cacheFilename) +WebRequestContext* WebRequestContext::getContextForPath(const char* cookieFilename, const char* cacheFilename) { - std::string cookieString(GetDatabaseDirectory()); + std::string cookieString(getDatabaseDirectory()); cookieString.append(cookieFilename); FilePath cookiePath(cookieString.c_str()); - std::string cacheString(GetCacheDirectory()); + std::string cacheString(getCacheDirectory()); cacheString.append(cacheFilename); FilePath cachePath(cacheString.c_str()); - WebRequestContext* androidContext = new WebRequestContext(); - androidContext->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0); + WebRequestContext* context = new WebRequestContext(); + context->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0); base::Thread* ioThread = WebUrlLoaderClient::ioThread(); scoped_refptr<base::MessageLoopProxy> cacheMessageLoopProxy = ioThread->message_loop_proxy(); // Todo: check if the context takes ownership of the cache net::HttpCache::DefaultBackend* defaultBackend = new net::HttpCache::DefaultBackend(net::DISK_CACHE, cachePath, 20 * 1024 * 1024, cacheMessageLoopProxy); - androidContext->http_transaction_factory_ = new net::HttpCache(androidContext->host_resolver(), net::ProxyService::CreateDirect(), net::SSLConfigService::CreateSystemSSLConfigService(), net::HttpAuthHandlerFactory::CreateDefault(androidContext->host_resolver_), 0, 0, defaultBackend); + context->http_transaction_factory_ = new net::HttpCache(context->host_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 + // This is needed for the page cycler. See http://b/2944150 net::CookieMonster::EnableFileScheme(); - androidContext->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0); + context->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0); - return androidContext; + return context; } -URLRequestContext* WebRequestContext::GetAndroidContext() +WebRequestContext* WebRequestContext::getRegularContext() { - static scoped_refptr<URLRequestContext> androidContext(0); - if (!androidContext) - androidContext = GetAndroidContextForPath(kCookiesDatabaseFilename, kCacheDirectory); - return androidContext; + static scoped_refptr<WebRequestContext> regularContext(0); + if (!regularContext) + regularContext = getContextForPath(kCookiesDatabaseFilename, kCacheDirectory); + return regularContext; } -URLRequestContext* WebRequestContext::GetAndroidPrivateBrowsingContext() +WebRequestContext* WebRequestContext::getPrivateBrowsingContext() { - WTF::MutexLocker lock(androidPrivateBrowsingContextMutex); + MutexLocker lock(privateBrowsingContextMutex); - if (!androidPrivateBrowsingContext) { + if (!privateBrowsingContext) { // TODO: Where is the right place to put the temporary db? Should it be // kept in memory? - androidPrivateBrowsingContext = GetAndroidContextForPath(kCookiesDatabaseFilenamePrivate, kCacheDirectoryPrivate); + privateBrowsingContext = getContextForPath(kCookiesDatabaseFilenamePrivate, kCacheDirectoryPrivate); } - return androidPrivateBrowsingContext; + return privateBrowsingContext; } -URLRequestContext* WebRequestContext::GetContext(bool isPrivateBrowsing) +WebRequestContext* WebRequestContext::get(bool isPrivateBrowsing) { - return isPrivateBrowsing ? GetAndroidPrivateBrowsingContext() : GetAndroidContext(); + return isPrivateBrowsing ? getPrivateBrowsingContext() : getRegularContext(); } static void removeFileOrDirectory(const char* filename) @@ -208,12 +218,13 @@ static void removeFileOrDirectory(const char* filename) unlink(filename); } -bool WebRequestContext::CleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory) +bool WebRequestContext::cleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory) { - WTF::MutexLocker lock(androidPrivateBrowsingContextMutex); + // This is called on the UI thread. + MutexLocker lock(privateBrowsingContextMutex); - if (!androidPrivateBrowsingContext || androidPrivateBrowsingContext->HasOneRef()) { - androidPrivateBrowsingContext = 0; + if (!privateBrowsingContext || privateBrowsingContext->HasOneRef()) { + privateBrowsingContext = 0; std::string cookiePath(databaseDirectory); cookiePath.append(kCookiesDatabaseFilenamePrivate); diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.h b/WebKit/android/WebCoreSupport/WebRequestContext.h index c9059c0..3f5631f 100644 --- a/WebKit/android/WebCoreSupport/WebRequestContext.h +++ b/WebKit/android/WebCoreSupport/WebRequestContext.h @@ -26,8 +26,6 @@ #ifndef WebRequestContext_h #define WebRequestContext_h -// Cannot forward declare the chrome classes since this is -// a subclass of a chrome class. #include "ChromiumIncludes.h" #include "PlatformString.h" @@ -35,25 +33,25 @@ namespace android { class WebRequestContext : public URLRequestContext { public: - virtual const std::string& GetUserAgent(const GURL& url) const; + // URLRequestContext overrides. + virtual const std::string& GetUserAgent(const GURL&) const; virtual const std::string& GetAcceptLanguage() const; // Lazily create the relevant context. This class holds a reference. - static URLRequestContext* GetContext(bool isPrivateBrowsing); + static WebRequestContext* get(bool isPrivateBrowsing); - static bool CleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory); - - static void SetUserAgent(WTF::String); - static void SetAcceptLanguage(WTF::String); + // These methods are threadsafe. + static bool cleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory); + static void setUserAgent(WTF::String); + static void setAcceptLanguage(WTF::String); private: - static URLRequestContext* GetAndroidContext(); - static URLRequestContext* GetAndroidPrivateBrowsingContext(); - static const std::string& GetDatabaseDirectory(); - static const std::string& GetCacheDirectory(); - static WebRequestContext* GetAndroidContextForPath(const char* cookiePath, const char* cachePath); WebRequestContext(); ~WebRequestContext(); + + static WebRequestContext* getContextForPath(const char* cookieFilename, const char* cacheFilename); + static WebRequestContext* getRegularContext(); + static WebRequestContext* getPrivateBrowsingContext(); }; } // namespace android diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp index 26c377e..ef9d598 100644 --- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp +++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp @@ -49,9 +49,9 @@ namespace android { -static URLRequestContext* WebAutoFillContextGetter() +static URLRequestContext* webAutoFillContextGetter() { - return WebRequestContext::GetContext(false /* isPrivateBrowsing */); + return WebRequestContext::get(false /* isPrivateBrowsing */); } WebAutoFill::WebAutoFill() @@ -60,7 +60,7 @@ WebAutoFill::WebAutoFill() mFormManager = new FormManager(); mQueryId = 1; - AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&WebAutoFillContextGetter); + AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&webAutoFillContextGetter); AndroidURLRequestContextGetter::Get()->SetIOThread(WebUrlLoaderClient::ioThread()); mTabContents = new TabContents(); mAutoFillManager = new AutoFillManager(mTabContents.get()); |