summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2020-10-21 16:55:40 +0200
committerMichal Klocek <michal.klocek@qt.io>2020-11-24 09:45:24 +0100
commit5400fb840b3d04eacc29b4d91a2f2e053fbe0b48 (patch)
treee0fa82b2a064251b8598d8ef5d85f67fa7e20f5e
parent5a95654b3fc7bff082346c2d59f816ed0d3a4077 (diff)
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 <allan.jensen@qt.io>
-rw-r--r--src/core/api/core_api.pro8
-rw-r--r--src/core/api/qwebenginehistory.cpp (renamed from src/webenginewidgets/api/qwebenginehistory.cpp)102
-rw-r--r--src/core/api/qwebenginehistory.h (renamed from src/webenginewidgets/api/qwebenginehistory.h)15
-rw-r--r--src/core/api/qwebenginehistory_p.h (renamed from src/webenginewidgets/api/qwebenginehistory_p.h)18
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp17
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h4
-rw-r--r--src/webenginewidgets/webenginewidgets.pro2
7 files changed, 85 insertions, 81 deletions
diff --git a/src/core/api/core_api.pro b/src/core/api/core_api.pro
index ac7313a1a..95095a2f7 100644
--- a/src/core/api/core_api.pro
+++ b/src/core/api/core_api.pro
@@ -62,7 +62,10 @@ HEADERS = \
qwebenginescriptcollection_p.h \
qwebengineprofile.h \
qwebengineprofile_p.h \
- qwebengineclientcertificateselection.h
+ qwebengineclientcertificateselection.h \
+ qwebenginehistory.h \
+ qwebenginehistory_p.h
+
SOURCES = \
qtwebenginecoreglobal.cpp \
@@ -86,7 +89,8 @@ SOURCES = \
qwebenginescript.cpp \
qwebenginescriptcollection.cpp \
qwebengineprofile.cpp \
- qwebengineclientcertificateselection.cpp
+ qwebengineclientcertificateselection.cpp \
+ qwebenginehistory.cpp
# Chromium headers included are not remotely clean
CONFIG -= warning_clean
diff --git a/src/webenginewidgets/api/qwebenginehistory.cpp b/src/core/api/qwebenginehistory.cpp
index 6a85b984e..2f32444b2 100644
--- a/src/webenginewidgets/api/qwebenginehistory.cpp
+++ b/src/core/api/qwebenginehistory.cpp
@@ -40,7 +40,6 @@
#include "qwebenginehistory.h"
#include "qwebenginehistory_p.h"
-#include "qwebenginepage_p.h"
#include "web_contents_adapter.h"
QT_BEGIN_NAMESPACE
@@ -50,21 +49,15 @@ QT_BEGIN_NAMESPACE
Swaps the history item with the \a other item.
*/
-QWebEngineHistoryItemPrivate::QWebEngineHistoryItemPrivate(QWebEnginePagePrivate *page, int index)
- : page(page)
- , index(index)
+QWebEngineHistoryItemPrivate::QWebEngineHistoryItemPrivate(
+ QtWebEngineCore::WebContentsAdapterClient *adapter, int index)
+ : m_adapter(adapter), index(index)
{
}
-QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d)
- : d(d)
-{
-}
+QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d) : d(d) { }
-QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other)
- : d(other.d)
-{
-}
+QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other) : d(other.d) { }
QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryItem &other)
{
@@ -72,32 +65,35 @@ QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryI
return *this;
}
-QWebEngineHistoryItem::~QWebEngineHistoryItem()
-{
-}
+QWebEngineHistoryItem::~QWebEngineHistoryItem() { }
QUrl QWebEngineHistoryItem::originalUrl() const
{
Q_D(const QWebEngineHistoryItem);
- return d->page ? d->page->webContents()->getNavigationEntryOriginalUrl(d->index) : QUrl();
+ return d->m_adapter
+ ? d->m_adapter->webContentsAdapter()->getNavigationEntryOriginalUrl(d->index)
+ : QUrl();
}
QUrl QWebEngineHistoryItem::url() const
{
Q_D(const QWebEngineHistoryItem);
- return d->page ? d->page->webContents()->getNavigationEntryUrl(d->index) : QUrl();
+ return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryUrl(d->index)
+ : QUrl();
}
QString QWebEngineHistoryItem::title() const
{
Q_D(const QWebEngineHistoryItem);
- return d->page ? d->page->webContents()->getNavigationEntryTitle(d->index) : QString();
+ return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryTitle(d->index)
+ : QString();
}
QDateTime QWebEngineHistoryItem::lastVisited() const
{
Q_D(const QWebEngineHistoryItem);
- return d->page ? d->page->webContents()->getNavigationEntryTimestamp(d->index) : QDateTime();
+ return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryTimestamp(d->index)
+ : QDateTime();
}
/*!
@@ -108,19 +104,21 @@ QDateTime QWebEngineHistoryItem::lastVisited() const
QUrl QWebEngineHistoryItem::iconUrl() const
{
Q_D(const QWebEngineHistoryItem);
- return d->page ? d->page->webContents()->getNavigationEntryIconUrl(d->index) : QUrl();
+ return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryIconUrl(d->index)
+ : QUrl();
}
bool QWebEngineHistoryItem::isValid() const
{
Q_D(const QWebEngineHistoryItem);
- if (!d->page)
+ if (!d->m_adapter)
return false;
- return d->index >= 0 && d->index < d->page->webContents()->navigationEntryCount();
+ return d->index >= 0 && d->index < d->m_adapter->webContentsAdapter()->navigationEntryCount();
}
-QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(QWebEnginePagePrivate *page)
- : page(page)
+QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(
+ QtWebEngineCore::WebContentsAdapterClient *adapter)
+ : m_adapter(adapter)
{
}
@@ -129,38 +127,33 @@ QWebEngineHistoryPrivate::~QWebEngineHistoryPrivate()
// Invalidate shared item references possibly still out there.
QList<QWebEngineHistoryItem>::iterator it, end;
for (it = items.begin(), end = items.end(); it != end; ++it)
- it->d->page = 0;
+ it->d->m_adapter = 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();
+ // and avoid dangling references to our m_adapter.
+ int entryCount = m_adapter->webContentsAdapter()->navigationEntryCount();
while (items.size() > entryCount) {
- items.last().d->page = 0;
+ items.last().d->m_adapter = 0;
items.removeLast();
}
while (items.size() < entryCount) {
int nextIndex = items.size();
- items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(page, nextIndex)));
+ items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(m_adapter, nextIndex)));
}
}
-QWebEngineHistory::QWebEngineHistory(QWebEngineHistoryPrivate *d)
- : d_ptr(d)
-{
-}
+QWebEngineHistory::QWebEngineHistory(QWebEngineHistoryPrivate *d) : d_ptr(d) { }
-QWebEngineHistory::~QWebEngineHistory()
-{
-}
+QWebEngineHistory::~QWebEngineHistory() { }
void QWebEngineHistory::clear()
{
Q_D(const QWebEngineHistory);
- d->page->webContents()->clearNavigationHistory();
- d->page->updateNavigationActions();
+ d->m_adapter->webContentsAdapter()->clearNavigationHistory();
+ d->m_adapter->updateNavigationActions();
}
QList<QWebEngineHistoryItem> QWebEngineHistory::items() const
@@ -191,32 +184,32 @@ QList<QWebEngineHistoryItem> QWebEngineHistory::forwardItems(int maxItems) const
bool QWebEngineHistory::canGoBack() const
{
Q_D(const QWebEngineHistory);
- return d->page->webContents()->canGoToOffset(-1);
+ return d->m_adapter->webContentsAdapter()->canGoToOffset(-1);
}
bool QWebEngineHistory::canGoForward() const
{
Q_D(const QWebEngineHistory);
- return d->page->webContents()->canGoToOffset(1);
+ return d->m_adapter->webContentsAdapter()->canGoToOffset(1);
}
void QWebEngineHistory::back()
{
Q_D(const QWebEngineHistory);
- d->page->webContents()->navigateToOffset(-1);
+ d->m_adapter->webContentsAdapter()->navigateToOffset(-1);
}
void QWebEngineHistory::forward()
{
Q_D(const QWebEngineHistory);
- d->page->webContents()->navigateToOffset(1);
+ d->m_adapter->webContentsAdapter()->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);
+ Q_ASSERT(item.d->m_adapter == d->m_adapter);
+ d->m_adapter->webContentsAdapter()->navigateToIndex(item.d->index);
}
QWebEngineHistoryItem QWebEngineHistory::backItem() const
@@ -251,30 +244,15 @@ QWebEngineHistoryItem QWebEngineHistory::itemAt(int i) const
int QWebEngineHistory::currentItemIndex() const
{
Q_D(const QWebEngineHistory);
- return d->page->webContents()->currentNavigationEntryIndex();
+ return d->m_adapter->webContentsAdapter()->currentNavigationEntryIndex();
}
int QWebEngineHistory::count() const
{
Q_D(const QWebEngineHistory);
- if (!d->page->webContents()->isInitialized())
+ if (!d->m_adapter->webContentsAdapter()->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;
+ return d->m_adapter->webContentsAdapter()->navigationEntryCount();
}
QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebenginehistory.h b/src/core/api/qwebenginehistory.h
index 33d91d523..f7e591e38 100644
--- a/src/webenginewidgets/api/qwebenginehistory.h
+++ b/src/core/api/qwebenginehistory.h
@@ -40,12 +40,12 @@
#ifndef QWEBENGINEHISTORY_H
#define QWEBENGINEHISTORY_H
+#include <QtWebEngineCore/qtwebenginecoreglobal.h>
#include <QtCore/qurl.h>
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qshareddata.h>
#include <QtGui/qicon.h>
-#include <QtWebEngineWidgets/qtwebenginewidgetsglobal.h>
QT_BEGIN_NAMESPACE
@@ -54,7 +54,8 @@ class QWebEngineHistoryItemPrivate;
class QWebEnginePage;
class QWebEnginePagePrivate;
-class QWEBENGINEWIDGETS_EXPORT QWebEngineHistoryItem {
+class Q_WEBENGINECORE_EXPORT QWebEngineHistoryItem
+{
public:
QWebEngineHistoryItem(const QWebEngineHistoryItem &other);
QWebEngineHistoryItem &operator=(const QWebEngineHistoryItem &other);
@@ -82,7 +83,8 @@ private:
Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QWebEngineHistoryItem)
class QWebEngineHistoryPrivate;
-class QWEBENGINEWIDGETS_EXPORT QWebEngineHistory {
+class Q_WEBENGINECORE_EXPORT QWebEngineHistory
+{
public:
void clear();
@@ -114,15 +116,12 @@ private:
Q_DECLARE_PRIVATE(QWebEngineHistory)
QScopedPointer<QWebEngineHistoryPrivate> d_ptr;
- friend QWEBENGINEWIDGETS_EXPORT QDataStream& operator>>(QDataStream&, QWebEngineHistory&);
- friend QWEBENGINEWIDGETS_EXPORT QDataStream& operator<<(QDataStream&, const QWebEngineHistory&);
+ friend Q_WEBENGINECORE_EXPORT QDataStream &operator>>(QDataStream &, QWebEngineHistory &);
+ friend Q_WEBENGINECORE_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/core/api/qwebenginehistory_p.h
index 8f7001967..2ca944e5b 100644
--- a/src/webenginewidgets/api/qwebenginehistory_p.h
+++ b/src/core/api/qwebenginehistory_p.h
@@ -50,29 +50,33 @@
//
// We mean it.
//
-
+#include "qtwebenginecoreglobal_p.h"
#include <QtCore/qshareddata.h>
+namespace QtWebEngineCore {
+class WebContentsAdapterClient;
+}
+
QT_BEGIN_NAMESPACE
class QWebEnginePagePrivate;
class QWebEngineHistoryItemPrivate : public QSharedData
{
public:
- QWebEngineHistoryItemPrivate(QWebEnginePagePrivate *page = 0, int index = 0);
-
- QWebEnginePagePrivate *page;
+ QWebEngineHistoryItemPrivate(QtWebEngineCore::WebContentsAdapterClient *adapter = nullptr,
+ int index = 0);
+ QtWebEngineCore::WebContentsAdapterClient *m_adapter;
int index;
};
-class QWebEngineHistoryPrivate
+class Q_WEBENGINECORE_PRIVATE_EXPORT QWebEngineHistoryPrivate
{
public:
- QWebEngineHistoryPrivate(QWebEnginePagePrivate *page);
+ QWebEngineHistoryPrivate(QtWebEngineCore::WebContentsAdapterClient *adapter);
~QWebEngineHistoryPrivate();
void updateItems() const;
- QWebEnginePagePrivate *page;
+ QtWebEngineCore::WebContentsAdapterClient *m_adapter;
mutable QList<QWebEngineHistoryItem> items;
};
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<QWebEnginePagePrivate *>(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<QWebEnginePagePrivate *>(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
diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro
index 788554ae3..7263c1bbe 100644
--- a/src/webenginewidgets/webenginewidgets.pro
+++ b/src/webenginewidgets/webenginewidgets.pro
@@ -12,7 +12,6 @@ QT_PRIVATE += quick-private gui-private core-private widgets-private quickwidget
INCLUDEPATH += $$PWD api ../core ../core/api ../webengine/api
SOURCES = \
- api/qwebenginehistory.cpp \
api/qwebenginenotificationpresenter.cpp \
api/qwebenginepage.cpp \
api/qwebengineview.cpp \
@@ -20,7 +19,6 @@ SOURCES = \
HEADERS = \
api/qtwebenginewidgetsglobal.h \
- api/qwebenginehistory.h \
api/qwebenginenotificationpresenter_p.h \
api/qwebenginepage.h \
api/qwebenginepage_p.h \