Commit c205608a authored by Laurent Montel's avatar Laurent Montel 😁

Get href + title

parent 71f1324f
......@@ -20,6 +20,7 @@
#include "scamcheckshorturlmanager.h"
#include "scamdetectiondetailsdialog.h"
#include "settings/messageviewersettings.h"
#include "webengine/webenginescript.h"
#include <KLocalizedString>
......@@ -27,6 +28,25 @@
#include <QWebEnginePage>
using namespace MessageViewer;
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
R *receiver;
void (C::*memberFunction)(Arg);
void operator()(Arg result)
{
(receiver->*memberFunction)(result);
}
};
template<typename Arg, typename R, typename C>
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg))
{
InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction};
return wrapper;
}
static QString addWarningColor(const QString &url)
{
const QString error = QStringLiteral("<font color=#FF0000>%1</font>").arg(url);
......@@ -64,13 +84,19 @@ ScamCheckShortUrl *ScamDetectionWebEngine::scamCheckShortUrl() const
void ScamDetectionWebEngine::scanPage(QWebEnginePage *page)
{
if (MessageViewer::MessageViewerSettings::self()->scamDetectionEnabled()) {
bool foundScam = false;
d->mDetails.clear();
d->mDetails = QLatin1String("<b>") + i18n("Details:") + QLatin1String("</b><ul>");
//TODO
if (foundScam) {
Q_EMIT messageMayBeAScam();
}
page->runJavaScript(MessageViewer::WebEngineScript::findAllAnchors(), invoke(this, &ScamDetectionWebEngine::handleScanPage));
}
}
void ScamDetectionWebEngine::handleScanPage(const QVariant &result)
{
bool foundScam = false;
d->mDetails.clear();
d->mDetails = QLatin1String("<b>") + i18n("Details:") + QLatin1String("</b><ul>");
qDebug()<<" void ScamDetectionWebEngine::handleScanPage(const QVariant &result)"<< result;
//TODO
if (foundScam) {
Q_EMIT messageMayBeAScam();
}
}
......
......@@ -19,6 +19,7 @@
#define SCAMDETECTIONWEBENGINE_H
#include <QObject>
#include <QVariant>
#include "messageviewer_export.h"
class QWebEnginePage;
namespace MessageViewer
......@@ -34,9 +35,13 @@ public:
ScamCheckShortUrl *scamCheckShortUrl() const;
void scanPage(QWebEnginePage *page);
public Q_SLOTS:
void showDetails();
private Q_SLOTS:
void handleScanPage(const QVariant &result);
Q_SIGNALS:
void messageMayBeAScam();
......
......@@ -56,12 +56,11 @@ QString WebEngineScript::findAllAnchors()
{
const QString source = QLatin1String("(function() {"
"var out = [];"
"var anchor = document.getElementsByTagName('a');"
"for (var i = 0; i < anchor.length; ++i) {"
" var e = anchor[i];"
"var anchors = document.getElementsByTagName('a');"
"for (var i = 0; i < anchors.length; ++i) {"
" out.push({"
" src: e.getAttribute('href');"
" title = e.text;"
" src: anchors[i].href,"
" title: anchors[i].title"
" });"
"}"
"return out;"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment