articleviewerwebenginepage.cpp 2.92 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
2
   Copyright (C) 2015-2017 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
Laurent Montel's avatar
Laurent Montel committed
18 19 20
*/

#include "articleviewerwebenginepage.h"
Laurent Montel's avatar
Laurent Montel committed
21
#include <QWebEngineSettings>
Laurent Montel's avatar
Laurent Montel committed
22
#include <QWebEngineProfile>
Laurent Montel's avatar
Laurent Montel committed
23 24
using namespace Akregator;

Laurent Montel's avatar
Laurent Montel committed
25 26
ArticleViewerWebEnginePage::ArticleViewerWebEnginePage(QWebEngineProfile *profile, QObject *parent)
    : WebEngineViewer::WebEnginePage(profile, parent)
Laurent Montel's avatar
Laurent Montel committed
27
{
Laurent Montel's avatar
Laurent Montel committed
28
    settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
Laurent Montel's avatar
Laurent Montel committed
29 30
    settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
    settings()->setAttribute(QWebEngineSettings::AutoLoadImages, true);
31 32 33 34 35 36
    settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
    settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, false);
    settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
    settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
    settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, false);
    settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, false);
Laurent Montel's avatar
Laurent Montel committed
37 38 39
    settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
    settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, false);
    settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
40
    settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false);
Laurent Montel's avatar
Laurent Montel committed
41 42
    settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, false);
    settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
Laurent Montel's avatar
Laurent Montel committed
43 44 45
    connect(this, &QWebEnginePage::featurePermissionRequested,
            this, &ArticleViewerWebEnginePage::slotFeaturePermissionRequested);

Laurent Montel's avatar
Laurent Montel committed
46 47 48 49 50 51 52 53 54
}

ArticleViewerWebEnginePage::~ArticleViewerWebEnginePage()
{

}

bool ArticleViewerWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
{
Laurent Montel's avatar
Laurent Montel committed
55 56
    Q_UNUSED(type);
    if (isMainFrame && type == NavigationTypeLinkClicked) {
Laurent Montel's avatar
Laurent Montel committed
57
        Q_EMIT urlClicked(url);
58
        return false;
Laurent Montel's avatar
Laurent Montel committed
59
    }
Laurent Montel's avatar
Laurent Montel committed
60
    return true;
Laurent Montel's avatar
Laurent Montel committed
61
}
Laurent Montel's avatar
Laurent Montel committed
62

Laurent Montel's avatar
Laurent Montel committed
63
void ArticleViewerWebEnginePage::slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature)
Laurent Montel's avatar
Laurent Montel committed
64 65 66 67
{
    //Denied all permissions.
    setFeaturePermission(url, feature, QWebEnginePage::PermissionDeniedByUser);
}