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 // We need to activate in qt6 otherwise it can't load external url.
30 settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
31 // We need to activate it in qt5.15 otherwise we can't load local css file and co
32 // settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, enableElement);
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 connect(this, &QWebEnginePage::featurePermissionRequested, this, &MailWebEnginePage::slotFeaturePermissionRequested);
52}
53
54void MailWebEnginePage::setPrintElementBackground(bool printElementBackground)
55{
56 settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, printElementBackground);
57}
58
59void MailWebEnginePage::slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature)
60{
61 // Denied all permissions.
62 setFeaturePermission(url, feature, QWebEnginePage::PermissionDeniedByUser);
63}
64
65#include "moc_mailwebenginepage.cpp"
KCRASH_EXPORT void initialize()
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 Fri Oct 11 2024 12:08:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.