diff options
author | Michal Klocek <michal.klocek@qt.io> | 2023-01-05 10:54:33 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-08-14 14:55:54 +0000 |
commit | 75133302ee7f6b3f48e4df18c31e09bdeddb1b68 (patch) | |
tree | 79a09cf0dd1a104f680845a4e783f67c07ed68f9 | |
parent | 0484b100fbee19cddef7d632f8be651166fdb3f1 (diff) |
Add initial internal version page
We kept urls in examples to point to company website.
However this site is heavy to load and moreover it changes
overtime leaving example screenshots obsolete.
Introduce internal qt version web ui page which will
be default page for examples and which displays basic
information and can work offline.
For start show version info and command line options
for chrome://qt
Change-Id: I0271ce6e7b152efe4942a6240b0c74ba382d5fcc
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
(cherry picked from commit a748cb9183143b76cad1e940220dcabf25475493)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/webenginequick/quicknanobrowser/main.cpp | 2 | ||||
-rw-r--r-- | examples/webenginewidgets/simplebrowser/main.cpp | 2 | ||||
-rw-r--r-- | src/core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/core/net/webui_controller_factory_qt.cpp | 5 | ||||
-rw-r--r-- | src/core/version_ui_qt.cpp | 57 | ||||
-rw-r--r-- | src/core/version_ui_qt.h | 32 | ||||
-rw-r--r-- | tests/auto/core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/core/qtversion/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tests/auto/core/qtversion/tst_qtversion.cpp | 34 | ||||
-rw-r--r-- | tests/manual/examples/quick/minimal/main.qml | 2 | ||||
-rw-r--r-- | tests/manual/examples/widgets/minimal/main.cpp | 2 |
11 files changed, 143 insertions, 5 deletions
diff --git a/examples/webenginequick/quicknanobrowser/main.cpp b/examples/webenginequick/quicknanobrowser/main.cpp index 850b8c443..1e693cbcd 100644 --- a/examples/webenginequick/quicknanobrowser/main.cpp +++ b/examples/webenginequick/quicknanobrowser/main.cpp @@ -21,7 +21,7 @@ static QUrl startupUrl(const QCommandLineParser &parser) if (url.isValid()) return url; } - return QUrl(QStringLiteral("https://www.qt.io")); + return QUrl(QStringLiteral("chrome://qt")); } int main(int argc, char **argv) diff --git a/examples/webenginewidgets/simplebrowser/main.cpp b/examples/webenginewidgets/simplebrowser/main.cpp index d5d9e78ab..bd9a3a198 100644 --- a/examples/webenginewidgets/simplebrowser/main.cpp +++ b/examples/webenginewidgets/simplebrowser/main.cpp @@ -18,7 +18,7 @@ QUrl commandLineUrlArgument() if (!arg.startsWith(u'-')) return QUrl::fromUserInput(arg); } - return QUrl(u"https://www.qt.io"_s); + return QUrl(u"chrome://qt"_s); } int main(int argc, char **argv) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 21793972d..4153ce180 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -183,6 +183,7 @@ foreach(arch ${archs}) type_conversion.cpp type_conversion.h user_notification_controller.cpp user_notification_controller.h user_script.cpp user_script.h + version_ui_qt.cpp version_ui_qt.h visited_links_manager_qt.cpp visited_links_manager_qt.h web_contents_adapter.cpp web_contents_adapter.h web_contents_adapter_client.h diff --git a/src/core/net/webui_controller_factory_qt.cpp b/src/core/net/webui_controller_factory_qt.cpp index ca0e66a9b..ed35a3e36 100644 --- a/src/core/net/webui_controller_factory_qt.cpp +++ b/src/core/net/webui_controller_factory_qt.cpp @@ -10,7 +10,6 @@ #include "build_config_qt.h" #include "devtools_frontend_qt.h" - #include "base/functional/bind.h" #include "build/build_config.h" #include "chrome/browser/accessibility/accessibility_ui.h" @@ -26,6 +25,7 @@ #include "media/media_buildflags.h" #include "printing/buildflags/buildflags.h" #include "url/gurl.h" +#include "version_ui_qt.h" #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) #include "chrome/browser/ui/webui/sandbox/sandbox_internals_ui.h" @@ -107,6 +107,9 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI *web_ui, Profile *profile, co if (url.host_piece() == chrome::kChromeUIDeviceLogHost) return &NewWebUI<chromeos::DeviceLogUI>; + if (url.host_piece() == chrome::kChromeUIVersionQtHost) + return &NewWebUI<VersionUIQt>; + // if (url.host_piece() == chrome::kChromeUIInspectHost) // return &NewWebUI<InspectUI>; // diff --git a/src/core/version_ui_qt.cpp b/src/core/version_ui_qt.cpp new file mode 100644 index 000000000..252394e2b --- /dev/null +++ b/src/core/version_ui_qt.cpp @@ -0,0 +1,57 @@ +// 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/qtlogo.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::Create(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("images/qt.png", IDR_QT_LOGO); + html_source->AddResourcePath("images/qtwebengine.png", 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 + content::WebUIDataSource::Add(profile, html_source); +} + +VersionUIQt::~VersionUIQt() { } diff --git a/src/core/version_ui_qt.h b/src/core/version_ui_qt.h new file mode 100644 index 000000000..1fe8ef9e0 --- /dev/null +++ b/src/core/version_ui_qt.h @@ -0,0 +1,32 @@ +// 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 + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef VERSION_UI_QT_H_ +#define VERSION_UI_QT_H_ + +#include "build/build_config.h" +#include "content/public/browser/web_ui_controller.h" +#include "content/public/browser/web_ui_data_source.h" + +class VersionUIQt : public content::WebUIController +{ +public: + explicit VersionUIQt(content::WebUI *web_ui); + ~VersionUIQt() override; + + VersionUIQt(const VersionUIQt &) = delete; + VersionUIQt &operator=(const VersionUIQt &) = delete; +}; + +#endif // VERSION_UI_QT_H diff --git a/tests/auto/core/CMakeLists.txt b/tests/auto/core/CMakeLists.txt index 9981d4950..3dd8b720a 100644 --- a/tests/auto/core/CMakeLists.txt +++ b/tests/auto/core/CMakeLists.txt @@ -11,6 +11,7 @@ add_subdirectory(qwebengineurlrequestjob) add_subdirectory(origins) add_subdirectory(devtools) add_subdirectory(getdomainandregistry) +add_subdirectory(qtversion) if(QT_FEATURE_ssl) add_subdirectory(qwebengineclientcertificatestore) diff --git a/tests/auto/core/qtversion/CMakeLists.txt b/tests/auto/core/qtversion/CMakeLists.txt new file mode 100644 index 000000000..9a5e89266 --- /dev/null +++ b/tests/auto/core/qtversion/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_internal_add_test(tst_qtversion + SOURCES + tst_qtversion.cpp + LIBRARIES + Qt::WebEngineCore +) + diff --git a/tests/auto/core/qtversion/tst_qtversion.cpp b/tests/auto/core/qtversion/tst_qtversion.cpp new file mode 100644 index 000000000..44c2d4e5c --- /dev/null +++ b/tests/auto/core/qtversion/tst_qtversion.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QtTest/QtTest> +#include <QtWebEngineCore/qwebenginepage.h> + +class tst_QtVersion : public QObject +{ + Q_OBJECT +signals: + void done(); +private Q_SLOTS: + void checkVersion(); +}; + +void tst_QtVersion::checkVersion() +{ + QWebEnginePage page; + QSignalSpy loadSpy(&page, &QWebEnginePage::loadFinished); + QSignalSpy doneSpy(this, &tst_QtVersion::done); + page.load(QUrl("chrome://qt")); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.size(), 1, 12000); + page.toPlainText([this](const QString &result) { + QVERIFY(result.contains(qWebEngineVersion())); + QVERIFY(result.contains(qWebEngineChromiumVersion())); + QVERIFY(result.contains(qWebEngineChromiumSecurityPatchVersion())); + emit done(); + }); + QTRY_VERIFY(doneSpy.size()); +} + +QTEST_MAIN(tst_QtVersion) + +#include "tst_qtversion.moc" diff --git a/tests/manual/examples/quick/minimal/main.qml b/tests/manual/examples/quick/minimal/main.qml index a8733a8c8..6890b501b 100644 --- a/tests/manual/examples/quick/minimal/main.qml +++ b/tests/manual/examples/quick/minimal/main.qml @@ -11,6 +11,6 @@ Window { visible: true WebEngineView { anchors.fill: parent - url: "https://www.qt.io" + url: "chrome://qt" } } diff --git a/tests/manual/examples/widgets/minimal/main.cpp b/tests/manual/examples/widgets/minimal/main.cpp index 86c04e721..425973116 100644 --- a/tests/manual/examples/widgets/minimal/main.cpp +++ b/tests/manual/examples/widgets/minimal/main.cpp @@ -11,7 +11,7 @@ QUrl commandLineUrlArgument() if (!arg.startsWith(QLatin1Char('-'))) return QUrl::fromUserInput(arg); } - return QUrl(QStringLiteral("https://www.qt.io")); + return QUrl(QStringLiteral("chrome://qt")); } int main(int argc, char *argv[]) |