Commit ac627a3b authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

bfcache: Support for find-in-page.

When a page is navigated away, every RenderFrameHostImpl are properly
removed from find-in-page thanks to:
https://chromium-review.googlesource.com/c/chromium/src/+/1254262

However, the problem is that a removed frame does not automatically
remove its highlighted selections when it is removed.
This patch clear the highlighted selection.

If this CL is not applied, when users will go back to the page using the
back-forward cache. They will continue to see the yellow highlight.

Bug=1001087

Change-Id: Ied5d152d34210d66dfa9afc66b4b775f7cd82bc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841631
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706547}
parent e8ae087b
...@@ -409,6 +409,11 @@ void FindRequestManager::RemoveFrame(RenderFrameHost* rfh) { ...@@ -409,6 +409,11 @@ void FindRequestManager::RemoveFrame(RenderFrameHost* rfh) {
if (current_session_id_ == kInvalidId || !CheckFrame(rfh)) if (current_session_id_ == kInvalidId || !CheckFrame(rfh))
return; return;
// Make sure to always clear the highlighted selection. It is useful in case
// the user goes back to the same page using the BackForwardCache.
static_cast<RenderFrameHostImpl*>(rfh)->GetFindInPage()->StopFinding(
blink::mojom::StopFindAction::kStopFindActionClearSelection);
// If matches are counted for the frame that is being removed, decrement the // If matches are counted for the frame that is being removed, decrement the
// match total before erasing that entry. // match total before erasing that entry.
auto it = find_in_page_clients_.find(rfh); auto it = find_in_page_clients_.find(rfh);
......
...@@ -845,4 +845,63 @@ IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, ActivateNearestFindMatch) { ...@@ -845,4 +845,63 @@ IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, ActivateNearestFindMatch) {
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
// Test basic find-in-page functionality after going back and forth to the same
// page. In particular, find-in-page should continue to work after going back to
// a page using the back-forward cache.
IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, HistoryBackAndForth) {
GURL url_a = embedded_test_server()->GetURL("a.com", "/find_in_page.html");
GURL url_b = embedded_test_server()->GetURL("b.com", "/find_in_page.html");
auto test_page = [&] {
if (GetParam())
MakeChildFrameCrossProcess();
auto options = blink::mojom::FindOptions::New();
// The initial find-in-page request.
Find("result", options->Clone());
delegate()->WaitForFinalReply();
FindResults results = delegate()->GetFindResults();
EXPECT_EQ(last_request_id(), results.request_id);
EXPECT_EQ(19, results.number_of_matches);
// Iterate forward/backward over a few elements.
int match_index = results.active_match_ordinal;
for (int delta : {-1, -1, +1, +1, +1, +1, -1, +1, +1}) {
options->find_next = true;
options->forward = delta > 0;
// |active_match_ordinal| uses 1-based index. It belongs to [1, 19].
match_index += delta;
match_index = (match_index + 18) % 19 + 1;
Find("result", options->Clone());
delegate()->WaitForFinalReply();
results = delegate()->GetFindResults();
EXPECT_EQ(last_request_id(), results.request_id);
EXPECT_EQ(19, results.number_of_matches);
EXPECT_EQ(match_index, results.active_match_ordinal);
}
};
// 1) Navigate to A.
EXPECT_TRUE(NavigateToURL(shell(), url_a));
test_page();
// 2) Navigate to B.
EXPECT_TRUE(NavigateToURL(shell(), url_b));
test_page();
// 3) Go back to A.
contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
test_page();
// 4) Go forward to B.
contents()->GetController().GoForward();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
test_page();
}
} // namespace content } // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment