diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h index 5e489353c368001cc5ed4e5cc36ed42c7e3088d5..5d5dc356dee4b8d3015dcde7cd1207318a85604d 100644 --- a/src/core/type_conversion.h +++ b/src/core/type_conversion.h @@ -43,11 +43,13 @@ #define TYPE_CONVERSION_H #include <QColor> +#include <QDateTime> #include <QMatrix4x4> #include <QRect> #include <QString> #include <QUrl> #include "base/files/file_path.h" +#include "base/time/time.h" #include "third_party/skia/include/utils/SkMatrix44.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/rect.h" @@ -126,6 +128,11 @@ inline QMatrix4x4 toQt(const SkMatrix44 &m) m.get(3, 0), m.get(3, 1), m.get(3, 2), m.get(3, 3)); } +inline QDateTime toQt(base::Time time) +{ + return QDateTime::fromMSecsSinceEpoch(time.ToJavaTime()); +} + inline base::FilePath::StringType toFilePathString(const QString &str) { #if defined(OS_WIN) diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 7dad03e457d4cc423b5f73abea3cb031c6d18ded..7fbda1ab69606d5fd8a1259eac193822e62746d5 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -565,6 +565,13 @@ QString WebContentsAdapter::getNavigationEntryTitle(int index) return entry ? toQt(entry->GetTitle()) : QString(); } +QDateTime WebContentsAdapter::getNavigationEntryTimestamp(int index) +{ + Q_D(WebContentsAdapter); + content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index); + return entry ? toQt(entry->GetTimestamp()) : QDateTime(); +} + void WebContentsAdapter::clearNavigationHistory() { Q_D(WebContentsAdapter); diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index ba59252bf2b7188dda212bf4d1a51a2a4a44295a..6ce15aa6a6abf9c21abe2783754f7b0669e37aa3 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -89,6 +89,7 @@ public: QUrl getNavigationEntryOriginalUrl(int index); QUrl getNavigationEntryUrl(int index); QString getNavigationEntryTitle(int index); + QDateTime getNavigationEntryTimestamp(int index); void clearNavigationHistory(); void serializeNavigationHistory(QDataStream &output); void setZoomFactor(qreal); diff --git a/src/webenginewidgets/api/qwebenginehistory.cpp b/src/webenginewidgets/api/qwebenginehistory.cpp index 9b76fa1274ad8369d5888530c702bf5f7e541083..cbd3fb3b13edcb0b4e52bd1bcc85a6207995cefd 100644 --- a/src/webenginewidgets/api/qwebenginehistory.cpp +++ b/src/webenginewidgets/api/qwebenginehistory.cpp @@ -97,8 +97,8 @@ QString QWebEngineHistoryItem::title() const QDateTime QWebEngineHistoryItem::lastVisited() const { - qWarning("Not implemented: %s", __func__); - return QDateTime(); + Q_D(const QWebEngineHistoryItem); + return d->page ? d->page->webContents()->getNavigationEntryTimestamp(d->index) : QDateTime(); } QIcon QWebEngineHistoryItem::icon() const diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index cebfee67ae5f20dee80a567752054768a7ccd8ac..a5cbc6103debd67076e5c0eac456b83a6363661a 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -47,6 +47,7 @@ public Q_SLOTS: private Q_SLOTS: void title(); + void lastVisited(); void count(); void back(); void forward(); @@ -111,6 +112,12 @@ void tst_QWebEngineHistory::title() QCOMPARE(hist->currentItem().title(), QString("page5")); } +void tst_QWebEngineHistory::lastVisited() +{ + // Check that the conversion from Chromium's internal time format went well. + QVERIFY(qAbs(hist->itemAt(0).lastVisited().secsTo(QDateTime::currentDateTime())) < 60); +} + /** * Check QWebEngineHistory::count() method */