Messagelib

cidreferencesurlinterceptor.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "cidreferencesurlinterceptor.h"
8#include "htmlwriter/webengineembedpart.h"
9
10#include <QUrl>
11#include <QWebEngineUrlRequestInfo>
12
13// This class is not needed if we get cidschemehandler working,
14// which could also help us avoid having to giving local file access.
15
16using namespace MessageViewer;
17CidReferencesUrlInterceptor::CidReferencesUrlInterceptor(QObject *parent)
18 : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
19{
20}
21
22CidReferencesUrlInterceptor::~CidReferencesUrlInterceptor() = default;
23
24bool CidReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
25{
26 const QUrl urlRequestUrl(info.requestUrl());
27 if (urlRequestUrl.scheme() == QLatin1StringView("cid")) {
28 if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage) {
29 const QUrl newUrl = QUrl(MessageViewer::WebEngineEmbedPart::self()->contentUrl(urlRequestUrl.path()));
30 if (!newUrl.isEmpty()) {
31 info.redirect(newUrl);
32 }
33 }
34 }
35 return false;
36}
37
38#include "moc_cidreferencesurlinterceptor.cpp"
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.