summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-06-23 13:11:58 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-06-29 09:17:28 +0200
commitf341988f451c6ba1fc3b8da765c00d1d64eaff30 (patch)
tree407e1f7d121c19d20006ec7e143210a0aea7ef92
parent1a26c0ace958c3604c8a751134429dd38168a1a1 (diff)
Return valid path in Profile::GetPath() for incognito profiles
Parts of Chromium depends on it for temporary directories it creates. This also changes the logic of depending on it being empty as indicating an in memory profile, so it required a bit of cleaning up. Note this does subtly change the return value of off-the-record profiles. Task-number: QTBUG-62957 Change-Id: Iec6e24556128c515fce27803171a766b8a9d92e3 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
-rw-r--r--src/core/devtools_frontend_qt.cpp3
-rw-r--r--src/core/pref_service_adapter.cpp2
-rw-r--r--src/core/profile_adapter.cpp30
-rw-r--r--src/core/profile_io_data_qt.cpp8
-rw-r--r--src/core/profile_io_data_qt.h2
-rw-r--r--src/core/web_engine_context.cpp2
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp5
7 files changed, 30 insertions, 22 deletions
diff --git a/src/core/devtools_frontend_qt.cpp b/src/core/devtools_frontend_qt.cpp
index 52d7dc669..8070d1c98 100644
--- a/src/core/devtools_frontend_qt.cpp
+++ b/src/core/devtools_frontend_qt.cpp
@@ -339,7 +339,8 @@ void DevToolsFrontendQt::RemovePreference(const std::string &name)
void DevToolsFrontendQt::ClearPreferences()
{
- if (web_contents()->GetBrowserContext()->IsOffTheRecord())
+ ProfileQt *profile = static_cast<ProfileQt *>(web_contents()->GetBrowserContext());
+ if (profile->IsOffTheRecord() || profile->profileAdapter()->storageName().isEmpty())
m_prefStore = scoped_refptr<PersistentPrefStore>(new InMemoryPrefStore());
else
CreateJsonPreferences(true);
diff --git a/src/core/pref_service_adapter.cpp b/src/core/pref_service_adapter.cpp
index 4ded70d07..65dfb73ee 100644
--- a/src/core/pref_service_adapter.cpp
+++ b/src/core/pref_service_adapter.cpp
@@ -85,7 +85,7 @@ void PrefServiceAdapter::setup(const ProfileAdapter &profileAdapter)
WebEngineContext::commandLine()));
QString userPrefStorePath = profileAdapter.dataPath();
- if (userPrefStorePath.isEmpty() || profileAdapter.isOffTheRecord()) {
+ if (profileAdapter.isOffTheRecord() || profileAdapter.storageName().isEmpty()) {
factory.set_user_prefs(new InMemoryPrefStore);
} else {
userPrefStorePath += QDir::separator();
diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp
index 4557ad7a4..c436c8277 100644
--- a/src/core/profile_adapter.cpp
+++ b/src/core/profile_adapter.cpp
@@ -245,13 +245,17 @@ QObject* ProfileAdapter::globalQObjectRoot()
QString ProfileAdapter::dataPath() const
{
- if (m_offTheRecord)
- return QString();
if (!m_dataPath.isEmpty())
return m_dataPath;
- if (!m_name.isNull())
- return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation), m_name);
- return QString();
+ // And off-the-record or memory-only profile should not write to disk
+ // but Chromium often creates temporary directories anyway, so given them
+ // a location to do so.
+ QString name = m_name;
+ if (m_offTheRecord)
+ name = QStringLiteral("OffTheRecord");
+ else if (m_name.isEmpty())
+ name = QStringLiteral("UnknownProfile");
+ return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation), name);
}
void ProfileAdapter::setDataPath(const QString &path)
@@ -259,13 +263,11 @@ void ProfileAdapter::setDataPath(const QString &path)
if (m_dataPath == path)
return;
m_dataPath = path;
- if (!m_offTheRecord) {
- m_profile->setupPrefService();
- if (!m_profile->m_profileIOData->isClearHttpCacheInProgress())
- m_profile->m_profileIOData->resetNetworkContext();
- if (m_visitedLinksManager)
- resetVisitedLinksManager();
- }
+ m_profile->setupPrefService();
+ if (!m_profile->m_profileIOData->isClearHttpCacheInProgress())
+ m_profile->m_profileIOData->resetNetworkContext();
+ if (!m_offTheRecord && m_visitedLinksManager)
+ resetVisitedLinksManager();
}
void ProfileAdapter::setDownloadPath(const QString &path)
@@ -353,7 +355,7 @@ void ProfileAdapter::setHttpCacheType(ProfileAdapter::HttpCacheType newhttpCache
ProfileAdapter::PersistentCookiesPolicy ProfileAdapter::persistentCookiesPolicy() const
{
- if (isOffTheRecord() || dataPath().isEmpty())
+ if (isOffTheRecord() || m_name.isEmpty())
return NoPersistentCookies;
return m_persistentCookiesPolicy;
}
@@ -372,7 +374,7 @@ ProfileAdapter::VisitedLinksPolicy ProfileAdapter::visitedLinksPolicy() const
{
if (isOffTheRecord() || m_visitedLinksPolicy == DoNotTrackVisitedLinks)
return DoNotTrackVisitedLinks;
- if (dataPath().isEmpty())
+ if (m_name.isEmpty())
return TrackVisitedLinksInMemory;
return m_visitedLinksPolicy;
}
diff --git a/src/core/profile_io_data_qt.cpp b/src/core/profile_io_data_qt.cpp
index ecebbdaa7..02912e35e 100644
--- a/src/core/profile_io_data_qt.cpp
+++ b/src/core/profile_io_data_qt.cpp
@@ -179,6 +179,8 @@ void ProfileIODataQt::setFullConfiguration()
m_httpCacheMaxSize = m_profileAdapter->httpCacheMaxSize();
m_useForGlobalCertificateVerification = m_profileAdapter->isUsedForGlobalCertificateVerification();
m_dataPath = m_profileAdapter->dataPath();
+ m_storageName = m_profileAdapter->storageName();
+ m_inMemoryOnly = m_profileAdapter->isOffTheRecord() || m_storageName.isEmpty();
}
void ProfileIODataQt::resetNetworkContext()
@@ -221,7 +223,7 @@ network::mojom::NetworkContextParamsPtr ProfileIODataQt::CreateNetworkContextPar
network::mojom::NetworkContextParamsPtr network_context_params =
SystemNetworkContextManager::GetInstance()->CreateDefaultNetworkContextParams();
- network_context_params->context_name = m_profile->profileAdapter()->storageName().toStdString();
+ network_context_params->context_name = m_storageName.toStdString();
network_context_params->user_agent = m_httpUserAgent.toStdString();
network_context_params->accept_language = m_httpAcceptLanguage.toStdString();
@@ -234,7 +236,7 @@ network::mojom::NetworkContextParamsPtr ProfileIODataQt::CreateNetworkContextPar
if (m_httpCacheType == ProfileAdapter::DiskHttpCache && !m_httpCachePath.isEmpty())
network_context_params->http_cache_path = toFilePath(m_httpCachePath);
- if (m_persistentCookiesPolicy != ProfileAdapter::NoPersistentCookies && !m_dataPath.isEmpty()) {
+ if (m_persistentCookiesPolicy != ProfileAdapter::NoPersistentCookies && !m_inMemoryOnly) {
base::FilePath cookie_path = toFilePath(m_dataPath);
cookie_path = cookie_path.AppendASCII("Cookies");
network_context_params->cookie_path = cookie_path;
@@ -242,7 +244,7 @@ network::mojom::NetworkContextParamsPtr ProfileIODataQt::CreateNetworkContextPar
network_context_params->restore_old_session_cookies = m_persistentCookiesPolicy == ProfileAdapter::ForcePersistentCookies;
network_context_params->persist_session_cookies = m_persistentCookiesPolicy != ProfileAdapter::NoPersistentCookies;
}
- if (!m_dataPath.isEmpty()) {
+ if (!m_inMemoryOnly) {
network_context_params->http_server_properties_path = toFilePath(m_dataPath).AppendASCII("Network Persistent State");
network_context_params->transport_security_persister_path = toFilePath(m_dataPath);
}
diff --git a/src/core/profile_io_data_qt.h b/src/core/profile_io_data_qt.h
index b0567dead..00d2c392c 100644
--- a/src/core/profile_io_data_qt.h
+++ b/src/core/profile_io_data_qt.h
@@ -133,6 +133,8 @@ private:
QString m_httpUserAgent;
ProfileAdapter::HttpCacheType m_httpCacheType;
QString m_httpCachePath;
+ QString m_storageName;
+ bool m_inMemoryOnly;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex m_mutex{QMutex::Recursive};
using QRecursiveMutex = QMutex;
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index a28e469a3..b36e76417 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -324,7 +324,7 @@ void WebEngineContext::addProfileAdapter(ProfileAdapter *profileAdapter)
{
Q_ASSERT(!m_profileAdapters.contains(profileAdapter));
const QString path = profileAdapter->dataPath();
- if (!path.isEmpty()) {
+ if (!profileAdapter->isOffTheRecord() && !profileAdapter->storageName().isEmpty()) {
for (auto profileAdapter : m_profileAdapters) {
if (profileAdapter->dataPath() == path) {
// QTBUG-66068
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 00d4bae5a..836f1885e 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -136,12 +136,13 @@ void tst_QWebEngineProfile::privateProfile()
QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache);
QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
QCOMPARE(otrProfile.cachePath(), QString());
- QCOMPARE(otrProfile.persistentStoragePath(), QString());
+ QCOMPARE(otrProfile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ + QStringLiteral("/QtWebEngine/OffTheRecord"));
// TBD: setters do not really work
otrProfile.setCachePath(QStringLiteral("/home/foo/bar"));
QCOMPARE(otrProfile.cachePath(), QString());
otrProfile.setPersistentStoragePath(QStringLiteral("/home/foo/bar"));
- QCOMPARE(otrProfile.persistentStoragePath(), QString());
+ QCOMPARE(otrProfile.persistentStoragePath(), QStringLiteral("/home/foo/bar"));
otrProfile.setHttpCacheType(QWebEngineProfile::DiskHttpCache);
QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache);
otrProfile.setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);