summaryrefslogtreecommitdiffstats
path: root/src/core/api/qtwebenginecoreglobal.cpp
blob: 18da6bd4374293915194039fcb36ab3cf2e4d77d (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
// Copyright (C) 2021 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
// Qt-Security score:significant reason:default

#include "qtwebenginecoreglobal_p.h"

#include "web_engine_context.h"
#include "web_engine_library_info.h"

#include "base/base_paths.h"
#include "base/i18n/icu_util.h"
#include "base/path_service.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"

#include <QUrl>

namespace QtWebEngineCore {
Q_WEBENGINECORE_EXPORT void initialize() { }

bool closingDown()
{
    return WebEngineContext::closingDown();
}

} // namespace QtWebEngineCore

#if defined(Q_OS_WIN)
namespace QtWebEngineSandbox {
sandbox::SandboxInterfaceInfo *staticSandboxInterfaceInfo(sandbox::SandboxInterfaceInfo *info)
{
    static sandbox::SandboxInterfaceInfo *g_info = nullptr;
    if (info) {
        Q_ASSERT(g_info == nullptr);
        g_info = info;
    }
    return g_info;
}
} //namespace
#endif

QT_BEGIN_NAMESPACE

QString qWebEngineGetDomainAndRegistry(const QUrl &url) {
    base::FilePath icuDataPath;
    // Let's assume that ICU is already initialized if DIR_QT_LIBRARY_DATA is set.
    if (!base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &icuDataPath)) {
        icuDataPath = WebEngineLibraryInfo::getPath(base::DIR_QT_LIBRARY_DATA);
        if (!base::PathService::OverrideAndCreateIfNeeded(base::DIR_QT_LIBRARY_DATA, icuDataPath, false, false))
            qWarning("Failed to set ICU data path.");
        base::i18n::InitializeICU();
    }

    const QString host = url.host();
    const std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(host.toStdString(), net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
    return QString::fromStdString(domain);
}

QT_END_NAMESPACE