summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitriy Kuminov <coding@dmik\.org>2019-10-29 11:17:38 +0100
committerJüri Valdmann <juri.valdmann@qt.io>2019-11-08 17:50:24 +0100
commit85dbb7c99e25889b4b24594f46d2093c8c6febc9 (patch)
treeeb1572b0a229287c90f27c20d0697c1a9b3a962d /src
parent025710fa77f80c0940705bc4ad405872b5aeecfe (diff)
Store favicon URL when serializing QWebEngineHistory
This is to make QWebEngineHistoryItem::iconUrl of the deserialized QWebEngineHistory object return the same URL it had when serializing. Otherwise it's impossible to have favicons for URLs from the navigation history of a restored browser session until these URLs are visited again (so that Chromium refetches their favicons). These icons are usually needed much earlier - e.g. when showing a popup with the navigation history and having an icon URL allows to load it from a disk cache before visiting the page. Fixes: QTBUG-78998 Change-Id: Ief2d089d52f301826e5c131d401cafd08952a8b5 Reviewed-by: Michael Brüning <michael.bruning@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/web_contents_adapter.cpp26
1 files changed, 20 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();
}