From 5400fb840b3d04eacc29b4d91a2f2e053fbe0b48 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Wed, 21 Oct 2020 16:55:40 +0200 Subject: Move QWebEngineHistory to core Keep debug stream operators in page for now, since QWebEngineHsitory is accessible from page only. [ChangeLog] QWebEngineHistory is in QtWebEngineCore Task-number: QTBUG-74585 Change-Id: I5dfc13a0d59ac87f18fe4905ebcfd4a9ec5ad3a1 Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginehistory.cpp | 280 ------------------------- src/webenginewidgets/api/qwebenginehistory.h | 128 ----------- src/webenginewidgets/api/qwebenginehistory_p.h | 81 ------- src/webenginewidgets/api/qwebenginepage.cpp | 17 ++ src/webenginewidgets/api/qwebenginepage.h | 4 + 5 files changed, 21 insertions(+), 489 deletions(-) delete mode 100644 src/webenginewidgets/api/qwebenginehistory.cpp delete mode 100644 src/webenginewidgets/api/qwebenginehistory.h delete mode 100644 src/webenginewidgets/api/qwebenginehistory_p.h (limited to 'src/webenginewidgets/api') diff --git a/src/webenginewidgets/api/qwebenginehistory.cpp b/src/webenginewidgets/api/qwebenginehistory.cpp deleted file mode 100644 index 6a85b984e..000000000 --- a/src/webenginewidgets/api/qwebenginehistory.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwebenginehistory.h" -#include "qwebenginehistory_p.h" - -#include "qwebenginepage_p.h" -#include "web_contents_adapter.h" - -QT_BEGIN_NAMESPACE - -/*! - \fn QWebEngineHistoryItem::swap(QWebEngineHistoryItem &other) - Swaps the history item with the \a other item. -*/ - -QWebEngineHistoryItemPrivate::QWebEngineHistoryItemPrivate(QWebEnginePagePrivate *page, int index) - : page(page) - , index(index) -{ -} - -QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d) - : d(d) -{ -} - -QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other) - : d(other.d) -{ -} - -QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryItem &other) -{ - d = other.d; - return *this; -} - -QWebEngineHistoryItem::~QWebEngineHistoryItem() -{ -} - -QUrl QWebEngineHistoryItem::originalUrl() const -{ - Q_D(const QWebEngineHistoryItem); - return d->page ? d->page->webContents()->getNavigationEntryOriginalUrl(d->index) : QUrl(); -} - -QUrl QWebEngineHistoryItem::url() const -{ - Q_D(const QWebEngineHistoryItem); - return d->page ? d->page->webContents()->getNavigationEntryUrl(d->index) : QUrl(); -} - -QString QWebEngineHistoryItem::title() const -{ - Q_D(const QWebEngineHistoryItem); - return d->page ? d->page->webContents()->getNavigationEntryTitle(d->index) : QString(); -} - -QDateTime QWebEngineHistoryItem::lastVisited() const -{ - Q_D(const QWebEngineHistoryItem); - return d->page ? d->page->webContents()->getNavigationEntryTimestamp(d->index) : QDateTime(); -} - -/*! - Returns the URL of the icon associated with the history item. - - \sa url(), originalUrl(), title() -*/ -QUrl QWebEngineHistoryItem::iconUrl() const -{ - Q_D(const QWebEngineHistoryItem); - return d->page ? d->page->webContents()->getNavigationEntryIconUrl(d->index) : QUrl(); -} - -bool QWebEngineHistoryItem::isValid() const -{ - Q_D(const QWebEngineHistoryItem); - if (!d->page) - return false; - return d->index >= 0 && d->index < d->page->webContents()->navigationEntryCount(); -} - -QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(QWebEnginePagePrivate *page) - : page(page) -{ -} - -QWebEngineHistoryPrivate::~QWebEngineHistoryPrivate() -{ - // Invalidate shared item references possibly still out there. - QList::iterator it, end; - for (it = items.begin(), end = items.end(); it != end; ++it) - it->d->page = 0; -} - -void QWebEngineHistoryPrivate::updateItems() const -{ - // Keep track of items we return to be able to invalidate them - // and avoid dangling references to our page. - int entryCount = page->webContents()->navigationEntryCount(); - while (items.size() > entryCount) { - items.last().d->page = 0; - items.removeLast(); - } - while (items.size() < entryCount) { - int nextIndex = items.size(); - items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(page, nextIndex))); - } -} - -QWebEngineHistory::QWebEngineHistory(QWebEngineHistoryPrivate *d) - : d_ptr(d) -{ -} - -QWebEngineHistory::~QWebEngineHistory() -{ -} - -void QWebEngineHistory::clear() -{ - Q_D(const QWebEngineHistory); - d->page->webContents()->clearNavigationHistory(); - d->page->updateNavigationActions(); -} - -QList QWebEngineHistory::items() const -{ - Q_D(const QWebEngineHistory); - d->updateItems(); - return d->items; -} - -QList QWebEngineHistory::backItems(int maxItems) const -{ - Q_D(const QWebEngineHistory); - d->updateItems(); - const int end = currentItemIndex(); - const int start = std::max(0, end - maxItems); - return d->items.mid(start, end - start); -} - -QList QWebEngineHistory::forwardItems(int maxItems) const -{ - Q_D(const QWebEngineHistory); - d->updateItems(); - const int start = currentItemIndex() + 1; - const int end = std::min(count(), start + maxItems); - return d->items.mid(start, end - start); -} - -bool QWebEngineHistory::canGoBack() const -{ - Q_D(const QWebEngineHistory); - return d->page->webContents()->canGoToOffset(-1); -} - -bool QWebEngineHistory::canGoForward() const -{ - Q_D(const QWebEngineHistory); - return d->page->webContents()->canGoToOffset(1); -} - -void QWebEngineHistory::back() -{ - Q_D(const QWebEngineHistory); - d->page->webContents()->navigateToOffset(-1); -} - -void QWebEngineHistory::forward() -{ - Q_D(const QWebEngineHistory); - d->page->webContents()->navigateToOffset(1); -} - -void QWebEngineHistory::goToItem(const QWebEngineHistoryItem &item) -{ - Q_D(const QWebEngineHistory); - Q_ASSERT(item.d->page == d->page); - d->page->webContents()->navigateToIndex(item.d->index); -} - -QWebEngineHistoryItem QWebEngineHistory::backItem() const -{ - return itemAt(currentItemIndex() - 1); -} - -QWebEngineHistoryItem QWebEngineHistory::currentItem() const -{ - return itemAt(currentItemIndex()); -} - -QWebEngineHistoryItem QWebEngineHistory::forwardItem() const -{ - return itemAt(currentItemIndex() + 1); -} - -QWebEngineHistoryItem QWebEngineHistory::itemAt(int i) const -{ - Q_D(const QWebEngineHistory); - if (i >= 0 && i < count()) { - d->updateItems(); - return d->items[i]; - } else { - // Return an invalid item right away. - QWebEngineHistoryItem item(new QWebEngineHistoryItemPrivate(0, i)); - Q_ASSERT(!item.isValid()); - return item; - } -} - -int QWebEngineHistory::currentItemIndex() const -{ - Q_D(const QWebEngineHistory); - return d->page->webContents()->currentNavigationEntryIndex(); -} - -int QWebEngineHistory::count() const -{ - Q_D(const QWebEngineHistory); - if (!d->page->webContents()->isInitialized()) - return 0; - return d->page->webContents()->navigationEntryCount(); -} - -QDataStream& operator<<(QDataStream& stream, const QWebEngineHistory& history) -{ - QtWebEngineCore::WebContentsAdapter *adapter = history.d_func()->page->webContents(); - if (!adapter->isInitialized()) - adapter->loadDefault(); - adapter->serializeNavigationHistory(stream); - return stream; -} - -QDataStream& operator>>(QDataStream& stream, QWebEngineHistory& history) -{ - history.d_func()->page->recreateFromSerializedHistory(stream); - return stream; -} - -QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebenginehistory.h b/src/webenginewidgets/api/qwebenginehistory.h deleted file mode 100644 index 33d91d523..000000000 --- a/src/webenginewidgets/api/qwebenginehistory.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWEBENGINEHISTORY_H -#define QWEBENGINEHISTORY_H - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QWebEngineHistory; -class QWebEngineHistoryItemPrivate; -class QWebEnginePage; -class QWebEnginePagePrivate; - -class QWEBENGINEWIDGETS_EXPORT QWebEngineHistoryItem { -public: - QWebEngineHistoryItem(const QWebEngineHistoryItem &other); - QWebEngineHistoryItem &operator=(const QWebEngineHistoryItem &other); - ~QWebEngineHistoryItem(); - - QUrl originalUrl() const; - QUrl url() const; - - QString title() const; - QDateTime lastVisited() const; - QUrl iconUrl() const; - - bool isValid() const; - - void swap(QWebEngineHistoryItem &other) Q_DECL_NOTHROW { qSwap(d, other.d); } - -private: - QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *priv); - Q_DECLARE_PRIVATE_D(d.data(), QWebEngineHistoryItem) - QExplicitlySharedDataPointer d; - friend class QWebEngineHistory; - friend class QWebEngineHistoryPrivate; -}; - -Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QWebEngineHistoryItem) - -class QWebEngineHistoryPrivate; -class QWEBENGINEWIDGETS_EXPORT QWebEngineHistory { -public: - void clear(); - - QList items() const; - QList backItems(int maxItems) const; - QList forwardItems(int maxItems) const; - - bool canGoBack() const; - bool canGoForward() const; - - void back(); - void forward(); - void goToItem(const QWebEngineHistoryItem &item); - - QWebEngineHistoryItem backItem() const; - QWebEngineHistoryItem currentItem() const; - QWebEngineHistoryItem forwardItem() const; - QWebEngineHistoryItem itemAt(int i) const; - - int currentItemIndex() const; - - int count() const; - -private: - QWebEngineHistory(QWebEngineHistoryPrivate *d); - ~QWebEngineHistory(); - - Q_DISABLE_COPY(QWebEngineHistory) - Q_DECLARE_PRIVATE(QWebEngineHistory) - QScopedPointer d_ptr; - - friend QWEBENGINEWIDGETS_EXPORT QDataStream& operator>>(QDataStream&, QWebEngineHistory&); - friend QWEBENGINEWIDGETS_EXPORT QDataStream& operator<<(QDataStream&, const QWebEngineHistory&); - friend class QWebEnginePage; - friend class QWebEnginePagePrivate; -}; - -QWEBENGINEWIDGETS_EXPORT QDataStream& operator<<(QDataStream& stream, const QWebEngineHistory& history); -QWEBENGINEWIDGETS_EXPORT QDataStream& operator>>(QDataStream& stream, QWebEngineHistory& history); - -QT_END_NAMESPACE - -#endif // QWEBENGINEHISTORY_H diff --git a/src/webenginewidgets/api/qwebenginehistory_p.h b/src/webenginewidgets/api/qwebenginehistory_p.h deleted file mode 100644 index 8f7001967..000000000 --- a/src/webenginewidgets/api/qwebenginehistory_p.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWEBENGINEHISTORY_P_H -#define QWEBENGINEHISTORY_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 - -QT_BEGIN_NAMESPACE -class QWebEnginePagePrivate; - -class QWebEngineHistoryItemPrivate : public QSharedData -{ -public: - QWebEngineHistoryItemPrivate(QWebEnginePagePrivate *page = 0, int index = 0); - - QWebEnginePagePrivate *page; - int index; -}; - -class QWebEngineHistoryPrivate -{ -public: - QWebEngineHistoryPrivate(QWebEnginePagePrivate *page); - ~QWebEngineHistoryPrivate(); - void updateItems() const; - - QWebEnginePagePrivate *page; - mutable QList items; -}; - -QT_END_NAMESPACE - -#endif // QWEBENGINEHISTORY_P_H diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 3b9e3e526..8cffa5dcd 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -2432,6 +2432,23 @@ QWebEnginePage* QWebEnginePage::fromDownloadRequest(QWebEngineDownloadRequest *r return static_cast(request->d_ptr->m_adapterClient)->q_ptr; } +QDataStream &operator<<(QDataStream &stream, const QWebEngineHistory &history) +{ + QtWebEngineCore::WebContentsAdapter *adapter = + history.d_func()->m_adapter->webContentsAdapter(); + if (!adapter->isInitialized()) + adapter->loadDefault(); + adapter->serializeNavigationHistory(stream); + return stream; +} + +QDataStream &operator>>(QDataStream &stream, QWebEngineHistory &history) +{ + static_cast(history.d_func()->m_adapter) + ->recreateFromSerializedHistory(stream); + return stream; +} + QT_END_NAMESPACE #include "moc_qwebenginepage.cpp" diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index ab4b7af0f..d96dcf4d0 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -395,6 +395,10 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QWebEnginePage::FindFlags) +QWEBENGINEWIDGETS_EXPORT QDataStream &operator<<(QDataStream &stream, + const QWebEngineHistory &history); +QWEBENGINEWIDGETS_EXPORT QDataStream &operator>>(QDataStream &stream, QWebEngineHistory &history); + QT_END_NAMESPACE #endif // QWEBENGINEPAGE_H -- cgit v1.2.3