summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <[email protected]>2017-04-28 13:52:20 +0200
committerDaniel Vrátil <[email protected]>2017-04-28 13:54:13 +0200
commit4df06e0e4276d9d028560269bcc699bb65c7bcf4 (patch)
tree7fe5a98d1468d5256b499647cc420ce7f33feae4
parent04f595fe71cfe62ca9de0a807228fd28ce29f83f (diff)
Don't use LocalDataBaseManager as a singleton
Instead make LocalDatabaseManager an instance-based interface for a singleton backend. The reason is that when running Kontact, both Akregator, KMail and possibly others who use WebEngineViewer would share the same instance of LocalDataBaseManager and connect to its signal. This means that when you click on a link in KMail, KMail requests URL check from LocalDataBaseManager singleton and the singleton emits a signal, the signal is delivered to all applications that are connected to it, not just KMail. This results in each application opening the link. This patch removes the singleton from LocalDataBaseManager and makes each WebEngineView own its own instance of LocalDataBaseManager. Internally, the actual implementation is still a singleton, however the public interface is non-singleton, which means that each application is connected to its own LocalDataBaseManager instance, thus avoiding the issue described above. Differential Review: https://phabricator.kde.org/D5577
-rw-r--r--CMakeLists.txt2
-rw-r--r--messageviewer/autotests/viewergrantleethemesupporttest.cpp2
-rw-r--r--messageviewer/autotests/viewertest.cpp2
-rw-r--r--messageviewer/src/viewer/viewer_p.cpp16
-rw-r--r--messageviewer/src/viewer/viewer_p.h2
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp34
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp173
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.h16
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager_p.h148
-rw-r--r--webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.cpp4
-rw-r--r--webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.h5
-rw-r--r--webengineviewer/src/checkphishingurl/tests/webengineviewwithsafebrowsingsupport.cpp6
-rw-r--r--webengineviewer/src/webengineview.cpp14
-rw-r--r--webengineviewer/src/webengineview.h4
14 files changed, 222 insertions, 206 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 90ee027..19938e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
-set(PIM_VERSION "5.5.42")
+set(PIM_VERSION "5.5.43")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
diff --git a/messageviewer/autotests/viewergrantleethemesupporttest.cpp b/messageviewer/autotests/viewergrantleethemesupporttest.cpp
index 3031677..42b31ac 100644
--- a/messageviewer/autotests/viewergrantleethemesupporttest.cpp
+++ b/messageviewer/autotests/viewergrantleethemesupporttest.cpp
@@ -24,11 +24,9 @@
#include <KSharedConfig>
#include <QTest>
-extern MESSAGEVIEWER_EXPORT bool messageviewer_initialize_database;
ViewerGrantleeThemeSupportTest::ViewerGrantleeThemeSupportTest(QObject *parent)
: QObject(parent)
{
- messageviewer_initialize_database = false;
}
ViewerGrantleeThemeSupportTest::~ViewerGrantleeThemeSupportTest()
diff --git a/messageviewer/autotests/viewertest.cpp b/messageviewer/autotests/viewertest.cpp
index c0ed26c..928a6fd 100644
--- a/messageviewer/autotests/viewertest.cpp
+++ b/messageviewer/autotests/viewertest.cpp
@@ -21,10 +21,8 @@
#include <qtestmouse.h>
#include <KActionCollection>
-extern MESSAGEVIEWER_EXPORT bool messageviewer_initialize_database;
ViewerTest::ViewerTest()
{
- messageviewer_initialize_database = false;
}
void ViewerTest::shouldHaveDefaultValuesOnCreation()
diff --git a/messageviewer/src/viewer/viewer_p.cpp b/messageviewer/src/viewer/viewer_p.cpp
index 157cdac..104e7aa 100644
--- a/messageviewer/src/viewer/viewer_p.cpp
+++ b/messageviewer/src/viewer/viewer_p.cpp
@@ -163,7 +163,6 @@ using namespace MessageViewer;
using namespace MessageCore;
static QAtomicInt _k_attributeInitialized;
-MESSAGEVIEWER_EXPORT bool messageviewer_initialize_database = true;
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
@@ -229,7 +228,8 @@ ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow,
mHeaderStyleMenuManager(nullptr),
mViewerPluginToolManager(nullptr),
mZoomActionMenu(nullptr),
- mCurrentPrinter(nullptr)
+ mCurrentPrinter(nullptr),
+ mPhishingDatabase(nullptr)
{
mMimePartTree = nullptr;
if (!mainWindow) {
@@ -238,13 +238,11 @@ ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow,
if (_k_attributeInitialized.testAndSetAcquire(0, 1)) {
Akonadi::AttributeFactory::registerAttribute<MessageViewer::MessageDisplayFormatAttribute>();
Akonadi::AttributeFactory::registerAttribute<MessageViewer::ScamAttribute>();
-
- //Make sure to initialize it once.
- if (messageviewer_initialize_database) {
- WebEngineViewer::LocalDataBaseManager::self()->initialize();
- }
}
- connect(WebEngineViewer::LocalDataBaseManager::self(), &WebEngineViewer::LocalDataBaseManager::checkUrlFinished, this, &ViewerPrivate::slotCheckedUrlFinished);
+ mPhishingDatabase = new WebEngineViewer::LocalDataBaseManager(this);
+ mPhishingDatabase->initialize();
+ connect(mPhishingDatabase , &WebEngineViewer::LocalDataBaseManager::checkUrlFinished,
+ this, &ViewerPrivate::slotCheckedUrlFinished);
mShareServiceManager = new PimCommon::ShareServiceUrlManager(this);
@@ -1987,7 +1985,7 @@ void ViewerPrivate::slotUrlOpen(const QUrl &url)
void ViewerPrivate::checkPhishingUrl()
{
if (!PimCommon::NetworkUtil::self()->lowBandwidth() && MessageViewer::MessageViewerSettings::self()->checkPhishingUrl() && (mClickedUrl.scheme() != QLatin1String("mailto"))) {
- WebEngineViewer::LocalDataBaseManager::self()->checkUrl(mClickedUrl);
+ mPhishingDatabase->checkUrl(mClickedUrl);
} else {
executeRunner(mClickedUrl);
}
diff --git a/messageviewer/src/viewer/viewer_p.h b/messageviewer/src/viewer/viewer_p.h
index 59663b2..d36cadd 100644
--- a/messageviewer/src/viewer/viewer_p.h
+++ b/messageviewer/src/viewer/viewer_p.h
@@ -79,6 +79,7 @@ namespace WebEngineViewer
class WebHitTestResult;
class FindBarWebEngineView;
class ZoomActionMenu;
+class LocalDataBaseManager;
}
namespace MessageViewer
{
@@ -694,6 +695,7 @@ public:
WebEngineViewer::ZoomActionMenu *mZoomActionMenu;
QPrinter *mCurrentPrinter;
QList<QPointer<MessageViewer::MailSourceWebEngineViewer> > mListMailSourceViewer;
+ WebEngineViewer::LocalDataBaseManager *mPhishingDatabase;
};
}
diff --git a/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp b/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp
index eb88192..6bbf674 100644
--- a/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp
@@ -19,38 +19,48 @@
#include "localdatabasemanagertest.h"
#include "../localdatabasemanager.h"
+#include "../localdatabasemanager_p.h"
#include <QTest>
+class TestLocalDatabaseManagerPrivate : public WebEngineViewer::LocalDataBaseManagerPrivate
+{
+public:
+ TestLocalDatabaseManagerPrivate()
+ : WebEngineViewer::LocalDataBaseManagerPrivate()
+ {
+ }
+
+protected:
+ void downloadDataBase(const QString &clientState) Q_DECL_OVERRIDE
+ {
+ // don't actually download anything
+ }
+};
+
class TestLocalDataBaseManager : public WebEngineViewer::LocalDataBaseManager
{
public:
TestLocalDataBaseManager(QObject *parent)
- : WebEngineViewer::LocalDataBaseManager(parent)
+ : WebEngineViewer::LocalDataBaseManager(new TestLocalDatabaseManagerPrivate, parent)
{
}
+ ~TestLocalDataBaseManager()
+ {
+ delete d;
+ }
+
void setDownloadInfoSendByServer(const QString &data)
{
mDownloadInfoSendByServer = data;
}
- // LocalDataBaseManager interface
-protected:
- void downloadFullDataBase() Q_DECL_OVERRIDE;
- void downloadPartialDataBase() Q_DECL_OVERRIDE;
private:
QString mDownloadInfoSendByServer;
};
-void TestLocalDataBaseManager::downloadFullDataBase()
-{
-}
-
-void TestLocalDataBaseManager::downloadPartialDataBase()
-{
-}
LocalDataBaseManagerTest::LocalDataBaseManagerTest(QObject *parent)
: QObject(parent)
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 21c19b0..20d678b 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -17,194 +17,48 @@
Boston, MA 02110-1301, USA.
*/
#include "localdatabasemanager.h"
+#include "localdatabasemanager_p.h"
#include "webengineviewer_debug.h"
#include "createphishingurldatabasejob.h"
#include "createdatabasefilejob.h"
#include "checkphishingurlutil.h"
-#include "localdatabasefile.h"
-#include "downloadlocaldatabasethread.h"
#include "urlhashing.h"
#include "backoffmodemanager.h"
#include <KConfigGroup>
#include <KSharedConfig>
-#include <QPointer>
-#include <QStandardPaths>
-#include <QDebug>
-#include <QDir>
#include <QTimer>
#include <QCryptographicHash>
using namespace WebEngineViewer;
-Q_GLOBAL_STATIC(LocalDataBaseManager, s_localDataBaseManager)
+Q_GLOBAL_STATIC(LocalDataBaseManagerPrivate, s_localDataBaseManager)
-namespace
-{
-inline QString localDataBasePath()
-{
- return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/phishingurl/");
-}
-inline QString databaseFullPath()
-{
- return localDataBasePath() + QLatin1Char('/') + WebEngineViewer::CheckPhishingUrlUtil::databaseFileName();
-}
-}
-
-class WebEngineViewer::LocalDataBaseManagerPrivate
-{
-public:
- LocalDataBaseManagerPrivate(LocalDataBaseManager *qq)
- : mFile(databaseFullPath()),
- mSecondToStartRefreshing(0),
- mDataBaseOk(false),
- mDownloadProgress(false),
- q(qq)
- {
- QDir().mkpath(localDataBasePath());
- readConfig();
- }
- ~LocalDataBaseManagerPrivate()
- {
- if (downloadLocalDatabaseThread) {
- downloadLocalDatabaseThread->quit();
- downloadLocalDatabaseThread->wait();
- delete downloadLocalDatabaseThread;
- }
- saveConfig();
- }
-
- void readConfig();
- void saveConfig();
- LocalDataBaseFile mFile;
- QString mNewClientState;
- QString mMinimumWaitDuration;
- uint mSecondToStartRefreshing;
- bool mDataBaseOk;
- bool mDownloadProgress;
- QPointer<WebEngineViewer::DownloadLocalDatabaseThread> downloadLocalDatabaseThread;
- LocalDataBaseManager *q;
-};
-
-LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
+LocalDataBaseManager::LocalDataBaseManager(LocalDataBaseManagerPrivate *impl, QObject *parent)
: QObject(parent),
- d(new LocalDataBaseManagerPrivate(this))
-
+ d(impl)
{
qRegisterMetaType<WebEngineViewer::UpdateDataBaseInfo>();
qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult>();
qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::ContraintsCompressionType>();
}
-LocalDataBaseManager::~LocalDataBaseManager()
-{
- delete d;
-}
-
-void LocalDataBaseManagerPrivate::readConfig()
-{
- KConfig phishingurlKConfig(WebEngineViewer::CheckPhishingUrlUtil::configFileName());
- KConfigGroup grp = phishingurlKConfig.group(QStringLiteral("General"));
- mNewClientState = grp.readEntry(QStringLiteral("DataBaseState"));
- mMinimumWaitDuration = grp.readEntry(QStringLiteral("RefreshDataBase"));
- if (!mMinimumWaitDuration.isEmpty()) {
- mSecondToStartRefreshing = WebEngineViewer::CheckPhishingUrlUtil::refreshingCacheAfterThisTime(WebEngineViewer::CheckPhishingUrlUtil::convertToSecond(mMinimumWaitDuration));
- }
-}
-
-void LocalDataBaseManagerPrivate::saveConfig()
-{
- KConfig phishingurlKConfig(WebEngineViewer::CheckPhishingUrlUtil::configFileName());
- KConfigGroup grp = phishingurlKConfig.group(QStringLiteral("General"));
- grp.writeEntry(QStringLiteral("DataBaseState"), mNewClientState);
- grp.writeEntry(QStringLiteral("RefreshDataBase"), mMinimumWaitDuration);
-}
-
-void LocalDataBaseManager::downloadDataBase(const QString &clientState)
-{
- setDownloadProgress(true);
- d->downloadLocalDatabaseThread = new WebEngineViewer::DownloadLocalDatabaseThread;
- d->downloadLocalDatabaseThread->setDatabaseFullPath(databaseFullPath());
- d->downloadLocalDatabaseThread->setDataBaseState(clientState);
- connect(d->downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::createDataBaseFailed, this, &LocalDataBaseManager::slotCreateDataBaseFailed);
- connect(d->downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::createDataBaseFinished, this, &LocalDataBaseManager::slotCreateDataBaseFileNameFinished);
- connect(d->downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::finished, d->downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::deleteLater);
- d->downloadLocalDatabaseThread->start();
-}
-
-void LocalDataBaseManager::slotCreateDataBaseFailed()
+LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
+ : LocalDataBaseManager(s_localDataBaseManager, parent)
{
- d->mDataBaseOk = false;
- d->mDownloadProgress = false;
}
-void LocalDataBaseManager::downloadPartialDataBase()
-{
- downloadDataBase(d->mNewClientState);
-}
-void LocalDataBaseManager::downloadFullDataBase()
+LocalDataBaseManager::~LocalDataBaseManager()
{
- downloadDataBase(QString());
}
void LocalDataBaseManager::initialize()
{
- if (d->mDownloadProgress) {
- return;
- }
- if (!d->mDataBaseOk) {
- qCDebug(WEBENGINEVIEWER_LOG) << "Start to create database";
- if (!QFileInfo::exists(databaseFullPath())) {
- downloadFullDataBase();
- } else {
- const uint now = QDateTime::currentDateTimeUtc().toTime_t();
- //qDebug() << " now "<< now << " d->mSecondToStartRefreshing "<<d->mSecondToStartRefreshing << " now > d->mSecondToStartRefreshing" << (now > d->mSecondToStartRefreshing);
- if ((d->mSecondToStartRefreshing != 0) && (d->mSecondToStartRefreshing > now)) {
- qCWarning(WEBENGINEVIEWER_LOG) << " It's not necessary to check database now";
- d->mDataBaseOk = true;
- } else {
- //Perhaps don't download for each start of kmail
- downloadPartialDataBase();
- }
- }
- } else {
- qCWarning(WEBENGINEVIEWER_LOG) << "Database already initialized. It's a bug in code if you call it twice.";
- }
-}
-
-void LocalDataBaseManager::slotCheckDataBase()
-{
- const uint now = QDateTime::currentDateTimeUtc().toTime_t();
- if (d->mDataBaseOk && !d->mDownloadProgress && (d->mSecondToStartRefreshing < now)) {
- downloadPartialDataBase();
- }
-}
-
-void LocalDataBaseManager::slotCreateDataBaseFileNameFinished(bool success, const QString &newClientState, const QString &minimumWaitDurationStr)
-{
- d->mDataBaseOk = success;
- d->mDownloadProgress = false;
- d->mNewClientState = success ? newClientState : QString();
- d->mMinimumWaitDuration = minimumWaitDurationStr;
- d->saveConfig();
- //if !success => redownload full!
- if (!success) {
- qCWarning(WEBENGINEVIEWER_LOG) << "We need to redownload full database";
- downloadFullDataBase();
- }
-}
-
-LocalDataBaseManager *LocalDataBaseManager::self()
-{
- return s_localDataBaseManager;
+ d->initialize();
}
-void LocalDataBaseManager::setDownloadProgress(bool downloadProgress)
-{
- d->mDownloadProgress = downloadProgress;
-}
void LocalDataBaseManager::checkUrl(const QUrl &url)
{
@@ -235,7 +89,10 @@ void LocalDataBaseManager::checkUrl(const QUrl &url)
job->setDatabaseState(QStringList() << d->mNewClientState);
job->setSearchHashs(conflictHashs);
job->setSearchFullHashForUrl(url);
- connect(job, &SearchFullHashJob::result, this, &LocalDataBaseManager::slotSearchOnServerResult);
+ connect(job, &SearchFullHashJob::result,
+ this, [this](CheckPhishingUrlUtil::UrlStatus status, const QUrl &url) {
+ Q_EMIT checkUrlFinished(url, status);
+ });
job->start();
}
}
@@ -247,9 +104,3 @@ void LocalDataBaseManager::checkUrl(const QUrl &url)
d->mFile.reload();
}
}
-
-void LocalDataBaseManager::slotSearchOnServerResult(WebEngineViewer::CheckPhishingUrlUtil::UrlStatus status, const QUrl &url)
-{
- qCWarning(WEBENGINEVIEWER_LOG) << " Url " << url << " status " << status;
- Q_EMIT checkUrlFinished(url, status);
-}
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.h b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
index f142f3a..6b390b9 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
@@ -27,6 +27,7 @@
#include <QUrl>
namespace WebEngineViewer
{
+class WebEngineView;
class LocalDataBaseManagerPrivate;
class WEBENGINEVIEWER_EXPORT LocalDataBaseManager : public QObject
{
@@ -35,27 +36,16 @@ public:
explicit LocalDataBaseManager(QObject *parent = nullptr);
~LocalDataBaseManager();
- static LocalDataBaseManager *self();
-
void checkUrl(const QUrl &url);
void initialize();
- void slotCreateDataBaseFileNameFinished(bool finished, const QString &newClientState, const QString &minimumWaitDurationStr);
-
Q_SIGNALS:
void checkUrlFinished(const QUrl &url, WebEngineViewer::CheckPhishingUrlUtil::UrlStatus status);
protected:
- void setDownloadProgress(bool downloadProgress);
- virtual void downloadFullDataBase();
- virtual void downloadPartialDataBase();
-
-private:
- void slotSearchOnServerResult(WebEngineViewer::CheckPhishingUrlUtil::UrlStatus status, const QUrl &url);
- void slotCheckDataBase();
- void downloadDataBase(const QString &clientState);
- void slotCreateDataBaseFailed();
+ explicit LocalDataBaseManager(LocalDataBaseManagerPrivate *impl,
+ QObject *parent = nullptr);
LocalDataBaseManagerPrivate *const d;
};
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager_p.h b/webengineviewer/src/checkphishingurl/localdatabasemanager_p.h
new file mode 100644
index 0000000..601b464
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager_p.h
@@ -0,0 +1,148 @@
+/*
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "localdatabasefile.h"
+#include "webengineviewer_debug.h"
+#include "downloadlocaldatabasethread.h"
+
+#include <KConfigGroup>
+#include <KConfig>
+
+#include <QDir>
+#include <QStandardPaths>
+#include <QPointer>
+
+namespace
+{
+inline QString localDataBasePath()
+{
+ return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/phishingurl/");
+}
+inline QString databaseFullPath()
+{
+ return localDataBasePath() + QLatin1Char('/') + WebEngineViewer::CheckPhishingUrlUtil::databaseFileName();
+}
+}
+
+namespace WebEngineViewer
+{
+
+class LocalDataBaseManagerPrivate
+{
+public:
+ LocalDataBaseManagerPrivate()
+ : mFile(databaseFullPath()),
+ mSecondToStartRefreshing(0),
+ mDataBaseOk(false),
+ mDownloadProgress(false)
+ {
+ QDir().mkpath(localDataBasePath());
+ readConfig();
+ }
+ virtual ~LocalDataBaseManagerPrivate()
+ {
+ if (downloadLocalDatabaseThread) {
+ downloadLocalDatabaseThread->quit();
+ downloadLocalDatabaseThread->wait();
+ delete downloadLocalDatabaseThread;
+ }
+ saveConfig();
+ }
+
+ void initialize()
+ {
+ if (mDownloadProgress) {
+ return;
+ }
+ if (!mDataBaseOk) {
+ qCDebug(WEBENGINEVIEWER_LOG) << "Start to create database";
+ if (!QFileInfo::exists(databaseFullPath())) {
+ downloadDataBase(QString());
+ } else {
+ const uint now = QDateTime::currentDateTimeUtc().toTime_t();
+ //qDebug() << " now "<< now << " d->mSecondToStartRefreshing "<<d->mSecondToStartRefreshing << " now > d->mSecondToStartRefreshing" << (now > d->mSecondToStartRefreshing);
+ if ((mSecondToStartRefreshing != 0) && (mSecondToStartRefreshing > now)) {
+ qCWarning(WEBENGINEVIEWER_LOG) << " It's not necessary to check database now";
+ mDataBaseOk = true;
+ } else {
+ //Perhaps don't download for each start of kmail
+ downloadDataBase(mNewClientState);
+ }
+ }
+ }
+ }
+
+ virtual void downloadDataBase(const QString &clientState)
+ {
+ mDownloadProgress = true;
+ downloadLocalDatabaseThread = new WebEngineViewer::DownloadLocalDatabaseThread;
+ downloadLocalDatabaseThread->setDatabaseFullPath(databaseFullPath());
+ downloadLocalDatabaseThread->setDataBaseState(clientState);
+ QObject::connect(downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::createDataBaseFailed,
+ [this]() {
+ mDataBaseOk = false;
+ mDownloadProgress = false;
+ });
+ QObject::connect(downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::createDataBaseFinished,
+ [this](bool success, const QString &newClientState, const QString &minWaitDurationStr) {
+ mDataBaseOk = success;
+ mDownloadProgress = false;
+ mNewClientState = success ? newClientState : QString();
+ mMinimumWaitDuration = minWaitDurationStr;
+ saveConfig();
+ //if !success => redownload full!
+ if (!success) {
+ qCWarning(WEBENGINEVIEWER_LOG) << "We need to redownload full database";
+ downloadDataBase(QString()); // download full database
+ }
+ });
+ QObject::connect(downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::finished,
+ downloadLocalDatabaseThread.data(), &DownloadLocalDatabaseThread::deleteLater);
+ downloadLocalDatabaseThread->start();
+ }
+
+ void readConfig()
+ {
+ KConfig phishingurlKConfig(WebEngineViewer::CheckPhishingUrlUtil::configFileName());
+ KConfigGroup grp = phishingurlKConfig.group(QStringLiteral("General"));
+ mNewClientState = grp.readEntry(QStringLiteral("DataBaseState"));
+ mMinimumWaitDuration = grp.readEntry(QStringLiteral("RefreshDataBase"));
+ if (!mMinimumWaitDuration.isEmpty()) {
+ mSecondToStartRefreshing = WebEngineViewer::CheckPhishingUrlUtil::refreshingCacheAfterThisTime(WebEngineViewer::CheckPhishingUrlUtil::convertToSecond(mMinimumWaitDuration));
+ }
+ }
+
+ void saveConfig()
+ {
+ KConfig phishingurlKConfig(WebEngineViewer::CheckPhishingUrlUtil::configFileName());
+ KConfigGroup grp = phishingurlKConfig.group(QStringLiteral("General"));
+ grp.writeEntry(QStringLiteral("DataBaseState"), mNewClientState);
+ grp.writeEntry(QStringLiteral("RefreshDataBase"), mMinimumWaitDuration);
+ }
+
+ LocalDataBaseFile mFile;
+ QString mNewClientState;
+ QString mMinimumWaitDuration;
+ uint mSecondToStartRefreshing;
+ bool mDataBaseOk;
+ bool mDownloadProgress;
+ QPointer<WebEngineViewer::DownloadLocalDatabaseThread> downloadLocalDatabaseThread;
+};
+
+}
diff --git a/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.cpp b/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.cpp
index a791c7a..5e2c5c6 100644
--- a/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.cpp
+++ b/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.cpp
@@ -31,6 +31,7 @@
ManageLocalDataBaseGui::ManageLocalDataBaseGui(QWidget *parent)
: QWidget(parent)
+ , mDbManager(new WebEngineViewer::LocalDataBaseManager(this))
{
QVBoxLayout *layout = new QVBoxLayout(this);
@@ -45,12 +46,11 @@ ManageLocalDataBaseGui::ManageLocalDataBaseGui(QWidget *parent)
ManageLocalDataBaseGui::~ManageLocalDataBaseGui()
{
-
}
void ManageLocalDataBaseGui::slotDownloadFullDatabase()
{
- WebEngineViewer::LocalDataBaseManager::self()->initialize();
+ mDbManager->initialize();
}
int main(int argc, char **argv)
diff --git a/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.h b/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.h
index a27ea81..a9f3544 100644
--- a/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.h
+++ b/webengineviewer/src/checkphishingurl/tests/managelocaldatabasegui.h
@@ -22,6 +22,10 @@
#include <QWidget>
class QPlainTextEdit;
+namespace WebEngineViewer {
+class LocalDataBaseManager;
+}
+
class ManageLocalDataBaseGui : public QWidget
{
Q_OBJECT
@@ -32,6 +36,7 @@ private Q_SLOTS:
void slotDownloadFullDatabase();
private:
QPlainTextEdit *mResult;
+ WebEngineViewer::LocalDataBaseManager *mDbManager;
};
#endif // MANAGELOCALDATABASEGUI_H
diff --git a/webengineviewer/src/checkphishingurl/tests/webengineviewwithsafebrowsingsupport.cpp b/webengineviewer/src/checkphishingurl/tests/webengineviewwithsafebrowsingsupport.cpp
index 9ed5e1a..5c0497a 100644
--- a/webengineviewer/src/checkphishingurl/tests/webengineviewwithsafebrowsingsupport.cpp
+++ b/webengineviewer/src/checkphishingurl/tests/webengineviewwithsafebrowsingsupport.cpp
@@ -35,9 +35,9 @@ WebEngineViewWithSafeBrowsingSupport::WebEngineViewWithSafeBrowsingSupport(QWidg
{
QVBoxLayout *layout = new QVBoxLayout(this);
QStandardPaths::setTestModeEnabled(true);
- WebEngineViewer::LocalDataBaseManager::self()->initialize();
- connect(WebEngineViewer::LocalDataBaseManager::self(), &WebEngineViewer::LocalDataBaseManager::checkUrlFinished, this, &WebEngineViewWithSafeBrowsingSupport::slotCheckedUrlFinished);
pageView = new WebEngineViewer::WebEngineView(this);
+ connect(pageView->phishingDatabase(), &WebEngineViewer::LocalDataBaseManager::checkUrlFinished,
+ this, &WebEngineViewWithSafeBrowsingSupport::slotCheckedUrlFinished);
layout->addWidget(pageView);
WebEngineViewer::WebEnginePage *mEnginePage = new WebEngineViewer::WebEnginePage(this);
pageView->setPage(mEnginePage);
@@ -60,7 +60,7 @@ WebEngineViewWithSafeBrowsingSupport::~WebEngineViewWithSafeBrowsingSupport()
void WebEngineViewWithSafeBrowsingSupport::slotUrlClicked(const QUrl &url)
{
qDebug() << " url clicked " << url;
- WebEngineViewer::LocalDataBaseManager::self()->checkUrl(url);
+ pageView->phishingDatabase()->checkUrl(url);
}
void WebEngineViewWithSafeBrowsingSupport::slotCheckedUrlFinished(const QUrl &url, WebEngineViewer::CheckPhishingUrlUtil::UrlStatus status)
diff --git a/webengineviewer/src/webengineview.cpp b/webengineviewer/src/webengineview.cpp
index 7c0f405..2b4dd5d 100644
--- a/webengineviewer/src/webengineview.cpp
+++ b/webengineviewer/src/webengineview.cpp
@@ -21,6 +21,7 @@
#include "webenginenavigationrequestinterceptor.h"
#include "webenginemanagescript.h"
#include "webengineviewer_debug.h"
+#include "checkphishingurl/localdatabasemanager.h"
#include "../config-webengineviewer.h"
#include <QEvent>
#include <QKeyEvent>
@@ -36,7 +37,8 @@ public:
: mSavedRelativePosition(-1),
mCurrentWidget(nullptr),
mWebEngineNavigatorInterceptor(nullptr),
- mWebEngineNavigatorInterceptorView(nullptr)
+ mWebEngineNavigatorInterceptorView(nullptr),
+ mPhishingDatabase(nullptr)
{
@@ -54,6 +56,7 @@ public:
WebEngineManageScript *mManagerScript;
WebEngineNavigationRequestInterceptor *mWebEngineNavigatorInterceptor;
WebEngineView *mWebEngineNavigatorInterceptorView;
+ LocalDataBaseManager *mPhishingDatabase;
};
WebEngineView::WebEngineView(QWidget *parent)
@@ -206,3 +209,12 @@ qreal WebEngineView::relativePosition() const
qCDebug(WEBENGINEVIEWER_LOG) << "Relative Position" << d->mSavedRelativePosition;
return d->mSavedRelativePosition;
}
+
+LocalDataBaseManager * WebEngineView::phishingDatabase() const
+{
+ if (!d->mPhishingDatabase) {
+ d->mPhishingDatabase = new LocalDataBaseManager(const_cast<WebEngineView*>(this));
+ d->mPhishingDatabase->initialize();
+ }
+ return d->mPhishingDatabase;
+}
diff --git a/webengineviewer/src/webengineview.h b/webengineviewer/src/webengineview.h
index 582c59e..614fc4f 100644
--- a/webengineviewer/src/webengineview.h
+++ b/webengineviewer/src/webengineview.h
@@ -27,6 +27,8 @@ namespace WebEngineViewer
{
class WebEngineViewPrivate;
class WebEngineManageScript;
+class LocalDataBaseManager;
+
class WEBENGINEVIEWER_EXPORT WebEngineView : public QWebEngineView
{
Q_OBJECT
@@ -44,6 +46,8 @@ public:
WebEngineManageScript *webEngineManagerScript() const;
void setLinkHovered(const QUrl &url);
+ WebEngineViewer::LocalDataBaseManager *phishingDatabase() const;
+
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) Q_DECL_OVERRIDE;