Messagelib

mailwebenginepage.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "mailwebenginepage.h"
7 #include <QFontDatabase>
8 #include <QWebEngineProfile>
9 #include <QWebEngineSettings>
10 
11 using namespace MessageViewer;
12 
13 MailWebEnginePage::MailWebEnginePage(QObject *parent)
14  : WebEngineViewer::WebEnginePage(parent)
15 {
16  initialize();
17 }
18 
19 void MailWebEnginePage::initialize()
20 {
21  const bool enableElement = false;
22  settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, enableElement);
23  settings()->setAttribute(QWebEngineSettings::PluginsEnabled, enableElement);
24  settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, enableElement);
25  settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, enableElement);
26  settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, enableElement);
27  settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, enableElement);
28  settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, enableElement);
29  // We need to activate it in qt5.15 otherwise we can't load local css file and co
30  // settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, enableElement);
31  settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, enableElement);
32  settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, enableElement);
33  settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, enableElement);
34  settings()->setAttribute(QWebEngineSettings::WebGLEnabled, enableElement);
35  settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, enableElement);
36  settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, enableElement);
37  settings()->setAttribute(QWebEngineSettings::WebGLEnabled, enableElement);
38 
39  settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, enableElement);
40  settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, enableElement);
41  settings()->setAttribute(QWebEngineSettings::PdfViewerEnabled, enableElement);
42  profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
43  profile()->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
44 
45  const QFontInfo font(QFontDatabase().systemFont(QFontDatabase::GeneralFont));
46  settings()->setFontFamily(QWebEngineSettings::StandardFont, font.family());
47  settings()->setFontSize(QWebEngineSettings::DefaultFontSize, font.pixelSize());
48  connect(this, &QWebEnginePage::featurePermissionRequested, this, &MailWebEnginePage::slotFeaturePermissionRequested);
49 }
50 
51 void MailWebEnginePage::setPrintElementBackground(bool printElementBackground)
52 {
53  settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, printElementBackground);
54 }
55 
56 void MailWebEnginePage::slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature)
57 {
58  // Denied all permissions.
59  setFeaturePermission(url, feature, QWebEnginePage::PermissionDeniedByUser);
60 }
KCRASH_EXPORT void initialize()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Dec 2 2021 23:06:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.