├── .tag ├── examples ├── examples.pro ├── webview │ ├── webview.pro │ ├── minibrowser │ │ ├── images │ │ │ ├── left-32.png │ │ │ ├── stop-32.png │ │ │ ├── refresh-32.png │ │ │ ├── right-32.png │ │ │ └── settings-32.png │ │ ├── doc │ │ │ ├── images │ │ │ │ └── webview-example.jpg │ │ │ └── src │ │ │ │ └── minibrowser.qdoc │ │ ├── minibrowser.pro │ │ ├── qml.qrc │ │ ├── macos │ │ │ └── Info.plist │ │ ├── CMakeLists.txt │ │ ├── ios │ │ │ └── Info.plist │ │ ├── main.cpp │ │ └── main.qml │ └── CMakeLists.txt └── CMakeLists.txt ├── src ├── plugins │ ├── wasm │ │ ├── wasm.json │ │ ├── CMakeLists.txt │ │ ├── qwasmwebviewplugin.cpp │ │ ├── qwasmwebview_p.h │ │ └── qwasmwebview.cpp │ ├── webengine │ │ ├── webengine.json │ │ ├── CMakeLists.txt │ │ ├── qwebenginewebviewplugin.cpp │ │ └── qwebenginewebview_p.h │ ├── darwin │ │ ├── darwin.json │ │ ├── qdarwinwebviewplugin.cpp │ │ ├── CMakeLists.txt │ │ └── qdarwinwebview_p.h │ ├── windows │ │ ├── windows.json │ │ ├── CMakeLists.txt │ │ ├── qwebview2webviewplugin.cpp │ │ └── qwebview2webview_p.h │ ├── android │ │ ├── android.json │ │ ├── CMakeLists.txt │ │ ├── qandroidwebviewplugin.cpp │ │ └── qandroidwebview_p.h │ └── CMakeLists.txt ├── CMakeLists.txt ├── webview │ ├── doc │ │ ├── src │ │ │ ├── qtwebview-examples.qdoc │ │ │ ├── qtwebview-qmltypes.qdoc │ │ │ ├── qtwebview-module.qdoc │ │ │ ├── qt6-changes.qdoc │ │ │ └── qtwebview-overview.qdoc │ │ └── qtwebview.qdocconf │ ├── qtwebviewfunctions.h │ ├── qwebviewplugin.cpp │ ├── qwebview_global.h │ ├── qwebviewfactory_p.h │ ├── qwebviewloadrequest.cpp │ ├── qwebviewplugin_p.h │ ├── qwebviewloadrequest.h │ ├── CMakeLists.txt │ ├── qwebviewsettings.cpp │ ├── qtwebviewfunctions.cpp │ ├── qwebviewsettings.h │ ├── configure.cmake │ ├── qwebview_p.h │ ├── qwebview.cpp │ ├── qwebviewfactory.cpp │ └── qwebview.h ├── jar │ └── CMakeLists.txt └── quick │ ├── qtwebviewquickglobal_p.h │ ├── CMakeLists.txt │ ├── qquickwebviewloadrequest_p.h │ ├── qquickwebviewloadrequest.cpp │ ├── qquickwebviewsettings_p.h │ ├── qquickwebviewsettings.cpp │ ├── qquickwebview_p.h │ └── qquickwebview.cpp ├── tests ├── auto │ ├── qml │ │ ├── CMakeLists.txt │ │ └── qquickwebview │ │ │ ├── html │ │ │ ├── basic_page2.html │ │ │ ├── basic_page.html │ │ │ ├── resources │ │ │ │ └── simple_image.png │ │ │ ├── cookies.html │ │ │ ├── inputmethod.html │ │ │ ├── javascript.html │ │ │ ├── scroll.html │ │ │ └── direct-image-compositing.html │ │ │ ├── dummy.qml │ │ │ ├── testwindow.h │ │ │ ├── CMakeLists.txt │ │ │ └── util.h │ ├── webview │ │ ├── CMakeLists.txt │ │ └── qwebview │ │ │ ├── BLACKLIST │ │ │ ├── CMakeLists.txt │ │ │ └── tst_qwebview.cpp │ └── CMakeLists.txt ├── manual │ ├── inquickwidget │ │ ├── qml.qrc │ │ ├── tst_quickwidget.pro │ │ ├── main.qml │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── CMakeLists.txt ├── tests.pro └── CMakeLists.txt ├── .gitreview ├── qt_cmdline.cmake ├── dependencies.yaml ├── .cmake.conf ├── config_help.txt ├── dist ├── REUSE.toml ├── changes-5.12.0 ├── changes-5.13.0 ├── changes-5.12.1 ├── changes-5.13.1 ├── changes-5.14.1 ├── changes-5.11.3 ├── changes-5.12.4 ├── changes-5.12.5 ├── changes-5.13.2 ├── changes-5.14.2 ├── changes-5.7.0 ├── changes-5.10.0 ├── changes-5.14.0 ├── changes-5.9.1 ├── changes-5.9.2 ├── changes-5.9.3 ├── changes-5.11.1 ├── changes-5.9.4 ├── changes-5.9.6 ├── changes-5.11.2 ├── changes-5.9.5 ├── changes-5.8.0 ├── changes-5.10.1 ├── changes-5.12.3 ├── changes-5.12.2 ├── changes-5.6.1 ├── changes-5.15.0 ├── changes-5.6.3 ├── changes-5.6.2 ├── changes-5.11.0 ├── changes-5.6.0 ├── changes-5.7.1 └── changes-5.9.0 ├── LICENSES ├── LicenseRef-Qt-Commercial.txt ├── BSD-3-Clause.txt └── LGPL-3.0-only.txt ├── coin ├── module_config.yaml ├── instructions │ ├── run_native_plugin_tests.yaml │ └── run_webengine_plugin_tests.yaml └── axivion │ └── ci_config_linux.json ├── CMakeLists.txt ├── cmake └── FindWebView2.cmake ├── REUSE.toml └── licenseRule.json /.tag: -------------------------------------------------------------------------------- 1 | c2b5a51e40fff4d7df979aef7bd837dfd3a65cdb 2 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS += webview 3 | -------------------------------------------------------------------------------- /src/plugins/wasm/wasm.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": ["native"] 3 | } 4 | -------------------------------------------------------------------------------- /tests/auto/qml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(qquickwebview) 2 | -------------------------------------------------------------------------------- /tests/auto/webview/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(qwebview) 2 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/basic_page2.html: -------------------------------------------------------------------------------- 1 |

Basic page 2

2 | -------------------------------------------------------------------------------- /examples/webview/webview.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | qtHaveModule(webview): SUBDIRS += minibrowser 3 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=codereview.qt-project.org 3 | project=qt/qtwebview 4 | defaultbranch=dev 5 | -------------------------------------------------------------------------------- /src/plugins/webengine/webengine.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": ["webengine"], 3 | "RequiresInit": true 4 | } 5 | -------------------------------------------------------------------------------- /src/plugins/darwin/darwin.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": [ 3 | "native", 4 | "webkit" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/auto/webview/qwebview/BLACKLIST: -------------------------------------------------------------------------------- 1 | # QTBUG-102712 2 | [load] 3 | android 4 | [loadRequest] 5 | android 6 | -------------------------------------------------------------------------------- /src/plugins/windows/windows.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": [ 3 | "native", 4 | "webview2" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /src/plugins/android/android.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": [ 3 | "native", 4 | "android_view" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/images/left-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/examples/webview/minibrowser/images/left-32.png -------------------------------------------------------------------------------- /examples/webview/minibrowser/images/stop-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/examples/webview/minibrowser/images/stop-32.png -------------------------------------------------------------------------------- /tests/manual/inquickwidget/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/images/refresh-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/examples/webview/minibrowser/images/refresh-32.png -------------------------------------------------------------------------------- /examples/webview/minibrowser/images/right-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/examples/webview/minibrowser/images/right-32.png -------------------------------------------------------------------------------- /examples/webview/minibrowser/images/settings-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/examples/webview/minibrowser/images/settings-32.png -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/basic_page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Basic Page 4 | 5 |

Basic page

6 | 7 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/dummy.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtWebView 1.1 3 | 4 | WebView { 5 | width: 100 6 | height: 62 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/manual/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | add_subdirectory(inquickwidget) 5 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/doc/images/webview-example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/examples/webview/minibrowser/doc/images/webview-example.jpg -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/resources/simple_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebview/HEAD/tests/auto/qml/qquickwebview/html/resources/simple_image.png -------------------------------------------------------------------------------- /qt_cmdline.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | qt_commandline_option(webview2-sdk TYPE path CMAKE_VARIABLE WEBVIEW2_SDK_ROOT) 5 | -------------------------------------------------------------------------------- /tests/manual/inquickwidget/tst_quickwidget.pro: -------------------------------------------------------------------------------- 1 | QT += core gui webview quickwidgets 2 | 3 | SOURCES += \ 4 | main.cpp 5 | 6 | RESOURCES += \ 7 | qml.qrc 8 | 9 | DISTFILES += \ 10 | main.qml 11 | -------------------------------------------------------------------------------- /dependencies.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | ../qtdeclarative: 3 | ref: fc162d455eedbb68f22f302dee45f7faf4146dd0 4 | required: true 5 | ../qtwebengine: 6 | ref: 018416c36b6cb53b9946bedaeaf965ee7bfc26d8 7 | required: false 8 | -------------------------------------------------------------------------------- /examples/webview/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | if(TARGET Qt6::WebView) 5 | qt_internal_add_example(minibrowser) 6 | endif() 7 | -------------------------------------------------------------------------------- /.cmake.conf: -------------------------------------------------------------------------------- 1 | set(QT_REPO_MODULE_VERSION "6.11.0") 2 | set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") 3 | set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_QASCONST=1") 4 | list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_FOREACH=1") 5 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/cookies.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | qt_examples_build_begin(EXTERNAL_BUILD) 5 | add_subdirectory(webview) 6 | qt_examples_build_end() 7 | -------------------------------------------------------------------------------- /config_help.txt: -------------------------------------------------------------------------------- 1 | WebView options: 2 | 3 | -webview2-sdk path .... Set WebView 2 SDK root path 4 | [$WEBVIEW2_SDK_ROOT, Setting this enables building of 5 | WebView2 plugin for Qt WebView.] (Windows only) 6 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | add_subdirectory(webview) 5 | add_subdirectory(quick) 6 | add_subdirectory(plugins) 7 | if(ANDROID) 8 | add_subdirectory(jar) 9 | endif() 10 | -------------------------------------------------------------------------------- /tests/tests.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | # Currently the tests are adapted for the platforms 4 | # that provide a native WebView implementation. 5 | android|ios|winrt { 6 | SUBDIRS += auto 7 | } 8 | 9 | SUBDIRS += \ 10 | manual/tst_quickwidget 11 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | if(QT_BUILD_STANDALONE_TESTS) 5 | find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS WebEngineCore WebEngineQuick) 6 | endif() 7 | 8 | qt_build_tests() 9 | -------------------------------------------------------------------------------- /dist/REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["*"] 5 | precedence = "override" 6 | comment = "Licensed as documentation." 7 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 9 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/inputmethod.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Basic Page For Input Method Testing 4 | 5 | 6 |

Basic page

7 | 8 | 9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /src/webview/doc/src/qtwebview-examples.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | 5 | /*! 6 | \group qtwebview-examples 7 | \title Qt WebView Examples 8 | \brief Examples for the Qt WebView module 9 | 10 | These are the Qt WebView examples. 11 | 12 | */ 13 | 14 | -------------------------------------------------------------------------------- /tests/manual/inquickwidget/main.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | import QtQuick 2.0 5 | import QtWebView 1.1 6 | 7 | Rectangle { 8 | anchors.fill: parent 9 | color: "green" 10 | 11 | WebView { 12 | anchors.fill: parent 13 | url: "https://qt.io" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/javascript.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | JavaScript 11 | 12 | 13 |
14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/minibrowser.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = minibrowser 3 | 4 | QT += qml quick webview 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | EXAMPLE_FILES += doc 11 | 12 | macos:QMAKE_INFO_PLIST = macos/Info.plist 13 | ios:QMAKE_INFO_PLIST = ios/Info.plist 14 | 15 | target.path = $$[QT_INSTALL_EXAMPLES]/webview/minibrowser 16 | INSTALLS += target 17 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | images/left-32.png 5 | images/stop-32.png 6 | images/refresh-32.png 7 | images/right-32.png 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/auto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | if(QT_FEATURE_webview_webengine_plugin OR 4 | QT_FEATURE_webview_webview2_plugin OR 5 | QT_FEATURE_webview_android_plugin OR 6 | QT_FEATURE_webview_darwin_plugin OR 7 | QT_FEATURE_webview_winrt_plugin OR 8 | QT_FEATURE_webview_wasm_plugin) 9 | add_subdirectory(webview) 10 | add_subdirectory(qml) 11 | endif() 12 | -------------------------------------------------------------------------------- /tests/auto/webview/qwebview/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## tst_qwebview Test: 6 | ##################################################################### 7 | 8 | qt_internal_add_test(tst_qwebview 9 | SOURCES 10 | tst_qwebview.cpp 11 | LIBRARIES 12 | Qt::Gui 13 | Qt::WebViewPrivate 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /src/jar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | 5 | qt_internal_add_jar(QtAndroidWebView 6 | INCLUDE_JARS ${QT_ANDROID_JAR} 7 | SOURCES src/org/qtproject/qt/android/view/QtAndroidWebViewController.java 8 | OUTPUT_DIR "${QT_BUILD_DIR}/jar" 9 | ) 10 | 11 | qt_path_join(destination ${INSTALL_DATADIR} "jar") 12 | 13 | install_jar(QtAndroidWebView 14 | DESTINATION ${destination} 15 | COMPONENT Devel 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /LICENSES/LicenseRef-Qt-Commercial.txt: -------------------------------------------------------------------------------- 1 | Licensees holding valid commercial Qt licenses may use this software in 2 | accordance with the the terms contained in a written agreement between 3 | you and The Qt Company. Alternatively, the terms and conditions that were 4 | accepted by the licensee when buying and/or downloading the 5 | software do apply. 6 | 7 | For the latest licensing terms and conditions, see https://www.qt.io/terms-conditions. 8 | For further information use the contact form at https://www.qt.io/contact-us. 9 | -------------------------------------------------------------------------------- /src/webview/qtwebviewfunctions.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QTWEBVIEWFUNCTIONS_H 6 | #define QTWEBVIEWFUNCTIONS_H 7 | 8 | #include 9 | 10 | QT_BEGIN_NAMESPACE 11 | 12 | namespace QtWebView 13 | { 14 | Q_WEBVIEW_EXPORT void initialize(); 15 | } 16 | 17 | QT_END_NAMESPACE 18 | 19 | #endif // QTWEBVIEWFUNCTIONS_H 20 | -------------------------------------------------------------------------------- /coin/module_config.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | accept_configuration: 3 | condition: property 4 | property: features 5 | not_contains_value: Disable 6 | 7 | instructions: 8 | Build: 9 | - type: EnvironmentVariable 10 | variableName: VERIFY_SOURCE_SBOM 11 | variableValue: "ON" 12 | - !include "{{qt/qtbase}}/coin_module_build_template_v2.yaml" 13 | 14 | Test: 15 | - !include "{{qt/qtwebview}}/run_native_plugin_tests.yaml" 16 | - !include "{{qt/qtwebview}}/run_webengine_plugin_tests.yaml" 17 | - !include "{{qt/qtbase}}/coin_module_test_docs.yaml" 18 | -------------------------------------------------------------------------------- /src/plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | if(QT_FEATURE_webview_android_plugin) 5 | add_subdirectory(android) 6 | endif() 7 | 8 | if(QT_FEATURE_webview_darwin_plugin) 9 | add_subdirectory(darwin) 10 | endif() 11 | 12 | if(QT_FEATURE_webview_wasm_plugin) 13 | add_subdirectory(wasm) 14 | endif() 15 | 16 | if(QT_FEATURE_webview_webview2_plugin) 17 | add_subdirectory(windows) 18 | endif() 19 | 20 | if(QT_FEATURE_webview_webengine_plugin) 21 | add_subdirectory(webengine) 22 | endif() 23 | -------------------------------------------------------------------------------- /src/plugins/wasm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## QWasmWebViewPlugin Plugin: 6 | ##################################################################### 7 | 8 | qt_internal_add_plugin(QWasmWebViewPlugin 9 | OUTPUT_NAME qtwebview_wasm 10 | PLUGIN_TYPE webview 11 | SOURCES 12 | qwasmwebview.cpp qwasmwebview_p.h 13 | qwasmwebviewplugin.cpp 14 | LIBRARIES 15 | Qt::CorePrivate 16 | Qt::Core 17 | Qt::Gui 18 | Qt::WebViewPrivate 19 | ) 20 | -------------------------------------------------------------------------------- /src/webview/qwebviewplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebviewplugin_p.h" 6 | 7 | QT_BEGIN_NAMESPACE 8 | 9 | QWebViewPlugin::QWebViewPlugin(QObject *parent) : QObject(parent) 10 | { 11 | 12 | } 13 | 14 | QWebViewPlugin::~QWebViewPlugin() 15 | { 16 | 17 | } 18 | 19 | void QWebViewPlugin::prepare() const 20 | { 21 | // Only called for plugins that has "RequiresInit" set to true in their plugin metadata. 22 | } 23 | 24 | QT_END_NAMESPACE 25 | -------------------------------------------------------------------------------- /src/webview/doc/src/qtwebview-qmltypes.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | 5 | /*! 6 | \qmlmodule QtWebView 7 | \title Qt WebView QML Types 8 | \ingroup qmlmodules 9 | \brief Provides QML types for Qt WebView. 10 | 11 | The Qt WebView module provides a QML type that can be used to include 12 | web content in an application. 13 | 14 | The QML type can be imported into your application using the following 15 | import statement: 16 | 17 | \qml 18 | import QtWebView 19 | \endqml 20 | 21 | \section1 QML Types 22 | */ 23 | -------------------------------------------------------------------------------- /src/webview/doc/src/qtwebview-module.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \module QtWebView 6 | \title Qt WebView C++ Classes and Namespaces 7 | \ingroup modules 8 | \brief Provides a helper function to set up and use the WebView. 9 | \qtvariable webview 10 | \qtcmakepackage WebView 11 | 12 | The Qt WebView module provides functionality to initialize the backend 13 | for using the WebView QML type. 14 | 15 | To include the module's definitions, use the following directive: 16 | 17 | \code 18 | #include 19 | \endcode 20 | */ 21 | -------------------------------------------------------------------------------- /tests/manual/inquickwidget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | find_package(Qt6 COMPONENTS Widgets QuickWidgets) 5 | 6 | qt_internal_add_manual_test(manual_tst_inquickwidget 7 | GUI 8 | SOURCES 9 | main.cpp 10 | LIBRARIES 11 | Qt::Gui 12 | Qt::Quick 13 | Qt::Widgets 14 | Qt::QuickWidgets 15 | Qt::WebView 16 | ) 17 | 18 | # Resources: 19 | set(qml_resource_files 20 | "main.qml" 21 | ) 22 | 23 | qt_internal_add_resource(manual_tst_inquickwidget "qml" 24 | PREFIX 25 | "/" 26 | FILES 27 | ${qml_resource_files} 28 | ) 29 | -------------------------------------------------------------------------------- /coin/instructions/run_native_plugin_tests.yaml: -------------------------------------------------------------------------------- 1 | type: Group 2 | enable_if: 3 | condition: or 4 | conditions: 5 | - condition: property 6 | property: target.os 7 | equals_value: Windows 8 | - condition: property 9 | property: target.osVersion 10 | equals_value: Android_ANY 11 | - condition: property 12 | property: target.os 13 | equals_value: MacOS 14 | - condition: property 15 | property: target.os 16 | equals_value: IOS 17 | instructions: 18 | - type: EnvironmentVariable 19 | variableName: QT_WEBVIEW_PLUGIN 20 | variableValue: native 21 | - !include "{{qt/qtbase}}/coin_module_test_template_v3.yaml" 22 | -------------------------------------------------------------------------------- /src/plugins/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## QAndroidWebViewPlugin Plugin: 6 | ##################################################################### 7 | 8 | qt_internal_add_plugin(QAndroidWebViewPlugin 9 | OUTPUT_NAME qtwebview_android 10 | PLUGIN_TYPE webview 11 | SOURCES 12 | qandroidwebview.cpp qandroidwebview_p.h 13 | qandroidwebviewplugin.cpp 14 | LIBRARIES 15 | jnigraphics 16 | Qt::CorePrivate 17 | Qt::Core 18 | Qt::Gui 19 | Qt::WebViewPrivate 20 | ) 21 | -------------------------------------------------------------------------------- /src/webview/qwebview_global.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEWGLOBAL_H 6 | #define QWEBVIEWGLOBAL_H 7 | 8 | #include 9 | #include 10 | 11 | QT_BEGIN_NAMESPACE 12 | 13 | #ifndef QT_STATIC 14 | # if defined(QT_BUILD_WEBVIEW_LIB) 15 | # define Q_WEBVIEW_EXPORT Q_DECL_EXPORT 16 | # else 17 | # define Q_WEBVIEW_EXPORT Q_DECL_IMPORT 18 | # endif 19 | #else 20 | # define Q_WEBVIEW_EXPORT 21 | #endif 22 | 23 | QT_END_NAMESPACE 24 | #endif // QWEBVIEWGLOBAL_H 25 | -------------------------------------------------------------------------------- /src/webview/doc/src/qt6-changes.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebview-changes-qt6.html 6 | \title Changes to Qt WebView 7 | \ingroup changes-qt-5-to-6 8 | \brief Migrate Qt WebView to Qt 6. 9 | 10 | Qt 6 is a result of the conscious effort to make the framework more 11 | efficient and easy to use. 12 | 13 | We try to maintain binary and source compatibility for all the public 14 | APIs in each release. But some changes were inevitable in an effort to 15 | make Qt a better framework. 16 | 17 | No source breaking changes have been made to Qt WebView. 18 | 19 | */ 20 | -------------------------------------------------------------------------------- /src/plugins/webengine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## QWebEngineWebViewPlugin Plugin: 6 | ##################################################################### 7 | 8 | qt_internal_add_plugin(QWebEngineWebViewPlugin 9 | OUTPUT_NAME qtwebview_webengine 10 | PLUGIN_TYPE webview 11 | SOURCES 12 | qwebenginewebview.cpp qwebenginewebview_p.h 13 | qwebenginewebviewplugin.cpp 14 | LIBRARIES 15 | Qt::Core 16 | Qt::Gui 17 | Qt::WebEngineCorePrivate 18 | Qt::WebEngineQuickPrivate 19 | Qt::WebViewPrivate 20 | Qt::WebViewQuickPrivate 21 | ) 22 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/scroll.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 21 | 22 | 23 | Scroll test 24 | 25 | 26 |
27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /dist/changes-5.12.0: -------------------------------------------------------------------------------- 1 | Qt 5.12 introduces many new features and improvements as well as bugfixes 2 | over the 5.11.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 8 | Applications compiled for 5.11 will continue to run with 5.12. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | - This release contains only minor code improvements. 19 | -------------------------------------------------------------------------------- /dist/changes-5.13.0: -------------------------------------------------------------------------------- 1 | Qt 5.13 introduces many new features and improvements as well as bugfixes 2 | over the 5.12.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 8 | Applications compiled for 5.12 will continue to run with 5.13. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | - This release contains only minor code improvements. 19 | -------------------------------------------------------------------------------- /src/plugins/wasm/qwasmwebviewplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwasmwebview_p.h" 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | 10 | class QWasmWebViewPlugin : public QWebViewPlugin 11 | { 12 | Q_OBJECT 13 | Q_PLUGIN_METADATA(IID QWebViewPluginInterface_iid FILE "wasm.json") 14 | 15 | public: 16 | QWebViewPrivate *create(const QString &key, QWebView *view) const override 17 | { 18 | return key == QLatin1String("webview") ? new QWasmWebViewPrivate(view) : nullptr; 19 | } 20 | }; 21 | 22 | QT_END_NAMESPACE 23 | 24 | #include "qwasmwebviewplugin.moc" 25 | -------------------------------------------------------------------------------- /src/plugins/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## QWebview2Webview Plugin: 6 | ##################################################################### 7 | 8 | qt_internal_add_plugin(QWebView2WebViewPlugin 9 | OUTPUT_NAME qtwebview_webview2 10 | PLUGIN_TYPE webview 11 | SOURCES 12 | qwebview2webview.cpp qwebview2webview_p.h 13 | qwebview2webviewplugin.cpp 14 | INCLUDE_DIRECTORIES 15 | ${WEBVIEW2_INCLUDE_DIR} 16 | LIBRARIES 17 | urlmon 18 | Qt::Core 19 | Qt::Gui 20 | Qt::WebViewPrivate 21 | WebView2::WebView2 22 | NO_PCH_SOURCES 23 | "qwebview2webview.cpp" 24 | ) 25 | -------------------------------------------------------------------------------- /tests/manual/inquickwidget/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | QQuickWindow::setGraphicsApi(QSGRendererInterface::GraphicsApi::OpenGL); 11 | QApplication a(argc, argv); 12 | QWidget w; 13 | w.setGeometry(0, 0, 800, 600); 14 | w.setLayout(new QHBoxLayout); 15 | QQuickWidget *qw = new QQuickWidget; 16 | qw->setResizeMode(QQuickWidget::ResizeMode::SizeRootObjectToView); 17 | qw->setSource(QUrl(QStringLiteral("qrc:/main.qml"))); 18 | w.layout()->addWidget(qw); 19 | w.show(); 20 | return a.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /coin/instructions/run_webengine_plugin_tests.yaml: -------------------------------------------------------------------------------- 1 | type: Group 2 | enable_if: 3 | condition: or 4 | conditions: 5 | - condition: property 6 | property: target.os 7 | equals_value: Windows 8 | - condition: property 9 | property: target.os 10 | equals_value: MacOS 11 | - condition: property 12 | property: target.os 13 | equals_value: Linux 14 | instructions: 15 | - type: EnvironmentVariable 16 | variableName: QTWEBENGINE_DISABLE_SANDBOX 17 | variableValue: "1" 18 | enable_if: 19 | condition: property 20 | property: target.osVersion 21 | equals_value: QEMU 22 | - type: EnvironmentVariable 23 | variableName: QT_WEBVIEW_PLUGIN 24 | variableValue: webengine 25 | - !include "{{qt/qtbase}}/coin_module_test_template_v3.yaml" 26 | -------------------------------------------------------------------------------- /src/plugins/android/qandroidwebviewplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qandroidwebview_p.h" 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | 10 | class QAndroidWebViewPlugin : public QWebViewPlugin 11 | { 12 | Q_OBJECT 13 | Q_PLUGIN_METADATA(IID QWebViewPluginInterface_iid FILE "android.json") 14 | 15 | public: 16 | QWebViewPrivate *create(const QString &key, QWebView *view) const override 17 | { 18 | return (key == QLatin1String("webview")) ? new QAndroidWebViewPrivate(view) : nullptr; 19 | } 20 | }; 21 | 22 | QT_END_NAMESPACE 23 | 24 | #include "qandroidwebviewplugin.moc" 25 | -------------------------------------------------------------------------------- /dist/changes-5.12.1: -------------------------------------------------------------------------------- 1 | Qt 5.12.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.1: -------------------------------------------------------------------------------- 1 | Qt 5.13.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.1: -------------------------------------------------------------------------------- 1 | Qt 5.14.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /src/plugins/windows/qwebview2webviewplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2025 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebview2webview_p.h" 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | 10 | class QWebView2WebViewPlugin : public QWebViewPlugin 11 | { 12 | Q_OBJECT 13 | Q_PLUGIN_METADATA(IID QWebViewPluginInterface_iid FILE "windows.json") 14 | 15 | public: 16 | QWebViewPrivate *create(const QString &key, QWebView *view) const override 17 | { 18 | return (key == QLatin1String("webview")) ? new QWebView2WebViewPrivate(view) : nullptr; 19 | } 20 | }; 21 | 22 | QT_END_NAMESPACE 23 | 24 | #include "qwebview2webviewplugin.moc" 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.3: -------------------------------------------------------------------------------- 1 | Qt 5.11.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.4: -------------------------------------------------------------------------------- 1 | Qt 5.12.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.3. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.5: -------------------------------------------------------------------------------- 1 | Qt 5.12.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.4. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.2: -------------------------------------------------------------------------------- 1 | Qt 5.13.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0 through 5.13.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.2: -------------------------------------------------------------------------------- 1 | Qt 5.14.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0 through 5.14.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /src/plugins/webengine/qwebenginewebviewplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebenginewebview_p.h" 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | 10 | class QWebEngineWebViewPlugin : public QWebViewPlugin 11 | { 12 | Q_OBJECT 13 | Q_PLUGIN_METADATA(IID QWebViewPluginInterface_iid FILE "webengine.json") 14 | 15 | public: 16 | QWebViewPrivate *create(const QString &key, QWebView *view) const override 17 | { 18 | return (key == QLatin1String("webview")) ? new QWebEngineWebViewPrivate(view) : nullptr; 19 | } 20 | 21 | void prepare() const override { } 22 | }; 23 | 24 | QT_END_NAMESPACE 25 | 26 | #include "qwebenginewebviewplugin.moc" 27 | -------------------------------------------------------------------------------- /src/plugins/darwin/qdarwinwebviewplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qdarwinwebview_p.h" 6 | #include 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | 11 | class QDarwinWebViewPlugin : public QWebViewPlugin 12 | { 13 | Q_OBJECT 14 | Q_PLUGIN_METADATA(IID QWebViewPluginInterface_iid FILE "darwin.json") 15 | 16 | public: 17 | QWebViewPrivate *create(const QString &key, QWebView *view) const override 18 | { 19 | return (key == QLatin1String("webview")) ? new QDarwinWebViewPrivate(view) : nullptr; 20 | } 21 | 22 | void prepare() const override 23 | { 24 | } 25 | }; 26 | 27 | QT_END_NAMESPACE 28 | 29 | #include "qdarwinwebviewplugin.moc" 30 | -------------------------------------------------------------------------------- /dist/changes-5.7.0: -------------------------------------------------------------------------------- 1 | Qt 5.7 introduces many new features and improvements as well as bugfixes 2 | over the 5.6.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io 6 | 7 | The Qt version 5.7 series is binary compatible with the 5.6.x series. 8 | Applications compiled for 5.6 will continue to run with 5.7. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | - This release contains only minor improvements. 22 | -------------------------------------------------------------------------------- /src/webview/qwebviewfactory_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEWFACTORY_H 6 | #define QWEBVIEWFACTORY_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include "qwebview_p.h" 20 | 21 | QT_BEGIN_NAMESPACE 22 | 23 | class QWebViewPlugin; 24 | 25 | namespace QWebViewFactory 26 | { 27 | QWebViewPlugin *getPlugin(); 28 | QWebViewPrivate *createWebView(QWebView *view); 29 | bool requiresExtraInitializationSteps(); 30 | Q_WEBVIEW_EXPORT bool loadedPluginHasKey(const QString key); 31 | }; 32 | 33 | QT_END_NAMESPACE 34 | 35 | #endif // QWEBVIEWFACTORY_H 36 | -------------------------------------------------------------------------------- /src/quick/qtwebviewquickglobal_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QTWEBVIEWQUICKGLOBAL_H 6 | #define QTWEBVIEWQUICKGLOBAL_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | 21 | QT_BEGIN_NAMESPACE 22 | 23 | #ifndef QT_STATIC 24 | # if defined(QT_BUILD_WEBVIEWQUICK_LIB) 25 | # define Q_WEBVIEWQUICK_EXPORT Q_DECL_EXPORT 26 | # else 27 | # define Q_WEBVIEWQUICK_EXPORT Q_DECL_IMPORT 28 | # endif 29 | #else 30 | # define Q_WEBVIEWQUICK_EXPORT 31 | #endif 32 | 33 | QT_END_NAMESPACE 34 | 35 | #endif // QTWEBENGINEQUICKGLOBAL_H 36 | -------------------------------------------------------------------------------- /src/webview/qwebviewloadrequest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | 9 | QWebViewLoadRequest::QWebViewLoadRequest() { } 10 | 11 | QWebViewLoadRequest::QWebViewLoadRequest(const QUrl &url, LoadStatus status, 12 | const QString &errorString) 13 | : m_url(url), m_status(status), m_errorString(errorString) 14 | { 15 | } 16 | 17 | QWebViewLoadRequest::~QWebViewLoadRequest() { } 18 | 19 | // FIXME add c++ docs 20 | 21 | QUrl QWebViewLoadRequest::url() const 22 | { 23 | return m_url; 24 | } 25 | 26 | QWebViewLoadRequest::LoadStatus QWebViewLoadRequest::status() const 27 | { 28 | return m_status; 29 | } 30 | 31 | QString QWebViewLoadRequest::errorString() const 32 | { 33 | return m_errorString; 34 | } 35 | 36 | QT_END_NAMESPACE 37 | -------------------------------------------------------------------------------- /dist/changes-5.10.0: -------------------------------------------------------------------------------- 1 | Qt 5.10 introduces many new features and improvements as well as bugfixes 2 | over the 5.9.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 8 | Applications compiled for 5.9 will continue to run with 5.10. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.10.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /dist/changes-5.14.0: -------------------------------------------------------------------------------- 1 | Qt 5.14 introduces many new features and improvements as well as bugfixes 2 | over the 5.13.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 8 | Applications compiled for 5.13 will continue to run with 5.14. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.14.0 Changes * 20 | **************************************************************************** 21 | 22 | - [QTBUG-68746] Added property for getting/setting the httpUserAgent 23 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/doc/src/minibrowser.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \title Qt WebView Examples - Minibrowser 6 | \example minibrowser 7 | \brief Minibrowser example demonstrates how to use the Qt WebView module with Qt Quick. 8 | \image webview-example.jpg 9 | \ingroup qtwebview-examples 10 | \examplecategory {Web Technologies} 11 | 12 | Minibrowser uses Qt Quick Controls and Qt WebView to provide basic 13 | browsing experience. Besides the addressbar for the URL, it has a 14 | couple of controls to navigate through the browsing history. 15 | 16 | \note When using the Qt WebView module it is necessary to call QtWebView::initialize() 17 | immediately before creating the QGuiApplication instance. Calling QtWebView::initialize() 18 | will ensure that the necessary pre-setup steps are run. 19 | 20 | \snippet minibrowser/main.cpp 0 21 | 22 | \include examples-run.qdocinc 23 | */ 24 | -------------------------------------------------------------------------------- /dist/changes-5.9.1: -------------------------------------------------------------------------------- 1 | Qt 5.9.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.2: -------------------------------------------------------------------------------- 1 | Qt 5.9.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.2 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.3: -------------------------------------------------------------------------------- 1 | Qt 5.9.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.3 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.1: -------------------------------------------------------------------------------- 1 | Qt 5.11.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.1 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.4: -------------------------------------------------------------------------------- 1 | Qt 5.9.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.4 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | 26 | -------------------------------------------------------------------------------- /dist/changes-5.9.6: -------------------------------------------------------------------------------- 1 | Qt 5.9.6 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0 through 5.9.5. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.6 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.2: -------------------------------------------------------------------------------- 1 | Qt 5.11.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.2 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.5: -------------------------------------------------------------------------------- 1 | Qt 5.9.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.5 Changes * 22 | **************************************************************************** 23 | 24 | - [QTBUG-66927] Fixed visibility updates when a WebView is inside a QQuick 25 | widget scene. 26 | -------------------------------------------------------------------------------- /dist/changes-5.8.0: -------------------------------------------------------------------------------- 1 | Qt 5.8 introduces many new features and improvements as well as bugfixes 2 | over the 5.7.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.8 series is binary compatible with the 5.7.x series. 8 | Applications compiled for 5.7 will continue to run with 5.8. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | Android 19 | ------- 20 | 21 | - Added support for various url schemes. 22 | 23 | macOS / iOS 24 | ----------- 25 | - [QTBUG-48996] Added WKWebView backend for macOS 10.10 and iOS 8.0, or 26 | newer. 27 | 28 | General 29 | ------- 30 | 31 | - [QTBUG-54128] Fixed missing geometry update bug when a webview changed 32 | anchestor (e.g. when pushing it onto a StackView). 33 | -------------------------------------------------------------------------------- /dist/changes-5.10.1: -------------------------------------------------------------------------------- 1 | Qt 5.10.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.10.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 10 | Applications compiled for 5.9 will continue to run with 5.10. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | This release contains all fixes included in the Qt 5.9.4 release. 21 | 22 | **************************************************************************** 23 | * Qt 5.10.1 Changes * 24 | **************************************************************************** 25 | 26 | - This release contains only minor code improvements. 27 | -------------------------------------------------------------------------------- /dist/changes-5.12.3: -------------------------------------------------------------------------------- 1 | Qt 5.12.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.12.3 Changes * 22 | **************************************************************************** 23 | 24 | - [QTBUG-71380] Fixed crash when attempting to use a plugin that couldn't be 25 | loaded due to unmet dependencies. 26 | -------------------------------------------------------------------------------- /dist/changes-5.12.2: -------------------------------------------------------------------------------- 1 | Qt 5.12.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Platform Specific Changes * 22 | **************************************************************************** 23 | 24 | - iOS: 25 | * Now opens links with _blank target in the current WebView if the 26 | external browser cannot open them. 27 | -------------------------------------------------------------------------------- /src/plugins/darwin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## QDarwinWebViewPlugin Plugin: 6 | ##################################################################### 7 | 8 | qt_internal_find_apple_system_framework(FWWebKit WebKit) 9 | qt_internal_find_apple_system_framework(FWAppKit AppKit) 10 | qt_internal_find_apple_system_framework(FWUIKit UIKit) 11 | qt_internal_find_apple_system_framework(FWFoundation Foundation) 12 | 13 | qt_internal_add_plugin(QDarwinWebViewPlugin 14 | OUTPUT_NAME qtwebview_darwin 15 | PLUGIN_TYPE webview 16 | SOURCES 17 | qdarwinwebview.mm qdarwinwebview_p.h 18 | qdarwinwebviewplugin.cpp 19 | LIBRARIES 20 | ${FWFoundation} 21 | ${FWWebKit} 22 | Qt::Core 23 | Qt::Gui 24 | Qt::Quick 25 | Qt::WebViewPrivate 26 | ) 27 | 28 | qt_internal_extend_target(QDarwinWebViewPlugin CONDITION MACOS 29 | LIBRARIES 30 | ${FWAppKit} 31 | ) 32 | 33 | qt_internal_extend_target(QDarwinWebViewPlugin CONDITION IOS 34 | LIBRARIES 35 | ${FWUIKit} 36 | ) 37 | -------------------------------------------------------------------------------- /src/webview/qwebviewplugin_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEWPLUGIN_H 6 | #define QWEBVIEWPLUGIN_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include "qwebview_global.h" 20 | #include "qwebview_p.h" 21 | 22 | #include 23 | 24 | #define QWebViewPluginInterface_iid "org.qt-project.Qt.QWebViewPluginInterface" 25 | 26 | QT_BEGIN_NAMESPACE 27 | 28 | class Q_WEBVIEW_EXPORT QWebViewPlugin : public QObject 29 | { 30 | Q_OBJECT 31 | public: 32 | explicit QWebViewPlugin(QObject *parent = nullptr); 33 | virtual ~QWebViewPlugin(); 34 | 35 | virtual QWebViewPrivate *create(const QString &key, QWebView *view) const = 0; 36 | 37 | virtual void prepare() const; 38 | }; 39 | 40 | QT_END_NAMESPACE 41 | 42 | #endif // QWEBVIEWPLUGIN_H 43 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | 6 | include(.cmake.conf) 7 | project(QtWebView 8 | VERSION "${QT_REPO_MODULE_VERSION}" 9 | DESCRIPTION "Qt WebView Libraries" 10 | HOMEPAGE_URL "https://qt.io/" 11 | LANGUAGES CXX C 12 | ) 13 | 14 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals) 15 | 16 | # This should be called as early as possible, just after find_package(BuildInternals) where it is 17 | # defined. 18 | qt_internal_project_setup() 19 | 20 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core) 21 | find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Gui Qml Quick 22 | WebEngineCore WebEngineQuick) 23 | 24 | # Make sure we use the fixed BASE argument of qt_add_resource. 25 | set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE) 26 | 27 | if(QNX) 28 | message(NOTICE "Skipping the build as the condition \"NOT QNX\" is not met.") 29 | return() 30 | endif() 31 | 32 | if(NOT QT_FEATURE_gui) 33 | message(NOTICE "Skipping the build as the condition \"QT_FEATURE_gui\" is not met.") 34 | return() 35 | endif() 36 | qt_build_repo() 37 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/testwindow.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #ifndef TESTWINDOW_H 5 | #define TESTWINDOW_H 6 | 7 | #if 0 8 | #pragma qt_no_master_include 9 | #endif 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // TestWindow: Utility class to ignore QQuickView details. 17 | class TestWindow : public QQuickView { 18 | public: 19 | inline TestWindow(QQuickItem *webView); 20 | QScopedPointer webView; 21 | 22 | protected: 23 | inline void resizeEvent(QResizeEvent*) override; 24 | }; 25 | 26 | inline TestWindow::TestWindow(QQuickItem *webView) 27 | : webView(webView) 28 | { 29 | Q_ASSERT(webView); 30 | webView->setParentItem(contentItem()); 31 | resize(300, 400); 32 | } 33 | 34 | inline void TestWindow::resizeEvent(QResizeEvent *event) 35 | { 36 | QQuickView::resizeEvent(event); 37 | webView->setX(0); 38 | webView->setY(0); 39 | webView->setWidth(event->size().width()); 40 | webView->setHeight(event->size().height()); 41 | } 42 | 43 | #endif /* TESTWINDOW_H */ 44 | -------------------------------------------------------------------------------- /src/quick/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | 5 | if(TARGET Qt::WebEngineQuick) 6 | set(qmlDependency "QtWebEngine/auto") 7 | endif() 8 | 9 | qt_internal_add_qml_module(WebViewQuick 10 | URI "QtWebView" 11 | VERSION "${PROJECT_VERSION}" 12 | CLASS_NAME QWebViewQuickPlugin 13 | PLUGIN_TARGET qtwebviewquickplugin 14 | DEPENDENCIES 15 | QtQuick/auto 16 | ${qmlDependency} 17 | SOURCES 18 | qquickwebview.cpp qquickwebview_p.h 19 | qquickwebviewloadrequest.cpp qquickwebviewloadrequest_p.h 20 | qtwebviewquickglobal_p.h 21 | qquickwebviewsettings.cpp qquickwebviewsettings_p.h 22 | PUBLIC_LIBRARIES # TODO: QTBUG-86533 workaround, PUBLIC_LIBRARIES should be moved to LIBRARIES. 23 | Qt::Quick 24 | Qt::QmlModels 25 | LIBRARIES 26 | Qt::QuickPrivate 27 | Qt::WebViewPrivate 28 | PRIVATE_MODULE_INTERFACE 29 | Qt::QuickPrivate 30 | ) 31 | 32 | # TODO: QTBUG-86533 workaround, PUBLIC_LIBRARIES should be moved to LIBRARIES. 33 | qt_internal_extend_target(WebViewQuick CONDITION TARGET Qt::OpenGL 34 | PUBLIC_LIBRARIES 35 | Qt::OpenGL 36 | ) 37 | -------------------------------------------------------------------------------- /coin/axivion/ci_config_linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "Project": { 3 | "BuildSystemIntegration": { 4 | "child_order": [ 5 | "GCCSetup", 6 | "CMake", 7 | "LinkLibraries" 8 | ] 9 | }, 10 | "CMake": { 11 | "_active": true, 12 | "_copy_from": "CMakeIntegration", 13 | "build_environment": {}, 14 | "build_options": "-j4", 15 | "generate_options": "--fresh", 16 | "generator": "Ninja" 17 | }, 18 | "GCCSetup": { 19 | "_active": true, 20 | "_copy_from": "Command", 21 | "build_command": "gccsetup --cc gcc --cxx g++ --config ../../../axivion/" 22 | }, 23 | "LinkLibraries": { 24 | "_active": true, 25 | "_copy_from": "AxivionLinker", 26 | "input_files": [ 27 | "build/lib/lib*.so*.ir", 28 | "build/qml/*/lib*.so*.ir" 29 | ], 30 | "ir": "build/$(env:TESTED_MODULE_COIN).ir" 31 | } 32 | }, 33 | "_Format": "1.0", 34 | "_Version": "7.6.2", 35 | "_VersionNum": [ 36 | 7, 37 | 6, 38 | 2, 39 | 12725 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /dist/changes-5.6.1: -------------------------------------------------------------------------------- 1 | Qt 5.6.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.6.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5.6/ 8 | 9 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 10 | Applications compiled for 5.5 will continue to run with 5.6. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | http://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Platform Specific Changes * 22 | **************************************************************************** 23 | Android 24 | ------- 25 | - [QTBUG-51198] Fixed problem with clipping when High DPI mode is enabled. 26 | 27 | iOS 28 | --- 29 | - The minibrowser example will now load non-https URLs. 30 | - [QTBUG-48221] Improved the usability together with QQuickWidget. 31 | -------------------------------------------------------------------------------- /dist/changes-5.15.0: -------------------------------------------------------------------------------- 1 | Qt 5.15 introduces many new features and improvements as well as bugfixes 2 | over the 5.14.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 8 | Applications compiled for 5.14 will continue to run with 5.15. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.15.0 Changes * 20 | **************************************************************************** 21 | 22 | - [QTBUG-79213] Fixed visibility updates when the WebView is placed inside 23 | a QQuickWidget. 24 | - [QTBUG-82778] The initial httpUserAgent property will now be correctly set. 25 | - [QTBUG-80912] Fixed the initialize() documentation and usage 26 | to be consistent with QtWebEngine. 27 | -------------------------------------------------------------------------------- /dist/changes-5.6.3: -------------------------------------------------------------------------------- 1 | Qt 5.6.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.6.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 10 | Applications compiled for 5.5 will continue to run with 5.6. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | General 25 | ------- 26 | 27 | - [QTBUG-54128] Fixed missing geometry update bug when a webview changed 28 | ancestor (e.g. when pushing it onto a StackView). 29 | 30 | - [QTBUG-53839] Fixed issue with initial properties not being forwarded 31 | to the WebEngine web view. 32 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## tst_qquickwebview Binary: 6 | ##################################################################### 7 | 8 | qt_internal_add_test(tst_qquickwebview 9 | SOURCES 10 | util.h testwindow.h 11 | tst_qquickwebview.cpp 12 | LIBRARIES 13 | Qt::Quick 14 | Qt::WebViewPrivate 15 | Qt::WebViewQuickPrivate 16 | ) 17 | 18 | set(testdata_resource_files 19 | "html/basic_page.html" 20 | "html/basic_page2.html" 21 | "html/direct-image-compositing.html" 22 | "html/inputmethod.html" 23 | "html/scroll.html" 24 | "html/cookies.html" 25 | "html/javascript.html" 26 | ) 27 | 28 | qt_internal_add_resource(tst_qquickwebview "testdata" 29 | PREFIX 30 | "/" 31 | BASE 32 | "html" 33 | FILES 34 | ${testdata_resource_files} 35 | ) 36 | set(testdata1_resource_files 37 | "html/resources/simple_image.png" 38 | ) 39 | 40 | qt_internal_add_resource(tst_qquickwebview "testdata1" 41 | PREFIX 42 | "/resources" 43 | BASE 44 | "html" 45 | FILES 46 | ${testdata1_resource_files} 47 | ) 48 | 49 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/macos/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIconFile 6 | 7 | CFBundlePackageType 8 | APPL 9 | CFBundleSignature 10 | ???? 11 | CFBundleExecutable 12 | minibrowser 13 | CFBundleIdentifier 14 | sd.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleDisplayName 16 | ${PRODUCT_NAME} 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1.0 23 | NSPrincipalClass 24 | NSApplication 25 | NSAppTransportSecurity 26 | 27 | 28 | NSAllowsArbitraryLoads 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(minibrowser LANGUAGES CXX) 6 | 7 | set(CMAKE_AUTOMOC ON) 8 | 9 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 10 | set(INSTALL_EXAMPLESDIR "examples") 11 | endif() 12 | 13 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webview/minibrowser") 14 | 15 | find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick WebView) 16 | 17 | qt_add_executable(minibrowser 18 | main.cpp 19 | ) 20 | 21 | set_target_properties(minibrowser PROPERTIES 22 | WIN32_EXECUTABLE TRUE 23 | MACOSX_BUNDLE TRUE 24 | ) 25 | 26 | target_link_libraries(minibrowser PUBLIC 27 | Qt6::Core 28 | Qt6::Gui 29 | Qt6::Qml 30 | Qt6::Quick 31 | Qt6::WebView 32 | ) 33 | 34 | # Resources: 35 | set(qml_resource_files 36 | "images/left-32.png" 37 | "images/refresh-32.png" 38 | "images/right-32.png" 39 | "images/stop-32.png" 40 | "images/settings-32.png" 41 | "main.qml" 42 | ) 43 | 44 | qt6_add_resources(minibrowser "qml" 45 | PREFIX 46 | "/" 47 | BASE 48 | "images" 49 | FILES 50 | ${qml_resource_files} 51 | ) 52 | 53 | install(TARGETS minibrowser 54 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 55 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 56 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 57 | ) 58 | -------------------------------------------------------------------------------- /src/webview/qwebviewloadrequest.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEWLOADREQUEST_H 6 | #define QWEBVIEWLOADREQUEST_H 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | QT_BEGIN_NAMESPACE 14 | 15 | class Q_WEBVIEW_EXPORT QWebViewLoadRequest 16 | { 17 | Q_GADGET 18 | Q_PROPERTY(QUrl url READ url CONSTANT) 19 | Q_PROPERTY(LoadStatus status READ status CONSTANT) 20 | Q_PROPERTY(QString errorString READ errorString CONSTANT) 21 | Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") 22 | 23 | public: 24 | enum class LoadStatus { 25 | LoadStartedStatus, 26 | LoadStoppedStatus, 27 | LoadSucceededStatus, 28 | LoadFailedStatus 29 | }; 30 | Q_ENUM(LoadStatus) 31 | 32 | QWebViewLoadRequest(); 33 | QWebViewLoadRequest(const QUrl &url, LoadStatus status, const QString &errorString); 34 | ~QWebViewLoadRequest(); 35 | 36 | QUrl url() const; 37 | LoadStatus status() const; 38 | QString errorString() const; 39 | 40 | private: 41 | QUrl m_url; 42 | LoadStatus m_status; 43 | QString m_errorString; 44 | }; 45 | 46 | QT_END_NAMESPACE 47 | 48 | Q_DECLARE_METATYPE(QWebViewLoadRequest) 49 | 50 | #endif // QWEBVIEWLOADREQUEST_H 51 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /src/webview/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | ##################################################################### 5 | ## WebView Module: 6 | ##################################################################### 7 | 8 | qt_internal_add_module(WebView 9 | PLUGIN_TYPES webview 10 | DEPENDENCIES 11 | QtQuick/auto 12 | SOURCES 13 | qtwebviewfunctions.cpp qtwebviewfunctions.h 14 | qwebview.cpp qwebview.h qwebview_p.h 15 | qwebview_global.h 16 | qwebviewfactory.cpp qwebviewfactory_p.h 17 | qwebviewloadrequest.cpp qwebviewloadrequest.h 18 | qwebviewsettings.cpp qwebviewsettings.h 19 | qwebviewplugin.cpp qwebviewplugin_p.h 20 | LIBRARIES 21 | Qt::CorePrivate 22 | Qt::GuiPrivate 23 | PUBLIC_LIBRARIES 24 | Qt::Core 25 | Qt::Gui 26 | PRIVATE_MODULE_INTERFACE 27 | Qt::CorePrivate 28 | Qt::GuiPrivate 29 | NO_GENERATE_CPP_EXPORTS 30 | ) 31 | 32 | if(ANDROID) 33 | set_property(TARGET WebView APPEND PROPERTY QT_ANDROID_BUNDLED_JAR_DEPENDENCIES 34 | jar/QtAndroidWebView.jar 35 | ) 36 | set_property(TARGET WebView APPEND PROPERTY QT_ANDROID_LIB_DEPENDENCIES 37 | ${INSTALL_PLUGINSDIR}/webview/libplugins_webview_qtwebview_android.so 38 | ) 39 | qt_internal_add_android_permission(WebView 40 | NAME android.permission.ACCESS_FINE_LOCATION 41 | ) 42 | endif() 43 | qt_internal_add_docs(WebView 44 | doc/qtwebview.qdocconf 45 | ) 46 | 47 | -------------------------------------------------------------------------------- /src/quick/qquickwebviewloadrequest_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QQUICKWEBVIEWREQUEST_H 6 | #define QQUICKWEBVIEWREQUEST_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | class QWebViewLoadRequest; 26 | 27 | class Q_WEBVIEWQUICK_EXPORT QQuickWebViewLoadRequest : public QObject 28 | { 29 | Q_OBJECT 30 | Q_PROPERTY(QUrl url READ url) 31 | Q_PROPERTY(QQuickWebView::LoadStatus status READ status) 32 | Q_PROPERTY(QString errorString READ errorString) 33 | QML_NAMED_ELEMENT(WebViewLoadRequest) 34 | QML_ADDED_IN_VERSION(1, 1) 35 | QML_EXTRA_VERSION(2, 0) 36 | QML_UNCREATABLE("") 37 | 38 | public: 39 | ~QQuickWebViewLoadRequest(); 40 | 41 | QUrl url() const; 42 | QQuickWebView::LoadStatus status() const; 43 | QString errorString() const; 44 | 45 | private: 46 | friend class QQuickWebView; 47 | explicit QQuickWebViewLoadRequest(const QWebViewLoadRequest &d); 48 | QScopedPointer d_ptr; 49 | }; 50 | 51 | QT_END_NAMESPACE 52 | 53 | #endif // QQUICKWEBVIEWREQUEST_H 54 | -------------------------------------------------------------------------------- /dist/changes-5.6.2: -------------------------------------------------------------------------------- 1 | Qt 5.6.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.6.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 10 | Applications compiled for 5.5 will continue to run with 5.6. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | QtWebView 25 | --------- 26 | 27 | - [QTBUG-55127] Fixed QQuickViewChangeListener, so it to properly removes 28 | itself from its ancestors. 29 | 30 | **************************************************************************** 31 | * Platform-specific Changes * 32 | **************************************************************************** 33 | 34 | Android 35 | ------- 36 | 37 | - [QTBUG-53736] Added support for various url schemes. 38 | 39 | WinRT 40 | ----- 41 | 42 | - [QTBUG-53405] Fixed sizing and position issues that occurred when a DPI 43 | scale value different than 1.0 was used. 44 | -------------------------------------------------------------------------------- /dist/changes-5.11.0: -------------------------------------------------------------------------------- 1 | Qt 5.11 introduces many new features and improvements as well as bugfixes 2 | over the 5.10.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 8 | Applications compiled for 5.10 will continue to run with 5.11. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.11.0 Changes * 20 | **************************************************************************** 21 | 22 | WebView 23 | ------- 24 | 25 | - [QTBUG-63137] QtWebView will now load its backends at run-time. 26 | - [QTBUG-66927] Fixed visibility updates for when the scene, containing the 27 | WebView, is inside a widget application. 28 | 29 | **************************************************************************** 30 | * Platform-specific Changes * 31 | **************************************************************************** 32 | 33 | macOS & iOS 34 | ----------- 35 | 36 | - [QTBUG-67293] Links with target="_blank" will now be handled by forwarding 37 | the request to the system. 38 | - Added error handler for "didFailNavigation", to properly handle errors 39 | occurring during navigation. 40 | -------------------------------------------------------------------------------- /dist/changes-5.6.0: -------------------------------------------------------------------------------- 1 | Qt 5.6 introduces many new features and improvements as well as bugfixes 2 | over the 5.5.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5.6 6 | 7 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 8 | Applications compiled for 5.5 will continue to run with 5.6. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | http://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Important Behavior Changes * 20 | **************************************************************************** 21 | 22 | - [OS X] QtWebEngine is now the default backend on OS X. 23 | - Calling QtWebView::initialize() is now required to make sure the WebView 24 | functions correctly on all platforms. 25 | 26 | **************************************************************************** 27 | * Platform-specific Changes * 28 | **************************************************************************** 29 | 30 | WinRT 31 | ---- 32 | - Added support for Windows Runtime. 33 | 34 | Android 35 | ------- 36 | - [QTBUG-49664] JavaScript evaluation will now be stopped before the 37 | WebView is released. 38 | - [QTBUG-49566] Accessing geolocation is now allowed when the application 39 | has the permission for ACCESS_FINE_LOCATION. 40 | -------------------------------------------------------------------------------- /dist/changes-5.7.1: -------------------------------------------------------------------------------- 1 | Qt 5.7.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.7.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.7 series is binary compatible with the 5.6.x series. 10 | Applications compiled for 5.6 will continue to run with 5.7. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | QtWebView 25 | --------- 26 | 27 | - [QTBUG-53839] Fixed issue with initial properties not being forwarded 28 | to the WebEngine web view. 29 | 30 | - [QTBUG-55127] Fixed QQuickViewChangeListener, so it to properly removes 31 | itself from its ancestors. 32 | 33 | **************************************************************************** 34 | * Platform-specific Changes * 35 | **************************************************************************** 36 | 37 | Android 38 | ------- 39 | 40 | - [QTBUG-53736] Added support for various url schemes. 41 | 42 | WinRT 43 | ----- 44 | 45 | - [QTBUG-53405] Fixed sizing and position issues that occurred when a DPI 46 | scale value different than 1.0 was used. 47 | -------------------------------------------------------------------------------- /dist/changes-5.9.0: -------------------------------------------------------------------------------- 1 | Qt 5.9 introduces many new features and improvements as well as bugfixes 2 | over the 5.8.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 8 | Applications compiled for 5.8 will continue to run with 5.9. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Library * 20 | **************************************************************************** 21 | 22 | - [QTBUG-59559] Fixed bundling of module resources for static builds. 23 | 24 | - [QTBUG-60150] The WebView will now receive the active focus when 25 | forceActiveFocus is called. 26 | 27 | - [QTBUG-57284] Fixed QtWebEngine dependency for the qml plugin. 28 | 29 | **************************************************************************** 30 | * Platform-specific Changes * 31 | **************************************************************************** 32 | 33 | WinRT 34 | ----- 35 | 36 | - [QTBUG-57288] Removed support for WinRT 8.1 and Windows Phone 8.1. 37 | 38 | macOS & iOS 39 | ----------- 40 | 41 | - Removed WebView and UIWebView backends. Minimum deployment target is 42 | now macOS 10.10 and iOS 8.0, so the WKWebView backend is used for both 43 | platforms. 44 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/ios/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIconFile 6 | 7 | CFBundlePackageType 8 | APPL 9 | CFBundleSignature 10 | ???? 11 | CFBundleExecutable 12 | minibrowser 13 | CFBundleIdentifier 14 | sd.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleDisplayName 16 | ${PRODUCT_NAME} 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1.0 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UISupportedInterfaceOrientations 28 | 29 | UIInterfaceOrientationPortrait 30 | UIInterfaceOrientationPortraitUpsideDown 31 | UIInterfaceOrientationLandscapeLeft 32 | UIInterfaceOrientationLandscapeRight 33 | 34 | NSAppTransportSecurity 35 | 36 | 37 | NSAllowsArbitraryLoads 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /cmake/FindWebView2.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | if(TARGET WebView2::WebView2) 5 | set(WebView2_FOUND TRUE) 6 | return() 7 | endif() 8 | 9 | function(get_cpu_arch result arch) 10 | set(arm64List arm64 ARM64 aarch64) 11 | set(x64List x86_64 AMD64 x86_64h) 12 | if(arch IN_LIST x64List) 13 | set(${result} "x64" PARENT_SCOPE) 14 | elseif(arch IN_LIST arm64List) 15 | set(${result} "arm64" PARENT_SCOPE) 16 | else() 17 | message(FATAL_ERROR "Unknown architecture: ${arch}") 18 | endif() 19 | endfunction() 20 | 21 | get_cpu_arch(webview2_sdk_arch ${CMAKE_SYSTEM_PROCESSOR}) 22 | 23 | if(NOT DEFINED WEBVIEW2_SDK_ROOT) 24 | if(DEFINED ENV{WEBVIEW2_SDK_ROOT}) 25 | file(TO_NATIVE_PATH "$ENV{WEBVIEW2_SDK_ROOT}" sdk_path) 26 | if(NOT EXISTS ${sdk_path}) 27 | message(FATAL_ERROR "WEBVIEW2_SDK_ROOT set to non-existing ${sdk_path} path") 28 | endif() 29 | set(WEBVIEW2_SDK_ROOT "${sdk_path}" CACHE STRING "") 30 | unset(sdk_path) 31 | endif() 32 | endif() 33 | 34 | find_path(WEBVIEW2_INCLUDE_DIR 35 | NAMES WebView2.h 36 | PATHS "${WEBVIEW2_SDK_ROOT}/build/native/include") 37 | find_library(WEBVIEW2_LIBRARY 38 | NAMES WebView2LoaderStatic.lib 39 | PATHS "${WEBVIEW2_SDK_ROOT}/build/native/${webview2_sdk_arch}") 40 | 41 | if(WEBVIEW2_LIBRARY AND WEBVIEW2_INCLUDE_DIR) 42 | set(WEBVIEW2_LIBRARY_DIR "${WEBVIEW2_SDK_ROOT}/build/native/${webview2_sdk_arch}" CACHE STRING "") 43 | add_library(WebView2::WebView2 UNKNOWN IMPORTED) 44 | set_target_properties(WebView2::WebView2 PROPERTIES 45 | IMPORTED_LOCATION ${WEBVIEW2_LIBRARY} 46 | INTERFACE_INCLUDE_DIRECTORIES ${WEBVIEW2_INCLUDE_DIR} 47 | ) 48 | endif() 49 | 50 | include(FindPackageHandleStandardArgs) 51 | find_package_handle_standard_args(WebView2 REQUIRED_VARS 52 | WEBVIEW2_LIBRARY 53 | WEBVIEW2_INCLUDE_DIR 54 | ) 55 | -------------------------------------------------------------------------------- /src/webview/qwebviewsettings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2025 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebviewsettings.h" 6 | #include "qwebview_p.h" 7 | 8 | QT_BEGIN_NAMESPACE 9 | 10 | // FIXME add c++ docs 11 | 12 | QWebViewSettings::QWebViewSettings(QWebViewSettingsPrivate *settings) : d(settings) 13 | { 14 | Q_ASSERT(settings != nullptr); 15 | } 16 | 17 | QWebViewSettings::~QWebViewSettings() { } 18 | 19 | bool QWebViewSettings::localStorageEnabled() const 20 | { 21 | return d->localStorageEnabled(); 22 | } 23 | 24 | void QWebViewSettings::setLocalStorageEnabled(bool enabled) 25 | { 26 | if (d->localStorageEnabled() == enabled) 27 | return; 28 | 29 | d->setLocalStorageEnabled(enabled); 30 | emit localStorageEnabledChanged(); 31 | } 32 | 33 | bool QWebViewSettings::javaScriptEnabled() const 34 | { 35 | return d->javaScriptEnabled(); 36 | } 37 | 38 | void QWebViewSettings::setJavaScriptEnabled(bool enabled) 39 | { 40 | if (d->javaScriptEnabled() == enabled) 41 | return; 42 | 43 | d->setJavaScriptEnabled(enabled); 44 | emit javaScriptEnabledChanged(); 45 | } 46 | 47 | void QWebViewSettings::setAllowFileAccess(bool enabled) 48 | { 49 | if (d->allowFileAccess() == enabled) 50 | return; 51 | 52 | d->setAllowFileAccess(enabled); 53 | emit allowFileAccessChanged(); 54 | } 55 | 56 | bool QWebViewSettings::allowFileAccess() const 57 | { 58 | return d->allowFileAccess(); 59 | } 60 | 61 | bool QWebViewSettings::localContentCanAccessFileUrls() const 62 | { 63 | return d->localContentCanAccessFileUrls(); 64 | } 65 | 66 | void QWebViewSettings::setLocalContentCanAccessFileUrls(bool enabled) 67 | { 68 | if (d->localContentCanAccessFileUrls() == enabled) 69 | return; 70 | 71 | d->setLocalContentCanAccessFileUrls(enabled); 72 | emit localContentCanAccessFileUrlsChanged(); 73 | } 74 | 75 | QT_END_NAMESPACE 76 | -------------------------------------------------------------------------------- /src/webview/qtwebviewfunctions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qtwebviewfunctions.h" 6 | 7 | #include "qwebviewfactory_p.h" 8 | #include "qwebviewplugin_p.h" 9 | 10 | #include 11 | 12 | QT_BEGIN_NAMESPACE 13 | 14 | /*! 15 | \namespace QtWebView 16 | \inmodule QtWebView 17 | \brief The QtWebView namespace provides functions that makes it easier to set-up and use the WebView. 18 | \inheaderfile QtWebView 19 | */ 20 | 21 | // This is a separate function so we can be sure that in non-static cases it can be registered 22 | // as a pre hook for QCoreApplication, ensuring this is called after the plugin paths have 23 | // been set to their defaults. For static builds then this will be called explicitly when 24 | // QtWebView::initialize() is called by the application 25 | 26 | static void initializeImpl() 27 | { 28 | if (QWebViewFactory::requiresExtraInitializationSteps()) { 29 | // There might be plugins available, but their dependencies might not be met, 30 | // so make sure we have a valid plugin before using it. 31 | // Note: A warning will be printed later if we're unable to load the plugin. 32 | QWebViewPlugin *plugin = QWebViewFactory::getPlugin(); 33 | if (plugin) 34 | plugin->prepare(); 35 | } 36 | } 37 | 38 | #ifndef QT_STATIC 39 | Q_COREAPP_STARTUP_FUNCTION(initializeImpl); 40 | #endif 41 | 42 | /*! 43 | \fn void QtWebView::initialize() 44 | \keyword qtwebview-initialize 45 | 46 | This function initializes resources or sets options that are required by the different back-ends. 47 | 48 | \note The \c initialize() function needs to be called immediately before the QGuiApplication 49 | instance is created. 50 | */ 51 | 52 | void QtWebView::initialize() 53 | { 54 | #ifdef QT_STATIC 55 | initializeImpl(); 56 | #endif 57 | } 58 | 59 | QT_END_NAMESPACE 60 | -------------------------------------------------------------------------------- /src/webview/qwebviewsettings.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2025 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEWSETTINGS_H 6 | #define QWEBVIEWSETTINGS_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | QT_BEGIN_NAMESPACE 15 | 16 | class QWebViewSettingsPrivate; 17 | class QWindow; 18 | 19 | class Q_WEBVIEW_EXPORT QWebViewSettings : public QObject 20 | { 21 | Q_OBJECT 22 | Q_PROPERTY(bool localStorageEnabled READ localStorageEnabled WRITE setLocalStorageEnabled NOTIFY 23 | localStorageEnabledChanged) 24 | Q_PROPERTY(bool javaScriptEnabled READ javaScriptEnabled WRITE setJavaScriptEnabled NOTIFY 25 | javaScriptEnabledChanged) 26 | Q_PROPERTY(bool allowFileAccess READ allowFileAccess WRITE setAllowFileAccess NOTIFY 27 | allowFileAccessChanged) 28 | Q_PROPERTY(bool localContentCanAccessFileUrls READ localContentCanAccessFileUrls WRITE 29 | setLocalContentCanAccessFileUrls NOTIFY localContentCanAccessFileUrlsChanged) 30 | 31 | public: 32 | explicit QWebViewSettings(QWebViewSettingsPrivate *webview); 33 | virtual ~QWebViewSettings() override; 34 | 35 | bool localStorageEnabled() const; 36 | bool javaScriptEnabled() const; 37 | bool allowFileAccess() const; 38 | bool localContentCanAccessFileUrls() const; 39 | 40 | void setLocalStorageEnabled(bool enabled); 41 | void setJavaScriptEnabled(bool enabled); 42 | void setAllowFileAccess(bool enabled); 43 | void setLocalContentCanAccessFileUrls(bool enabled); 44 | 45 | Q_SIGNALS: 46 | void localStorageEnabledChanged(); 47 | void javaScriptEnabledChanged(); 48 | void allowFileAccessChanged(); 49 | void localContentCanAccessFileUrlsChanged(); 50 | 51 | private: 52 | std::unique_ptr d; 53 | }; 54 | 55 | QT_END_NAMESPACE 56 | 57 | #endif // QWEBVIEWSETTINGS_H 58 | -------------------------------------------------------------------------------- /src/webview/configure.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #### Inputs 5 | 6 | #### Libraries 7 | if(WIN32) 8 | qt_find_package(WebView2 PROVIDED_TARGETS WebView2::WebView2 MODULE_NAME core QMAKE_LIB webview2) 9 | endif() 10 | #### Tests 11 | 12 | #### Features 13 | 14 | qt_feature("webview-webview2-plugin" PUBLIC 15 | LABEL "WebView2 (Windows only)" 16 | PURPOSE "Provides native Microsoft Edge WebView2 control as a plugin for Qt WebView." 17 | CONDITION WIN32 AND MSVC AND WebView2_FOUND 18 | ) 19 | qt_feature("webview-webengine-plugin" PUBLIC 20 | LABEL "WebEngine" 21 | PURPOSE "Provides QtWebEngine based plugin for Qt WebView." 22 | CONDITION TARGET Qt::WebEngineCore AND TARGET Qt::WebEngineQuick 23 | ) 24 | qt_feature("webview-android-plugin" PUBLIC 25 | LABEL "Android WebView (Android only)" 26 | PURPOSE "Provides Android WebView plugin for Qt WebView." 27 | CONDITION ANDROID 28 | ) 29 | qt_feature("webview-darwin-plugin" PUBLIC 30 | LABEL "Darwin WebKit (MacOS and IOS only)" 31 | PURPOSE "Provides Darwin Webkit plugin for Qt WebView." 32 | CONDITION MACOS OR IOS 33 | ) 34 | qt_feature("webview-wasm-plugin" PUBLIC 35 | LABEL "Wasm Webview (Web Assembly only)" 36 | PURPOSE "Provides Wasm WebView plugin for Qt WebView." 37 | CONDITION WASM 38 | ) 39 | 40 | qt_configure_add_summary_section(NAME "Qt WebView plugins") 41 | qt_configure_add_summary_entry(ARGS "webview-webengine-plugin") 42 | qt_configure_add_summary_entry(ARGS "webview-webview2-plugin") 43 | qt_configure_add_summary_entry(ARGS "webview-android-plugin") 44 | qt_configure_add_summary_entry(ARGS "webview-darwin-plugin") 45 | qt_configure_add_summary_entry(ARGS "webview-wasm-plugin") 46 | qt_configure_end_summary_section() 47 | 48 | qt_configure_add_report_entry( 49 | TYPE WARNING 50 | MESSAGE "No WebView2 SDK found, compiling QtWebView without WebView2 plugin.\n 51 | Please set WEBVIEW2_SDK_ROOT to point to WebView2 SDK directory." 52 | CONDITION WIN32 AND MSVC AND NOT QT_FEATURE_webview_webview2_plugin 53 | ) 54 | -------------------------------------------------------------------------------- /src/quick/qquickwebviewloadrequest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qquickwebviewloadrequest_p.h" 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | 10 | /*! 11 | \qmltype WebViewLoadRequest 12 | //! \nativetype QQuickWebViewLoadRequest 13 | \inqmlmodule QtWebView 14 | 15 | \brief A utility type for \l {WebView}'s \l {WebView::}{loadingChanged()} signal. 16 | 17 | The WebViewLoadRequest type contains load status information for the requested URL. 18 | 19 | \sa {WebView::loadingChanged()}{WebView.loadingChanged()} 20 | */ 21 | QQuickWebViewLoadRequest::QQuickWebViewLoadRequest(const QWebViewLoadRequest &d) 22 | : d_ptr(new QWebViewLoadRequest(d)) 23 | { 24 | } 25 | 26 | QQuickWebViewLoadRequest::~QQuickWebViewLoadRequest() { } 27 | 28 | /*! 29 | \qmlproperty url QtWebView::WebViewLoadRequest::url 30 | \readonly 31 | 32 | The URL of the load request. 33 | */ 34 | QUrl QQuickWebViewLoadRequest::url() const 35 | { 36 | return d_ptr->url(); 37 | } 38 | 39 | /*! 40 | \qmlproperty enumeration WebViewLoadRequest::status 41 | \readonly 42 | 43 | This enumeration represents the load status of a web page load request. 44 | 45 | \value WebView.LoadStartedStatus The page is currently loading. 46 | \value WebView.LoadSucceededStatus The page was loaded successfully. 47 | \value WebView.LoadFailedStatus The page could not be loaded. 48 | 49 | \sa {WebView::loadingChanged()}{WebView.loadingChanged} 50 | */ 51 | QQuickWebView::LoadStatus QQuickWebViewLoadRequest::status() const 52 | { 53 | return QQuickWebView::LoadStatus(d_ptr->status()); 54 | } 55 | 56 | /*! 57 | \qmlproperty string QtWebView::WebViewLoadRequest::errorString 58 | \readonly 59 | 60 | Holds the error message if the load request failed. 61 | */ 62 | QString QQuickWebViewLoadRequest::errorString() const 63 | { 64 | return d_ptr->errorString(); 65 | } 66 | 67 | QT_END_NAMESPACE 68 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/html/direct-image-compositing.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | Testing direct image layer optimization 8 | 23 | 24 | 25 | 26 |

Image optimization in layers

27 | 28 |

29 | This test exercises direct compositing of images with hardware acceleration. The visual results 30 | using ACCELERATED_COMPOSITING and regular TOT should be identical. Running this test manually with 31 | the correct debug options will show which elements are directly composited. See 32 | https://bugs.webkit.org/show_bug.cgi?id=23361 33 |

34 | 35 |
36 | 37 | Basic image - no style - can be directly composited 38 |
39 | 40 |
41 | 42 | 5px blue border - can NOT be directly composited 43 |
44 | 45 |
46 | 47 | margin - can NOT be directly composited 48 |
49 | 50 |
51 | 52 | solid background - can be directly composited 53 |
54 | 55 |
56 | 57 | background image - can NOT be directly composited 58 |
59 | 60 |
61 | 62 | rotated but otherwise no style - can be directly composited 63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/webview/doc/qtwebview.qdocconf: -------------------------------------------------------------------------------- 1 | include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) 2 | include($QT_INSTALL_DOCS/config/exampleurl-qtwebview.qdocconf) 3 | 4 | project = QtWebView 5 | description = Qt WebView Reference Documentation 6 | version = $QT_VERSION 7 | 8 | qhp.projects = QtWebView 9 | 10 | qhp.QtWebView.file = qtwebview.qhp 11 | qhp.QtWebView.namespace = org.qt-project.qtwebview.$QT_VERSION_TAG 12 | qhp.QtWebView.virtualFolder = qtwebview 13 | qhp.QtWebView.indexTitle = Qt WebView 14 | qhp.QtWebView.indexRoot = 15 | 16 | qhp.QtWebView.subprojects = classes qmltypes examples 17 | qhp.QtWebView.subprojects.classes.selectors = namespace 18 | qhp.QtWebView.subprojects.classes.title = C++ Classes and Namespaces 19 | qhp.QtWebView.subprojects.classes.indexTitle = Qt WebView C++ Classes and Namespaces 20 | qhp.QtWebView.subprojects.classes.sortPages = true 21 | qhp.QtWebView.subprojects.qmltypes.title = QML Types 22 | qhp.QtWebView.subprojects.qmltypes.indexTitle = Qt WebView QML Types 23 | qhp.QtWebView.subprojects.qmltypes.selectors = qmlclass 24 | qhp.QtWebView.subprojects.qmltypes.sortPages = true 25 | qhp.QtWebView.subprojects.examples.title = Examples 26 | qhp.QtWebView.subprojects.examples.indexTitle = Qt WebView Examples 27 | qhp.QtWebView.subprojects.examples.selectors = doc:example 28 | qhp.QtWebView.subprojects.examples.sortPages = true 29 | 30 | headerdirs += ../../ 31 | sourcedirs += ../../ src 32 | exampledirs += ../../../examples/webview 33 | imagedirs += images 34 | 35 | examplesinstallpath = webview 36 | 37 | # Path to the root of qtwebview (for automatic linking to source code) 38 | url.sources.rootdir = ../../.. 39 | 40 | depends = qtcore qtdoc qtgui qtquick qtqml qtwebengine qmake qtcmake 41 | 42 | manifestmeta.highlighted.names = "QtWebView/Qt WebView Examples - Minibrowser" 43 | 44 | navigation.landingpage = "Qt WebView" 45 | navigation.qmltypespage = "Qt WebView QML Types" 46 | navigation.cppclassespage = "Qt WebView C++ Classes and Namespaces" 47 | 48 | # Allow zero warnings when testing documentation in CI 49 | warninglimit = 0 50 | -------------------------------------------------------------------------------- /src/quick/qquickwebviewsettings_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QQUICKWEBVIEWSETTINGS_H 6 | #define QQUICKWEBVIEWSETTINGS_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | QT_BEGIN_NAMESPACE 26 | 27 | class QWebView; 28 | class QWebViewSettings; 29 | 30 | class Q_WEBVIEWQUICK_EXPORT QQuickWebViewSettings : public QObject 31 | { 32 | Q_OBJECT 33 | Q_PROPERTY(bool localStorageEnabled READ localStorageEnabled WRITE setLocalStorageEnabled NOTIFY localStorageEnabledChanged) 34 | Q_PROPERTY(bool javaScriptEnabled READ javaScriptEnabled WRITE setJavaScriptEnabled NOTIFY javaScriptEnabledChanged) 35 | Q_PROPERTY(bool allowFileAccess READ allowFileAccess WRITE setAllowFileAccess NOTIFY allowFileAccessChanged) 36 | Q_PROPERTY(bool localContentCanAccessFileUrls READ localContentCanAccessFileUrls WRITE setLocalContentCanAccessFileUrls NOTIFY localContentCanAccessFileUrlsChanged) 37 | QML_NAMED_ELEMENT(WebViewSettings) 38 | QML_ADDED_IN_VERSION(6, 5) 39 | QML_UNCREATABLE("") 40 | 41 | public: 42 | ~QQuickWebViewSettings() override; 43 | 44 | bool localStorageEnabled() const; 45 | bool javaScriptEnabled() const; 46 | bool localContentCanAccessFileUrls() const; 47 | bool allowFileAccess() const; 48 | 49 | public Q_SLOTS: 50 | void setLocalStorageEnabled(bool enabled); 51 | void setJavaScriptEnabled(bool enabled); 52 | void setAllowFileAccess(bool enabled); 53 | void setLocalContentCanAccessFileUrls(bool enabled); 54 | 55 | Q_SIGNALS: 56 | void localStorageEnabledChanged(); 57 | void javaScriptEnabledChanged(); 58 | void allowFileAccessChanged(); 59 | void localContentCanAccessFileUrlsChanged(); 60 | 61 | private: 62 | friend class QQuickWebView; 63 | 64 | explicit QQuickWebViewSettings(QWebViewSettings *webviewsettings, QObject *p = nullptr); 65 | QPointer d; 66 | bool m_allowFileAccess; 67 | }; 68 | 69 | QT_END_NAMESPACE 70 | 71 | #endif // QQUICKWEBVIEWSETTINGS_H 72 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["tests/auto/qml/qquickwebview/dummy.qml", 5 | "tests/auto/qml/qquickwebview/html/*.html", 6 | "tests/auto/qml/qquickwebview/html/resources/simple_image.png"] 7 | precedence = "closest" 8 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 9 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GPL-3.0-only" 10 | 11 | [[annotations]] 12 | path = ["src/plugins/android/android.json", 13 | "src/plugins/darwin/darwin.json", 14 | "src/plugins/wasm/wasm.json", 15 | "src/plugins/webengine/webengine.json", 16 | "src/plugins/winrt/winrt.json", 17 | "src/plugins/windows/windows.json"] 18 | comment = "module and plugin" 19 | precedence = "closest" 20 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 21 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only" 22 | 23 | [[annotations]] 24 | path = ["**.pro", "**.qrc", "**CMakeLists.txt", ".cmake.conf", "**.yaml", 25 | "**BLACKLIST", "**.plist", "coin/axivion/ci_config_linux.json", ".tag"] 26 | precedence = "closest" 27 | comment = "build system" 28 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 29 | SPDX-License-Identifier = "BSD-3-Clause" 30 | 31 | [[annotations]] 32 | path = ["**/.gitattributes", "**.gitignore", ".gitreview"] 33 | precedence = "closest" 34 | comment = "version control system. Infrastructure" 35 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 36 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 37 | 38 | [[annotations]] 39 | path = ["examples/webview/minibrowser/images/*", "examples/**"] 40 | comment = "this must be after the build system table because example and snippets take precedence over build system" 41 | precedence = "closest" 42 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 43 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 44 | 45 | [[annotations]] 46 | path = ["**/doc/images/**", "**.qdocconf", "config_help.txt"] 47 | comment = "documentation" 48 | precedence = "closest" 49 | SPDX-FileCopyrightText = "Copyright (C) 2025 The Qt Company Ltd." 50 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 51 | 52 | [[annotations]] 53 | path = ["**.toml", "licenseRule.json"] 54 | comment = "infrastructure" 55 | precedence = "override" 56 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 57 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 58 | 59 | [[annotations]] 60 | path = ["**/qt_attribution.json"] 61 | comment = "documentation" 62 | precedence = "override" 63 | SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd." 64 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 65 | -------------------------------------------------------------------------------- /src/webview/doc/src/qtwebview-overview.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | 5 | /*! 6 | \page qtwebview-index.html 7 | \title Qt WebView 8 | \brief A light-weight web view. 9 | 10 | Qt \WebView lets you display web content inside a QML application. To avoid 11 | including a full web browser stack, Qt \WebView uses native APIs where 12 | appropriate. 13 | 14 | This is useful on mobile platforms, such as \l {Qt for Android}{Android} and 15 | \l{Qt for iOS}{iOS}. On iOS, policies dictate that all web content is 16 | displayed using the operating system's web view. 17 | 18 | On Windows, Qt \WebView can use both \l{Qt WebEngine} module and 19 | \l {https://learn.microsoft.com/en-us/microsoft-edge/webview2/}{WebView2} to 20 | render content. 21 | 22 | On Linux, Qt \WebView depends on the \l{Qt WebEngine} module to 23 | render content. 24 | 25 | On \macos, the system web view is used in the same manner as iOS. 26 | 27 | \section1 Prerequisites 28 | 29 | To make the Qt WebView module function correctly across all platforms, it's 30 | necessary to call \l {qtwebview-initialize} {\c QtWebView::initialize()} 31 | before creating the \l {QGuiApplication} {\c QGuiApplication} instance and 32 | before window's \c QPlatformOpenGLContext is created. 33 | 34 | \section1 Using The Module 35 | 36 | \section2 QML API 37 | 38 | \include {module-use.qdocinc} {using the qml api} {QtWebView} 39 | 40 | \section2 C++ API 41 | 42 | \include {module-use.qdocinc} {using the c++ api} 43 | 44 | \section3 Building with CMake 45 | 46 | \include {module-use.qdocinc} {building with cmake} {WebView} 47 | 48 | \section3 Building with qmake 49 | 50 | \include {module-use.qdocinc} {building_with_qmake} {webview} 51 | 52 | \section1 Limitations 53 | 54 | Due to platform limitations, overlapping the WebView with other QML components 55 | is not supported. Doing this will have unpredictable results, which may differ 56 | from platform to platform. Applications can also not rely on events in the 57 | WebView to propagate into the Qt event delivery system. E.g. it is not possible 58 | to "overlay" an invisible item on top of the WebView to handle certain events, 59 | or to handle events that the WebView doesn't process in a parent item. 60 | 61 | \section1 Examples 62 | 63 | Look at the \l{Qt WebView Examples} for a demonstration on 64 | how the APIs can be used in applications. 65 | 66 | \section1 Reference 67 | 68 | \list 69 | \li \l{Qt WebView QML Types} 70 | \li \l{Qt WebView C++ Classes and Namespaces} 71 | \endlist 72 | 73 | \section1 Licenses 74 | 75 | Qt \WebView is available under commercial licenses from \l{The Qt Company}. 76 | In addition, it is available under the 77 | \l{GNU Lesser General Public License, version 3}, or 78 | the \l{GNU General Public License, version 2}. 79 | See \l{Qt Licensing} for further details. 80 | */ 81 | -------------------------------------------------------------------------------- /src/webview/qwebview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QABSTRACTWEBVIEW_P_H 6 | #define QABSTRACTWEBVIEW_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include "qwebview_global.h" 20 | #include "qwebview.h" 21 | 22 | #include 23 | #include 24 | 25 | QT_BEGIN_NAMESPACE 26 | 27 | class QWindow; 28 | class QWebViewSettings; 29 | class QWebViewLoadRequest; 30 | 31 | class Q_WEBVIEW_EXPORT QWebViewSettingsPrivate : public QObject 32 | { 33 | Q_OBJECT 34 | public: 35 | virtual bool localStorageEnabled() const = 0; 36 | virtual bool javaScriptEnabled() const = 0; 37 | virtual bool localContentCanAccessFileUrls() const = 0; 38 | virtual bool allowFileAccess() const = 0; 39 | 40 | virtual void setLocalContentCanAccessFileUrls(bool) = 0; 41 | virtual void setJavaScriptEnabled(bool) = 0; 42 | virtual void setLocalStorageEnabled(bool) = 0; 43 | virtual void setAllowFileAccess(bool) = 0; 44 | 45 | protected: 46 | explicit QWebViewSettingsPrivate(QObject *p = nullptr) : QObject(p) { } 47 | }; 48 | 49 | class Q_WEBVIEW_EXPORT QWebViewPrivate : public QObject 50 | { 51 | public: 52 | virtual void initialize(QObject *context) = 0; 53 | virtual QWebViewSettingsPrivate *settings() const = 0; 54 | virtual QString httpUserAgent() const = 0; 55 | virtual void setHttpUserAgent(const QString &httpUserAgent) = 0; 56 | virtual void setUrl(const QUrl &url) = 0; 57 | virtual bool canGoBack() const = 0; 58 | virtual bool canGoForward() const = 0; 59 | virtual QString title() const = 0; 60 | virtual QUrl url() const = 0; 61 | virtual int loadProgress() const = 0; 62 | virtual bool isLoading() const = 0; 63 | virtual void goBack() = 0; 64 | virtual void goForward() = 0; 65 | virtual void stop() = 0; 66 | virtual void reload() = 0; 67 | virtual void loadHtml(const QString &html, const QUrl &baseUrl) = 0; 68 | virtual void setCookie(const QString &domain, const QString &name, const QString &value) = 0; 69 | virtual void deleteCookie(const QString &domain, const QString &name) = 0; 70 | virtual void deleteAllCookies() = 0; 71 | virtual QWindow *nativeWindow() const = 0; 72 | virtual void runJavaScript(const QString &script, 73 | const std::function &resultCallback) = 0; 74 | 75 | protected: 76 | explicit QWebViewPrivate(QWebView *view) : q_ptr(view) { }; 77 | 78 | public: 79 | std::unique_ptr m_settings; 80 | QWebView *q_ptr; 81 | }; 82 | 83 | QT_END_NAMESPACE 84 | 85 | #endif // QABSTRACTWEBVIEW_P_H 86 | -------------------------------------------------------------------------------- /src/webview/qwebview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebview.h" 6 | 7 | #include "qwebviewsettings.h" 8 | #include "qwebviewplugin_p.h" 9 | #include "qwebviewloadrequest.h" 10 | #include "qwebviewfactory_p.h" 11 | 12 | QT_BEGIN_NAMESPACE 13 | 14 | QWebView::QWebView(QWindow *parent) : QWindow(parent), d(QWebViewFactory::createWebView(this)) 15 | { 16 | Q_ASSERT(d); 17 | d->m_settings.reset(new QWebViewSettings(d->settings())); 18 | qRegisterMetaType(); 19 | } 20 | 21 | QWebView::QWebView(QScreen *screen) : QWindow(screen), d(QWebViewFactory::createWebView(this)) 22 | { 23 | Q_ASSERT(d); 24 | d->m_settings.reset(new QWebViewSettings(d->settings())); 25 | qRegisterMetaType(); 26 | } 27 | 28 | QWebView::~QWebView() { } 29 | 30 | QString QWebView::httpUserAgent() const 31 | { 32 | return d->httpUserAgent(); 33 | } 34 | 35 | void QWebView::setHttpUserAgent(const QString &userAgent) 36 | { 37 | return d->setHttpUserAgent(userAgent); 38 | } 39 | 40 | QUrl QWebView::url() const 41 | { 42 | return d->url(); 43 | } 44 | 45 | void QWebView::setUrl(const QUrl &url) 46 | { 47 | d->setUrl(url); 48 | } 49 | 50 | bool QWebView::canGoBack() const 51 | { 52 | return d->canGoBack(); 53 | } 54 | 55 | void QWebView::goBack() 56 | { 57 | d->goBack(); 58 | } 59 | 60 | bool QWebView::canGoForward() const 61 | { 62 | return d->canGoForward(); 63 | } 64 | 65 | void QWebView::goForward() 66 | { 67 | d->goForward(); 68 | } 69 | 70 | void QWebView::reload() 71 | { 72 | d->reload(); 73 | } 74 | 75 | void QWebView::stop() 76 | { 77 | d->stop(); 78 | } 79 | 80 | QString QWebView::title() const 81 | { 82 | return d->title(); 83 | } 84 | 85 | int QWebView::loadProgress() const 86 | { 87 | return d->loadProgress(); 88 | } 89 | 90 | bool QWebView::isLoading() const 91 | { 92 | return d->isLoading(); 93 | } 94 | 95 | QWebViewSettings *QWebView::settings() 96 | { 97 | return d->m_settings.get(); 98 | } 99 | 100 | void QWebView::loadHtml(const QString &html, const QUrl &baseUrl) 101 | { 102 | d->loadHtml(html, baseUrl); 103 | } 104 | 105 | void QWebView::runJavaScript(const QString &script, 106 | const std::function &resultCallback) 107 | { 108 | return d->runJavaScript(script, resultCallback); 109 | } 110 | 111 | void QWebView::setCookie(const QString &domain, const QString &name, const QString &value) 112 | { 113 | d->setCookie(domain, name, value); 114 | } 115 | 116 | void QWebView::deleteCookie(const QString &domain, const QString &name) 117 | { 118 | d->deleteCookie(domain, name); 119 | } 120 | 121 | void QWebView::deleteAllCookies() 122 | { 123 | d->deleteAllCookies(); 124 | } 125 | 126 | QT_END_NAMESPACE 127 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace Qt::StringLiterals; 15 | 16 | // Workaround: As of Qt 5.4 QtQuick does not expose QUrl::fromUserInput. 17 | class Utils : public QObject 18 | { 19 | Q_OBJECT 20 | public: 21 | using QObject::QObject; 22 | 23 | Q_INVOKABLE static QUrl fromUserInput(const QString &userInput); 24 | }; 25 | 26 | QUrl Utils::fromUserInput(const QString &userInput) 27 | { 28 | if (!userInput.isEmpty()) { 29 | if (const QUrl result = QUrl::fromUserInput(userInput); result.isValid()) 30 | return result; 31 | } 32 | return QUrl::fromUserInput("about:blank"_L1); 33 | } 34 | 35 | #include "main.moc" 36 | 37 | int main(int argc, char *argv[]) 38 | { 39 | //! [0] 40 | QtWebView::initialize(); 41 | QGuiApplication app(argc, argv); 42 | //! [0] 43 | QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main", 44 | "QtWebView Example")); 45 | QCommandLineParser parser; 46 | QCoreApplication::setApplicationVersion(QT_VERSION_STR); 47 | parser.setApplicationDescription(QGuiApplication::applicationDisplayName()); 48 | parser.addHelpOption(); 49 | parser.addVersionOption(); 50 | parser.addPositionalArgument("url"_L1, "The initial URL to open."_L1); 51 | parser.process(QCoreApplication::arguments()); 52 | const QString initialUrl = parser.positionalArguments().value(0, "https://www.qt.io"_L1); 53 | 54 | QQmlApplicationEngine engine; 55 | QQmlContext *context = engine.rootContext(); 56 | context->setContextProperty("utils"_L1, new Utils(&engine)); 57 | context->setContextProperty("initialUrl"_L1, 58 | Utils::fromUserInput(initialUrl)); 59 | 60 | QRect geometry = QGuiApplication::primaryScreen()->availableGeometry(); 61 | if (!QGuiApplication::styleHints()->showIsFullScreen()) { 62 | const QSize size = geometry.size() * 4 / 5; 63 | const QSize offset = (geometry.size() - size) / 2; 64 | const QPoint pos = geometry.topLeft() + QPoint(offset.width(), offset.height()); 65 | geometry = QRect(pos, size); 66 | } 67 | 68 | engine.setInitialProperties(QVariantMap{{"x"_L1, geometry.x()}, 69 | {"y"_L1, geometry.y()}, 70 | {"width"_L1, geometry.width()}, 71 | {"height"_L1, geometry.height()}}); 72 | 73 | engine.load(QUrl("qrc:/main.qml"_L1)); 74 | if (engine.rootObjects().isEmpty()) 75 | return -1; 76 | 77 | return app.exec(); 78 | } 79 | -------------------------------------------------------------------------------- /src/webview/qwebviewfactory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebviewfactory_p.h" 6 | #include "qwebviewplugin_p.h" 7 | #include 8 | #include 9 | 10 | QT_BEGIN_NAMESPACE 11 | 12 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QWebViewPluginInterface_iid, QLatin1String("/webview"))) 13 | 14 | static QString getPluginName() 15 | { 16 | static const QString name = !qEnvironmentVariableIsEmpty("QT_WEBVIEW_PLUGIN") 17 | ? QString::fromLatin1(qgetenv("QT_WEBVIEW_PLUGIN")) 18 | : QStringLiteral("native"); 19 | return name; 20 | } 21 | 22 | QWebViewPrivate *QWebViewFactory::createWebView(QWebView *view) 23 | { 24 | QWebViewPrivate *wv = nullptr; 25 | QWebViewPlugin *plugin = getPlugin(); 26 | if (plugin) 27 | wv = plugin->create(QStringLiteral("webview"), view); 28 | 29 | if (!wv || !plugin) { 30 | qFatal("No WebView plug-in found!"); 31 | } 32 | 33 | return wv; 34 | } 35 | 36 | bool QWebViewFactory::requiresExtraInitializationSteps() 37 | { 38 | const QString pluginName = getPluginName(); 39 | const int index = pluginName.isEmpty() ? 0 : qMax(0, loader->indexOf(pluginName)); 40 | 41 | const QList metaDataList = loader->metaData(); 42 | if (metaDataList.isEmpty()) 43 | return false; 44 | 45 | const auto &pluginMetaData = metaDataList.at(index); 46 | Q_ASSERT(pluginMetaData.value(QtPluginMetaDataKeys::IID) == QLatin1String(QWebViewPluginInterface_iid)); 47 | const auto metaDataObject = pluginMetaData.value(QtPluginMetaDataKeys::MetaData).toMap(); 48 | return metaDataObject.value(QLatin1String("RequiresInit")).toBool(); 49 | } 50 | 51 | QWebViewPlugin *QWebViewFactory::getPlugin() 52 | { 53 | // Plugin loading logic: 54 | // 1. Get plugin name - plugin name is either user specified or "native" 55 | // - Exception: macOS, which will default to using "webengine" until the native plugin is matured. 56 | // 2. If neither a user specified or "default" plugin exists, then the first available is used. 57 | const QString pluginName = getPluginName(); 58 | const int index = pluginName.isEmpty() ? 0 : qMax(0, loader->indexOf(pluginName)); 59 | return qobject_cast(loader->instance(index)); 60 | } 61 | 62 | bool QWebViewFactory::loadedPluginHasKey(const QString key) 63 | { 64 | const QString &pluginName = getPluginName(); 65 | // instead of creating multimap with QFactoryLoader::KeyMap and doing a search 66 | // simply check if loded and key index matches 67 | if (pluginName.isEmpty()) 68 | return false; 69 | const int loadedIndex = qMax(0, loader->indexOf(pluginName)); 70 | const int keyIndex = loader->indexOf(key); 71 | return keyIndex > -1 && loadedIndex == keyIndex; 72 | } 73 | 74 | QT_END_NAMESPACE 75 | -------------------------------------------------------------------------------- /src/webview/qwebview.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEW_H 6 | #define QWEBVIEW_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | class tst_QWebView; 19 | 20 | QT_BEGIN_NAMESPACE 21 | 22 | class QWebViewPrivate; 23 | class QWebViewLoadRequest; 24 | 25 | class Q_WEBVIEW_EXPORT QWebView : public QWindow 26 | { 27 | Q_OBJECT 28 | Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY 29 | httpUserAgentChanged FINAL REVISION(1, 14)) 30 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged FINAL) 31 | Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged FINAL REVISION(1, 1)) 32 | Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged FINAL) 33 | Q_PROPERTY(QString title READ title NOTIFY titleChanged FINAL) 34 | Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged FINAL) 35 | Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged FINAL) 36 | Q_PROPERTY(QWebViewSettings *settings READ settings CONSTANT FINAL REVISION(6, 5)) 37 | 38 | public: 39 | explicit QWebView(QScreen *screen = nullptr); 40 | explicit QWebView(QWindow *parent); 41 | ~QWebView() override; 42 | 43 | QString httpUserAgent() const; 44 | void setHttpUserAgent(const QString &httpUserAgent); 45 | QUrl url() const; 46 | void setUrl(const QUrl &url); 47 | bool canGoBack() const; 48 | bool canGoForward() const; 49 | QString title() const; 50 | int loadProgress() const; 51 | bool isLoading() const; 52 | 53 | QWebViewSettings *settings(); 54 | 55 | Q_INVOKABLE void goBack(); 56 | Q_INVOKABLE void goForward(); 57 | Q_INVOKABLE void reload(); 58 | Q_INVOKABLE void stop(); 59 | Q_INVOKABLE void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()); 60 | Q_INVOKABLE void setCookie(const QString &domain, const QString &name, const QString &value); 61 | Q_INVOKABLE void deleteCookie(const QString &domain, const QString &name); 62 | Q_INVOKABLE void deleteAllCookies(); 63 | 64 | void runJavaScript(const QString &script, 65 | const std::function &resultCallback = {}); 66 | 67 | Q_SIGNALS: 68 | void titleChanged(QString title); 69 | void urlChanged(QUrl url); 70 | void loadingChanged(const QWebViewLoadRequest &loadRequest); 71 | void loadProgressChanged(int loadProgress); 72 | void httpUserAgentChanged(QString userAgent); 73 | void cookieAdded(const QString &domain, const QString &name); 74 | void cookieRemoved(const QString &domain, const QString &name); 75 | 76 | private: 77 | Q_DISABLE_COPY(QWebView) 78 | 79 | friend class QQuickWebView; 80 | friend class ::tst_QWebView; 81 | 82 | std::unique_ptr d; 83 | }; 84 | 85 | QT_END_NAMESPACE 86 | 87 | #endif // QWEBVIEW_H 88 | -------------------------------------------------------------------------------- /src/plugins/wasm/qwasmwebview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWASMWEBVIEW_P_H 6 | #define QWASMWEBVIEW_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | QT_BEGIN_NAMESPACE 32 | 33 | class QWasmWebViewSettingsPrivate final : public QWebViewSettingsPrivate 34 | { 35 | Q_OBJECT 36 | public: 37 | explicit QWasmWebViewSettingsPrivate(QObject *p = nullptr); 38 | 39 | bool localStorageEnabled() const final; 40 | bool javaScriptEnabled() const final; 41 | bool localContentCanAccessFileUrls() const final; 42 | bool allowFileAccess() const final; 43 | 44 | void setLocalContentCanAccessFileUrls(bool enabled) final; 45 | void setJavaScriptEnabled(bool enabled) final; 46 | void setLocalStorageEnabled(bool enabled) final; 47 | void setAllowFileAccess(bool enabled) final; 48 | }; 49 | 50 | class QWasmWebViewPrivate final : public QWebViewPrivate 51 | { 52 | Q_OBJECT 53 | public: 54 | explicit QWasmWebViewPrivate(QWebView *view); 55 | ~QWasmWebViewPrivate() override; 56 | 57 | void initialize(QObject *context) override { Q_UNUSED(context); }; 58 | QString httpUserAgent() const final; 59 | void setHttpUserAgent(const QString &httpUserAgent) final; 60 | QUrl url() const override; 61 | void setUrl(const QUrl &url) final; 62 | bool canGoBack() const final; 63 | bool canGoForward() const final; 64 | QString title() const final; 65 | int loadProgress() const final; 66 | bool isLoading() const final; 67 | 68 | QWindow *nativeWindow() const override { return m_window; } 69 | 70 | void goBack() final; 71 | void goForward() final; 72 | void reload() final; 73 | void stop() final; 74 | void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) final; 75 | void setCookie(const QString &domain, const QString &name, const QString &value) final; 76 | void deleteCookie(const QString &domain, const QString &name) final; 77 | void deleteAllCookies() final; 78 | 79 | void runJavaScript(const QString &script, 80 | const std::function &resultCallback) final; 81 | 82 | protected: 83 | QWebViewSettingsPrivate *settings() const final; 84 | 85 | private: 86 | Q_INVOKABLE void initializeIFrame(); 87 | void updateGeometry(); 88 | 89 | QWasmWebViewSettingsPrivate *m_settings; 90 | QWindow *m_window = nullptr; 91 | std::optional m_iframe; 92 | std::optional m_geometry; 93 | QUrl m_currentUrl; 94 | }; 95 | 96 | QT_END_NAMESPACE 97 | 98 | #endif // QWASMWEBVIEW_P_H 99 | -------------------------------------------------------------------------------- /src/plugins/darwin/qdarwinwebview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QDARWINWEBVIEW_P_H 6 | #define QDARWINWEBVIEW_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | Q_FORWARD_DECLARE_OBJC_CLASS(WKWebView); 28 | Q_FORWARD_DECLARE_OBJC_CLASS(WKNavigation); 29 | Q_FORWARD_DECLARE_OBJC_CLASS(WKWebViewConfiguration); 30 | 31 | QT_BEGIN_NAMESPACE 32 | 33 | class QDarwinWebViewSettingsPrivate : public QWebViewSettingsPrivate 34 | { 35 | Q_OBJECT 36 | public: 37 | explicit QDarwinWebViewSettingsPrivate(WKWebViewConfiguration *conf, QObject *p = nullptr); 38 | 39 | bool localStorageEnabled() const; 40 | bool javaScriptEnabled() const; 41 | bool localContentCanAccessFileUrls() const; 42 | bool allowFileAccess() const; 43 | 44 | void setLocalContentCanAccessFileUrls(bool enabled); 45 | void setJavaScriptEnabled(bool enabled); 46 | void setLocalStorageEnabled(bool enabled); 47 | void setAllowFileAccess(bool enabled); 48 | 49 | private: 50 | WKWebViewConfiguration *m_conf = nullptr; 51 | bool m_allowFileAccess = false; 52 | bool m_localContentCanAccessFileUrls = false; 53 | }; 54 | 55 | class QDarwinWebViewPrivate : public QWebViewPrivate 56 | { 57 | Q_OBJECT 58 | public: 59 | explicit QDarwinWebViewPrivate(QWebView *view); 60 | ~QDarwinWebViewPrivate() override; 61 | 62 | void initialize(QObject *context) override { Q_UNUSED(context); }; 63 | QString httpUserAgent() const override; 64 | void setHttpUserAgent(const QString &httpUserAgent) override; 65 | QUrl url() const override; 66 | void setUrl(const QUrl &url) override; 67 | bool canGoBack() const override; 68 | bool canGoForward() const override; 69 | QString title() const override; 70 | int loadProgress() const override; 71 | bool isLoading() const override; 72 | 73 | QWindow *nativeWindow() const override { return m_window; } 74 | QWebViewSettingsPrivate *settings() const override; 75 | 76 | void goBack() override; 77 | void goForward() override; 78 | void reload() override; 79 | void stop() override; 80 | void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override; 81 | void setCookie(const QString &domain, const QString &name, const QString &value) override; 82 | void deleteCookie(const QString &domain, const QString &name) override; 83 | void deleteAllCookies() override; 84 | 85 | void runJavaScript(const QString &script, 86 | const std::function &resultCallback) override; 87 | 88 | public: 89 | WKWebView *wkWebView; 90 | WKNavigation *wkNavigation; 91 | QDarwinWebViewSettingsPrivate *m_settings = nullptr; 92 | QWindow *m_window = nullptr; 93 | }; 94 | 95 | QT_END_NAMESPACE 96 | 97 | #endif // QDARWINWEBVIEW_P_H 98 | -------------------------------------------------------------------------------- /src/quick/qquickwebviewsettings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qquickwebviewsettings_p.h" 6 | 7 | #include 8 | #include 9 | 10 | QT_BEGIN_NAMESPACE 11 | 12 | /*! 13 | \qmltype WebViewSettings 14 | //! \nativetype QQuickWebViewSettings 15 | \inqmlmodule QtWebView 16 | \since QtWebView 6.5 17 | \brief Allows configuration of browser properties and attributes. 18 | 19 | The WebViewSettings type can be used to configure browser properties and generic 20 | attributes, such as JavaScript support, file access and local storage features. 21 | This type is uncreatable, but the default settings for all web views can be accessed by using 22 | the \l [QML] {WebView::settings}{WebView.settings} property. 23 | 24 | The default values are left as set by the different platforms. 25 | */ 26 | 27 | QQuickWebViewSettings::QQuickWebViewSettings(QWebViewSettings *webviewsettings, QObject *p) 28 | : QObject(p) 29 | , d(webviewsettings) 30 | { 31 | connect(d, &QWebViewSettings::localStorageEnabledChanged, 32 | this, &QQuickWebViewSettings::localStorageEnabledChanged); 33 | connect(d, &QWebViewSettings::javaScriptEnabledChanged, 34 | this, &QQuickWebViewSettings::javaScriptEnabledChanged); 35 | connect(d, &QWebViewSettings::localContentCanAccessFileUrlsChanged, 36 | this, &QQuickWebViewSettings::localContentCanAccessFileUrlsChanged); 37 | connect(d, &QWebViewSettings::allowFileAccessChanged, 38 | this, &QQuickWebViewSettings::allowFileAccessChanged); 39 | } 40 | 41 | QQuickWebViewSettings::~QQuickWebViewSettings() 42 | { 43 | 44 | } 45 | 46 | /*! 47 | \qmlproperty bool WebViewSettings::localStorageEnabled 48 | 49 | Enables support for the HTML 5 local storage feature. 50 | */ 51 | bool QQuickWebViewSettings::localStorageEnabled() const 52 | { 53 | return d->localStorageEnabled(); 54 | } 55 | 56 | void QQuickWebViewSettings::setLocalStorageEnabled(bool enabled) 57 | { 58 | d->setLocalStorageEnabled(enabled); 59 | } 60 | 61 | /*! 62 | \qmlproperty bool WebViewSettings::javaScriptEnabled 63 | 64 | Enables the running of JavaScript programs. 65 | */ 66 | bool QQuickWebViewSettings::javaScriptEnabled() const 67 | { 68 | return d->javaScriptEnabled(); 69 | } 70 | 71 | void QQuickWebViewSettings::setJavaScriptEnabled(bool enabled) 72 | { 73 | d->setJavaScriptEnabled(enabled); 74 | } 75 | 76 | /*! 77 | \qmlproperty bool WebViewSettings::localContentCanAccessFileUrls 78 | 79 | Allows locally loaded documents to access other local URLs. 80 | */ 81 | bool QQuickWebViewSettings::localContentCanAccessFileUrls() const 82 | { 83 | return d->localContentCanAccessFileUrls(); 84 | } 85 | 86 | void QQuickWebViewSettings::setLocalContentCanAccessFileUrls(bool enabled) 87 | { 88 | d->setLocalContentCanAccessFileUrls(enabled); 89 | } 90 | 91 | /*! 92 | \qmlproperty bool WebViewSettings::allowFileAccess 93 | 94 | Enables the WebView to load file URLs. 95 | */ 96 | bool QQuickWebViewSettings::allowFileAccess() const 97 | { 98 | return d->allowFileAccess(); 99 | } 100 | 101 | void QQuickWebViewSettings::setAllowFileAccess(bool enabled) 102 | { 103 | d->setAllowFileAccess(enabled); 104 | } 105 | 106 | QT_END_NAMESPACE 107 | -------------------------------------------------------------------------------- /src/plugins/android/qandroidwebview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QANDROIDWEBVIEW_P_H 6 | #define QANDROIDWEBVIEW_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | Q_DECLARE_JNI_CLASS(WebViewController, "org/qtproject/qt/android/view/QtAndroidWebViewController"); 30 | Q_DECLARE_JNI_CLASS(WebView, "android/webkit/WebView"); 31 | 32 | class QAndroidWebViewSettingsPrivate : public QWebViewSettingsPrivate 33 | { 34 | Q_OBJECT 35 | public: 36 | explicit QAndroidWebViewSettingsPrivate(const QtJniTypes::WebViewController &viewController, 37 | QObject *p = nullptr); 38 | 39 | bool localStorageEnabled() const; 40 | bool javaScriptEnabled() const; 41 | bool localContentCanAccessFileUrls() const; 42 | bool allowFileAccess() const; 43 | 44 | public: 45 | void setLocalContentCanAccessFileUrls(bool enabled); 46 | void setJavaScriptEnabled(bool enabled); 47 | void setLocalStorageEnabled(bool enabled); 48 | void setAllowFileAccess(bool enabled); 49 | 50 | private: 51 | QtJniTypes::WebViewController m_viewController; 52 | }; 53 | 54 | class QAndroidWebViewPrivate : public QWebViewPrivate 55 | { 56 | Q_OBJECT 57 | public: 58 | explicit QAndroidWebViewPrivate(QWebView *view); 59 | ~QAndroidWebViewPrivate() override; 60 | 61 | void initialize(QObject *context) override { Q_UNUSED(context); }; 62 | QString httpUserAgent() const override; 63 | void setHttpUserAgent(const QString &httpUserAgent) override; 64 | QUrl url() const override; 65 | void setUrl(const QUrl &url) override; 66 | bool canGoBack() const override; 67 | bool canGoForward() const override; 68 | QString title() const override; 69 | int loadProgress() const override; 70 | bool isLoading() const override; 71 | 72 | QWindow *nativeWindow() const override { return m_window; } 73 | 74 | void goBack() override; 75 | void goForward() override; 76 | void reload() override; 77 | void stop() override; 78 | void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override; 79 | void setCookie(const QString &domain, const QString &name, const QString &value) override; 80 | void deleteCookie(const QString &domain, const QString &name) override; 81 | void deleteAllCookies() override; 82 | 83 | void runJavaScript(const QString &script, 84 | const std::function &resultCallback) override; 85 | 86 | void javaScriptResult(int id, const QVariant &result); 87 | 88 | protected: 89 | QWebViewSettingsPrivate *settings() const override; 90 | 91 | private Q_SLOTS: 92 | void onApplicationStateChanged(Qt::ApplicationState state); 93 | 94 | private: 95 | int m_callbackId; 96 | QMap> m_callbacks; 97 | 98 | QWindow *m_window; 99 | QtJniTypes::WebViewController m_viewController; 100 | QtJniTypes::WebView m_webView; 101 | QAndroidWebViewSettingsPrivate *m_settings; 102 | }; 103 | 104 | QT_END_NAMESPACE 105 | 106 | #endif // QANDROIDWEBVIEW_P_H 107 | -------------------------------------------------------------------------------- /src/quick/qquickwebview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QQUICKWEBVIEW_H 6 | #define QQUICKWEBVIEW_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | Q_MOC_INCLUDE() 26 | Q_MOC_INCLUDE() 27 | Q_MOC_INCLUDE() 28 | 29 | QT_BEGIN_NAMESPACE 30 | 31 | class QQuickWebViewLoadRequest; 32 | class QWebViewLoadRequest; 33 | class QQuickWebViewSettings; 34 | 35 | class Q_WEBVIEWQUICK_EXPORT QQuickWebView : public QQuickWindowContainer 36 | { 37 | Q_OBJECT 38 | Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY 39 | httpUserAgentChanged FINAL REVISION(1, 14)) 40 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged FINAL) 41 | Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged FINAL REVISION(1, 1)) 42 | Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged FINAL) 43 | Q_PROPERTY(QString title READ title NOTIFY titleChanged FINAL) 44 | Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged FINAL) 45 | Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged FINAL) 46 | Q_PROPERTY(QQuickWebViewSettings *settings READ settings CONSTANT FINAL REVISION(6, 5)) 47 | QML_NAMED_ELEMENT(WebView) 48 | QML_ADDED_IN_VERSION(1, 0) 49 | QML_EXTRA_VERSION(2, 0) 50 | 51 | public: 52 | enum LoadStatus { // Changes here needs to be done in QWebView as well 53 | LoadStartedStatus, 54 | LoadStoppedStatus, 55 | LoadSucceededStatus, 56 | LoadFailedStatus 57 | }; 58 | Q_ENUM(LoadStatus) 59 | 60 | QQuickWebView(QQuickItem *parent = nullptr); 61 | ~QQuickWebView(); 62 | 63 | QString httpUserAgent() const ; 64 | void setHttpUserAgent(const QString &userAgent); 65 | QUrl url() const; 66 | QWebView &webView() const { return *m_webView; }; 67 | void setUrl(const QUrl &url); 68 | int loadProgress() const; 69 | QString title() const; 70 | bool canGoBack() const; 71 | bool isLoading() const; 72 | bool canGoForward() const; 73 | QWindow *nativeWindow(); 74 | QQuickWebViewSettings *settings() const; 75 | 76 | public Q_SLOTS: 77 | void goBack(); 78 | void goForward(); 79 | void reload(); 80 | void stop(); 81 | Q_REVISION(1, 1) void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()); 82 | Q_REVISION(1, 1) 83 | void runJavaScript(const QString &script, const QJSValue &callback = QJSValue()); 84 | Q_REVISION(6, 3) void setCookie(const QString &domain, const QString &name, const QString &value); 85 | Q_REVISION(6, 3) void deleteCookie(const QString &domain, const QString &name); 86 | Q_REVISION(6, 3) void deleteAllCookies(); 87 | 88 | Q_SIGNALS: 89 | void titleChanged(); 90 | void urlChanged(); 91 | Q_REVISION(1, 1) void loadingChanged(QQuickWebViewLoadRequest *loadRequest); 92 | void loadProgressChanged(); 93 | Q_REVISION(1, 14) void httpUserAgentChanged(); 94 | Q_REVISION(6, 3) void cookieAdded(const QString &domain, const QString &name); 95 | Q_REVISION(6, 3) void cookieRemoved(const QString &domain, const QString &name); 96 | 97 | private Q_SLOTS: 98 | void onLoadingChanged(const QWebViewLoadRequest &loadRequest); 99 | 100 | private: 101 | friend class QWebEngineWebViewPrivate; 102 | QWebView *m_webView; 103 | QQuickWebViewSettings *m_settings; 104 | }; 105 | 106 | QT_END_NAMESPACE 107 | 108 | #endif // QQUICKWEBVIEW_H 109 | -------------------------------------------------------------------------------- /tests/auto/qml/qquickwebview/util.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #ifndef UTIL_H 5 | #define UTIL_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #if !defined(TESTS_SOURCE_DIR) 15 | #define TESTS_SOURCE_DIR "" 16 | #endif 17 | 18 | class LoadSpy : public QEventLoop { 19 | Q_OBJECT 20 | 21 | public: 22 | LoadSpy(QQuickWebView *webView) 23 | { 24 | connect(webView, SIGNAL(loadingChanged(QQuickWebViewLoadRequest*)), SLOT(onLoadingChanged(QQuickWebViewLoadRequest*))); 25 | } 26 | 27 | ~LoadSpy() { } 28 | 29 | Q_SIGNALS: 30 | void loadSucceeded(); 31 | void loadFailed(); 32 | 33 | private Q_SLOTS: 34 | void onLoadingChanged(QQuickWebViewLoadRequest *loadRequest) 35 | { 36 | if (loadRequest->status() == QQuickWebView::LoadSucceededStatus) 37 | emit loadSucceeded(); 38 | else if (loadRequest->status() == QQuickWebView::LoadFailedStatus) 39 | emit loadFailed(); 40 | } 41 | }; 42 | 43 | class LoadStartedCatcher : public QObject { 44 | Q_OBJECT 45 | 46 | public: 47 | LoadStartedCatcher(QQuickWebView *webView) 48 | : m_webView(webView) 49 | { 50 | connect(m_webView, SIGNAL(loadingChanged(QQuickWebViewLoadRequest*)), this, SLOT(onLoadingChanged(QQuickWebViewLoadRequest*))); 51 | } 52 | 53 | virtual ~LoadStartedCatcher() { } 54 | 55 | public Q_SLOTS: 56 | void onLoadingChanged(QQuickWebViewLoadRequest *loadRequest) 57 | { 58 | if (loadRequest->status() == QQuickWebView::LoadStartedStatus) 59 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); 60 | } 61 | 62 | Q_SIGNALS: 63 | void finished(); 64 | 65 | private: 66 | QQuickWebView *m_webView; 67 | }; 68 | 69 | /** 70 | * Starts an event loop that runs until the given signal is received. 71 | * Optionally the event loop 72 | * can return earlier on a timeout. 73 | * 74 | * \return \p true if the requested signal was received 75 | * \p false on timeout 76 | */ 77 | inline bool waitForSignal(QObject *obj, const char *signal, int timeout = 10000) 78 | { 79 | QEventLoop loop; 80 | QObject::connect(obj, signal, &loop, SLOT(quit())); 81 | QTimer timer; 82 | QSignalSpy timeoutSpy(&timer, SIGNAL(timeout())); 83 | if (timeout > 0) { 84 | QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); 85 | timer.setSingleShot(true); 86 | timer.start(timeout); 87 | } 88 | loop.exec(); 89 | return timeoutSpy.isEmpty(); 90 | } 91 | 92 | inline bool waitForLoadSucceeded(QQuickWebView *webView, int timeout = 10000) 93 | { 94 | LoadSpy loadSpy(webView); 95 | return waitForSignal(&loadSpy, SIGNAL(loadSucceeded()), timeout); 96 | } 97 | 98 | inline bool waitForLoadFailed(QQuickWebView *webView, int timeout = 10000) 99 | { 100 | LoadSpy loadSpy(webView); 101 | return waitForSignal(&loadSpy, SIGNAL(loadFailed()), timeout); 102 | } 103 | 104 | struct Cookie 105 | { 106 | struct SigArg 107 | { 108 | QString domain; 109 | QString name; 110 | }; 111 | 112 | using List = QList; 113 | using SignalReturnValues = QList>; 114 | 115 | QString domain; 116 | QString name; 117 | QString value; 118 | friend bool operator==(const Cookie &a, const Cookie::SigArg &b) 119 | { 120 | return (a.domain == b.domain) && (a.name == b.name); 121 | } 122 | 123 | static bool testSignalValues(const Cookie::List &cookies, const SignalReturnValues &sigValues) 124 | { 125 | if (cookies.size() != sigValues.size()) 126 | return false; 127 | 128 | int found = 0; 129 | for (const auto &cookie : cookies) { 130 | auto it = std::find_if(sigValues.constBegin(), sigValues.constEnd(), [cookie](const QVariantList &sigArgs) { 131 | return (cookie == Cookie::SigArg{sigArgs.at(0).toString(), sigArgs.at(1).toString() }); 132 | }); 133 | if (it != sigValues.constEnd()) 134 | ++found; 135 | } 136 | 137 | return (found == cookies.size()); 138 | } 139 | }; 140 | 141 | #endif /* UTIL_H */ 142 | -------------------------------------------------------------------------------- /src/plugins/windows/qwebview2webview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2025 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBVIEW2WEBVIEW_P_H 6 | #define QWEBVIEW2WEBVIEW_P_H 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | QT_BEGIN_NAMESPACE 18 | 19 | using namespace Microsoft::WRL; 20 | 21 | class QWebview2WebViewSettingsPrivate final : public QWebViewSettingsPrivate 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit QWebview2WebViewSettingsPrivate(QObject *p = nullptr); 26 | 27 | void init(ICoreWebView2Controller* viewController); 28 | 29 | bool localStorageEnabled() const final; 30 | bool javaScriptEnabled() const final; 31 | bool localContentCanAccessFileUrls() const final; 32 | bool allowFileAccess() const final; 33 | 34 | public: 35 | void setLocalContentCanAccessFileUrls(bool enabled) final; 36 | void setJavaScriptEnabled(bool enabled) final; 37 | void setLocalStorageEnabled(bool enabled) final; 38 | void setAllowFileAccess(bool enabled) final; 39 | 40 | private: 41 | ComPtr m_webviewController; 42 | ComPtr m_webview; 43 | bool m_allowFileAccess = false; 44 | bool m_localContentCanAccessFileUrls = false; 45 | bool m_javaScriptEnabled = true; 46 | }; 47 | 48 | // This is used to store informations before webview2 is initialized 49 | // Because WebView2 initialization is async 50 | struct QWebViewInitData{ 51 | QString m_html; 52 | struct CookieData{ 53 | QString domain; 54 | QString name; 55 | QString value; 56 | }; 57 | QMap m_cookies; 58 | QString m_httpUserAgent; 59 | }; 60 | 61 | class QWebView2WebViewPrivate : public QWebViewPrivate 62 | { 63 | Q_OBJECT 64 | public: 65 | explicit QWebView2WebViewPrivate(QWebView *view); 66 | ~QWebView2WebViewPrivate() override; 67 | 68 | void initialize(QObject *context) override { Q_UNUSED(context); }; 69 | QString httpUserAgent() const override; 70 | void setHttpUserAgent(const QString &userAgent) override; 71 | QUrl url() const override; 72 | void setUrl(const QUrl &url) override; 73 | bool canGoBack() const override; 74 | bool canGoForward() const override; 75 | QString title() const override; 76 | int loadProgress() const override; 77 | bool isLoading() const override; 78 | 79 | QWindow* nativeWindow() const override; 80 | 81 | void goBack() override; 82 | void goForward() override; 83 | void reload() override; 84 | void stop() override; 85 | void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override; 86 | void setCookie(const QString &domain, const QString &name, const QString &value) override; 87 | void deleteCookie(const QString &domain, const QString &name) override; 88 | void deleteAllCookies() override; 89 | void runJavaScript(const QString &script, 90 | const std::function &resultCallback) override; 91 | 92 | private: 93 | HRESULT onNavigationStarting(ICoreWebView2* webview, ICoreWebView2NavigationStartingEventArgs* args); 94 | HRESULT onNavigationCompleted(ICoreWebView2* webview, ICoreWebView2NavigationCompletedEventArgs* args); 95 | HRESULT onWebResourceRequested(ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args); 96 | HRESULT onContentLoading(ICoreWebView2* webview, ICoreWebView2ContentLoadingEventArgs* args); 97 | HRESULT onNewWindowRequested(ICoreWebView2* webview, ICoreWebView2NewWindowRequestedEventArgs* args); 98 | void updateWindowGeometry(); 99 | void initialize(HWND hWnd); 100 | 101 | protected: 102 | QWebViewSettingsPrivate *settings() const override; 103 | 104 | private: 105 | ComPtr m_webviewController; 106 | ComPtr m_webview; 107 | ComPtr m_cookieManager; 108 | QWebview2WebViewSettingsPrivate *m_settings; 109 | QWindow *m_window; 110 | bool m_isLoading; 111 | int m_progress; 112 | QUrl m_url; 113 | QWebViewInitData m_initData; 114 | }; 115 | 116 | QT_END_NAMESPACE 117 | 118 | #endif // QWEBVIEW2WEBVIEW_P_H 119 | -------------------------------------------------------------------------------- /licenseRule.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "comment": ["file_pattern_ending: strings matched against the end of a file name.", 4 | "location keys: regular expression matched against the beginning of", 5 | "the file path (relative to the git submodule root).", 6 | "spdx: list of SPDX-License-Expression's allowed in the matching files.", 7 | "-------------------------------------------------------", 8 | "Files with the following endings are Build System licensed,", 9 | "unless they are examples", 10 | "Files with other endings can also be build system files" 11 | ], 12 | "file_pattern_ending": ["CMakeLists.txt", ".cmake", ".pro", ".pri", ".prf", 13 | "configure", "configure.bat", "cmake.in", "plist.in", "CMakeLists.txt.in", 14 | ".cmake.conf", ".tag", ".cmake.conf", ".yaml", 15 | "coin/axivion/ci_config_linux.json", ".plist", 16 | ".pro", "BLACKLIST", ".qrc"], 17 | "location": { 18 | "": { 19 | "comment": "Default", 20 | "file type": "build system", 21 | "spdx": ["BSD-3-Clause"] 22 | }, 23 | "(.*)(examples/|snippets/)": { 24 | "comment": "Example takes precedence", 25 | "file type": "examples and snippets", 26 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 27 | } 28 | } 29 | }, 30 | { 31 | "comments": ["Files with the following endings are infrastructure licensed"], 32 | "file_pattern_ending": [".gitattributes", ".gitignore", ".gitmodules", ".gitreview", 33 | "_clang-format", "licenseRule.json", "REUSE.toml"], 34 | "location":{ 35 | "": { 36 | "comment": "Default", 37 | "file type": "infrastructure", 38 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 39 | } 40 | } 41 | }, 42 | { 43 | "comments": ["Files with the following endings are Tool licensed,", 44 | "unless they are examples.", 45 | "Files with other endings can also be tool files."], 46 | "file_pattern_ending": [".sh", ".py", ".pl", ".bat", ".ps1"], 47 | "location":{ 48 | "": { 49 | "comment": "Default", 50 | "file type": "tools and utils", 51 | "spdx": ["LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0"] 52 | }, 53 | "(.*)(examples/|snippets/)": { 54 | "comment": "Example takes precedence", 55 | "file type": "examples and snippets", 56 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 57 | } 58 | } 59 | }, 60 | { 61 | "comment": "Files with the following endings are Documentation licensed.", 62 | "file_pattern_ending": [".qdoc", ".qdocinc" , ".qdocconf", ".txt", "README", "qt_attribution.json"], 63 | "location":{ 64 | "": { 65 | "comment": "", 66 | "file type": "documentation", 67 | "spdx": ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] 68 | } 69 | } 70 | }, 71 | { 72 | "comment": ["All other files", 73 | "The licensing is defined only by the file location in the Qt module repository.", 74 | "NO key for this case!", 75 | "This needs to be the last entry of the file."], 76 | "location": { 77 | "": { 78 | "comment": "Default", 79 | "file type": "module and plugin", 80 | "spdx": ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] 81 | }, 82 | "dist/": { 83 | "comment": "Default", 84 | "file type": "documentation", 85 | "spdx": ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] 86 | }, 87 | "src/": { 88 | "comment": "Default", 89 | "file type": "module and plugin", 90 | "spdx": ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] 91 | }, 92 | "tests/": { 93 | "comment": "Default", 94 | "file type": "test", 95 | "spdx": ["LicenseRef-Qt-Commercial OR GPL-3.0-only"] 96 | }, 97 | "(.*)(examples/|snippets/)": { 98 | "comment": "Default", 99 | "file type": "examples and snippets", 100 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 101 | }, 102 | "(.*|examples)(.*)/doc/images": { 103 | "comment": "Default", 104 | "file type": "documentation", 105 | "spdx": ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] 106 | } 107 | } 108 | } 109 | ] 110 | -------------------------------------------------------------------------------- /src/plugins/webengine/qwebenginewebview_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBENGINEWEBVIEW_P_H 6 | #define QWEBENGINEWEBVIEW_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | QT_BEGIN_NAMESPACE 32 | 33 | class QQuickItem; 34 | class QQuickWebEngineView; 35 | class QQuickWindow; 36 | class QWebEngineLoadingInfo; 37 | class QNetworkCookie; 38 | class QWebEngineWebViewPrivate; 39 | 40 | class QWebEngineWebViewSettingsPrivate : public QWebViewSettingsPrivate 41 | { 42 | Q_OBJECT 43 | public: 44 | explicit QWebEngineWebViewSettingsPrivate(QWebEngineWebViewPrivate *p = nullptr); 45 | 46 | bool localStorageEnabled() const override; 47 | bool javaScriptEnabled() const override; 48 | bool localContentCanAccessFileUrls() const override; 49 | bool allowFileAccess() const override; 50 | 51 | void setLocalContentCanAccessFileUrls(bool enabled) override; 52 | void setJavaScriptEnabled(bool enabled) override; 53 | void setLocalStorageEnabled(bool enabled) override; 54 | void setAllowFileAccess(bool enabled) override; 55 | 56 | void init(QQuickWebEngineSettings *settings); 57 | 58 | private: 59 | QPointer m_settings; 60 | bool m_localStorageEnabled = true; 61 | bool m_javaScriptEnabled = true; 62 | bool m_localContentCanAccessFileUrlsEnabled = true; 63 | bool m_allowFileAccessEnabled = true; 64 | }; 65 | 66 | class QWebEngineWebViewPrivate : public QWebViewPrivate 67 | { 68 | Q_OBJECT 69 | public: 70 | explicit QWebEngineWebViewPrivate(QWebView *p); 71 | ~QWebEngineWebViewPrivate() override; 72 | 73 | void initialize(QObject *context) override; 74 | QString httpUserAgent() const override; 75 | void setHttpUserAgent(const QString &userAgent) override; 76 | QUrl url() const override; 77 | void setUrl(const QUrl &url) override; 78 | bool canGoBack() const override; 79 | bool canGoForward() const override; 80 | QString title() const override; 81 | int loadProgress() const override; 82 | bool isLoading() const override; 83 | 84 | QWebViewSettingsPrivate *settings() const override; 85 | QWindow *nativeWindow() const override { return nullptr; } 86 | 87 | void goBack() override; 88 | void goForward() override; 89 | void reload() override; 90 | void stop() override; 91 | void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override; 92 | void setCookie(const QString &domain, const QString &name, 93 | const QString &value) override; 94 | void deleteCookie(const QString &domain, const QString &name) override; 95 | void deleteAllCookies() override; 96 | void runJavaScript(const QString &script, 97 | const std::function &resultCallback) override; 98 | 99 | private Q_SLOTS: 100 | void q_urlChanged(); 101 | void q_loadProgressChanged(); 102 | void q_titleChanged(); 103 | void q_loadingChanged(const QWebEngineLoadingInfo &loadRequest); 104 | void q_profileChanged(); 105 | void q_httpUserAgentChanged(); 106 | void q_cookieAdded(const QNetworkCookie &cookie); 107 | void q_cookieRemoved(const QNetworkCookie &cookie); 108 | 109 | private: 110 | friend class QWebEngineWebViewSettingsPrivate; 111 | 112 | QQuickWebEngineProfile *m_profile = nullptr; 113 | mutable QWebEngineWebViewSettingsPrivate *m_settings = nullptr; 114 | QString m_httpUserAgent; 115 | struct QQuickWebEngineViewPtr 116 | { 117 | inline QQuickWebEngineView *operator->() const 118 | { 119 | if (!m_webEngineView) 120 | init(); 121 | return m_webEngineView.get(); 122 | } 123 | void init() const; 124 | 125 | QWebEngineWebViewPrivate *m_parent; 126 | mutable std::unique_ptr m_webEngineView; 127 | } m_webEngineView; 128 | struct QWebEngineCookieStorePtr 129 | { 130 | inline QWebEngineCookieStore *operator->() const 131 | { 132 | if (!m_cookieStore) 133 | init(); 134 | return m_cookieStore; 135 | } 136 | void init() const; 137 | 138 | QQuickWebEngineViewPtr *m_webEngineViewPtr = nullptr; 139 | mutable QWebEngineCookieStore *m_cookieStore = nullptr; 140 | } m_cookieStore; 141 | QQuickItem *m_parentItem; 142 | QQuickWindow *m_window; 143 | bool m_ownsWindow; 144 | }; 145 | 146 | QT_END_NAMESPACE 147 | 148 | #endif // QWEBENGINEWEBVIEW_P_H 149 | -------------------------------------------------------------------------------- /examples/webview/minibrowser/main.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | import QtQuick 5 | import QtQuick.Controls 6 | import QtWebView 7 | import QtQuick.Layouts 8 | 9 | 10 | ApplicationWindow { 11 | id: window 12 | visible: true 13 | title: webView.title 14 | 15 | menuBar: ToolBar { 16 | id: navigationBar 17 | RowLayout { 18 | anchors.fill: parent 19 | spacing: 0 20 | 21 | ToolButton { 22 | id: backButton 23 | icon.source: "qrc:/left-32.png" 24 | icon.color: "transparent" 25 | onClicked: webView.goBack() 26 | enabled: webView.canGoBack 27 | Layout.preferredWidth: navigationBar.height 28 | } 29 | 30 | ToolButton { 31 | id: forwardButton 32 | icon.source: "qrc:/right-32.png" 33 | icon.color: "transparent" 34 | onClicked: webView.goForward() 35 | enabled: webView.canGoForward 36 | Layout.preferredWidth: navigationBar.height 37 | } 38 | 39 | ToolButton { 40 | id: reloadButton 41 | icon.source: webView.loading ? "qrc:/stop-32.png" : "qrc:/refresh-32.png" 42 | icon.color: "transparent" 43 | onClicked: webView.loading ? webView.stop() : webView.reload() 44 | Layout.preferredWidth: navigationBar.height 45 | } 46 | 47 | Item { Layout.preferredWidth: 5 } 48 | 49 | TextField { 50 | Layout.fillWidth: true 51 | id: urlField 52 | inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhPreferLowercase 53 | text: webView.url 54 | onAccepted: webView.url = utils.fromUserInput(text) 55 | } 56 | 57 | Item { Layout.preferredWidth: 5 } 58 | 59 | ToolButton { 60 | id: goButton 61 | text: qsTr("Go") 62 | onClicked: { 63 | Qt.inputMethod.commit() 64 | Qt.inputMethod.hide() 65 | webView.url = utils.fromUserInput(urlField.text) 66 | } 67 | } 68 | 69 | ToolButton { 70 | id: settingsButton 71 | icon.source: "qrc:/settings-32.png" 72 | onClicked: { 73 | settingsDrawer.width = (settingsDrawer.width > 0) ? 0 : window.width * 1/4 74 | } 75 | Layout.preferredWidth: navigationBar.height 76 | } 77 | 78 | Item { Layout.preferredWidth: 10 } 79 | } 80 | ProgressBar { 81 | id: progress 82 | anchors { 83 | left: parent.left 84 | top: parent.bottom 85 | right: parent.right 86 | leftMargin: parent.leftMargin 87 | rightMargin: parent.rightMargin 88 | } 89 | height:3 90 | z: Qt.platform.os === "android" ? -1 : -2 91 | background: Item {} 92 | visible: Qt.platform.os !== "ios" && Qt.platform.os !== "winrt" 93 | from: 0 94 | to: 100 95 | value: webView.loadProgress < 100 ? webView.loadProgress : 0 96 | } 97 | } 98 | 99 | Item { 100 | id: settingsDrawer 101 | anchors.right: parent.right 102 | ColumnLayout { 103 | Label { 104 | text: "JavaScript" 105 | } 106 | CheckBox { 107 | id: javaScriptEnabledCheckBox 108 | text: "enabled" 109 | onCheckStateChanged: webView.settings.javaScriptEnabled = (checkState == Qt.Checked) 110 | } 111 | Label { 112 | text: "Local storage" 113 | } 114 | CheckBox { 115 | id: localStorageEnabledCheckBox 116 | text: "enabled" 117 | onCheckStateChanged: webView.settings.localStorageEnabled = (checkState == Qt.Checked) 118 | } 119 | Label { 120 | text: "Allow file access" 121 | } 122 | CheckBox { 123 | id: allowFileAccessEnabledCheckBox 124 | text: "enabled" 125 | onCheckStateChanged: webView.settings.allowFileAccess = (checkState == Qt.Checked) 126 | } 127 | Label { 128 | text: "Local content can access file URLs" 129 | } 130 | CheckBox { 131 | id: localContentCanAccessFileUrlsEnabledCheckBox 132 | text: "enabled" 133 | onCheckStateChanged: webView.settings.localContentCanAccessFileUrls = (checkState == Qt.Checked) 134 | } 135 | } 136 | } 137 | 138 | WebView { 139 | id: webView 140 | url: initialUrl 141 | anchors.right: settingsDrawer.left 142 | anchors.left: parent.left 143 | height: parent.height 144 | onLoadingChanged: function(loadRequest) { 145 | if (loadRequest.errorString) 146 | console.error(loadRequest.errorString); 147 | } 148 | 149 | Component.onCompleted: { 150 | javaScriptEnabledCheckBox.checkState = settings.javaScriptEnabled ? Qt.Checked : Qt.Unchecked 151 | localStorageEnabledCheckBox.checkState = settings.localStorageEnabled ? Qt.Checked : Qt.Unchecked 152 | allowFileAccessEnabledCheckBox.checkState = settings.allowFileAccess ? Qt.Checked : Qt.Unchecked 153 | localContentCanAccessFileUrlsEnabledCheckBox.checkState = settings.localContentCanAccessFileUrls ? Qt.Checked : Qt.Unchecked 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/plugins/wasm/qwasmwebview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwasmwebview_p.h" 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | QT_BEGIN_NAMESPACE 23 | 24 | QWasmWebViewSettingsPrivate::QWasmWebViewSettingsPrivate(QObject *p) 25 | : QWebViewSettingsPrivate(p) { } 26 | 27 | bool QWasmWebViewSettingsPrivate::localStorageEnabled() const 28 | { 29 | qWarning("localStorageEnabled() not supported on this platform"); 30 | return false; 31 | } 32 | 33 | bool QWasmWebViewSettingsPrivate::javaScriptEnabled() const 34 | { 35 | qWarning("javaScriptEnabled() not supported on this platform"); 36 | return false; 37 | } 38 | 39 | bool QWasmWebViewSettingsPrivate::localContentCanAccessFileUrls() const 40 | { 41 | qWarning("localContentCanAccessFileUrls() not supported on this platform"); 42 | return false; 43 | } 44 | 45 | bool QWasmWebViewSettingsPrivate::allowFileAccess() const 46 | { 47 | qWarning("allowFileAccess() not supported on this platform"); 48 | return false; 49 | } 50 | 51 | void QWasmWebViewSettingsPrivate::setLocalContentCanAccessFileUrls(bool enabled) 52 | { 53 | Q_UNUSED(enabled); 54 | qWarning("setLocalContentCanAccessFileUrls() not supported on this platform"); 55 | } 56 | 57 | void QWasmWebViewSettingsPrivate::setJavaScriptEnabled(bool enabled) 58 | { 59 | Q_UNUSED(enabled); 60 | qWarning("setJavaScriptEnabled() not supported on this platform"); 61 | } 62 | 63 | void QWasmWebViewSettingsPrivate::setLocalStorageEnabled(bool enabled) 64 | { 65 | Q_UNUSED(enabled); 66 | qWarning("setLocalStorageEnabled() not supported on this platform"); 67 | } 68 | 69 | void QWasmWebViewSettingsPrivate::setAllowFileAccess(bool enabled) 70 | { 71 | Q_UNUSED(enabled); 72 | qWarning("setAllowFileAccess() not supported on this platform"); 73 | } 74 | 75 | QWasmWebViewPrivate::QWasmWebViewPrivate(QWebView *view) : QWebViewPrivate(view), m_window(view) 76 | { 77 | m_settings = new QWasmWebViewSettingsPrivate(this); 78 | QMetaObject::invokeMethod(this, &QWasmWebViewPrivate::initializeIFrame, Qt::QueuedConnection); 79 | } 80 | 81 | QWasmWebViewPrivate::~QWasmWebViewPrivate() { } 82 | 83 | QString QWasmWebViewPrivate::httpUserAgent() const 84 | { 85 | if (m_iframe) 86 | return QString::fromStdString( 87 | (*m_iframe)["contentWindow"]["navigator"]["userAgent"].as()); 88 | return QString(); 89 | } 90 | 91 | void QWasmWebViewPrivate::setHttpUserAgent(const QString &userAgent) 92 | { 93 | Q_UNUSED(userAgent); 94 | qWarning("setHttpUserAgent() not supported on this platform"); 95 | } 96 | 97 | QUrl QWasmWebViewPrivate::url() const 98 | { 99 | return m_currentUrl; 100 | } 101 | 102 | void QWasmWebViewPrivate::setUrl(const QUrl &url) 103 | { 104 | m_currentUrl = url; 105 | if (m_iframe) { 106 | (*m_iframe).call("removeAttribute", emscripten::val("srcdoc")); 107 | (*m_iframe).set("src", m_currentUrl.toString().toStdString()); 108 | } 109 | } 110 | 111 | void QWasmWebViewPrivate::loadHtml(const QString &html, const QUrl &baseUrl) 112 | { 113 | if (!baseUrl.isEmpty()) 114 | qWarning("Base URLs for loadHtml() are not supported on this platform."); 115 | 116 | if (m_iframe) 117 | (*m_iframe).set("srcdoc", html.toStdString()); 118 | } 119 | 120 | bool QWasmWebViewPrivate::canGoBack() const 121 | { 122 | qWarning("canGoBack() not supported on this platform"); 123 | return false; 124 | } 125 | 126 | void QWasmWebViewPrivate::goBack() 127 | { 128 | qWarning("goBack() not supported on this platform"); 129 | } 130 | 131 | bool QWasmWebViewPrivate::canGoForward() const 132 | { 133 | qWarning("canGoForward() not supported on this platform"); 134 | return false; 135 | } 136 | 137 | void QWasmWebViewPrivate::goForward() 138 | { 139 | qWarning("goForward() not supported on this platform"); 140 | } 141 | 142 | void QWasmWebViewPrivate::reload() 143 | { 144 | if (m_iframe) { 145 | (*m_iframe)["contentWindow"]["location"].call("reload"); 146 | setUrl(m_currentUrl); 147 | // this order of operation is important, setting URL before reload() 148 | // did not work, HTTP reload request was being cancelled by browser 149 | } 150 | } 151 | 152 | void QWasmWebViewPrivate::stop() 153 | { 154 | qWarning("stop() not supported on this platform"); 155 | } 156 | 157 | QString QWasmWebViewPrivate::title() const 158 | { 159 | if (m_iframe) 160 | return QString::fromStdString( 161 | (*m_iframe)["contentWindow"]["document"]["title"].as()); 162 | return QString(); 163 | } 164 | 165 | int QWasmWebViewPrivate::loadProgress() const 166 | { 167 | qWarning("loadProgress() not supported on this platform"); 168 | return 100; 169 | } 170 | 171 | bool QWasmWebViewPrivate::isLoading() const 172 | { 173 | qWarning("isLoading() not supported on this platform"); 174 | return false; 175 | } 176 | 177 | void QWasmWebViewPrivate::setCookie(const QString &domain, const QString &name, 178 | const QString &value) 179 | { 180 | Q_UNUSED(domain); 181 | Q_UNUSED(name); 182 | Q_UNUSED(value); 183 | qWarning("setCookie() not supported on this platform"); 184 | } 185 | 186 | void QWasmWebViewPrivate::deleteCookie(const QString &domain, const QString &name) 187 | { 188 | Q_UNUSED(domain); 189 | Q_UNUSED(name); 190 | qWarning("deleteCookie() not supported on this platform"); 191 | } 192 | 193 | void QWasmWebViewPrivate::deleteAllCookies() 194 | { 195 | qWarning("deleteAllCookies() not supported on this platform"); 196 | } 197 | 198 | void QWasmWebViewPrivate::runJavaScript(const QString &script, 199 | const std::function &resultCallback) 200 | { 201 | Q_UNUSED(script); 202 | Q_UNUSED(resultCallback); 203 | qWarning("runJavaScript() not supported on this platform"); 204 | } 205 | 206 | QWebViewSettingsPrivate *QWasmWebViewPrivate::settings() const 207 | { 208 | return m_settings; 209 | } 210 | 211 | // clang-format off 212 | EM_JS(void, addResizeObservers, (emscripten::EM_VAL clientAreaHandle, emscripten::EM_VAL frameHandle), { 213 | var clientArea = Emval.toValue(clientAreaHandle); 214 | var frame = Emval.toValue(frameHandle); 215 | const resizeObserver = new ResizeObserver((entries) => { 216 | for (const entry of entries) { 217 | frame.width = entry.contentBoxSize[0].inlineSize; 218 | frame.height = entry.contentBoxSize[0].blockSize; 219 | } 220 | }); 221 | resizeObserver.observe(clientArea); 222 | }); 223 | // clang-format on 224 | 225 | void QWasmWebViewPrivate::initializeIFrame() 226 | { 227 | auto wasmWindow = dynamic_cast(m_window->handle()); 228 | Q_ASSERT(wasmWindow); 229 | 230 | auto document = wasmWindow->document(); 231 | auto clientArea = wasmWindow->clientArea(); 232 | 233 | m_iframe = document.call("createElement", emscripten::val("iframe")); 234 | clientArea.call("appendChild", *m_iframe); 235 | (*m_iframe)["style"].set("position", "absolute"); 236 | (*m_iframe)["style"].set("border", "none"); 237 | (*m_iframe)["style"].set("top", "0px"); 238 | (*m_iframe)["style"].set("left", "0px"); 239 | addResizeObservers(clientArea.as_handle(), m_iframe.value().as_handle()); 240 | 241 | // NOTE: Make sure any pending url is set now. 242 | setUrl(m_currentUrl); 243 | } 244 | 245 | QT_END_NAMESPACE 246 | -------------------------------------------------------------------------------- /LICENSES/LGPL-3.0-only.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /tests/auto/webview/qwebview/tst_qwebview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) 16 | #include 17 | #define ANDROID_REQUIRES_API_LEVEL(N) \ 18 | if (QtAndroidPrivate::androidSdkVersion() < N) \ 19 | QSKIP("This feature is not supported on this version of Android"); 20 | #else 21 | #define ANDROID_REQUIRES_API_LEVEL(N) 22 | #endif 23 | 24 | class tst_QWebView : public QObject 25 | { 26 | Q_OBJECT 27 | public: 28 | tst_QWebView() : m_cacheLocation(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) {} 29 | 30 | private slots: 31 | void initTestCase(); 32 | void load(); 33 | void runJavaScript(); 34 | void loadHtml_data(); 35 | void loadHtml(); 36 | void loadRequest(); 37 | void setAndDeleteCookie(); 38 | 39 | private: 40 | const QString m_cacheLocation; 41 | }; 42 | 43 | void tst_QWebView::initTestCase() 44 | { 45 | if (!qEnvironmentVariableIsEmpty("QEMU_LD_PREFIX")) 46 | QSKIP("This test is unstable on QEMU, so it will be skipped."); 47 | if (!QFileInfo(m_cacheLocation).isDir()) { 48 | QDir dir; 49 | QVERIFY(dir.mkpath(m_cacheLocation)); 50 | } 51 | } 52 | 53 | void tst_QWebView::load() 54 | { 55 | QTemporaryFile file(m_cacheLocation + QStringLiteral("/XXXXXXfile.html")); 56 | QVERIFY2(file.open(), 57 | qPrintable(QStringLiteral("Cannot create temporary file:") + file.errorString())); 58 | 59 | file.write("FooBar"); 60 | const QString fileName = file.fileName(); 61 | file.close(); 62 | 63 | QWebView view; 64 | view.settings()->setAllowFileAccess(true); 65 | view.settings()->setLocalContentCanAccessFileUrls(true); 66 | QCOMPARE(view.loadProgress(), 0); 67 | const QUrl url = QUrl::fromLocalFile(fileName); 68 | view.setUrl(url); 69 | QTRY_COMPARE(view.loadProgress(), 100); 70 | QTRY_VERIFY(!view.isLoading()); 71 | QCOMPARE(view.title(), QStringLiteral("FooBar")); 72 | QVERIFY(!view.canGoBack()); 73 | QVERIFY(!view.canGoForward()); 74 | QCOMPARE(view.url(), url); 75 | } 76 | 77 | void tst_QWebView::runJavaScript() 78 | { 79 | ANDROID_REQUIRES_API_LEVEL(19) 80 | const QString tstProperty = QString(QLatin1String("Qt.tst_data")); 81 | const QString title = QString(QLatin1String("WebViewTitle")); 82 | 83 | QWebView view; 84 | QCOMPARE(view.loadProgress(), 0); 85 | view.loadHtml(QString("%1").arg(title)); 86 | QTRY_COMPARE(view.loadProgress(), 100); 87 | QTRY_VERIFY(!view.isLoading()); 88 | QCOMPARE(view.title(), title); 89 | bool called = false; 90 | QString documentTitle; 91 | auto callback = [&](const QVariant &result) { 92 | called = true; 93 | documentTitle = result.value(); 94 | }; 95 | view.runJavaScript(QString(QLatin1String("document.title")), callback); 96 | QTRY_COMPARE(called, true); 97 | QCOMPARE(documentTitle, title); 98 | } 99 | 100 | void tst_QWebView::loadHtml_data() 101 | { 102 | QTest::addColumn("content"); 103 | QTest::addColumn("loadUrl"); 104 | QTest::addColumn("resultUrl"); 105 | QWebView view; 106 | QCOMPARE(view.loadProgress(), 0); 107 | QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(QWebViewLoadRequest))); 108 | const QByteArray content( 109 | QByteArrayLiteral("WebViewTitle" 110 | "Hello")); 111 | QByteArray encoded("data:text/html;charset=UTF-8,"); 112 | encoded.append(content.toPercentEncoding()); 113 | 114 | if (!QWebViewFactory::loadedPluginHasKey("webkit")) { 115 | QTest::newRow("set conent without base url") << content << QUrl() << QUrl(encoded); 116 | } else { 117 | QTest::newRow("set conent without base url") << content << QUrl() << QUrl("about:blank"); 118 | } 119 | QTest::newRow("set content with data base url") << content << QUrl(encoded) << QUrl(encoded); 120 | 121 | if (!QWebViewFactory::loadedPluginHasKey("webview2")) { 122 | QTest::newRow("set content with non-data base url") 123 | << content << QUrl("http://foobar.com/") << QUrl("http://foobar.com/"); 124 | } else { 125 | QTest::newRow("set content with non-data base url") 126 | << content << QUrl("http://foobar.com/") << QUrl(encoded); 127 | } 128 | } 129 | 130 | void tst_QWebView::loadHtml() 131 | { 132 | QFETCH(QByteArray, content); 133 | QFETCH(QUrl, loadUrl); 134 | QFETCH(QUrl, resultUrl); 135 | 136 | QWebView view; 137 | QCOMPARE(view.loadProgress(), 0); 138 | QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(QWebViewLoadRequest))); 139 | view.loadHtml(content, loadUrl); 140 | QTRY_COMPARE(view.loadProgress(), 100); 141 | QTRY_VERIFY(!view.isLoading()); 142 | QCOMPARE(view.title(), QStringLiteral("WebViewTitle")); 143 | QTRY_COMPARE(loadChangedSingalSpy.size(), 2); 144 | // take load finished 145 | const QWebViewLoadRequest &lr = loadChangedSingalSpy.at(1).at(0).value(); 146 | QCOMPARE(lr.status(), QWebViewLoadRequest::LoadStatus::LoadSucceededStatus); 147 | bool called = false; 148 | QUrl url; 149 | auto callback = [&](const QVariant &result) { 150 | called = true; 151 | url = result.value(); 152 | }; 153 | view.runJavaScript("document.baseURI", callback); 154 | QTRY_COMPARE(called, true); 155 | QCOMPARE(url, resultUrl); 156 | 157 | QVERIFY(view.url().isValid()); 158 | QCOMPARE(view.url(), resultUrl); 159 | } 160 | 161 | void tst_QWebView::loadRequest() 162 | { 163 | // LoadSucceeded 164 | { 165 | QTemporaryFile file(m_cacheLocation + QStringLiteral("/XXXXXXfile.html")); 166 | QVERIFY2(file.open(), 167 | qPrintable(QStringLiteral("Cannot create temporary file:") + file.errorString())); 168 | 169 | file.write("FooBar"); 170 | const QString fileName = file.fileName(); 171 | file.close(); 172 | 173 | QWebView view; 174 | 175 | view.settings()->setAllowFileAccess(true); 176 | view.settings()->setLocalContentCanAccessFileUrls(true); 177 | QCOMPARE(view.loadProgress(), 0); 178 | const QUrl url = QUrl::fromLocalFile(fileName); 179 | QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(QWebViewLoadRequest))); 180 | view.setUrl(url); 181 | QTRY_VERIFY(!view.isLoading()); 182 | QTRY_COMPARE(view.loadProgress(), 100); 183 | QTRY_COMPARE(view.title(), QStringLiteral("FooBar")); 184 | QCOMPARE(view.url(), url); 185 | QTRY_COMPARE(loadChangedSingalSpy.size(), 2); 186 | { 187 | const QList &loadStartedArgs = loadChangedSingalSpy.takeFirst(); 188 | const QWebViewLoadRequest &lr = loadStartedArgs.at(0).value(); 189 | QCOMPARE(lr.status(), QWebViewLoadRequest::LoadStatus::LoadStartedStatus); 190 | } 191 | { 192 | const QList &loadStartedArgs = loadChangedSingalSpy.takeFirst(); 193 | const QWebViewLoadRequest &lr = loadStartedArgs.at(0).value(); 194 | QCOMPARE(lr.status(), QWebViewLoadRequest::LoadStatus::LoadSucceededStatus); 195 | } 196 | } 197 | 198 | // LoadFailed 199 | { 200 | QWebView view; 201 | view.settings()->setAllowFileAccess(true); 202 | view.settings()->setLocalContentCanAccessFileUrls(true); 203 | QCOMPARE(view.loadProgress(), 0); 204 | QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(QWebViewLoadRequest))); 205 | view.setUrl(QUrl(QStringLiteral("file:///file_that_does_not_exist.html"))); 206 | QTRY_VERIFY(!view.isLoading()); 207 | QTRY_COMPARE(loadChangedSingalSpy.size(), 2); 208 | { 209 | const QList &loadStartedArgs = loadChangedSingalSpy.takeFirst(); 210 | const QWebViewLoadRequest &lr = loadStartedArgs.at(0).value(); 211 | QCOMPARE(lr.status(), QWebViewLoadRequest::LoadStatus::LoadStartedStatus); 212 | } 213 | { 214 | const QList &loadStartedArgs = loadChangedSingalSpy.takeFirst(); 215 | const QWebViewLoadRequest &lr = loadStartedArgs.at(0).value(); 216 | QCOMPARE(lr.status(), QWebViewLoadRequest::LoadStatus::LoadFailedStatus); 217 | } 218 | if (QWebViewFactory::loadedPluginHasKey("webengine")) 219 | QCOMPARE(view.loadProgress(), 100); 220 | } 221 | } 222 | 223 | void tst_QWebView::setAndDeleteCookie() 224 | { 225 | QWebView view; 226 | view.settings()->setLocalStorageEnabled(true); 227 | view.settings()->setAllowFileAccess(true); 228 | view.settings()->setLocalContentCanAccessFileUrls(true); 229 | 230 | QSignalSpy cookieAddedSpy(&view, SIGNAL(cookieAdded(QString,QString))); 231 | QSignalSpy cookieRemovedSpy(&view, SIGNAL(cookieRemoved(QString,QString))); 232 | 233 | view.setCookie(".example.com", "TestCookie", "testValue"); 234 | view.setCookie(".example2.com", "TestCookie2", "testValue2"); 235 | view.setCookie(".example3.com", "TestCookie3", "testValue3"); 236 | QTRY_COMPARE(cookieAddedSpy.size(), 3); 237 | 238 | view.deleteCookie(".example.com", "TestCookie"); 239 | QTRY_COMPARE(cookieRemovedSpy.size(), 1); 240 | 241 | // deleting a cookie using a name that has not been set 242 | view.deleteCookie(".example.com", "NewCookieName"); 243 | QTRY_COMPARE(cookieRemovedSpy.size(), 1); 244 | 245 | // deleting a cookie using a domain that has not been set 246 | view.deleteCookie(".new.domain.com", "TestCookie2"); 247 | QTRY_COMPARE(cookieRemovedSpy.size(), 1); 248 | 249 | view.deleteAllCookies(); 250 | if (QWebViewFactory::loadedPluginHasKey("android_view")) 251 | QEXPECT_FAIL("", "Notification for deleteAllCookies() is not implemented on Android, yet!", Continue); 252 | QTRY_COMPARE(cookieRemovedSpy.size(), 3); 253 | } 254 | 255 | QTEST_MAIN(tst_QWebView) 256 | 257 | #include "tst_qwebview.moc" 258 | -------------------------------------------------------------------------------- /src/quick/qquickwebview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qquickwebview_p.h" 6 | #include "qquickwebviewloadrequest_p.h" 7 | #include "qquickwebviewsettings_p.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace { 14 | 15 | class CallbackStorage 16 | { 17 | public: 18 | int insertCallback(const QJSValue &callback) 19 | { 20 | QMutexLocker locker(&m_mtx); 21 | const int nextId = qMax(++m_counter, 0); 22 | if (nextId == 0) 23 | m_counter = 1; 24 | 25 | m_callbacks.insert(nextId, callback); 26 | return nextId; 27 | } 28 | 29 | QJSValue takeCallback(int callbackId) 30 | { 31 | QMutexLocker lock(&m_mtx); 32 | return m_callbacks.take(callbackId); 33 | } 34 | 35 | private: 36 | QMutex m_mtx; 37 | int m_counter; 38 | QHash m_callbacks; 39 | }; 40 | 41 | } // namespace 42 | 43 | Q_GLOBAL_STATIC(CallbackStorage, callbacks) 44 | 45 | /*! 46 | \qmltype WebView 47 | \inqmlmodule QtWebView 48 | \ingroup qtwebview 49 | \brief A component for displaying web content. 50 | 51 | WebView is a component for displaying web content which is implemented using native 52 | APIs on the platforms where this is available, thus it does not necessarily require 53 | including a full web browser stack as part of the application. 54 | 55 | To make the Qt WebView module function correctly across all platforms, it is necessary 56 | to call \l {qtwebview-initialize}{QtWebView::initialize}() right after creating the 57 | QGuiApplication instance. 58 | 59 | \note Due to platform limitations overlapping the WebView and other QML components 60 | is not supported. 61 | */ 62 | 63 | QQuickWebView::QQuickWebView(QQuickItem *parent) 64 | : QQuickWindowContainer(parent), 65 | m_webView(new QWebView(window())), 66 | m_settings(new QQuickWebViewSettings(m_webView->settings(), this)) 67 | { 68 | if (QWindow *nativeWindow = m_webView->d->nativeWindow()) 69 | setContainedWindow(nativeWindow); 70 | 71 | connect(m_webView, &QWebView::titleChanged, this, &QQuickWebView::titleChanged); 72 | connect(m_webView, &QWebView::urlChanged, this, &QQuickWebView::urlChanged); 73 | connect(m_webView, &QWebView::loadProgressChanged, this, &QQuickWebView::loadProgressChanged); 74 | connect(m_webView, &QWebView::loadingChanged, this, &QQuickWebView::onLoadingChanged); 75 | connect(m_webView, &QWebView::httpUserAgentChanged, this, &QQuickWebView::httpUserAgentChanged); 76 | connect(m_webView, &QWebView::cookieAdded, this, &QQuickWebView::cookieAdded); 77 | connect(m_webView, &QWebView::cookieRemoved, this, &QQuickWebView::cookieRemoved); 78 | 79 | m_webView->d->initialize(this); 80 | } 81 | 82 | QQuickWebView::~QQuickWebView() { } 83 | 84 | /*! 85 | \qmlproperty url QtWebView::WebView::httpUserAgent 86 | \since QtWebView 1.14 87 | The user agent in use. 88 | */ 89 | 90 | void QQuickWebView::setHttpUserAgent(const QString &userAgent) 91 | { 92 | m_webView->setHttpUserAgent(userAgent); 93 | } 94 | 95 | QString QQuickWebView::httpUserAgent() const 96 | { 97 | return m_webView->httpUserAgent(); 98 | } 99 | 100 | /*! 101 | \qmlproperty url QtWebView::WebView::url 102 | 103 | The URL of currently loaded web page. Changing this will trigger 104 | loading new content. 105 | 106 | The URL is used as-is. URLs that originate from user input should 107 | be parsed with QUrl::fromUserInput(). 108 | 109 | \note The WebView does not support loading content through the Qt Resource system. 110 | */ 111 | 112 | void QQuickWebView::setUrl(const QUrl &url) 113 | { 114 | m_webView->setUrl(url); 115 | } 116 | 117 | /*! 118 | \qmlproperty string QtWebView::WebView::title 119 | \readonly 120 | 121 | The title of the currently loaded web page. 122 | */ 123 | 124 | QString QQuickWebView::title() const 125 | { 126 | return m_webView->title(); 127 | } 128 | 129 | QUrl QQuickWebView::url() const 130 | { 131 | return m_webView->url(); 132 | } 133 | 134 | /*! 135 | \qmlproperty bool QtWebView::WebView::canGoBack 136 | \readonly 137 | 138 | Holds \c true if it's currently possible to navigate back in the web history. 139 | */ 140 | 141 | bool QQuickWebView::canGoBack() const 142 | { 143 | return m_webView->canGoBack(); 144 | } 145 | 146 | /*! 147 | \qmlproperty bool QtWebView::WebView::canGoForward 148 | \readonly 149 | 150 | Holds \c true if it's currently possible to navigate forward in the web history. 151 | */ 152 | 153 | bool QQuickWebView::canGoForward() const 154 | { 155 | return m_webView->canGoForward(); 156 | } 157 | 158 | /*! 159 | \qmlproperty int QtWebView::WebView::loadProgress 160 | \readonly 161 | 162 | The current load progress of the web content, represented as 163 | an integer between 0 and 100. 164 | */ 165 | int QQuickWebView::loadProgress() const 166 | { 167 | return m_webView->loadProgress(); 168 | } 169 | 170 | /*! 171 | \qmlproperty bool QtWebView::WebView::loading 172 | \readonly 173 | 174 | Holds \c true if the WebView is currently in the process of loading 175 | new content, \c false otherwise. 176 | 177 | \sa loadingChanged() 178 | */ 179 | 180 | /*! 181 | \qmlsignal QtWebView::WebView::loadingChanged(WebViewLoadRequest loadRequest) 182 | 183 | This signal is emitted when the state of loading the web content changes. 184 | By handling this signal it's possible, for example, to react to page load 185 | errors. 186 | 187 | The \a loadRequest parameter holds the \e url and \e status of the request, 188 | as well as an \e errorString containing an error message for a failed 189 | request. 190 | 191 | \sa WebViewLoadRequest 192 | */ 193 | bool QQuickWebView::isLoading() const 194 | { 195 | return m_webView->isLoading(); 196 | } 197 | 198 | /*! 199 | \qmlmethod void QtWebView::WebView::goBack() 200 | 201 | Navigates back in the web history. 202 | */ 203 | void QQuickWebView::goBack() 204 | { 205 | m_webView->goBack(); 206 | } 207 | 208 | /*! 209 | \qmlmethod void QtWebView::WebView::goForward() 210 | 211 | Navigates forward in the web history. 212 | */ 213 | void QQuickWebView::goForward() 214 | { 215 | m_webView->goForward(); 216 | } 217 | 218 | /*! 219 | \qmlmethod void QtWebView::WebView::reload() 220 | 221 | Reloads the current \l url. 222 | */ 223 | void QQuickWebView::reload() 224 | { 225 | m_webView->reload(); 226 | } 227 | 228 | /*! 229 | \qmlmethod void QtWebView::WebView::stop() 230 | 231 | Stops loading the current \l url. 232 | */ 233 | void QQuickWebView::stop() 234 | { 235 | m_webView->stop(); 236 | } 237 | 238 | /*! 239 | \qmlmethod void QtWebView::WebView::loadHtml(string html, url baseUrl) 240 | 241 | Loads the specified \a html content to the web view. 242 | 243 | This method offers a lower-level alternative to the \l url property, 244 | which references HTML pages via URL. 245 | 246 | External objects such as stylesheets or images referenced in the HTML 247 | document should be located relative to \a baseUrl. For example, if \a html 248 | is retrieved from \c http://www.example.com/documents/overview.html, which 249 | is the base URL, then an image referenced with the relative url, \c diagram.png, 250 | should be at \c{http://www.example.com/documents/diagram.png}. 251 | 252 | \note The WebView does not support loading content through the Qt Resource system. 253 | 254 | \sa url 255 | */ 256 | void QQuickWebView::loadHtml(const QString &html, const QUrl &baseUrl) 257 | { 258 | m_webView->loadHtml(html, baseUrl); 259 | } 260 | 261 | /*! 262 | \qmlmethod void QtWebView::WebView::runJavaScript(string script, variant callback) 263 | 264 | Runs the specified JavaScript. 265 | In case a \a callback function is provided, it will be invoked after the \a script 266 | finished running. 267 | 268 | \badcode 269 | runJavaScript("document.title", function(result) { console.log(result); }); 270 | \endcode 271 | */ 272 | void QQuickWebView::runJavaScript(const QString &script, const QJSValue &callback) 273 | { 274 | if (callback.isCallable()) { 275 | int callbackId = callbacks->insertCallback(callback); 276 | QPointer weakEngine = qmlEngine(this); 277 | m_webView->runJavaScript(script, [callbackId, weakEngine](const QVariant &result) { 278 | QJSValue callback = callbacks->takeCallback(callbackId); 279 | if (!weakEngine) { 280 | qWarning("No JavaScript engine, unable to handle JavaScript callback!"); 281 | return; 282 | } 283 | 284 | Q_ASSERT(callback.isCallable()); 285 | QJSValueList args; 286 | args.append(weakEngine->toScriptValue(result)); 287 | callback.call(args); 288 | }); 289 | } else { 290 | m_webView->runJavaScript(script); 291 | } 292 | } 293 | 294 | /*! 295 | \qmlmethod void QtWebView::WebView::setCookie(string domain, string name, string value) 296 | \since QtWebView 6.3 297 | Adds a cookie with the specified \a domain, \a name and \a value. 298 | 299 | The \l cookieAdded signal will be emitted when the cookie is added. 300 | */ 301 | /*! 302 | \qmlsignal QtWebView::WebView::cookieAdded(string domain, string name) 303 | 304 | This signal is emitted when a cookie is added. 305 | 306 | The parameters provide information about the \a domain and the \a name of the added cookie. 307 | 308 | \note When Qt WebEngine module is used as backend, cookieAdded signal will be emitted for any 309 | cookie added to the underlying QWebEngineCookieStore, including those added by websites. 310 | In other cases cookieAdded signal is only emitted for cookies explicitly added with \l setCookie(). 311 | */ 312 | void QQuickWebView::setCookie(const QString &domain, const QString &name, const QString &value) 313 | { 314 | m_webView->setCookie(domain, name, value); 315 | } 316 | 317 | /*! 318 | \qmlmethod void QtWebView::WebView::deleteCookie(string domain, string name) 319 | \since QtWebView 6.3 320 | Deletes a cookie with the specified \a domain and \a name. 321 | 322 | The \l cookieRemoved signal will be emitted when the cookie is deleted. 323 | */ 324 | /*! 325 | \qmlsignal QtWebView::WebView::cookieRemoved(string domain, string name) 326 | 327 | This signal is emitted when a cookie is deleted. 328 | 329 | The parameters provide information about the \a domain and the \a name of the deleted cookie. 330 | */ 331 | void QQuickWebView::deleteCookie(const QString &domain, const QString &name) 332 | { 333 | m_webView->deleteCookie(domain, name); 334 | } 335 | 336 | /*! 337 | \qmlmethod void QtWebView::WebView::deleteAllCookies() 338 | \since QtWebView 6.3 339 | Deletes all the cookies. 340 | */ 341 | void QQuickWebView::deleteAllCookies() 342 | { 343 | m_webView->deleteAllCookies(); 344 | } 345 | 346 | void QQuickWebView::onLoadingChanged(const QWebViewLoadRequest &loadRequest) 347 | { 348 | QQuickWebViewLoadRequest qqLoadRequest(loadRequest); 349 | Q_EMIT loadingChanged(&qqLoadRequest); 350 | } 351 | 352 | /*! 353 | \qmlproperty WebViewSettings WebView::settings 354 | \readonly 355 | \since QtWebView 6.5 356 | 357 | Settings object for the WebView. 358 | 359 | \sa WebViewSettings 360 | */ 361 | 362 | QQuickWebViewSettings *QQuickWebView::settings() const 363 | { 364 | return m_settings; 365 | } 366 | --------------------------------------------------------------------------------