Skip to content

Commit b4589db

Browse files
author
Kirill Burtsev
committed
Reset findText reply id on StopFinding to prevent callback later
Not updating lastReceivedFindReply caused next findText call after StopFinding to trigger redundant callback call on checking stale query. Fixes: QTBUG-77029 Change-Id: Iad4b71364ecb3ec3db3096b739e77620d12731f9 Reviewed-by: Peter Varga <[email protected]>
1 parent 73daf5b commit b4589db

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

src/core/web_contents_adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ quint64 WebContentsAdapter::findText(const QString &subString, bool caseSensitiv
987987
// waiting for it forever.
988988
// Assume that any unfinished find has been unsuccessful when a new one is started
989989
// to cover that case.
990+
m_webContentsDelegate->setLastReceivedFindReply(m_lastFindRequestId);
990991
m_adapterClient->didFindText(m_lastFindRequestId, 0);
991992
}
992993

@@ -1007,6 +1008,7 @@ quint64 WebContentsAdapter::findText(const QString &subString, bool caseSensitiv
10071008
void WebContentsAdapter::stopFinding()
10081009
{
10091010
CHECK_INITIALIZED();
1011+
m_webContentsDelegate->setLastReceivedFindReply(m_lastFindRequestId);
10101012
m_webContentsDelegate->setLastSearchedString(QString());
10111013
m_webContents->StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION);
10121014
}

src/core/web_contents_delegate_qt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ void WebContentsDelegateQt::FindReply(content::WebContents *source, int request_
510510
Q_UNUSED(source)
511511
Q_UNUSED(selection_rect)
512512
Q_UNUSED(active_match_ordinal)
513-
if (final_update) {
513+
if (final_update && request_id > m_lastReceivedFindReply) {
514514
m_lastReceivedFindReply = request_id;
515515
m_viewClient->didFindText(request_id, number_of_matches);
516516
}

src/core/web_contents_delegate_qt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class WebContentsDelegateQt : public content::WebContentsDelegate
114114
QString lastSearchedString() const { return m_lastSearchedString; }
115115
void setLastSearchedString(const QString &s) { m_lastSearchedString = s; }
116116
int lastReceivedFindReply() const { return m_lastReceivedFindReply; }
117+
void setLastReceivedFindReply(int id) { m_lastReceivedFindReply = id; }
117118

118119
QUrl url() const { return m_url; }
119120
QString title() const { return m_title; }

tests/auto/quick/qmltests/data/tst_findText.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ TestWebEngineView {
222222
expectFailContinue('', 'No unexpected findText callback calls occurred.')
223223
tryVerify(function() { return webEngineView.findCallbackCalled() })
224224
verify(!webEngineView.findCallbackCalled())
225+
226+
webEngineView.clear();
227+
webEngineView.findText('New page', findFlags, webEngineView.findTextCallback)
228+
tryCompare(webEngineView, 'matchCount', 1)
225229
}
226230
}
227231
}

0 commit comments

Comments
 (0)