diff options
-rw-r--r-- | src/core/web_contents_adapter.cpp | 26 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginehistory/resources/page5.html | 1 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp | 8 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 3ad2d54d2..4cfcf6acd 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -134,7 +134,7 @@ namespace QtWebEngineCore { static const int kTestWindowWidth = 800; static const int kTestWindowHeight = 600; -static const int kHistoryStreamVersion = 3; +static const int kHistoryStreamVersion = 4; static QVariant fromJSValue(const base::Value *result) { @@ -279,6 +279,9 @@ static void serializeNavigationHistory(content::NavigationController &controller output << entry->GetIsOverridingUserAgent(); output << static_cast<qint64>(entry->GetTimestamp().ToInternalValue()); output << entry->GetHttpStatusCode(); + // kHistoryStreamVersion >= 4 + content::FaviconStatus &favicon = entry->GetFavicon(); + output << (favicon.valid ? toQt(favicon.url) : QUrl()); } } } @@ -287,8 +290,8 @@ static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, { int version; input >> version; - if (version != kHistoryStreamVersion) { - // We do not try to decode previous history stream versions. + if (version < 3 || version > kHistoryStreamVersion) { + // We do not try to decode history stream versions before 3. // Make sure that our history is cleared and mark the rest of the stream as invalid. input.setStatus(QDataStream::ReadCorruptData); *currentIndex = -1; @@ -301,7 +304,7 @@ static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, entries->reserve(count); // Logic taken from SerializedNavigationEntry::ReadFromPickle and ToNavigationEntries. for (int i = 0; i < count; ++i) { - QUrl virtualUrl, referrerUrl, originalRequestUrl; + QUrl virtualUrl, referrerUrl, originalRequestUrl, iconUrl; QString title; QByteArray pageState; qint32 transitionType, referrerPolicy; @@ -319,6 +322,9 @@ static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, input >> isOverridingUserAgent; input >> timestamp; input >> httpStatusCode; + // kHistoryStreamVersion >= 4 + if (version >= 4) + input >> iconUrl; // If we couldn't unpack the entry successfully, abort everything. if (input.status() != QDataStream::Ok) { @@ -351,6 +357,14 @@ static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, entry->SetIsOverridingUserAgent(isOverridingUserAgent); entry->SetTimestamp(base::Time::FromInternalValue(timestamp)); entry->SetHttpStatusCode(httpStatusCode); + if (iconUrl.isValid()) { + // Note: we don't set .image below as we don't have it and chromium will refetch favicon + // anyway. However, we set .url and .valid to let QWebEngineHistory items restored from + // a stream receive valid icon URLs via our getNavigationEntryIconUrl calls. + content::FaviconStatus &favicon = entry->GetFavicon(); + favicon.url = toGurl(iconUrl); + favicon.valid = true; + } entries->push_back(std::move(entry)); } } @@ -778,7 +792,7 @@ QUrl WebContentsAdapter::iconUrl() const { CHECK_INITIALIZED(QUrl()); if (content::NavigationEntry* entry = m_webContents->GetController().GetVisibleEntry()) { - content::FaviconStatus favicon = entry->GetFavicon(); + content::FaviconStatus &favicon = entry->GetFavicon(); if (favicon.valid) return toQt(favicon.url); } @@ -935,7 +949,7 @@ QUrl WebContentsAdapter::getNavigationEntryIconUrl(int index) content::NavigationEntry *entry = m_webContents->GetController().GetEntryAtIndex(index); if (!entry) return QUrl(); - content::FaviconStatus favicon = entry->GetFavicon(); + content::FaviconStatus &favicon = entry->GetFavicon(); return favicon.valid ? toQt(favicon.url) : QUrl(); } diff --git a/tests/auto/widgets/qwebenginehistory/resources/page5.html b/tests/auto/widgets/qwebenginehistory/resources/page5.html index 859355279..cad6d964e 100644 --- a/tests/auto/widgets/qwebenginehistory/resources/page5.html +++ b/tests/auto/widgets/qwebenginehistory/resources/page5.html @@ -1 +1,2 @@ +<link rel="icon" href="qrc:/qt-project.org/qmessagebox/images/qtlogo-64.png"> <title>page5</title><body><h1>page5</h1></body> diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index 6209401cb..bdb486793 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -51,6 +51,7 @@ public Q_SLOTS: private Q_SLOTS: void title(); void lastVisited(); + void iconUrl(); void count(); void back(); void forward(); @@ -126,6 +127,11 @@ void tst_QWebEngineHistory::lastVisited() QVERIFY(qAbs(hist->itemAt(0).lastVisited().secsTo(QDateTime::currentDateTime())) < 60); } +void tst_QWebEngineHistory::iconUrl() +{ + QTRY_COMPARE(hist->currentItem().iconUrl(), QUrl("qrc:/qt-project.org/qmessagebox/images/qtlogo-64.png")); +} + /** * Check QWebEngineHistory::count() method */ @@ -336,6 +342,7 @@ void tst_QWebEngineHistory::serialize_3() QDateTime lastVisited(a.lastVisited()); QUrl originalUrl(a.originalUrl()); QUrl url(a.url()); + QUrl iconUrl(a.iconUrl()); save << *hist; QVERIFY(save.status() == QDataStream::Ok); @@ -351,6 +358,7 @@ void tst_QWebEngineHistory::serialize_3() QTRY_COMPARE(b.lastVisited(), lastVisited); QTRY_COMPARE(b.originalUrl(), originalUrl); QTRY_COMPARE(b.url(), url); + QTRY_COMPARE(b.iconUrl(), iconUrl); //Check if all data was read QVERIFY(load.atEnd()); |