summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2021-06-02 19:40:10 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-25 05:23:05 +0000
commit5616249d243fda35312def89424a8ad62f1b9bce (patch)
treeb899e93efaee5f08ebb29b720604a62ac24a62d1
parentd8d02172a12a6cd2f66aee9c90b6f0ef85221e92 (diff)
Make default profile off the record
Make default profile otr, this prevents accessing data cache which could be created by older other version of Chromium. Allow to register a protocol handler on ort profile. [ChangeLog][QtWebEngineCore] Default profile is off-the-record Off-the-record profile can have registered protocol handlers. Task-number: QTBUG-66068 Change-Id: Ief202de5c6734d293cb64d83ad447b1eba19e9a4 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit d0ff107c0096fa0e0347ddadda9a98438d27631e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.cpp12
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.h2
-rw-r--r--src/core/api/qwebengineprofile.cpp2
-rw-r--r--src/core/web_contents_delegate_qt.cpp4
-rw-r--r--src/core/web_engine_context.cpp2
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp80
6 files changed, 45 insertions, 57 deletions
diff --git a/examples/webenginewidgets/simplebrowser/browser.cpp b/examples/webenginewidgets/simplebrowser/browser.cpp
index 68458b2a4..f5f7e6fc1 100644
--- a/examples/webenginewidgets/simplebrowser/browser.cpp
+++ b/examples/webenginewidgets/simplebrowser/browser.cpp
@@ -63,13 +63,13 @@ Browser::Browser()
BrowserWindow *Browser::createWindow(bool offTheRecord)
{
- if (offTheRecord && !m_otrProfile) {
- m_otrProfile.reset(new QWebEngineProfile);
- QObject::connect(
- m_otrProfile.get(), &QWebEngineProfile::downloadRequested,
- &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
+ if (!offTheRecord && !m_profile) {
+ m_profile.reset(new QWebEngineProfile(
+ QString::fromLatin1("simplebrowser.%1").arg(qWebEngineChromiumVersion())));
+ QObject::connect(m_profile.get(), &QWebEngineProfile::downloadRequested,
+ &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
}
- auto profile = offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile();
+ auto profile = !offTheRecord ? m_profile.get() : QWebEngineProfile::defaultProfile();
auto mainWindow = new BrowserWindow(this, profile, false);
m_windows.append(mainWindow);
QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
diff --git a/examples/webenginewidgets/simplebrowser/browser.h b/examples/webenginewidgets/simplebrowser/browser.h
index cb84ea670..2296eda9a 100644
--- a/examples/webenginewidgets/simplebrowser/browser.h
+++ b/examples/webenginewidgets/simplebrowser/browser.h
@@ -73,6 +73,6 @@ public:
private:
QList<BrowserWindow*> m_windows;
DownloadManagerWidget m_downloadManagerWidget;
- QScopedPointer<QWebEngineProfile> m_otrProfile;
+ QScopedPointer<QWebEngineProfile> m_profile;
};
#endif // BROWSER_H
diff --git a/src/core/api/qwebengineprofile.cpp b/src/core/api/qwebengineprofile.cpp
index 29edc3afb..4074a4c31 100644
--- a/src/core/api/qwebengineprofile.cpp
+++ b/src/core/api/qwebengineprofile.cpp
@@ -666,7 +666,7 @@ std::function<void(std::unique_ptr<QWebEngineNotification>)> QWebEngineProfile::
/*!
Returns the default profile.
- The default profile uses the storage name "Default".
+ The default profile is off-the-record.
\sa storageName()
*/
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index a04ef700b..afa48a5b1 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -794,8 +794,6 @@ bool WebContentsDelegateQt::CheckMediaAccessPermission(content::RenderFrameHost
void WebContentsDelegateQt::RegisterProtocolHandler(content::RenderFrameHost *frameHost, const std::string &protocol, const GURL &url, bool)
{
content::BrowserContext *context = frameHost->GetBrowserContext();
- if (context->IsOffTheRecord())
- return;
ProtocolHandler handler =
ProtocolHandler::CreateProtocolHandler(protocol, url);
@@ -813,8 +811,6 @@ void WebContentsDelegateQt::RegisterProtocolHandler(content::RenderFrameHost *fr
void WebContentsDelegateQt::UnregisterProtocolHandler(content::RenderFrameHost *frameHost, const std::string &protocol, const GURL &url, bool)
{
content::BrowserContext* context = frameHost->GetBrowserContext();
- if (context->IsOffTheRecord())
- return;
ProtocolHandler handler =
ProtocolHandler::CreateProtocolHandler(protocol, url);
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 83abd17b6..3806d3e7e 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -525,7 +525,7 @@ ProfileAdapter *WebEngineContext::createDefaultProfileAdapter()
{
Q_ASSERT(!m_destroyed);
if (!m_defaultProfileAdapter) {
- ProfileAdapter *profile = new ProfileAdapter(QStringLiteral("Default"));
+ ProfileAdapter *profile = new ProfileAdapter();
// profile when added to m_profileAdapters might be set default
// profile in case of single-process
if (!m_defaultProfileAdapter)
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index fb0425893..c75715ae8 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -57,9 +57,8 @@ class tst_QWebEngineProfile : public QObject
private Q_SLOTS:
void initTestCase();
- void init();
- void cleanup();
- void privateProfile();
+ void userDefaultProfile();
+ void defaultProfile();
void testProfile();
void clearDataFromCache();
void disableCache();
@@ -105,48 +104,41 @@ void tst_QWebEngineProfile::initTestCase()
QWebEngineUrlScheme::registerScheme(myscheme);
}
-void tst_QWebEngineProfile::init()
+void tst_QWebEngineProfile::userDefaultProfile()
{
- //make sure defualt global profile is 'default' across all the tests
- QWebEngineProfile *profile = QWebEngineProfile::defaultProfile();
- QVERIFY(profile);
- QVERIFY(!profile->isOffTheRecord());
- QCOMPARE(profile->storageName(), QStringLiteral("Default"));
- QCOMPARE(profile->httpCacheType(), QWebEngineProfile::DiskHttpCache);
- QCOMPARE(profile->persistentCookiesPolicy(), QWebEngineProfile::AllowPersistentCookies);
- QCOMPARE(profile->cachePath(), QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
- + QStringLiteral("/QtWebEngine/Default"));
- QCOMPARE(profile->persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
- + QStringLiteral("/QtWebEngine/Default"));
+ QWebEngineProfile profile("Default");
+ QVERIFY(!profile.isOffTheRecord());
+ QCOMPARE(profile.storageName(), QStringLiteral("Default"));
+ QCOMPARE(profile.httpCacheType(), QWebEngineProfile::DiskHttpCache);
+ QCOMPARE(profile.persistentCookiesPolicy(), QWebEngineProfile::AllowPersistentCookies);
+ QCOMPARE(profile.cachePath(),
+ QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
+ + QStringLiteral("/QtWebEngine/Default"));
+ QCOMPARE(profile.persistentStoragePath(),
+ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+ + QStringLiteral("/QtWebEngine/Default"));
}
-void tst_QWebEngineProfile::cleanup()
+void tst_QWebEngineProfile::defaultProfile()
{
QWebEngineProfile *profile = QWebEngineProfile::defaultProfile();
- profile->setCachePath(QString());
- profile->setPersistentStoragePath(QString());
- profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- profile->removeAllUrlSchemeHandlers();
-}
-
-void tst_QWebEngineProfile::privateProfile()
-{
- QWebEngineProfile otrProfile;
- QVERIFY(otrProfile.isOffTheRecord());
- QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache);
- QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
- QCOMPARE(otrProfile.cachePath(), QString());
- QCOMPARE(otrProfile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
- + QStringLiteral("/QtWebEngine/OffTheRecord"));
+ QVERIFY(profile);
+ QVERIFY(profile->isOffTheRecord());
+ QCOMPARE(profile->httpCacheType(), QWebEngineProfile::MemoryHttpCache);
+ QCOMPARE(profile->persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
+ QCOMPARE(profile->cachePath(), QString());
+ QCOMPARE(profile->persistentStoragePath(),
+ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+ + 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(), QStringLiteral("/home/foo/bar"));
- otrProfile.setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache);
- otrProfile.setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
- QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
+ profile->setCachePath(QStringLiteral("/home/foo/bar"));
+ QCOMPARE(profile->cachePath(), QString());
+ profile->setPersistentStoragePath(QStringLiteral("/home/foo/bar"));
+ QCOMPARE(profile->persistentStoragePath(), QStringLiteral("/home/foo/bar"));
+ profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
+ QCOMPARE(profile->httpCacheType(), QWebEngineProfile::MemoryHttpCache);
+ profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
+ QCOMPARE(profile->persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
}
@@ -255,18 +247,18 @@ void tst_QWebEngineProfile::disableCache()
AutoDir cacheDir("./tst_QWebEngineProfile_disableCache");
- QWebEnginePage page;
- QWebEngineProfile *profile = page.profile();
- profile->setCachePath(cacheDir.path());
+ QWebEngineProfile profile("disableCache");
+ QWebEnginePage page(&profile);
+ profile.setCachePath(cacheDir.path());
QVERIFY(!cacheDir.exists("Cache"));
- profile->setHttpCacheType(QWebEngineProfile::NoCache);
+ profile.setHttpCacheType(QWebEngineProfile::NoCache);
// Wait for cache to be cleared.
QTest::qWait(1000);
QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
QVERIFY(!cacheDir.exists("Cache"));
- profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
+ profile.setHttpCacheType(QWebEngineProfile::DiskHttpCache);
QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
QVERIFY(cacheDir.exists("Cache"));