diff options
Diffstat (limited to 'src/webengine')
34 files changed, 1152 insertions, 2404 deletions
diff --git a/src/webengine/api/qquickwebenginecertificateerror_p.h b/src/webengine/api/qquickwebenginecertificateerror_p.h deleted file mode 100644 index 4a8ef6ae0..000000000 --- a/src/webengine/api/qquickwebenginecertificateerror_p.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKWEBENGINECERTIFICATEERROR_P_H -#define QQUICKWEBENGINECERTIFICATEERROR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QObject> -#include "qquickwebengineview_p.h" - -QT_BEGIN_NAMESPACE - -class QQuickWebEngineCertificateErrorPrivate; -class CertificateErrorController; - -class Q_WEBENGINE_EXPORT QQuickWebEngineCertificateError : public QObject { - Q_OBJECT - Q_PROPERTY(QUrl url READ url CONSTANT FINAL) - Q_PROPERTY(Error error READ error CONSTANT FINAL) - Q_PROPERTY(QString description READ description CONSTANT FINAL) - Q_PROPERTY(bool overridable READ overridable CONSTANT FINAL) - -public: - - // Keep this identical to CertificateErrorController::CertificateError, or add mapping layer. - enum Error { - SslPinnedKeyNotInCertificateChain = -150, - CertificateCommonNameInvalid = -200, - CertificateDateInvalid = -201, - CertificateAuthorityInvalid = -202, - CertificateContainsErrors = -203, - CertificateNoRevocationMechanism = -204, - CertificateUnableToCheckRevocation = -205, - CertificateRevoked = -206, - CertificateInvalid = -207, - CertificateWeakSignatureAlgorithm = -208, - CertificateNonUniqueName = -210, - CertificateWeakKey = -211, - CertificateNameConstraintViolation = -212, - CertificateValidityTooLong = -213, - CertificateTransparencyRequired = -214, - CertificateKnownInterceptionBlocked = -217, - }; - Q_ENUM(Error) - - QQuickWebEngineCertificateError(const QSharedPointer<CertificateErrorController> &controller, QObject *parent = 0); - ~QQuickWebEngineCertificateError(); - - Q_INVOKABLE void defer(); - Q_INVOKABLE void ignoreCertificateError(); - Q_INVOKABLE void rejectCertificate(); - QUrl url() const; - Error error() const; - QString description() const; - bool overridable() const; - bool deferred() const; - bool answered() const; - -private: - Q_DISABLE_COPY(QQuickWebEngineCertificateError) - Q_DECLARE_PRIVATE(QQuickWebEngineCertificateError) - QScopedPointer<QQuickWebEngineCertificateErrorPrivate> d_ptr; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickWebEngineCertificateError) - -#endif // QQUICKWEBENGINECERTIFICATEERROR_P_H diff --git a/src/webengine/api/qquickwebengineclientcertificateselection.cpp b/src/webengine/api/qquickwebengineclientcertificateselection.cpp index c48a59887..f6c37a5b0 100644 --- a/src/webengine/api/qquickwebengineclientcertificateselection.cpp +++ b/src/webengine/api/qquickwebengineclientcertificateselection.cpp @@ -132,8 +132,9 @@ void QQuickWebEngineClientCertificateOption::select() \sa {WebEngineView::selectClientCertificate}{WebEngineView.selectClientCertificate} */ -QQuickWebEngineClientCertificateSelection::QQuickWebEngineClientCertificateSelection(QSharedPointer<ClientCertSelectController> selectController) - : QObject(), d_ptr(selectController) +QQuickWebEngineClientCertificateSelection::QQuickWebEngineClientCertificateSelection( + QSharedPointer<QtWebEngineCore::ClientCertSelectController> selectController) + : QObject(), d_ptr(selectController) {} int QQuickWebEngineClientCertificateSelection::certificates_count( @@ -162,7 +163,7 @@ QQuickWebEngineClientCertificateOption *QQuickWebEngineClientCertificateSelectio QQmlListProperty<QQuickWebEngineClientCertificateOption> QQuickWebEngineClientCertificateSelection::certificates() { if (m_certificates.empty()) { - QVector<QSslCertificate> certificates = d_ptr->certificates(); + QList<QSslCertificate> certificates = d_ptr->certificates(); for (int i = 0; i < certificates.count(); ++i) m_certificates.push_back(new QQuickWebEngineClientCertificateOption(this, i)); } diff --git a/src/webengine/api/qquickwebengineclientcertificateselection_p.h b/src/webengine/api/qquickwebengineclientcertificateselection_p.h index adf8b5f7c..fe868e76c 100644 --- a/src/webengine/api/qquickwebengineclientcertificateselection_p.h +++ b/src/webengine/api/qquickwebengineclientcertificateselection_p.h @@ -57,14 +57,17 @@ #include <QtCore/QObject> #include <QtCore/QSharedPointer> #include <QtCore/QUrl> -#include <QtCore/QVector> +#include <QtCore/QList> #include <QtQml/QQmlListProperty> #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) +namespace QtWebEngineCore { +class ClientCertSelectController; +} + QT_BEGIN_NAMESPACE -class ClientCertSelectController; class QQuickWebEngineClientCertificateSelection; class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineClientCertificateOption : public QObject { @@ -114,10 +117,11 @@ private: static int certificates_count(QQmlListProperty<QQuickWebEngineClientCertificateOption> *p); static QQuickWebEngineClientCertificateOption *certificates_at(QQmlListProperty<QQuickWebEngineClientCertificateOption> *p, int idx); - explicit QQuickWebEngineClientCertificateSelection(QSharedPointer<ClientCertSelectController>); + explicit QQuickWebEngineClientCertificateSelection( + QSharedPointer<QtWebEngineCore::ClientCertSelectController>); - mutable QVector<QQuickWebEngineClientCertificateOption *> m_certificates; - QSharedPointer<ClientCertSelectController> d_ptr; + mutable QList<QQuickWebEngineClientCertificateOption *> m_certificates; + QSharedPointer<QtWebEngineCore::ClientCertSelectController> d_ptr; }; QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginecontextmenurequest.cpp b/src/webengine/api/qquickwebenginecontextmenurequest.cpp deleted file mode 100644 index e1ebd4c8c..000000000 --- a/src/webengine/api/qquickwebenginecontextmenurequest.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickwebenginecontextmenurequest_p.h" -#include "web_contents_adapter_client.h" - -QT_BEGIN_NAMESPACE - -// Match MediaType enum -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeNone, - QQuickWebEngineContextMenuRequest::MediaTypeNone) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeImage, - QQuickWebEngineContextMenuRequest::MediaTypeImage) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeAudio, - QQuickWebEngineContextMenuRequest::MediaTypeAudio) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeVideo, - QQuickWebEngineContextMenuRequest::MediaTypeVideo) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeCanvas, - QQuickWebEngineContextMenuRequest::MediaTypeCanvas) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeFile, - QQuickWebEngineContextMenuRequest::MediaTypeFile) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypePlugin, - QQuickWebEngineContextMenuRequest::MediaTypePlugin) - -// Match MediaFlag enum -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaInError, - QQuickWebEngineContextMenuRequest::MediaInError) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaPaused, - QQuickWebEngineContextMenuRequest::MediaPaused) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaMuted, - QQuickWebEngineContextMenuRequest::MediaMuted) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaLoop, - QQuickWebEngineContextMenuRequest::MediaLoop) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaCanSave, - QQuickWebEngineContextMenuRequest::MediaCanSave) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaHasAudio, - QQuickWebEngineContextMenuRequest::MediaHasAudio) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaCanToggleControls, - QQuickWebEngineContextMenuRequest::MediaCanToggleControls) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaControls, - QQuickWebEngineContextMenuRequest::MediaControls) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaCanPrint, - QQuickWebEngineContextMenuRequest::MediaCanPrint) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaCanRotate, - QQuickWebEngineContextMenuRequest::MediaCanRotate) - -// Match EditFlag enum -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanUndo, - QQuickWebEngineContextMenuRequest::CanUndo) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanRedo, - QQuickWebEngineContextMenuRequest::CanRedo) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanCut, - QQuickWebEngineContextMenuRequest::CanCut) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanCopy, - QQuickWebEngineContextMenuRequest::CanCopy) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanPaste, - QQuickWebEngineContextMenuRequest::CanPaste) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanDelete, - QQuickWebEngineContextMenuRequest::CanDelete) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanSelectAll, - QQuickWebEngineContextMenuRequest::CanSelectAll) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanTranslate, - QQuickWebEngineContextMenuRequest::CanTranslate) -ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::CanEditRichly, - QQuickWebEngineContextMenuRequest::CanEditRichly) - -/*! - \qmltype ContextMenuRequest - \instantiates QQuickWebEngineContextMenuRequest - \inqmlmodule QtWebEngine - \since QtWebEngine 1.4 - - \brief A request for showing a context menu. - - A ContextMenuRequest is passed as an argument of the - WebEngineView::contextMenuRequested signal. It provides further - information about the context of the request. The position of the - request origin can be found via the \l x and \l y properties. - - The \l accepted property of the request indicates whether the request - is handled by the user code or the default context menu should - be displayed. - - The following code uses a custom menu to handle the request: - - \code - WebEngineView { - id: view - // ... - onContextMenuRequested: function(request) { - request.accepted = true; - myMenu.x = request.x; - myMenu.y = request.y; - myMenu.trigger.connect(view.triggerWebAction); - myMenu.popup(); - } - // ... - } - \endcode -*/ - -QQuickWebEngineContextMenuRequest::QQuickWebEngineContextMenuRequest( - const QtWebEngineCore::WebEngineContextMenuData &data, QObject *parent): - QObject(parent) - , m_data(new QtWebEngineCore::WebEngineContextMenuData(data)) - , m_accepted(false) -{ -} - -QQuickWebEngineContextMenuRequest::~QQuickWebEngineContextMenuRequest() -{ -} - -/*! - \qmlproperty int ContextMenuRequest::x - \readonly - - The x coordinate of the user action from where the context - menu request originates. -*/ - -int QQuickWebEngineContextMenuRequest::x() const -{ - return m_data->position().x(); -} - -/*! - \qmlproperty int ContextMenuRequest::y - \readonly - - The y coordinate of the user action from where the context - menu request originates. -*/ - -int QQuickWebEngineContextMenuRequest::y() const -{ - return m_data->position().y(); -} - -/*! - \qmlproperty string ContextMenuRequest::selectedText - \readonly - - The selected text the context menu was created for. -*/ - -QString QQuickWebEngineContextMenuRequest::selectedText() const -{ - return m_data->selectedText(); -} - -/*! - \qmlproperty string ContextMenuRequest::linkText - \readonly - - The text of the link if the context menu was requested for a link. -*/ - -QString QQuickWebEngineContextMenuRequest::linkText() const -{ - return m_data->linkText(); -} - -/*! - \qmlproperty url ContextMenuRequest::linkUrl - \readonly - - The URL of the link if the selected web page content is a link. - It is not guaranteed to be a valid URL. -*/ - -QUrl QQuickWebEngineContextMenuRequest::linkUrl() const -{ - return m_data->unfilteredLinkUrl(); -} - -/*! - \qmlproperty url ContextMenuRequest::mediaUrl - \readonly - - The URL of media if the selected web content is a media element. -*/ - -QUrl QQuickWebEngineContextMenuRequest::mediaUrl() const -{ - return m_data->mediaUrl(); -} - -/*! - \qmlproperty enumeration ContextMenuRequest::mediaType - \readonly - - The type of the media element or \c MediaTypeNone if - the selected web page content is not a media element. - - \value ContextMenuRequest.MediaTypeNone - Not a media. - \value ContextMenuRequest.MediaTypeImage - An image. - \value ContextMenuRequest.MediaTypeVideo - A video. - \value ContextMenuRequest.MediaTypeAudio - An audio element. - \value ContextMenuRequest.MediaTypeCanvas - A canvas. - \value ContextMenuRequest.MediaTypeFile - A file. - \value ContextMenuRequest.MediaTypePlugin - A plugin. -*/ - -QQuickWebEngineContextMenuRequest::MediaType QQuickWebEngineContextMenuRequest::mediaType() const -{ - return static_cast<QQuickWebEngineContextMenuRequest::MediaType>(m_data->mediaType()); -} - -/*! - \qmlproperty bool ContextMenuRequest::isContentEditable - \readonly - - Indicates whether the selected web content is editable. -*/ - -bool QQuickWebEngineContextMenuRequest::isContentEditable() const -{ - return m_data->isEditable(); -} - -/*! - \qmlproperty string ContextMenuRequest::misspelledWord - \readonly - - If the context is a word considered misspelled by the spell-checker, - returns the misspelled word. -*/ - -QString QQuickWebEngineContextMenuRequest::misspelledWord() const -{ - return m_data->misspelledWord(); -} - -/*! - \qmlproperty stringlist ContextMenuRequest::spellCheckerSuggestions - \readonly - - If the context is a word considered misspelled by the spell-checker, - returns a list of suggested replacements. -*/ - -QStringList QQuickWebEngineContextMenuRequest::spellCheckerSuggestions() const -{ - return m_data->spellCheckerSuggestions(); -} - -/*! - \qmlproperty bool ContextMenuRequest::accepted - - Indicates whether the context menu request has been - handled by the signal handler. - - If the property is \c false after any signal handlers - for WebEngineView::contextMenuRequested have been executed, - a default context menu will be shown. - To prevent this, set \c{request.accepted} to \c true. - - The default is \c false. - - \note The default content of the context menu depends on the - web element for which the request was actually generated. -*/ - -bool QQuickWebEngineContextMenuRequest::isAccepted() const -{ - return m_accepted; -} - -void QQuickWebEngineContextMenuRequest::setAccepted(bool accepted) -{ - m_accepted = accepted; -} - -/*! - \qmlproperty flags ContextMenuRequest::mediaFlags - \readonly - \since QtWebEngine 1.7 - - The current media element's status and its available operations. - \c MediaNone if the selected web page content is not a media element. - - \value ContextMenuRequest.MediaInError - An error occurred. - \value ContextMenuRequest.MediaPaused - Media is paused. - \value ContextMenuRequest.MediaMuted - Media is muted. - \value ContextMenuRequest.MediaLoop - Media can be looped. - \value ContextMenuRequest.MediaCanSave - Media can be saved. - \value ContextMenuRequest.MediaHasAudio - Media has audio. - \value ContextMenuRequest.MediaCanToggleControls - Media can show controls. - \value ContextMenuRequest.MediaControls - Media controls are shown. - \value ContextMenuRequest.MediaCanPrint - Media is printable. - \value ContextMenuRequest.MediaCanRotate - Media is rotatable. -*/ -QQuickWebEngineContextMenuRequest::MediaFlags QQuickWebEngineContextMenuRequest::mediaFlags() const -{ - return static_cast<QQuickWebEngineContextMenuRequest::MediaFlags>(m_data->mediaFlags()); -} - -/*! - \qmlproperty flags ContextMenuRequest::editFlags - \readonly - \since QtWebEngine 1.7 - - The available edit operations in the current context or \c CanDoNone if no actions are available. - - \value ContextMenuRequest.CanUndo - Undo is available. - \value ContextMenuRequest.CanRedo - Redo is available. - \value ContextMenuRequest.CanCut - Cut is available. - \value ContextMenuRequest.CanCopy - Copy is available. - \value ContextMenuRequest.CanPaste - Paste is available. - \value ContextMenuRequest.CanDelete - Delete is available. - \value ContextMenuRequest.CanSelectAll - Select All is available. - \value ContextMenuRequest.CanTranslate - Translate is available. - \value ContextMenuRequest.CanEditRichly - Context is richly editable. -*/ -QQuickWebEngineContextMenuRequest::EditFlags QQuickWebEngineContextMenuRequest::editFlags() const -{ - return static_cast<QQuickWebEngineContextMenuRequest::EditFlags>(m_data->editFlags()); -} - -QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginecontextmenurequest_p.h b/src/webengine/api/qquickwebenginecontextmenurequest_p.h deleted file mode 100644 index bc50eccb8..000000000 --- a/src/webengine/api/qquickwebenginecontextmenurequest_p.h +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKWEBENGINECONTEXTMENUREQUEST_H -#define QQUICKWEBENGINECONTEXTMENUREQUEST_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#include <QtWebEngine/private/qtwebengineglobal_p.h> -#include <QtCore/QScopedPointer> -#include <QtCore/QObject> -#include <QtCore/QUrl> - -namespace QtWebEngineCore { - class WebEngineContextMenuData; -} - -QT_BEGIN_NAMESPACE - -class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineContextMenuRequest: public QObject { - Q_OBJECT -public: - enum MediaType { - MediaTypeNone, - MediaTypeImage, - MediaTypeVideo, - MediaTypeAudio, - MediaTypeCanvas, - MediaTypeFile, - MediaTypePlugin - }; - Q_ENUM(MediaType) - - // Must match QWebEngineCore::WebEngineContextMenuData::MediaFlags: - enum MediaFlag { - MediaInError = 0x1, - MediaPaused = 0x2, - MediaMuted = 0x4, - MediaLoop = 0x8, - MediaCanSave = 0x10, - MediaHasAudio = 0x20, - MediaCanToggleControls = 0x40, - MediaControls = 0x80, - MediaCanPrint = 0x100, - MediaCanRotate = 0x200, - }; - Q_DECLARE_FLAGS(MediaFlags, MediaFlag) - Q_FLAG(MediaFlags) - - // Must match QWebEngineCore::WebEngineContextMenuData::EditFlags: - enum EditFlag { - CanUndo = 0x1, - CanRedo = 0x2, - CanCut = 0x4, - CanCopy = 0x8, - CanPaste = 0x10, - CanDelete = 0x20, - CanSelectAll = 0x40, - CanTranslate = 0x80, - CanEditRichly = 0x100, - }; - Q_DECLARE_FLAGS(EditFlags, EditFlag) - Q_FLAG(EditFlags) - - Q_PROPERTY(int x READ x CONSTANT FINAL) - Q_PROPERTY(int y READ y CONSTANT FINAL) - Q_PROPERTY(QString selectedText READ selectedText CONSTANT FINAL) - Q_PROPERTY(QString linkText READ linkText CONSTANT FINAL) - Q_PROPERTY(QUrl linkUrl READ linkUrl CONSTANT FINAL) - Q_PROPERTY(QUrl mediaUrl READ mediaUrl CONSTANT FINAL) - Q_PROPERTY(MediaType mediaType READ mediaType CONSTANT FINAL) - Q_PROPERTY(bool isContentEditable READ isContentEditable CONSTANT FINAL) - Q_PROPERTY(QString misspelledWord READ misspelledWord CONSTANT FINAL) - Q_PROPERTY(QStringList spellCheckerSuggestions READ spellCheckerSuggestions CONSTANT FINAL) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL) - Q_PROPERTY(MediaFlags mediaFlags READ mediaFlags CONSTANT FINAL REVISION 1) - Q_PROPERTY(EditFlags editFlags READ editFlags CONSTANT FINAL REVISION 1) - - ~QQuickWebEngineContextMenuRequest(); - int x() const; - int y() const; - QString selectedText() const; - QString linkText() const; - QUrl linkUrl() const; - QUrl mediaUrl() const; - MediaType mediaType() const; - bool isContentEditable() const; - QString misspelledWord() const; - QStringList spellCheckerSuggestions() const; - bool isAccepted() const; - void setAccepted(bool accepted); - MediaFlags mediaFlags() const; - EditFlags editFlags() const; - -private: - QQuickWebEngineContextMenuRequest(const QtWebEngineCore::WebEngineContextMenuData &data, QObject *parent = nullptr); - QScopedPointer<QtWebEngineCore::WebEngineContextMenuData> m_data; - bool m_accepted; - friend class QQuickWebEngineView; - friend class QQuickWebEngineViewPrivate; - Q_DISABLE_COPY(QQuickWebEngineContextMenuRequest) -}; - -QT_END_NAMESPACE - -#endif // QQUICKWEBENGINECONTEXTMENUREQUEST_H diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp deleted file mode 100644 index 767ada58f..000000000 --- a/src/webengine/api/qquickwebenginedownloaditem.cpp +++ /dev/null @@ -1,789 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickwebenginedownloaditem_p.h" -#include "qquickwebenginedownloaditem_p_p.h" - -#include "profile_adapter.h" -#include "qquickwebengineprofile_p.h" - -#include <QDir> -#include "QFileInfo" - -using QtWebEngineCore::ProfileAdapterClient; - -QT_BEGIN_NAMESPACE - -ASSERT_ENUMS_MATCH(ProfileAdapterClient::NoReason, QQuickWebEngineDownloadItem::NoReason) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileFailed, QQuickWebEngineDownloadItem::FileFailed) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileAccessDenied, QQuickWebEngineDownloadItem::FileAccessDenied) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileNoSpace, QQuickWebEngineDownloadItem::FileNoSpace) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileNameTooLong, QQuickWebEngineDownloadItem::FileNameTooLong) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileTooLarge, QQuickWebEngineDownloadItem::FileTooLarge) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileVirusInfected, QQuickWebEngineDownloadItem::FileVirusInfected) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileTransientError, QQuickWebEngineDownloadItem::FileTransientError) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileBlocked, QQuickWebEngineDownloadItem::FileBlocked) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileSecurityCheckFailed, QQuickWebEngineDownloadItem::FileSecurityCheckFailed) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileTooShort, QQuickWebEngineDownloadItem::FileTooShort) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::FileHashMismatch, QQuickWebEngineDownloadItem::FileHashMismatch) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::NetworkFailed, QQuickWebEngineDownloadItem::NetworkFailed) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::NetworkTimeout, QQuickWebEngineDownloadItem::NetworkTimeout) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::NetworkDisconnected, QQuickWebEngineDownloadItem::NetworkDisconnected) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::NetworkServerDown, QQuickWebEngineDownloadItem::NetworkServerDown) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::NetworkInvalidRequest, QQuickWebEngineDownloadItem::NetworkInvalidRequest) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerFailed, QQuickWebEngineDownloadItem::ServerFailed) -//ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerNoRange, QQuickWebEngineDownloadItem::ServerNoRange) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerBadContent, QQuickWebEngineDownloadItem::ServerBadContent) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerUnauthorized, QQuickWebEngineDownloadItem::ServerUnauthorized) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerCertProblem, QQuickWebEngineDownloadItem::ServerCertProblem) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerForbidden, QQuickWebEngineDownloadItem::ServerForbidden) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::ServerUnreachable, QQuickWebEngineDownloadItem::ServerUnreachable) -ASSERT_ENUMS_MATCH(ProfileAdapterClient::UserCanceled, QQuickWebEngineDownloadItem::UserCanceled) -//ASSERT_ENUMS_MATCH(ProfileAdapterClient::UserShutdown, QQuickWebEngineDownloadItem::UserShutdown) -//ASSERT_ENUMS_MATCH(ProfileAdapterClient::Crash, QQuickWebEngineDownloadItem::Crash) - -static inline QQuickWebEngineDownloadItem::DownloadState toDownloadState(int state) { - switch (state) { - case ProfileAdapterClient::DownloadInProgress: - return QQuickWebEngineDownloadItem::DownloadInProgress; - case ProfileAdapterClient::DownloadCompleted: - return QQuickWebEngineDownloadItem::DownloadCompleted; - case ProfileAdapterClient::DownloadCancelled: - return QQuickWebEngineDownloadItem::DownloadCancelled; - case ProfileAdapterClient::DownloadInterrupted: - return QQuickWebEngineDownloadItem::DownloadInterrupted; - default: - Q_UNREACHABLE(); - return QQuickWebEngineDownloadItem::DownloadCancelled; - } -} - -static inline QQuickWebEngineDownloadItem::DownloadInterruptReason toDownloadInterruptReason(int reason) -{ - return static_cast<QQuickWebEngineDownloadItem::DownloadInterruptReason>(reason); -} - -QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfile *p, const QUrl &url) - : profile(p) - , downloadId(-1) - , downloadState(QQuickWebEngineDownloadItem::DownloadCancelled) - , savePageFormat(QQuickWebEngineDownloadItem::UnknownSaveFormat) - , type(QQuickWebEngineDownloadItem::Attachment) - , interruptReason(QQuickWebEngineDownloadItem::NoReason) - , totalBytes(-1) - , receivedBytes(0) - , downloadFinished(false) - , downloadPaused(false) - , view(nullptr) - , downloadUrl(url) - , isCustomFileName(false) -{ -} - -QQuickWebEngineDownloadItemPrivate::~QQuickWebEngineDownloadItemPrivate() -{ - if (profile) - profile->d_ptr->downloadDestroyed(downloadId); -} - -/*! - \qmltype WebEngineDownloadItem - \instantiates QQuickWebEngineDownloadItem - \inqmlmodule QtWebEngine - \since QtWebEngine 1.1 - \brief Provides information about a download. - - WebEngineDownloadItem models a download throughout its life cycle, starting - with a pending download request and finishing with a completed download. It - can be used, for example, to get information about new downloads, to monitor - progress, and to pause, resume, and cancel downloads. - - Downloads are usually triggered by user interaction on a web page. It is the - WebEngineProfile's responsibility to notify the application of new download - requests, which it does by emitting the - \l{WebEngineProfile::downloadRequested}{downloadRequested} signal together - with a newly created WebEngineDownloadItem. The application can then examine - this item and decide whether to accept it or not. A signal handler must - explicitly call accept() on the item for \QWE to actually start - downloading and writing data to disk. If no signal handler calls accept(), - then the download request will be automatically rejected and nothing will be - written to disk. - - \note Some properties, like the \l path under which the file will be saved, - can only be changed before calling accept(). - - \section2 Object Life Cycle - - All items are guaranteed to be valid during the emission of the - \l{WebEngineProfile::downloadRequested}{downloadRequested} signal. If - accept() is \e not called by any signal handler, then the item will be - deleted \e immediately after signal emission. This means that the - application \b{must not} keep references to rejected download items. - - \section2 Web Page Downloads - - In addition to normal file downloads, which consist simply of retrieving - some raw bytes from the network and writing them to disk, \QWE also - supports saving complete web pages, which involves parsing the page's HTML, - downloading any dependent resources, and potentially packaging everything - into a special file format (\l savePageFormat). To check if a download is - for a file or a web page, use \l isSavePageDownload. - - \sa WebEngineProfile, WebEngineProfile::downloadRequested, - WebEngineProfile::downloadFinished -*/ - -void QQuickWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::DownloadItemInfo &info) -{ - Q_Q(QQuickWebEngineDownloadItem); - - updateState(toDownloadState(info.state)); - - if (toDownloadInterruptReason(info.downloadInterruptReason) != interruptReason) { - interruptReason = toDownloadInterruptReason(info.downloadInterruptReason); - Q_EMIT q->interruptReasonChanged(); - } - - if (info.receivedBytes != receivedBytes) { - receivedBytes = info.receivedBytes; - Q_EMIT q->receivedBytesChanged(); - } - - if (info.totalBytes != totalBytes) { - totalBytes = info.totalBytes; - Q_EMIT q->totalBytesChanged(); - } - - if (info.done) - setFinished(); - - if (info.paused != downloadPaused) { - downloadPaused = info.paused; - Q_EMIT q->isPausedChanged(); - } -} - -void QQuickWebEngineDownloadItemPrivate::updateState(QQuickWebEngineDownloadItem::DownloadState newState) -{ - Q_Q(QQuickWebEngineDownloadItem); - - if (downloadState != newState) { - downloadState = newState; - Q_EMIT q->stateChanged(); - } -} - -void QQuickWebEngineDownloadItemPrivate::setFinished() -{ - Q_Q(QQuickWebEngineDownloadItem); - - if (downloadFinished) - return; - - downloadFinished = true; - Q_EMIT q->isFinishedChanged(); -} - -/*! - \qmlmethod void WebEngineDownloadItem::accept() - - Accepts the download request, which will start the download. - - If the item is in the \c DownloadRequested state, then it will transition - into the \c DownloadInProgress state and the downloading will begin. If the - item is in any other state, then nothing will happen. - - \sa state -*/ - -void QQuickWebEngineDownloadItem::accept() -{ - Q_D(QQuickWebEngineDownloadItem); - - if (d->downloadState != QQuickWebEngineDownloadItem::DownloadRequested) - return; - - d->updateState(QQuickWebEngineDownloadItem::DownloadInProgress); -} - -/*! - \qmlmethod void WebEngineDownloadItem::cancel() - - Cancels the download. - - If the item is in the \c DownloadInProgress state, then it will transition - into the \c DownloadCancelled state, the downloading will stop, and - partially downloaded files will be deleted from disk. - - If the item is in the \c DownloadCompleted state, then nothing will happen. - If the item is in any other state, then it will transition into the \c - DownloadCancelled state without further effect. - - \sa state -*/ - -void QQuickWebEngineDownloadItem::cancel() -{ - Q_D(QQuickWebEngineDownloadItem); - - QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; - - if (state == QQuickWebEngineDownloadItem::DownloadCompleted - || state == QQuickWebEngineDownloadItem::DownloadCancelled) - return; - - d->updateState(QQuickWebEngineDownloadItem::DownloadCancelled); - d->setFinished(); - - // We directly cancel the download if the user cancels before - // it even started, so no need to notify the profile here. - if (state == QQuickWebEngineDownloadItem::DownloadInProgress) { - if (d->profile) - d->profile->d_ptr->cancelDownload(d->downloadId); - } -} - - -/*! - \qmlmethod void WebEngineDownloadItem::pause() - \since QtWebEngine 1.6 - - Pauses the download. - - Has no effect if the state is not \c DownloadInProgress. Does not change the - state. - - \sa resume, isPaused -*/ - -void QQuickWebEngineDownloadItem::pause() -{ - Q_D(QQuickWebEngineDownloadItem); - - QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; - - if (state != QQuickWebEngineDownloadItem::DownloadInProgress) - return; - - if (d->profile) - d->profile->d_ptr->profileAdapter()->pauseDownload(d->downloadId); -} - -/*! - \qmlmethod void WebEngineDownloadItem::resume() - \since QtWebEngine 1.6 - - Resumes the download if it was paused or interrupted. - - Has no effect if the state is not \c DownloadInProgress or \c - DownloadInterrupted. Does not change the state. - - \sa pause, isPaused -*/ -void QQuickWebEngineDownloadItem::resume() -{ - Q_D(QQuickWebEngineDownloadItem); - - QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; - - if (d->downloadFinished || (state != QQuickWebEngineDownloadItem::DownloadInProgress && state != QQuickWebEngineDownloadItem::DownloadInterrupted)) - return; - - if (d->profile) - d->profile->d_ptr->profileAdapter()->resumeDownload(d->downloadId); -} - -/*! - \qmlproperty int WebEngineDownloadItem::id - - Holds the download item's ID. -*/ - -quint32 QQuickWebEngineDownloadItem::id() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadId; -} - -/*! - \qmlproperty enumeration WebEngineDownloadItem::state - - Describes the state of the download: - - \value WebEngineDownloadItem.DownloadRequested - Download has been requested, but it has not been accepted yet. - \value WebEngineDownloadItem.DownloadInProgress - Download is in progress. - \value WebEngineDownloadItem.DownloadCompleted - Download completed successfully. - \value WebEngineDownloadItem.DownloadCancelled - Download was cancelled by the user. - \value WebEngineDownloadItem.DownloadInterrupted - Download has been interrupted (by the server or because of lost connectivity). -*/ - -QQuickWebEngineDownloadItem::DownloadState QQuickWebEngineDownloadItem::state() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadState; -} - -/*! - \qmlproperty int WebEngineDownloadItem::totalBytes - - Holds the total amount of data to download in bytes. - - \c -1 means the total size is unknown. -*/ - -qint64 QQuickWebEngineDownloadItem::totalBytes() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->totalBytes; -} - -/*! - \qmlproperty int WebEngineDownloadItem::receivedBytes - - Holds the amount of data in bytes that has been downloaded so far. -*/ - -qint64 QQuickWebEngineDownloadItem::receivedBytes() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->receivedBytes; -} - -/*! - \qmlproperty url WebEngineDownloadItem::url - \readonly - \since QtWebEngine 1.10 - - Returns the download's origin URL. -*/ - -QUrl QQuickWebEngineDownloadItem::url() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadUrl; -} - -/*! - \qmlproperty string WebEngineDownloadItem::mimeType - \since QtWebEngine 1.2 - - Holds the MIME type of the download. -*/ - -QString QQuickWebEngineDownloadItem::mimeType() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->mimeType; -} - -/*! - \qmlproperty string WebEngineDownloadItem::path - \obsolete - - Use \l suggestedFileName, \l downloadDirectory, and - \l downloadFileName instead. - - Holds the full target path where data is being downloaded to. - - The path includes the file name. The default suggested path is the standard - download location and file name is deduced not to overwrite already existing files. - - The download path can only be set in the - \l{WebEngineProfile::downloadRequested}{downloadRequested} handler before - the download is accepted. - - \sa WebEngineProfile::downloadRequested(), accept() -*/ - -QString QQuickWebEngineDownloadItem::path() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return QDir::cleanPath(QDir(d->downloadDirectory).filePath(d->downloadFileName)); -} - -void QQuickWebEngineDownloadItem::setPath(QString path) -{ - Q_D(QQuickWebEngineDownloadItem); - if (d->downloadState != QQuickWebEngineDownloadItem::DownloadRequested) { - qWarning("Setting the download path is not allowed after the download has been accepted."); - return; - } - if (QDir(d->downloadDirectory).filePath(d->downloadFileName) != path) { - if (QFileInfo(path).fileName().isEmpty()) { - qWarning("The download path does not include file name."); - return; - } - - if (QFileInfo(path).isDir()) { - qWarning("The download path matches with an already existing directory path."); - return; - } - - QString newDirectory; - QString newFileName; - - if (QFileInfo(path).fileName() == path) { - newDirectory = QStringLiteral(""); - newFileName = path; - } else { - newDirectory = QFileInfo(path).path(); - newFileName = QFileInfo(path).fileName(); - } - - if (d->downloadDirectory != newDirectory) { - d->downloadDirectory = newDirectory; - Q_EMIT pathChanged(); - Q_EMIT downloadDirectoryChanged(); - } - - if (d->downloadFileName != newFileName) { - d->downloadFileName = newFileName; - Q_EMIT pathChanged(); - Q_EMIT downloadFileNameChanged(); - } - } -} - -/*! - \qmlproperty string WebEngineDownloadItem::downloadDirectory - \since QtWebEngine 1.10 - - Holds the full target path without file name where data is being downloaded to. - - The download directory can only be set in the - \l{WebEngineProfile::downloadRequested}{downloadRequested} handler before - the download is accepted. - - \sa WebEngineProfile::downloadRequested(), accept() -*/ - -QString QQuickWebEngineDownloadItem::downloadDirectory() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadDirectory; -} - -void QQuickWebEngineDownloadItem::setDownloadDirectory(const QString &directory) -{ - Q_D(QQuickWebEngineDownloadItem); - if (d->downloadState != QQuickWebEngineDownloadItem::DownloadRequested) { - qWarning("Setting the download directory is not allowed after the download has been accepted."); - return; - } - - bool isPathChanged = false; - QString changeDirectory = d->downloadDirectory; - if (!directory.isEmpty() && changeDirectory != directory) { - changeDirectory = directory; - - if (d->downloadDirectory != changeDirectory) { - d->downloadDirectory = changeDirectory; - Q_EMIT downloadDirectoryChanged(); - isPathChanged = true; - } - - if (!d->isCustomFileName) { - QString newFileName = QFileInfo(d->profile->d_ptr->profileAdapter()->determineDownloadPath(d->downloadDirectory, - d->suggestedFileName, - d->startTime)).fileName(); - if (d->downloadFileName != newFileName) { - d->downloadFileName = newFileName; - Q_EMIT downloadFileNameChanged(); - isPathChanged = true; - } - } - } - - if (isPathChanged) - Q_EMIT pathChanged(); -} - -/*! - \qmlproperty string WebEngineDownloadItem::downloadFileName - \since QtWebEngine 1.10 - - Holds the name of the file to which data is being downloaded. - - The download file name can only be set in the - \l{WebEngineProfile::downloadRequested}{downloadRequested} handler before - the download is accepted. - - \sa WebEngineProfile::downloadRequested(), accept() -*/ - -QString QQuickWebEngineDownloadItem::downloadFileName() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadFileName; -} - -void QQuickWebEngineDownloadItem::setDownloadFileName(const QString &fileName) -{ - Q_D(QQuickWebEngineDownloadItem); - if (d->downloadState != QQuickWebEngineDownloadItem::DownloadRequested) { - qWarning("Setting the download file name is not allowed after the download has been accepted."); - return; - } - - if (d->downloadFileName != fileName && !fileName.isEmpty()) { - d->downloadFileName = fileName; - d->isCustomFileName = true; - Q_EMIT downloadFileNameChanged(); - Q_EMIT pathChanged(); - } -} - -/*! - \qmlproperty string WebEngineDownloadItem::suggestedFileName - \since QtWebEngine 1.10 - - Returns the suggested file name. -*/ - -QString QQuickWebEngineDownloadItem::suggestedFileName() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->suggestedFileName; -} - -/*! - \qmlproperty enumeration WebEngineDownloadItem::savePageFormat - \since QtWebEngine 1.3 - - Describes the format that is used to save a web page. - - \value WebEngineDownloadItem.UnknownSaveFormat - This is not a request for downloading a complete web page. - \value WebEngineDownloadItem.SingleHtmlSaveFormat - The page is saved as a single HTML page. Resources such as images - are not saved. - \value WebEngineDownloadItem.CompleteHtmlSaveFormat - The page is saved as a complete HTML page, for example a directory - containing the single HTML page and the resources. - \value WebEngineDownloadItem.MimeHtmlSaveFormat - The page is saved as a complete web page in the MIME HTML format. -*/ - -QQuickWebEngineDownloadItem::SavePageFormat QQuickWebEngineDownloadItem::savePageFormat() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->savePageFormat; -} - -void QQuickWebEngineDownloadItem::setSavePageFormat(QQuickWebEngineDownloadItem::SavePageFormat format) -{ - Q_D(QQuickWebEngineDownloadItem); - if (d->savePageFormat != format) { - d->savePageFormat = format; - Q_EMIT savePageFormatChanged(); - } -} - -/*! - \qmlproperty enumeration WebEngineDownloadItem::type - \readonly - \since QtWebEngine 1.4 - \obsolete - - Describes the requested download's type. - - \note This property works unreliably, except for \c SavePage - downloads. Use \l isSavePageDownload instead. - - \value WebEngineDownloadItem.Attachment The web server's response includes a - \c Content-Disposition header with the \c attachment directive. If \c Content-Disposition - is present in the reply, the web server is indicating that the client should prompt the - user to save the content regardless of the content type. - See \l {RFC 2616 section 19.5.1} for details. - \value WebEngineDownloadItem.DownloadAttribute The user clicked a link with the \c download - attribute. - \value WebEngineDownloadItem.UserRequested The user initiated the download, for example by - selecting a web action. - \value WebEngineDownloadItem.SavePage Saving of the current page was requested (for example by - the \l{WebEngineView::WebAction}{WebEngineView.SavePage} web action). - -*/ - -QQuickWebEngineDownloadItem::DownloadType QQuickWebEngineDownloadItem::type() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->type; -} - -/*! - \qmlproperty bool WebEngineDownloadItem::isSavePageDownload - \readonly - \since QtWebEngine 1.7 - - Whether this is a download request for saving a web page or a file. - - \sa savePageFormat -*/ -bool QQuickWebEngineDownloadItem::isSavePageDownload() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->type == QQuickWebEngineDownloadItem::SavePage; -} - -/*! - \qmlproperty enumeration WebEngineDownloadItem::interruptReason - \readonly - \since QtWebEngine 1.5 - - Returns the reason why the download was interrupted: - - \value WebEngineDownloadItem.NoReason Unknown reason or not interrupted. - \value WebEngineDownloadItem.FileFailed General file operation failure. - \value WebEngineDownloadItem.FileAccessDenied The file cannot be written locally, due to access restrictions. - \value WebEngineDownloadItem.FileNoSpace Insufficient space on the target drive. - \value WebEngineDownloadItem.FileNameTooLong The directory or file name is too long. - \value WebEngineDownloadItem.FileTooLarge The file size exceeds the file system limitation. - \value WebEngineDownloadItem.FileVirusInfected The file is infected with a virus. - \value WebEngineDownloadItem.FileTransientError Temporary problem (for example the file is in use, - out of memory, or too many files are opened at once). - \value WebEngineDownloadItem.FileBlocked The file was blocked due to local policy. - \value WebEngineDownloadItem.FileSecurityCheckFailed An attempt to check the safety of the download - failed due to unexpected reasons. - \value WebEngineDownloadItem.FileTooShort An attempt was made to seek past the end of a file when - opening a file (as part of resuming a previously interrupted download). - \value WebEngineDownloadItem.FileHashMismatch The partial file did not match the expected hash. - - \value WebEngineDownloadItem.NetworkFailed General network failure. - \value WebEngineDownloadItem.NetworkTimeout The network operation has timed out. - \value WebEngineDownloadItem.NetworkDisconnected The network connection has been terminated. - \value WebEngineDownloadItem.NetworkServerDown The server has gone down. - \value WebEngineDownloadItem.NetworkInvalidRequest The network request was invalid (for example, the - original or redirected URL is invalid, has an unsupported scheme, or is disallowed by policy). - - \value WebEngineDownloadItem.ServerFailed General server failure. - \value WebEngineDownloadItem.ServerBadContent The server does not have the requested data. - \value WebEngineDownloadItem.ServerUnauthorized The server did not authorize access to the resource. - \value WebEngineDownloadItem.ServerCertProblem A problem with the server certificate occurred. - \value WebEngineDownloadItem.ServerForbidden Access forbidden by the server. - \value WebEngineDownloadItem.ServerUnreachable Unexpected server response (might indicate that - the responding server may not be the intended server). - \value WebEngineDownloadItem.UserCanceled The user canceled the download. - - \sa interruptReasonString -*/ - -QQuickWebEngineDownloadItem::DownloadInterruptReason QQuickWebEngineDownloadItem::interruptReason() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->interruptReason; -} - -/*! - \qmlproperty string WebEngineDownloadItem::interruptReasonString - Returns a human-readable description of the reason for interrupting the download. - \since QtWebEngine 1.5 - - \sa interruptReason -*/ -QString QQuickWebEngineDownloadItem::interruptReasonString() const -{ - return ProfileAdapterClient::downloadInterruptReasonToString( - static_cast<ProfileAdapterClient::DownloadInterruptReason>(interruptReason())); -} - -/*! - \qmlproperty bool WebEngineDownloadItem::isFinished - \readonly - \since QtWebEngine 1.6 - - Whether this download is finished (completed, cancelled, or non-resumable interrupted state). - */ - -bool QQuickWebEngineDownloadItem::isFinished() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadFinished; -} - -/*! - \qmlproperty bool WebEngineDownloadItem::isPaused - \readonly - \since QtWebEngine 1.6 - - Whether this download is paused. - - \sa pause, resume - */ - -bool QQuickWebEngineDownloadItem::isPaused() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->downloadPaused; -} - -/*! - \qmlproperty WebEngineView WebEngineDownloadItem::view - \readonly - \since QtWebEngine 1.8 - - Returns the view the download was requested on. If the download was not triggered by content in a view, - \c nullptr is returned. - - \sa WebEngineView -*/ -QQuickWebEngineView *QQuickWebEngineDownloadItem::view() const -{ - Q_D(const QQuickWebEngineDownloadItem); - return d->view; -} - -QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate *p, QObject *parent) - : QObject(parent) - , d_ptr(p) -{ - p->q_ptr = this; -} - -QQuickWebEngineDownloadItem::~QQuickWebEngineDownloadItem() -{ - if (!isFinished()) - cancel(); -} - -QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h deleted file mode 100644 index e1b1b9040..000000000 --- a/src/webengine/api/qquickwebenginedownloaditem_p.h +++ /dev/null @@ -1,199 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKWEBENGINEDOWNLOADITEM_P_H -#define QQUICKWEBENGINEDOWNLOADITEM_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtWebEngine/private/qtwebengineglobal_p.h> -#include <QObject> -#include <QScopedPointer> -#include <QString> -#include <QUrl> - -QT_BEGIN_NAMESPACE - -class QQuickWebEngineDownloadItemPrivate; -class QQuickWebEngineProfilePrivate; -class QQuickWebEngineView; - -class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineDownloadItem: public QObject { - Q_OBJECT -public: - ~QQuickWebEngineDownloadItem(); - enum DownloadState { - DownloadRequested, - DownloadInProgress, - DownloadCompleted, - DownloadCancelled, - DownloadInterrupted - }; - Q_ENUM(DownloadState) - - enum SavePageFormat { - UnknownSaveFormat = -1, - SingleHtmlSaveFormat, - CompleteHtmlSaveFormat, - MimeHtmlSaveFormat - }; - Q_ENUM(SavePageFormat) - - enum DownloadInterruptReason { - NoReason = 0, - FileFailed = 1, - FileAccessDenied = 2, - FileNoSpace = 3, - FileNameTooLong = 5, - FileTooLarge = 6, - FileVirusInfected = 7, - FileTransientError = 10, - FileBlocked = 11, - FileSecurityCheckFailed = 12, - FileTooShort = 13, - FileHashMismatch = 14, - NetworkFailed = 20, - NetworkTimeout = 21, - NetworkDisconnected = 22, - NetworkServerDown = 23, - NetworkInvalidRequest = 24, - ServerFailed = 30, - //ServerNoRange = 31, - ServerBadContent = 33, - ServerUnauthorized = 34, - ServerCertProblem = 35, - ServerForbidden = 36, - ServerUnreachable = 37, - UserCanceled = 40, - //UserShutdown = 41, - //Crash = 50 - }; - Q_ENUM(DownloadInterruptReason) - - enum DownloadType { - Attachment = 0, - DownloadAttribute, - UserRequested, - SavePage - }; - Q_ENUM(DownloadType) - - Q_PROPERTY(quint32 id READ id CONSTANT FINAL) - Q_PROPERTY(DownloadState state READ state NOTIFY stateChanged FINAL) - Q_PROPERTY(SavePageFormat savePageFormat READ savePageFormat WRITE setSavePageFormat NOTIFY savePageFormatChanged REVISION 2 FINAL) - Q_PROPERTY(qint64 totalBytes READ totalBytes NOTIFY totalBytesChanged FINAL) - Q_PROPERTY(qint64 receivedBytes READ receivedBytes NOTIFY receivedBytesChanged FINAL) - Q_PROPERTY(QString mimeType READ mimeType NOTIFY mimeTypeChanged REVISION 1 FINAL) - Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL) - Q_PROPERTY(DownloadType type READ type NOTIFY typeChanged REVISION 3 FINAL) - Q_PROPERTY(DownloadInterruptReason interruptReason READ interruptReason NOTIFY interruptReasonChanged REVISION 4 FINAL) - Q_PROPERTY(QString interruptReasonString READ interruptReasonString NOTIFY interruptReasonChanged REVISION 4 FINAL) - Q_PROPERTY(bool isFinished READ isFinished NOTIFY isFinishedChanged REVISION 5 FINAL) - Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged REVISION 5 FINAL) - Q_PROPERTY(bool isSavePageDownload READ isSavePageDownload CONSTANT REVISION 6 FINAL) - Q_PROPERTY(QQuickWebEngineView *view READ view CONSTANT REVISION 7 FINAL) - Q_PROPERTY(QUrl url READ url CONSTANT REVISION 10 FINAL) - Q_PROPERTY(QString suggestedFileName READ suggestedFileName CONSTANT REVISION 10 FINAL) - Q_PROPERTY(QString downloadDirectory READ downloadDirectory WRITE setDownloadDirectory NOTIFY downloadDirectoryChanged REVISION 10 FINAL) - Q_PROPERTY(QString downloadFileName READ downloadFileName WRITE setDownloadFileName NOTIFY downloadFileNameChanged REVISION 10 FINAL) - - Q_INVOKABLE void accept(); - Q_INVOKABLE void cancel(); - Q_INVOKABLE void pause(); - Q_INVOKABLE void resume(); - - quint32 id() const; - DownloadState state() const; - qint64 totalBytes() const; - qint64 receivedBytes() const; - QString mimeType() const; - QString path() const; - void setPath(QString path); - SavePageFormat savePageFormat() const; - void setSavePageFormat(SavePageFormat format); - DownloadType Q_DECL_DEPRECATED type() const; - DownloadInterruptReason interruptReason() const; - QString interruptReasonString() const; - bool isFinished() const; - bool isPaused() const; - bool isSavePageDownload() const; - QQuickWebEngineView *view() const; - QUrl url() const; - QString suggestedFileName() const; - QString downloadDirectory() const; - void setDownloadDirectory(const QString &directory); - QString downloadFileName() const; - void setDownloadFileName(const QString &fileName); - bool isCustomFileName; - -Q_SIGNALS: - void stateChanged(); - Q_REVISION(2) void savePageFormatChanged(); - void receivedBytesChanged(); - void totalBytesChanged(); - Q_REVISION(1) void mimeTypeChanged(); - void pathChanged(); - Q_REVISION(3) void typeChanged(); - Q_REVISION(4) void interruptReasonChanged(); - Q_REVISION(5) void isFinishedChanged(); - Q_REVISION(5) void isPausedChanged(); - Q_REVISION(10) void downloadDirectoryChanged(); - Q_REVISION(10) void downloadFileNameChanged(); - -private: - QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate*, QObject *parent = 0); - Q_DISABLE_COPY(QQuickWebEngineDownloadItem) - Q_DECLARE_PRIVATE(QQuickWebEngineDownloadItem) - friend class QQuickWebEngineProfilePrivate; - - QScopedPointer<QQuickWebEngineDownloadItemPrivate> d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QQUICKWEBENGINEDOWNLOADITEM_P_H diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h deleted file mode 100644 index acd7fe806..000000000 --- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKWEBENGINEDOWNLOADITEM_P_P_H -#define QQUICKWEBENGINEDOWNLOADITEM_P_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "profile_adapter_client.h" -#include "qquickwebenginedownloaditem_p.h" -#include "qquickwebengineprofile.h" -#include <QString> -#include <QPointer> - -QT_BEGIN_NAMESPACE -class QQuickWebEngineProfilePrivate; -class QQuickWebEngineView; - -class QQuickWebEngineDownloadItemPrivate { - QQuickWebEngineDownloadItem *q_ptr; - QPointer<QQuickWebEngineProfile> profile; - friend class QQuickWebEngineProfilePrivate; -public: - Q_DECLARE_PUBLIC(QQuickWebEngineDownloadItem) - QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfile *p, const QUrl &url); - ~QQuickWebEngineDownloadItemPrivate(); - - quint32 downloadId; - qint64 startTime; - QQuickWebEngineDownloadItem::DownloadState downloadState; - QQuickWebEngineDownloadItem::SavePageFormat savePageFormat; - QQuickWebEngineDownloadItem::DownloadType type; - QQuickWebEngineDownloadItem::DownloadInterruptReason interruptReason; - qint64 totalBytes; - qint64 receivedBytes; - QString mimeType; - QString downloadPath; - bool downloadFinished; - bool downloadPaused; - QQuickWebEngineView *view; - QUrl downloadUrl; - QString suggestedFileName; - QString downloadDirectory; - QString downloadFileName; - bool isCustomFileName; - - void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info); - void updateState(QQuickWebEngineDownloadItem::DownloadState newState); - void setFinished(); -}; - -QT_END_NAMESPACE - -#endif // QQUICKWEBENGINEDOWNLOADITEM_P_P_H diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 834bb6a05..2bea21115 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -39,8 +39,6 @@ #include "qquickwebengineprofile.h" -#include "qquickwebenginedownloaditem_p.h" -#include "qquickwebenginedownloaditem_p_p.h" #include "qquickwebengineprofile_p.h" #include "qquickwebenginescript_p.h" #include "qquickwebenginesettings_p.h" @@ -56,17 +54,13 @@ #include "renderer_host/user_resource_controller_host.h" #include "web_engine_settings.h" +#include <QtWebEngineCore/private/qwebenginedownloadrequest_p.h> #include <QtWebEngineCore/qwebengineurlscheme.h> using QtWebEngineCore::ProfileAdapter; QT_BEGIN_NAMESPACE -ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::UnknownSaveFormat, QtWebEngineCore::ProfileAdapterClient::UnknownSavePageFormat) -ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngineCore::ProfileAdapterClient::SingleHtmlSaveFormat) -ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::ProfileAdapterClient::CompleteHtmlSaveFormat) -ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::ProfileAdapterClient::MimeHtmlSaveFormat) - /*! \class QQuickWebEngineProfile \brief The QQuickWebEngineProfile class provides a web engine profile shared by multiple pages. @@ -133,12 +127,12 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC */ /*! - \fn QQuickWebEngineProfile::downloadRequested(QQuickWebEngineDownloadItem *download) + \fn QQuickWebEngineProfile::downloadRequested(QWebEngineDownloadRequest *download) This signal is emitted whenever a download has been triggered. The \a download argument holds the state of the download. The download has to be explicitly accepted with - \c{QQuickWebEngineDownloadItem::accept()} or it will be + \c{QWebEngineDownloadRequest::accept()} or it will be cancelled by default. The download item is parented by the profile. If it is not accepted, it will be deleted immediately after the signal emission. @@ -146,7 +140,7 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC */ /*! - \fn QQuickWebEngineProfile::downloadFinished(QQuickWebEngineDownloadItem *download) + \fn QQuickWebEngineProfile::downloadFinished(QWebEngineDownloadRequest *download) This signal is emitted whenever downloading stops, because it finished successfully, was cancelled, or was interrupted (for example, because connectivity was lost). @@ -168,10 +162,9 @@ QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(ProfileAdapter *pro , m_profileAdapter(profileAdapter) { profileAdapter->addClient(this); - m_settings->d_ptr->initDefaults(); // Fullscreen API was implemented before the supported setting, so we must // make it default true to avoid change in default API behavior. - m_settings->d_ptr->setAttribute(QtWebEngineCore::WebEngineSettings::FullScreenSupportEnabled, true); + m_settings->d_ptr->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); } QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate() @@ -242,38 +235,38 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) Q_Q(QQuickWebEngineProfile); Q_ASSERT(!m_ongoingDownloads.contains(info.id)); - QQuickWebEngineDownloadItemPrivate *itemPrivate = new QQuickWebEngineDownloadItemPrivate(q, info.url); + QWebEngineDownloadRequestPrivate *itemPrivate = new QWebEngineDownloadRequestPrivate(m_profileAdapter, info.url); itemPrivate->downloadId = info.id; - itemPrivate->downloadState = QQuickWebEngineDownloadItem::DownloadRequested; + itemPrivate->downloadState = QWebEngineDownloadRequest::DownloadRequested; itemPrivate->startTime = info.startTime; itemPrivate->totalBytes = info.totalBytes; itemPrivate->mimeType = info.mimeType; itemPrivate->downloadDirectory = QFileInfo(info.path).path(); itemPrivate->downloadFileName = QFileInfo(info.path).fileName(); itemPrivate->suggestedFileName = info.suggestedFileName; - itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>( + itemPrivate->savePageFormat = static_cast<QWebEngineDownloadRequest::SavePageFormat>( info.savePageFormat); - itemPrivate->type = static_cast<QQuickWebEngineDownloadItem::DownloadType>(info.downloadType); + itemPrivate->isSavePageDownload = info.isSavePageDownload; if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::QmlClient) - itemPrivate->view = static_cast<QQuickWebEngineViewPrivate *>(info.page)->q_ptr; + itemPrivate->page = static_cast<QQuickWebEngineViewPrivate *>(info.page)->q_ptr; else - itemPrivate->view = nullptr; + itemPrivate->page = nullptr; - QQuickWebEngineDownloadItem *download = new QQuickWebEngineDownloadItem(itemPrivate, q); + QWebEngineDownloadRequest *download = new QWebEngineDownloadRequest(itemPrivate, q); m_ongoingDownloads.insert(info.id, download); - QObject::connect(download, &QQuickWebEngineDownloadItem::destroyed, q, [id = info.id, this] () { downloadDestroyed(id); }); + QObject::connect(download, &QWebEngineDownloadRequest::destroyed, q, [id = info.id, this] () { downloadDestroyed(id); }); QQmlEngine::setObjectOwnership(download, QQmlEngine::JavaScriptOwnership); Q_EMIT q->downloadRequested(download); - QQuickWebEngineDownloadItem::DownloadState state = download->state(); + QWebEngineDownloadRequest::DownloadState state = download->state(); info.path = QDir(download->downloadDirectory()).filePath(download->downloadFileName()); info.savePageFormat = itemPrivate->savePageFormat; - info.accepted = state != QQuickWebEngineDownloadItem::DownloadCancelled - && state != QQuickWebEngineDownloadItem::DownloadRequested; + info.accepted = state != QWebEngineDownloadRequest::DownloadCancelled + && state != QWebEngineDownloadRequest::DownloadRequested; - if (state == QQuickWebEngineDownloadItem::DownloadRequested) { + if (state == QWebEngineDownloadRequest::DownloadRequested) { // Delete unaccepted downloads. info.accepted = false; delete download; @@ -287,7 +280,7 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info Q_Q(QQuickWebEngineProfile); - QQuickWebEngineDownloadItem* download = m_ongoingDownloads.value(info.id).data(); + QWebEngineDownloadRequest* download = m_ongoingDownloads.value(info.id).data(); if (!download) { downloadDestroyed(info.id); diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h index e5f7ff713..ca90d7ae8 100644 --- a/src/webengine/api/qquickwebengineprofile.h +++ b/src/webengine/api/qquickwebengineprofile.h @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE -class QQuickWebEngineDownloadItem; +class QWebEngineDownloadRequest; class QQuickWebEngineProfilePrivate; class QQuickWebEngineScript; class QQuickWebEngineSettings; @@ -173,8 +173,8 @@ Q_SIGNALS: Q_REVISION(5) void useForGlobalCertificateVerificationChanged(); Q_REVISION(5) void downloadPathChanged(); - void downloadRequested(QQuickWebEngineDownloadItem *download); - void downloadFinished(QQuickWebEngineDownloadItem *download); + void downloadRequested(QWebEngineDownloadRequest *download); + void downloadFinished(QWebEngineDownloadRequest *download); Q_REVISION(5) void presentNotification(QWebEngineNotification *notification); @@ -186,8 +186,6 @@ private: friend class QQuickWebEngineSettings; friend class QQuickWebEngineSingleton; friend class QQuickWebEngineViewPrivate; - friend class QQuickWebEngineDownloadItem; - friend class QQuickWebEngineDownloadItemPrivate; friend class QQuickWebEngineView; QScopedPointer<QQuickWebEngineProfilePrivate> d_ptr; }; diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h index c6d412ab3..f1fd93543 100644 --- a/src/webengine/api/qquickwebengineprofile_p.h +++ b/src/webengine/api/qquickwebengineprofile_p.h @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -class QQuickWebEngineDownloadItem; +class QWebEngineDownloadRequest; class QQuickWebEngineSettings; class QQuickWebEngineViewPrivate; @@ -100,7 +100,7 @@ private: QQuickWebEngineProfile *q_ptr; QScopedPointer<QQuickWebEngineSettings> m_settings; QPointer<QtWebEngineCore::ProfileAdapter> m_profileAdapter; - QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads; + QMap<quint32, QPointer<QWebEngineDownloadRequest> > m_ongoingDownloads; QList<QQuickWebEngineScript *> m_userScripts; }; diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp index 78fbe16e8..8728cc51a 100644 --- a/src/webengine/api/qquickwebenginesettings.cpp +++ b/src/webengine/api/qquickwebenginesettings.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE using QtWebEngineCore::WebEngineSettings; QQuickWebEngineSettings::QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings) - : d_ptr(new WebEngineSettings(parentSettings ? parentSettings->d_ptr.data() : 0)) + : d_ptr(new QWebEngineSettings(parentSettings ? parentSettings->d_ptr.data() : nullptr)) { } /*! @@ -97,7 +97,7 @@ QQuickWebEngineSettings::~QQuickWebEngineSettings() */ bool QQuickWebEngineSettings::autoLoadImages() const { - return d_ptr->testAttribute(WebEngineSettings::AutoLoadImages); + return d_ptr->testAttribute(QWebEngineSettings::AutoLoadImages); } /*! @@ -109,7 +109,7 @@ bool QQuickWebEngineSettings::autoLoadImages() const */ bool QQuickWebEngineSettings::javascriptEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::JavascriptEnabled); + return d_ptr->testAttribute(QWebEngineSettings::JavascriptEnabled); } /*! @@ -121,7 +121,7 @@ bool QQuickWebEngineSettings::javascriptEnabled() const */ bool QQuickWebEngineSettings::javascriptCanOpenWindows() const { - return d_ptr->testAttribute(WebEngineSettings::JavascriptCanOpenWindows); + return d_ptr->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows); } /*! @@ -137,7 +137,7 @@ bool QQuickWebEngineSettings::javascriptCanOpenWindows() const */ bool QQuickWebEngineSettings::javascriptCanAccessClipboard() const { - return d_ptr->testAttribute(WebEngineSettings::JavascriptCanAccessClipboard); + return d_ptr->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard); } /*! @@ -149,7 +149,7 @@ bool QQuickWebEngineSettings::javascriptCanAccessClipboard() const */ bool QQuickWebEngineSettings::linksIncludedInFocusChain() const { - return d_ptr->testAttribute(WebEngineSettings::LinksIncludedInFocusChain); + return d_ptr->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain); } /*! @@ -161,7 +161,7 @@ bool QQuickWebEngineSettings::linksIncludedInFocusChain() const */ bool QQuickWebEngineSettings::localStorageEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::LocalStorageEnabled); + return d_ptr->testAttribute(QWebEngineSettings::LocalStorageEnabled); } /*! @@ -173,7 +173,7 @@ bool QQuickWebEngineSettings::localStorageEnabled() const */ bool QQuickWebEngineSettings::localContentCanAccessRemoteUrls() const { - return d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls); + return d_ptr->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls); } /*! @@ -191,7 +191,7 @@ bool QQuickWebEngineSettings::localContentCanAccessRemoteUrls() const */ bool QQuickWebEngineSettings::spatialNavigationEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::SpatialNavigationEnabled); + return d_ptr->testAttribute(QWebEngineSettings::SpatialNavigationEnabled); } /*! @@ -203,7 +203,7 @@ bool QQuickWebEngineSettings::spatialNavigationEnabled() const */ bool QQuickWebEngineSettings::localContentCanAccessFileUrls() const { - return d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessFileUrls); + return d_ptr->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls); } /*! @@ -215,7 +215,7 @@ bool QQuickWebEngineSettings::localContentCanAccessFileUrls() const */ bool QQuickWebEngineSettings::hyperlinkAuditingEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::HyperlinkAuditingEnabled); + return d_ptr->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled); } /*! @@ -227,7 +227,7 @@ bool QQuickWebEngineSettings::hyperlinkAuditingEnabled() const */ bool QQuickWebEngineSettings::errorPageEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::ErrorPageEnabled); + return d_ptr->testAttribute(QWebEngineSettings::ErrorPageEnabled); } /*! @@ -241,7 +241,7 @@ bool QQuickWebEngineSettings::errorPageEnabled() const */ bool QQuickWebEngineSettings::pluginsEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::PluginsEnabled); + return d_ptr->testAttribute(QWebEngineSettings::PluginsEnabled); } /*! @@ -254,7 +254,7 @@ bool QQuickWebEngineSettings::pluginsEnabled() const */ bool QQuickWebEngineSettings::fullScreenSupportEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::FullScreenSupportEnabled); + return d_ptr->testAttribute(QWebEngineSettings::FullScreenSupportEnabled); } /*! @@ -267,7 +267,7 @@ bool QQuickWebEngineSettings::fullScreenSupportEnabled() const */ bool QQuickWebEngineSettings::screenCaptureEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::ScreenCaptureEnabled); + return d_ptr->testAttribute(QWebEngineSettings::ScreenCaptureEnabled); } /*! @@ -280,7 +280,7 @@ bool QQuickWebEngineSettings::screenCaptureEnabled() const */ bool QQuickWebEngineSettings::webGLEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::WebGLEnabled); + return d_ptr->testAttribute(QWebEngineSettings::WebGLEnabled); } /*! @@ -294,7 +294,7 @@ bool QQuickWebEngineSettings::webGLEnabled() const */ bool QQuickWebEngineSettings::accelerated2dCanvasEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::Accelerated2dCanvasEnabled); + return d_ptr->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled); } /*! @@ -307,7 +307,7 @@ bool QQuickWebEngineSettings::accelerated2dCanvasEnabled() const */ bool QQuickWebEngineSettings::autoLoadIconsForPage() const { - return d_ptr->testAttribute(WebEngineSettings::AutoLoadIconsForPage); + return d_ptr->testAttribute(QWebEngineSettings::AutoLoadIconsForPage); } /*! @@ -320,7 +320,7 @@ bool QQuickWebEngineSettings::autoLoadIconsForPage() const */ bool QQuickWebEngineSettings::touchIconsEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::TouchIconsEnabled); + return d_ptr->testAttribute(QWebEngineSettings::TouchIconsEnabled); } /*! @@ -334,7 +334,7 @@ bool QQuickWebEngineSettings::touchIconsEnabled() const */ bool QQuickWebEngineSettings::focusOnNavigationEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::FocusOnNavigationEnabled); + return d_ptr->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled); } /*! @@ -347,7 +347,7 @@ bool QQuickWebEngineSettings::focusOnNavigationEnabled() const */ bool QQuickWebEngineSettings::printElementBackgrounds() const { - return d_ptr->testAttribute(WebEngineSettings::PrintElementBackgrounds); + return d_ptr->testAttribute(QWebEngineSettings::PrintElementBackgrounds); } /*! @@ -362,7 +362,7 @@ bool QQuickWebEngineSettings::printElementBackgrounds() const */ bool QQuickWebEngineSettings::allowRunningInsecureContent() const { - return d_ptr->testAttribute(WebEngineSettings::AllowRunningInsecureContent); + return d_ptr->testAttribute(QWebEngineSettings::AllowRunningInsecureContent); } /*! @@ -377,7 +377,7 @@ bool QQuickWebEngineSettings::allowRunningInsecureContent() const */ bool QQuickWebEngineSettings::allowGeolocationOnInsecureOrigins() const { - return d_ptr->testAttribute(WebEngineSettings::AllowGeolocationOnInsecureOrigins); + return d_ptr->testAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins); } /*! @@ -387,7 +387,7 @@ bool QQuickWebEngineSettings::allowGeolocationOnInsecureOrigins() const */ bool QQuickWebEngineSettings::allowWindowActivationFromJavaScript() const { - return d_ptr->testAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript); + return d_ptr->testAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript); } /*! @@ -397,7 +397,7 @@ bool QQuickWebEngineSettings::allowWindowActivationFromJavaScript() const */ bool QQuickWebEngineSettings::showScrollBars() const { - return d_ptr->testAttribute(WebEngineSettings::ShowScrollBars); + return d_ptr->testAttribute(QWebEngineSettings::ShowScrollBars); } /*! @@ -415,7 +415,7 @@ bool QQuickWebEngineSettings::showScrollBars() const */ bool QQuickWebEngineSettings::playbackRequiresUserGesture() const { - return d_ptr->testAttribute(WebEngineSettings::PlaybackRequiresUserGesture); + return d_ptr->testAttribute(QWebEngineSettings::PlaybackRequiresUserGesture); } /*! @@ -429,7 +429,7 @@ bool QQuickWebEngineSettings::playbackRequiresUserGesture() const */ bool QQuickWebEngineSettings::webRTCPublicInterfacesOnly() const { - return d_ptr->testAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly); + return d_ptr->testAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly); } /*! @@ -443,7 +443,7 @@ bool QQuickWebEngineSettings::webRTCPublicInterfacesOnly() const */ bool QQuickWebEngineSettings::javascriptCanPaste() const { - return d_ptr->testAttribute(WebEngineSettings::JavascriptCanPaste); + return d_ptr->testAttribute(QWebEngineSettings::JavascriptCanPaste); } /*! @@ -457,7 +457,7 @@ bool QQuickWebEngineSettings::javascriptCanPaste() const */ bool QQuickWebEngineSettings::dnsPrefetchEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::DnsPrefetchEnabled); + return d_ptr->testAttribute(QWebEngineSettings::DnsPrefetchEnabled); } /*! @@ -471,7 +471,7 @@ bool QQuickWebEngineSettings::dnsPrefetchEnabled() const */ bool QQuickWebEngineSettings::pdfViewerEnabled() const { - return d_ptr->testAttribute(WebEngineSettings::PdfViewerEnabled); + return d_ptr->testAttribute(QWebEngineSettings::PdfViewerEnabled); } /*! @@ -488,12 +488,12 @@ QString QQuickWebEngineSettings::defaultTextEncoding() const return d_ptr->defaultTextEncoding(); } -ASSERT_ENUMS_MATCH(QQuickWebEngineSettings::DisallowUnknownUrlSchemes, WebEngineSettings::DisallowUnknownUrlSchemes) -ASSERT_ENUMS_MATCH(QQuickWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction, WebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction) -ASSERT_ENUMS_MATCH(QQuickWebEngineSettings::AllowAllUnknownUrlSchemes, WebEngineSettings::AllowAllUnknownUrlSchemes) +ASSERT_ENUMS_MATCH(QQuickWebEngineSettings::DisallowUnknownUrlSchemes, QWebEngineSettings::DisallowUnknownUrlSchemes) +ASSERT_ENUMS_MATCH(QQuickWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction, QWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction) +ASSERT_ENUMS_MATCH(QQuickWebEngineSettings::AllowAllUnknownUrlSchemes, QWebEngineSettings::AllowAllUnknownUrlSchemes) /*! - \qmlproperty WebEngineSettings::UnknownUrlSchemePolicy WebEngineSettings::unknownUrlSchemePolicy + \qmlproperty QWebEngineSettings::UnknownUrlSchemePolicy WebEngineSettings::unknownUrlSchemePolicy \since QtWebEngine 1.7 Specifies how navigation requests to URLs with unknown schemes are handled. @@ -506,58 +506,58 @@ QQuickWebEngineSettings::UnknownUrlSchemePolicy QQuickWebEngineSettings::unknown void QQuickWebEngineSettings::setAutoLoadImages(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::AutoLoadImages); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::AutoLoadImages); // Set unconditionally as it sets the override for the current settings while the current setting // could be from the fallback and is prone to changing later on. - d_ptr->setAttribute(WebEngineSettings::AutoLoadImages, on); + d_ptr->setAttribute(QWebEngineSettings::AutoLoadImages, on); if (wasOn != on) Q_EMIT autoLoadImagesChanged(); } void QQuickWebEngineSettings::setJavascriptEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptEnabled); - d_ptr->setAttribute(WebEngineSettings::JavascriptEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::JavascriptEnabled); + d_ptr->setAttribute(QWebEngineSettings::JavascriptEnabled, on); if (wasOn != on) Q_EMIT javascriptEnabledChanged(); } void QQuickWebEngineSettings::setJavascriptCanOpenWindows(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptCanOpenWindows); - d_ptr->setAttribute(WebEngineSettings::JavascriptCanOpenWindows, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows); + d_ptr->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, on); if (wasOn != on) Q_EMIT javascriptCanOpenWindowsChanged(); } void QQuickWebEngineSettings::setJavascriptCanAccessClipboard(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptCanAccessClipboard); - d_ptr->setAttribute(WebEngineSettings::JavascriptCanAccessClipboard, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard); + d_ptr->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, on); if (wasOn != on) Q_EMIT javascriptCanAccessClipboardChanged(); } void QQuickWebEngineSettings::setLinksIncludedInFocusChain(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::LinksIncludedInFocusChain); - d_ptr->setAttribute(WebEngineSettings::LinksIncludedInFocusChain, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain); + d_ptr->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain, on); if (wasOn != on) Q_EMIT linksIncludedInFocusChainChanged(); } void QQuickWebEngineSettings::setLocalStorageEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::LocalStorageEnabled); - d_ptr->setAttribute(WebEngineSettings::LocalStorageEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::LocalStorageEnabled); + d_ptr->setAttribute(QWebEngineSettings::LocalStorageEnabled, on); if (wasOn != on) Q_EMIT localStorageEnabledChanged(); } void QQuickWebEngineSettings::setLocalContentCanAccessRemoteUrls(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls); - d_ptr->setAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls); + d_ptr->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, on); if (wasOn != on) Q_EMIT localContentCanAccessRemoteUrlsChanged(); } @@ -565,96 +565,96 @@ void QQuickWebEngineSettings::setLocalContentCanAccessRemoteUrls(bool on) void QQuickWebEngineSettings::setSpatialNavigationEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::SpatialNavigationEnabled); - d_ptr->setAttribute(WebEngineSettings::SpatialNavigationEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::SpatialNavigationEnabled); + d_ptr->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, on); if (wasOn != on) Q_EMIT spatialNavigationEnabledChanged(); } void QQuickWebEngineSettings::setLocalContentCanAccessFileUrls(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessFileUrls); - d_ptr->setAttribute(WebEngineSettings::LocalContentCanAccessFileUrls, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls); + d_ptr->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, on); if (wasOn != on) Q_EMIT localContentCanAccessFileUrlsChanged(); } void QQuickWebEngineSettings::setHyperlinkAuditingEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::HyperlinkAuditingEnabled); - d_ptr->setAttribute(WebEngineSettings::HyperlinkAuditingEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled); + d_ptr->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, on); if (wasOn != on) Q_EMIT hyperlinkAuditingEnabledChanged(); } void QQuickWebEngineSettings::setErrorPageEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::ErrorPageEnabled); - d_ptr->setAttribute(WebEngineSettings::ErrorPageEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::ErrorPageEnabled); + d_ptr->setAttribute(QWebEngineSettings::ErrorPageEnabled, on); if (wasOn != on) Q_EMIT errorPageEnabledChanged(); } void QQuickWebEngineSettings::setPluginsEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::PluginsEnabled); - d_ptr->setAttribute(WebEngineSettings::PluginsEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::PluginsEnabled); + d_ptr->setAttribute(QWebEngineSettings::PluginsEnabled, on); if (wasOn != on) Q_EMIT pluginsEnabledChanged(); } void QQuickWebEngineSettings::setFullScreenSupportEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::FullScreenSupportEnabled); - d_ptr->setAttribute(WebEngineSettings::FullScreenSupportEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::FullScreenSupportEnabled); + d_ptr->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, on); if (wasOn != on) Q_EMIT fullScreenSupportEnabledChanged(); } void QQuickWebEngineSettings::setScreenCaptureEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::ScreenCaptureEnabled); - d_ptr->setAttribute(WebEngineSettings::ScreenCaptureEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::ScreenCaptureEnabled); + d_ptr->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, on); if (wasOn != on) Q_EMIT screenCaptureEnabledChanged(); } void QQuickWebEngineSettings::setWebGLEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::WebGLEnabled); - d_ptr->setAttribute(WebEngineSettings::WebGLEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::WebGLEnabled); + d_ptr->setAttribute(QWebEngineSettings::WebGLEnabled, on); if (wasOn != on) Q_EMIT webGLEnabledChanged(); } void QQuickWebEngineSettings::setAccelerated2dCanvasEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::Accelerated2dCanvasEnabled); - d_ptr->setAttribute(WebEngineSettings::Accelerated2dCanvasEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled); + d_ptr->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, on); if (wasOn != on) Q_EMIT accelerated2dCanvasEnabledChanged(); } void QQuickWebEngineSettings::setAutoLoadIconsForPage(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::AutoLoadIconsForPage); - d_ptr->setAttribute(WebEngineSettings::AutoLoadIconsForPage, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::AutoLoadIconsForPage); + d_ptr->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, on); if (wasOn != on) Q_EMIT autoLoadIconsForPageChanged(); } void QQuickWebEngineSettings::setTouchIconsEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::TouchIconsEnabled); - d_ptr->setAttribute(WebEngineSettings::TouchIconsEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::TouchIconsEnabled); + d_ptr->setAttribute(QWebEngineSettings::TouchIconsEnabled, on); if (wasOn != on) Q_EMIT touchIconsEnabledChanged(); } void QQuickWebEngineSettings::setPrintElementBackgrounds(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::PrintElementBackgrounds); - d_ptr->setAttribute(WebEngineSettings::PrintElementBackgrounds, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::PrintElementBackgrounds); + d_ptr->setAttribute(QWebEngineSettings::PrintElementBackgrounds, on); if (wasOn != on) Q_EMIT printElementBackgroundsChanged(); } @@ -669,8 +669,8 @@ void QQuickWebEngineSettings::setDefaultTextEncoding(QString encoding) void QQuickWebEngineSettings::setFocusOnNavigationEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::FocusOnNavigationEnabled); - d_ptr->setAttribute(WebEngineSettings::FocusOnNavigationEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled); + d_ptr->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, on); if (wasOn != on) Q_EMIT focusOnNavigationEnabledChanged(); } @@ -678,72 +678,72 @@ void QQuickWebEngineSettings::setFocusOnNavigationEnabled(bool on) void QQuickWebEngineSettings::setAllowRunningInsecureContent(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::AllowRunningInsecureContent); - d_ptr->setAttribute(WebEngineSettings::AllowRunningInsecureContent, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::AllowRunningInsecureContent); + d_ptr->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, on); if (wasOn != on) Q_EMIT allowRunningInsecureContentChanged(); } void QQuickWebEngineSettings::setAllowGeolocationOnInsecureOrigins(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::AllowGeolocationOnInsecureOrigins); - d_ptr->setAttribute(WebEngineSettings::AllowGeolocationOnInsecureOrigins, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins); + d_ptr->setAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins, on); if (wasOn != on) Q_EMIT allowGeolocationOnInsecureOriginsChanged(); } void QQuickWebEngineSettings::setAllowWindowActivationFromJavaScript(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript); - d_ptr->setAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript); + d_ptr->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, on); if (wasOn != on) Q_EMIT allowWindowActivationFromJavaScriptChanged(); } void QQuickWebEngineSettings::setShowScrollBars(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::ShowScrollBars); - d_ptr->setAttribute(WebEngineSettings::ShowScrollBars, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::ShowScrollBars); + d_ptr->setAttribute(QWebEngineSettings::ShowScrollBars, on); if (wasOn != on) Q_EMIT showScrollBarsChanged(); } void QQuickWebEngineSettings::setPlaybackRequiresUserGesture(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::PlaybackRequiresUserGesture); - d_ptr->setAttribute(WebEngineSettings::PlaybackRequiresUserGesture, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::PlaybackRequiresUserGesture); + d_ptr->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, on); if (wasOn != on) Q_EMIT playbackRequiresUserGestureChanged(); } void QQuickWebEngineSettings::setJavascriptCanPaste(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptCanPaste); - d_ptr->setAttribute(WebEngineSettings::JavascriptCanPaste, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::JavascriptCanPaste); + d_ptr->setAttribute(QWebEngineSettings::JavascriptCanPaste, on); if (wasOn != on) Q_EMIT javascriptCanPasteChanged(); } void QQuickWebEngineSettings::setDnsPrefetchEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::DnsPrefetchEnabled); - d_ptr->setAttribute(WebEngineSettings::DnsPrefetchEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::DnsPrefetchEnabled); + d_ptr->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, on); if (wasOn != on) Q_EMIT dnsPrefetchEnabledChanged(); } void QQuickWebEngineSettings::setPdfViewerEnabled(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::PdfViewerEnabled); - d_ptr->setAttribute(WebEngineSettings::PdfViewerEnabled, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::PdfViewerEnabled); + d_ptr->setAttribute(QWebEngineSettings::PdfViewerEnabled, on); if (wasOn != on) Q_EMIT pdfViewerEnabledChanged(); } void QQuickWebEngineSettings::setUnknownUrlSchemePolicy(QQuickWebEngineSettings::UnknownUrlSchemePolicy policy) { - WebEngineSettings::UnknownUrlSchemePolicy oldPolicy = d_ptr->unknownUrlSchemePolicy(); - WebEngineSettings::UnknownUrlSchemePolicy newPolicy = static_cast<WebEngineSettings::UnknownUrlSchemePolicy>(policy); + QWebEngineSettings::UnknownUrlSchemePolicy oldPolicy = d_ptr->unknownUrlSchemePolicy(); + QWebEngineSettings::UnknownUrlSchemePolicy newPolicy = static_cast<QWebEngineSettings::UnknownUrlSchemePolicy>(policy); d_ptr->setUnknownUrlSchemePolicy(newPolicy); if (oldPolicy != newPolicy) Q_EMIT unknownUrlSchemePolicyChanged(); @@ -751,8 +751,8 @@ void QQuickWebEngineSettings::setUnknownUrlSchemePolicy(QQuickWebEngineSettings: void QQuickWebEngineSettings::setWebRTCPublicInterfacesOnly(bool on) { - bool wasOn = d_ptr->testAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly); - d_ptr->setAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly, on); + bool wasOn = d_ptr->testAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly); + d_ptr->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, on); if (wasOn != on) Q_EMIT webRTCPublicInterfacesOnlyChanged(); } @@ -760,7 +760,6 @@ void QQuickWebEngineSettings::setWebRTCPublicInterfacesOnly(bool on) void QQuickWebEngineSettings::setParentSettings(QQuickWebEngineSettings *parentSettings) { d_ptr->setParentSettings(parentSettings->d_ptr.data()); - d_ptr->scheduleApplyRecursively(); } QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginesettings_p.h b/src/webengine/api/qquickwebenginesettings_p.h index ce43e0e9c..20db86448 100644 --- a/src/webengine/api/qquickwebenginesettings_p.h +++ b/src/webengine/api/qquickwebenginesettings_p.h @@ -61,6 +61,7 @@ class WebEngineSettings; QT_BEGIN_NAMESPACE +class QWebEngineSettings; class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject { Q_OBJECT Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages NOTIFY autoLoadImagesChanged FINAL) @@ -211,7 +212,7 @@ private: friend class QQuickWebEngineView; void setParentSettings(QQuickWebEngineSettings *parentSettings); - QScopedPointer<QtWebEngineCore::WebEngineSettings> d_ptr; + QScopedPointer<QWebEngineSettings> d_ptr; }; QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginesingleton.cpp b/src/webengine/api/qquickwebenginesingleton.cpp index 3e84f5cf0..2fbc95c32 100644 --- a/src/webengine/api/qquickwebenginesingleton.cpp +++ b/src/webengine/api/qquickwebenginesingleton.cpp @@ -71,6 +71,7 @@ QT_BEGIN_NAMESPACE \sa WebEngineSettings */ + QQuickWebEngineSettings *QQuickWebEngineSingleton::settings() const { return defaultProfile()->settings(); @@ -90,4 +91,6 @@ QQuickWebEngineProfile *QQuickWebEngineSingleton::defaultProfile() const return QQuickWebEngineProfile::defaultProfile(); } +#include "moc_qquickwebenginesingleton_p.cpp" + QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginesingleton_p.h b/src/webengine/api/qquickwebenginesingleton_p.h index ba63382e5..eb33cc06d 100644 --- a/src/webengine/api/qquickwebenginesingleton_p.h +++ b/src/webengine/api/qquickwebenginesingleton_p.h @@ -55,8 +55,10 @@ #include <QObject> QT_BEGIN_NAMESPACE -class QQuickWebEngineProfile; + class QQuickWebEngineSettings; +class QQuickWebEngineProfile; + class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSingleton : public QObject { Q_OBJECT Q_PROPERTY(QQuickWebEngineSettings* settings READ settings CONSTANT FINAL) diff --git a/src/webengine/api/qquickwebenginetouchhandleprovider.cpp b/src/webengine/api/qquickwebenginetouchhandleprovider.cpp index 80f4727b6..56162b223 100644 --- a/src/webengine/api/qquickwebenginetouchhandleprovider.cpp +++ b/src/webengine/api/qquickwebenginetouchhandleprovider.cpp @@ -67,7 +67,7 @@ void QQuickWebEngineTouchHandleProvider::init(const QMap<int, QImage> &images) return; } - m_touchHandleMap.unite(images); + m_touchHandleMap.insert(images); } QImage QQuickWebEngineTouchHandleProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 7b875bf55..72089a5c4 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -41,7 +41,6 @@ #include "qquickwebengineview_p_p.h" #include "authentication_dialog_controller.h" #include "profile_adapter.h" -#include "certificate_error_controller.h" #include "file_picker_controller.h" #include "find_text_helper.h" #include "javascript_dialog_controller.h" @@ -50,9 +49,7 @@ #include "qquickwebengineaction_p.h" #include "qquickwebengineaction_p_p.h" #include "qquickwebenginehistory_p.h" -#include "qquickwebenginecertificateerror_p.h" #include "qquickwebengineclientcertificateselection_p.h" -#include "qquickwebenginecontextmenurequest_p.h" #include "qquickwebenginedialogrequests_p.h" #include "qquickwebenginefaviconprovider_p_p.h" #include "qquickwebengineloadrequest_p.h" @@ -62,6 +59,7 @@ #include "qquickwebenginesettings_p.h" #include "qquickwebenginescript_p.h" #include "qquickwebenginetouchhandleprovider_p_p.h" +#include "qwebenginecertificateerror.h" #include "qwebenginefindtextresult.h" #include "qwebenginequotarequest.h" #include "qwebengineregisterprotocolhandlerrequest.h" @@ -98,7 +96,6 @@ #include <QTimer> #include <QtGui/private/qguiapplication_p.h> #include <QtGui/qpa/qplatformintegration.h> - QT_BEGIN_NAMESPACE using namespace QtWebEngineCore; @@ -135,6 +132,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , m_zoomFactor(1.0) , m_ui2Enabled(false) , m_profileInitialized(false) + , m_contextMenuRequest(nullptr) { memset(actions, 0, sizeof(actions)); @@ -229,13 +227,15 @@ RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHo return quickDelegate; } -void QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenuData &data) +void QQuickWebEngineViewPrivate::contextMenuRequested(QWebEngineContextMenuRequest *request) { Q_Q(QQuickWebEngineView); - m_contextMenuData = data; + m_contextMenuRequest = request; - QQuickWebEngineContextMenuRequest *request = new QQuickWebEngineContextMenuRequest(data); + // FIXME: we most liekly do not need to make any copy here + auto *r = new QWebEngineContextMenuRequest( + new QWebEngineContextMenuRequestPrivate(*request->d.data())); QQmlEngine *engine = qmlEngine(q); // TODO: this is a workaround for QTBUG-65044 @@ -243,19 +243,19 @@ void QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu return; // mark the object for gc by creating temporary jsvalue - engine->newQObject(request); - Q_EMIT q->contextMenuRequested(request); + engine->newQObject(r); + Q_EMIT q->contextMenuRequested(r); - if (request->isAccepted()) + if (r->isAccepted()) return; // Assign the WebEngineView as the parent of the menu, so mouse events are properly propagated // on OSX. - QObject *menu = ui()->addMenu(q, QString(), data.position()); + QObject *menu = ui()->addMenu(q, QString(), r->position()); if (!menu) return; - QQuickContextMenuBuilder contextMenuBuilder(data, q, menu); + QQuickContextMenuBuilder contextMenuBuilder(r, q, menu); // Populate our menu contextMenuBuilder.initMenu(); @@ -290,21 +290,14 @@ void QQuickWebEngineViewPrivate::javascriptDialog(QSharedPointer<JavaScriptDialo ui()->showDialog(dialog); } -void QQuickWebEngineViewPrivate::allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) +void QQuickWebEngineViewPrivate::allowCertificateError(const QWebEngineCertificateError &error) { Q_Q(QQuickWebEngineView); - - QQuickWebEngineCertificateError *quickController = new QQuickWebEngineCertificateError(errorController); - // mark the object for gc by creating temporary jsvalue - qmlEngine(q)->newQObject(quickController); - Q_EMIT q->certificateError(quickController); - if (!quickController->overridable() || (!quickController->deferred() && !quickController->answered())) - quickController->rejectCertificate(); - else - m_certificateErrorControllers.append(errorController); + Q_EMIT q->certificateError(error); } -void QQuickWebEngineViewPrivate::selectClientCert(const QSharedPointer<ClientCertSelectController> &controller) +void QQuickWebEngineViewPrivate::selectClientCert( + const QSharedPointer<QtWebEngineCore::ClientCertSelectController> &controller) { #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) Q_Q(QQuickWebEngineView); @@ -468,7 +461,6 @@ void QQuickWebEngineViewPrivate::loadStarted(const QUrl &provisionalUrl, bool is isLoading = true; m_history->reset(); - m_certificateErrorControllers.clear(); QTimer::singleShot(0, q, [q, provisionalUrl]() { QQuickWebEngineLoadRequest loadRequest(provisionalUrl, QQuickWebEngineView::LoadStartedStatus); @@ -482,11 +474,29 @@ void QQuickWebEngineViewPrivate::loadCommitted() m_history->reset(); } -void QQuickWebEngineViewPrivate::loadVisuallyCommitted() +void QQuickWebEngineViewPrivate::didFirstVisuallyNonEmptyPaint() { #if QT_CONFIG(webengine_testsupport) - if (m_testSupport) - Q_EMIT m_testSupport->loadVisuallyCommitted(); + if (m_loadVisuallyCommittedState == NotCommitted) { + m_loadVisuallyCommittedState = DidFirstVisuallyNonEmptyPaint; + } else if (m_loadVisuallyCommittedState == DidFirstCompositorFrameSwap) { + if (m_testSupport) + Q_EMIT m_testSupport->loadVisuallyCommitted(); + m_loadVisuallyCommittedState = NotCommitted; + } +#endif +} + +void QQuickWebEngineViewPrivate::didCompositorFrameSwap() +{ +#if QT_CONFIG(webengine_testsupport) + if (m_loadVisuallyCommittedState == NotCommitted) { + m_loadVisuallyCommittedState = DidFirstCompositorFrameSwap; + } else if (m_loadVisuallyCommittedState == DidFirstVisuallyNonEmptyPaint) { + if (m_testSupport) + Q_EMIT m_testSupport->loadVisuallyCommitted(); + m_loadVisuallyCommittedState = NotCommitted; + } #endif } @@ -729,7 +739,7 @@ void QQuickWebEngineViewPrivate::findTextFinished(const QWebEngineFindTextResult Q_EMIT q->findTextFinished(result); } -WebEngineSettings *QQuickWebEngineViewPrivate::webEngineSettings() const +QWebEngineSettings *QQuickWebEngineViewPrivate::webEngineSettings() const { return m_settings->d_ptr.data(); } @@ -1554,7 +1564,7 @@ void QQuickWebEngineView::setWebChannel(QQmlWebChannel *webChannel) d->adapter->setWebChannel(webChannel, d->m_webChannelWorld); Q_EMIT webChannelChanged(); #else - Q_UNUSED(webChannel) + Q_UNUSED(webChannel); qWarning("WebEngine compiled without webchannel support"); #endif } @@ -1576,7 +1586,7 @@ void QQuickWebEngineView::setWebChannelWorld(uint webChannelWorld) d->adapter->setWebChannel(d->m_webChannel, d->m_webChannelWorld); Q_EMIT webChannelWorldChanged(webChannelWorld); #else - Q_UNUSED(webChannelWorld) + Q_UNUSED(webChannelWorld); qWarning("WebEngine compiled without webchannel support"); #endif } @@ -1700,9 +1710,9 @@ void QQuickWebEngineView::fullScreenCancelled() d->adapter->exitFullScreen(); } -void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +void QQuickWebEngineView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) { - QQuickItem::geometryChanged(newGeometry, oldGeometry); + QQuickItem::geometryChange(newGeometry, oldGeometry); Q_D(QQuickWebEngineView); if (d->widget) d->widget->setSize(newGeometry.size()); @@ -1720,16 +1730,16 @@ void QQuickWebEngineView::itemChange(ItemChange change, const ItemChangeData &va } #if QT_CONFIG(draganddrop) -static QPoint mapToScreen(const QQuickItem *item, const QPoint &clientPos) +static QPointF mapToScreen(const QQuickItem *item, const QPointF &clientPos) { - return item->window()->position() + item->mapToScene(clientPos).toPoint(); + return item->window()->position() + item->mapToScene(clientPos); } void QQuickWebEngineView::dragEnterEvent(QDragEnterEvent *e) { Q_D(QQuickWebEngineView); e->accept(); - d->adapter->enterDrag(e, mapToScreen(this, e->pos())); + d->adapter->enterDrag(e, mapToScreen(this, e->position())); } void QQuickWebEngineView::dragLeaveEvent(QDragLeaveEvent *e) @@ -1742,7 +1752,7 @@ void QQuickWebEngineView::dragLeaveEvent(QDragLeaveEvent *e) void QQuickWebEngineView::dragMoveEvent(QDragMoveEvent *e) { Q_D(QQuickWebEngineView); - Qt::DropAction dropAction = d->adapter->updateDragPosition(e, mapToScreen(this, e->pos())); + Qt::DropAction dropAction = d->adapter->updateDragPosition(e, mapToScreen(this, e->position())); if (Qt::IgnoreAction == dropAction) { e->ignore(); } else { @@ -1755,7 +1765,7 @@ void QQuickWebEngineView::dropEvent(QDropEvent *e) { Q_D(QQuickWebEngineView); e->accept(); - d->adapter->endDragging(e, mapToScreen(this, e->pos())); + d->adapter->endDragging(e, mapToScreen(this, e->position())); } #endif // QT_CONFIG(draganddrop) @@ -1803,32 +1813,33 @@ void QQuickWebEngineView::triggerWebAction(WebAction action) d->adapter->unselect(); break; case OpenLinkInThisWindow: - if (d->m_contextMenuData.linkUrl().isValid()) - setUrl(d->m_contextMenuData.linkUrl()); + if (d->m_contextMenuRequest->filteredLinkUrl().isValid()) + setUrl(d->m_contextMenuRequest->filteredLinkUrl()); break; case OpenLinkInNewWindow: - if (d->m_contextMenuData.linkUrl().isValid()) { + if (d->m_contextMenuRequest->filteredLinkUrl().isValid()) { QQuickWebEngineNewViewRequest request; - request.m_requestedUrl = d->m_contextMenuData.linkUrl(); + request.m_requestedUrl = d->m_contextMenuRequest->filteredLinkUrl(); request.m_isUserInitiated = true; request.m_destination = NewViewInWindow; Q_EMIT newViewRequested(&request); } break; case OpenLinkInNewTab: - if (d->m_contextMenuData.linkUrl().isValid()) { + if (d->m_contextMenuRequest->filteredLinkUrl().isValid()) { QQuickWebEngineNewViewRequest request; - request.m_requestedUrl = d->m_contextMenuData.linkUrl(); + request.m_requestedUrl = d->m_contextMenuRequest->filteredLinkUrl(); request.m_isUserInitiated = true; request.m_destination = NewViewInBackgroundTab; Q_EMIT newViewRequested(&request); } break; case CopyLinkToClipboard: - if (!d->m_contextMenuData.unfilteredLinkUrl().isEmpty()) { - QString urlString = d->m_contextMenuData.unfilteredLinkUrl().toString(QUrl::FullyEncoded); - QString linkText = d->m_contextMenuData.linkText().toHtmlEscaped(); - QString title = d->m_contextMenuData.titleText(); + if (!d->m_contextMenuRequest->linkUrl().isEmpty()) { + QString urlString = + d->m_contextMenuRequest->linkUrl().toString(QUrl::FullyEncoded); + QString linkText = d->m_contextMenuRequest->linkText().toHtmlEscaped(); + QString title = d->m_contextMenuRequest->titleText(); if (!title.isEmpty()) title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped()); QMimeData *data = new QMimeData(); @@ -1836,99 +1847,118 @@ void QQuickWebEngineView::triggerWebAction(WebAction action) QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral(">") + linkText + QStringLiteral("</a>"); data->setHtml(html); - data->setUrls(QList<QUrl>() << d->m_contextMenuData.unfilteredLinkUrl()); + data->setUrls(QList<QUrl>() << d->m_contextMenuRequest->linkUrl()); qApp->clipboard()->setMimeData(data); } break; case DownloadLinkToDisk: - if (d->m_contextMenuData.linkUrl().isValid()) - d->adapter->download(d->m_contextMenuData.linkUrl(), d->m_contextMenuData.suggestedFileName(), - d->m_contextMenuData.referrerUrl(), d->m_contextMenuData.referrerPolicy()); + if (d->m_contextMenuRequest->filteredLinkUrl().isValid()) + d->adapter->download(d->m_contextMenuRequest->filteredLinkUrl(), + d->m_contextMenuRequest->suggestedFileName(), + d->m_contextMenuRequest->referrerUrl(), + d->m_contextMenuRequest->referrerPolicy()); break; case CopyImageToClipboard: - if (d->m_contextMenuData.hasImageContent() && - (d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeImage || - d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeCanvas)) - { - d->adapter->copyImageAt(d->m_contextMenuData.position()); + if (d->m_contextMenuRequest->hasImageContent() + && (d->m_contextMenuRequest->mediaType() == QWebEngineContextMenuRequest::MediaTypeImage + || d->m_contextMenuRequest->mediaType() + == QWebEngineContextMenuRequest::MediaTypeCanvas)) { + d->adapter->copyImageAt(d->m_contextMenuRequest->position()); } break; case CopyImageUrlToClipboard: - if (d->m_contextMenuData.mediaUrl().isValid() && d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeImage) { - QString urlString = d->m_contextMenuData.mediaUrl().toString(QUrl::FullyEncoded); - QString alt = d->m_contextMenuData.altText(); + if (d->m_contextMenuRequest->mediaUrl().isValid() + && d->m_contextMenuRequest->mediaType() + == QWebEngineContextMenuRequest::MediaTypeImage) { + QString urlString = d->m_contextMenuRequest->mediaUrl().toString(QUrl::FullyEncoded); + QString alt = d->m_contextMenuRequest->altText(); if (!alt.isEmpty()) alt = QStringLiteral(" alt=\"%1\"").arg(alt.toHtmlEscaped()); - QString title = d->m_contextMenuData.titleText(); + QString title = d->m_contextMenuRequest->titleText(); if (!title.isEmpty()) title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped()); QMimeData *data = new QMimeData(); data->setText(urlString); QString html = QStringLiteral("<img src=\"") + urlString + QStringLiteral("\"") + title + alt + QStringLiteral("></img>"); data->setHtml(html); - data->setUrls(QList<QUrl>() << d->m_contextMenuData.mediaUrl()); + data->setUrls(QList<QUrl>() << d->m_contextMenuRequest->mediaUrl()); qApp->clipboard()->setMimeData(data); } break; case DownloadImageToDisk: case DownloadMediaToDisk: - if (d->m_contextMenuData.mediaUrl().isValid()) - d->adapter->download(d->m_contextMenuData.mediaUrl(), d->m_contextMenuData.suggestedFileName(), - d->m_contextMenuData.referrerUrl(), d->m_contextMenuData.referrerPolicy()); + if (d->m_contextMenuRequest->mediaUrl().isValid()) + d->adapter->download(d->m_contextMenuRequest->mediaUrl(), + d->m_contextMenuRequest->suggestedFileName(), + d->m_contextMenuRequest->referrerUrl(), + d->m_contextMenuRequest->referrerPolicy()); break; case CopyMediaUrlToClipboard: - if (d->m_contextMenuData.mediaUrl().isValid() && - (d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeAudio || - d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeVideo)) - { - QString urlString = d->m_contextMenuData.mediaUrl().toString(QUrl::FullyEncoded); - QString title = d->m_contextMenuData.titleText(); + if (d->m_contextMenuRequest->mediaUrl().isValid() + && (d->m_contextMenuRequest->mediaType() == QWebEngineContextMenuRequest::MediaTypeAudio + || d->m_contextMenuRequest->mediaType() + == QWebEngineContextMenuRequest::MediaTypeVideo)) { + QString urlString = d->m_contextMenuRequest->mediaUrl().toString(QUrl::FullyEncoded); + QString title = d->m_contextMenuRequest->titleText(); if (!title.isEmpty()) title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped()); QMimeData *data = new QMimeData(); data->setText(urlString); - if (d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeAudio) + if (d->m_contextMenuRequest->mediaType() + == QWebEngineContextMenuRequest::MediaTypeAudio) data->setHtml(QStringLiteral("<audio src=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral("></audio>")); else data->setHtml(QStringLiteral("<video src=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral("></video>")); - data->setUrls(QList<QUrl>() << d->m_contextMenuData.mediaUrl()); + data->setUrls(QList<QUrl>() << d->m_contextMenuRequest->mediaUrl()); qApp->clipboard()->setMimeData(data); } break; case ToggleMediaControls: - if (d->m_contextMenuData.mediaUrl().isValid() && d->m_contextMenuData.mediaFlags() & WebEngineContextMenuData::MediaCanToggleControls) { - bool enable = !(d->m_contextMenuData.mediaFlags() & WebEngineContextMenuData::MediaControls); - d->adapter->executeMediaPlayerActionAt(d->m_contextMenuData.position(), WebContentsAdapter::MediaPlayerControls, enable); + if (d->m_contextMenuRequest->mediaUrl().isValid() + && d->m_contextMenuRequest->mediaFlags() + & QWebEngineContextMenuRequest::MediaCanToggleControls) { + bool enable = !(d->m_contextMenuRequest->mediaFlags() + & QWebEngineContextMenuRequest::MediaControls); + d->adapter->executeMediaPlayerActionAt(d->m_contextMenuRequest->position(), + WebContentsAdapter::MediaPlayerControls, enable); } break; case ToggleMediaLoop: - if (d->m_contextMenuData.mediaUrl().isValid() && - (d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeAudio || - d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeVideo)) - { - bool enable = !(d->m_contextMenuData.mediaFlags() & WebEngineContextMenuData::MediaLoop); - d->adapter->executeMediaPlayerActionAt(d->m_contextMenuData.position(), WebContentsAdapter::MediaPlayerLoop, enable); + if (d->m_contextMenuRequest->mediaUrl().isValid() + && (d->m_contextMenuRequest->mediaType() == QWebEngineContextMenuRequest::MediaTypeAudio + || d->m_contextMenuRequest->mediaType() + == QWebEngineContextMenuRequest::MediaTypeVideo)) { + bool enable = !(d->m_contextMenuRequest->mediaFlags() + & QWebEngineContextMenuRequest::MediaLoop); + d->adapter->executeMediaPlayerActionAt(d->m_contextMenuRequest->position(), + WebContentsAdapter::MediaPlayerLoop, enable); } break; case ToggleMediaPlayPause: - if (d->m_contextMenuData.mediaUrl().isValid() && - (d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeAudio || - d->m_contextMenuData.mediaType() == WebEngineContextMenuData::MediaTypeVideo)) - { - bool enable = (d->m_contextMenuData.mediaFlags() & WebEngineContextMenuData::MediaPaused); - d->adapter->executeMediaPlayerActionAt(d->m_contextMenuData.position(), WebContentsAdapter::MediaPlayerPlay, enable); + if (d->m_contextMenuRequest->mediaUrl().isValid() + && (d->m_contextMenuRequest->mediaType() == QWebEngineContextMenuRequest::MediaTypeAudio + || d->m_contextMenuRequest->mediaType() + == QWebEngineContextMenuRequest::MediaTypeVideo)) { + bool enable = (d->m_contextMenuRequest->mediaFlags() + & QWebEngineContextMenuRequest::MediaPaused); + d->adapter->executeMediaPlayerActionAt(d->m_contextMenuRequest->position(), + WebContentsAdapter::MediaPlayerPlay, enable); } break; case ToggleMediaMute: - if (d->m_contextMenuData.mediaUrl().isValid() && d->m_contextMenuData.mediaFlags() & WebEngineContextMenuData::MediaHasAudio) { - bool enable = !(d->m_contextMenuData.mediaFlags() & WebEngineContextMenuData::MediaMuted); - d->adapter->executeMediaPlayerActionAt(d->m_contextMenuData.position(), WebContentsAdapter::MediaPlayerMute, enable); + if (d->m_contextMenuRequest->mediaUrl().isValid() + && d->m_contextMenuRequest->mediaFlags() + & QWebEngineContextMenuRequest::MediaHasAudio) { + bool enable = !(d->m_contextMenuRequest->mediaFlags() + & QWebEngineContextMenuRequest::MediaMuted); + d->adapter->executeMediaPlayerActionAt(d->m_contextMenuRequest->position(), + WebContentsAdapter::MediaPlayerMute, enable); } break; case InspectElement: - d->adapter->inspectElementAt(d->m_contextMenuData.position()); + d->adapter->inspectElementAt(d->m_contextMenuRequest->position()); break; case ExitFullScreen: d->adapter->exitFullScreen(); @@ -2281,12 +2311,9 @@ void QQuickWebEngineFullScreenRequest::reject() m_viewPrivate->setFullScreenMode(!m_toggleOn); } -QQuickContextMenuBuilder::QQuickContextMenuBuilder(const QtWebEngineCore::WebEngineContextMenuData &data, - QQuickWebEngineView *view, - QObject *menu) - : QtWebEngineCore::RenderViewContextMenuQt(data) - , m_view(view) - , m_menu(menu) +QQuickContextMenuBuilder::QQuickContextMenuBuilder(QWebEngineContextMenuRequest *request, + QQuickWebEngineView *view, QObject *menu) + : QtWebEngineCore::RenderViewContextMenuQt(request), m_view(view), m_menu(menu) { } @@ -2394,9 +2421,9 @@ void QQuickContextMenuBuilder::addMenuItem(ContextMenuItem menuItem) case ContextMenuItem::SpellingSuggestions: { QPointer<QQuickWebEngineView> thisRef(m_view); - for (int i=0; i < m_contextData.spellCheckerSuggestions().count() && i < 4; i++) { + for (int i = 0; i < m_contextData->spellCheckerSuggestions().count() && i < 4; i++) { action = new QQuickWebEngineAction(m_menu); - QString replacement = m_contextData.spellCheckerSuggestions().at(i); + QString replacement = m_contextData->spellCheckerSuggestions().at(i); QObject::connect(action, &QQuickWebEngineAction::triggered, [thisRef, replacement] { thisRef->replaceMisspelledWord(replacement); }); m_view->d_ptr->ui()->addMenuItem(action, m_menu); } @@ -2421,19 +2448,19 @@ bool QQuickContextMenuBuilder::isMenuItemEnabled(ContextMenuItem menuItem) case ContextMenuItem::Reload: return true; case ContextMenuItem::Cut: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanCut; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanCut; case ContextMenuItem::Copy: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanCopy; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanCopy; case ContextMenuItem::Paste: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanPaste; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanPaste; case ContextMenuItem::Undo: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanUndo; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanUndo; case ContextMenuItem::Redo: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanRedo; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanRedo; case ContextMenuItem::SelectAll: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanSelectAll; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanSelectAll; case ContextMenuItem::PasteAndMatchStyle: - return m_contextData.editFlags() & QtWebEngineCore::WebEngineContextMenuData::CanPaste; + return m_contextData->editFlags() & QWebEngineContextMenuRequest::CanPaste; case ContextMenuItem::OpenLinkInNewWindow: case ContextMenuItem::OpenLinkInNewTab: case ContextMenuItem::CopyLinkToClipboard: @@ -2498,3 +2525,4 @@ void QQuickWebEngineTouchHandle::setOpacity(float opacity) QT_END_NAMESPACE +#include "moc_qquickwebengineview_p.cpp" diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index ab84b2600..e169d0490 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -51,22 +51,26 @@ // We mean it. // +#include <QtWebEngineCore/qtwebenginecoreglobal.h> #include <QtWebEngine/private/qtwebengineglobal_p.h> #include <QQuickItem> #include <QtGui/qcolor.h> +#include "qquickwebengineprofile.h" #include "qquickwebenginescript.h" +namespace QtWebEngineCore { +class RenderWidgetHostViewQtDelegateQuick; +} + QT_BEGIN_NAMESPACE class QQmlWebChannel; class QQuickContextMenuBuilder; class QQuickWebEngineAction; class QQuickWebEngineAuthenticationDialogRequest; -class QQuickWebEngineCertificateError; class QQuickWebEngineClientCertificateSelection; class QQuickWebEngineColorDialogRequest; -class QQuickWebEngineContextMenuRequest; class QQuickWebEngineFaviconProvider; class QQuickWebEngineFileDialogRequest; class QQuickWebEngineHistory; @@ -74,14 +78,15 @@ class QQuickWebEngineJavaScriptDialogRequest; class QQuickWebEngineLoadRequest; class QQuickWebEngineNavigationRequest; class QQuickWebEngineNewViewRequest; -class QQuickWebEngineProfile; class QQuickWebEngineSettings; class QQuickWebEngineTooltipRequest; class QQuickWebEngineFormValidationMessageRequest; class QQuickWebEngineViewPrivate; +class QWebEngineCertificateError; class QWebEngineFindTextResult; class QWebEngineQuotaRequest; class QWebEngineRegisterProtocolHandlerRequest; +class QWebEngineContextMenuRequest; #if QT_CONFIG(webengine_testsupport) class QQuickWebEngineTestSupport; @@ -123,7 +128,9 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(QQuickWebEngineProfile *profile READ profile WRITE setProfile NOTIFY profileChanged FINAL REVISION 1) Q_PROPERTY(QQuickWebEngineSettings *settings READ settings REVISION 1 CONSTANT FINAL) Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL REVISION 1) +#if QT_CONFIG(webengine_webchannel) Q_PROPERTY(QQmlWebChannel *webChannel READ webChannel WRITE setWebChannel NOTIFY webChannelChanged REVISION 1 FINAL) +#endif Q_PROPERTY(QQmlListProperty<QQuickWebEngineScript> userScripts READ userScripts FINAL REVISION 1) Q_PROPERTY(bool activeFocusOnPress READ activeFocusOnPress WRITE setActiveFocusOnPress NOTIFY activeFocusOnPressChanged REVISION 2 FINAL) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged REVISION 2 FINAL) @@ -545,7 +552,7 @@ Q_SIGNALS: void linkHovered(const QUrl &hoveredUrl); void navigationRequested(QQuickWebEngineNavigationRequest *request); void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID); - Q_REVISION(1) void certificateError(QQuickWebEngineCertificateError *error); + Q_REVISION(1) void certificateError(const QWebEngineCertificateError &error); Q_REVISION(1) void fullScreenRequested(const QQuickWebEngineFullScreenRequest &request); Q_REVISION(1) void isFullScreenChanged(); Q_REVISION(1) void featurePermissionRequested(const QUrl &securityOrigin, Feature feature); @@ -562,7 +569,7 @@ Q_SIGNALS: Q_REVISION(3) void audioMutedChanged(bool muted); Q_REVISION(3) void recentlyAudibleChanged(bool recentlyAudible); Q_REVISION(3) void webChannelWorldChanged(uint); - Q_REVISION(4) void contextMenuRequested(QQuickWebEngineContextMenuRequest *request); + Q_REVISION(4) void contextMenuRequested(QWebEngineContextMenuRequest *request); Q_REVISION(4) void authenticationDialogRequested(QQuickWebEngineAuthenticationDialogRequest *request); Q_REVISION(4) void javaScriptDialogRequested(QQuickWebEngineJavaScriptDialogRequest *request); Q_REVISION(4) void colorDialogRequested(QQuickWebEngineColorDialogRequest *request); @@ -587,7 +594,7 @@ Q_SIGNALS: #endif protected: - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; void itemChange(ItemChange, const ItemChangeData &) override; #if QT_CONFIG(draganddrop) void dragEnterEvent(QDragEnterEvent *e) override; @@ -600,6 +607,7 @@ private: Q_DECLARE_PRIVATE(QQuickWebEngineView) QScopedPointer<QQuickWebEngineViewPrivate> d_ptr; + friend class QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick; friend class QQuickContextMenuBuilder; friend class QQuickWebEngineNewViewRequest; friend class QQuickWebEngineFaviconProvider; diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 68d65410a..d8219751e 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -75,7 +75,7 @@ QT_BEGIN_NAMESPACE class QQuickWebEngineView; class QQmlComponent; class QQmlContext; -class QQuickWebEngineContextMenuRequest; +class QWebEngineContextMenuRequest; class QQuickWebEngineSettings; class QQuickWebEngineFaviconProvider; class QQuickWebEngineProfilePrivate; @@ -115,7 +115,7 @@ public: QColor backgroundColor() const override; void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) override; void loadCommitted() override; - void loadVisuallyCommitted() override; + void didFirstVisuallyNonEmptyPaint() override; void loadFinished(bool success, const QUrl &url, bool isErrorPage = false, int errorCode = 0, const QString &errorDescription = QString()) override; void focusContainer() override; void unhandledKeyEvent(QKeyEvent *event) override; @@ -128,7 +128,7 @@ public: void windowCloseRejected() override; void requestFullScreenMode(const QUrl &origin, bool fullscreen) override; bool isFullScreenMode() const override; - void contextMenuRequested(const QtWebEngineCore::WebEngineContextMenuData &) override; + void contextMenuRequested(QWebEngineContextMenuRequest *request) override; void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) override; void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) override; void runFileChooser(QSharedPointer<QtWebEngineCore::FilePickerController>) override; @@ -146,9 +146,10 @@ public: void runQuotaRequest(QWebEngineQuotaRequest) override; void runRegisterProtocolHandlerRequest(QWebEngineRegisterProtocolHandlerRequest) override; QObject *accessibilityParentObject() override; - QtWebEngineCore::WebEngineSettings *webEngineSettings() const override; - void allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) override; - void selectClientCert(const QSharedPointer<ClientCertSelectController> &selectController) override; + QWebEngineSettings *webEngineSettings() const override; + void allowCertificateError(const QWebEngineCertificateError &error) override; + void selectClientCert(const QSharedPointer<QtWebEngineCore::ClientCertSelectController> + &selectController) override; void runFeaturePermissionRequest(QtWebEngineCore::ProfileAdapter::PermissionType permission, const QUrl &securityOrigin) override; void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus, int exitCode) override; void requestGeometryChange(const QRect &geometry, const QRect &frameGeometry) override; @@ -173,6 +174,8 @@ public: void widgetChanged(QtWebEngineCore::RenderWidgetHostViewQtDelegate *newWidgetBase) override; void findTextFinished(const QWebEngineFindTextResult &result) override; + void didCompositorFrameSwap(); + void updateAction(QQuickWebEngineView::WebAction) const; void adoptWebContents(QtWebEngineCore::WebContentsAdapter *webContents); void setProfile(QQuickWebEngineProfile *profile); @@ -198,7 +201,6 @@ public: QQuickWebEngineTestSupport *m_testSupport; #endif QQmlComponent *contextMenuExtraItems; - QtWebEngineCore::WebEngineContextMenuData m_contextMenuData; QUrl m_url; QString m_html; QUrl iconUrl; @@ -210,7 +212,6 @@ public: bool m_navigationActionTriggered; qreal devicePixelRatio; QMap<quint64, QJSValue> m_callbacks; - QList<QSharedPointer<CertificateErrorController> > m_certificateErrorControllers; QQmlWebChannel *m_webChannel; QPointer<QQuickWebEngineView> inspectedView; QPointer<QQuickWebEngineView> devToolsView; @@ -223,12 +224,20 @@ public: bool profileInitialized() const; private: + enum LoadVisuallyCommittedState { + NotCommitted, + DidFirstVisuallyNonEmptyPaint, + DidFirstCompositorFrameSwap + }; + QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; QList<QQuickWebEngineScript *> m_userScripts; QColor m_backgroundColor; qreal m_zoomFactor; bool m_ui2Enabled; bool m_profileInitialized; + QWebEngineContextMenuRequest *m_contextMenuRequest; + LoadVisuallyCommittedState m_loadVisuallyCommittedState = NotCommitted; }; #ifndef QT_NO_ACCESSIBILITY @@ -254,7 +263,8 @@ private: class QQuickContextMenuBuilder : public QtWebEngineCore::RenderViewContextMenuQt { public: - QQuickContextMenuBuilder(const QtWebEngineCore::WebEngineContextMenuData &data, QQuickWebEngineView *view, QObject *menu); + QQuickContextMenuBuilder(QWebEngineContextMenuRequest *data, QQuickWebEngineView *view, + QObject *menu); void appendExtraItems(QQmlEngine *engine); private: diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp index 4346832c9..825805888 100644 --- a/src/webengine/api/qtwebengineglobal.cpp +++ b/src/webengine/api/qtwebengineglobal.cpp @@ -39,6 +39,7 @@ #include "qtwebengineglobal.h" #include <QCoreApplication> +#include <QQuickWindow> namespace QtWebEngineCore { @@ -72,15 +73,16 @@ namespace QtWebEngine { */ void initialize() { - QCoreApplication *app = QCoreApplication::instance(); - if (app) { + QCoreApplication *app = QCoreApplication::instance(); + if (app) { qWarning("QtWebEngine::initialize() called with QCoreApplication object already created and should be call before. "\ "This is depreciated and may fail in the future."); QtWebEngineCore::initialize(); return; - } - // call initialize the same way as widgets do - qAddPreRoutine(QtWebEngineCore::initialize); + } + // call initialize the same way as widgets do + qAddPreRoutine(QtWebEngineCore::initialize); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); } } // namespace QtWebEngine diff --git a/src/webengine/doc/src/context_menu_request.qdoc b/src/webengine/doc/src/context_menu_request.qdoc new file mode 100644 index 000000000..cc812dcf2 --- /dev/null +++ b/src/webengine/doc/src/context_menu_request.qdoc @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmltype ContextMenuRequest + \instantiates QQuickWebEngineContextMenuRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.4 + + \brief A request for showing a context menu. + + A ContextMenuRequest is passed as an argument of the + WebEngineView::contextMenuRequested signal. It provides further + information about the context of the request. The position of the + request origin can be found via the \l x and \l y properties. + + The \l accepted property of the request indicates whether the request + is handled by the user code or the default context menu should + be displayed. + + The following code uses a custom menu to handle the request: + + \code + WebEngineView { + id: view + // ... + onContextMenuRequested: function(request) { + request.accepted = true; + myMenu.x = request.x; + myMenu.y = request.y; + myMenu.trigger.connect(view.triggerWebAction); + myMenu.popup(); + } + // ... + } + \endcode +*/ + +/*! + \qmlproperty point ContextMenuRequest::position + \readonly + + The position of the user action from where the context + menu request originates. +*/ + +/*! + \qmlproperty string ContextMenuRequest::selectedText + \readonly + + The selected text the context menu was created for. +*/ + +/*! + \qmlproperty string ContextMenuRequest::linkText + \readonly + + The text of the link if the context menu was requested for a link. +*/ + +/*! + \qmlproperty url ContextMenuRequest::linkUrl + \readonly + + The URL of the link if the selected web page content is a link. + It is not guaranteed to be a valid URL. +*/ + +/*! + \qmlproperty url ContextMenuRequest::mediaUrl + \readonly + + The URL of media if the selected web content is a media element. +*/ + +/*! + \qmlproperty enumeration ContextMenuRequest::mediaType + \readonly + + The type of the media element or \c MediaTypeNone if + the selected web page content is not a media element. + + \value ContextMenuRequest.MediaTypeNone + Not a media. + \value ContextMenuRequest.MediaTypeImage + An image. + \value ContextMenuRequest.MediaTypeVideo + A video. + \value ContextMenuRequest.MediaTypeAudio + An audio element. + \value ContextMenuRequest.MediaTypeCanvas + A canvas. + \value ContextMenuRequest.MediaTypeFile + A file. + \value ContextMenuRequest.MediaTypePlugin + A plugin. +*/ + +/*! + \qmlproperty bool ContextMenuRequest::isContentEditable + \readonly + + Indicates whether the selected web content is editable. +*/ + +/*! + \qmlproperty string ContextMenuRequest::misspelledWord + \readonly + + If the context is a word considered misspelled by the spell-checker, + returns the misspelled word. +*/ + +/*! + \qmlproperty stringlist ContextMenuRequest::spellCheckerSuggestions + \readonly + + If the context is a word considered misspelled by the spell-checker, + returns a list of suggested replacements. +*/ + +/*! + \qmlproperty bool ContextMenuRequest::accepted + + Indicates whether the context menu request has been + handled by the signal handler. + + If the property is \c false after any signal handlers + for WebEngineView::contextMenuRequested have been executed, + a default context menu will be shown. + To prevent this, set \c{request.accepted} to \c true. + + The default is \c false. + + \note The default content of the context menu depends on the + web element for which the request was actually generated. +*/ + +/*! + \qmlproperty flags ContextMenuRequest::mediaFlags + \readonly + \since QtWebEngine 1.7 + + The current media element's status and its available operations. + \c MediaNone if the selected web page content is not a media element. + + \value ContextMenuRequest.MediaInError + An error occurred. + \value ContextMenuRequest.MediaPaused + Media is paused. + \value ContextMenuRequest.MediaMuted + Media is muted. + \value ContextMenuRequest.MediaLoop + Media can be looped. + \value ContextMenuRequest.MediaCanSave + Media can be saved. + \value ContextMenuRequest.MediaHasAudio + Media has audio. + \value ContextMenuRequest.MediaCanToggleControls + Media can show controls. + \value ContextMenuRequest.MediaControls + Media controls are shown. + \value ContextMenuRequest.MediaCanPrint + Media is printable. + \value ContextMenuRequest.MediaCanRotate + Media is rotatable. +*/ + +/*! + \qmlproperty flags ContextMenuRequest::editFlags + \readonly + \since QtWebEngine 1.7 + + The available edit operations in the current context or \c CanDoNone if no actions are available. + + \value ContextMenuRequest.CanUndo + Undo is available. + \value ContextMenuRequest.CanRedo + Redo is available. + \value ContextMenuRequest.CanCut + Cut is available. + \value ContextMenuRequest.CanCopy + Copy is available. + \value ContextMenuRequest.CanPaste + Paste is available. + \value ContextMenuRequest.CanDelete + Delete is available. + \value ContextMenuRequest.CanSelectAll + Select All is available. + \value ContextMenuRequest.CanTranslate + Translate is available. + \value ContextMenuRequest.CanEditRichly + Context is richly editable. +*/ diff --git a/src/webengine/doc/src/fullscreen_request.qdoc b/src/webengine/doc/src/fullscreen_request.qdoc new file mode 100644 index 000000000..230d62e50 --- /dev/null +++ b/src/webengine/doc/src/fullscreen_request.qdoc @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmltype FullScreenRequest + \instantiates QQuickWebEngineFullScreenRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.1 + + \brief A utility type for the WebEngineView::fullScreenRequested() signal. + + \sa WebEngineView::fullScreenRequested() +*/ + +/*! + \qmlproperty url FullScreenRequest::origin + \readonly + The URL of the web page that issued the fullscreen request. +*/ + +/*! + \qmlproperty bool FullScreenRequest::toggleOn + \readonly + + Returns \c{true} if the application should toggle fullscreen mode on, \c{false} otherwise. + + \sa accept() +*/ + +/*! + \qmlmethod void FullScreenRequest::accept() + + Call this method to accept the fullscreen request. It sets the WebEngineView::isFullScreen + property to be equal to toggleOn. + + \qml + ApplicationWindow { + id: window + WebEngineView { + onFullScreenRequested: function(request) { + if (request.toggleOn) + window.showFullScreen() + else + window.showNormal() + request.accept() + } + } + } + \endqml + + \sa toggleOn +*/ + +/*! + \qmlmethod void FullScreenRequest::reject() + Rejects a fullscreen request. +*/ + diff --git a/src/webengine/doc/src/quota_request.qdoc b/src/webengine/doc/src/quota_request.qdoc new file mode 100644 index 000000000..ee64c0484 --- /dev/null +++ b/src/webengine/doc/src/quota_request.qdoc @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmltype QuotaRequest + \instantiates QWebEngineQuotaRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.7 + + \brief A utility type for the WebEngineView::quotaRequested() signal. + + \sa WebEngineView::quotaRequested() +*/ + +/*! + \qmlproperty url QuotaRequest::origin + \readonly + + The URL of the web page that issued the quota request. +*/ + +/*! + \qmlproperty qint64 QuotaRequest::requestedSize + \readonly + + Contains the size of the requested disk space in bytes. +*/ + +/*! + \qmlmethod void QuotaRequest::accept() + + Accepts the quota request. + + \qml + WebEngineView { + onQuotaRequested: function(request) { + if (request.requestedSize <= 5 * 1024 * 1024) + request.accept(); + else + request.reject(); + } + } + \endqml +*/ + +/*! + \qmlmethod void QuotaRequest::reject() + Rejects the quota request. +*/ + diff --git a/src/webengine/doc/src/register_protocol_handler_request.qdoc b/src/webengine/doc/src/register_protocol_handler_request.qdoc new file mode 100644 index 000000000..b3ebcb31b --- /dev/null +++ b/src/webengine/doc/src/register_protocol_handler_request.qdoc @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmltype RegisterProtocolHandlerRequest + \instantiates QWebEngineRegisterProtocolHandlerRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.7 + \brief The RegisterProtocolHandlerRequest type enables accepting + or rejecting requests from the \l registerProtocolHandler API. + + \sa WebEngineView::registerProtocolHandlerRequested() +*/ + +/*! + \qmlproperty url RegisterProtocolHandlerRequest::origin + \brief The URL template for the protocol handler. + + This is the second parameter from the \l registerProtocolHandler call. +*/ + +/*! + \qmlproperty string RegisterProtocolHandlerRequest::scheme + \brief The URL scheme for the protocol handler. + + This is the first parameter from the \l registerProtocolHandler call. +*/ + +/*! + \qmlmethod void RegisterProtocolHandlerRequest::accept() + \brief Accepts the request. + + Subsequent calls to accept() and reject() are ignored. +*/ + +/*! + \qmlmethod void RegisterProtocolHandlerRequest::reject() + \brief Accepts the request. + + Subsequent calls to accept() and reject() are ignored. +*/ + diff --git a/src/webengine/api/qquickwebenginecertificateerror.cpp b/src/webengine/doc/src/webengine_certificate_error.qdoc index 63beb1bae..8c032dc8b 100644 --- a/src/webengine/api/qquickwebenginecertificateerror.cpp +++ b/src/webengine/doc/src/webengine_certificate_error.qdoc @@ -1,11 +1,11 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** -** This file is part of the QtWebEngine module of the Qt Toolkit. +** This file is part of the documentation of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:FDL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the @@ -14,56 +14,20 @@ ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include <qquickwebenginecertificateerror_p.h> -#include "certificate_error_controller.h" -QT_BEGIN_NAMESPACE - -class QQuickWebEngineCertificateErrorPrivate { -public: - QQuickWebEngineCertificateErrorPrivate(const QSharedPointer<CertificateErrorController> &controller) - : weakRefCertErrorController(controller), - error(static_cast<QQuickWebEngineCertificateError::Error>(static_cast<int>(controller->error()))), - description(controller->errorString()), - overridable(controller->overridable()), - async(false), - answered(false) - { - } - - const QWeakPointer<CertificateErrorController> weakRefCertErrorController; - QQuickWebEngineCertificateError::Error error; - QString description; - bool overridable; - bool async; - bool answered; -}; - /*! \qmltype WebEngineCertificateError - \instantiates QQuickWebEngineCertificateError + \instantiates QWebEngineCertificateError \inqmlmodule QtWebEngine \since QtWebEngine 1.1 @@ -85,20 +49,6 @@ public: \sa WebEngineView::certificateError */ -QQuickWebEngineCertificateError::QQuickWebEngineCertificateError(const QSharedPointer<CertificateErrorController> &controller, QObject *parent) - : QObject(parent) - , d_ptr(new QQuickWebEngineCertificateErrorPrivate(controller)) -{ -} - -QQuickWebEngineCertificateError::~QQuickWebEngineCertificateError() -{ - Q_D(QQuickWebEngineCertificateError); - if (!d->answered) - rejectCertificate(); -} - - /*! \qmlmethod void WebEngineCertificateError::defer() @@ -107,58 +57,22 @@ QQuickWebEngineCertificateError::~QQuickWebEngineCertificateError() URL request until WebEngineCertificateError::ignoreCertificateError() or WebEngineCertificateError::rejectCertificate() is called. */ -void QQuickWebEngineCertificateError::defer() -{ - Q_D(QQuickWebEngineCertificateError); - d->async = true; -} /*! \qmlmethod void WebEngineCertificateError::ignoreCertificateError() The certificate error is ignored, and the web engine view continues to load the requested URL. */ -void QQuickWebEngineCertificateError::ignoreCertificateError() -{ - Q_D(QQuickWebEngineCertificateError); - - d->answered = true; - - QSharedPointer<CertificateErrorController> strongRefCert = d->weakRefCertErrorController.toStrongRef(); - if (strongRefCert) - strongRefCert->accept(true); -} - /*! \qmlmethod void WebEngineCertificateError::rejectCertificate() The certificate is rejected, and the web engine view stops loading the requested URL. */ -void QQuickWebEngineCertificateError::rejectCertificate() -{ - Q_D(QQuickWebEngineCertificateError); - - d->answered = true; - - QSharedPointer<CertificateErrorController> strongRefCert = d->weakRefCertErrorController.toStrongRef(); - if (strongRefCert) - strongRefCert->accept(false); -} - /*! \qmlproperty url WebEngineCertificateError::url \readonly The URL that triggered the error. */ -QUrl QQuickWebEngineCertificateError::url() const -{ - Q_D(const QQuickWebEngineCertificateError); - QSharedPointer<CertificateErrorController> strongRefCert = d->weakRefCertErrorController.toStrongRef(); - if (strongRefCert) - return strongRefCert->url(); - return QUrl(); -} - /*! \qmlproperty enumeration WebEngineCertificateError::error \readonly @@ -205,47 +119,15 @@ QUrl QQuickWebEngineCertificateError::url() const the device owner. (Added in 5.15) */ -QQuickWebEngineCertificateError::Error QQuickWebEngineCertificateError::error() const -{ - Q_D(const QQuickWebEngineCertificateError); - return d->error; -} - /*! \qmlproperty string WebEngineCertificateError::description \readonly A short localized human-readable description of the error. */ -QString QQuickWebEngineCertificateError::description() const -{ - Q_D(const QQuickWebEngineCertificateError); - return d->description; -} - /*! \qmlproperty bool WebEngineCertificateError::overridable \readonly A boolean that indicates whether the certificate error can be overridden and ignored. */ -bool QQuickWebEngineCertificateError::overridable() const -{ - Q_D(const QQuickWebEngineCertificateError); - return d->overridable; -} - -bool QQuickWebEngineCertificateError::deferred() const -{ - Q_D(const QQuickWebEngineCertificateError); - return d->async; -} - -bool QQuickWebEngineCertificateError::answered() const -{ - Q_D(const QQuickWebEngineCertificateError); - return d->answered; -} - -QT_END_NAMESPACE - diff --git a/src/webengine/doc/src/webengine_download_request.qdoc b/src/webengine/doc/src/webengine_download_request.qdoc new file mode 100644 index 000000000..2b96ec45b --- /dev/null +++ b/src/webengine/doc/src/webengine_download_request.qdoc @@ -0,0 +1,302 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmltype WebEngineDownloadRequest + \instantiates QWebEngineDownloadRequest + \inqmlmodule QtWebEngine + \brief Provides information about a download. + + WebEngineDownloadRequest models a download throughout its life cycle, starting + with a pending download request and finishing with a completed download. It + can be used, for example, to get information about new downloads, to monitor + progress, and to pause, resume, and cancel downloads. + + Downloads are usually triggered by user interaction on a web page. It is the + WebEngineProfile's responsibility to notify the application of new download + requests, which it does by emitting the + \l{WebEngineProfile::downloadRequested}{downloadRequested} signal together + with a newly created WebEngineDownloadRequest. The application can then examine + this item and decide whether to accept it or not. A signal handler must + explicitly call accept() on the item for \QWE to actually start + downloading and writing data to disk. If no signal handler calls accept(), + then the download request will be automatically rejected and nothing will be + written to disk. + + \note Some properties, like the \l path under which the file will be saved, + can only be changed before calling accept(). + + \section2 Object Life Cycle + + All items are guaranteed to be valid during the emission of the + \l{WebEngineProfile::downloadRequested}{downloadRequested} signal. If + accept() is \e not called by any signal handler, then the item will be + deleted \e immediately after signal emission. This means that the + application \b{must not} keep references to rejected download items. + + \section2 Web Page Downloads + + In addition to normal file downloads, which consist simply of retrieving + some raw bytes from the network and writing them to disk, \QWE also + supports saving complete web pages, which involves parsing the page's HTML, + downloading any dependent resources, and potentially packaging everything + into a special file format (\l savePageFormat). To check if a download is + for a file or a web page, use \l isSavePageDownload. + + \sa WebEngineProfile, WebEngineProfile::downloadRequested, + WebEngineProfile::downloadFinished +*/ + +/*! + \qmlmethod void WebEngineDownloadRequest::accept() + + Accepts the download request, which will start the download. + + If the item is in the \c DownloadRequested state, then it will transition + into the \c DownloadInProgress state and the downloading will begin. If the + item is in any other state, then nothing will happen. + + \sa state +*/ + +/*! + \qmlmethod void WebEngineDownloadRequest::cancel() + + Cancels the download. + + If the item is in the \c DownloadInProgress state, then it will transition + into the \c DownloadCancelled state, the downloading will stop, and + partially downloaded files will be deleted from disk. + + If the item is in the \c DownloadCompleted state, then nothing will happen. + If the item is in any other state, then it will transition into the \c + DownloadCancelled state without further effect. + + \sa state +*/ + +/*! + \qmlmethod void WebEngineDownloadRequest::pause() + + Pauses the download. + + Has no effect if the state is not \c DownloadInProgress. Does not change the + state. + + \sa resume, isPaused +*/ + +/*! + \qmlmethod void WebEngineDownloadRequest::resume() + + Resumes the download if it was paused or interrupted. + + Has no effect if the state is not \c DownloadInProgress or \c + DownloadInterrupted. Does not change the state. + + \sa pause, isPaused +*/ + +/*! + \qmlproperty int WebEngineDownloadRequest::id + + Holds the download item's ID. +*/ + +/*! + \qmlproperty enumeration WebEngineDownloadRequest::state + + Describes the state of the download: + + \value WebEngineDownloadRequest.DownloadRequested + Download has been requested, but it has not been accepted yet. + \value WebEngineDownloadRequest.DownloadInProgress + Download is in progress. + \value WebEngineDownloadRequest.DownloadCompleted + Download completed successfully. + \value WebEngineDownloadRequest.DownloadCancelled + Download was cancelled by the user. + \value WebEngineDownloadRequest.DownloadInterrupted + Download has been interrupted (by the server or because of lost connectivity). +*/ + +/*! + \qmlproperty int WebEngineDownloadRequest::totalBytes + + Holds the total amount of data to download in bytes. + + \c -1 means the total size is unknown. +*/ + +/*! + \qmlproperty int WebEngineDownloadRequest::receivedBytes + + Holds the amount of data in bytes that has been downloaded so far. +*/ + +/*! + \qmlproperty url WebEngineDownloadRequest::url + \readonly + + Returns the download's origin URL. +*/ + +/*! + \qmlproperty string WebEngineDownloadRequest::mimeType + + Holds the MIME type of the download. +*/ + +/*! + \qmlproperty string WebEngineDownloadRequest::downloadDirectory + + Holds the full target path without file name where data is being downloaded to. + + The download directory can only be set in the + \l{WebEngineProfile::downloadRequested}{downloadRequested} handler before + the download is accepted. + + \sa WebEngineProfile::downloadRequested(), accept() +*/ + +/*! + \qmlproperty string WebEngineDownloadRequest::downloadFileName + + Holds the name of the file to which data is being downloaded. + + The download file name can only be set in the + \l{WebEngineProfile::downloadRequested}{downloadRequested} handler before + the download is accepted. + + \sa WebEngineProfile::downloadRequested(), accept() +*/ + +/*! + \qmlproperty string WebEngineDownloadRequest::suggestedFileName + + Returns the suggested file name. +*/ + +/*! + \qmlproperty enumeration WebEngineDownloadRequest::savePageFormat + + Describes the format that is used to save a web page. + + \value WebEngineDownloadRequest.UnknownSaveFormat + This is not a request for downloading a complete web page. + \value WebEngineDownloadRequest.SingleHtmlSaveFormat + The page is saved as a single HTML page. Resources such as images + are not saved. + \value WebEngineDownloadRequest.CompleteHtmlSaveFormat + The page is saved as a complete HTML page, for example a directory + containing the single HTML page and the resources. + \value WebEngineDownloadRequest.MimeHtmlSaveFormat + The page is saved as a complete web page in the MIME HTML format. +*/ + +/*! + \qmlproperty bool WebEngineDownloadItem::isSavePageDownload + \readonly + + Whether this is a download request for saving a web page or a file. + + \sa savePageFormat +*/ + +/*! + \qmlproperty enumeration WebEngineDownloadRequest::interruptReason + \readonly + + Returns the reason why the download was interrupted: + + \value WebEngineDownloadRequest.NoReason Unknown reason or not interrupted. + \value WebEngineDownloadRequest.FileFailed General file operation failure. + \value WebEngineDownloadRequest.FileAccessDenied The file cannot be written locally, due to access restrictions. + \value WebEngineDownloadRequest.FileNoSpace Insufficient space on the target drive. + \value WebEngineDownloadRequest.FileNameTooLong The directory or file name is too long. + \value WebEngineDownloadRequest.FileTooLarge The file size exceeds the file system limitation. + \value WebEngineDownloadRequest.FileVirusInfected The file is infected with a virus. + \value WebEngineDownloadRequest.FileTransientError Temporary problem (for example the file is in use, + out of memory, or too many files are opened at once). + \value WebEngineDownloadRequest.FileBlocked The file was blocked due to local policy. + \value WebEngineDownloadRequest.FileSecurityCheckFailed An attempt to check the safety of the download + failed due to unexpected reasons. + \value WebEngineDownloadRequest.FileTooShort An attempt was made to seek past the end of a file when + opening a file (as part of resuming a previously interrupted download). + \value WebEngineDownloadRequest.FileHashMismatch The partial file did not match the expected hash. + + \value WebEngineDownloadRequest.NetworkFailed General network failure. + \value WebEngineDownloadRequest.NetworkTimeout The network operation has timed out. + \value WebEngineDownloadRequest.NetworkDisconnected The network connection has been terminated. + \value WebEngineDownloadRequest.NetworkServerDown The server has gone down. + \value WebEngineDownloadRequest.NetworkInvalidRequest The network request was invalid (for example, the + original or redirected URL is invalid, has an unsupported scheme, or is disallowed by policy). + + \value WebEngineDownloadRequest.ServerFailed General server failure. + \value WebEngineDownloadRequest.ServerBadContent The server does not have the requested data. + \value WebEngineDownloadRequest.ServerUnauthorized The server did not authorize access to the resource. + \value WebEngineDownloadRequest.ServerCertProblem A problem with the server certificate occurred. + \value WebEngineDownloadRequest.ServerForbidden Access forbidden by the server. + \value WebEngineDownloadRequest.ServerUnreachable Unexpected server response (might indicate that + the responding server may not be the intended server). + \value WebEngineDownloadRequest.UserCanceled The user canceled the download. + + \sa interruptReasonString +*/ + +/*! + \qmlproperty string WebEngineDownloadRequest::interruptReasonString + Returns a human-readable description of the reason for interrupting the download. + + \sa interruptReason +*/ + +/*! + \qmlproperty bool WebEngineDownloadRequest::isFinished + \readonly + + Whether this download is finished (completed, cancelled, or non-resumable interrupted state). + */ + +/*! + \qmlproperty bool WebEngineDownloadRequest::isPaused + \readonly + + Whether this download is paused. + + \sa pause, resume + */ + +/*! + \qmlproperty WebEngineView WebEngineDownloadRequest::view + \readonly + + Returns the view the download was requested on. If the download was not triggered by content in a view, + \c nullptr is returned. + + \sa WebEngineView +*/ diff --git a/src/webengine/doc/src/webengineview_lgpl.qdoc b/src/webengine/doc/src/webengineview_lgpl.qdoc index 0cd8441cf..2be475903 100644 --- a/src/webengine/doc/src/webengineview_lgpl.qdoc +++ b/src/webengine/doc/src/webengineview_lgpl.qdoc @@ -1065,61 +1065,6 @@ */ /*! - \qmltype FullScreenRequest - \instantiates QQuickWebEngineFullScreenRequest - \inqmlmodule QtWebEngine - \since QtWebEngine 1.1 - - \brief A utility type for the WebEngineView::fullScreenRequested() signal. - - \sa WebEngineView::fullScreenRequested() -*/ - -/*! - \qmlproperty url FullScreenRequest::origin - \readonly - The URL of the web page that issued the fullscreen request. -*/ - -/*! - \qmlproperty bool FullScreenRequest::toggleOn - \readonly - - Returns \c{true} if the application should toggle fullscreen mode on, \c{false} otherwise. - - \sa accept() -*/ - -/*! - \qmlmethod void FullScreenRequest::accept() - - Call this method to accept the fullscreen request. It sets the WebEngineView::isFullScreen - property to be equal to toggleOn. - - \qml - ApplicationWindow { - id: window - WebEngineView { - onFullScreenRequested: function(request) { - if (request.toggleOn) - window.showFullScreen() - else - window.showNormal() - request.accept() - } - } - } - \endqml - - \sa toggleOn -*/ - -/*! - \qmlmethod void FullScreenRequest::reject() - Rejects a fullscreen request. -*/ - -/*! \qmlproperty bool WebEngineView::audioMuted \brief The state of whether the current page audio is muted. \since QtWebEngine 1.3 @@ -1332,53 +1277,6 @@ */ /*! - \qmltype QuotaRequest - \instantiates QWebEngineQuotaRequest - \inqmlmodule QtWebEngine - \since QtWebEngine 1.7 - - \brief A utility type for the WebEngineView::quotaRequested() signal. - - \sa WebEngineView::quotaRequested() -*/ - -/*! - \qmlproperty url QuotaRequest::origin - \readonly - - The URL of the web page that issued the quota request. -*/ - -/*! - \qmlproperty qint64 QuotaRequest::requestedSize - \readonly - - Contains the size of the requested disk space in bytes. -*/ - -/*! - \qmlmethod void QuotaRequest::accept() - - Accepts the quota request. - - \qml - WebEngineView { - onQuotaRequested: function(request) { - if (request.requestedSize <= 5 * 1024 * 1024) - request.accept(); - else - request.reject(); - } - } - \endqml -*/ - -/*! - \qmlmethod void QuotaRequest::reject() - Rejects the quota request. -*/ - -/*! \qmlsignal WebEngineView::registerProtocolHandlerRequested(RegisterProtocolHandlerRequest request) \since QtWebEngine 1.7 @@ -1389,45 +1287,6 @@ */ /*! - \qmltype RegisterProtocolHandlerRequest - \instantiates QWebEngineRegisterProtocolHandlerRequest - \inqmlmodule QtWebEngine - \since QtWebEngine 1.7 - \brief The RegisterProtocolHandlerRequest type enables accepting - or rejecting requests from the \l registerProtocolHandler API. - - \sa WebEngineView::registerProtocolHandlerRequested() -*/ - -/*! - \qmlproperty url RegisterProtocolHandlerRequest::origin - \brief The URL template for the protocol handler. - - This is the second parameter from the \l registerProtocolHandler call. -*/ - -/*! - \qmlproperty string RegisterProtocolHandlerRequest::scheme - \brief The URL scheme for the protocol handler. - - This is the first parameter from the \l registerProtocolHandler call. -*/ - -/*! - \qmlmethod void RegisterProtocolHandlerRequest::accept() - \brief Accepts the request. - - Subsequent calls to accept() and reject() are ignored. -*/ - -/*! - \qmlmethod void RegisterProtocolHandlerRequest::reject() - \brief Accepts the request. - - Subsequent calls to accept() and reject() are ignored. -*/ - -/*! \qmlsignal WebEngineView::geometryChangeRequested(rect geometry, rect frameGeometry) \since QtWebEngine 1.7 @@ -1626,7 +1485,6 @@ \sa renderProcessPidChanged */ - /*! \qmlsignal WebEngineView::renderProcessPidChanged(qint64 pid) \since QtWebEngine 1.11 diff --git a/src/webengine/module.pro b/src/webengine/module.pro index 49a1086b2..8b1cab596 100644 --- a/src/webengine/module.pro +++ b/src/webengine/module.pro @@ -1,5 +1,5 @@ include($$QTWEBENGINE_OUT_ROOT/src/webengine/qtwebengine-config.pri) -QT_FOR_CONFIG += webengine-private +QT_FOR_CONFIG += webengine-private webenginecore-private TARGET = QtWebEngine MODULE = webengine @@ -16,11 +16,8 @@ INCLUDEPATH += $$PWD api ../core ../core/api SOURCES = \ api/qquickwebengineaction.cpp \ - api/qquickwebenginecertificateerror.cpp \ api/qquickwebengineclientcertificateselection.cpp \ - api/qquickwebenginecontextmenurequest.cpp \ api/qquickwebenginedialogrequests.cpp \ - api/qquickwebenginedownloaditem.cpp \ api/qquickwebenginehistory.cpp \ api/qquickwebenginefaviconprovider.cpp \ api/qquickwebengineloadrequest.cpp \ @@ -42,12 +39,8 @@ HEADERS = \ api/qtwebengineglobal_p.h \ api/qquickwebengineaction_p.h \ api/qquickwebengineaction_p_p.h \ - api/qquickwebenginecertificateerror_p.h \ api/qquickwebengineclientcertificateselection_p.h \ - api/qquickwebenginecontextmenurequest_p.h \ api/qquickwebenginedialogrequests_p.h \ - api/qquickwebenginedownloaditem_p.h \ - api/qquickwebenginedownloaditem_p_p.h \ api/qquickwebenginehistory_p.h \ api/qquickwebenginefaviconprovider_p_p.h \ api/qquickwebengineloadrequest_p.h \ diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index a74373b23..2dad9fefc 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -40,11 +40,8 @@ #include <QtQml/qqmlextensionplugin.h> #include <QtWebEngine/QQuickWebEngineProfile> -#include <QtWebEngine/private/qquickwebenginecertificateerror_p.h> #include <QtWebEngine/private/qquickwebengineclientcertificateselection_p.h> -#include <QtWebEngine/private/qquickwebenginecontextmenurequest_p.h> #include <QtWebEngine/private/qquickwebenginedialogrequests_p.h> -#include <QtWebEngine/private/qquickwebenginedownloaditem_p.h> #include <QtWebEngine/private/qquickwebenginehistory_p.h> #include <QtWebEngine/private/qquickwebenginefaviconprovider_p_p.h> #include <QtWebEngine/private/qquickwebengineloadrequest_p.h> @@ -55,10 +52,13 @@ #include <QtWebEngine/private/qquickwebenginetouchhandleprovider_p_p.h> #include <QtWebEngine/private/qquickwebengineview_p.h> #include <QtWebEngine/private/qquickwebengineaction_p.h> +#include <QtWebEngineCore/qwebenginecertificateerror.h> #include <QtWebEngineCore/qwebenginefindtextresult.h> #include <QtWebEngineCore/qwebenginenotification.h> #include <QtWebEngineCore/qwebenginequotarequest.h> #include <QtWebEngineCore/qwebengineregisterprotocolhandlerrequest.h> +#include <QtWebEngineCore/qwebenginecontextmenurequest.h> +#include <QtWebEngineCore/qwebenginedownloadrequest.h> QT_BEGIN_NAMESPACE @@ -105,25 +105,10 @@ public: qmlRegisterType<QQuickWebEngineProfile, 4>(uri, 1, 5, "WebEngineProfile"); qmlRegisterType<QQuickWebEngineProfile, 5>(uri, 1, 9, "WebEngineProfile"); qmlRegisterType<QQuickWebEngineScript>(uri, 1, 1, "WebEngineScript"); - qmlRegisterUncreatableType<QQuickWebEngineCertificateError>(uri, 1, 1, "WebEngineCertificateError", msgUncreatableType("WebEngineCertificateError")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem>(uri, 1, 1, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 1>(uri, 1, 2, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 2>(uri, 1, 3, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 3>(uri, 1, 4, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 4>(uri, 1, 5, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 5>(uri, 1, 6, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 6>(uri, 1, 7, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 7>(uri, 1, 8, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); - qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 10>(uri, 1, 10, "WebEngineDownloadItem", - msgUncreatableType("WebEngineDownloadItem")); + qRegisterMetaType<QWebEngineCertificateError>(); + qmlRegisterUncreatableType<QWebEngineCertificateError>(uri, 1, 1, "WebEngineCertificateError", msgUncreatableType("WebEngineCertificateError")); + qmlRegisterUncreatableType<QWebEngineDownloadRequest>(uri, 1, 1, "WebEngineDownloadRequest", + msgUncreatableType("WebEngineDownloadRequest")); qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest>(uri, 1, 1, "WebEngineNewViewRequest", msgUncreatableType("WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest, 1>(uri, 1, 5, "WebEngineNewViewRequest", tr("Cannot create separate instance of WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineSettings>(uri, 1, 1, "WebEngineSettings", msgUncreatableType("WebEngineSettings")); @@ -144,10 +129,8 @@ public: qmlRegisterUncreatableType<QQuickWebEngineFullScreenRequest>(uri, 1, 1, "FullScreenRequest", msgUncreatableType("FullScreenRequest")); - qmlRegisterUncreatableType<QQuickWebEngineContextMenuRequest>(uri, 1, 4, "ContextMenuRequest", - msgUncreatableType("ContextMenuRequest")); - qmlRegisterUncreatableType<QQuickWebEngineContextMenuRequest, 1>(uri, 1, 7, "ContextMenuRequest", - msgUncreatableType("ContextMenuRequest")); + qmlRegisterUncreatableType<QWebEngineContextMenuRequest, 1>( + uri, 1, 7, "ContextMenuRequest", msgUncreatableType("ContextMenuRequest")); qmlRegisterUncreatableType<QQuickWebEngineAuthenticationDialogRequest>(uri, 1, 4, "AuthenticationDialogRequest", msgUncreatableType("AuthenticationDialogRequest")); qmlRegisterUncreatableType<QQuickWebEngineJavaScriptDialogRequest>(uri, 1, 4, "JavaScriptDialogRequest", diff --git a/src/webengine/plugin/plugins.qmltypes b/src/webengine/plugin/plugins.qmltypes index 24b073290..8f0a848d5 100644 --- a/src/webengine/plugin/plugins.qmltypes +++ b/src/webengine/plugin/plugins.qmltypes @@ -320,8 +320,7 @@ Module { Method { name: "dialogReject" } } Component { - name: "QQuickWebEngineCertificateError" - prototype: "QObject" + name: "QWebEngineCertificateError" exports: ["QtWebEngine/WebEngineCertificateError 1.1"] isCreatable: false exportMetaObjectRevisions: [0] @@ -1371,7 +1370,7 @@ Module { Signal { name: "certificateError" revision: 1 - Parameter { name: "error"; type: "QQuickWebEngineCertificateError"; isPointer: true } + Parameter { name: "error"; type: "QWebEngineCertificateError" } } Signal { name: "fullScreenRequested" diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index 6a5bef16d..6fcf7f3ac 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -39,14 +39,18 @@ #include "render_widget_host_view_qt_delegate_quick.h" +#include "render_widget_host_view_qt_delegate_client.h" + #include "qquickwebengineview_p.h" #include "qquickwebengineview_p_p.h" #include <QGuiApplication> +#include <QOpenGLContext> #include <QQuickPaintedItem> #include <QQuickWindow> #include <QSurfaceFormat> #include <QVariant> #include <QWindow> +#include <QtQuick/qsgimagenode.h> #include <QtQuick/private/qquickwindow_p.h> namespace QtWebEngineCore { @@ -62,29 +66,12 @@ RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderW return; setFocus(true); setActiveFocusOnTab(true); - -#if defined(Q_OS_MACOS) && QT_CONFIG(opengl) - // Check that the default QSurfaceFormat OpenGL profile is compatible with the global OpenGL - // shared context profile, otherwise this could lead to a nasty crash. - QOpenGLContext *globalSharedContext = QOpenGLContext::globalShareContext(); - if (globalSharedContext) { - QSurfaceFormat sharedFormat = globalSharedContext->format(); - QSurfaceFormat defaultFormat = QSurfaceFormat::defaultFormat(); - - if (defaultFormat.profile() != sharedFormat.profile() - && defaultFormat.profile() == QSurfaceFormat::CoreProfile - && defaultFormat.version() >= qMakePair(3, 2)) { - qFatal("QWebEngine: Default QSurfaceFormat OpenGL profile is not compatible with the " - "global shared context OpenGL profile. Please make sure you set a compatible " - "QSurfaceFormat before the QtGui application instance is created."); - } - } -#endif - + bind(client->compositorId()); } RenderWidgetHostViewQtDelegateQuick::~RenderWidgetHostViewQtDelegateQuick() { + unbind(); QQuickWebEngineViewPrivate::bindViewAndWidget(nullptr, this); } @@ -163,30 +150,10 @@ QWindow* RenderWidgetHostViewQtDelegateQuick::window() const return QQuickItem::window(); } -QSGTexture *RenderWidgetHostViewQtDelegateQuick::createTextureFromImage(const QImage &image) -{ - return QQuickItem::window()->createTextureFromImage(image, QQuickWindow::TextureCanUseAtlas); -} - -QSGLayer *RenderWidgetHostViewQtDelegateQuick::createLayer() -{ - QSGRenderContext *renderContext = QQuickWindowPrivate::get(QQuickItem::window())->context; - return renderContext->sceneGraphContext()->createLayer(renderContext); -} - -QSGImageNode *RenderWidgetHostViewQtDelegateQuick::createImageNode() -{ - return QQuickItem::window()->createImageNode(); -} - -QSGRectangleNode *RenderWidgetHostViewQtDelegateQuick::createRectangleNode() +void RenderWidgetHostViewQtDelegateQuick::readyToSwap() { - return QQuickItem::window()->createRectangleNode(); -} - -void RenderWidgetHostViewQtDelegateQuick::update() -{ - QQuickItem::update(); + // Call update() on UI thread. + QMetaObject::invokeMethod(this, &QQuickItem::update, Qt::QueuedConnection); } void RenderWidgetHostViewQtDelegateQuick::updateCursor(const QCursor &cursor) @@ -305,7 +272,8 @@ void RenderWidgetHostViewQtDelegateQuick::hoverMoveEvent(QHoverEvent *event) { QQuickItem *parent = parentItem(); if ((!m_isPopup && parent && !parent->property("activeFocusOnPress").toBool() - && !parent->hasActiveFocus()) || event->posF() == event->oldPosF()) { + && !parent->hasActiveFocus()) + || event->position() == event->oldPosF()) { event->ignore(); return; } @@ -327,9 +295,9 @@ void RenderWidgetHostViewQtDelegateQuick::inputMethodEvent(QInputMethodEvent *ev m_client->forwardEvent(event); } -void RenderWidgetHostViewQtDelegateQuick::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +void RenderWidgetHostViewQtDelegateQuick::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) { - QQuickItem::geometryChanged(newGeometry, oldGeometry); + QQuickItem::geometryChange(newGeometry, oldGeometry); m_client->visualPropertiesChanged(); } @@ -341,6 +309,8 @@ void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const It disconnect(c); m_windowConnections.clear(); if (value.window) { + m_windowConnections.append(connect(value.window, SIGNAL(beforeRendering()), + SLOT(onBeforeRendering()), Qt::DirectConnection)); m_windowConnections.append(connect(value.window, SIGNAL(xChanged(int)), SLOT(onWindowPosChanged()))); m_windowConnections.append(connect(value.window, SIGNAL(yChanged(int)), SLOT(onWindowPosChanged()))); if (!m_isPopup) @@ -355,7 +325,55 @@ void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const It QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { - return m_client->updatePaintNode(oldNode); + auto comp = compositor(); + if (!comp) + return nullptr; + + QQuickWindow *win = QQuickItem::window(); + + // Delete old node before swapFrame to decrement refcount of + // QImage in software mode. + delete oldNode; + QSGImageNode *node = win->createImageNode(); + node->setOwnsTexture(true); + + comp->swapFrame(); + + QSize texSize = comp->size(); + QSizeF texSizeInDips = QSizeF(texSize) / comp->devicePixelRatio(); + node->setRect(QRectF(QPointF(0, 0), texSizeInDips)); + + if (comp->type() == Compositor::Type::Software) { + QImage image = comp->image(); + node->setTexture(win->createTextureFromImage(image)); + } else if (comp->type() == Compositor::Type::OpenGL) { + QQuickWindow::CreateTextureOptions texOpts; + if (comp->hasAlphaChannel()) + texOpts.setFlag(QQuickWindow::TextureHasAlphaChannel); + int texId = comp->textureId(); + node->setTexture(win->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture, + texId, 0, texSize, texOpts)); + node->setTextureCoordinatesTransform(QSGImageNode::MirrorVertically); + } else { + Q_UNREACHABLE(); + } + +#if QT_CONFIG(webengine_testsupport) + if (m_view) + QMetaObject::invokeMethod( + m_view, [view = m_view]() { view->d_ptr->didCompositorFrameSwap(); }, + Qt::QueuedConnection); +#endif + + return node; +} + +void RenderWidgetHostViewQtDelegateQuick::onBeforeRendering() +{ + auto comp = compositor(); + if (!comp || comp->type() != Compositor::Type::OpenGL) + return; + comp->waitForTexture(); } void RenderWidgetHostViewQtDelegateQuick::onWindowPosChanged() @@ -369,17 +387,6 @@ void RenderWidgetHostViewQtDelegateQuick::onHide() m_client->forwardEvent(&event); } -bool RenderWidgetHostViewQtDelegateQuick::copySurface(const QRect &rect, const QSize &size, QImage &image) -{ - image = QQuickItem::window()->grabWindow(); - if (image.isNull()) - return false; - QRect subrect = !rect.isEmpty() ? rect : image.rect(); - image = image.copy(subrect); - image = image.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - return true; -} - #if QT_CONFIG(accessibility) RenderWidgetHostViewQtDelegateQuickAccessible::RenderWidgetHostViewQtDelegateQuickAccessible(RenderWidgetHostViewQtDelegateQuick *o, QQuickWebEngineView *view) : QAccessibleObject(o) diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h index f70de50d7..d7ff0ffe9 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.h @@ -40,6 +40,7 @@ #ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_QUICK_H #define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_QUICK_H +#include "compositor/compositor.h" #include "render_widget_host_view_qt_delegate.h" #include <QAccessibleObject> @@ -53,7 +54,11 @@ QT_END_NAMESPACE namespace QtWebEngineCore { -class RenderWidgetHostViewQtDelegateQuick : public QQuickItem, public RenderWidgetHostViewQtDelegate +class RenderWidgetHostViewQtDelegateClient; + +class RenderWidgetHostViewQtDelegateQuick : public QQuickItem, + public RenderWidgetHostViewQtDelegate, + public Compositor::Observer { Q_OBJECT public: @@ -71,11 +76,6 @@ public: void hide() override; bool isVisible() const override; QWindow* window() const override; - QSGTexture *createTextureFromImage(const QImage &) override; - QSGLayer *createLayer() override; - QSGImageNode *createImageNode() override; - QSGRectangleNode *createRectangleNode() override; - void update() override; void updateCursor(const QCursor &) override; void resize(int width, int height) override; void move(const QPoint&) override { } @@ -83,7 +83,8 @@ public: void setInputMethodHints(Qt::InputMethodHints) override { } // The QtQuick view doesn't have a backbuffer of its own and doesn't need this void setClearColor(const QColor &) override { } - bool copySurface(const QRect &rect, const QSize &size, QImage &image) override; + + void readyToSwap() override; protected: bool event(QEvent *event) override; @@ -100,11 +101,12 @@ protected: void hoverLeaveEvent(QHoverEvent *event) override; QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; void inputMethodEvent(QInputMethodEvent *event) override; - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; void itemChange(ItemChange change, const ItemChangeData &value) override; QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; private slots: + void onBeforeRendering(); void onWindowPosChanged(); void onHide(); diff --git a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp index 1de4d8835..0b7e736ad 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp @@ -121,32 +121,6 @@ QWindow *RenderWidgetHostViewQtDelegateQuickWindow::window() const return const_cast<RenderWidgetHostViewQtDelegateQuickWindow*>(this); } -QSGTexture *RenderWidgetHostViewQtDelegateQuickWindow::createTextureFromImage(const QImage &image) -{ - return m_realDelegate->createTextureFromImage(image); -} - -QSGLayer *RenderWidgetHostViewQtDelegateQuickWindow::createLayer() -{ - return m_realDelegate->createLayer(); -} - -QSGImageNode *RenderWidgetHostViewQtDelegateQuickWindow::createImageNode() -{ - return m_realDelegate->createImageNode(); -} - -QSGRectangleNode *RenderWidgetHostViewQtDelegateQuickWindow::createRectangleNode() -{ - return m_realDelegate->createRectangleNode(); -} - -void RenderWidgetHostViewQtDelegateQuickWindow::update() -{ - QQuickWindow::update(); - m_realDelegate->update(); -} - void RenderWidgetHostViewQtDelegateQuickWindow::updateCursor(const QCursor &cursor) { setCursor(cursor); diff --git a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h index bebbfa439..c05e14266 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h @@ -66,18 +66,12 @@ public: void hide() override; bool isVisible() const override; QWindow* window() const override; - QSGTexture *createTextureFromImage(const QImage &) override; - QSGLayer *createLayer() override; - QSGImageNode *createImageNode() override; - QSGRectangleNode *createRectangleNode() override; - void update() override; void updateCursor(const QCursor &) override; void resize(int width, int height) override; void move(const QPoint &screenPos) override; void inputMethodStateChanged(bool, bool) override {} void setInputMethodHints(Qt::InputMethodHints) override { } void setClearColor(const QColor &) override { } - bool copySurface(const QRect &, const QSize &, QImage &) override { return false; } void setVirtualParent(QQuickItem *virtualParent); |