diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-11-25 17:16:23 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2014-12-03 14:04:54 +0100 |
commit | 065a197007038ea02f0c72bdb592cd26edd4d20a (patch) | |
tree | 81cab628bd953c68385e0c93571991f9cd9c187d /src | |
parent | 9fb7bb8a3a2316fb447a612f1194947f9d65186c (diff) |
Use in-memory caches for off-the-record browsing
Off the record should leave no record, which means we should not use
disk storage for cookies and cache but instead trigger memory caching.
Change-Id: I3e14ed0f91f925bc65675d2e7d9f07eb379a30b0
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/browser_context_qt.cpp | 2 | ||||
-rw-r--r-- | src/core/url_request_context_getter_qt.cpp | 48 | ||||
-rw-r--r-- | src/core/url_request_context_getter_qt.h | 7 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 2 |
4 files changed, 38 insertions, 21 deletions
diff --git a/src/core/browser_context_qt.cpp b/src/core/browser_context_qt.cpp index 8dc4a3da2..2484ba879 100644 --- a/src/core/browser_context_qt.cpp +++ b/src/core/browser_context_qt.cpp @@ -128,7 +128,7 @@ content::PushMessagingService *BrowserContextQt::GetPushMessagingService() net::URLRequestContextGetter *BrowserContextQt::CreateRequestContext(content::ProtocolHandlerMap *protocol_handlers) { - url_request_getter_ = new URLRequestContextGetterQt(GetPath(), GetCachePath(), protocol_handlers); + url_request_getter_ = new URLRequestContextGetterQt(this, protocol_handlers); static_cast<ResourceContextQt*>(resourceContext.get())->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 8ec600a85..282e5e94f 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -61,18 +61,18 @@ #include "net/url_request/ftp_protocol_handler.h" #include "net/ftp/ftp_network_layer.h" -#include "network_delegate_qt.h" +#include "browser_context_qt.h" #include "content_client_qt.h" +#include "network_delegate_qt.h" #include "qrc_protocol_handler_qt.h" static const char kQrcSchemeQt[] = "qrc"; using content::BrowserThread; -URLRequestContextGetterQt::URLRequestContextGetterQt(const base::FilePath &dataPath, const base::FilePath &cachePath, content::ProtocolHandlerMap *protocolHandlers) +URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextQt *browserContext, content::ProtocolHandlerMap *protocolHandlers) : m_ignoreCertificateErrors(false) - , m_dataPath(dataPath) - , m_cachePath(cachePath) + , m_browserContext(browserContext) { std::swap(m_protocolHandlers, *protocolHandlers); @@ -94,9 +94,13 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() m_urlRequestContext->set_network_delegate(m_networkDelegate.get()); - base::FilePath cookiesPath = m_dataPath.Append(FILE_PATH_LITERAL("Cookies")); - content::CookieStoreConfig cookieStoreConfig(cookiesPath, content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, NULL, NULL); - scoped_refptr<net::CookieStore> cookieStore = content::CreateCookieStore(cookieStoreConfig); + scoped_refptr<net::CookieStore> cookieStore; + if (m_browserContext->IsOffTheRecord()) { + cookieStore = content::CreateCookieStore(content::CookieStoreConfig(base::FilePath(), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, NULL, NULL)); + } else { + base::FilePath cookiesPath = m_browserContext->GetPath().Append(FILE_PATH_LITERAL("Cookies")); + cookieStore = content::CreateCookieStore(content::CookieStoreConfig(cookiesPath, content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, NULL, NULL)); + } m_storage.reset(new net::URLRequestContextStorage(m_urlRequestContext.get())); m_storage->set_cookie_store(cookieStore.get()); @@ -120,15 +124,27 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); m_storage->set_http_server_properties(scoped_ptr<net::HttpServerProperties>(new net::HttpServerPropertiesImpl)); - base::FilePath cache_path = m_cachePath.Append(FILE_PATH_LITERAL("Cache")); - net::HttpCache::DefaultBackend* main_backend = - new net::HttpCache::DefaultBackend( - net::DISK_CACHE, - net::CACHE_BACKEND_DEFAULT, - cache_path, - 0, - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::CACHE)); + net::HttpCache::DefaultBackend* main_backend; + if (m_browserContext->IsOffTheRecord()) { + main_backend = + new net::HttpCache::DefaultBackend( + net::MEMORY_CACHE, + net::CACHE_BACKEND_DEFAULT, + base::FilePath(), + 0, + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::CACHE)); + } else { + base::FilePath cache_path = m_browserContext->GetCachePath().Append(FILE_PATH_LITERAL("Cache")); + main_backend = + new net::HttpCache::DefaultBackend( + net::DISK_CACHE, + net::CACHE_BACKEND_DEFAULT, + cache_path, + 0, + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::CACHE)); + } net::HttpNetworkSession::Params network_session_params; network_session_params.transport_security_state = diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h index 6c9ac6d59..2c42322bd 100644 --- a/src/core/url_request_context_getter_qt.h +++ b/src/core/url_request_context_getter_qt.h @@ -56,9 +56,11 @@ class NetworkDelegate; class ProxyConfigService; } +class BrowserContextQt; + class URLRequestContextGetterQt : public net::URLRequestContextGetter { public: - explicit URLRequestContextGetterQt(const base::FilePath &, const base::FilePath &, content::ProtocolHandlerMap *protocolHandlers); + explicit URLRequestContextGetterQt(BrowserContextQt *browserContext, content::ProtocolHandlerMap *protocolHandlers); virtual net::URLRequestContext *GetURLRequestContext() Q_DECL_OVERRIDE; virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const Q_DECL_OVERRIDE; @@ -67,8 +69,7 @@ private: virtual ~URLRequestContextGetterQt() {} bool m_ignoreCertificateErrors; - base::FilePath m_dataPath; - base::FilePath m_cachePath; + BrowserContextQt *m_browserContext; content::ProtocolHandlerMap m_protocolHandlers; scoped_ptr<net::ProxyConfigService> m_proxyConfigService; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 46830f865..a2d548fc7 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -269,7 +269,7 @@ void WebContentsDelegateQt::UpdateTargetURL(content::WebContents *source, int32 void WebContentsDelegateQt::DidNavigateAnyFrame(const content::LoadCommittedDetails &, const content::FrameNavigateParams ¶ms) { - if (!params.should_update_history) + if (!params.should_update_history || m_viewClient->browserContextAdapter()->isOffTheRecord()) return; m_viewClient->browserContextAdapter()->visitedLinksManager()->addUrl(params.url); } |