6#include "mailwebengineview.h"
7#include "../urlhandlermanager.h"
8#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
9#include "cidschemehandler/cidschemehandler.h"
10#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
11#include "mailwebenginepage.h"
12#include "messageviewer/messageviewersettings.h"
13#include "webengineviewer/webengineaccesskey.h"
14#include "webengineviewer/webenginescript.h"
15#include <WebEngineViewer/BlockExternalResourcesUrlInterceptor>
16#include <WebEngineViewer/InterceptorManager>
17#include <WebEngineViewer/WebEngineManageScript>
19#include "scamdetection/scamdetectionwebengine.h"
20#include <QContextMenuEvent>
21#include <QWebEngineProfile>
22#include <WebEngineViewer/WebHitTest>
25#include <QWebEngineUrlScheme>
27#include <WebEngineViewer/WebHitTestResult>
29using namespace MessageViewer;
30template<
typename Arg,
typename R,
typename C>
33 void (C::*memberFunction)(Arg);
34 void operator()(Arg result)
36 (receiver->*memberFunction)(result);
40template<
typename Arg,
typename R,
typename C>
42InvokeWrapper<Arg, R, C> invoke(R *receiver,
void (C::*memberFunction)(Arg))
44 InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction};
48class MessageViewer::MailWebEngineViewPrivate
51 MailWebEngineViewPrivate() =
default;
57 MessageViewer::LoadExternalReferencesUrlInterceptor *mExternalReference =
nullptr;
60 MessageViewer::ViewerPrivate *mViewer =
nullptr;
62 bool mCanStartDrag =
false;
66 : WebEngineViewer::WebEngineView(parent)
67 , d(new MessageViewer::MailWebEngineViewPrivate)
70 setPage(d->mPageEngine);
72 d->mWebViewAccessKey->setActionCollection(ac);
74 connect(d->mScamDetection, &ScamDetectionWebEngine::messageMayBeAScam,
this, &MailWebEngineView::messageMayBeAScam);
75 connect(d->mWebViewAccessKey, &WebEngineViewer::WebEngineAccessKey::openUrl,
this, &MailWebEngineView::openUrl);
76 connect(
this, &MailWebEngineView::loadFinished,
this, &MailWebEngineView::slotLoadFinished);
78 d->mPageEngine->profile()->installUrlSchemeHandler(QByteArrayLiteral(
"cid"),
new CidSchemeHandler(
this));
81 d->mExternalReference =
new MessageViewer::LoadExternalReferencesUrlInterceptor(
this);
82 connect(d->mExternalReference, &MessageViewer::LoadExternalReferencesUrlInterceptor::urlBlocked,
this, &MailWebEngineView::urlBlocked);
83 d->mNetworkAccessManager->addInterceptor(d->mExternalReference);
84 auto cidReference =
new MessageViewer::CidReferencesUrlInterceptor(
this);
85 d->mNetworkAccessManager->addInterceptor(cidReference);
86 auto blockExternalUrl =
new WebEngineViewer::BlockExternalResourcesUrlInterceptor(
this);
87 connect(blockExternalUrl, &WebEngineViewer::BlockExternalResourcesUrlInterceptor::formSubmittedForbidden,
this, &MailWebEngineView::formSubmittedForbidden);
88 d->mNetworkAccessManager->addInterceptor(blockExternalUrl);
91 connect(d->mBlockMailTrackingUrl, &WebEngineViewer::BlockTrackingUrlInterceptor::trackingFound,
this, &MailWebEngineView::mailTrackingFound);
92 d->mNetworkAccessManager->addInterceptor(d->mBlockMailTrackingUrl);
95 connect(d->mPageEngine, &MailWebEnginePage::urlClicked,
this, &MailWebEngineView::openUrl);
96 connect(page(), &QWebEnginePage::scrollPositionChanged, d->mWebViewAccessKey, &WebEngineViewer::WebEngineAccessKey::hideAccessKeys);
99MailWebEngineView::~MailWebEngineView() =
default;
101void MailWebEngineView::readConfig()
103 d->mBlockMailTrackingUrl->setEnabledMailTrackingInterceptor(MessageViewer::MessageViewerSettings::self()->mailTrackingUrlEnabled());
106void MailWebEngineView::setLinkHovered(
const QUrl &url)
109 d->mHoveredUrl = url;
112void MailWebEngineView::runJavaScriptInWordId(
const QString &script)
114 page()->runJavaScript(script, WebEngineViewer::WebEngineManageScript::scriptWordId());
117void MailWebEngineView::setViewer(MessageViewer::ViewerPrivate *viewer)
125 connect(webHit, &WebEngineViewer::WebHitTest::finished,
this, &MailWebEngineView::slotWebHitFinished);
133void MailWebEngineView::scrollUp(
int pixels)
135 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollUp(pixels));
138void MailWebEngineView::scrollDown(
int pixels)
140 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollDown(pixels));
143void MailWebEngineView::selectAll()
145 page()->triggerAction(QWebEnginePage::SelectAll);
148void MailWebEngineView::slotZoomChanged(qreal zoom)
153void MailWebEngineView::scamCheck()
155 d->mScamDetection->scanPage(page());
158void MailWebEngineView::slotShowDetails()
160 d->mScamDetection->showDetails();
163void MailWebEngineView::forwardKeyReleaseEvent(
QKeyEvent *e)
165 if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
166 d->mWebViewAccessKey->keyReleaseEvent(e);
170void MailWebEngineView::forwardMousePressEvent(
QMouseEvent *event)
172 if (d->mViewer && !d->mHoveredUrl.isEmpty()) {
175 if (URLHandlerManager::instance()->handleShiftClick(d->mHoveredUrl, d->mViewer)) {
181 d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl, d->mViewer);
182 d->mLastClickPosition =
event->pos();
187void MailWebEngineView::forwardMouseMoveEvent(
QMouseEvent *event)
189 if (d->mViewer && !d->mHoveredUrl.isEmpty()) {
193 if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) {
195 d->mCanStartDrag =
false;
203void MailWebEngineView::forwardMouseReleaseEvent(
QMouseEvent *event)
206 d->mCanStartDrag =
false;
209void MailWebEngineView::forwardKeyPressEvent(
QKeyEvent *e)
211 if (e && hasFocus()) {
212 if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
213 d->mWebViewAccessKey->keyPressEvent(e);
218void MailWebEngineView::forwardWheelEvent(
QWheelEvent *e)
220 if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
221 d->mWebViewAccessKey->wheelEvent(e);
225 const int numSteps = numDegrees / 15;
226 Q_EMIT wheelZoomChanged(numSteps);
233 if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
234 d->mWebViewAccessKey->resizeEvent(e);
236 QWebEngineView::resizeEvent(e);
239void MailWebEngineView::saveMainFrameScreenshotInFile(
const QString &filename)
251 image.save(filename);
254void MailWebEngineView::showAccessKeys()
256 d->mWebViewAccessKey->showAccessKeys();
259void MailWebEngineView::hideAccessKeys()
261 d->mWebViewAccessKey->hideAccessKeys();
264void MailWebEngineView::isScrolledToBottom()
266 page()->runJavaScript(WebEngineViewer::WebEngineScript::isScrolledToBottom(),
267 WebEngineViewer::WebEngineManageScript::scriptWordId(),
268 invoke(
this, &MailWebEngineView::handleIsScrolledToBottom));
271void MailWebEngineView::setElementByIdVisible(
const QString &
id,
bool visible)
273 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setElementByIdVisible(
id, visible));
276void MailWebEngineView::removeAttachmentMarking(
const QString &
id)
278 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::removeStyleToElement(
id));
281void MailWebEngineView::markAttachment(
const QString &
id,
const QString &style)
283 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setStyleToElement(
id, style));
286void MailWebEngineView::scrollToAnchor(
const QString &anchor)
288 page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor),
289 WebEngineViewer::WebEngineManageScript::scriptWordId(),
290 invoke(
this, &MailWebEngineView::handleScrollToAnchor));
293void MailWebEngineView::handleIsScrolledToBottom(
const QVariant &result)
295 bool scrolledToBottomResult =
false;
297 scrolledToBottomResult = result.
toBool();
299 Q_EMIT pageIsScrolledToBottom(scrolledToBottomResult);
302void MailWebEngineView::handleScrollToAnchor(
const QVariant &result)
306 if (lst.
count() == 2) {
307 const QPoint pos(lst.
at(0).toInt(), lst.
at(1).toInt());
308 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToPosition(pos));
313void MailWebEngineView::scrollPageDown(
int percent)
315 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollPercentage(percent));
318void MailWebEngineView::scrollPageUp(
int percent)
320 scrollPageDown(-percent);
323void MailWebEngineView::scrollToRelativePosition(qreal pos)
325 runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToRelativePosition(pos));
328void MailWebEngineView::setAllowExternalContent(
bool b)
330 if (d->mExternalReference->allowExternalContent() != b) {
331 d->mExternalReference->setAllowExternalContent(b);
338 return d->mNetworkAccessManager->interceptorUrlActions(result);
341void MailWebEngineView::slotLoadFinished()
346void MailWebEngineView::setPrintElementBackground(
bool printElementBackground)
348 d->mPageEngine->setPrintElementBackground(printElementBackground);
351void MailWebEngineView::initializeCustomScheme()
353 QWebEngineUrlScheme cidScheme(
"cid");
354 cidScheme.setFlags(QWebEngineUrlScheme::SecureScheme | QWebEngineUrlScheme::ContentSecurityPolicyIgnored | QWebEngineUrlScheme::LocalScheme
355 | QWebEngineUrlScheme::LocalAccessAllowed);
356 cidScheme.setSyntax(QWebEngineUrlScheme::Syntax::Path);
357 QWebEngineUrlScheme::registerScheme(cidScheme);
360#include "moc_mailwebengineview.cpp"
The MailWebEnginePage class.
void popupMenu(const WebEngineViewer::WebHitTestResult &result)
Emitted when the user right-clicks somewhere.
The ScamDetectionWebEngine class.
The BlockMailTrackingUrlInterceptor class.
The InterceptorManager class.
The WebEngineAccessKey class.
The WebHitTestResult class.
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
const QList< QKeySequence > & reload()
Qt::KeyboardModifiers keyboardModifiers()
const_reference at(qsizetype i) const const
qsizetype count() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const
bool toBool() const const
QList< QVariant > toList() const const
QPoint angleDelta() const const