summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_adapter.cpp
diff options
context:
space:
mode:
authorMartin Negyokru <negyokru@inf.u-szeged.hu>2023-09-26 14:45:15 +0200
committerMartin Negyokru <negyokru@inf.u-szeged.hu>2023-09-28 13:47:27 +0000
commitf19aa5e343db66e5baacacd3c360c4cb00a01c7c (patch)
tree97a552e9cf1d6d9c4fb680d41488f8af3490c224 /src/core/web_contents_adapter.cpp
parentbd8572420779a916969fc2286e04269616348f71 (diff)
Handle initial NavigationEntries
Chromium introduced the Initial NavigationEntry that meant to represent the initial empty document at FrameTree creation time. It is just a placeholder entry put in the list of NavigationEntries that gets replaced on the next navigation. A side effect of this is that we have an extra entry in the list before we load any page. This change also reverts the history related tests modified by 106 Adaptations that introduced this behavior. Fixes: QTBUG-117489 Pick-to: 6.5 6.6 Change-Id: I2738591b681082792544bd884f8ecec54ce9d72d Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r--src/core/web_contents_adapter.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 31a3ab93c..91a939bd2 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -210,10 +210,28 @@ static std::unique_ptr<content::WebContents> createBlankWebContents(WebContentsA
return webContents;
}
+static int navigationListSize(content::NavigationController &controller) {
+ // If we're currently on the initial NavigationEntry, no navigation has
+ // committed, so the initial NavigationEntry should not be part of the
+ // "Navigation List", and we should return 0 as the navigation list size.
+ if (controller.GetLastCommittedEntry()->IsInitialEntry())
+ return 0;
+ return controller.GetEntryCount();
+}
+
+static int navigationListCurrentIndex(content::NavigationController &controller) {
+ // If we're currently on the initial NavigationEntry, no navigation has
+ // committed, so the initial NavigationEntry should not be part of the
+ // "Navigation List", and we should return -1 as the current index.
+ if (controller.GetLastCommittedEntry()->IsInitialEntry())
+ return -1;
+ return controller.GetCurrentEntryIndex();
+}
+
static void serializeNavigationHistory(content::NavigationController &controller, QDataStream &output)
{
- const int currentIndex = controller.GetCurrentEntryIndex();
- const int count = controller.GetEntryCount();
+ const int currentIndex = navigationListCurrentIndex(controller);
+ const int count = navigationListSize(controller);
const int pendingIndex = controller.GetPendingEntryIndex();
output << kHistoryStreamVersion;
@@ -910,13 +928,13 @@ void WebContentsAdapter::navigateToOffset(int offset)
int WebContentsAdapter::navigationEntryCount()
{
CHECK_INITIALIZED(0);
- return m_webContents->GetController().GetEntryCount();
+ return navigationListSize(m_webContents->GetController());
}
int WebContentsAdapter::currentNavigationEntryIndex()
{
CHECK_INITIALIZED(0);
- return m_webContents->GetController().GetCurrentEntryIndex();
+ return navigationListCurrentIndex(m_webContents->GetController());
}
QUrl WebContentsAdapter::getNavigationEntryOriginalUrl(int index)