loadexternalreferencesurlinterceptor.cpp 1.61 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

4
   SPDX-License-Identifier: LGPL-2.0-or-later
5
6
7
8
*/

#include "loadexternalreferencesurlinterceptor.h"

Laurent Montel's avatar
Laurent Montel committed
9
#include <QDebug>
10
11
12
13
14
#include <QWebEngineUrlRequestInfo>

using namespace MessageViewer;

LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
Laurent Montel's avatar
Laurent Montel committed
15
    : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
16
17
18
19
20
21
22
{
}

LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor()
{
}

23
bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
24
{
25
    const QString scheme = info.requestUrl().scheme();
Laurent Montel's avatar
Laurent Montel committed
26
    if (scheme == QLatin1String("data") || scheme == QLatin1String("file")) {
27
        return false;
Laurent Montel's avatar
Laurent Montel committed
28
    }
29
    if (mAllowLoadExternalReference) {
Laurent Montel's avatar
Laurent Montel committed
30
31
        return false;
    } else {
Laurent Montel's avatar
Laurent Montel committed
32
        if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage && !info.requestUrl().isLocalFile() && (scheme != QLatin1String("cid"))) {
33
            Q_EMIT urlBlocked(info.requestUrl());
Laurent Montel's avatar
Laurent Montel committed
34
            qDebug() << " info.requestUrl()" << info.requestUrl();
35
            return true;
36
37
        } else if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeFontResource) {
            return true;
Laurent Montel's avatar
Laurent Montel committed
38
39
        } else if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeStylesheet) {
            return true;
40
41
        }
    }
42
    return false;
43
44
45
46
}

void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b)
{
47
    mAllowLoadExternalReference = b;
48
49
50
51
}

bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const
{
52
    return mAllowLoadExternalReference;
53
}