summaryrefslogtreecommitdiffstats
path: root/src/core/net/version_ui_qt.cpp
blob: 61a89596a2d7e28ee0e1030867a7c49a44ad1b15 (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
// 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 "version_ui_qt.h"
#include "api/qtwebenginecoreglobal.h"
#include "build/build_config.h"
#include "base/command_line.h"
#include "chrome/common/url_constants.h"
#include "chrome/browser/profiles/profile.h"
#include "qtwebengine/grit/qt_webengine_resources.h"
#include "services/network/public/cpp/content_security_policy/content_security_policy.h"

namespace {
const char kQtWebEngineVersion[] = "qtwebengine_version";
const char kQtWebEngineChromiumVersion[] = "qtwebengine_chromium_version";
const char kQtWebEngineChromiumSecurityPatchVersion[] =
        "qtwebengine_chromium_security_patch_version";
const char kCommandLine[] = "command_line";
const char kQtVersionCSS[] = "qt_version.css";
const char kQtLogo[] = "images/qt.png";
const char kQtWebEngineLogo[] = "images/qtwebengine.png";
}

VersionUIQt::VersionUIQt(content::WebUI *web_ui) : content::WebUIController(web_ui)
{

    Profile *profile = Profile::FromWebUI(web_ui);
    content::WebUIDataSource *html_source =
            content::WebUIDataSource::CreateAndAdd(profile, chrome::kChromeUIVersionQtHost);
    html_source->OverrideContentSecurityPolicy(
            network::mojom::CSPDirectiveName::ScriptSrc,
            "script-src chrome://resources 'self' 'unsafe-inline';");
    html_source->SetDefaultResource(IDR_VERSION_UI_QT_HTML);
    html_source->AddResourcePath(kQtVersionCSS, IDR_VERSION_UI_QT_CSS);
    html_source->AddResourcePath(kQtLogo, IDR_QT_LOGO);
    html_source->AddResourcePath(kQtWebEngineLogo, IDR_QTWEBENGINE_LOGO);

    html_source->AddString(kQtWebEngineVersion, qWebEngineVersion());
    html_source->AddString(kQtWebEngineChromiumVersion, qWebEngineChromiumVersion());
    html_source->AddString(kQtWebEngineChromiumSecurityPatchVersion,
                           qWebEngineChromiumSecurityPatchVersion());
#if BUILDFLAG(IS_WIN)
    html_source->AddString(
            kCommandLine,
            base::AsString16(base::CommandLine::ForCurrentProcess()->GetCommandLineString()));
#else
    std::string command_line;
    typedef std::vector<std::string> ArgvList;
    const ArgvList &argv = base::CommandLine::ForCurrentProcess()->argv();
    for (auto iter = argv.begin(); iter != argv.end(); iter++)
        command_line += " " + *iter;
    html_source->AddString(kCommandLine, command_line);
#endif
}

VersionUIQt::~VersionUIQt() { }