Messagelib

mailwebenginepage.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "mailwebenginepage.h"
7#include <QFontDatabase>
8#include <QFontInfo>
9#include <QWebEngineProfile>
10#include <QWebEngineSettings>
11
12using namespace MessageViewer;
13
14MailWebEnginePage::MailWebEnginePage(QObject *parent)
15 : WebEngineViewer::WebEnginePage(parent)
16{
17 initialize();
18}
19
20void MailWebEnginePage::initialize()
21{
22 const bool enableElement = false;
23 settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, enableElement);
24 settings()->setAttribute(QWebEngineSettings::PluginsEnabled, enableElement);
25 settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, enableElement);
26 settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, enableElement);
27 settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, enableElement);
28 settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, enableElement);
29 // Default off, needed to load any external urls, we filter them manual
30 settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
31 // Default on, needed to load our own icons and cid urls. FIXME: Ideally should be off for additional security
32 settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
33 settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, enableElement);
34 settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, enableElement);
35 settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, enableElement);
36 settings()->setAttribute(QWebEngineSettings::WebGLEnabled, enableElement);
37 settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, enableElement);
38 settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, enableElement);
39 settings()->setAttribute(QWebEngineSettings::WebGLEnabled, enableElement);
40
41 settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, enableElement);
42 settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, enableElement);
43 settings()->setAttribute(QWebEngineSettings::PdfViewerEnabled, enableElement);
44 settings()->setAttribute(QWebEngineSettings::NavigateOnDropEnabled, enableElement);
45 profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
46 profile()->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
47
49 settings()->setFontFamily(QWebEngineSettings::StandardFont, font.family());
50 settings()->setFontSize(QWebEngineSettings::DefaultFontSize, font.pixelSize());
51#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
52 connect(this, &QWebEnginePage::permissionRequested, this, &MailWebEnginePage::slotFeaturePermissionRequested);
53#else
54 connect(this, &QWebEnginePage::featurePermissionRequested, this, &MailWebEnginePage::slotFeaturePermissionRequested);
55#endif
56}
57
58void MailWebEnginePage::setPrintElementBackground(bool printElementBackground)
59{
60 settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, printElementBackground);
61}
62
63#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
64void MailWebEnginePage::slotFeaturePermissionRequested(QWebEnginePermission feature)
65#else
66void MailWebEnginePage::slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature)
67#endif
68{
69#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
70 // Denied all permissions.
71 feature.deny();
72#else
73 setFeaturePermission(url, feature, QWebEnginePage::PermissionDeniedByUser);
74#endif
75}
76
77#include "moc_mailwebenginepage.cpp"
void initialize(StandardShortcut id)
QFont systemFont(SystemFont type)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.