summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-17 07:06:50 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-17 07:06:50 (GMT)
commitb34448bfbca4ccf5c41184c7cdb194c912c8308e (patch)
treef970681e48a6385fbb44b16b98f2c666f65a8aa5
parent2903fd09a4af6633b402d4dfc055a46d812b6237 (diff)
Add a util class
-rw-r--r--webengineviewer/src/CMakeLists.txt1
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/CMakeLists.txt6
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurljob.cpp8
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurljob.h1
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurlutil.cpp25
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurlutil.h30
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp9
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h1
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp2
9 files changed, 64 insertions, 19 deletions
diff --git a/webengineviewer/src/CMakeLists.txt b/webengineviewer/src/CMakeLists.txt
index c9b8723..c635ce1 100644
--- a/webengineviewer/src/CMakeLists.txt
+++ b/webengineviewer/src/CMakeLists.txt
@@ -36,6 +36,7 @@ set(libwebengineviewer_checkphishingurl_SRCS
checkphishingurl/createphishingurldatabasejob.cpp
checkphishingurl/checkphishingurlfromlocaldatabasejob.cpp
checkphishingurl/localdatabasemanager.cpp
+ checkphishingurl/checkphishingurlutil.cpp
)
set(libwebengineviewer_interceptor_SRCS
diff --git a/webengineviewer/src/checkphishingurl/autotests/CMakeLists.txt b/webengineviewer/src/checkphishingurl/autotests/CMakeLists.txt
index 1dcf1e6..76d7c76 100644
--- a/webengineviewer/src/checkphishingurl/autotests/CMakeLists.txt
+++ b/webengineviewer/src/checkphishingurl/autotests/CMakeLists.txt
@@ -2,20 +2,20 @@ set(testwebengineviewer_webengine_common_SRCS)
ecm_qt_declare_logging_category(testwebengineviewer_webengine_common_SRCS HEADER webengineviewer_debug.h IDENTIFIER WEBENGINEVIEWER_LOG CATEGORY_NAME org.kde.pim.webengineviewer)
add_definitions( -DCHECKPHISHINGURL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
-ecm_add_test(checkphishingurljobtest.cpp ../checkphishingurljob.cpp ${testwebengineviewer_webengine_common_SRCS}
+ecm_add_test(checkphishingurljobtest.cpp ../checkphishingurljob.cpp ../checkphishingurlutil.cpp ${testwebengineviewer_webengine_common_SRCS}
TEST_NAME checkphishingurljobtest
NAME_PREFIX "webengineview-checkphishingurl-"
LINK_LIBRARIES Qt5::Test Qt5::WebKitWidgets KF5::WebEngineViewer
)
-ecm_add_test(checkphishingurlfromlocaldatabasejobtest.cpp ../checkphishingurlfromlocaldatabasejob.cpp ${testwebengineviewer_webengine_common_SRCS}
+ecm_add_test(checkphishingurlfromlocaldatabasejobtest.cpp ../checkphishingurlutil.cpp ../checkphishingurlfromlocaldatabasejob.cpp ${testwebengineviewer_webengine_common_SRCS}
TEST_NAME checkphishingurlfromlocaldatabasetest
NAME_PREFIX "webengineview-checkphishingurl-"
LINK_LIBRARIES Qt5::Test Qt5::WebKitWidgets KF5::WebEngineViewer
)
-ecm_add_test(createphishingurldatabasejobtest.cpp ../createphishingurldatabasejob.cpp ${testwebengineviewer_webengine_common_SRCS}
+ecm_add_test(createphishingurldatabasejobtest.cpp ../checkphishingurlutil.cpp ../createphishingurldatabasejob.cpp ${testwebengineviewer_webengine_common_SRCS}
TEST_NAME createphishingurldatabasejobtest
NAME_PREFIX "webengineview-checkphishingurl-"
LINK_LIBRARIES Qt5::Test Qt5::WebKitWidgets KF5::WebEngineViewer
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp b/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
index 393de59..6fe69ef 100644
--- a/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
+++ b/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
@@ -18,6 +18,7 @@
*/
#include "checkphishingurljob.h"
+#include "checkphishingurlutil.h"
#include <QNetworkAccessManager>
#include <QNetworkConfigurationManager>
#include <PimCommon/NetworkManager>
@@ -45,11 +46,6 @@ void CheckPhishingUrlJob::slotSslErrors(QNetworkReply *reply, const QList<QSslEr
reply->ignoreSslErrors(error);
}
-QString CheckPhishingUrlJob::apiKey() const
-{
- return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
-}
-
void CheckPhishingUrlJob::setUseCompactJson(bool useCompactJson)
{
mUseCompactJson = useCompactJson;
@@ -136,7 +132,7 @@ void CheckPhishingUrlJob::start()
deleteLater();
} else if (canStart()) {
QUrl safeUrl = QUrl(QStringLiteral("https://safebrowsing.googleapis.com/v4/threatMatches:find"));
- safeUrl.addQueryItem(QStringLiteral("key"), apiKey());
+ safeUrl.addQueryItem(QStringLiteral("key"), WebEngineViewer::CheckPhishingUrlUtil::apiKey());
//qDebug() << " safeUrl" << safeUrl;
QNetworkRequest request(safeUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json"));
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurljob.h b/webengineviewer/src/checkphishingurl/checkphishingurljob.h
index 83d941b..946d75d 100644
--- a/webengineviewer/src/checkphishingurl/checkphishingurljob.h
+++ b/webengineviewer/src/checkphishingurl/checkphishingurljob.h
@@ -61,7 +61,6 @@ private Q_SLOTS:
void slotError(QNetworkReply::NetworkError error);
void slotCheckUrlFinished(QNetworkReply *reply);
private:
- QString apiKey() const;
QUrl mUrl;
bool mUseCompactJson;
QNetworkAccessManager *mNetworkAccessManager;
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurlutil.cpp b/webengineviewer/src/checkphishingurl/checkphishingurlutil.cpp
new file mode 100644
index 0000000..fba583c
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/checkphishingurlutil.cpp
@@ -0,0 +1,25 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ 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 "checkphishingurlutil.h"
+
+QString WebEngineViewer::CheckPhishingUrlUtil::apiKey()
+{
+ return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
+}
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurlutil.h b/webengineviewer/src/checkphishingurl/checkphishingurlutil.h
new file mode 100644
index 0000000..9ca2b8b
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/checkphishingurlutil.h
@@ -0,0 +1,30 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ 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.
+*/
+
+#ifndef CHECKPHISHINGURLUTIL_H
+#define CHECKPHISHINGURLUTIL_H
+
+#include <QString>
+
+namespace WebEngineViewer {
+namespace CheckPhishingUrlUtil {
+QString apiKey();
+}
+}
+#endif // CHECKPHISHINGURLUTIL_H
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
index 1593668..bf8da1c 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
@@ -19,6 +19,7 @@
#include "createphishingurldatabasejob.h"
+#include "checkphishingurlutil.h"
#include "webengineviewer_debug.h"
#include <PimCommon/NetworkManager>
@@ -42,12 +43,6 @@ CreatePhishingUrlDataBaseJob::~CreatePhishingUrlDataBaseJob()
}
-QString CreatePhishingUrlDataBaseJob::apiKey() const
-{
- return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
-}
-
-
void CreatePhishingUrlDataBaseJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)
{
qCDebug(WEBENGINEVIEWER_LOG) << " void CreatePhishingUrlDataBaseJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)" << error.count();
@@ -61,7 +56,7 @@ void CreatePhishingUrlDataBaseJob::start()
deleteLater();
} else {
QUrl safeUrl = QUrl(QStringLiteral("https://safebrowsing.googleapis.com/v4/threatListUpdates:fetch"));
- safeUrl.addQueryItem(QStringLiteral("key"), apiKey());
+ safeUrl.addQueryItem(QStringLiteral("key"), WebEngineViewer::CheckPhishingUrlUtil::apiKey());
//qDebug() << " safeUrl" << safeUrl;
QNetworkRequest request(safeUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json"));
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
index ea82852..ac9eb7f 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
@@ -108,7 +108,6 @@ Q_SIGNALS:
void debugJson(const QByteArray &ba);
private:
- QString apiKey() const;
void slotDownloadDataBaseFinished(QNetworkReply *reply);
void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
void slotError(QNetworkReply::NetworkError error);
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 26f18fa..37f013f 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -25,7 +25,7 @@ Q_GLOBAL_STATIC(LocalDataBaseManager, s_localDataBaseManager)
LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
: QObject(parent)
{
-
+ initializeDataBase();
}
LocalDataBaseManager::~LocalDataBaseManager()