diff options
author | Steve Block <steveblock@google.com> | 2010-10-20 17:24:30 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-10-21 11:49:39 +0100 |
commit | f6c40294adb5fce93668a0e92e8731e21752a1df (patch) | |
tree | f1d852cdea4735d70f7c15cbf75ce709642e8ecf /WebKit | |
parent | 0fe675d3b8a2b02feaf6720e30bc0a9270a8072a (diff) | |
download | external_webkit-f6c40294adb5fce93668a0e92e8731e21752a1df.zip external_webkit-f6c40294adb5fce93668a0e92e8731e21752a1df.tar.gz external_webkit-f6c40294adb5fce93668a0e92e8731e21752a1df.tar.bz2 |
Fix Chromium HTTP request context getters to use raw pointers
All call sites into the Chromium stack take raw pointers rather than
scoped_refptr, so we should do the same for simplicity. This change
also makes the ownership model more clear.
Previously we were sometimes throwing away the scoped_refptr and using
the raw pointer, which is unsafe unless you know that somebody else
holds a reference.
Requires a change to external/chromium ...
https://android-git.corp.google.com/g/75220
Change-Id: I09c86d424193a3f3c2644bcf77a2d363fa24293b
Diffstat (limited to 'WebKit')
-rw-r--r-- | WebKit/android/WebCoreSupport/PlatformBridge.cpp | 16 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCache.cpp | 2 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequest.cpp | 6 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequestContext.cpp | 15 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequestContext.h | 10 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp | 2 |
6 files changed, 24 insertions, 27 deletions
diff --git a/WebKit/android/WebCoreSupport/PlatformBridge.cpp b/WebKit/android/WebCoreSupport/PlatformBridge.cpp index ddcdb7f..7a5369a 100644 --- a/WebKit/android/WebCoreSupport/PlatformBridge.cpp +++ b/WebKit/android/WebCoreSupport/PlatformBridge.cpp @@ -71,12 +71,8 @@ void PlatformBridge::setCookies(const Document* document, const KURL& url, const #if USE(CHROME_NETWORK_STACK) std::string cookieValue(value.utf8().data()); GURL cookieGurl(url.string().utf8().data()); - URLRequestContext* androidContext; - if (document->settings() && document->settings()->privateBrowsingEnabled()) - androidContext = WebRequestContext::GetAndroidPrivateBrowsingContext(); - else - androidContext = WebRequestContext::GetAndroidContext(); - androidContext->cookie_store()->SetCookie(cookieGurl, cookieValue); + bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled(); + WebRequestContext::GetContext(isPrivateBrowsing)->cookie_store()->SetCookie(cookieGurl, cookieValue); #else CookieClient* client = JavaSharedClient::GetCookieClient(); if (!client) @@ -90,12 +86,8 @@ String PlatformBridge::cookies(const Document* document, const KURL& url) { #if USE(CHROME_NETWORK_STACK) GURL cookieGurl(url.string().utf8().data()); - URLRequestContext* androidContext; - if (document->settings() && document->settings()->privateBrowsingEnabled()) - androidContext = WebRequestContext::GetAndroidPrivateBrowsingContext(); - else - androidContext = WebRequestContext::GetAndroidContext(); - std::string cookies = androidContext->cookie_store()->GetCookies(cookieGurl); + bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled(); + std::string cookies = WebRequestContext::GetContext(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 006bb74..b46e180 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::GetAndroidContext(); + URLRequestContext* context = WebRequestContext::GetContext(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 0e3149d..77e1acb 100644 --- a/WebKit/android/WebCoreSupport/WebRequest.cpp +++ b/WebKit/android/WebCoreSupport/WebRequest.cpp @@ -140,11 +140,7 @@ void WebRequest::start(bool isPrivateBrowsing) if (m_request->url().SchemeIs("browser")) return handleBrowserURL(m_request->url()); - scoped_refptr<URLRequestContext> context; - if (!isPrivateBrowsing) - context = WebRequestContext::GetAndroidContext(); - else - context = WebRequestContext::GetAndroidPrivateBrowsingContext(); + URLRequestContext* context = WebRequestContext::GetContext(isPrivateBrowsing); m_request->set_context(context); m_request->Start(); diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp index b2a81c9..729a2eb 100644 --- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp +++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp @@ -55,7 +55,6 @@ static const char* const kCacheDirectory = "/webviewCacheChromium"; static const char* const kCookiesDatabaseFilenamePrivate = "/webviewCookiesChromiumPrivate.db"; static const char* const kCacheDirectoryPrivate = "/webviewCacheChromiumPrivate"; -static scoped_refptr<URLRequestContext> androidContext(0); static scoped_refptr<URLRequestContext> androidPrivateBrowsingContext(0); static WTF::Mutex androidPrivateBrowsingContextMutex; @@ -132,7 +131,7 @@ const std::string& WebRequestContext::GetCacheDirectory() return cacheDirectory; } -scoped_refptr<WebRequestContext> WebRequestContext::GetAndroidContextForPath(const char* cookieFilename, const char* cacheFilename) +WebRequestContext* WebRequestContext::GetAndroidContextForPath(const char* cookieFilename, const char* cacheFilename) { std::string cookieString(GetDatabaseDirectory()); cookieString.append(cookieFilename); @@ -141,7 +140,7 @@ scoped_refptr<WebRequestContext> WebRequestContext::GetAndroidContextForPath(con cacheString.append(cacheFilename); FilePath cachePath(cacheString.c_str()); - scoped_refptr<WebRequestContext> androidContext = new WebRequestContext(); + WebRequestContext* androidContext = new WebRequestContext(); androidContext->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0); base::Thread* ioThread = WebUrlLoaderClient::ioThread(); scoped_refptr<base::MessageLoopProxy> cacheMessageLoopProxy = ioThread->message_loop_proxy(); @@ -160,14 +159,15 @@ scoped_refptr<WebRequestContext> WebRequestContext::GetAndroidContextForPath(con return androidContext; } -scoped_refptr<URLRequestContext> WebRequestContext::GetAndroidContext() +URLRequestContext* WebRequestContext::GetAndroidContext() { + static scoped_refptr<URLRequestContext> androidContext(0); if (!androidContext) androidContext = GetAndroidContextForPath(kCookiesDatabaseFilename, kCacheDirectory); return androidContext; } -scoped_refptr<URLRequestContext> WebRequestContext::GetAndroidPrivateBrowsingContext() +URLRequestContext* WebRequestContext::GetAndroidPrivateBrowsingContext() { WTF::MutexLocker lock(androidPrivateBrowsingContextMutex); @@ -179,6 +179,11 @@ scoped_refptr<URLRequestContext> WebRequestContext::GetAndroidPrivateBrowsingCon return androidPrivateBrowsingContext; } +URLRequestContext* WebRequestContext::GetContext(bool isPrivateBrowsing) +{ + return isPrivateBrowsing ? GetAndroidPrivateBrowsingContext() : GetAndroidContext(); +} + static void removeFileOrDirectory(const char* filename) { struct stat filetype; diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.h b/WebKit/android/WebCoreSupport/WebRequestContext.h index 80b28a6..c9059c0 100644 --- a/WebKit/android/WebCoreSupport/WebRequestContext.h +++ b/WebKit/android/WebCoreSupport/WebRequestContext.h @@ -37,17 +37,21 @@ class WebRequestContext : public URLRequestContext { public: virtual const std::string& GetUserAgent(const GURL& url) const; virtual const std::string& GetAcceptLanguage() const; - static scoped_refptr<URLRequestContext> GetAndroidContext(); - static scoped_refptr<URLRequestContext> GetAndroidPrivateBrowsingContext(); + + // Lazily create the relevant context. This class holds a reference. + static URLRequestContext* GetContext(bool isPrivateBrowsing); + 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 scoped_refptr<WebRequestContext> GetAndroidContextForPath(const char* cookiePath, const char* cachePath); + static WebRequestContext* GetAndroidContextForPath(const char* cookiePath, const char* cachePath); WebRequestContext(); ~WebRequestContext(); }; diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp index ed42c7a..bc4ca05 100644 --- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp +++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp @@ -55,7 +55,7 @@ WebAutoFill::WebAutoFill() mFormManager = new FormManager(); mQueryId = 1; - AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&WebRequestContext::GetAndroidContext); + AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&WebRequestContext::GetContext); AndroidURLRequestContextGetter::Get()->SetIOThread(WebUrlLoaderClient::ioThread()); mTabContents = new TabContents(); mAutoFillManager = new AutoFillManager(mTabContents.get()); |