Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: content/browser/find_request_manager.cc

Issue 2236403004: Handling new frames and frame navigations with find-in-page during a find session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and updated comment. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/find_request_manager.cc
diff --git a/content/browser/find_request_manager.cc b/content/browser/find_request_manager.cc
index db706a283a7ccf9267e7669048611d6fac0939c9..5c2eeb2df374da1d18e384648cea298a81708156 100644
--- a/content/browser/find_request_manager.cc
+++ b/content/browser/find_request_manager.cc
@@ -151,11 +151,18 @@ void FindRequestManager::OnFindReply(RenderFrameHost* rfh,
// Check for an update to the number of matches.
if (number_of_matches != -1) {
DCHECK_GE(number_of_matches, 0);
- // Increment the global number of matches by the number of additional
- // matches found for this frame.
auto matches_per_frame_it = matches_per_frame_.find(rfh);
- number_of_matches_ += number_of_matches - matches_per_frame_it->second;
- matches_per_frame_it->second = number_of_matches;
+ if (int matches_delta = number_of_matches - matches_per_frame_it->second) {
+ // Increment the global number of matches by the number of additional
+ // matches found for this frame.
+ number_of_matches_ += matches_delta;
+ matches_per_frame_it->second = number_of_matches;
+
+ // The active match ordinal may need updating since the number of matches
+ // before the active match may have changed.
+ if (rfh != active_frame_)
+ UpdateActiveMatchOrdinal();
+ }
}
// Check for an update to the selection rect.
@@ -346,6 +353,15 @@ void FindRequestManager::OnFindMatchRectsReply(
}
#endif
+void FindRequestManager::DidFinishLoad(RenderFrameHost* rfh,
+ const GURL& validated_url) {
+ if (current_session_id_ == kInvalidId)
+ return;
+
+ RemoveFrame(rfh);
+ AddFrame(rfh, true /* force */);
+}
+
void FindRequestManager::RenderFrameDeleted(RenderFrameHost* rfh) {
RemoveFrame(rfh);
}
@@ -405,7 +421,7 @@ void FindRequestManager::FindInternal(const FindRequest& request) {
// This is an initial find operation.
Reset(request);
for (FrameTreeNode* node : contents_->GetFrameTree()->Nodes())
- AddFrame(node->current_frame_host());
+ AddFrame(node->current_frame_host(), false /* force */);
}
void FindRequestManager::AdvanceQueue(int request_id) {
@@ -484,18 +500,19 @@ RenderFrameHost* FindRequestManager::Traverse(RenderFrameHost* from_rfh,
return nullptr;
}
-void FindRequestManager::AddFrame(RenderFrameHost* rfh) {
+void FindRequestManager::AddFrame(RenderFrameHost* rfh, bool force) {
if (!rfh || !rfh->IsRenderFrameLive())
return;
- // A frame that is already being searched should not be added again.
- DCHECK(!CheckFrame(rfh));
+ // A frame that is already being searched should not normally be added again.
+ DCHECK(force || !CheckFrame(rfh));
matches_per_frame_[rfh] = 0;
FindRequest request = current_request_;
request.id = current_session_id_;
request.options.findNext = false;
+ request.options.force = force;
SendFindIPC(request, rfh);
}
@@ -528,7 +545,7 @@ void FindRequestManager::FinalUpdateReceived(int request_id,
RenderFrameHost* rfh) {
if (!number_of_matches_ ||
(active_match_ordinal_ && !pending_active_match_ordinal_) ||
- request_id != current_request_.id) {
+ pending_find_next_reply_) {
// All the find results for |request_id| are in and ready to report. Note
// that |final_update| will be set to false if there are still pending
// replies expected from the initial find request.
@@ -542,7 +559,7 @@ void FindRequestManager::FinalUpdateReceived(int request_id,
// request must be sent.
RenderFrameHost* target_rfh;
- if (current_request_.options.findNext) {
+ if (request_id == current_request_.id && current_request_.options.findNext) {
// If this was a find next operation, then the active match will be in the
// next frame with matches after this one.
target_rfh = Traverse(rfh,

Powered by Google App Engine
This is Rietveld 408576698