summaryrefslogtreecommitdiffstats
path: root/src/webengine
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/api/qquickwebenginehistory.cpp193
-rw-r--r--src/webengine/api/qquickwebenginehistory_p.h114
-rw-r--r--src/webengine/api/qquickwebenginehistory_p_p.h91
-rw-r--r--src/webengine/api/qquickwebengineview.cpp27
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h7
-rw-r--r--src/webengine/plugin/experimental/plugin.cpp5
-rw-r--r--src/webengine/webengine.pro2
7 files changed, 439 insertions, 0 deletions
diff --git a/src/webengine/api/qquickwebenginehistory.cpp b/src/webengine/api/qquickwebenginehistory.cpp
new file mode 100644
index 000000000..551a57205
--- /dev/null
+++ b/src/webengine/api/qquickwebenginehistory.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "qquickwebenginehistory_p.h"
+#include "qquickwebenginehistory_p_p.h"
+#include "qquickwebengineloadrequest_p.h"
+#include "qquickwebengineview_p_p.h"
+#include "web_contents_adapter.h"
+
+QT_BEGIN_NAMESPACE
+
+QQuickWebEngineHistoryListModelPrivate::QQuickWebEngineHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
+ : view(view)
+{
+}
+
+QQuickWebEngineHistoryListModelPrivate::~QQuickWebEngineHistoryListModelPrivate()
+{
+}
+
+WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const
+{
+ return view->adapter.data();
+}
+
+QQuickWebEngineBackHistoryListModelPrivate::QQuickWebEngineBackHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
+ : QQuickWebEngineHistoryListModelPrivate(view)
+{
+}
+
+int QQuickWebEngineBackHistoryListModelPrivate::count() const
+{
+ return adapter()->currentNavigationEntryIndex();
+}
+
+int QQuickWebEngineBackHistoryListModelPrivate::index(int i) const
+{
+ Q_ASSERT(i >= 0 && i < count());
+ return count() - 1 - i;
+}
+
+QQuickWebEngineForwardHistoryListModelPrivate::QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
+ : QQuickWebEngineHistoryListModelPrivate(view)
+{
+}
+
+int QQuickWebEngineForwardHistoryListModelPrivate::count() const
+{
+ return adapter()->navigationEntryCount() - adapter()->currentNavigationEntryIndex() - 1;
+}
+
+int QQuickWebEngineForwardHistoryListModelPrivate::index(int i) const
+{
+ return adapter()->currentNavigationEntryIndex() + i;
+}
+
+QQuickWebEngineHistoryListModel::QQuickWebEngineHistoryListModel()
+ : QAbstractListModel()
+{
+}
+
+QQuickWebEngineHistoryListModel::QQuickWebEngineHistoryListModel(QQuickWebEngineHistoryListModelPrivate *d)
+ : QAbstractListModel()
+ , d_ptr(d)
+{
+}
+
+QQuickWebEngineHistoryListModel::~QQuickWebEngineHistoryListModel()
+{
+}
+
+QHash<int, QByteArray> QQuickWebEngineHistoryListModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[QQuickWebEngineHistory::UrlRole] = "url";
+ roles[QQuickWebEngineHistory::TitleRole] = "title";
+ return roles;
+}
+
+int QQuickWebEngineHistoryListModel::rowCount(const QModelIndex &index) const
+{
+ Q_UNUSED(index);
+ Q_D(const QQuickWebEngineHistoryListModel);
+ return d->count();
+}
+
+QVariant QQuickWebEngineHistoryListModel::data(const QModelIndex &index, int role) const
+{
+ Q_D(const QQuickWebEngineHistoryListModel);
+
+ if (!index.isValid())
+ return QVariant();
+
+ if (role < QQuickWebEngineHistory::UrlRole || role > QQuickWebEngineHistory::TitleRole)
+ return QVariant();
+
+ if (role == QQuickWebEngineHistory::UrlRole)
+ return QUrl(d->adapter()->getNavigationEntryUrl(d->index(index.row())));
+
+ if (role == QQuickWebEngineHistory::TitleRole)
+ return QString(d->adapter()->getNavigationEntryTitle(d->index(index.row())));
+
+ return QVariant();
+}
+
+void QQuickWebEngineHistoryListModel::reset()
+{
+ beginResetModel();
+ endResetModel();
+}
+
+QQuickWebEngineHistoryPrivate::QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate *view)
+ : m_backNavigationModel(new QQuickWebEngineHistoryListModel(new QQuickWebEngineBackHistoryListModelPrivate(view)))
+ , m_forwardNavigationModel(new QQuickWebEngineHistoryListModel(new QQuickWebEngineForwardHistoryListModelPrivate(view)))
+{
+}
+
+QQuickWebEngineHistoryPrivate::~QQuickWebEngineHistoryPrivate()
+{
+}
+
+QQuickWebEngineHistory::QQuickWebEngineHistory(QQuickWebEngineViewPrivate *view)
+ : d_ptr(new QQuickWebEngineHistoryPrivate(view))
+{
+}
+
+QQuickWebEngineHistory::~QQuickWebEngineHistory()
+{
+}
+
+QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::backItems() const
+{
+ Q_D(const QQuickWebEngineHistory);
+ return d->m_backNavigationModel.data();
+}
+
+QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::forwardItems() const
+{
+ Q_D(const QQuickWebEngineHistory);
+ return d->m_forwardNavigationModel.data();
+}
+
+void QQuickWebEngineHistory::reset(QQuickWebEngineLoadRequest *loadRequest)
+{
+ Q_D(QQuickWebEngineHistory);
+
+ if (loadRequest->status() != QQuickWebEngineView::LoadSucceededStatus)
+ return;
+
+ d->m_backNavigationModel->reset();
+ d->m_forwardNavigationModel->reset();
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebenginehistory_p.h b/src/webengine/api/qquickwebenginehistory_p.h
new file mode 100644
index 000000000..9267b1a6c
--- /dev/null
+++ b/src/webengine/api/qquickwebenginehistory_p.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 QQUICKWEBENGINEHISOTRY_P_H
+#define QQUICKWEBENGINEHISTORY_P_H
+
+#include <qtwebengineglobal_p.h>
+#include <QAbstractListModel>
+#include <QtCore/qshareddata.h>
+#include <QQuickItem>
+#include <QUrl>
+#include <QVariant>
+
+QT_BEGIN_NAMESPACE
+
+class WebEngineHistory;
+class WebEngineHistoryItem;
+class QQuickWebEngineHistory;
+class QQuickWebEngineHistoryPrivate;
+class QQuickWebEngineHistoryListModelPrivate;
+class QQuickWebEngineLoadRequest;
+class QQuickWebEngineViewPrivate;
+
+class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineHistoryListModel : public QAbstractListModel {
+ Q_OBJECT
+
+public:
+ QQuickWebEngineHistoryListModel(QQuickWebEngineHistoryListModelPrivate*);
+ virtual ~QQuickWebEngineHistoryListModel();
+
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role) const;
+ QHash<int, QByteArray> roleNames() const;
+ void reset();
+
+private:
+ QQuickWebEngineHistoryListModel();
+
+ Q_DECLARE_PRIVATE(QQuickWebEngineHistoryListModel);
+ QScopedPointer<QQuickWebEngineHistoryListModelPrivate> d_ptr;
+
+ friend class QQuickWebEngineHistory;
+};
+
+class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineHistory : public QQuickItem {
+ Q_OBJECT
+ Q_PROPERTY(QQuickWebEngineHistoryListModel *backItems READ backItems CONSTANT FINAL)
+ Q_PROPERTY(QQuickWebEngineHistoryListModel *forwardItems READ forwardItems CONSTANT FINAL)
+
+public:
+ QQuickWebEngineHistory(QQuickWebEngineViewPrivate*);
+ virtual ~QQuickWebEngineHistory();
+
+ enum NavigationHistoryRoles {
+ UrlRole = Qt::UserRole + 1,
+ TitleRole = Qt::UserRole + 2
+ };
+
+ QQuickWebEngineHistoryListModel *backItems() const;
+ QQuickWebEngineHistoryListModel *forwardItems() const;
+
+public Q_SLOTS:
+ void reset(QQuickWebEngineLoadRequest*);
+
+private:
+ QQuickWebEngineHistory();
+
+ Q_DECLARE_PRIVATE(QQuickWebEngineHistory);
+ QScopedPointer<QQuickWebEngineHistoryPrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickWebEngineHistory)
+
+#endif // QQUICKWEBENGINEHISTORY_P_H
diff --git a/src/webengine/api/qquickwebenginehistory_p_p.h b/src/webengine/api/qquickwebenginehistory_p_p.h
new file mode 100644
index 000000000..6bd0b6662
--- /dev/null
+++ b/src/webengine/api/qquickwebenginehistory_p_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 QQUICKWEBENGINEHISOTRY_P_P_H
+#define QQUICKWEBENGINEHISTORY_P_P_H
+
+class WebContentsAdapter;
+class QQuickWebEngineHistoryListModel;
+class QQuickWebEngineViewPrivate;
+
+QT_BEGIN_NAMESPACE
+
+class QQuickWebEngineHistoryListModelPrivate {
+public:
+ QQuickWebEngineHistoryListModelPrivate(QQuickWebEngineViewPrivate*);
+ virtual ~QQuickWebEngineHistoryListModelPrivate();
+
+ virtual int count() const = 0;
+ virtual int index(int) const = 0;
+
+ WebContentsAdapter *adapter() const;
+
+ QQuickWebEngineViewPrivate *view;
+};
+
+class QQuickWebEngineBackHistoryListModelPrivate : public QQuickWebEngineHistoryListModelPrivate {
+public:
+ QQuickWebEngineBackHistoryListModelPrivate(QQuickWebEngineViewPrivate*);
+
+ int count() const;
+ int index(int) const;
+};
+
+class QQuickWebEngineForwardHistoryListModelPrivate : public QQuickWebEngineHistoryListModelPrivate {
+public:
+ QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate*);
+
+ int count() const;
+ int index(int) const;
+};
+
+class QQuickWebEngineHistoryPrivate {
+public:
+ QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate*);
+ ~QQuickWebEngineHistoryPrivate();
+
+ QScopedPointer<QQuickWebEngineHistoryListModel> m_backNavigationModel;
+ QScopedPointer<QQuickWebEngineHistoryListModel> m_forwardNavigationModel;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKWEBENGINEHISTORY_P_P_H
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 64c7f337e..58262cd3f 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -43,6 +43,7 @@
#include "qquickwebengineview_p_p.h"
#include "javascript_dialog_controller.h"
+#include "qquickwebenginehistory_p.h"
#include "qquickwebengineloadrequest_p.h"
#include "qquickwebenginenewviewrequest_p.h"
#include "render_widget_host_view_qt_delegate_quick.h"
@@ -67,6 +68,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
: adapter(new WebContentsAdapter(qApp->property("QQuickWebEngineView_DisableHardwareAcceleration").toBool() ? SoftwareRenderingMode : HardwareAccelerationMode))
, e(new QQuickWebEngineViewExperimental(this))
, v(new QQuickWebEngineViewport(this))
+ , m_history(new QQuickWebEngineHistory(this))
, contextMenuExtraItems(0)
, loadProgress(0)
, inspectable(false)
@@ -359,6 +361,8 @@ QQuickWebEngineView::QQuickWebEngineView(QQuickItem *parent)
d->e->q_ptr = this;
d->adapter->initialize(d);
+ QObject::connect(this, &QQuickWebEngineView::loadingChanged, d->m_history.data(), &QQuickWebEngineHistory::reset);
+
this->setFocus(true);
this->setActiveFocusOnTab(true);
this->setFlag(QQuickItem::ItemIsFocusScope);
@@ -514,6 +518,29 @@ void QQuickWebEngineViewExperimental::runJavaScript(const QString &script, const
d_ptr->adapter->runJavaScript(script, /*xPath=*/QString());
}
+QQuickWebEngineHistory *QQuickWebEngineViewExperimental::navigationHistory() const
+{
+ return d_ptr->m_history.data();
+}
+
+void QQuickWebEngineViewExperimental::goBackTo(int index)
+{
+ int count = d_ptr->adapter->currentNavigationEntryIndex();
+ if (index < 0 || index >= count)
+ return;
+
+ d_ptr->adapter->navigateToIndex(count - 1 - index);
+}
+
+void QQuickWebEngineViewExperimental::goForwardTo(int index)
+{
+ int count = d_ptr->adapter->navigationEntryCount() - d_ptr->adapter->currentNavigationEntryIndex() - 1;
+ if (index < 0 || index >= count)
+ return;
+
+ d_ptr->adapter->navigateToIndex(d_ptr->adapter->currentNavigationEntryIndex() + 1 + index);
+}
+
void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
QQuickItem::geometryChanged(newGeometry, oldGeometry);
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 7fed546d4..8b489138c 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -55,6 +55,7 @@ class WebContentsAdapter;
class UIDelegatesManager;
QT_BEGIN_NAMESPACE
+class QQuickWebEngineHistory;
class QQuickWebEngineNewViewRequest;
class QQuickWebEngineView;
class QQmlComponent;
@@ -83,6 +84,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewExperimental : public QObjec
Q_PROPERTY(QQuickWebEngineViewport *viewport READ viewport)
Q_PROPERTY(QQmlComponent *extraContextMenuEntriesComponent READ extraContextMenuEntriesComponent WRITE setExtraContextMenuEntriesComponent NOTIFY extraContextMenuEntriesComponentChanged)
Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setIsFullScreen NOTIFY isFullScreenChanged)
+ Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL)
public:
void setIsFullScreen(bool fullscreen);
@@ -90,8 +92,12 @@ public:
QQuickWebEngineViewport *viewport() const;
void setExtraContextMenuEntriesComponent(QQmlComponent *);
QQmlComponent *extraContextMenuEntriesComponent() const;
+ int currentNavigationEntryIndex() const;
+ QQuickWebEngineHistory *navigationHistory() const;
public Q_SLOTS:
+ void goBackTo(int index);
+ void goForwardTo(int index);
void runJavaScript(const QString&, const QJSValue & = QJSValue());
Q_SIGNALS:
@@ -153,6 +159,7 @@ public:
QExplicitlySharedDataPointer<WebContentsAdapter> adapter;
QScopedPointer<QQuickWebEngineViewExperimental> e;
QScopedPointer<QQuickWebEngineViewport> v;
+ QScopedPointer<QQuickWebEngineHistory> m_history;
QQmlComponent *contextMenuExtraItems;
QUrl icon;
int loadProgress;
diff --git a/src/webengine/plugin/experimental/plugin.cpp b/src/webengine/plugin/experimental/plugin.cpp
index 6107147cf..5274ea3fa 100644
--- a/src/webengine/plugin/experimental/plugin.cpp
+++ b/src/webengine/plugin/experimental/plugin.cpp
@@ -41,6 +41,7 @@
#include <QtQml/qqmlextensionplugin.h>
+#include "qquickwebenginehistory_p.h"
#include "qquickwebengineview_p.h"
#include "qquickwebengineview_p_p.h"
@@ -71,6 +72,10 @@ public:
QObject::tr("Cannot create a separate instance of WebEngineViewExperimental"));
qmlRegisterUncreatableType<QQuickWebEngineViewport>(uri, 1, 0, "WebEngineViewport",
QObject::tr("Cannot create a separate instance of WebEngineViewport"));
+ qmlRegisterUncreatableType<QQuickWebEngineHistory>(uri, 1, 0, "NavigationHistory",
+ QObject::tr("Cannot create a separate instance of NavigationHistory"));
+ qmlRegisterUncreatableType<QQuickWebEngineHistoryListModel>(uri, 1, 0, "NavigationHistoryListModel",
+ QObject::tr("Cannot create a separate instance of NavigationHistory"));
}
};
diff --git a/src/webengine/webengine.pro b/src/webengine/webengine.pro
index cd175bfcc..c0e90892a 100644
--- a/src/webengine/webengine.pro
+++ b/src/webengine/webengine.pro
@@ -9,6 +9,7 @@ QT_PRIVATE += webenginecore qml-private quick-private gui-private core-private
INCLUDEPATH += $$PWD api ../core
SOURCES = \
+ api/qquickwebenginehistory.cpp \
api/qquickwebengineloadrequest.cpp \
api/qquickwebenginenewviewrequest.cpp \
api/qquickwebengineview.cpp \
@@ -18,6 +19,7 @@ SOURCES = \
HEADERS = \
api/qtwebengineglobal.h \
api/qtwebengineglobal_p.h \
+ api/qquickwebenginehistory_p.h \
api/qquickwebengineloadrequest_p.h \
api/qquickwebenginenewviewrequest_p.h \
api/qquickwebengineview_p.h \