Messagelib

webengineviewer/src/urlinterceptor/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "loadexternalreferencesurlinterceptor.h"
8 #include <QWebEngineUrlRequestInfo>
9 
10 using namespace WebEngineViewer;
11 
12 LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
14 {
15 }
16 
17 LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor() = default;
18 
19 bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
20 {
21  const QUrl requestUrl = info.requestUrl();
22  const QString scheme = requestUrl.scheme();
23  if (scheme == QLatin1String("data") || scheme == QLatin1String("file")) {
24  return false;
25  }
26  const QWebEngineUrlRequestInfo::ResourceType resourceType{info.resourceType()};
27  if (mAllowLoadExternalReference) {
28  if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1String("cid"))) {
29  return urlIsBlocked(requestUrl);
30  }
31  return false;
32  } else {
33  if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1String("cid"))) {
34  return urlIsAuthorized(requestUrl);
35  } else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeFontResource) {
36  return true;
37  } else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeStylesheet) {
38  return true;
39  }
40  }
41  return false;
42 }
43 
44 bool LoadExternalReferencesUrlInterceptor::urlIsBlocked(const QUrl &requestedUrl)
45 {
46  Q_UNUSED(requestedUrl)
47  return false;
48 }
49 
50 bool LoadExternalReferencesUrlInterceptor::urlIsAuthorized(const QUrl &requestedUrl)
51 {
52  Q_UNUSED(requestedUrl)
53  return true;
54 }
55 
56 void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b)
57 {
58  mAllowLoadExternalReference = b;
59 }
60 
61 bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const
62 {
63  return mAllowLoadExternalReference;
64 }
QString scheme() const const
bool isLocalFile() const const
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.