summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/browser_context_adapter.cpp6
-rw-r--r--src/core/browser_context_adapter.h2
-rw-r--r--src/core/url_request_context_getter_qt.cpp18
-rw-r--r--src/core/url_request_context_getter_qt.h2
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp14
-rw-r--r--src/webengine/api/qquickwebengineprofile_p.h1
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp11
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.h2
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp40
9 files changed, 96 insertions, 0 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index 7b40688a1..7d2d0478f 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -423,4 +423,10 @@ void BrowserContextAdapter::setHttpAcceptLanguage(const QString &httpAcceptLangu
m_httpAcceptLanguage = httpAcceptLanguage;
}
+void BrowserContextAdapter::clearHttpCache()
+{
+ if (m_browserContext->url_request_getter_.get())
+ m_browserContext->url_request_getter_->clearHttpCache();
+}
+
} // namespace QtWebEngineCore
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h
index 97a4dca4a..ee913b8cb 100644
--- a/src/core/browser_context_adapter.h
+++ b/src/core/browser_context_adapter.h
@@ -157,6 +157,8 @@ public:
QString httpAcceptLanguage() const;
void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
+ void clearHttpCache();
+
private:
QString m_name;
bool m_offTheRecord;
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp
index 121a103b0..4a2a63348 100644
--- a/src/core/url_request_context_getter_qt.cpp
+++ b/src/core/url_request_context_getter_qt.cpp
@@ -45,6 +45,7 @@
#include "content/public/common/content_switches.h"
#include "net/base/cache_type.h"
#include "net/cert/cert_verifier.h"
+#include "net/disk_cache/disk_cache.h"
#include "net/dns/host_resolver.h"
#include "net/dns/mapped_host_resolver.h"
#include "net/http/http_auth_handler_factory.h"
@@ -330,6 +331,23 @@ void URLRequestContextGetterQt::generateHttpCache()
m_storage->set_http_transaction_factory(scoped_ptr<net::HttpCache>(new net::HttpCache(network_session_params, main_backend)));
}
+void URLRequestContextGetterQt::clearHttpCache()
+{
+ if (m_urlRequestContext)
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::clearCurrentCacheBackend, this));
+}
+
+static void doomCallback(int error_code) { Q_UNUSED(error_code); }
+
+void URLRequestContextGetterQt::clearCurrentCacheBackend()
+{
+ if (m_urlRequestContext->http_transaction_factory() && m_urlRequestContext->http_transaction_factory()->GetCache()) {
+ disk_cache::Backend *backend = m_urlRequestContext->http_transaction_factory()->GetCache()->GetCurrentBackend();
+ if (backend)
+ backend->DoomAllEntries(base::Bind(&doomCallback));
+ }
+}
+
void URLRequestContextGetterQt::generateJobFactory()
{
Q_ASSERT(m_urlRequestContext);
diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h
index c7a4366ec..9c355082d 100644
--- a/src/core/url_request_context_getter_qt.h
+++ b/src/core/url_request_context_getter_qt.h
@@ -76,6 +76,7 @@ public:
void updateUserAgent();
void updateCookieStore();
void updateHttpCache();
+ void clearHttpCache();
private:
virtual ~URLRequestContextGetterQt();
@@ -86,6 +87,7 @@ private:
void generateHttpCache();
void generateUserAgent();
void generateJobFactory();
+ void clearCurrentCacheBackend();
bool m_ignoreCertificateErrors;
QAtomicInt m_updateCookieStore;
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index 0c3f7400b..6df16bf54 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -436,6 +436,20 @@ QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const
return d->browserContext()->cookieStore();
}
+/*!
+ \qmlmethod void WebEngineProfile::clearHttpCache()
+ \since QtWebEngine 1.3
+
+ Removes the profile's cache entries.
+
+ \sa WebEngineProfile::cachePath
+*/
+void QQuickWebEngineProfile::clearHttpCache()
+{
+ Q_D(QQuickWebEngineProfile);
+ d->browserContext()->clearHttpCache();
+}
+
QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
{
const Q_D(QQuickWebEngineProfile);
diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h
index 5839d51a5..2744ed0ec 100644
--- a/src/webengine/api/qquickwebengineprofile_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p.h
@@ -123,6 +123,7 @@ public:
static QQuickWebEngineProfile *defaultProfile();
Q_REVISION(1) Q_INVOKABLE QWebEngineCookieStore *cookieStore() const;
+ Q_REVISION(2) Q_INVOKABLE void clearHttpCache();
signals:
void storageNameChanged();
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 9955f7728..286889c1f 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -629,4 +629,15 @@ void QWebEngineProfile::destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *ob
removeUrlSchemeHandler(obj);
}
+/*!
+ \since 5.7
+
+ Removes the profile's cache entries.
+*/
+void QWebEngineProfile::clearHttpCache()
+{
+ Q_D(QWebEngineProfile);
+ d->browserContext()->clearHttpCache();
+}
+
QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h
index 416ef23db..4b37a7d73 100644
--- a/src/webenginewidgets/api/qwebengineprofile.h
+++ b/src/webenginewidgets/api/qwebengineprofile.h
@@ -115,6 +115,8 @@ public:
void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *);
void removeAllUrlSchemeHandlers();
+ void clearHttpCache();
+
static QWebEngineProfile *defaultProfile();
Q_SIGNALS:
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 09929d33f..d24a43b41 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -37,6 +37,7 @@
#include "../util.h"
#include <QtTest/QtTest>
#include <qwebengineprofile.h>
+#include <qwebenginepage.h>
class tst_QWebEngineProfile : public QObject
{
@@ -45,6 +46,7 @@ class tst_QWebEngineProfile : public QObject
private Q_SLOTS:
void defaultProfile();
void profileConstructors();
+ void clearDataFromCache();
};
void tst_QWebEngineProfile::defaultProfile()
@@ -69,7 +71,45 @@ void tst_QWebEngineProfile::profileConstructors()
QCOMPARE(diskProfile.httpCacheType(), QWebEngineProfile::DiskHttpCache);
QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
QCOMPARE(diskProfile.persistentCookiesPolicy(), QWebEngineProfile::AllowPersistentCookies);
+}
+
+void tst_QWebEngineProfile::clearDataFromCache()
+{
+ QWebEnginePage page;
+
+ QDir cacheDir("./tst_QWebEngineProfile_cacheDir");
+ cacheDir.makeAbsolute();
+ if (cacheDir.exists())
+ cacheDir.removeRecursively();
+ cacheDir.mkpath(cacheDir.path());
+
+ QWebEngineProfile *profile = page.profile();
+ profile->setCachePath(cacheDir.path());
+ profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
+
+ QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
+ page.load(QUrl("http://qt-project.org"));
+ if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
+ QSKIP("Couldn't load page from network, skipping test.");
+
+ cacheDir.refresh();
+ QVERIFY(cacheDir.entryList().contains("Cache"));
+ cacheDir.cd("./Cache");
+ int filesBeforeClear = cacheDir.entryList().count();
+
+ QFileSystemWatcher fileSystemWatcher;
+ fileSystemWatcher.addPath(cacheDir.path());
+ QSignalSpy directoryChangedSpy(&fileSystemWatcher, SIGNAL(directoryChanged(const QString &)));
+
+ // It deletes most of the files, but not all of them.
+ profile->clearHttpCache();
+ QTest::qWait(1000);
+ QTRY_VERIFY(directoryChangedSpy.count() > 0);
+
+ cacheDir.refresh();
+ QVERIFY(filesBeforeClear > cacheDir.entryList().count());
+ cacheDir.removeRecursively();
}
QTEST_MAIN(tst_QWebEngineProfile)