summaryrefslogtreecommitdiffstats
path: root/src/webengine/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/api')
-rw-r--r--src/webengine/api/qquickwebengineaction.cpp172
-rw-r--r--src/webengine/api/qquickwebengineaction_p.h108
-rw-r--r--src/webengine/api/qquickwebengineaction_p_p.h86
-rw-r--r--src/webengine/api/qquickwebenginecontextmenurequest_p.h2
-rw-r--r--src/webengine/api/qquickwebenginedialogrequests_p.h2
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp91
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p.h5
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p_p.h7
-rw-r--r--src/webengine/api/qquickwebenginefaviconprovider_p_p.h2
-rw-r--r--src/webengine/api/qquickwebenginehistory_p.h2
-rw-r--r--src/webengine/api/qquickwebengineloadrequest_p.h2
-rw-r--r--src/webengine/api/qquickwebenginenavigationrequest_p.h1
-rw-r--r--src/webengine/api/qquickwebenginenewviewrequest_p.h2
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp186
-rw-r--r--src/webengine/api/qquickwebengineprofile.h5
-rw-r--r--src/webengine/api/qquickwebengineprofile_p.h21
-rw-r--r--src/webengine/api/qquickwebenginesettings.cpp22
-rw-r--r--src/webengine/api/qquickwebenginesettings_p.h8
-rw-r--r--src/webengine/api/qquickwebenginesingleton_p.h2
-rw-r--r--src/webengine/api/qquickwebenginetestsupport_p.h4
-rw-r--r--src/webengine/api/qquickwebengineview.cpp569
-rw-r--r--src/webengine/api/qquickwebengineview_p.h18
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h26
23 files changed, 1042 insertions, 301 deletions
diff --git a/src/webengine/api/qquickwebengineaction.cpp b/src/webengine/api/qquickwebengineaction.cpp
new file mode 100644
index 000000000..a0be20b54
--- /dev/null
+++ b/src/webengine/api/qquickwebengineaction.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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 "qquickwebengineaction_p.h"
+#include "qquickwebengineaction_p_p.h"
+#include "qquickwebengineview_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype WebEngineAction
+ \instantiates QQuickWebEngineAction
+ \inqmlmodule QtWebEngine
+ \since QtWebEngine 1.8
+
+ \brief An action that represents a \l WebEngineView::WebAction
+
+ A WebEngineAction is returned by the \l WebEngineView::action()
+ method. It provides information about the action, such as
+ whether it is \l enabled.
+
+ The following code uses the \l WebEngineView::action() method to check if the
+ the copy action is enabled:
+
+ \code
+ var copyAction = webEngineView.action(WebEngineView.Copy);
+ if (copyAction.enabled)
+ console.log("Copy is enabled.");
+ else
+ console.log("Copy is disabled.");
+ \endcode
+*/
+
+QQuickWebEngineActionPrivate::QQuickWebEngineActionPrivate(const QVariant &data, const QString &text, const QString &iconText, bool enabled)
+ : m_data(data)
+ , m_text(text)
+ , m_iconText(iconText)
+ , m_enabled(enabled)
+{
+}
+
+QQuickWebEngineActionPrivate::~QQuickWebEngineActionPrivate()
+{
+}
+
+void QQuickWebEngineActionPrivate::setEnabled(bool enabled)
+{
+ Q_Q(QQuickWebEngineAction);
+ if (m_enabled == enabled)
+ return;
+ m_enabled = enabled;
+ emit q->enabledChanged(enabled);
+}
+
+QVariant QQuickWebEngineActionPrivate::data() const
+{
+ return m_data;
+}
+
+void QQuickWebEngineActionPrivate::trigger()
+{
+ Q_Q(QQuickWebEngineAction);
+ if (QQuickWebEngineView *view = static_cast<QQuickWebEngineView*>(q->parent())) {
+ view->triggerWebAction(static_cast<QQuickWebEngineView::WebAction>(data().toInt()));
+ }
+}
+
+QQuickWebEngineAction::QQuickWebEngineAction(const QVariant &data, const QString &text, const QString &iconText, bool enabled, QObject *parent)
+ : QObject(parent)
+ , d_ptr(new QQuickWebEngineActionPrivate(data, text, iconText, enabled))
+{
+ d_ptr->q_ptr = this;
+}
+
+QQuickWebEngineAction::QQuickWebEngineAction(QObject *parent)
+ : QObject(parent)
+ , d_ptr(new QQuickWebEngineActionPrivate(-1, QStringLiteral(""), QStringLiteral(""), false))
+{
+ d_ptr->q_ptr = this;
+}
+
+QQuickWebEngineAction::~QQuickWebEngineAction()
+{
+}
+
+/*!
+ \qmlproperty int WebEngineAction::text
+
+ This property holds a textual description of the action.
+*/
+QString QQuickWebEngineAction::text() const
+{
+ Q_D(const QQuickWebEngineAction);
+ return d->m_text;
+}
+
+/*!
+ \qmlproperty string WebEngineAction::iconText
+
+ This property holds the action's descriptive icon text.
+*/
+QString QQuickWebEngineAction::iconText() const
+{
+ Q_D(const QQuickWebEngineAction);
+ return d->m_iconText;
+}
+
+/*!
+ \qmlproperty bool WebEngineAction::enabled
+
+ This property holds whether the action is enabled.
+*/
+bool QQuickWebEngineAction::isEnabled() const
+{
+ Q_D(const QQuickWebEngineAction);
+ return d->m_enabled;
+}
+
+/*!
+ \qmlmethod void WebEngineAction::trigger()
+
+ Triggers the action.
+*/
+void QQuickWebEngineAction::trigger()
+{
+ Q_D(QQuickWebEngineAction);
+ if (!isEnabled())
+ return;
+
+ d->trigger();
+ emit triggered();
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/webengine/api/qquickwebengineaction_p.h b/src/webengine/api/qquickwebengineaction_p.h
new file mode 100644
index 000000000..5296f9dd6
--- /dev/null
+++ b/src/webengine/api/qquickwebengineaction_p.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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 QQUICKWEBENGINEACTION_P_H
+#define QQUICKWEBENGINEACTION_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 <QtQml/qqml.h>
+#include "qtwebengineglobal_p.h"
+#include <QVariant>
+
+namespace QtWebEngineCore {
+ class UIDelegatesManager;
+ class UI2DelegatesManager;
+}
+
+QT_BEGIN_NAMESPACE
+
+class QQuickWebEngineActionPrivate;
+
+class Q_WEBENGINE_EXPORT QQuickWebEngineAction : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text CONSTANT FINAL)
+ Q_PROPERTY(QString iconText READ iconText CONSTANT FINAL)
+ Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged FINAL)
+
+public:
+ QQuickWebEngineAction(const QVariant &data, const QString &text, const QString &iconText, bool enabled, QObject *parent);
+ QQuickWebEngineAction(QObject *parent);
+ ~QQuickWebEngineAction();
+
+ QString text() const;
+ QString iconText() const;
+ bool isEnabled() const;
+
+public Q_SLOTS:
+ Q_INVOKABLE void trigger();
+
+Q_SIGNALS:
+ void toggled();
+ void triggered();
+ void enabledChanged(const bool enabled);
+
+private:
+ Q_DECLARE_PRIVATE(QQuickWebEngineAction)
+ friend class QQuickWebEngineView;
+ friend class QQuickWebEngineViewPrivate;
+ friend class QtWebEngineCore::UIDelegatesManager;
+ friend class QtWebEngineCore::UI2DelegatesManager;
+ friend class QQuickContextMenuBuilder;
+
+ QScopedPointer<QQuickWebEngineActionPrivate> d_ptr;
+};
+
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickWebEngineAction)
+
+#endif // QQUICKWEBENGINEACTION_P_H
diff --git a/src/webengine/api/qquickwebengineaction_p_p.h b/src/webengine/api/qquickwebengineaction_p_p.h
new file mode 100644
index 000000000..cb1817e55
--- /dev/null
+++ b/src/webengine/api/qquickwebengineaction_p_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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 QQUICKWEBENGINEACTION_P_P_H
+#define QQUICKWEBENGINEACTION_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 <QObject>
+#include "qtwebengineglobal_p.h"
+#include <QVariant>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickWebEngineAction;
+
+class QQuickWebEngineActionPrivate
+{
+public:
+ Q_DECLARE_PUBLIC(QQuickWebEngineAction)
+ QQuickWebEngineActionPrivate(const QVariant &data, const QString &text, const QString &iconText, bool enabled);
+ ~QQuickWebEngineActionPrivate();
+
+ void setEnabled(bool enabled);
+
+ QVariant data() const;
+
+ void trigger();
+
+private:
+ QQuickWebEngineAction *q_ptr;
+
+ QVariant m_data;
+ QString m_text;
+ QString m_iconText;
+ bool m_enabled;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKWEBENGINEACTION_P_P_H
diff --git a/src/webengine/api/qquickwebenginecontextmenurequest_p.h b/src/webengine/api/qquickwebenginecontextmenurequest_p.h
index 245955788..bc50eccb8 100644
--- a/src/webengine/api/qquickwebenginecontextmenurequest_p.h
+++ b/src/webengine/api/qquickwebenginecontextmenurequest_p.h
@@ -50,7 +50,7 @@
//
// We mean it.
-#include <private/qtwebengineglobal_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QtCore/QScopedPointer>
#include <QtCore/QObject>
#include <QtCore/QUrl>
diff --git a/src/webengine/api/qquickwebenginedialogrequests_p.h b/src/webengine/api/qquickwebenginedialogrequests_p.h
index d8a0e004c..cdb10c26b 100644
--- a/src/webengine/api/qquickwebenginedialogrequests_p.h
+++ b/src/webengine/api/qquickwebenginedialogrequests_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <private/qtwebengineglobal_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QtCore/QUrl>
#include <QtCore/QWeakPointer>
#include <QtCore/QRect>
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp
index 4f60083c8..4dce4ecd9 100644
--- a/src/webengine/api/qquickwebenginedownloaditem.cpp
+++ b/src/webengine/api/qquickwebenginedownloaditem.cpp
@@ -40,50 +40,50 @@
#include "qquickwebenginedownloaditem_p.h"
#include "qquickwebenginedownloaditem_p_p.h"
-#include "browser_context_adapter.h"
+#include "profile_adapter.h"
#include "qquickwebengineprofile_p.h"
-using QtWebEngineCore::BrowserContextAdapterClient;
+using QtWebEngineCore::ProfileAdapterClient;
QT_BEGIN_NAMESPACE
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::NoReason, QQuickWebEngineDownloadItem::NoReason)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileFailed, QQuickWebEngineDownloadItem::FileFailed)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileAccessDenied, QQuickWebEngineDownloadItem::FileAccessDenied)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileNoSpace, QQuickWebEngineDownloadItem::FileNoSpace)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileNameTooLong, QQuickWebEngineDownloadItem::FileNameTooLong)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileTooLarge, QQuickWebEngineDownloadItem::FileTooLarge)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileVirusInfected, QQuickWebEngineDownloadItem::FileVirusInfected)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileTransientError, QQuickWebEngineDownloadItem::FileTransientError)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileBlocked, QQuickWebEngineDownloadItem::FileBlocked)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileSecurityCheckFailed, QQuickWebEngineDownloadItem::FileSecurityCheckFailed)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileTooShort, QQuickWebEngineDownloadItem::FileTooShort)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::FileHashMismatch, QQuickWebEngineDownloadItem::FileHashMismatch)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::NetworkFailed, QQuickWebEngineDownloadItem::NetworkFailed)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::NetworkTimeout, QQuickWebEngineDownloadItem::NetworkTimeout)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::NetworkDisconnected, QQuickWebEngineDownloadItem::NetworkDisconnected)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::NetworkServerDown, QQuickWebEngineDownloadItem::NetworkServerDown)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::NetworkInvalidRequest, QQuickWebEngineDownloadItem::NetworkInvalidRequest)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerFailed, QQuickWebEngineDownloadItem::ServerFailed)
-//ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerNoRange, QQuickWebEngineDownloadItem::ServerNoRange)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerBadContent, QQuickWebEngineDownloadItem::ServerBadContent)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerUnauthorized, QQuickWebEngineDownloadItem::ServerUnauthorized)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerCertProblem, QQuickWebEngineDownloadItem::ServerCertProblem)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerForbidden, QQuickWebEngineDownloadItem::ServerForbidden)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::ServerUnreachable, QQuickWebEngineDownloadItem::ServerUnreachable)
-ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::UserCanceled, QQuickWebEngineDownloadItem::UserCanceled)
-//ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::UserShutdown, QQuickWebEngineDownloadItem::UserShutdown)
-//ASSERT_ENUMS_MATCH(BrowserContextAdapterClient::Crash, QQuickWebEngineDownloadItem::Crash)
+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 BrowserContextAdapterClient::DownloadInProgress:
+ case ProfileAdapterClient::DownloadInProgress:
return QQuickWebEngineDownloadItem::DownloadInProgress;
- case BrowserContextAdapterClient::DownloadCompleted:
+ case ProfileAdapterClient::DownloadCompleted:
return QQuickWebEngineDownloadItem::DownloadCompleted;
- case BrowserContextAdapterClient::DownloadCancelled:
+ case ProfileAdapterClient::DownloadCancelled:
return QQuickWebEngineDownloadItem::DownloadCancelled;
- case BrowserContextAdapterClient::DownloadInterrupted:
+ case ProfileAdapterClient::DownloadInterrupted:
return QQuickWebEngineDownloadItem::DownloadInterrupted;
default:
Q_UNREACHABLE();
@@ -107,6 +107,7 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb
, receivedBytes(0)
, downloadFinished(false)
, downloadPaused(false)
+ , view(nullptr)
{
}
@@ -163,7 +164,7 @@ QQuickWebEngineDownloadItemPrivate::~QQuickWebEngineDownloadItemPrivate()
WebEngineProfile::downloadFinished
*/
-void QQuickWebEngineDownloadItemPrivate::update(const BrowserContextAdapterClient::DownloadItemInfo &info)
+void QQuickWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::DownloadItemInfo &info)
{
Q_Q(QQuickWebEngineDownloadItem);
@@ -286,7 +287,7 @@ void QQuickWebEngineDownloadItem::pause()
return;
if (d->profile)
- d->profile->d_ptr->browserContext()->pauseDownload(d->downloadId);
+ d->profile->d_ptr->profileAdapter()->pauseDownload(d->downloadId);
}
/*!
@@ -310,7 +311,7 @@ void QQuickWebEngineDownloadItem::resume()
return;
if (d->profile)
- d->profile->d_ptr->browserContext()->resumeDownload(d->downloadId);
+ d->profile->d_ptr->profileAdapter()->resumeDownload(d->downloadId);
}
/*!
@@ -557,8 +558,8 @@ QQuickWebEngineDownloadItem::DownloadInterruptReason QQuickWebEngineDownloadItem
*/
QString QQuickWebEngineDownloadItem::interruptReasonString() const
{
- return BrowserContextAdapterClient::downloadInterruptReasonToString(
- static_cast<BrowserContextAdapterClient::DownloadInterruptReason>(interruptReason()));
+ return ProfileAdapterClient::downloadInterruptReasonToString(
+ static_cast<ProfileAdapterClient::DownloadInterruptReason>(interruptReason()));
}
/*!
@@ -591,6 +592,20 @@ bool QQuickWebEngineDownloadItem::isPaused() const
return d->downloadPaused;
}
+/*!
+ \qmlproperty bool 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.
+*/
+QQuickWebEngineView *QQuickWebEngineDownloadItem::view() const
+{
+ Q_D(const QQuickWebEngineDownloadItem);
+ return d->view;
+}
+
QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate *p, QObject *parent)
: QObject(parent)
, d_ptr(p)
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h
index 1699ee9dc..d19ca4828 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <private/qtwebengineglobal_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QObject>
#include <QScopedPointer>
#include <QString>
@@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE
class QQuickWebEngineDownloadItemPrivate;
class QQuickWebEngineProfilePrivate;
+class QQuickWebEngineView;
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineDownloadItem: public QObject {
Q_OBJECT
@@ -134,6 +135,7 @@ public:
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_INVOKABLE void accept();
Q_INVOKABLE void cancel();
@@ -155,6 +157,7 @@ public:
bool isFinished() const;
bool isPaused() const;
bool isSavePageDownload() const;
+ QQuickWebEngineView *view() const;
Q_SIGNALS:
void stateChanged();
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
index 6b4f7c8d3..4b89335bd 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
@@ -51,15 +51,15 @@
// We mean it.
//
-#include "browser_context_adapter_client.h"
+#include "profile_adapter_client.h"
#include "qquickwebenginedownloaditem_p.h"
#include "qquickwebengineprofile.h"
-#include <private/qtwebengineglobal_p.h>
#include <QString>
#include <QPointer>
QT_BEGIN_NAMESPACE
class QQuickWebEngineProfilePrivate;
+class QQuickWebEngineView;
class QQuickWebEngineDownloadItemPrivate {
QQuickWebEngineDownloadItem *q_ptr;
@@ -81,8 +81,9 @@ public:
QString downloadPath;
bool downloadFinished;
bool downloadPaused;
+ QQuickWebEngineView *view;
- void update(const QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info);
+ void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info);
void updateState(QQuickWebEngineDownloadItem::DownloadState newState);
};
diff --git a/src/webengine/api/qquickwebenginefaviconprovider_p_p.h b/src/webengine/api/qquickwebenginefaviconprovider_p_p.h
index 52f3fb7a9..18b6d61c8 100644
--- a/src/webengine/api/qquickwebenginefaviconprovider_p_p.h
+++ b/src/webengine/api/qquickwebenginefaviconprovider_p_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <private/qtwebengineglobal_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QtQuick/QQuickImageProvider>
#include <QtCore/QMap>
diff --git a/src/webengine/api/qquickwebenginehistory_p.h b/src/webengine/api/qquickwebenginehistory_p.h
index 22340e483..bf049b2a6 100644
--- a/src/webengine/api/qquickwebenginehistory_p.h
+++ b/src/webengine/api/qquickwebenginehistory_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <qtwebengineglobal.h>
+#include <QtWebEngine/qtwebengineglobal.h>
#include <QAbstractListModel>
#include <QtCore/qshareddata.h>
#include <QQuickItem>
diff --git a/src/webengine/api/qquickwebengineloadrequest_p.h b/src/webengine/api/qquickwebengineloadrequest_p.h
index aa4bc906c..6d8dd8061 100644
--- a/src/webengine/api/qquickwebengineloadrequest_p.h
+++ b/src/webengine/api/qquickwebengineloadrequest_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include "qtwebengineglobal_p.h"
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include "qquickwebengineview_p.h"
QT_BEGIN_NAMESPACE
diff --git a/src/webengine/api/qquickwebenginenavigationrequest_p.h b/src/webengine/api/qquickwebenginenavigationrequest_p.h
index 852cd03c4..55e3ca673 100644
--- a/src/webengine/api/qquickwebenginenavigationrequest_p.h
+++ b/src/webengine/api/qquickwebenginenavigationrequest_p.h
@@ -51,7 +51,6 @@
// We mean it.
//
-#include "qtwebengineglobal_p.h"
#include "qquickwebengineview_p.h"
#include <QtCore/QObject>
diff --git a/src/webengine/api/qquickwebenginenewviewrequest_p.h b/src/webengine/api/qquickwebenginenewviewrequest_p.h
index 9cc0f291f..e21f76111 100644
--- a/src/webengine/api/qquickwebenginenewviewrequest_p.h
+++ b/src/webengine/api/qquickwebenginenewviewrequest_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include "qtwebengineglobal_p.h"
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include "qquickwebengineview_p.h"
namespace QtWebEngineCore {
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index c89e4d522..f536695ef 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -44,23 +44,23 @@
#include "qquickwebengineprofile_p.h"
#include "qquickwebenginescript_p.h"
#include "qquickwebenginesettings_p.h"
+#include "qquickwebengineview_p_p.h"
#include "qwebenginecookiestore.h"
#include <QQmlEngine>
-#include "browser_context_adapter.h"
-#include <qtwebenginecoreglobal.h>
+#include "profile_adapter.h"
#include "renderer_host/user_resource_controller_host.h"
#include "web_engine_settings.h"
-using QtWebEngineCore::BrowserContextAdapter;
+using QtWebEngineCore::ProfileAdapter;
QT_BEGIN_NAMESPACE
-ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::UnknownSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::UnknownSavePageFormat)
-ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::SingleHtmlSaveFormat)
-ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::CompleteHtmlSaveFormat)
-ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::MimeHtmlSaveFormat)
+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
@@ -141,10 +141,11 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC
The \a download argument holds the state of the finished download instance.
*/
-QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter> browserContext)
+QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(ProfileAdapter *profileAdapter)
: m_settings(new QQuickWebEngineSettings())
- , m_browserContext(new QWebEngineBrowserContext(browserContext, this))
+ , 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.
@@ -153,26 +154,53 @@ QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer<Brow
QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate()
{
- Q_FOREACH (QQuickWebEngineDownloadItem *download, m_ongoingDownloads) {
+
+ while (!m_webContentsAdapterClients.isEmpty()) {
+ m_webContentsAdapterClients.first()->destroy();
+ }
+
+ if (m_profileAdapter) {
+ // In the case the user sets this profile as the parent of the interceptor
+ // it can be deleted before the browser-context still referencing it is.
+ m_profileAdapter->setRequestInterceptor(nullptr);
+ m_profileAdapter->removeClient(this);
+ }
+
+ for (QQuickWebEngineDownloadItem *download : qAsConst(m_ongoingDownloads)) {
if (download)
download->cancel();
}
m_ongoingDownloads.clear();
- if (m_browserContext)
- m_browserContext->shutdown();
+ if (m_profileAdapter != QtWebEngineCore::ProfileAdapter::defaultProfileAdapter())
+ delete m_profileAdapter;
+}
+
+void QQuickWebEngineProfilePrivate::addWebContentsAdapterClient(QQuickWebEngineViewPrivate *adapter)
+{
+ m_webContentsAdapterClients.append(adapter);
}
-QSharedPointer<QtWebEngineCore::BrowserContextAdapter> QQuickWebEngineProfilePrivate::browserContext() const
+void QQuickWebEngineProfilePrivate::removeWebContentsAdapterClient(QQuickWebEngineViewPrivate*adapter)
{
- return m_browserContext ? m_browserContext->browserContextRef : nullptr;
+ m_webContentsAdapterClients.removeAll(adapter);
+}
+
+QtWebEngineCore::ProfileAdapter *QQuickWebEngineProfilePrivate::profileAdapter() const
+{
+ return m_profileAdapter;
+}
+
+QQuickWebEngineSettings *QQuickWebEngineProfilePrivate::settings() const
+{
+ return m_settings.data();
}
void QQuickWebEngineProfilePrivate::cancelDownload(quint32 downloadId)
{
- if (m_browserContext)
- m_browserContext->browserContextRef->cancelDownload(downloadId);
+ if (m_profileAdapter)
+ m_profileAdapter->cancelDownload(downloadId);
}
void QQuickWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId)
@@ -194,6 +222,10 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>(
info.savePageFormat);
itemPrivate->type = static_cast<QQuickWebEngineDownloadItem::DownloadType>(info.downloadType);
+ if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::QmlClient)
+ itemPrivate->view = static_cast<QQuickWebEngineViewPrivate *>(info.page)->q_ptr;
+ else
+ itemPrivate->view = nullptr;
QQuickWebEngineDownloadItem *download = new QQuickWebEngineDownloadItem(itemPrivate, q);
@@ -232,7 +264,7 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info
download->d_func()->update(info);
- if (info.state != BrowserContextAdapterClient::DownloadInProgress) {
+ if (info.state != ProfileAdapterClient::DownloadInProgress) {
Q_EMIT q->downloadFinished(download);
m_ongoingDownloads.remove(info.id);
}
@@ -242,7 +274,7 @@ void QQuickWebEngineProfilePrivate::userScripts_append(QQmlListProperty<QQuickWe
{
Q_ASSERT(p && p->data);
QQuickWebEngineProfilePrivate *d = static_cast<QQuickWebEngineProfilePrivate *>(p->data);
- QtWebEngineCore::UserResourceControllerHost *resourceController = d->browserContext()->userResourceController();
+ QtWebEngineCore::UserResourceControllerHost *resourceController = d->profileAdapter()->userResourceController();
d->m_userScripts.append(script);
script->d_func()->bind(resourceController);
}
@@ -265,7 +297,7 @@ void QQuickWebEngineProfilePrivate::userScripts_clear(QQmlListProperty<QQuickWeb
{
Q_ASSERT(p && p->data);
QQuickWebEngineProfilePrivate *d = static_cast<QQuickWebEngineProfilePrivate *>(p->data);
- QtWebEngineCore::UserResourceControllerHost *resourceController = d->browserContext()->userResourceController();
+ QtWebEngineCore::UserResourceControllerHost *resourceController = d->profileAdapter()->userResourceController();
resourceController->clearAllScripts(NULL);
d->m_userScripts.clear();
}
@@ -307,10 +339,8 @@ void QQuickWebEngineProfilePrivate::userScripts_clear(QQmlListProperty<QQuickWeb
*/
QQuickWebEngineProfile::QQuickWebEngineProfile(QObject *parent)
: QObject(parent),
- d_ptr(new QQuickWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter>::create(false)))
+ d_ptr(new QQuickWebEngineProfilePrivate(new QtWebEngineCore::ProfileAdapter()))
{
- // Sets up the global WebEngineContext
- QQuickWebEngineProfile::defaultProfile();
d_ptr->q_ptr = this;
}
@@ -349,23 +379,23 @@ QQuickWebEngineProfile::~QQuickWebEngineProfile()
QString QQuickWebEngineProfile::storageName() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->storageName();
+ return d->profileAdapter()->storageName();
}
void QQuickWebEngineProfile::setStorageName(const QString &name)
{
Q_D(QQuickWebEngineProfile);
- if (d->browserContext()->storageName() == name)
+ if (d->profileAdapter()->storageName() == name)
return;
- BrowserContextAdapter::HttpCacheType oldCacheType = d->browserContext()->httpCacheType();
- BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = d->browserContext()->persistentCookiesPolicy();
- d->browserContext()->setStorageName(name);
+ ProfileAdapter::HttpCacheType oldCacheType = d->profileAdapter()->httpCacheType();
+ ProfileAdapter::PersistentCookiesPolicy oldPolicy = d->profileAdapter()->persistentCookiesPolicy();
+ d->profileAdapter()->setStorageName(name);
emit storageNameChanged();
emit persistentStoragePathChanged();
emit cachePathChanged();
- if (d->browserContext()->httpCacheType() != oldCacheType)
+ if (d->profileAdapter()->httpCacheType() != oldCacheType)
emit httpCacheTypeChanged();
- if (d->browserContext()->persistentCookiesPolicy() != oldPolicy)
+ if (d->profileAdapter()->persistentCookiesPolicy() != oldPolicy)
emit persistentCookiesPolicyChanged();
}
@@ -389,21 +419,21 @@ void QQuickWebEngineProfile::setStorageName(const QString &name)
bool QQuickWebEngineProfile::isOffTheRecord() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->isOffTheRecord();
+ return d->profileAdapter()->isOffTheRecord();
}
void QQuickWebEngineProfile::setOffTheRecord(bool offTheRecord)
{
Q_D(QQuickWebEngineProfile);
- if (d->browserContext()->isOffTheRecord() == offTheRecord)
+ if (d->profileAdapter()->isOffTheRecord() == offTheRecord)
return;
- BrowserContextAdapter::HttpCacheType oldCacheType = d->browserContext()->httpCacheType();
- BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = d->browserContext()->persistentCookiesPolicy();
- d->browserContext()->setOffTheRecord(offTheRecord);
+ ProfileAdapter::HttpCacheType oldCacheType = d->profileAdapter()->httpCacheType();
+ ProfileAdapter::PersistentCookiesPolicy oldPolicy = d->profileAdapter()->persistentCookiesPolicy();
+ d->profileAdapter()->setOffTheRecord(offTheRecord);
emit offTheRecordChanged();
- if (d->browserContext()->httpCacheType() != oldCacheType)
+ if (d->profileAdapter()->httpCacheType() != oldCacheType)
emit httpCacheTypeChanged();
- if (d->browserContext()->persistentCookiesPolicy() != oldPolicy)
+ if (d->profileAdapter()->persistentCookiesPolicy() != oldPolicy)
emit persistentCookiesPolicyChanged();
}
@@ -432,7 +462,7 @@ void QQuickWebEngineProfile::setOffTheRecord(bool offTheRecord)
QString QQuickWebEngineProfile::persistentStoragePath() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->dataPath();
+ return d->profileAdapter()->dataPath();
}
void QQuickWebEngineProfile::setPersistentStoragePath(const QString &path)
@@ -440,7 +470,7 @@ void QQuickWebEngineProfile::setPersistentStoragePath(const QString &path)
Q_D(QQuickWebEngineProfile);
if (persistentStoragePath() == path)
return;
- d->browserContext()->setDataPath(path);
+ d->profileAdapter()->setDataPath(path);
emit persistentStoragePathChanged();
}
@@ -467,7 +497,7 @@ void QQuickWebEngineProfile::setPersistentStoragePath(const QString &path)
QString QQuickWebEngineProfile::cachePath() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->cachePath();
+ return d->profileAdapter()->cachePath();
}
void QQuickWebEngineProfile::setCachePath(const QString &path)
@@ -475,7 +505,7 @@ void QQuickWebEngineProfile::setCachePath(const QString &path)
Q_D(QQuickWebEngineProfile);
if (cachePath() == path)
return;
- d->browserContext()->setCachePath(path);
+ d->profileAdapter()->setCachePath(path);
emit cachePathChanged();
}
@@ -498,15 +528,15 @@ void QQuickWebEngineProfile::setCachePath(const QString &path)
QString QQuickWebEngineProfile::httpUserAgent() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->httpUserAgent();
+ return d->profileAdapter()->httpUserAgent();
}
void QQuickWebEngineProfile::setHttpUserAgent(const QString &userAgent)
{
Q_D(QQuickWebEngineProfile);
- if (d->browserContext()->httpUserAgent() == userAgent)
+ if (d->profileAdapter()->httpUserAgent() == userAgent)
return;
- d->browserContext()->setHttpUserAgent(userAgent);
+ d->profileAdapter()->setHttpUserAgent(userAgent);
emit httpUserAgentChanged();
}
@@ -536,15 +566,15 @@ void QQuickWebEngineProfile::setHttpUserAgent(const QString &userAgent)
QQuickWebEngineProfile::HttpCacheType QQuickWebEngineProfile::httpCacheType() const
{
const Q_D(QQuickWebEngineProfile);
- return QQuickWebEngineProfile::HttpCacheType(d->browserContext()->httpCacheType());
+ return QQuickWebEngineProfile::HttpCacheType(d->profileAdapter()->httpCacheType());
}
void QQuickWebEngineProfile::setHttpCacheType(QQuickWebEngineProfile::HttpCacheType httpCacheType)
{
Q_D(QQuickWebEngineProfile);
- BrowserContextAdapter::HttpCacheType oldCacheType = d->browserContext()->httpCacheType();
- d->browserContext()->setHttpCacheType(BrowserContextAdapter::HttpCacheType(httpCacheType));
- if (d->browserContext()->httpCacheType() != oldCacheType)
+ ProfileAdapter::HttpCacheType oldCacheType = d->profileAdapter()->httpCacheType();
+ d->profileAdapter()->setHttpCacheType(ProfileAdapter::HttpCacheType(httpCacheType));
+ if (d->profileAdapter()->httpCacheType() != oldCacheType)
emit httpCacheTypeChanged();
}
@@ -573,15 +603,15 @@ void QQuickWebEngineProfile::setHttpCacheType(QQuickWebEngineProfile::HttpCacheT
QQuickWebEngineProfile::PersistentCookiesPolicy QQuickWebEngineProfile::persistentCookiesPolicy() const
{
const Q_D(QQuickWebEngineProfile);
- return QQuickWebEngineProfile::PersistentCookiesPolicy(d->browserContext()->persistentCookiesPolicy());
+ return QQuickWebEngineProfile::PersistentCookiesPolicy(d->profileAdapter()->persistentCookiesPolicy());
}
void QQuickWebEngineProfile::setPersistentCookiesPolicy(QQuickWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy)
{
Q_D(QQuickWebEngineProfile);
- BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = d->browserContext()->persistentCookiesPolicy();
- d->browserContext()->setPersistentCookiesPolicy(BrowserContextAdapter::PersistentCookiesPolicy(newPersistentCookiesPolicy));
- if (d->browserContext()->persistentCookiesPolicy() != oldPolicy)
+ ProfileAdapter::PersistentCookiesPolicy oldPolicy = d->profileAdapter()->persistentCookiesPolicy();
+ d->profileAdapter()->setPersistentCookiesPolicy(ProfileAdapter::PersistentCookiesPolicy(newPersistentCookiesPolicy));
+ if (d->profileAdapter()->persistentCookiesPolicy() != oldPolicy)
emit persistentCookiesPolicyChanged();
}
@@ -606,15 +636,15 @@ void QQuickWebEngineProfile::setPersistentCookiesPolicy(QQuickWebEngineProfile::
int QQuickWebEngineProfile::httpCacheMaximumSize() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->httpCacheMaxSize();
+ return d->profileAdapter()->httpCacheMaxSize();
}
void QQuickWebEngineProfile::setHttpCacheMaximumSize(int maximumSize)
{
Q_D(QQuickWebEngineProfile);
- if (d->browserContext()->httpCacheMaxSize() == maximumSize)
+ if (d->profileAdapter()->httpCacheMaxSize() == maximumSize)
return;
- d->browserContext()->setHttpCacheMaxSize(maximumSize);
+ d->profileAdapter()->setHttpCacheMaxSize(maximumSize);
emit httpCacheMaximumSizeChanged();
}
@@ -635,15 +665,15 @@ void QQuickWebEngineProfile::setHttpCacheMaximumSize(int maximumSize)
QString QQuickWebEngineProfile::httpAcceptLanguage() const
{
Q_D(const QQuickWebEngineProfile);
- return d->browserContext()->httpAcceptLanguage();
+ return d->profileAdapter()->httpAcceptLanguage();
}
void QQuickWebEngineProfile::setHttpAcceptLanguage(const QString &httpAcceptLanguage)
{
Q_D(QQuickWebEngineProfile);
- if (d->browserContext()->httpAcceptLanguage() == httpAcceptLanguage)
+ if (d->profileAdapter()->httpAcceptLanguage() == httpAcceptLanguage)
return;
- d->browserContext()->setHttpAcceptLanguage(httpAcceptLanguage);
+ d->profileAdapter()->setHttpAcceptLanguage(httpAcceptLanguage);
emit httpAcceptLanguageChanged();
}
@@ -657,8 +687,8 @@ void QQuickWebEngineProfile::setHttpAcceptLanguage(const QString &httpAcceptLang
QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
{
static QQuickWebEngineProfile *profile = new QQuickWebEngineProfile(
- new QQuickWebEngineProfilePrivate(BrowserContextAdapter::defaultContext()),
- BrowserContextAdapter::globalQObjectRoot());
+ new QQuickWebEngineProfilePrivate(ProfileAdapter::createDefaultProfileAdapter()),
+ ProfileAdapter::globalQObjectRoot());
return profile;
}
@@ -688,8 +718,8 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
void QQuickWebEngineProfile::setSpellCheckLanguages(const QStringList &languages)
{
Q_D(QQuickWebEngineProfile);
- if (languages != d->browserContext()->spellCheckLanguages()) {
- d->browserContext()->setSpellCheckLanguages(languages);
+ if (languages != d->profileAdapter()->spellCheckLanguages()) {
+ d->profileAdapter()->setSpellCheckLanguages(languages);
emit spellCheckLanguagesChanged();
}
}
@@ -702,7 +732,7 @@ void QQuickWebEngineProfile::setSpellCheckLanguages(const QStringList &languages
QStringList QQuickWebEngineProfile::spellCheckLanguages() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->spellCheckLanguages();
+ return d->profileAdapter()->spellCheckLanguages();
}
/*!
@@ -723,7 +753,7 @@ void QQuickWebEngineProfile::setSpellCheckEnabled(bool enable)
{
Q_D(QQuickWebEngineProfile);
if (enable != isSpellCheckEnabled()) {
- d->browserContext()->setSpellCheckEnabled(enable);
+ d->profileAdapter()->setSpellCheckEnabled(enable);
emit spellCheckEnabledChanged();
}
}
@@ -731,7 +761,7 @@ void QQuickWebEngineProfile::setSpellCheckEnabled(bool enable)
bool QQuickWebEngineProfile::isSpellCheckEnabled() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->isSpellCheckEnabled();
+ return d->profileAdapter()->isSpellCheckEnabled();
}
/*!
@@ -741,7 +771,7 @@ bool QQuickWebEngineProfile::isSpellCheckEnabled() const
QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const
{
const Q_D(QQuickWebEngineProfile);
- return d->browserContext()->cookieStore();
+ return d->profileAdapter()->cookieStore();
}
/*!
@@ -763,7 +793,7 @@ QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const
void QQuickWebEngineProfile::clearHttpCache()
{
Q_D(QQuickWebEngineProfile);
- d->browserContext()->clearHttpCache();
+ d->profileAdapter()->clearHttpCache();
}
@@ -777,7 +807,7 @@ void QQuickWebEngineProfile::clearHttpCache()
void QQuickWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor)
{
Q_D(QQuickWebEngineProfile);
- d->browserContext()->setRequestInterceptor(interceptor);
+ d->profileAdapter()->setRequestInterceptor(interceptor);
}
/*!
@@ -786,8 +816,8 @@ void QQuickWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestIntercept
const QWebEngineUrlSchemeHandler *QQuickWebEngineProfile::urlSchemeHandler(const QByteArray &scheme) const
{
const Q_D(QQuickWebEngineProfile);
- if (d->browserContext()->customUrlSchemeHandlers().contains(scheme))
- return d->browserContext()->customUrlSchemeHandlers().value(scheme);
+ if (d->profileAdapter()->customUrlSchemeHandlers().contains(scheme))
+ return d->profileAdapter()->customUrlSchemeHandlers().value(scheme);
return 0;
}
@@ -804,22 +834,26 @@ static bool checkInternalScheme(const QByteArray &scheme)
/*!
Registers a handler \a handler for custom URL scheme \a scheme in the profile.
+
+ It is recommended to first register the scheme with \l
+ QWebEngineUrlScheme::registerScheme at application startup.
*/
void QQuickWebEngineProfile::installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler)
{
Q_D(QQuickWebEngineProfile);
Q_ASSERT(handler);
- if (checkInternalScheme(scheme)) {
+ QByteArray canonicalScheme = scheme.toLower();
+ if (checkInternalScheme(canonicalScheme)) {
qWarning("Cannot install a URL scheme handler overriding internal scheme: %s", scheme.constData());
return;
}
- if (d->browserContext()->customUrlSchemeHandlers().contains(scheme)) {
- if (d->browserContext()->customUrlSchemeHandlers().value(scheme) != handler)
+ if (d->profileAdapter()->customUrlSchemeHandlers().contains(canonicalScheme)) {
+ if (d->profileAdapter()->customUrlSchemeHandlers().value(canonicalScheme) != handler)
qWarning("URL scheme handler already installed for the scheme: %s", scheme.constData());
return;
}
- d->browserContext()->addCustomUrlSchemeHandler(scheme, handler);
+ d->profileAdapter()->addCustomUrlSchemeHandler(canonicalScheme, handler);
connect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
}
@@ -832,7 +866,7 @@ void QQuickWebEngineProfile::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *
{
Q_D(QQuickWebEngineProfile);
Q_ASSERT(handler);
- if (!d->browserContext()->removeCustomUrlSchemeHandler(handler))
+ if (!d->profileAdapter()->removeCustomUrlSchemeHandler(handler))
return;
disconnect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
}
@@ -845,7 +879,7 @@ void QQuickWebEngineProfile::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *
void QQuickWebEngineProfile::removeUrlScheme(const QByteArray &scheme)
{
Q_D(QQuickWebEngineProfile);
- QWebEngineUrlSchemeHandler *handler = d->browserContext()->takeCustomUrlSchemeHandler(scheme);
+ QWebEngineUrlSchemeHandler *handler = d->profileAdapter()->takeCustomUrlSchemeHandler(scheme);
if (!handler)
return;
disconnect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
@@ -857,7 +891,7 @@ void QQuickWebEngineProfile::removeUrlScheme(const QByteArray &scheme)
void QQuickWebEngineProfile::removeAllUrlSchemeHandlers()
{
Q_D(QQuickWebEngineProfile);
- d->browserContext()->clearCustomUrlSchemeHandlers();
+ d->profileAdapter()->clearCustomUrlSchemeHandlers();
}
void QQuickWebEngineProfile::destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *obj)
diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h
index 0155c954a..9fc4f9eca 100644
--- a/src/webengine/api/qquickwebengineprofile.h
+++ b/src/webengine/api/qquickwebengineprofile.h
@@ -48,10 +48,6 @@
#include <QtCore/QString>
#include <QtQml/QQmlListProperty>
-namespace QtWebEngineCore {
-class BrowserContextAdapter;
-}
-
QT_BEGIN_NAMESPACE
class QQuickWebEngineDownloadItem;
@@ -172,6 +168,7 @@ private:
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 61968bf77..d31ded0ec 100644
--- a/src/webengine/api/qquickwebengineprofile_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p.h
@@ -51,9 +51,8 @@
// We mean it.
//
-#include "browser_context_adapter_client.h"
-#include "browser_context_adapter.h"
-#include "qwebenginebrowsercontext_p.h"
+#include "profile_adapter_client.h"
+#include "profile_adapter.h"
#include "qquickwebengineprofile_p.h"
#include <QExplicitlySharedDataPointer>
@@ -65,15 +64,18 @@ QT_BEGIN_NAMESPACE
class QQuickWebEngineDownloadItem;
class QQuickWebEngineSettings;
+class QQuickWebEngineViewPrivate;
-class QQuickWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient {
+class QQuickWebEngineProfilePrivate : public QtWebEngineCore::ProfileAdapterClient {
public:
Q_DECLARE_PUBLIC(QQuickWebEngineProfile)
- QQuickWebEngineProfilePrivate(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext);
+ QQuickWebEngineProfilePrivate(QtWebEngineCore::ProfileAdapter *profileAdapter);
~QQuickWebEngineProfilePrivate();
+ void addWebContentsAdapterClient(QQuickWebEngineViewPrivate *adapter);
+ void removeWebContentsAdapterClient(QQuickWebEngineViewPrivate *adapter);
- QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const;
- QQuickWebEngineSettings *settings() const { return m_settings.data(); }
+ QtWebEngineCore::ProfileAdapter* profileAdapter() const;
+ QQuickWebEngineSettings *settings() const;
void cancelDownload(quint32 downloadId);
void downloadDestroyed(quint32 downloadId);
@@ -88,12 +90,13 @@ public:
static void userScripts_clear(QQmlListProperty<QQuickWebEngineScript> *p);
private:
- friend class QQuickWebEngineViewPrivate;
+ friend class QQuickWebEngineView;
QQuickWebEngineProfile *q_ptr;
QScopedPointer<QQuickWebEngineSettings> m_settings;
- QPointer<QWebEngineBrowserContext> m_browserContext;
+ QPointer<QtWebEngineCore::ProfileAdapter> m_profileAdapter;
QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads;
QList<QQuickWebEngineScript *> m_userScripts;
+ QVector<QQuickWebEngineViewPrivate *> m_webContentsAdapterClients;
};
QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp
index 6203f20f1..6e96e76cf 100644
--- a/src/webengine/api/qquickwebenginesettings.cpp
+++ b/src/webengine/api/qquickwebenginesettings.cpp
@@ -443,6 +443,20 @@ bool QQuickWebEngineSettings::javascriptCanPaste() const
}
/*!
+ \qmlproperty bool WebEngineSettings::dnsPrefetchEnabled
+ \since QtWebEngine 1.8
+
+ Enables speculative prefetching of DNS records for HTML links before
+ they are activated.
+
+ Disabled by default.
+*/
+bool QQuickWebEngineSettings::dnsPrefetchEnabled() const
+{
+ return d_ptr->testAttribute(WebEngineSettings::DnsPrefetchEnabled);
+}
+
+/*!
\qmlproperty string WebEngineSettings::defaultTextEncoding
\since QtWebEngine 1.2
@@ -692,6 +706,14 @@ void QQuickWebEngineSettings::setJavascriptCanPaste(bool on)
Q_EMIT javascriptCanPasteChanged();
}
+void QQuickWebEngineSettings::setDnsPrefetchEnabled(bool on)
+{
+ bool wasOn = d_ptr->testAttribute(WebEngineSettings::DnsPrefetchEnabled);
+ d_ptr->setAttribute(WebEngineSettings::DnsPrefetchEnabled, on);
+ if (wasOn != on)
+ Q_EMIT dnsPrefetchEnabledChanged();
+}
+
void QQuickWebEngineSettings::setUnknownUrlSchemePolicy(QQuickWebEngineSettings::UnknownUrlSchemePolicy policy)
{
WebEngineSettings::UnknownUrlSchemePolicy oldPolicy = d_ptr->unknownUrlSchemePolicy();
diff --git a/src/webengine/api/qquickwebenginesettings_p.h b/src/webengine/api/qquickwebenginesettings_p.h
index 267767941..6e1aaca39 100644
--- a/src/webengine/api/qquickwebenginesettings_p.h
+++ b/src/webengine/api/qquickwebenginesettings_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <private/qtwebengineglobal_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QObject>
#include <QScopedPointer>
@@ -92,6 +92,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject {
Q_PROPERTY(bool playbackRequiresUserGesture READ playbackRequiresUserGesture WRITE setPlaybackRequiresUserGesture NOTIFY playbackRequiresUserGestureChanged REVISION 6 FINAL)
Q_PROPERTY(bool webRTCPublicInterfacesOnly READ webRTCPublicInterfacesOnly WRITE setWebRTCPublicInterfacesOnly NOTIFY webRTCPublicInterfacesOnlyChanged REVISION 6 FINAL)
Q_PROPERTY(bool javascriptCanPaste READ javascriptCanPaste WRITE setJavascriptCanPaste NOTIFY javascriptCanPasteChanged REVISION 6 FINAL)
+ Q_PROPERTY(bool dnsPrefetchEnabled READ dnsPrefetchEnabled WRITE setDnsPrefetchEnabled NOTIFY dnsPrefetchEnabledChanged REVISION 7 FINAL)
public:
enum UnknownUrlSchemePolicy {
@@ -133,6 +134,7 @@ public:
bool playbackRequiresUserGesture() const;
bool webRTCPublicInterfacesOnly() const;
bool javascriptCanPaste() const;
+ bool dnsPrefetchEnabled() const;
void setAutoLoadImages(bool on);
void setJavascriptEnabled(bool on);
@@ -163,6 +165,7 @@ public:
void setPlaybackRequiresUserGesture(bool on);
void setWebRTCPublicInterfacesOnly(bool on);
void setJavascriptCanPaste(bool on);
+ void setDnsPrefetchEnabled(bool on);
signals:
void autoLoadImagesChanged();
@@ -194,13 +197,14 @@ signals:
Q_REVISION(6) void playbackRequiresUserGestureChanged();
Q_REVISION(6) void webRTCPublicInterfacesOnlyChanged();
Q_REVISION(6) void javascriptCanPasteChanged();
+ Q_REVISION(7) void dnsPrefetchEnabledChanged();
private:
explicit QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings = 0);
Q_DISABLE_COPY(QQuickWebEngineSettings)
friend class QQuickWebEngineProfilePrivate;
friend class QQuickWebEngineViewPrivate;
-
+ friend class QQuickWebEngineView;
void setParentSettings(QQuickWebEngineSettings *parentSettings);
QScopedPointer<QtWebEngineCore::WebEngineSettings> d_ptr;
diff --git a/src/webengine/api/qquickwebenginesingleton_p.h b/src/webengine/api/qquickwebenginesingleton_p.h
index c7d946a37..ba63382e5 100644
--- a/src/webengine/api/qquickwebenginesingleton_p.h
+++ b/src/webengine/api/qquickwebenginesingleton_p.h
@@ -51,8 +51,8 @@
// We mean it.
//
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QObject>
-#include "qtwebengineglobal_p.h"
QT_BEGIN_NAMESPACE
class QQuickWebEngineProfile;
diff --git a/src/webengine/api/qquickwebenginetestsupport_p.h b/src/webengine/api/qquickwebenginetestsupport_p.h
index b601fb47c..30e6ee5c4 100644
--- a/src/webengine/api/qquickwebenginetestsupport_p.h
+++ b/src/webengine/api/qquickwebenginetestsupport_p.h
@@ -51,8 +51,8 @@
// We mean it.
//
-#include <private/qinputmethod_p.h>
-#include <private/qtwebengineglobal_p.h>
+#include <QtGui/private/qinputmethod_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include <QEvent>
#include <QObject>
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 86fea67e8..6bf23ea7b 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -39,12 +39,15 @@
#include "qquickwebengineview_p.h"
#include "qquickwebengineview_p_p.h"
-
+#include "qtwebenginecoreglobal_p.h"
#include "authentication_dialog_controller.h"
-#include "browser_context_adapter.h"
+#include "profile_adapter.h"
#include "certificate_error_controller.h"
#include "file_picker_controller.h"
#include "javascript_dialog_controller.h"
+
+#include "qquickwebengineaction_p.h"
+#include "qquickwebengineaction_p_p.h"
#include "qquickwebenginehistory_p.h"
#include "qquickwebenginecertificateerror_p.h"
#include "qquickwebenginecontextmenurequest_p.h"
@@ -59,7 +62,7 @@
#include "qwebenginequotarequest.h"
#include "qwebengineregisterprotocolhandlerrequest.h"
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
#include "qquickwebenginetestsupport_p.h"
#endif
@@ -82,13 +85,15 @@
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlProperty>
+#if QT_CONFIG(webengine_webchannel)
#include <QQmlWebChannel>
+#endif
#include <QQuickWebEngineProfile>
#include <QScreen>
#include <QUrl>
#include <QTimer>
-#include <private/qguiapplication_p.h>
-#include <qpa/qplatformintegration.h>
+#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/qpa/qplatformintegration.h>
QT_BEGIN_NAMESPACE
using namespace QtWebEngineCore;
@@ -102,12 +107,13 @@ static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *obje
}
#endif // QT_NO_ACCESSIBILITY
+static QLatin1String defaultMimeType("text/html;charset=UTF-8");
+
QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
- : adapter(QSharedPointer<WebContentsAdapter>::create())
+ : m_profile(nullptr)
+ , adapter(QSharedPointer<WebContentsAdapter>::create())
, m_history(new QQuickWebEngineHistory(this))
- , m_profile(QQuickWebEngineProfile::defaultProfile())
- , m_settings(new QQuickWebEngineSettings(m_profile->settings()))
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
, m_testSupport(0)
#endif
, contextMenuExtraItems(0)
@@ -122,9 +128,12 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
, m_isBeingAdopted(false)
, m_dpiScale(1.0)
, m_backgroundColor(Qt::white)
- , m_defaultZoomFactor(1.0)
+ , m_zoomFactor(1.0)
, m_ui2Enabled(false)
+ , m_profileInitialized(false)
{
+ memset(actions, 0, sizeof(actions));
+
QString platform = qApp->platformName().toLower();
if (platform == QLatin1Literal("eglfs"))
m_ui2Enabled = true;
@@ -152,6 +161,37 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
QQuickWebEngineViewPrivate::~QQuickWebEngineViewPrivate()
{
+ Q_ASSERT(m_profileInitialized);
+ m_profile->d_ptr->removeWebContentsAdapterClient(this);
+ adapter->stopFinding();
+ if (faviconProvider)
+ faviconProvider->detach(q_ptr);
+}
+
+void QQuickWebEngineViewPrivate::initializeProfile()
+{
+ if (!m_profileInitialized) {
+ Q_ASSERT(!adapter->isInitialized());
+ m_profileInitialized = true;
+ if (!m_profile)
+ m_profile = QQuickWebEngineProfile::defaultProfile();
+ m_profile->d_ptr->addWebContentsAdapterClient(this);
+ m_settings.reset(new QQuickWebEngineSettings(m_profile->settings()));
+ adapter->setClient(this);
+ }
+}
+
+bool QQuickWebEngineViewPrivate::profileInitialized() const
+{
+ return m_profileInitialized;
+}
+
+void QQuickWebEngineViewPrivate::destroy()
+{
+ // the profile for this web contens is about to be
+ // garbage collected, delete WebContent first and
+ // let the QQuickWebEngineView be collected later by gc.
+ delete q_ptr->d_ptr.take();
}
UIDelegatesManager *QQuickWebEngineViewPrivate::ui()
@@ -256,6 +296,11 @@ void QQuickWebEngineViewPrivate::allowCertificateError(const QSharedPointer<Cert
m_certificateErrorControllers.append(errorController);
}
+void QQuickWebEngineViewPrivate::selectClientCert(const QSharedPointer<ClientCertSelectController> &)
+{
+ // Doing nothing will free the select-controller and perform default continue.
+}
+
void QQuickWebEngineViewPrivate::runGeolocationPermissionRequest(const QUrl &url)
{
Q_Q(QQuickWebEngineView);
@@ -303,7 +348,6 @@ void QQuickWebEngineViewPrivate::urlChanged(const QUrl &url)
{
Q_Q(QQuickWebEngineView);
Q_UNUSED(url);
- explicitUrl = QUrl();
Q_EMIT q->urlChanged();
}
@@ -371,7 +415,7 @@ void QQuickWebEngineViewPrivate::loadStarted(const QUrl &provisionalUrl, bool is
{
Q_Q(QQuickWebEngineView);
if (isErrorPage) {
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
if (m_testSupport)
m_testSupport->errorPage()->loadStarted(provisionalUrl);
#endif
@@ -396,7 +440,7 @@ void QQuickWebEngineViewPrivate::loadCommitted()
void QQuickWebEngineViewPrivate::loadVisuallyCommitted()
{
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
if (m_testSupport)
Q_EMIT m_testSupport->loadVisuallyCommitted();
#endif
@@ -411,7 +455,7 @@ void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, boo
Q_Q(QQuickWebEngineView);
if (isErrorPage) {
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
if (m_testSupport)
m_testSupport->errorPage()->loadFinished(success, url);
#endif
@@ -428,9 +472,8 @@ void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, boo
return;
}
if (success) {
- explicitUrl = QUrl();
- QTimer::singleShot(0, q, [q, url]() {
- QQuickWebEngineLoadRequest loadRequest(url, QQuickWebEngineView::LoadSucceededStatus);
+ QTimer::singleShot(0, q, [q, url, errorDescription, errorCode]() {
+ QQuickWebEngineLoadRequest loadRequest(url, QQuickWebEngineView::LoadSucceededStatus, errorDescription, errorCode);
emit q->loadingChanged(&loadRequest);
});
return;
@@ -504,7 +547,7 @@ void QQuickWebEngineViewPrivate::close()
void QQuickWebEngineViewPrivate::windowCloseRejected()
{
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
if (m_testSupport)
Q_EMIT m_testSupport->windowCloseRejected();
#endif
@@ -608,9 +651,9 @@ QObject *QQuickWebEngineViewPrivate::accessibilityParentObject()
return q;
}
-QSharedPointer<BrowserContextAdapter> QQuickWebEngineViewPrivate::browserContextAdapter()
+ProfileAdapter *QQuickWebEngineViewPrivate::profileAdapter()
{
- return m_profile->d_ptr->browserContext();
+ return m_profile->d_ptr->profileAdapter();
}
WebContentsAdapter *QQuickWebEngineViewPrivate::webContentsAdapter()
@@ -618,6 +661,14 @@ WebContentsAdapter *QQuickWebEngineViewPrivate::webContentsAdapter()
return adapter.data();
}
+void QQuickWebEngineViewPrivate::printRequested()
+{
+ Q_Q(QQuickWebEngineView);
+ QTimer::singleShot(0, q, [q]() {
+ Q_EMIT q->printRequested();
+ });
+}
+
WebEngineSettings *QQuickWebEngineViewPrivate::webEngineSettings() const
{
return m_settings->d_ptr.data();
@@ -699,7 +750,7 @@ void QQuickWebEngineViewPrivate::adoptWebContents(WebContentsAdapter *webContent
return;
}
- if (webContents->browserContextAdapter() && browserContextAdapter() != webContents->browserContextAdapter()) {
+ if (webContents->profileAdapter() && profileAdapter() != webContents->profileAdapter()) {
qWarning("Can not adopt content from a different WebEngineProfile.");
return;
}
@@ -721,25 +772,22 @@ QQuickWebEngineView::QQuickWebEngineView(QQuickItem *parent)
{
Q_D(QQuickWebEngineView);
d->q_ptr = this;
- d->adapter->setClient(d);
-
this->setActiveFocusOnTab(true);
this->setFlags(QQuickItem::ItemIsFocusScope | QQuickItem::ItemAcceptsDrops);
}
QQuickWebEngineView::~QQuickWebEngineView()
{
- Q_D(QQuickWebEngineView);
- d->adapter->stopFinding();
- if (d->faviconProvider)
- d->faviconProvider->detach(this);
}
void QQuickWebEngineViewPrivate::ensureContentsAdapter()
{
+ initializeProfile();
if (!adapter->isInitialized()) {
- if (explicitUrl.isValid())
- adapter->load(explicitUrl);
+ if (!m_html.isEmpty())
+ adapter->setContent(m_html.toUtf8(), defaultMimeType, m_url);
+ else if (m_url.isValid())
+ adapter->load(m_url);
else
adapter->loadDefault();
}
@@ -749,18 +797,30 @@ void QQuickWebEngineViewPrivate::initializationFinished()
{
Q_Q(QQuickWebEngineView);
- if (m_backgroundColor != Qt::white)
- adapter->backgroundColorChanged();
+ Q_ASSERT(m_profileInitialized);
+ if (m_backgroundColor != Qt::white) {
+ adapter->setBackgroundColor(m_backgroundColor);
+ emit q->backgroundColorChanged();
+ }
+
+ if (!qFuzzyCompare(adapter->currentZoomFactor(), m_zoomFactor)) {
+ adapter->setZoomFactor(m_zoomFactor);
+ emit q->zoomFactorChanged(m_zoomFactor);
+ }
+
+#if QT_CONFIG(webengine_webchannel)
if (m_webChannel)
adapter->setWebChannel(m_webChannel, m_webChannelWorld);
- if (!qFuzzyCompare(adapter->currentZoomFactor(), m_defaultZoomFactor))
- q->setZoomFactor(m_defaultZoomFactor);
+#endif
if (devToolsView && devToolsView->d_ptr->adapter)
adapter->openDevToolsFrontend(devToolsView->d_ptr->adapter);
- Q_FOREACH (QQuickWebEngineScript *script, m_userScripts)
- script->d_func()->bind(browserContextAdapter()->userResourceController(), adapter.data());
+ for (QQuickWebEngineScript *script : qAsConst(m_userScripts))
+ script->d_func()->bind(profileAdapter()->userResourceController(), adapter.data());
+
+ if (q->window() && q->isVisible())
+ adapter->wasShown();
if (!m_isBeingAdopted)
return;
@@ -786,23 +846,61 @@ void QQuickWebEngineViewPrivate::setFullScreenMode(bool fullscreen)
}
}
+void QQuickWebEngineViewPrivate::updateAction(QQuickWebEngineView::WebAction action) const
+{
+ QQuickWebEngineAction *a = actions[action];
+ if (!a)
+ return;
+
+ bool enabled = true;
+
+ switch (action) {
+ case QQuickWebEngineView::Back:
+ enabled = adapter->canGoBack();
+ break;
+ case QQuickWebEngineView::Forward:
+ enabled = adapter->canGoForward();
+ break;
+ case QQuickWebEngineView::Stop:
+ enabled = isLoading;
+ break;
+ case QQuickWebEngineView::Reload:
+ case QQuickWebEngineView::ReloadAndBypassCache:
+ enabled = !isLoading;
+ break;
+ case QQuickWebEngineView::ViewSource:
+ enabled = adapter->canViewSource();
+ break;
+ default:
+ break;
+ }
+
+ a->d_ptr->setEnabled(enabled);
+}
+
+
QUrl QQuickWebEngineView::url() const
{
Q_D(const QQuickWebEngineView);
- return d->explicitUrl.isValid() ? d->explicitUrl : d->adapter->activeUrl();
+ if (d->adapter->isInitialized())
+ return d->adapter->activeUrl();
+ else
+ return d->m_url;
}
void QQuickWebEngineView::setUrl(const QUrl& url)
{
+ Q_D(QQuickWebEngineView);
if (url.isEmpty())
return;
- Q_D(QQuickWebEngineView);
- d->explicitUrl = url;
- if (d->adapter->isInitialized())
+ if (d->adapter->isInitialized()) {
d->adapter->load(url);
- if (!qmlEngine(this) || isComponentComplete())
- d->ensureContentsAdapter();
+ return;
+ }
+
+ d->m_url = url;
+ d->m_html.clear();
}
QUrl QQuickWebEngineView::icon() const
@@ -814,11 +912,12 @@ QUrl QQuickWebEngineView::icon() const
void QQuickWebEngineView::loadHtml(const QString &html, const QUrl &baseUrl)
{
Q_D(QQuickWebEngineView);
- d->explicitUrl = QUrl();
- if (!qmlEngine(this) || isComponentComplete())
- d->ensureContentsAdapter();
- if (d->adapter->isInitialized())
- d->adapter->setContent(html.toUtf8(), QStringLiteral("text/html;charset=UTF-8"), baseUrl);
+ d->m_url = baseUrl;
+ d->m_html = html;
+ if (d->adapter->isInitialized()) {
+ d->adapter->setContent(html.toUtf8(), defaultMimeType, baseUrl);
+ return;
+ }
}
void QQuickWebEngineView::goBack()
@@ -854,31 +953,48 @@ void QQuickWebEngineView::stop()
void QQuickWebEngineView::setZoomFactor(qreal arg)
{
Q_D(QQuickWebEngineView);
- d->m_defaultZoomFactor = arg;
-
- qreal oldFactor = d->adapter->currentZoomFactor();
- d->adapter->setZoomFactor(arg);
- if (qFuzzyCompare(oldFactor, d->adapter->currentZoomFactor()))
- return;
-
- emit zoomFactorChanged(arg);
+ if (d->adapter->isInitialized() && !qFuzzyCompare(d->m_zoomFactor, d->adapter->currentZoomFactor())) {
+ d->adapter->setZoomFactor(arg);
+ emit zoomFactorChanged(arg);
+ } else {
+ d->m_zoomFactor = arg;
+ }
}
-QQuickWebEngineProfile *QQuickWebEngineView::profile() const
+QQuickWebEngineProfile *QQuickWebEngineView::profile()
{
- Q_D(const QQuickWebEngineView);
+ Q_D(QQuickWebEngineView);
+ d->initializeProfile();
return d->m_profile;
}
void QQuickWebEngineView::setProfile(QQuickWebEngineProfile *profile)
{
Q_D(QQuickWebEngineView);
- d->setProfile(profile);
+
+ if (d->m_profile == profile)
+ return;
+
+ if (!d->profileInitialized()) {
+ d->m_profile = profile;
+ return;
+ }
+
+ if (d->m_profile)
+ d->m_profile->d_ptr->removeWebContentsAdapterClient(d);
+
+ d->m_profile = profile;
+ d->m_profile->d_ptr->addWebContentsAdapterClient(d);
+ d->m_settings->setParentSettings(profile->settings());
+
+ d->updateAdapter();
+ Q_EMIT profileChanged();
}
-QQuickWebEngineSettings *QQuickWebEngineView::settings() const
+QQuickWebEngineSettings *QQuickWebEngineView::settings()
{
- Q_D(const QQuickWebEngineView);
+ Q_D(QQuickWebEngineView);
+ d->initializeProfile();
return d->m_settings.data();
}
@@ -892,34 +1008,26 @@ QQmlListProperty<QQuickWebEngineScript> QQuickWebEngineView::userScripts()
d->userScripts_clear);
}
-void QQuickWebEngineViewPrivate::setProfile(QQuickWebEngineProfile *profile)
+void QQuickWebEngineViewPrivate::updateAdapter()
{
- Q_Q(QQuickWebEngineView);
-
- if (profile == m_profile)
- return;
- m_profile = profile;
- Q_EMIT q->profileChanged();
- m_settings->setParentSettings(profile->settings());
-
- if (adapter->browserContext() != browserContextAdapter()->browserContext()) {
- // When the profile changes we need to create a new WebContentAdapter and reload the active URL.
- bool wasInitialized = adapter->isInitialized();
- QUrl activeUrl = adapter->activeUrl();
- adapter = QSharedPointer<WebContentsAdapter>::create();
- adapter->setClient(this);
- if (wasInitialized) {
- if (explicitUrl.isValid())
- adapter->load(explicitUrl);
- else if (activeUrl.isValid())
- adapter->load(activeUrl);
- else
- adapter->loadDefault();
- }
+ // When the profile changes we need to create a new WebContentAdapter and reload the active URL.
+ bool wasInitialized = adapter->isInitialized();
+ QUrl activeUrl = adapter->activeUrl();
+ adapter = QSharedPointer<WebContentsAdapter>::create();
+ adapter->setClient(this);
+ if (wasInitialized) {
+ if (!m_html.isEmpty())
+ adapter->setContent(m_html.toUtf8(), defaultMimeType, m_url);
+ else if (m_url.isValid())
+ adapter->load(m_url);
+ else if (activeUrl.isValid())
+ adapter->load(activeUrl);
+ else
+ adapter->loadDefault();
}
}
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
QQuickWebEngineTestSupport *QQuickWebEngineView::testSupport() const
{
Q_D(const QQuickWebEngineView);
@@ -1080,7 +1188,7 @@ qreal QQuickWebEngineView::zoomFactor() const
{
Q_D(const QQuickWebEngineView);
if (!d->adapter->isInitialized())
- return d->m_defaultZoomFactor;
+ return d->m_zoomFactor;
return d->adapter->currentZoomFactor();
}
@@ -1096,8 +1204,10 @@ void QQuickWebEngineView::setBackgroundColor(const QColor &color)
if (color == d->m_backgroundColor)
return;
d->m_backgroundColor = color;
- d->adapter->backgroundColorChanged();
- emit backgroundColorChanged();
+ if (d->adapter->isInitialized()) {
+ d->adapter->setBackgroundColor(color);
+ emit backgroundColorChanged();
+ }
}
/*!
@@ -1130,7 +1240,7 @@ bool QQuickWebEngineView::recentlyAudible() const
void QQuickWebEngineView::printToPdf(const QString& filePath, PrintedPageSizeId pageSizeId, PrintedPageOrientation orientation)
{
-#if defined(ENABLE_PDF)
+#if QT_CONFIG(webengine_printing_and_pdf)
Q_D(QQuickWebEngineView);
QPageSize layoutSize(static_cast<QPageSize::PageSizeId>(pageSizeId));
QPageLayout::Orientation layoutOrientation = static_cast<QPageLayout::Orientation>(orientation);
@@ -1146,7 +1256,7 @@ void QQuickWebEngineView::printToPdf(const QString& filePath, PrintedPageSizeId
void QQuickWebEngineView::printToPdf(const QJSValue &callback, PrintedPageSizeId pageSizeId, PrintedPageOrientation orientation)
{
-#if defined(ENABLE_PDF)
+#if QT_CONFIG(webengine_printing_and_pdf)
Q_D(QQuickWebEngineView);
QPageSize layoutSize(static_cast<QPageSize::PageSizeId>(pageSizeId));
QPageLayout::Orientation layoutOrientation = static_cast<QPageLayout::Orientation>(orientation);
@@ -1209,23 +1319,31 @@ QQuickWebEngineHistory *QQuickWebEngineView::navigationHistory() const
QQmlWebChannel *QQuickWebEngineView::webChannel()
{
+#if QT_CONFIG(webengine_webchannel)
Q_D(QQuickWebEngineView);
if (!d->m_webChannel) {
d->m_webChannel = new QQmlWebChannel(this);
- d->adapter->setWebChannel(d->m_webChannel, d->m_webChannelWorld);
}
-
return d->m_webChannel;
+#endif
+ qWarning("WebEngine compiled without webchannel support");
+ return nullptr;
}
void QQuickWebEngineView::setWebChannel(QQmlWebChannel *webChannel)
{
+#if QT_CONFIG(webengine_webchannel)
Q_D(QQuickWebEngineView);
if (d->m_webChannel == webChannel)
return;
d->m_webChannel = webChannel;
- d->adapter->setWebChannel(webChannel, d->m_webChannelWorld);
+ if (d->profileInitialized())
+ d->adapter->setWebChannel(webChannel, d->m_webChannelWorld);
Q_EMIT webChannelChanged();
+#else
+ Q_UNUSED(webChannel)
+ qWarning("WebEngine compiled without webchannel support");
+#endif
}
uint QQuickWebEngineView::webChannelWorld() const
@@ -1236,12 +1354,18 @@ uint QQuickWebEngineView::webChannelWorld() const
void QQuickWebEngineView::setWebChannelWorld(uint webChannelWorld)
{
+#if QT_CONFIG(webengine_webchannel)
Q_D(QQuickWebEngineView);
if (d->m_webChannelWorld == webChannelWorld)
return;
d->m_webChannelWorld = webChannelWorld;
- d->adapter->setWebChannel(d->m_webChannel, d->m_webChannelWorld);
+ if (d->profileInitialized())
+ d->adapter->setWebChannel(d->m_webChannel, d->m_webChannelWorld);
Q_EMIT webChannelWorldChanged(webChannelWorld);
+#else
+ Q_UNUSED(webChannelWorld)
+ qWarning("WebEngine compiled without webchannel support");
+#endif
}
QQuickWebEngineView *QQuickWebEngineView::inspectedView() const
@@ -1271,6 +1395,7 @@ QQuickWebEngineView *QQuickWebEngineView::devToolsView() const
return d->devToolsView;
}
+
void QQuickWebEngineView::setDevToolsView(QQuickWebEngineView *devToolsView)
{
Q_D(QQuickWebEngineView);
@@ -1283,7 +1408,7 @@ void QQuickWebEngineView::setDevToolsView(QQuickWebEngineView *devToolsView)
d->devToolsView = devToolsView;
if (devToolsView)
devToolsView->setInspectedView(this);
- if (d->adapter->isInitialized()) {
+ if (d->profileInitialized() && d->adapter->isInitialized()) {
if (devToolsView)
d->adapter->openDevToolsFrontend(devToolsView->d_ptr->adapter);
else
@@ -1360,7 +1485,8 @@ void QQuickWebEngineView::fullScreenCancelled()
void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
QQuickItem::geometryChanged(newGeometry, oldGeometry);
- Q_FOREACH(QQuickItem *child, childItems()) {
+ const QList<QQuickItem *> children = childItems();
+ for (QQuickItem *child : children) {
if (qobject_cast<RenderWidgetHostViewQtDelegateQuick *>(child))
child->setSize(newGeometry.size());
}
@@ -1369,7 +1495,8 @@ void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRect
void QQuickWebEngineView::itemChange(ItemChange change, const ItemChangeData &value)
{
Q_D(QQuickWebEngineView);
- if (d->adapter->isInitialized() && (change == ItemSceneChange || change == ItemVisibleHasChanged)) {
+ if (d && d->profileInitialized() && d->adapter->isInitialized()
+ && (change == ItemSceneChange || change == ItemVisibleHasChanged)) {
if (window() && isVisible())
d->adapter->wasShown();
else
@@ -1630,6 +1757,170 @@ void QQuickWebEngineView::triggerWebAction(WebAction action)
}
}
+QQuickWebEngineAction *QQuickWebEngineView::action(WebAction action)
+{
+ Q_D(QQuickWebEngineView);
+ if (action == QQuickWebEngineView::NoWebAction)
+ return nullptr;
+ if (d->actions[action]) {
+ d->updateAction(action);
+ return d->actions[action];
+ }
+
+ QString text;
+ QString iconText;
+
+ switch (action) {
+ case Back:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Back);
+ iconText = QStringLiteral("go-previous");
+ break;
+ case Forward:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Forward);
+ iconText = QStringLiteral("go-next");
+ break;
+ case Stop:
+ text = tr("Stop");
+ break;
+ case Reload:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Reload);
+ iconText = QStringLiteral("view-refresh");
+ break;
+ case ReloadAndBypassCache:
+ text = tr("Reload and Bypass Cache");
+ break;
+ case Cut:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Cut);
+ iconText = QStringLiteral("Cut");
+ break;
+ case Copy:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Copy);
+ break;
+ case Paste:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Paste);
+ break;
+ case Undo:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Undo);
+ break;
+ case Redo:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Redo);
+ break;
+ case SelectAll:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::SelectAll);
+ break;
+ case PasteAndMatchStyle:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::PasteAndMatchStyle);
+ break;
+ case OpenLinkInThisWindow:
+ text = tr("Open link in this window");
+ break;
+ case OpenLinkInNewWindow:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::OpenLinkInNewWindow);
+ break;
+ case OpenLinkInNewTab:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::OpenLinkInNewTab);
+ break;
+ case CopyLinkToClipboard:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyLinkToClipboard);
+ break;
+ case DownloadLinkToDisk:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::DownloadLinkToDisk);
+ break;
+ case CopyImageToClipboard:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyImageToClipboard);
+ break;
+ case CopyImageUrlToClipboard:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyImageUrlToClipboard);
+ break;
+ case DownloadImageToDisk:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::DownloadImageToDisk);
+ break;
+ case CopyMediaUrlToClipboard:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyMediaUrlToClipboard);
+ break;
+ case ToggleMediaControls:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ToggleMediaControls);
+ break;
+ case ToggleMediaLoop:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ToggleMediaLoop);
+ break;
+ case ToggleMediaPlayPause:
+ text = tr("Toggle Play/Pause");
+ break;
+ case ToggleMediaMute:
+ text = tr("Toggle Mute");
+ break;
+ case DownloadMediaToDisk:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::DownloadMediaToDisk);
+ break;
+ case InspectElement:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::InspectElement);
+ break;
+ case ExitFullScreen:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ExitFullScreen);
+ break;
+ case RequestClose:
+ text = tr("Close Page");
+ break;
+ case Unselect:
+ text = tr("Unselect");
+ break;
+ case SavePage:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::SavePage);
+ break;
+ case ViewSource:
+ text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ViewSource);
+ iconText = QStringLiteral("view-source");
+ break;
+ case ToggleBold:
+ text = tr("&Bold");
+ break;
+ case ToggleItalic:
+ text = tr("&Italic");
+ break;
+ case ToggleUnderline:
+ text = tr("&Underline");
+ break;
+ case ToggleStrikethrough:
+ text = tr("&Strikethrough");
+ break;
+ case AlignLeft:
+ text = tr("Align &Left");
+ break;
+ case AlignCenter:
+ text = tr("Align &Center");
+ break;
+ case AlignRight:
+ text = tr("Align &Right");
+ break;
+ case AlignJustified:
+ text = tr("Align &Justified");
+ break;
+ case Indent:
+ text = tr("&Indent");
+ break;
+ case Outdent:
+ text = tr("&Outdent");
+ break;
+ case InsertOrderedList:
+ text = tr("Insert &Ordered List");
+ break;
+ case InsertUnorderedList:
+ text = tr("Insert &Unordered List");
+ break;
+ case NoWebAction:
+ case WebActionCount:
+ Q_UNREACHABLE();
+ break;
+ }
+
+ QQuickWebEngineAction *retVal = new QQuickWebEngineAction(action, text, iconText, false, this);
+
+ d->actions[action] = retVal;
+ d->updateAction(action);
+ return retVal;
+}
+
QSizeF QQuickWebEngineView::contentsSize() const
{
Q_D(const QQuickWebEngineView);
@@ -1650,7 +1941,7 @@ void QQuickWebEngineViewPrivate::userScripts_append(QQmlListProperty<QQuickWebEn
// If the adapter hasn't been initialized, we'll bind the scripts in initializationFinished()
if (!d->adapter->isInitialized())
return;
- UserResourceControllerHost *resourceController = d->browserContextAdapter()->userResourceController();
+ UserResourceControllerHost *resourceController = d->profileAdapter()->userResourceController();
script->d_func()->bind(resourceController, d->adapter.data());
}
@@ -1675,14 +1966,15 @@ void QQuickWebEngineViewPrivate::userScripts_clear(QQmlListProperty<QQuickWebEng
d->m_userScripts.clear();
if (!d->adapter->isInitialized())
return;
- UserResourceControllerHost *resourceController = d->browserContextAdapter()->userResourceController();
+ UserResourceControllerHost *resourceController = d->profileAdapter()->userResourceController();
resourceController->clearAllScripts(d->adapter.data());
}
void QQuickWebEngineView::componentComplete()
{
QQuickItem::componentComplete();
-
+ Q_D(QQuickWebEngineView);
+ d->initializeProfile();
#ifndef QT_NO_ACCESSIBILITY
// Enable accessibility via a dynamic QQmlProperty, instead of using private API call
// QQuickAccessibleAttached::qmlAttachedProperties(this). The qmlContext is required, otherwise
@@ -1758,112 +2050,101 @@ bool QQuickContextMenuBuilder::isFullScreenMode()
void QQuickContextMenuBuilder::addMenuItem(ContextMenuItem menuItem)
{
- MenuItemHandler *item = new MenuItemHandler(m_menu);
- QString menuItemIcon;
- QPointer<QQuickWebEngineView> thisRef(m_view);
+ QQuickWebEngineAction *action = nullptr;
switch (menuItem) {
case ContextMenuItem::Back:
- QObject::connect(item, &MenuItemHandler::triggered, thisRef, &QQuickWebEngineView::goBack);
- menuItemIcon = QStringLiteral("go-previous");
+ action = m_view->action(QQuickWebEngineView::Back);
break;
case ContextMenuItem::Forward:
- QObject::connect(item, &MenuItemHandler::triggered, thisRef, &QQuickWebEngineView::goForward);
- menuItemIcon = QStringLiteral("go-next");
+ action = m_view->action(QQuickWebEngineView::Forward);
break;
case ContextMenuItem::Reload:
- QObject::connect(item, &MenuItemHandler::triggered, thisRef, &QQuickWebEngineView::reload);
- menuItemIcon = QStringLiteral("view-refresh");
+ action = m_view->action(QQuickWebEngineView::Reload);
break;
case ContextMenuItem::Cut:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Cut); });
- menuItemIcon = QStringLiteral("Cut");
+ action = m_view->action(QQuickWebEngineView::Cut);
break;
case ContextMenuItem::Copy:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Copy); });
- menuItemIcon = QStringLiteral("Copy");
+ action = m_view->action(QQuickWebEngineView::Copy);
break;
-
case ContextMenuItem::Paste:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Paste); });
- menuItemIcon = QStringLiteral("Paste");
+ action = m_view->action(QQuickWebEngineView::Paste);
break;
case ContextMenuItem::Undo:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Undo); });
- menuItemIcon = QStringLiteral("Undo");
+ action = m_view->action(QQuickWebEngineView::Undo);
break;
case ContextMenuItem::Redo:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Redo); });
- menuItemIcon = QStringLiteral("Redo");
+ action = m_view->action(QQuickWebEngineView::Redo);
break;
case ContextMenuItem::SelectAll:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::SelectAll); });
- menuItemIcon = QStringLiteral("Select All");
+ action = m_view->action(QQuickWebEngineView::SelectAll);
break;
case ContextMenuItem::PasteAndMatchStyle:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::PasteAndMatchStyle); });
- menuItemIcon = QStringLiteral("Paste And Match Style");
+ action = m_view->action(QQuickWebEngineView::PasteAndMatchStyle);
break;
case ContextMenuItem::OpenLinkInNewWindow:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::OpenLinkInNewWindow); });
+ action = m_view->action(QQuickWebEngineView::OpenLinkInNewWindow);
break;
case ContextMenuItem::OpenLinkInNewTab:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::OpenLinkInNewTab); });
+ action = m_view->action(QQuickWebEngineView::OpenLinkInNewTab);
break;
case ContextMenuItem::CopyLinkToClipboard:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyLinkToClipboard); });
+ action = m_view->action(QQuickWebEngineView::CopyLinkToClipboard);
break;
case ContextMenuItem::DownloadLinkToDisk:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::DownloadLinkToDisk); });
+ action = m_view->action(QQuickWebEngineView::DownloadLinkToDisk);
break;
case ContextMenuItem::CopyImageToClipboard:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyImageToClipboard); });
+ action = m_view->action(QQuickWebEngineView::CopyImageToClipboard);
break;
case ContextMenuItem::CopyImageUrlToClipboard:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyImageUrlToClipboard); });
+ action = m_view->action(QQuickWebEngineView::CopyImageUrlToClipboard);
break;
case ContextMenuItem::DownloadImageToDisk:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::DownloadImageToDisk); });
+ action = m_view->action(QQuickWebEngineView::DownloadImageToDisk);
break;
case ContextMenuItem::CopyMediaUrlToClipboard:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyMediaUrlToClipboard); });
+ action = m_view->action(QQuickWebEngineView::CopyMediaUrlToClipboard);
break;
case ContextMenuItem::ToggleMediaControls:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ToggleMediaControls); });
+ action = m_view->action(QQuickWebEngineView::ToggleMediaControls);
break;
case ContextMenuItem::ToggleMediaLoop:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ToggleMediaLoop); });
+ action = m_view->action(QQuickWebEngineView::ToggleMediaLoop);
break;
case ContextMenuItem::DownloadMediaToDisk:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::DownloadMediaToDisk); });
+ action = m_view->action(QQuickWebEngineView::DownloadMediaToDisk);
break;
case ContextMenuItem::InspectElement:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::InspectElement); });
+ action = m_view->action(QQuickWebEngineView::InspectElement);
break;
case ContextMenuItem::ExitFullScreen:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ExitFullScreen); });
+ action = m_view->action(QQuickWebEngineView::ExitFullScreen);
break;
case ContextMenuItem::SavePage:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::SavePage); });
+ action = m_view->action(QQuickWebEngineView::SavePage);
break;
case ContextMenuItem::ViewSource:
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ViewSource); });
- menuItemIcon = QStringLiteral("view-source");
+ action = m_view->action(QQuickWebEngineView::ViewSource);
break;
case ContextMenuItem::SpellingSuggestions:
+ {
+ QPointer<QQuickWebEngineView> thisRef(m_view);
for (int i=0; i < m_contextData.spellCheckerSuggestions().count() && i < 4; i++) {
- item = new MenuItemHandler(m_menu);
+ action = new QQuickWebEngineAction(m_menu);
QString replacement = m_contextData.spellCheckerSuggestions().at(i);
- QObject::connect(item, &MenuItemHandler::triggered, [thisRef, replacement] { thisRef->replaceMisspelledWord(replacement); });
- m_view->d_ptr->ui()->addMenuItem(item, replacement);
+ QObject::connect(action, &QQuickWebEngineAction::triggered, [thisRef, replacement] { thisRef->replaceMisspelledWord(replacement); });
+ m_view->d_ptr->ui()->addMenuItem(action, m_menu);
}
return;
+ }
case ContextMenuItem::Separator:
- thisRef->d_ptr->ui()->addMenuSeparator(m_menu);
+ m_view->d_ptr->ui()->addMenuSeparator(m_menu);
return;
}
- QString menuItemName = RenderViewContextMenuQt::getMenuItemName(menuItem);
- thisRef->d_ptr->ui()->addMenuItem(item, menuItemName, menuItemIcon, isMenuItemEnabled(menuItem));
+ action->d_ptr->setEnabled(isMenuItemEnabled(menuItem));
+ m_view->d_ptr->ui()->addMenuItem(action, m_menu);
}
bool QQuickContextMenuBuilder::isMenuItemEnabled(ContextMenuItem menuItem)
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 8d20740e6..ae92b6df0 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -51,7 +51,8 @@
// We mean it.
//
-#include <private/qtwebengineglobal_p.h>
+#include <QtWebEngineCore/private/qtwebenginecoreglobal_p.h>
+#include <QtWebEngine/private/qtwebengineglobal_p.h>
#include "qquickwebenginescript.h"
#include <QQuickItem>
#include <QtGui/qcolor.h>
@@ -61,6 +62,7 @@ QT_BEGIN_NAMESPACE
class QQmlWebChannel;
class QQuickContextMenuBuilder;
+class QQuickWebEngineAction;
class QQuickWebEngineAuthenticationDialogRequest;
class QQuickWebEngineCertificateError;
class QQuickWebEngineColorDialogRequest;
@@ -79,7 +81,7 @@ class QQuickWebEngineViewPrivate;
class QWebEngineQuotaRequest;
class QWebEngineRegisterProtocolHandlerRequest;
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
class QQuickWebEngineTestSupport;
#endif
@@ -130,7 +132,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_PROPERTY(QQuickWebEngineView *inspectedView READ inspectedView WRITE setInspectedView NOTIFY inspectedViewChanged REVISION 7 FINAL)
Q_PROPERTY(QQuickWebEngineView *devToolsView READ devToolsView WRITE setDevToolsView NOTIFY devToolsViewChanged REVISION 7 FINAL)
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
Q_PROPERTY(QQuickWebEngineTestSupport *testSupport READ testSupport WRITE setTestSupport NOTIFY testSupportChanged FINAL)
#endif
@@ -459,22 +461,23 @@ public:
// QmlParserStatus
void componentComplete() override;
- QQuickWebEngineProfile *profile() const;
+ QQuickWebEngineProfile *profile();
void setProfile(QQuickWebEngineProfile *);
QQmlListProperty<QQuickWebEngineScript> userScripts();
- QQuickWebEngineSettings *settings() const;
+ QQuickWebEngineSettings *settings();
QQmlWebChannel *webChannel();
void setWebChannel(QQmlWebChannel *);
QQuickWebEngineHistory *navigationHistory() const;
uint webChannelWorld() const;
void setWebChannelWorld(uint);
+ Q_REVISION(8) Q_INVOKABLE QQuickWebEngineAction *action(WebAction action);
bool isAudioMuted() const;
void setAudioMuted(bool muted);
bool recentlyAudible() const;
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
QQuickWebEngineTestSupport *testSupport() const;
void setTestSupport(QQuickWebEngineTestSupport *testSupport);
#endif
@@ -546,8 +549,9 @@ Q_SIGNALS:
Q_REVISION(7) void inspectedViewChanged();
Q_REVISION(7) void devToolsViewChanged();
Q_REVISION(7) void registerProtocolHandlerRequested(const QWebEngineRegisterProtocolHandlerRequest &request);
+ Q_REVISION(8) void printRequested();
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
void testSupportChanged();
#endif
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 1723da7ea..ee38ece6b 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -74,10 +74,11 @@ class QQmlContext;
class QQuickWebEngineContextMenuRequest;
class QQuickWebEngineSettings;
class QQuickWebEngineFaviconProvider;
+class QQuickWebEngineProfilePrivate;
QQuickWebEngineView::WebAction editorActionForKeyEvent(QKeyEvent* event);
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
class QQuickWebEngineTestSupport;
#endif
@@ -88,7 +89,8 @@ public:
QQuickWebEngineView *q_ptr;
QQuickWebEngineViewPrivate();
~QQuickWebEngineViewPrivate();
-
+ void destroy();
+ void initializeProfile();
QtWebEngineCore::UIDelegatesManager *ui();
QtWebEngineCore::RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) override;
@@ -137,6 +139,7 @@ public:
QObject *accessibilityParentObject() override;
QtWebEngineCore::WebEngineSettings *webEngineSettings() const override;
void allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) override;
+ void selectClientCert(const QSharedPointer<ClientCertSelectController> &selectController) override;
void runGeolocationPermissionRequest(QUrl const&) override;
void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus, int exitCode) override;
void requestGeometryChange(const QRect &geometry, const QRect &frameGeometry) override;
@@ -148,12 +151,16 @@ public:
bool isEnabled() const override;
void setToolTip(const QString &toolTipText) override;
const QObject *holdingQObject() const override;
+ ClientType clientType() override { return QtWebEngineCore::WebContentsAdapterClient::QmlClient; }
- QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextAdapter() override;
+ QtWebEngineCore::ProfileAdapter *profileAdapter() override;
QtWebEngineCore::WebContentsAdapter *webContentsAdapter() override;
+ void printRequested() override;
+ void updateAction(QQuickWebEngineView::WebAction) const;
void adoptWebContents(QtWebEngineCore::WebContentsAdapter *webContents);
void setProfile(QQuickWebEngineProfile *profile);
+ void updateAdapter();
void ensureContentsAdapter();
void setFullScreenMode(bool);
@@ -163,16 +170,17 @@ public:
static QQuickWebEngineScript *userScripts_at(QQmlListProperty<QQuickWebEngineScript> *p, int idx);
static void userScripts_clear(QQmlListProperty<QQuickWebEngineScript> *p);
+ QQuickWebEngineProfile *m_profile;
QSharedPointer<QtWebEngineCore::WebContentsAdapter> adapter;
QScopedPointer<QQuickWebEngineHistory> m_history;
- QQuickWebEngineProfile *m_profile;
QScopedPointer<QQuickWebEngineSettings> m_settings;
-#ifdef ENABLE_QML_TESTSUPPORT_API
+#if QT_CONFIG(webengine_testsupport)
QQuickWebEngineTestSupport *m_testSupport;
#endif
QQmlComponent *contextMenuExtraItems;
QtWebEngineCore::WebEngineContextMenuData m_contextMenuData;
- QUrl explicitUrl;
+ QUrl m_url;
+ QString m_html;
QUrl iconUrl;
QQuickWebEngineFaviconProvider *faviconProvider;
int loadProgress;
@@ -188,14 +196,18 @@ public:
QPointer<QQuickWebEngineView> devToolsView;
uint m_webChannelWorld;
bool m_isBeingAdopted;
+ mutable QQuickWebEngineAction *actions[QQuickWebEngineView::WebActionCount];
+
+ bool profileInitialized() const;
private:
QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager;
QList<QQuickWebEngineScript *> m_userScripts;
qreal m_dpiScale;
QColor m_backgroundColor;
- qreal m_defaultZoomFactor;
+ qreal m_zoomFactor;
bool m_ui2Enabled;
+ bool m_profileInitialized;
};
#ifndef QT_NO_ACCESSIBILITY