summaryrefslogtreecommitdiffstats
path: root/src/webengine
diff options
context:
space:
mode:
authorAdam Kallai <kadam@inf.u-szeged.hu>2014-01-06 06:30:02 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-15 09:50:13 +0100
commite2382d300c2620d476ba2afad210a7ed0424bf8c (patch)
tree9241c2733f8870c67f9dfe80bca3704d554af0f0 /src/webengine
parent74ffcbf0cfe0235b5c09515231ff13543388d28b (diff)
Implement QQuickWebEngineLoadRequest class
It contains information about a requested load of a web page. Change-Id: Ie45706adb51ee5bce98e7af01252d9a8389db57d Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com> Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/api/qquickwebengineloadrequest.cpp113
-rw-r--r--src/webengine/api/qquickwebengineloadrequest_p.h96
-rw-r--r--src/webengine/api/qquickwebengineview.cpp40
-rw-r--r--src/webengine/api/qquickwebengineview_p.h22
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h3
-rw-r--r--src/webengine/plugin/plugin.cpp2
-rw-r--r--src/webengine/webengine.pro2
7 files changed, 271 insertions, 7 deletions
diff --git a/src/webengine/api/qquickwebengineloadrequest.cpp b/src/webengine/api/qquickwebengineloadrequest.cpp
new file mode 100644
index 00000000..e9e6fab1
--- /dev/null
+++ b/src/webengine/api/qquickwebengineloadrequest.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qquickwebengineloadrequest_p.h>
+
+/*!
+ \qmltype WebEngineLoadRequest
+ \instantiates QQuickWebEngineLoadRequest
+ \inqmlmodule QtWebEngine 1.0
+
+ \brief A utility class for the WebEngineView::loadingStateChanged signal.
+
+ This class contains information about a requested load of a web page, like the URL and
+ current loading status (started, finished, failed).
+
+ \sa WebEngineView::onLoadingStateChanged
+*/
+QQuickWebEngineLoadRequest::QQuickWebEngineLoadRequest(const QUrl& url, QQuickWebEngineView::LoadStatus status, const QString& errorString, int errorCode, QQuickWebEngineView::ErrorDomain errorDomain, QObject* parent)
+ : QObject(parent)
+ , d(new QQuickWebEngineLoadRequestPrivate(url, status, errorString, errorCode, errorDomain))
+{
+}
+
+QQuickWebEngineLoadRequest::~QQuickWebEngineLoadRequest()
+{
+}
+
+/*!
+ \qmlproperty url WebEngineLoadRequest::url
+ \brief The URL of the load request.
+ */
+QUrl QQuickWebEngineLoadRequest::url() const
+{
+ return d->url;
+}
+
+/*!
+ \qmlproperty enumeration WebEngineLoadRequest::status
+
+ The load status of a web page load request.
+
+ \list
+ \li WebEngineView::LoadStartedStatus - the page is currently loading.
+ \li WebEngineView::LoadSucceededStatus - the page has been loaded with success.
+ \li WebEngineView::LoadFailedStatus - the page has failed loading.
+ \endlist
+
+ \sa WebEngineLoadRequest
+ \sa WebEngineView::onLoadingStateChanged
+*/
+QQuickWebEngineView::LoadStatus QQuickWebEngineLoadRequest::status() const
+{
+ return d->status;
+}
+
+/*!
+ \qmlproperty string WebEngineLoadRequest::errorString
+*/
+QString QQuickWebEngineLoadRequest::errorString() const
+{
+ return d->errorString;
+}
+
+QQuickWebEngineView::ErrorDomain QQuickWebEngineLoadRequest::errorDomain() const
+{
+ return d->errorDomain;
+}
+
+/*!
+ \qmlproperty int WebEngineLoadRequest::errorCode
+*/
+int QQuickWebEngineLoadRequest::errorCode() const
+{
+ return d->errorCode;
+}
diff --git a/src/webengine/api/qquickwebengineloadrequest_p.h b/src/webengine/api/qquickwebengineloadrequest_p.h
new file mode 100644
index 00000000..6f627acb
--- /dev/null
+++ b/src/webengine/api/qquickwebengineloadrequest_p.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKWEBENGINELOADREQUEST_P_H
+#define QQUICKWEBENGINELOADREQUEST_P_H
+
+#include "qtwebengineglobal_p.h"
+#include "qquickwebengineview_p.h"
+#include "web_engine_error.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickWebEngineLoadRequestPrivate;
+
+class Q_WEBENGINE_EXPORT QQuickWebEngineLoadRequest : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QUrl url READ url)
+ Q_PROPERTY(QQuickWebEngineView::LoadStatus status READ status)
+ Q_PROPERTY(QString errorString READ errorString)
+ Q_PROPERTY(QQuickWebEngineView::ErrorDomain errorDomain READ errorDomain)
+ Q_PROPERTY(int errorCode READ errorCode)
+
+public:
+ QQuickWebEngineLoadRequest(const QUrl& url, QQuickWebEngineView::LoadStatus status, const QString& errorString = QString(), int errorCode = 0, QQuickWebEngineView::ErrorDomain errorDomain = QQuickWebEngineView::NoErrorDomain, QObject* parent = 0);
+ ~QQuickWebEngineLoadRequest();
+ QUrl url() const;
+ QQuickWebEngineView::LoadStatus status() const;
+ QString errorString() const;
+ QQuickWebEngineView::ErrorDomain errorDomain() const;
+ int errorCode() const;
+
+private:
+ QScopedPointer<QQuickWebEngineLoadRequestPrivate> d;
+};
+
+class QQuickWebEngineLoadRequestPrivate {
+public:
+ QQuickWebEngineLoadRequestPrivate(const QUrl& url, QQuickWebEngineView::LoadStatus status, const QString& errorString, int errorCode, QQuickWebEngineView::ErrorDomain errorDomain)
+ : url(url)
+ , status(status)
+ , errorString(errorString)
+ , errorCode(errorCode)
+ , errorDomain(errorDomain)
+ {
+ }
+
+ QUrl url;
+ QQuickWebEngineView::LoadStatus status;
+ QString errorString;
+ int errorCode;
+ QQuickWebEngineView::ErrorDomain errorDomain;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickWebEngineLoadRequest)
+
+#endif // QQUICKWEBENGINELOADREQUEST_P_H
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index d159ed8f..ac2dc681 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -42,7 +42,10 @@
#include "qquickwebengineview_p.h"
#include "qquickwebengineview_p_p.h"
+#include "net/base/net_errors.h"
+#include "qquickwebengineloadrequest_p.h"
#include "web_contents_adapter.h"
+#include "web_engine_error.h"
#include "render_widget_host_view_qt_delegate_quick.h"
#include <QScreen>
@@ -57,6 +60,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
, v(new QQuickWebEngineViewport(this))
, loadProgress(0)
, inspectable(false)
+ , m_isLoading(false)
, devicePixelRatio(QGuiApplication::primaryScreen()->devicePixelRatio())
, m_dpiScale(1.0)
{
@@ -123,7 +127,12 @@ void QQuickWebEngineViewPrivate::iconChanged(const QUrl &url)
void QQuickWebEngineViewPrivate::loadingStateChanged()
{
Q_Q(QQuickWebEngineView);
- Q_EMIT q->loadingStateChanged();
+ const bool wasLoading = m_isLoading;
+ m_isLoading = adapter->isLoading();
+ if (m_isLoading && !wasLoading) {
+ QQuickWebEngineLoadRequest loadRequest(q->url(), QQuickWebEngineView::LoadStartedStatus);
+ Q_EMIT q->loadingStateChanged(&loadRequest);
+ }
}
void QQuickWebEngineViewPrivate::loadProgressChanged(int progress)
@@ -144,11 +153,29 @@ qreal QQuickWebEngineViewPrivate::dpiScale() const
return m_dpiScale;
}
-void QQuickWebEngineViewPrivate::loadFinished(bool success)
+void QQuickWebEngineViewPrivate::loadFinished(bool success, int error_code, const QString &error_description)
{
Q_Q(QQuickWebEngineView);
- Q_UNUSED(success);
- Q_EMIT q->loadingStateChanged();
+ if (error_code == net::ERR_ABORTED) {
+ QQuickWebEngineLoadRequest loadRequest(q->url(), QQuickWebEngineView::LoadStoppedStatus);
+ Q_EMIT q->loadingStateChanged(&loadRequest);
+ return;
+ }
+ if (success) {
+ QQuickWebEngineLoadRequest loadRequest(q->url(), QQuickWebEngineView::LoadSucceededStatus);
+ Q_EMIT q->loadingStateChanged(&loadRequest);
+ return;
+ }
+
+ Q_ASSERT(error_code);
+ QQuickWebEngineLoadRequest loadRequest(
+ q->url(),
+ QQuickWebEngineView::LoadFailedStatus,
+ error_description,
+ error_code,
+ static_cast<QQuickWebEngineView::ErrorDomain>(WebEngineError::toQtErrorDomain(error_code)));
+ Q_EMIT q->loadingStateChanged(&loadRequest);
+ return;
}
void QQuickWebEngineViewPrivate::focusContainer()
@@ -391,7 +418,10 @@ void QQuickWebEngineViewExperimental::adoptHandle(QQuickWebEngineViewHandle *vie
emit q->titleChanged();
emit q->urlChanged();
emit q->iconChanged();
- emit q->loadingStateChanged();
+ // FIXME: The current loading state should be stored in the WebContentAdapter
+ // and it should be checked here if the signal emission is really necessary.
+ QQuickWebEngineLoadRequest loadRequest(viewHandle->adapter->activeUrl(), QQuickWebEngineView::LoadSucceededStatus);
+ emit q->loadingStateChanged(&loadRequest);
emit q->loadProgressChanged();
}
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 943ce080..76fbc785 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -48,6 +48,7 @@
QT_BEGIN_NAMESPACE
class QQuickWebEngineViewPrivate;
+class QQuickWebEngineLoadRequest;
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_OBJECT
@@ -59,6 +60,8 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingStateChanged)
Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingStateChanged)
Q_PROPERTY(bool inspectable READ inspectable WRITE setInspectable)
+ Q_ENUMS(LoadStatus);
+ Q_ENUMS(ErrorDomain);
public:
QQuickWebEngineView(QQuickItem *parent = 0);
@@ -75,6 +78,23 @@ public:
bool inspectable() const;
void setInspectable(bool);
+ enum LoadStatus {
+ LoadStartedStatus,
+ LoadStoppedStatus,
+ LoadSucceededStatus,
+ LoadFailedStatus
+ };
+
+ enum ErrorDomain {
+ NoErrorDomain,
+ InternalErrorDomain,
+ ConnectionErrorDomain,
+ CertificateErrorDomain,
+ HttpErrorDomain,
+ FtpErrorDomain,
+ DnsErrorDomain
+ };
+
public Q_SLOTS:
void goBack();
void goForward();
@@ -85,7 +105,7 @@ Q_SIGNALS:
void titleChanged();
void urlChanged();
void iconChanged();
- void loadingStateChanged();
+ void loadingStateChanged(QQuickWebEngineLoadRequest *loadRequest);
void loadProgressChanged();
protected:
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 0af1dcb4..f43bb17f 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -119,7 +119,7 @@ public:
virtual void loadProgressChanged(int progress) Q_DECL_OVERRIDE;
virtual QRectF viewportRect() const Q_DECL_OVERRIDE;
virtual qreal dpiScale() const Q_DECL_OVERRIDE;
- virtual void loadFinished(bool success) Q_DECL_OVERRIDE;
+ virtual void loadFinished(bool success, int error_code = 0, const QString &error_description = QString()) Q_DECL_OVERRIDE;
virtual void focusContainer() Q_DECL_OVERRIDE;
virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, const QRect &) Q_DECL_OVERRIDE;
virtual void close() Q_DECL_OVERRIDE;
@@ -134,6 +134,7 @@ public:
QUrl icon;
int loadProgress;
bool inspectable;
+ bool m_isLoading;
qreal devicePixelRatio;
private:
diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp
index 75191636..dd36bc6b 100644
--- a/src/webengine/plugin/plugin.cpp
+++ b/src/webengine/plugin/plugin.cpp
@@ -42,6 +42,7 @@
#include <QtQml/qqmlextensionplugin.h>
#include "qquickwebengineview_p.h"
+#include "qquickwebengineloadrequest_p.h"
QT_BEGIN_NAMESPACE
@@ -55,6 +56,7 @@ public:
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtWebEngine"));
qmlRegisterType<QQuickWebEngineView>(uri, 1, 0, "WebEngineView");
+ qmlRegisterUncreatableType<QQuickWebEngineLoadRequest>(uri, 1, 0, "WebEngineLoadRequest", QObject::tr("Cannot create separate instance of WebEngineLoadRequest"));
}
};
diff --git a/src/webengine/webengine.pro b/src/webengine/webengine.pro
index ccf87435..96724d46 100644
--- a/src/webengine/webengine.pro
+++ b/src/webengine/webengine.pro
@@ -20,12 +20,14 @@ QMAKE_RPATHDIR += $$LIBPATH
#DESTDIR = $$LIBPATH
SOURCES = \
+ api/qquickwebengineloadrequest.cpp \
api/qquickwebengineview.cpp \
render_widget_host_view_qt_delegate_quick.cpp
HEADERS = \
api/qtwebengineglobal.h \
api/qtwebengineglobal_p.h \
+ api/qquickwebengineloadrequest_p.h \
api/qquickwebengineview_p.h \
api/qquickwebengineview_p_p.h \
render_widget_host_view_qt_delegate_quick.h