summaryrefslogtreecommitdiffstats
path: root/src/core/api/qwebengineglobalsettings.cpp
blob: a12c8d2fd334fd4c0a19b87747a664f23178b819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qwebengineglobalsettings.h"
#include "qwebengineglobalsettings_p.h"

#ifdef signals
#undef signals
#endif

#include "content/public/browser/network_service_instance.h"
#include "services/network/network_service.h"

QT_BEGIN_NAMESPACE

/*!
    \class QWebEngineGlobalSettings
    \brief The QWebEngineGlobalSettings class configures global properties of the web engine.
    \since 6.6
    \inmodule QtWebEngineCore

    The QWebEngineGlobalSettings class is a singleton that configures global properties
    of the web engine.

    Invoke configureDnsOverHttps() to configure DNS-over-HTTPS capabilities.

    \sa QWebEngineGlobalSettings::configureDnsOverHttps()
*/

QWebEngineGlobalSettings::QWebEngineGlobalSettings(QObject *p)
    : QObject(p), d_ptr(new QWebEngineGlobalSettingsPrivate)
{
}

QWebEngineGlobalSettings::~QWebEngineGlobalSettings() { }

/*!
    \fn QWebEngineGlobalSettings *QWebEngineGlobalSettings::GetInstance()

    Gets the global instance of QWebEngineGlobalSettings.
*/
QWebEngineGlobalSettings *QWebEngineGlobalSettings::GetInstance()
{
    static QWebEngineGlobalSettings settings;
    return &settings;
}

/*!
    \enum QWebEngineGlobalSettings::DnsMode

    This enum sets the DNS-over-HTTPS mode:

    \value WithFallback Enable DNS-over-HTTPS with fallbacks. If a host
    can't be resolved, try the insecure DNS client of Chromium. If that fails as
    well, try the system DNS host resolution, which can be secure or insecure.
    \value Secure Enable DNS-over-HTTPS and only allow the secure Chromium
    DNS client to resolve hosts.
*/

/*!
    \fn QWebEngineGlobalSettings::configureDnsOverHttps(const DnsMode dnsMode,
                                                        const QString &dnsOverHttpsTemplates)

    Configures the Chromium stub host resolver, thus allowing DNS-over-HTTPS functionality.

    Set \a dnsMode to QWebEngineGlobalSettings::DnsMode::WithFallback to enable secure DNS
    host resolution with a fallback to insecure DNS host resolution and a final fallback to
    the system DNS resolution, which can be secure or insecure. Set it to
    QWebEngineGlobalSettings::DnsMode::Secure to only allow secure DNS host resolution via
    the Chromium DNS client.

    Independently of \a {dnsMode}, \a dnsOverHttpsTemplates has to be set to one or multiple
    valid \l{https://datatracker.ietf.org/doc/html/rfc6570}{URI templates} separated by
    whitespace characters. One example URI template is https://dns.google/dns-query{?dns}.
*/
void QWebEngineGlobalSettings::configureDnsOverHttps(const DnsMode dnsMode,
                                                     const QString &dnsOverHttpsTemplates)
{
    Q_D(QWebEngineGlobalSettings);

    d->dnsMode = dnsMode;
    d->dnsOverHttpsTemplates = dnsOverHttpsTemplates.toStdString();
    d->isDnsOverHttpsUserConfigured = true;

    // Make sure that DoH settings are in effect immediately if the network service already exists,
    // thus allowing to change DoH configuration at any point
    network::mojom::NetworkService *networkService = content::GetNetworkService();
    if (networkService) {
        networkService->ConfigureStubHostResolver(
                d->insecureDnsClientEnabled, net::SecureDnsMode(d->dnsMode),
                *net::DnsOverHttpsConfig::FromString(d->dnsOverHttpsTemplates),
                d->additionalInsecureDnsTypesEnabled);
    }
}

QT_END_NAMESPACE